From: Michal Voců Date: Thu, 8 Dec 2011 16:24:55 +0000 (+0000) Subject: added resource list type X-Git-Tag: merge_torque_to_head_src~7 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=1c3d6994f6732b10a8a41206e0534666971c10e6;p=jra1mw.git added resource list type --- diff --git a/org.glite.lb.client/examples/job_status.c b/org.glite.lb.client/examples/job_status.c index f07fcf6..a9ddd3b 100644 --- a/org.glite.lb.client/examples/job_status.c +++ b/org.glite.lb.client/examples/job_status.c @@ -343,7 +343,7 @@ static void printstat(edg_wll_JobStat stat, int level) printf("%spbs_dest_host : %s\n", ind, stat.pbs_dest_host); printf("%spbs_pid : %d\n", ind, stat.pbs_pid); printf("%spbs_resource_usage : %s%s\n", ind, - (stat.pbs_resource_usage) ? "\n" : "", stat.pbs_resource_usage); + (stat.pbs_resource_usage) ? "\n" : "", edg_wll_TagListToString(stat.pbs_resource_usage)); printf("%spbs_exit_status : %d\n", ind, stat.pbs_exit_status); printf("%spbs_error_desc : %s%s\n", ind, (stat.pbs_error_desc) ? "\n" : "", stat.pbs_error_desc); diff --git a/org.glite.lb.client/interface/Event.h.T b/org.glite.lb.client/interface/Event.h.T index 1a198b6..1aa05b3 100644 --- a/org.glite.lb.client/interface/Event.h.T +++ b/org.glite.lb.client/interface/Event.h.T @@ -181,6 +181,7 @@ public: NOTIFID_T, /**< NotifId value. */ FLOAT_T, /**< Float value. */ DOUBLE_T, /**< Double value. */ + TAGLIST_T, /**< List of user tags (name = value pairs). */ }; Type type; /**< Type of the event as defined by Type. */ diff --git a/org.glite.lb.client/src/EventAttrNames.pl b/org.glite.lb.client/src/EventAttrNames.pl index 89a89ac..9b24a03 100644 --- a/org.glite.lb.client/src/EventAttrNames.pl +++ b/org.glite.lb.client/src/EventAttrNames.pl @@ -119,4 +119,5 @@ OLDSUBSTATE NEWSTATE NEWSUBSTATE + RESOURCES /; diff --git a/org.glite.lb.client/src/args.c.T b/org.glite.lb.client/src/args.c.T index 88eddcf..df5af9e 100644 --- a/org.glite.lb.client/src/args.c.T +++ b/org.glite.lb.client/src/args.c.T @@ -333,6 +333,18 @@ static void read_jobid(const edg_wll_Args* o, char* arg, char* par) else glite_jobid_free(jobid); } +static void read_taglist(const edg_wll_Args* o, char* arg, char* par) +{ + edg_wll_TagValue *list = NULL; + + if(edg_wll_TagListParse(par, &list) != 0) { + fprintf(stderr, "ERROR %s can't parse %s: %s\n", arg, par, strerror(errno)); + exit(1); + } + if(o->value) *(edg_wll_TagValue **)o->value = list; + else /* FIXME: free it properly */ free(list); +} + static void show_help(const edg_wll_Args* o, int prefix) { unsigned max = 0; @@ -557,6 +569,9 @@ static int findOpt(opt_ctx_t* ctx, int olong) case EDG_WLL_ARGS_JOBID: read_jobid(o, arg, par); break; + case EDG_WLL_ARGS_TAGLIST: + read_taglist(o, arg, par); + break; default: printf("FIXME: unhandle option type %d\n", o->type); break; diff --git a/org.glite.lb.client/src/args.h b/org.glite.lb.client/src/args.h index 4e894b1..1118239 100644 --- a/org.glite.lb.client/src/args.h +++ b/org.glite.lb.client/src/args.h @@ -34,6 +34,7 @@ typedef enum { EDG_WLL_ARGS_SUBOPTIONS, EDG_WLL_ARGS_SELECTSTRING, EDG_WLL_ARGS_TIMEVAL, + EDG_WLL_ARGS_TAGLIST, } edg_wll_ArgsCode; typedef struct { diff --git a/org.glite.lb.client/src/logevent.c.T b/org.glite.lb.client/src/logevent.c.T index ed7c22c..2cf2a47 100644 --- a/org.glite.lb.client/src/logevent.c.T +++ b/org.glite.lb.client/src/logevent.c.T @@ -126,7 +126,8 @@ int main(int argc, char *argv[]) "edg_wll_NotifId", "EDG_WLL_ARGS_NOTIFID", "edg_wll_Source", "EDG_WLL_ARGS_SOURCE", "uint16_t", "EDG_WLL_ARGS_UINT16", - "struct timeval", "EDG_WLL_ARGS_TIMEVAL" + "struct timeval", "EDG_WLL_ARGS_TIMEVAL", + "edg_wll_TagValue *", "EDG_WLL_ARGS_TAGLIST", ); my %vars = (); for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } diff --git a/org.glite.lb.common/interface/events.h.T b/org.glite.lb.common/interface/events.h.T index dc94115..315f735 100644 --- a/org.glite.lb.common/interface/events.h.T +++ b/org.glite.lb.common/interface/events.h.T @@ -33,6 +33,8 @@ limitations under the License. #include #include "glite/jobid/cjobid.h" +#include "glite/lb/lb_types.h" + #ifdef BUILDING_LB_COMMON #include "context.h" @@ -118,6 +120,15 @@ extern char *edg_wll_EventToString(edg_wll_EventCode event); /** + * Free allocated edg_wll_TagValue * list + * \param list IN: list to free + */ +extern void edg_wll_FreeTagList( + edg_wll_TagValue *list +); + + +/** * \typedef edg_wll_KeyNameCode * Predefined ULM key types */ diff --git a/org.glite.lb.common/interface/events_parse.h b/org.glite.lb.common/interface/events_parse.h index 0f31cbb..b8b7139 100644 --- a/org.glite.lb.common/interface/events_parse.h +++ b/org.glite.lb.common/interface/events_parse.h @@ -110,6 +110,7 @@ extern edg_wll_LogLine edg_wll_UnparseNotifEvent( edg_wll_Event * event ); + #ifdef __cplusplus } #endif diff --git a/org.glite.lb.common/interface/jobstat.h.T b/org.glite.lb.common/interface/jobstat.h.T index c870a84..de517a2 100644 --- a/org.glite.lb.common/interface/jobstat.h.T +++ b/org.glite.lb.common/interface/jobstat.h.T @@ -32,6 +32,7 @@ limitations under the License. #include #include "glite/jobid/cjobid.h" +#include "glite/lb/lb_types.h" #ifdef __cplusplus extern "C" { @@ -95,15 +96,6 @@ typedef enum _edg_wll_JobStatCode { EDG_WLL_NUMBER_OF_STATCODES /**< Number of meaningful status codes */ } edg_wll_JobStatCode; -/*! - * - * Pair tag = value. - */ -typedef struct _edg_wll_TagValue { - char * tag; /**< User-specified information tag */ - char * value; /**< Value assigned to user-specified information tag */ -} edg_wll_TagValue; - /*! * diff --git a/org.glite.lb.common/interface/xml_conversions.h b/org.glite.lb.common/interface/xml_conversions.h index f07cf0b..3e88a53 100644 --- a/org.glite.lb.common/interface/xml_conversions.h +++ b/org.glite.lb.common/interface/xml_conversions.h @@ -138,7 +138,8 @@ void edg_wll_add_uint16_t_to_XMLBody(char **body, const uint16_t toAdd, const ch void edg_wll_add_logsrc_to_XMLBody(char **body, const edg_wll_Source toAdd, const char *tag, const edg_wll_Source null); void edg_wll_add_intlist_to_XMLBody(char **body, const int *toAdd, const char *tag, char *(*indexToTag)(), const char *indent, const int from, const int to); 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_taglist_to_XMLBody(char **body, const edg_wll_TagValue *toAdd, const char *tag, const edg_wll_TagValue *null); +void edg_wll_add_usertag_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); diff --git a/org.glite.lb.common/src/events.c.T b/org.glite.lb.common/src/events.c.T index 5173199..002c2c8 100644 --- a/org.glite.lb.common/src/events.c.T +++ b/org.glite.lb.common/src/events.c.T @@ -66,6 +66,37 @@ for my $e (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } "SysClStat", }; +/* Free the tags and values from list */ +void edg_wll_FreeTagList(edg_wll_TagValue *list) { + edg_wll_TagValue *tag; + + if(NULL == list) return; + + for(tag = list; tag->tag; tag++) { + free(tag->tag); + if(tag->value) free(tag->value); + } +} + +/* Deep copy the tag list */ +edg_wll_TagValue *edg_wll_CopyTagList(edg_wll_TagValue *src) { + edg_wll_TagValue *dst, *tag, *dtag; + int count; + + if(NULL == src) return NULL; + + for(tag = src, count = 0; tag->tag; tag++, count++); + + dst = (edg_wll_TagValue*)calloc(count + 1, sizeof(edg_wll_TagValue)); + for(tag = src, dtag = dst; tag->tag; tag++, dtag++) { + dtag->tag = strdup(tag->tag); + dtag->value = strdup(tag->value); + } + + return dst; +} + + /** * \fn edg_wll_EventCode edg_wll_StringToEvent(const char *name) * \param name a string event name (e.g. "JobTransfer") @@ -392,6 +423,9 @@ for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } if ($ft eq 'notifid') { gen $indent."\tif (event->$tl.$fn) edg_wll_NotifIdFree(event->$tl.$fn);\n" } + if ($ft eq 'taglist') { + gen $intent."\tif (event->$tl.$fn) { edg_wll_FreeTagList(event->$tl.$fn); free(event->$tl.$fn); }\n" + } } gen $indent.$indent."break;\n" } diff --git a/org.glite.lb.common/src/events_parse.c.T b/org.glite.lb.common/src/events_parse.c.T index 438c769..93dea0f 100644 --- a/org.glite.lb.common/src/events_parse.c.T +++ b/org.glite.lb.common/src/events_parse.c.T @@ -39,8 +39,80 @@ static const struct timeval null_timeval = {0,0}; /* -- Internal function prototype -- */ char *my_edg_wll_ULMGetValueAt( p_edg_wll_ULMFields, int ); +/* Function for parsing name=value tag lists */ +int edg_wll_TagListParse(const char *src, edg_wll_TagValue **list) { + int n = 0; + char *p; + edg_wll_TagValue *tag; + + if(NULL == src) + return -1; + + /* count tag=value pairs */ + for(p = (char*)src; *p; p++) { + if(',' == *p) n++; /* counts empty tokens as well... */ + } + /* one more for last empty struct */ + n += 2; + + *list = (edg_wll_TagValue*)malloc(n*sizeof(edg_wll_TagValue)); + if(NULL == *list) + return -1; + + for(p = strtok(src, ","), tag = *list; p; p = strtok(NULL, ","), tag++) { + char *s = strchr(p, '='); + + if(NULL == s || '\0' == *(s+1)) + continue; + + *s = 0; + tag->tag = strdup(p); + *s = '='; + tag->value = strdup(s+1); + } + tag->tag = NULL; + tag->value = NULL; + + return 0; +} + + +/* Function for stringifying name=value tag lists */ +char * edg_wll_TagListToString(edg_wll_TagValue *list) { + int len = 0; + edg_wll_TagValue *tag; + char *out, *p; + + if(NULL == list) return NULL; + + for(tag = list; tag->tag; tag++) { + len += strlen(tag->tag); + len += strlen(tag->value); + len++; + } + + out = malloc(len*sizeof(char)); + if(NULL == out) return NULL; + + *out = '\0'; + p = out; + for(tag = list; tag->tag; tag++) { + if(p != out) { + strcat(p++, ","); + } + strcat(p, tag->tag); + p += strlen(tag->tag); + strcat(p++, "="); + strcat(p, tag->value); + p += strlen(tag->value); + } + + return out; +} + + /** - * edg_wll_ParseEvent - parse ULM message to internal structures + * Edg_wll_ParseEvent - parse ULM message to internal structures * Calls: calloc, free, sprintf, strdup * edg_wll_ULMNewParseTable, edg_wll_ULMFreeParseTable, edg_wll_ULMProcessParseTable, * edg_wll_ULMGetNameAt, my_edg_wll_ULMGetValueAt, edg_wll_ULMDateToTimeval (edg_wll_ULMDateToDouble), @@ -304,7 +376,8 @@ for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } gen "\t\t".toString $f "event->$tl.$fn", "$fn\_str"; gen "\n"; } elsif ($ULMasString{$f->{type}}) { - gen "\t\tchar \*$fn\_str = ".$f->getType()."ToString(event->$tl.$fn);\n"; + #gen "\t\tchar \*$fn\_str = ".$f->getType()."ToString(event->$tl.$fn);\n"; + gen "\t\t". $f->toString("event->$tl.$fn","char \*$fn\_str",)."\n"; $free .= "free($fn\_str); "; } } diff --git a/org.glite.lb.common/src/status.c.T b/org.glite.lb.common/src/status.c.T index 413bd5b..b17ca93 100644 --- a/org.glite.lb.common/src/status.c.T +++ b/org.glite.lb.common/src/status.c.T @@ -26,6 +26,7 @@ limitations under the License. static const struct timeval null_timeval = {0,0}; +extern void edg_wll_FreeTagList(edg_wll_TagValue *); void edg_wll_FreeStatus(edg_wll_JobStat *stat) { @@ -55,10 +56,11 @@ void edg_wll_FreeStatus(edg_wll_JobStat *stat) } if ($ft eq 'taglist') { gen "\tif (stat->$_ != NULL ) {\n"; - gen "\t\tfor (i=0; stat->$_\[i].tag; i++) {\n"; - gen "\t\t\tfree(stat->$_\[i].tag);\n"; - gen "\t\t\tfree(stat->$_\[i].value);\n"; - gen "\t\t}\n"; + #gen "\t\tfor (i=0; stat->$_\[i].tag; i++) {\n"; + #gen "\t\t\tfree(stat->$_\[i].tag);\n"; + #gen "\t\t\tfree(stat->$_\[i].value);\n"; + #gen "\t\t}\n"; + gen "\t\tedg_wll_FreeTagList(stat->$_);\n"; gen "\t\tfree(stat->$_);\n"; gen "\t}\n"; } @@ -126,17 +128,7 @@ edg_wll_JobStat *edg_wll_CpyStatus(const edg_wll_JobStat *src, edg_wll_JobStat * gen "\tdest->$_ = src->$_;\n"; } if ($ft eq 'taglist') { - gen qq{ -! if (src->$_ != NULL) \{ -! for (i=0; src->$_\[i].tag; i++); -! dest->$_ = malloc(sizeof(*src->$_)*(i+1)); -! for (i=0; src->$_\[i].tag; i++) \{ -! dest->$_\[i].tag = strdup(src->$_\[i].tag); -! dest->$_\[i].value = strdup(src->$_\[i].value); -! \} -! dest->$_\[i].tag = NULL; -! \} - }; + gen "\tdest->$_ = edg_wll_CopyTagList(src->$_);\n"; } } @@@} diff --git a/org.glite.lb.common/src/xml_conversions.c b/org.glite.lb.common/src/xml_conversions.c index 6c69c02..221cf22 100644 --- a/org.glite.lb.common/src/xml_conversions.c +++ b/org.glite.lb.common/src/xml_conversions.c @@ -28,6 +28,7 @@ limitations under the License. #include "jobstat.h" +extern char *edg_wll_TagListToString(edg_wll_TagValue *); static const struct timeval null_timeval = {0,0}; @@ -448,7 +449,17 @@ void edg_wll_add_intlist_to_XMLBody(char **body, const int *toAdd, const char *t } -void edg_wll_add_taglist_to_XMLBody(char **body, const edg_wll_TagValue *toAdd, const char *tag, const char *subTag, const char *subTag2, const char *indent, const char *null) +void edg_wll_add_taglist_to_XMLBody(char **body, const edg_wll_TagValue *toAdd, const char *tag, const edg_wll_TagValue *null) +{ + char *s_taglist; + + s_taglist = edg_wll_TagListToString(toAdd); + edg_wll_add_string_to_XMLBody(body, s_taglist, tag, NULL); + free(s_taglist); +} + + +void edg_wll_add_usertag_to_XMLBody(char **body, const edg_wll_TagValue *toAdd, const char *tag, const char *subTag, const char *subTag2, const char *indent, const char *null) { char *pomA, *pomB, *newBody; char **list = NULL; @@ -748,8 +759,14 @@ void *edg_wll_from_string_to_cclassad(edg_wll_XML_ctx *XMLCtx) edg_wll_TagValue *edg_wll_from_string_to_taglist(edg_wll_XML_ctx *XMLCtx) { - // not done yet - return(NULL); + char *s, *out = NULL; + + s = glite_lbu_UnescapeXML((const char*) XMLCtx->char_buf); + if(s) { + edg_wll_TagListParse(s, &out); + } + + return out; } /************************************************************************/ diff --git a/org.glite.lb.types/Makefile b/org.glite.lb.types/Makefile index 34b64dc..a69d827 100644 --- a/org.glite.lb.types/Makefile +++ b/org.glite.lb.types/Makefile @@ -3,10 +3,13 @@ top_srcdir=. -include Makefile.inc +globalprefix=glite +lbprefix=lb PM=StructField.pm MultiStruct.pm T=events.T status.T types.T SCRIPTS=at3 check_version.pl +HDRS=lb_types.h default: compile @@ -25,6 +28,7 @@ install: compile done install -m 755 ${top_srcdir}/at3.in ${DESTDIR}${PREFIX}${prefix}/sbin/glite-lb-at3 install -m 755 ${top_srcdir}/check_version.pl ${DESTDIR}${PREFIX}${prefix}/sbin/glite-lb-check_version.pl + (cd ${top_srcdir}/interface && install -m 644 ${HDRS} ${DESTDIR}${PREFIX}${prefix}/include/${globalprefix}/${lbprefix}) clean: rm -rvf log.xml rpmbuild/ RPMS/ tgz/ debian/ diff --git a/org.glite.lb.types/events.T b/org.glite.lb.types/events.T index 4fc010d..fc9ad19 100644 --- a/org.glite.lb.types/events.T +++ b/org.glite.lb.types/events.T @@ -326,10 +326,7 @@ int usage Type of record _code_ REQUESTED Requested value _code_ USED Consumed quantity - string resource Resource's name. - double quantity Resources's quantity (how much). - _optional_ - string unit Units (sec, kB, etc.). + taglist resources List of resources @type PBSError Any error occured string error_desc Error reason diff --git a/org.glite.lb.types/interface/lb_types.h b/org.glite.lb.types/interface/lb_types.h new file mode 100644 index 0000000..07e433b --- /dev/null +++ b/org.glite.lb.types/interface/lb_types.h @@ -0,0 +1,48 @@ +#ifndef GLITE_LB_TYPES_H +#define GLITE_LB_TYPES_H + +/** + * \file lb_types.h + * \brief L&B API common types and related definitions + */ + + +#ident "$Header$" +/* +Copyright (c) Members of the EGEE Collaboration. 2004-2010. +See http://www.eu-egee.org/partners for details on the copyright holders. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * + * Pair tag = value. + */ +typedef struct _edg_wll_TagValue { + char * tag; /**< User-specified information tag */ + char * value; /**< Value assigned to user-specified information tag */ +} edg_wll_TagValue; + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/org.glite.lb.types/status.T b/org.glite.lb.types/status.T index 21aec7b..000d0a4 100644 --- a/org.glite.lb.types/status.T +++ b/org.glite.lb.types/status.T @@ -118,9 +118,7 @@ string pbs_scheduler Name of pbs scheduler string pbs_dest_host Hostname of node where job is running int pbs_pid PID of running job taglist pbs_resource_requested Resources requested - _special_ XMLstructured taglist pbs_resource_usage Resource usage - _special_ XMLstructured int pbs_exit_status Job exit status string pbs_error_desc Glued error descriptions from error events diff --git a/org.glite.lb.types/types.T b/org.glite.lb.types/types.T index 7b727f5..eecdb3c 100644 --- a/org.glite.lb.types/types.T +++ b/org.glite.lb.types/types.T @@ -90,11 +90,13 @@ logsrc=>'qq{$dst = edg_wll_SourceToString($src);}', cclassad=>'qq{$dst = NULL;}', # strlist, intlist, stslist are used only in consumer API, they don't need toString method + taglist=>'qq{$dst = edg_wll_TagListToString($src);}', } ); %ULMasString = ( - logsrc=>1 + logsrc=>1, + taglist=>1 ); %fromString = ( @@ -111,6 +113,7 @@ # level=>'qq{$dst = edg_wll_StringToLevel($src);}', logsrc=>'qq{$dst = edg_wll_StringToSource($src);}', # strlist, intlist, stslist are used only in consumer API, they don't need fromString method + taglist=>'qq{edg_wll_TagListParse($src, &$dst);}', } ); @@ -150,6 +153,7 @@ logsrc=>'"($a) == ($b)"', timeval=>'"($a).tv_sec == ($b).tv_sec && ($a).tv_usec == ($b).tv_usec"', cclassad=>'"($a == $b)"', + taglist=>'"($a == $b)"', } ); @@ -166,5 +170,6 @@ notifid=>'"%s"', logsrc=>'"%s"', timeval=>'"%s"', + taglist=>'"%s"', } );