From 50a2e00ed4b6afb2682ec2d1c7d0b18a6818e318 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zden=C4=9Bk=20=C5=A0ustr?= Date: Tue, 14 Oct 2008 19:53:13 +0000 Subject: [PATCH] Implementing classad parsing feature (the edg_wll_JDLField() function, the jdl_classad member of the job state structure, and related modifications). Functions parse_fields() and print_fields() in notify_supp.cpp affected and not fixed yet. --- org.glite.lb.client/interface/JobStatus.h.T | 3 +- org.glite.lb.client/src/StatusAttrNames.pl | 1 + org.glite.lb.client/src/notification.c | 2 +- org.glite.lb.client/src/notify.c | 6 ++- org.glite.lb.client/src/notify_supp.cpp | 68 +++++++++++++++++-------- org.glite.lb.client/src/notify_supp.h | 2 +- org.glite.lb.common/Makefile | 17 +++++-- org.glite.lb.common/interface/jobstat.h.T | 5 ++ org.glite.lb.common/interface/xml_conversions.h | 1 + org.glite.lb.common/src/status.c.T | 23 ++++++++- org.glite.lb.common/src/xml_conversions.c | 8 +++ org.glite.lb.server/src/query.c | 2 +- org.glite.lb.state-machine/src/process_event.c | 1 + org.glite.lb.types/status.T | 1 + org.glite.lb.types/types.T | 7 +++ 15 files changed, 112 insertions(+), 35 deletions(-) diff --git a/org.glite.lb.client/interface/JobStatus.h.T b/org.glite.lb.client/interface/JobStatus.h.T index 49a263b..b8103f9 100644 --- a/org.glite.lb.client/interface/JobStatus.h.T +++ b/org.glite.lb.client/interface/JobStatus.h.T @@ -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. diff --git a/org.glite.lb.client/src/StatusAttrNames.pl b/org.glite.lb.client/src/StatusAttrNames.pl index 1c7f01b..3fe6acc 100644 --- a/org.glite.lb.client/src/StatusAttrNames.pl +++ b/org.glite.lb.client/src/StatusAttrNames.pl @@ -72,4 +72,5 @@ USER_FQANS SANDBOX_RETRIEVED JW_STATUS + JDL_CLASSAD /; diff --git a/org.glite.lb.client/src/notification.c b/org.glite.lb.client/src/notification.c index e497381..c9e2c75 100644 --- a/org.glite.lb.client/src/notification.c +++ b/org.glite.lb.client/src/notification.c @@ -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, diff --git a/org.glite.lb.client/src/notify.c b/org.glite.lb.client/src/notify.c index 84b8ea5..2d7e589 100644 --- a/org.glite.lb.client/src/notify.c +++ b/org.glite.lb.client/src/notify.c @@ -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) { diff --git a/org.glite.lb.client/src/notify_supp.cpp b/org.glite.lb.client/src/notify_supp.cpp index 1db10c6..52ed7a8 100644 --- a/org.glite.lb.client/src/notify_supp.cpp +++ b/org.glite.lb.client/src/notify_supp.cpp @@ -2,6 +2,7 @@ #include #include #include +//#include #include "glite/lb/LoggingExceptions.h" #include "JobStatus.h" @@ -11,14 +12,23 @@ using namespace glite::lb; +typedef std::pair FieldPair; + char * parse_fields(const char *arg,void **out) { char *aux = strdup(arg),*p; - std::vector *fields = new std::vector; + std::vector *fields = new std::vector; 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 *fields = (std::vector *) ff; + std::vector *fields = (std::vector *) ff; JobStatus stat(*s,0); attrs_t attrs = stat.getAttrs(); attrs_t::iterator a; + std::vector::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::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; diff --git a/org.glite.lb.client/src/notify_supp.h b/org.glite.lb.client/src/notify_supp.h index acb5322..81daf50 100644 --- a/org.glite.lb.client/src/notify_supp.h +++ b/org.glite.lb.client/src/notify_supp.h @@ -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); diff --git a/org.glite.lb.common/Makefile b/org.glite.lb.common/Makefile index 879d004..3f3a4e9 100644 --- a/org.glite.lb.common/Makefile +++ b/org.glite.lb.common/Makefile @@ -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 diff --git a/org.glite.lb.common/interface/jobstat.h.T b/org.glite.lb.common/interface/jobstat.h.T index 2875a91..344f3f9 100644 --- a/org.glite.lb.common/interface/jobstat.h.T +++ b/org.glite.lb.common/interface/jobstat.h.T @@ -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); + /*@}*/ /* diff --git a/org.glite.lb.common/interface/xml_conversions.h b/org.glite.lb.common/interface/xml_conversions.h index 783587f..6517d6b 100644 --- a/org.glite.lb.common/interface/xml_conversions.h +++ b/org.glite.lb.common/interface/xml_conversions.h @@ -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); diff --git a/org.glite.lb.common/src/status.c.T b/org.glite.lb.common/src/status.c.T index 4f94b1a..f9358f2 100644 --- a/org.glite.lb.common/src/status.c.T +++ b/org.glite.lb.common/src/status.c.T @@ -3,6 +3,8 @@ #include #include +#include + #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; +} + diff --git a/org.glite.lb.common/src/xml_conversions.c b/org.glite.lb.common/src/xml_conversions.c index 36c2d22..7d75088 100644 --- a/org.glite.lb.common/src/xml_conversions.c +++ b/org.glite.lb.common/src/xml_conversions.c @@ -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); +} /************************************************************************/ diff --git a/org.glite.lb.server/src/query.c b/org.glite.lb.server/src/query.c index d4f3a54..fb9deb7 100644 --- a/org.glite.lb.server/src/query.c +++ b/org.glite.lb.server/src/query.c @@ -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); diff --git a/org.glite.lb.state-machine/src/process_event.c b/org.glite.lb.state-machine/src/process_event.c index 333a9d1..70b39c3 100644 --- a/org.glite.lb.state-machine/src/process_event.c +++ b/org.glite.lb.state-machine/src/process_event.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "glite/lb/context-int.h" diff --git a/org.glite.lb.types/status.T b/org.glite.lb.types/status.T index ecd12dc..f43db3b 100644 --- a/org.glite.lb.types/status.T +++ b/org.glite.lb.types/status.T @@ -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 diff --git a/org.glite.lb.types/types.T b/org.glite.lb.types/types.T index 23a972f..fee3817 100644 --- a/org.glite.lb.types/types.T +++ b/org.glite.lb.types/types.T @@ -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 } ); @@ -125,6 +130,7 @@ intlist=>'NULL', taglist=>'NULL', stslist=>'NULL', + cclassad=>'NULL', ); %compare = ( @@ -143,6 +149,7 @@ 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)"', } ); -- 1.8.2.3