From 40a8c2b1c51a1fa21197169687abe2192f92b92c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Fri, 28 Aug 2009 13:20:37 +0000 Subject: [PATCH] Purge notifications. --- org.glite.lb.client/src/notify.c | 2 +- org.glite.lb.server/src/db_store.c | 2 +- org.glite.lb.server/src/il_notification.h | 5 +++++ org.glite.lb.server/src/srv_purge.c | 29 +++++++++++++++++------------ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/org.glite.lb.client/src/notify.c b/org.glite.lb.client/src/notify.c index 913939d..2e7fc2c 100644 --- a/org.glite.lb.client/src/notify.c +++ b/org.glite.lb.client/src/notify.c @@ -198,7 +198,7 @@ int main(int argc,char **argv) for (sti = 0; sti < strlen(statelist); sti++) if (statelist[sti] == ',') stdelims++; conditions[i] = (edg_wll_QueryRec *)calloc(stdelims+2,sizeof(edg_wll_QueryRec)); - while(single = strtok(statelist, ",")) { + while((single = strtok(statelist, ","))) { single_code = edg_wll_StringToStat(single); if (single_code != -1) { conditions[i][statno].attr = EDG_WLL_QUERY_ATTR_STATUS; diff --git a/org.glite.lb.server/src/db_store.c b/org.glite.lb.server/src/db_store.c index dde7ce4..54cbcf0 100644 --- a/org.glite.lb.server/src/db_store.c +++ b/org.glite.lb.server/src/db_store.c @@ -15,6 +15,7 @@ #include "il_lbproxy.h" #include "jobstat.h" #include "db_supp.h" +#include "il_notification.h" #ifdef LB_PERF #include "glite/lb/lb_perftest.h" @@ -23,7 +24,6 @@ extern int unset_proxy_flag(edg_wll_Context, edg_wlc_JobId); -extern int edg_wll_NotifMatch(edg_wll_Context, const edg_wll_JobStat *, const edg_wll_JobStat *); extern int enable_lcas; diff --git a/org.glite.lb.server/src/il_notification.h b/org.glite.lb.server/src/il_notification.h index 45b396e..ef142d2 100644 --- a/org.glite.lb.server/src/il_notification.h +++ b/org.glite.lb.server/src/il_notification.h @@ -97,6 +97,11 @@ edg_wll_NotifCancelRegId(edg_wll_Context context, edg_wll_NotifId reg_id); +/** + * Check and perform notifications. + */ +int edg_wll_NotifMatch(edg_wll_Context context, const edg_wll_JobStat *oldstat, const edg_wll_JobStat *stat); + #ifdef __cplusplus } #endif diff --git a/org.glite.lb.server/src/srv_purge.c b/org.glite.lb.server/src/srv_purge.c index f3b2c8b..62538f2 100644 --- a/org.glite.lb.server/src/srv_purge.c +++ b/org.glite.lb.server/src/srv_purge.c @@ -30,6 +30,7 @@ #include "db_calls.h" #include "db_supp.h" #include "jobstat.h" +#include "il_notification.h" #define DUMP_FILE_STORAGE "/tmp/" @@ -45,7 +46,7 @@ static const char* const resp_headers[] = { static int purge_check(edg_wll_Context ctx, edg_wll_JobStat *stat, time_t start, time_t *timeout); static int purge_one_with_subjobs(edg_wll_Context ctx, edg_wll_JobStat *stat, int dumpfile, const edg_wll_PurgeRequest *request, edg_wll_PurgeResult *result, int *njobs, int *parse); -static int purge_one(edg_wll_Context ctx,glite_jobid_const_t,int,int,int); +static int purge_one(edg_wll_Context ctx,edg_wll_JobStat *,int,int,int); int unset_proxy_flag(edg_wll_Context ctx, glite_jobid_const_t job); static int unset_server_flag(edg_wll_Context ctx, glite_jobid_const_t job); int job_exists(edg_wll_Context ctx, glite_jobid_const_t job); @@ -191,7 +192,11 @@ int edg_wll_CreateFileStorage(edg_wll_Context ctx, char *file_type, char *prefix int edg_wll_PurgeServerProxy(edg_wll_Context ctx, glite_jobid_const_t job) { - switch ( purge_one(ctx, job, -1, 1, 1) ) { + edg_wll_JobStat stat; + + memset(&stat, 0, sizeof stat); + stat.jobId = (glite_jobid_t)job; + switch ( purge_one(ctx, &stat, -1, 1, 1) ) { case 0: case ENOENT: return(edg_wll_ResetError(ctx)); @@ -621,11 +626,10 @@ static int purge_check(edg_wll_Context ctx, edg_wll_JobStat *stat, time_t start, #define GRAN 32 static int purge_one_with_subjobs(edg_wll_Context ctx, edg_wll_JobStat *stat, int dumpfile, const edg_wll_PurgeRequest *request, edg_wll_PurgeResult *result, int *njobs, int *parse) { - glite_jobid_t subjob = NULL; char *job_s; int i; - if (purge_one(ctx,stat->jobId,dumpfile,request->flags&EDG_WLL_PURGE_REALLY_PURGE,ctx->isProxy)) return edg_wll_Error(ctx, NULL, NULL); + if (purge_one(ctx,stat,dumpfile,request->flags&EDG_WLL_PURGE_REALLY_PURGE,ctx->isProxy)) return edg_wll_Error(ctx, NULL, NULL); /* XXX: change with the streaming interface */ if (request->flags & EDG_WLL_PURGE_LIST_JOBS) { @@ -640,15 +644,9 @@ static int purge_one_with_subjobs(edg_wll_Context ctx, edg_wll_JobStat *stat, in /* purge the subjobs */ if (stat->children_num && stat->children) { for (i = 0; i < stat->children_num && stat->children[i]; i++) { - if (glite_jobid_parse(stat->children[i], &subjob)) { - fprintf(stderr,"%s: parse error (internal inconsistency !)\n",stat->children[i]); - *parse = 1; - } - if (purge_one(ctx, subjob, dumpfile, request->flags&EDG_WLL_PURGE_REALLY_PURGE,ctx->isProxy)) { - glite_jobid_free(subjob); + if (purge_one(ctx, stat->children_states + i, dumpfile, request->flags&EDG_WLL_PURGE_REALLY_PURGE,ctx->isProxy)) { return edg_wll_Error(ctx, NULL, NULL); } - glite_jobid_free(subjob); if (request->flags & EDG_WLL_PURGE_LIST_JOBS) { if (*njobs % GRAN == 0 || !result->jobs) @@ -664,7 +662,7 @@ static int purge_one_with_subjobs(edg_wll_Context ctx, edg_wll_JobStat *stat, in } -int purge_one(edg_wll_Context ctx,glite_jobid_const_t job,int dump, int purge, int purge_from_proxy_only) +int purge_one(edg_wll_Context ctx,edg_wll_JobStat *stat,int dump, int purge, int purge_from_proxy_only) { char *dbjob = NULL; char *stmt = NULL; @@ -674,6 +672,8 @@ int purge_one(edg_wll_Context ctx,glite_jobid_const_t job,int dump, int purge, i char *prefix = NULL, *suffix = NULL, *root = NULL; char *prefix_id = NULL, *suffix_id = NULL; int sql_retval; + glite_jobid_const_t job = stat->jobId; + edg_wll_JobStat new_stat; edg_wll_ResetError(ctx); if ( !purge && dump < 0 ) return 0; @@ -860,6 +860,11 @@ int purge_one(edg_wll_Context ctx,glite_jobid_const_t job,int dump, int purge, i } glite_lbu_FreeStmt(&q); free(stmt); stmt = NULL; + + /* notifications */ + memcpy(&new_stat, stat, sizeof new_stat); + new_stat.state = EDG_WLL_JOB_PURGED; + edg_wll_NotifMatch(ctx, stat, &new_stat); } if (dump >= 0) -- 1.8.2.3