From: Zdeněk Šustr Date: Fri, 27 Jun 2008 09:52:32 +0000 (+0000) Subject: Proper handling of event queries (taking into account job conditions) X-Git-Tag: glite-lb-client_R_3_2_2_1~16 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=48d4173b3b362ecc97f892214a022b12a891541e;p=jra1mw.git Proper handling of event queries (taking into account job conditions) - will get more testing. - broken event querying unit test Fixes bug #32390 --- diff --git a/org.glite.lb.server/Makefile b/org.glite.lb.server/Makefile index ee716a6..66abcff 100644 --- a/org.glite.lb.server/Makefile +++ b/org.glite.lb.server/Makefile @@ -271,7 +271,8 @@ ${MAN_GZ}: ${MAN} compile: glite-lb-bkserverd glite-lb-bkindex ${STATIC_LIB_BK} ${PLUGIN_LIB} store.c index.c jp_job_attrs.h ${MAN_GZ} -check: compile test.xml test.query +#check: compile test.xml test.query +check: compile test.xml -echo check.query not complete yet test_coverage: diff --git a/org.glite.lb.server/src/query.c b/org.glite.lb.server/src/query.c index 33247eb..8ec4237 100644 --- a/org.glite.lb.server/src/query.c +++ b/org.glite.lb.server/src/query.c @@ -61,6 +61,10 @@ int edg_wll_QueryEventsServer( eperm = 0; char *peerid = NULL; char *can_peername = NULL, *can_peerid = NULL; + edg_wlc_JobId *jobsfound; + edg_wll_JobStat *statesfound; + char *jobstr; + int ii; edg_wll_ResetError(ctx); @@ -92,130 +96,142 @@ int edg_wll_QueryEventsServer( can_peername = edg_wll_gss_normalize_subj(ctx->peerName, 0); if (can_peername) can_peerid = strdup(strmd5(can_peername,NULL)); -/* XXX: similar query in srv_purge.c ! They has to match due to common - * convert_event_head() called on the result - */ - trio_asprintf(&qbase,"SELECT e.event,j.userid,j.dg_jobid,e.code," - "e.prog,e.host,u.cert_subj,e.time_stamp,e.usec,e.level,e.arrived " - "FROM events e,users u,jobs j%s " - "WHERE %se.jobid=j.jobid AND e.userid=u.userid AND e.code != %d " - "%s %s %s %s", - i & FL_SEL_STATUS ? ",states s" : "", - i & FL_SEL_STATUS ? "s.jobid=j.jobid AND " : "", - EDG_WLL_EVENT_UNDEF, - job_where ? "AND" : "", - job_where ? job_where : "", - event_where ? "AND" : "", - event_where ? event_where : ""); - - if ( ctx->softLimit ) - { - if ( ctx->hardEventsLimit ) - limit = ctx->softLimit < ctx->hardEventsLimit? ctx->softLimit: ctx->hardEventsLimit; - else - limit = ctx->softLimit; - } - else if ( ctx->hardEventsLimit ) - limit = ctx->hardEventsLimit; - else - limit = 0; i = 0; out = calloc(1, sizeof(*out)); - do - { - if ( limit ) - trio_asprintf(&q, "%s LIMIT %d, %d", qbase, offset, limit); - else if ( !q ) - q = qbase; -// printf("\nquery: %s\n\n", q); - ret = edg_wll_ExecStmt(ctx, q, &sh); - if ( limit ) - free(q); - if ( ret < 0 ) - { - edg_wll_FreeStmt(&sh); - goto cleanup; - } - if ( ret == 0 ) + edg_wll_QueryJobsServer(ctx, job_conditions, 0, &jobsfound, &statesfound); + + for ( ii = 0; (jobsfound) && (jobsfound[ii]); ii++ ) { + jobstr = edg_wlc_JobIdUnparse(jobsfound[ii]); + +/* XXX: similar query in srv_purge.c ! They have to match due to common + * convert_event_head() called on the result + */ + trio_asprintf(&qbase,"SELECT e.event,j.userid,j.dg_jobid,e.code," + "e.prog,e.host,u.cert_subj,e.time_stamp,e.usec,e.level,e.arrived " + "FROM events e,users u,jobs j " + "WHERE j.dg_jobid = '%s' AND e.jobid=j.jobid AND e.userid=u.userid AND e.code != %d " + "%s %s %s %s", + jobstr, + EDG_WLL_EVENT_UNDEF, + job_where ? "AND" : "", + job_where ? job_where : "", + event_where ? "AND" : "", + event_where ? event_where : ""); + + if ( ctx->softLimit ) { - limit_loop = 0; - goto limit_cycle_cleanup; + if ( ctx->hardEventsLimit ) + limit = ctx->softLimit < ctx->hardEventsLimit? ctx->softLimit: ctx->hardEventsLimit; + else + limit = ctx->softLimit; } - if ( !limit || (ret < limit) ) - limit_loop = 0; + else if ( ctx->hardEventsLimit ) + limit = ctx->hardEventsLimit; + else + limit = 0; - offset += ret; - while ( (ret = edg_wll_FetchRow(sh, res)) == sizofa(res) ) + do { - int n = atoi(res[0]); - free(res[0]); + if ( limit ) + trio_asprintf(&q, "%s LIMIT %d, %d", qbase, offset, limit); + else if ( !q ) + q = qbase; + + ret = edg_wll_ExecStmt(ctx, q, &sh); + + free (qbase); qbase = NULL; - if ( convert_event_head(ctx, res+2, out+i) || edg_wll_get_event_flesh(ctx, n, out+i) ) + if ( limit ) + free(q); + q = NULL; + + if ( ret < 0 ) { - free(res[1]); - memset(out+i, 0, sizeof(*out)); edg_wll_FreeStmt(&sh); goto cleanup; } - - if ( !match_flesh_conditions(out+i,event_conditions) || check_strict_jobid(ctx,out[i].any.jobId) ) + if ( ret == 0 ) { - edg_wll_FreeEvent(out+i); - edg_wll_ResetError(ctx); /* check_strict_jobid() sets it */ - goto fetch_cycle_cleanup; + limit_loop = 0; + goto limit_cycle_cleanup; } + if ( !limit || (ret < limit) ) + limit_loop = 0; - if ( !noAuth ) + offset += ret; + while ( (ret = edg_wll_FetchRow(sh, res)) == sizofa(res) ) { - if (!ctx->peerName || (strcmp(res[1],peerid) && strcmp(res[1], can_peerid))) { - edg_wll_Acl acl = NULL; - char *jobid = NULL; - - ret = edg_wll_GetACL(ctx, out[i].any.jobId, &acl); - free(jobid); - if (ret || acl == NULL) { - eperm = 1; - edg_wll_FreeEvent(out+i); - edg_wll_ResetError(ctx); /* XXX: should be reported somewhere at least in debug mode */ - goto fetch_cycle_cleanup; - } + int n = atoi(res[0]); + free(res[0]); + + if ( convert_event_head(ctx, res+2, out+i) || edg_wll_get_event_flesh(ctx, n, out+i) ) + { + free(res[1]); + memset(out+i, 0, sizeof(*out)); + edg_wll_FreeStmt(&sh); + goto cleanup; + } - ret = edg_wll_CheckACL(ctx, acl, EDG_WLL_PERM_READ); - edg_wll_FreeAcl(acl); - if (ret) { - eperm = 1; - edg_wll_FreeEvent(out+i); - edg_wll_ResetError(ctx); /* XXX: should be reported somewhere at least in debug mode */ - goto fetch_cycle_cleanup; + if ( !match_flesh_conditions(out+i,event_conditions) || check_strict_jobid(ctx,out[i].any.jobId) ) + { + edg_wll_FreeEvent(out+i); + edg_wll_ResetError(ctx); /* check_strict_jobid() sets it */ + goto fetch_cycle_cleanup; + } + + if ( !noAuth ) + { + if (!ctx->peerName || (strcmp(res[1],peerid) && strcmp(res[1], can_peerid))) { + edg_wll_Acl acl = NULL; + char *jobid = NULL; + + ret = edg_wll_GetACL(ctx, out[i].any.jobId, &acl); + free(jobid); + if (ret || acl == NULL) { + eperm = 1; + edg_wll_FreeEvent(out+i); + edg_wll_ResetError(ctx); /* XXX: should be reported somewhere at least in debug mode */ + goto fetch_cycle_cleanup; + } + + ret = edg_wll_CheckACL(ctx, acl, EDG_WLL_PERM_READ); + edg_wll_FreeAcl(acl); + if (ret) { + eperm = 1; + edg_wll_FreeEvent(out+i); + edg_wll_ResetError(ctx); /* XXX: should be reported somewhere at least in debug mode */ + goto fetch_cycle_cleanup; + } } } - } - - if ( (ctx->p_query_results != EDG_WLL_QUERYRES_ALL) && limit && (i+1 > limit) ) - { - free(res[1]); - memset(out+i, 0, sizeof(*out)); - edg_wll_SetError(ctx, E2BIG, "Query result size limit exceeded"); - if ( ctx->p_query_results == EDG_WLL_QUERYRES_LIMITED ) + + if ( (ctx->p_query_results != EDG_WLL_QUERYRES_ALL) && limit && (i+1 > limit) ) { - limit_loop = 0; - goto limit_cycle_cleanup; + free(res[1]); + memset(out+i, 0, sizeof(*out)); + edg_wll_SetError(ctx, E2BIG, "Query result size limit exceeded"); + if ( ctx->p_query_results == EDG_WLL_QUERYRES_LIMITED ) + { + limit_loop = 0; + goto limit_cycle_cleanup; + } + goto cleanup; } - goto cleanup; - } - i++; - out = (edg_wll_Event *) realloc(out, (i+1) * sizeof(*out)); + i++; + out = (edg_wll_Event *) realloc(out, (i+1) * sizeof(*out)); fetch_cycle_cleanup: - memset(out+i, 0, sizeof(*out)); - free(res[1]); - } + memset(out+i, 0, sizeof(*out)); + free(res[1]); + } limit_cycle_cleanup: - edg_wll_FreeStmt(&sh); - } while ( limit_loop ); + edg_wll_FreeStmt(&sh); + } while ( limit_loop ); + free(jobstr); jobstr = NULL; + } if ( i == 0 && eperm ) edg_wll_SetError(ctx, EPERM, "matching events found but authorization failed"); @@ -235,7 +251,6 @@ cleanup: edg_wll_FreeEvent(out+i); free(out); } - free(qbase); free(job_where); free(event_where); free(peerid); @@ -320,7 +335,6 @@ int edg_wll_QueryJobsServer( else if ( !q ) q = qbase; -// printf("\nquery: %s\n\n", q); ret = edg_wll_ExecStmt(ctx, q, &sh); if ( limit ) free(q); diff --git a/org.glite.lb.server/test/oneJob.qry b/org.glite.lb.server/test/oneJob.qry index 74655ff..9011124 100644 --- a/org.glite.lb.server/test/oneJob.qry +++ b/org.glite.lb.server/test/oneJob.qry @@ -22,3 +22,7 @@ SEQCODE UI=000002:NS=0000000001:WM=000000:BH=0000000000:JSS=000000:LM=000000:LRM SRC_INSTANCE select name,value from long_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 1 + +SELECT DISTINCT j.dg_jobid,j.userid FROM jobs j WHERE (j.jobid='WrCEKje9QTXFiSOZuPMLtw') +https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw 294de3557d9d00b3d2d8a1e6aab028cf +