operator changed implementation (just proof of concept, for backup purpose only)
authorMiloš Mulač <mulac@civ.zcu.cz>
Mon, 3 Nov 2008 14:43:17 +0000 (14:43 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Mon, 3 Nov 2008 14:43:17 +0000 (14:43 +0000)
- recommit to something reasonable will appear soon

org.glite.lb.server/src/query.c

index fb9deb7..0ecf9ae 100644 (file)
@@ -198,7 +198,7 @@ int edg_wll_QueryEventsServer(
                                                goto fetch_cycle_cleanup;
                                        }
                                
-                                       if ( !(match_status_old = match_status(ctx, (&state_out), job_conditions)) )
+                                       if ( !(match_status_old = match_status(ctx, NULL, (&state_out), job_conditions)) )
                                        {
                                                edg_wll_FreeEvent(out+i);
                                                edg_wll_ResetError(ctx);        /* check_strict_jobid() sets it */
@@ -458,7 +458,7 @@ int edg_wll_QueryJobsServer(
 
                        }
                        if (where_flags & FL_FILTER) {
-                               if ( !match_status(ctx, states_out+i, conditions) )
+                               if ( !match_status(ctx, NULL, states_out+i, conditions) )
                                {
                                        edg_wlc_JobIdFree(jobs_out[i]);
                                        edg_wll_FreeStatus(states_out+i);
@@ -1394,7 +1394,7 @@ err:
 
 
 /* FIXME: other op's, ORed conditions */
-int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll_QueryRec **conds)
+int match_status(edg_wll_Context ctx, const edg_wll_JobStat *oldstat, const edg_wll_JobStat *stat, const edg_wll_QueryRec **conds)
 {
        int             i, j, n;
        char   *s, *s1;
@@ -1406,7 +1406,8 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
        {
                for ( j = 0; conds[i][j].attr; j++ )
                {
-                       if ( is_indexed(&(conds[i][j]), ctx) ) goto or_satisfied;
+                       // ignore operator CHANGED for non-notification matches
+                       if ( (conds[i][j].op == EDG_WLL_QUERY_OP_CHANGED) && !oldstat) continue;
 
                        switch ( conds[i][j].attr )
                        {
@@ -1429,13 +1430,19 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                        if (   conds[i][j].value.i <= stat->state
                                                && conds[i][j].value2.i >= stat->state ) goto or_satisfied;
                                        break;
+                               case EDG_WLL_QUERY_OP_CHANGED:
+                                       if ( oldstat->state != stat->state ) goto or_satisfied;
+                                       break;
                                }
                                break;
                        case EDG_WLL_QUERY_ATTR_RESUBMITTED:
                                if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) {
                                        if ( conds[i][j].value.i == stat->resubmitted ) goto or_satisfied;
-                               } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL )
+                               } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) {
                                        if ( conds[i][j].value.i != stat->resubmitted ) goto or_satisfied;
+                               } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_CHANGED ) {
+                                        if ( oldstat->resubmitted != stat->resubmitted ) goto or_satisfied;
+                               }
                                break;
                        case EDG_WLL_QUERY_ATTR_DONECODE:
                                switch ( conds[i][j].op )
@@ -1456,6 +1463,9 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                        if (   conds[i][j].value.i <= stat->done_code
                                                && conds[i][j].value2.i >= stat->done_code ) goto or_satisfied;
                                        break;
+                               case EDG_WLL_QUERY_OP_CHANGED:
+                                       if ( oldstat->done_code != stat->done_code ) goto or_satisfied;
+                                       break;
                                }
                                break;
                        case EDG_WLL_QUERY_ATTR_EXITCODE:
@@ -1477,6 +1487,9 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                        if (   conds[i][j].value.i <= stat->exit_code
                                                && conds[i][j].value2.i >= stat->exit_code ) goto or_satisfied;
                                        break;
+                               case EDG_WLL_QUERY_OP_CHANGED:
+                                       if ( oldstat->exit_code != stat->exit_code ) goto or_satisfied;
+                                       break;
                                }
                                break;
                        case EDG_WLL_QUERY_ATTR_OWNER:
@@ -1489,6 +1502,8 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                                if (edg_wll_gss_equal_subj(ctx->peerName, stat->owner) ) {
                                                        if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) goto or_satisfied;
                                                } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
+                                       } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_CHANGED ) {
+                                               if (!edg_wll_gss_equal_subj(oldstat->owner, stat->owner) ) goto or_satisfied;
                                        }
                                }
                                break;
@@ -1499,6 +1514,12 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                                if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) goto or_satisfied;
                                        } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
                                }
+                               if ( conds[i][j].op == EDG_WLL_QUERY_OP_CHANGED ) {
+                                               if ( (oldstat->location && !stat->location) || 
+                                                       (!oldstat->location && stat->location) ) goto or_satisfied;
+                                               if ( oldstat->location && stat->location && 
+                                                       strcmp(oldstat->location,stat->location) ) goto or_satisfied;
+                               }
                                break;
                        case EDG_WLL_QUERY_ATTR_DESTINATION:
                                if ( stat->destination )
@@ -1507,6 +1528,12 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                                if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) goto or_satisfied;
                                        } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
                                }
+                               if ( conds[i][j].op == EDG_WLL_QUERY_OP_CHANGED ) {
+                                               if ( (oldstat->destination && !stat->destination) || 
+                                                       (!oldstat->destination && stat->destination) ) goto or_satisfied;
+                                               if ( oldstat->destination && stat->destination && 
+                                                       strcmp(oldstat->destination,stat->destination) ) goto or_satisfied;
+                               }
                        case EDG_WLL_QUERY_ATTR_NETWORK_SERVER:
                                if ( stat->network_server )
                                {
@@ -1515,6 +1542,12 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                        } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
                                }
                                break;
