Full implementation of JDL attribute searches (handling EDG_WLL_QUERY_ATTR_JDL_ATTR...
authorZdeněk Šustr <sustr4@cesnet.cz>
Thu, 31 Jan 2008 13:15:30 +0000 (13:15 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Thu, 31 Jan 2008 13:15:30 +0000 (13:15 +0000)
org.glite.lb.client/examples/query_ext.c
org.glite.lb.common/src/query_rec.c
org.glite.lb.common/src/xml_parse.c.T
org.glite.lb.server/Makefile
org.glite.lb.server/src/index.c.T
org.glite.lb.server/src/lb_xml_parse.c.T
org.glite.lb.server/src/query.c

index 48879a9..6fc5018 100644 (file)
@@ -434,9 +434,21 @@ static char *get_job_condition(char *src, edg_wll_QueryRec *cond)
        case EDG_WLL_QUERY_ATTR_LOCATION:
        case EDG_WLL_QUERY_ATTR_DESTINATION:
        case EDG_WLL_QUERY_ATTR_USERTAG:
+               if ( !(cond->value.c = strdup(tmps)) )
+                       return 0;
+               break;
+
        case EDG_WLL_QUERY_ATTR_JDL_ATTR:
                if ( !(cond->value.c = strdup(tmps)) )
                        return 0;
+               if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL;
+               if ( tmps[0] == '\0' )
+               {
+                       fprintf(stderr,"%s: you need to specify attribute name\n", myname);
+                       return NULL;
+               }
+               if ( !(cond->attr_id.tag = strdup(tmps)) )
+                       return 0;
                break;
 
        case EDG_WLL_QUERY_ATTR_STATUS:
index 6c274ad..d484e50 100644 (file)
@@ -21,13 +21,13 @@ void edg_wll_QueryRecFree(edg_wll_QueryRec *prec)
        }
        switch (prec->attr) {
                case EDG_WLL_QUERY_ATTR_USERTAG:
+               case EDG_WLL_QUERY_ATTR_JDL_ATTR:
                        free(prec->attr_id.tag);
                case EDG_WLL_QUERY_ATTR_OWNER: 
                case EDG_WLL_QUERY_ATTR_LOCATION:
                case EDG_WLL_QUERY_ATTR_DESTINATION:
                case EDG_WLL_QUERY_ATTR_HOST:
                case EDG_WLL_QUERY_ATTR_INSTANCE:
-               case EDG_WLL_QUERY_ATTR_JDL_ATTR:
                        if ( prec->value.c ) free(prec->value.c);
                        break;
                case EDG_WLL_QUERY_ATTR_JOBID:
index 97c22e4..650ae81 100644 (file)
@@ -2493,7 +2493,7 @@ int edg_wll_JobQueryRecToXML(
                                                edg_wll_add_tagged_string_to_XMLBody(&pomValue, conditions[row][i].value.c, "usertag", conditions[row][i].attr_id.tag, "name", NULL);
                                                break;
                                        case EDG_WLL_QUERY_ATTR_JDL_ATTR:
-                                               edg_wll_add_string_to_XMLBody(&pomValue, conditions[row][i].value.c, "jdl", NULL);
+                                               edg_wll_add_tagged_string_to_XMLBody(&pomValue, conditions[row][i].value.c, "jdl", conditions[row][i].attr_id.tag, "name", NULL);
                                                break;
                                        case EDG_WLL_QUERY_ATTR_STATEENTERTIME:
                                                if (conditions[row][i].op == EDG_WLL_QUERY_OP_WITHIN) {
@@ -2647,6 +2647,9 @@ int edg_wll_QueryEventsRequestToXML(
                                case EDG_WLL_QUERY_ATTR_USERTAG:
                                        edg_wll_add_tagged_string_to_XMLBody(&pomValue, event_conditions[row][i].value.c, "usertag", event_conditions[row][i].attr_id.tag, "name", NULL);
                                        break;
+                               case EDG_WLL_QUERY_ATTR_JDL_ATTR:
+                                       edg_wll_add_tagged_string_to_XMLBody(&pomValue, event_conditions[row][i].value.c, "jdl", event_conditions[row][i].attr_id.tag, "name", NULL);
+                                       break;
                                default:
                                        free(pomValue);
                                        return -1;
index 758789c..a0d74f0 100644 (file)
@@ -188,7 +188,8 @@ ifeq ($(GLITE_LB_SERVER_WITH_WS),yes)
                ${LB_COMMON_LIB} \
                ${LB_UTILS_DB_LIB} \
                ${GSOAP_LIB} \
-               ${EXT_LIBS}
+               ${EXT_LIBS} \
+               ${classadslib}
 else
        BKSERVER_OBJS:= ${BKSERVER_BASE_OBJS}
                
@@ -197,7 +198,8 @@ else
                ${LB_COMMON_LIB} \
                ${LB_UTILS_DB_LIB} \
                -lglite_security_gss_${nothrflavour} \
-               ${EXT_LIBS}
+               ${EXT_LIBS} \
+               ${classadslib}
 endif
 
 INDEX_OBJS:= index.o index_parse.o jobstat_supp.o openserver.o \
@@ -314,7 +316,7 @@ query_events_objs := test_query_events.o query.o get_events.o jobstat_supp.o ind
 
 test_query_events: ${query_events_objs}
        ${LINKXX} -o $@ ${query_events_objs} \
-       ${TEST_LIBS} ${LB_COMMON_LIB}
+       ${TEST_LIBS} ${LB_COMMON_LIB} ${classadslib}
 #      ${TEST_LIBS} ${COMMON_LIBS} ${EXT_LIBS}
 
 test.soapconv: test_soap_conv
index e918aca..b92f57d 100644 (file)
@@ -144,6 +144,8 @@ int edg_wll_CmpColumn(const edg_wll_QueryRec *r1,const edg_wll_QueryRec *r2)
        switch (r1->attr) {
                case EDG_WLL_QUERY_ATTR_USERTAG:
                        return strcasecmp(r1->attr_id.tag,r2->attr_id.tag);
+               case EDG_WLL_QUERY_ATTR_JDL_ATTR:
+                       return strcasecmp(r1->attr_id.tag,r2->attr_id.tag);
                case EDG_WLL_QUERY_ATTR_TIME:
                        return r1->attr_id.state != r2->attr_id.state;
                default:
@@ -352,9 +354,10 @@ edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context ctx,
                        case EDG_WLL_QUERY_ATTR_LASTUPDATETIME:
                                glite_lbu_TimeToDB(stat->lastUpdateTime.tv_sec, &data);
                                break;
-                       case EDG_WLL_QUERY_ATTR_JDL_ATTR: // XXX: It's not clear how this is supposed to work
+                       case EDG_WLL_QUERY_ATTR_JDL_ATTR: // This is not the correct way to handle jdl searches.
+                                /* There's no way to index individual JDL attributes */
                                if (stat->jdl)
-                                       trio_asprintf(&data, "'%|Ss'", stat->destination);
+                                       trio_asprintf(&data, "'%|Ss'", stat->jdl);
                                else data = strdup("''");
                                break;
 /*                     case EDG_WLL_QUERY_ATTR_STATEENTERTIME: /// XXX: Which way of handling this is correct?
index 74e4548..3d1db75 100644 (file)
@@ -121,6 +121,11 @@ static void startJobQueryRec(void *data, const char *el, const char **attr)
                                         if (attr[0] && strcmp(attr[0],"state")) { unexp() break;}
                                        XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.state = edg_wll_StringToStat(attr[1]);
                                }
+                               if ( (i+1) == EDG_WLL_QUERY_ATTR_JDL_ATTR) {
+                                       if (!attr[0] || !attr[1]) { unexp() break;}
+                                       if (strcmp(attr[0],"name")) { unexp() break;}
+                                       XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.tag = strdup(attr[1]);
+                               } 
                                XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr = i+1;
                        }               
                        break;
@@ -633,6 +638,7 @@ static void endQueryEventsRequest(void *data, const char *el UNUSED_VAR)
                                case EDG_WLL_QUERY_ATTR_LOCATION:
                                case EDG_WLL_QUERY_ATTR_DESTINATION:
                                case EDG_WLL_QUERY_ATTR_USERTAG:
+                               case EDG_WLL_QUERY_ATTR_JDL_ATTR:
                                        XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.c = 
                                                edg_wll_from_string_to_string(XMLCtx);
                                        break;
@@ -709,6 +715,7 @@ static void endQueryEventsRequest(void *data, const char *el UNUSED_VAR)
                                case EDG_WLL_QUERY_ATTR_HOST:
                                case EDG_WLL_QUERY_ATTR_INSTANCE:
                                case EDG_WLL_QUERY_ATTR_USERTAG:
+                               case EDG_WLL_QUERY_ATTR_JDL_ATTR:
                                        XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].value.c =
                                                edg_wll_from_string_to_string(XMLCtx);
                                        break;
@@ -1932,6 +1939,11 @@ int edg_wll_IndexedAttrsToXML(
                                                ctx->job_index[i][j].attr_id.tag,
                                                "name", NULL);
 
+                               if (ctx->job_index[i][j].attr == EDG_WLL_QUERY_ATTR_JDL_ATTR)
+                                        edg_wll_add_string_to_XMLBody(&pomA,
+                                               ctx->job_index[i][j].attr_id.tag,
+                                               "name", NULL);
+
                                asprintf(&pomB, "%s\t\t%s\r\n",pomA,"</QueryRec>");
                                free(pomA);
                                pomA = pomB;
index 0c9f5be..a71bb4e 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <expat.h>
 
+#include <cclassad.h>
+
 #include "glite/jobid/strmd5.h"
 #include "glite/lbu/trio.h"
 
@@ -27,6 +29,7 @@
 #define FL_SEL_TAGS                    (1<<1)
 #define FL_SEL_JOB                     (1<<2)
 #define FL_FILTER                      (1<<3)  // DB query result needs further filtering
+#define FL_SEL_JDL                     (1<<4)  // Retrieve classads while filtering
 
 
 static int check_event_query_index(edg_wll_Context,const edg_wll_QueryRec **,const edg_wll_QueryRec **);
@@ -415,8 +418,9 @@ int edg_wll_QueryJobsServer(
                        }
                        
                        // if some condition hits unindexed column or states of matching jobs wanted
+
                        if ((where_flags & FL_FILTER) || !(flags & EDG_WLL_STAT_NO_STATES)) {
-                               if ( edg_wll_JobStatus(ctx, jobs_out[i], flags, &states_out[i]) )
+                               if ( edg_wll_JobStatus(ctx, jobs_out[i], (where_flags & FL_SEL_JDL)?(flags|EDG_WLL_STAT_CLASSADS):flags, &states_out[i]) )
                                {
                                        edg_wlc_JobIdFree(jobs_out[i]);
                                        if (edg_wll_Error(ctx,NULL,NULL) == EPERM) eperm = 1;
@@ -1118,7 +1122,7 @@ static char *jc_to_head_where(
                        if (   !is_indexed(&(jc[m][n]), ctx)
                                || !(cname = edg_wll_QueryRecToColumn(&(jc[m][n]))) )
                        {
-                               *where_flags |= FL_FILTER;
+                               *where_flags |= FL_FILTER | FL_SEL_JDL;
                                break;
                        }
 
@@ -1484,11 +1488,27 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll
                                }
                                break;
                        case EDG_WLL_QUERY_ATTR_JDL_ATTR:
-                               if ( stat->destination )
-                               {
-                                       if ( !strcmp(conds[i][j].value.c, stat->jdl) ) { // XXX: actually interested in one attribute only.
-                                               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 (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;
+
+                                       ad = cclassad_create(stat->jdl);
+                                       if (ad) {
+                                               if (!cclassad_evaluate_to_string(ad, conds[i][j].attr_id.tag, &extr_val)) // Extract attribute value
+                                                       extr_val = NULL;
+                                               cclassad_delete(ad);
+                                       }
+                                       if (extr_val) {
+
+                                               if ( !strcmp(conds[i][j].value.c, extr_val) ) {
+                                                       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;
+                                               }
+                                       }
                                }
                                break;
                        case EDG_WLL_QUERY_ATTR_STATEENTERTIME: