Implementing classad parsing feature (the edg_wll_JDLField() function, the jdl_classa...
authorZdeněk Šustr <sustr4@cesnet.cz>
Tue, 14 Oct 2008 19:53:13 +0000 (19:53 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Tue, 14 Oct 2008 19:53:13 +0000 (19:53 +0000)
Functions parse_fields() and print_fields() in notify_supp.cpp affected and not fixed yet.

15 files changed:
org.glite.lb.client/interface/JobStatus.h.T
org.glite.lb.client/src/StatusAttrNames.pl
org.glite.lb.client/src/notification.c
org.glite.lb.client/src/notify.c
org.glite.lb.client/src/notify_supp.cpp
org.glite.lb.client/src/notify_supp.h
org.glite.lb.common/Makefile
org.glite.lb.common/interface/jobstat.h.T
org.glite.lb.common/interface/xml_conversions.h
org.glite.lb.common/src/status.c.T
org.glite.lb.common/src/xml_conversions.c
org.glite.lb.server/src/query.c
org.glite.lb.state-machine/src/process_event.c
org.glite.lb.types/status.T
org.glite.lb.types/types.T

index 49a263b..b8103f9 100644 (file)
@@ -118,7 +118,8 @@ public:
                        INTLIST_T, /**< List of integer values. */
                        STRLIST_T, /**< List of string values. */
                        TAGLIST_T, /**< List of user tags. */
-                       STSLIST_T  /**< List of states. */
+                       STSLIST_T,  /**< List of states. */
+                       CCLASSAD_T /**< Unparsed classad */
        };
   
        /** Numeric status code. 
index 1c7f01b..3fe6acc 100644 (file)
@@ -72,4 +72,5 @@
        USER_FQANS
        SANDBOX_RETRIEVED
        JW_STATUS
+       JDL_CLASSAD
 /;
index e497381..c9e2c75 100644 (file)
@@ -884,7 +884,7 @@ select:
                edg_wll_SetError(ctx, EINVAL, "glite_lbu_UnescapeXML()");
                goto err;
        }
-               
+       
        /* fill in return values
         */
        if ( edg_wll_ParseJobStat(ctx, jobstat_char, 
index 84b8ea5..2d7e589 100644 (file)
@@ -272,7 +272,9 @@ int main(int argc,char **argv)
                                        - time(NULL);
                        if (tout.tv_sec < 0) tout.tv_sec = 0;
                        tout.tv_usec = 0;
-                       
+
+                       edg_wll_FreeStatus(&stat);
+               
                        if ( (err = edg_wll_NotifReceive(ctx, sock, &tout, &stat, &recv_nid)) ) {
                                edg_wll_NotifIdFree(recv_nid);
                                recv_nid = NULL; 
@@ -280,7 +282,7 @@ int main(int argc,char **argv)
                                if (err != ETIMEDOUT) goto receive_err;
                        }
                        else print_fields(fields,recv_nid,&stat);
-                       
+
                        if ((now = time(NULL)) >= client_tout) return 0;
 
                        if (refresh && now >= do_refresh) {
index 1db10c6..52ed7a8 100644 (file)
@@ -2,6 +2,7 @@
 #include <string.h>
 #include <iostream>
 #include <vector>
+//#include <classad.h>
 
 #include "glite/lb/LoggingExceptions.h"
 #include "JobStatus.h"
 
 using namespace glite::lb;
 
+typedef std::pair<JobStatus::Attr,std::string> FieldPair;
+
 char * parse_fields(const char *arg,void **out)
 {
        char    *aux = strdup(arg),*p;
-       std::vector<JobStatus::Attr>    *fields = new std::vector<JobStatus::Attr>;
+       std::vector<FieldPair>  *fields = new std::vector<FieldPair>;
 
        for (p = strtok(aux,","); p; p = strtok(NULL,",")) {
-               try { fields->push_back(JobStatus::attrByName(p)); }
-               catch (std::runtime_error &e) { delete fields; return p; };
+               /*special treatment for JDL (and possibly other) two-valued fields with ':' used as a separator  */
+               if (strncasecmp("jdl:", p, 4)) {
+                       try { fields->push_back(std::make_pair(JobStatus::attrByName(p), "")); }
+                       catch (std::runtime_error &e) { delete fields; return p; };
+               }
+               else {
+                       try { fields->push_back(std::make_pair(JobStatus::attrByName("jdl"), p + 4)); }
+                       catch (std::runtime_error &e) { delete fields; return p; };
+               }
        }
        
        *out = (void *) fields;
@@ -57,32 +67,46 @@ void dump_fields(void)
 
 extern "C" { char * TimeToStr(time_t); }
 
-void print_fields(void **ff,const edg_wll_NotifId n,edg_wll_JobStat const *s)
+void print_fields(void **ff,const edg_wll_NotifId n,edg_wll_JobStat *s)
 {
-       std::vector<JobStatus::Attr>    *fields = (std::vector<JobStatus::Attr> *) ff;
+       std::vector<FieldPair>  *fields = (std::vector<FieldPair> *) ff;
        JobStatus       stat(*s,0);
        attrs_t         attrs = stat.getAttrs();
        attrs_t::iterator a;
+       std::vector<FieldPair>::iterator f;
+       std::string val;
+       struct timeval t;
+       JobStatus::Attr attr;
 
        std::cout << glite_jobid_unparse(s->jobId) << '\t' << stat.name() << '\t';
 
-       for (std::vector<JobStatus::Attr>::iterator f = fields->begin(); f != fields->end(); f++) {
-               for (a = attrs.begin(); a != attrs.end() && a->first != *f; a++);
-               if (a != attrs.end() ) switch (a->second) {
-                       case JobStatus::INT_T:
-                               std::cout << stat.getValInt(a->first) << '\t';
-                               break;
-                       case JobStatus::STRING_T: {
-                               std::string val = stat.getValString(a->first);
-                               std::cout << (val.empty() ? "(null)" : escape(val)) << '\t';
-                               } break;
-                       case JobStatus::TIMEVAL_T: {
-                               struct timeval t = stat.getValTime(a->first);
-                               std::cout << TimeToStr(t.tv_sec) << '\t';
-                               } break;
-                       default:
-                               std::cout << "(unsupported)";
-                               break;
+       for (f = fields->begin(); f != fields->end(); f++) {
+               for (a = attrs.begin(); a != attrs.end() && a->first != f->first; a++);
+               if (a != attrs.end() ) {
+                       attr = (a->first);
+                       switch (a->second) {
+                               case (JobStatus::INT_T):
+                                       std::cout << stat.getValInt(attr) << '\t';
+                                       break;
+                               case (JobStatus::STRING_T):
+                                       val = stat.getValString(attr);
+                                       if (attr != JobStatus::JDL) {
+                                               std::cout << (val.empty() ? "(null)" : escape(val)) << '\t'; 
+                                       }
+                                       else {
+//                                             printf("\n1: %d\n2: %d\n", f->first, f->second); 
+                                               //XXX: Treat JDL
+                                       //      printf("\n\nJDL: %s\n\n", (*f).second);
+                                       }
+                                       break;
+                               case (JobStatus::TIMEVAL_T): 
+                                       t = stat.getValTime(attr);
+                                       std::cout << TimeToStr(t.tv_sec) << '\t'; 
+                                       break;
+                               default:
+                                       std::cout << "(unsupported)";
+                                       break;
+                       }
                }
        }
        std::cout << std::endl;
index acb5322..81daf50 100644 (file)
@@ -3,7 +3,7 @@ extern "C" {
 #endif
 
 char * parse_fields(const char *,void **);
-void print_fields(void **,const edg_wll_NotifId,edg_wll_JobStat const *);
+void print_fields(void **,const edg_wll_NotifId,edg_wll_JobStat *);
 void dump_fields(void);
 
 
index 879d004..3f3a4e9 100644 (file)
@@ -2,6 +2,7 @@
 top_srcdir=.
 stagedir=.
 globalprefix=glite
+classads_prefix=/opt/classads
 lbprefix=lb
 package=glite-lb-common
 version=0.0.0
@@ -43,10 +44,11 @@ CFLAGS:=${DEBUG} -I${top_srcdir}/src -I${top_srcdir}/interface \
        -I${top_srcdir}/test \
        -I${stagedir}/include \
        -I${expat_prefix}/include \
+       -I${classads_prefix}/include \
        ${COVERAGE_FLAGS} \
        -D_GNU_SOURCE \
        -DDATAGRID_EXTENSION ${LB_STANDALONE_FLAGS} \
-       -DBUILDING_LB_COMMON
+       -DBUILDING_LB_COMMON 
 
 ifneq (${expat_prefix},/usr)
        EXPAT_LIBS:=-L${expat_prefix}/lib
@@ -59,11 +61,16 @@ ifeq (${host_cpu},x86_64)
     archlib:=lib64
 endif
 
+ifneq (${classads_prefix},/usr)
+        classadslib := -L${classads_prefix}/${archlib} -lclassad
+endif
+
+
 LDFLAGS:=-L${stagedir}/${archlib} -L${stagedir}/lib \
        ${COVERAGE_FLAGS}
 
-EXT_LIBS:= ${EXPAT_LIBS} ${JOBID_LIB} ${TRIO_LIB}
-EXT_THRLIBS:= ${EXPAT_LIBS} ${JOBID_LIB} ${TRIO_LIB}
+EXT_LIBS:= ${EXPAT_LIBS} ${JOBID_LIB} ${TRIO_LIB} ${classadslib}
+EXT_THRLIBS:= ${EXPAT_LIBS} ${JOBID_LIB} ${TRIO_LIB} ${classadslib}
 
 TEST_LIBS:=-L${cppunit_prefix}/lib -lcppunit
 TEST_INC:=-I${cppunit_prefix}/include
@@ -142,13 +149,13 @@ ${THRSTATICLIB}: ${THROBJS}
        ranlib $@
 
 ${LTLIB}: ${OBJS}
-       ${LINK} ${version_info} -o $@ ${LOBJS} \
+       ${LINKXX} ${version_info} -o $@ ${LOBJS} \
                -lglite_security_gss_${nothrflavour} \
                ${EXT_LIBS} \
                -lm
 
 ${THRLTLIB}: ${THROBJS}
-       ${LINK} ${version_info} -o $@ ${THRLOBJS} \
+       ${LINKXX} ${version_info} -o $@ ${THRLOBJS} \
                -lglite_security_gss_${thrflavour} \
                ${EXT_THRLIBS} \
                -lm
index 2875a91..344f3f9 100644 (file)
@@ -194,6 +194,11 @@ extern enum edg_wll_StatJw_status edg_wll_StringToJWStat(const char *);
  */
 extern char *edg_wll_JWStatToString(enum edg_wll_StatJw_status);
 
+/** 
+ * Extract a variable from the JDL attribute 
+ */
+extern char *edg_wll_JDLField(edg_wll_JobStat *stat, const char *field_name);
+
 /*@}*/
 
 /*
index 783587f..6517d6b 100644 (file)
@@ -121,6 +121,7 @@ void edg_wll_add_intlist_to_XMLBody(char **body, const int *toAdd, const char *t
 void edg_wll_add_strlist_to_XMLBody(char **body, char * const *toAdd, const char *tag, const char *subTag, const char *indent, const  char *null);
 void edg_wll_add_taglist_to_XMLBody(char **body,  const edg_wll_TagValue *toAdd, const char *tag,  const char *subTag, const char *indent, const char *subTag2, const  char *null);
 void edg_wll_add_time_t_list_to_XMLBody(char **body, const time_t *toAdd, const char *tag, char *(*indexToTag)(), const char *indent, const int from, const int to);
+void edg_wll_add_cclassad_to_XMLBody(char **body, void *toAdd, const char *tag, const char *null);
 char *edg_wll_from_string_to_string(edg_wll_XML_ctx *XMLCtx);
 edg_wlc_JobId edg_wll_from_string_to_jobid(edg_wll_XML_ctx *XMLCtx);
 edg_wll_NotifId edg_wll_from_string_to_notifid(edg_wll_XML_ctx *XMLCtx);
index 4f94b1a..f9358f2 100644 (file)
@@ -3,6 +3,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <cclassad.h>
+
 #include "jobstat.h"
 
 static const struct timeval null_timeval = {0,0};
@@ -50,10 +52,11 @@ void edg_wll_FreeStatus(edg_wll_JobStat *stat)
                        gen "\t\tfree(stat->$_);\n";
                        gen "\t}\n";
                 }
-
+                if ($ft eq 'cclassad') {
+                        gen "\tif (stat->$_ != NULL )   { \tcclassad_delete(stat->$_); stat->$_=NULL; }\n";
+                }
         }
 @@@}
-    
   }
 }
 
@@ -201,4 +204,20 @@ char *edg_wll_JWStatToString(enum edg_wll_StatJw_status statCode)
         return strdup(jw_statNames[statCode]);
 }
 
+char *edg_wll_JDLField(edg_wll_JobStat *stat, const char *field_name)
+{
+       char *extr_val;
+
+       if (stat->jdl_classad == NULL) { //classad had not been unparsed yet
+
+               stat->jdl_classad = (struct classad*)cclassad_create(stat->jdl);
+       }
+
+       if (cclassad_evaluate_to_string(stat->jdl_classad, field_name, &extr_val)) {
+               return extr_val;
+       }
+       else 
+               return NULL;
+}
+
 
index 36c2d22..7d75088 100644 (file)
@@ -524,6 +524,9 @@ void edg_wll_add_time_t_list_to_XMLBody(char **body, const time_t *toAdd, const
         *body = newBody;
 }
 
+void edg_wll_add_cclassad_to_XMLBody(char **body, void *toAdd, const char *tag, const char *null) {
+       //dummy function. This conversion will never be done.
+}
 
 // void edg_wll_add_stslist_to_XMLBody(char **body, const edg_wll_JobStat *toAdd, const char *tag, const char *UNUSED_subTag, const int null)
 // in lbserver/lb_xml_parse.c.T
@@ -708,6 +711,11 @@ edg_wll_Source edg_wll_from_string_to_logsrc(edg_wll_XML_ctx *XMLCtx)
        return(out);
 }
 
+void *edg_wll_from_string_to_cclassad(edg_wll_XML_ctx *XMLCtx)
+{
+       //This conversion will never be done
+       return (NULL);
+}
 
 
 /************************************************************************/
index d4f3a54..fb9deb7 100644 (file)
@@ -1702,7 +1702,7 @@ int check_strict_jobid(edg_wll_Context ctx, glite_jobid_const_t job)
                char    *jobid,msg[300];
 
                jobid = edg_wlc_JobIdUnparse(job);
-               snprintf(msg,sizeof msg,"%s: does not match server address",jobid);
+               snprintf(msg,sizeof msg,"%s: does not match server address (%s:%d)",jobid,ctx->srvName,ctx->srvPort);
                msg[sizeof msg - 1] = 0;
                edg_wll_SetError(ctx,EINVAL,msg);
                free(jobid);
index 333a9d1..70b39c3 100644 (file)
@@ -7,6 +7,7 @@
 #include <errno.h>
 #include <assert.h>
 #include <syslog.h>
+#include <cclassad.h> 
 
 #include "glite/lb/context-int.h"
 
index ecd12dc..f43db3b 100644 (file)
@@ -96,6 +96,7 @@ int   jw_status               Status of Job wrapper
        _code_  WRAPPER_RUNNING Wrapper started
        _code_  PAYLOAD_RUNNING Payload running
        _code_  DONE            JW finished
+cclassad       jdl_classad     Unparsed JDL classad
 
 _pad_  55
 
index 23a972f..fee3817 100644 (file)
@@ -15,6 +15,7 @@
                int=>'"int"',
                float=>'"float"',
                double=>'"double"',
+               cclassad=>'"void *"',
        },
        'C++'=>{
                string=>'"std::string"',
@@ -30,6 +31,7 @@
                int=>'"int"',
                float=>'"float"',
                double=>'"double"',
+               cclassad=>'"void *"',
        },
        'wsdl'=>{
                bool=>'"xsd:boolean"',
@@ -48,6 +50,7 @@
                intlist=>'"intSequenceType"',
                stslist=>'"statusSequenceType"',
                taglist=>'"tagSequenceType"',
+               cclassad=>'"xsd:string"',
        },
        'java'=>{
                bool=>'"bool"',
@@ -84,6 +87,8 @@
                notifid=>'qq{$dst = edg_wll_NotifIdUnparse($src);}',
 #              level=>'qq{$dst = edg_wll_LevelToString($src);}',
                logsrc=>'qq{$dst = edg_wll_SourceToString($src);}',
+               logsrc=>'qq{$dst = edg_wll_StringToSource($src);}',
+               cclassad=>'qq{$dst = NULL;}',
 #      strlist, intlist, stslist are used only in consumer API, they don't need toString method
        }
 );
        intlist=>'NULL',
        taglist=>'NULL',
        stslist=>'NULL',
+       cclassad=>'NULL',
 );
 
 %compare = (
                        else { qq{(($a) == NULL && ($b) == NULL) || (($a)&&($b)&& !strcmp(edg_wll_NotifIdUnparse($a),edg_wll_NotifIdUnparse($b)))}; }',
                logsrc=>'"($a) == ($b)"',
                timeval=>'"($a).tv_sec == ($b).tv_sec && ($a).tv_usec == ($b).tv_usec"',
+               cclassad=>'"($a == $b)"',
        }
 );