+                               if ( conds[i][j].op == EDG_WLL_QUERY_OP_CHANGED ) {
+                                               if ( (oldstat->network_server && !stat->network_server) || 
+                                                       (!oldstat->network_server && stat->network_server) ) goto or_satisfied;
+                                               if ( oldstat->network_server && stat->network_server && 
+                                                       strcmp(oldstat->network_server,stat->network_server) ) goto or_satisfied;
+                               }
                        case EDG_WLL_QUERY_ATTR_JOBID:
                                if ( !stat->jobId )
                                        break;
@@ -1562,6 +1595,19 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                        }
                                if ( !stat->user_tags[n].tag && conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL )
                                        goto or_satisfied;
+                               if ( conds[i][j].op == EDG_WLL_QUERY_OP_CHANGED ) {
+                                               if ( (oldstat->user_tags && !stat->user_tags) || 
+                                                       (!oldstat->user_tags && stat->user_tags) ) goto or_satisfied;
+                                               if ( oldstat->user_tags && stat->user_tags ) { 
+                                                       for ( n = 0; stat->user_tags[n].tag; n++ )
+                                                               if ( !oldstat->user_tags[n].tag ) goto or_satisfied;
+                                                               if ( strcmp(oldstat->user_tags[n].tag,stat->user_tags[n].tag) ) goto or_satisfied;
+                                                               else {
+                                                                       if ( strcmp(oldstat->user_tags[n].value, stat->user_tags[n].value) ) goto or_satisfied;
+                                                               }
+                                               }
+                               }
+
                                break;
                        case EDG_WLL_QUERY_ATTR_TIME:
                                if ( !stat->stateEnterTimes || !stat->stateEnterTimes[1+conds[i][j].attr_id.state] )
@@ -1584,16 +1630,23 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                        if (   conds[i][j].value.t.tv_sec <= stat->stateEnterTimes[1+conds[i][j].attr_id.state]
                                                && conds[i][j].value2.t.tv_sec >= stat->stateEnterTimes[1+conds[i][j].attr_id.state] ) goto or_satisfied;
                                        break;
+                               case EDG_WLL_QUERY_OP_CHANGED:
+                                       if ( oldstat->stateEnterTimes[1+conds[i][j].attr_id.state] != stat->stateEnterTimes[1+conds[i][j].attr_id.state] ) goto or_satisfied;
+                                       break;
                                }
                                break;
                        case EDG_WLL_QUERY_ATTR_JDL_ATTR:
+                               if ( conds[i][j].op == EDG_WLL_QUERY_OP_CHANGED ) {
+                                               if ( (oldstat->jdl && !stat->jdl) || 
+                                                       (!oldstat->jdl && stat->jdl) ) goto or_satisfied;
+                               }
 
                                if (stat->jdl != NULL) {
                                        struct cclassad *ad = NULL;
                                        char *extr_val = NULL;
 
                                        // Jobs that do not have a JDL come with blabla:
-                                       if (!strcmp(stat->jdl,"blabla")) break;
+                                       if (!strcmp(stat->jdl,"blabla") && conds[i][j].op != EDG_WLL_QUERY_OP_CHANGED) break;
 
                                        ad = cclassad_create(stat->jdl);
                                        if (ad) {
@@ -1608,6 +1661,24 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                                        else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
                                                }
                                        }
+                                       if ( conds[i][j].op == EDG_WLL_QUERY_OP_CHANGED ) {
+                                               struct cclassad *ad2 = NULL;
+                                               char *extr_val2 = NULL;
+
+                                               // Jobs that do not have a JDL come with blabla:
+                                               if ( (!strcmp(stat->jdl,"blabla") && strcmp(oldstat->jdl,"blabla")) ||
+                                                       (strcmp(stat->jdl,"blabla") && !strcmp(oldstat->jdl,"blabla")) ) goto or_satisfied;
+
+                                               ad2 = cclassad_create(oldstat->jdl);
+                                               if (ad2) {
+                                                       if (!cclassad_evaluate_to_string(ad2, conds[i][j].attr_id.tag, &extr_val2)) // Extract attribute value
+                                                               extr_val2 = NULL;
+                                                       cclassad_delete(ad2);
+                                               }
+                                               if (extr_val2) {
+                                                       if ( strcmp(extr_val, extr_val2) ) goto or_satisfied;
+                                               }
+                                       }
                                }
                                break;
                        case EDG_WLL_QUERY_ATTR_STATEENTERTIME:
@@ -1631,6 +1702,9 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                        if (   conds[i][j].value.t.tv_sec <= stat->stateEnterTime.tv_sec
                                                && conds[i][j].value2.t.tv_sec >= stat->stateEnterTime.tv_sec ) goto or_satisfied;
                                        break;
+                               case EDG_WLL_QUERY_OP_CHANGED:
+                                       if ( oldstat->stateEnterTime.tv_sec != stat->stateEnterTime.tv_sec ) goto or_satisfied;
+                                       break;
                                }
                        case EDG_WLL_QUERY_ATTR_LASTUPDATETIME:
                                if ( !stat->lastUpdateTime.tv_sec )
@@ -1653,6 +1727,9 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                        if (   conds[i][j].value.t.tv_sec <= stat->lastUpdateTime.tv_sec
                                                && conds[i][j].value2.t.tv_sec >= stat->lastUpdateTime.tv_sec ) goto or_satisfied;
                                        break;
+                               case EDG_WLL_QUERY_OP_CHANGED:
+                                       if ( oldstat->lastUpdateTime.tv_sec != stat->lastUpdateTime.tv_sec ) goto or_satisfied;
+                                       break;
                                }
                        default:
                                break;