added resource list type
authorMichal Voců <michal@ruk.cuni.cz>
Thu, 8 Dec 2011 16:24:55 +0000 (16:24 +0000)
committerMichal Voců <michal@ruk.cuni.cz>
Thu, 8 Dec 2011 16:24:55 +0000 (16:24 +0000)
19 files changed:
org.glite.lb.client/examples/job_status.c
org.glite.lb.client/interface/Event.h.T
org.glite.lb.client/src/EventAttrNames.pl
org.glite.lb.client/src/args.c.T
org.glite.lb.client/src/args.h
org.glite.lb.client/src/logevent.c.T
org.glite.lb.common/interface/events.h.T
org.glite.lb.common/interface/events_parse.h
org.glite.lb.common/interface/jobstat.h.T
org.glite.lb.common/interface/xml_conversions.h
org.glite.lb.common/src/events.c.T
org.glite.lb.common/src/events_parse.c.T
org.glite.lb.common/src/status.c.T
org.glite.lb.common/src/xml_conversions.c
org.glite.lb.types/Makefile
org.glite.lb.types/events.T
org.glite.lb.types/interface/lb_types.h [new file with mode: 0644]
org.glite.lb.types/status.T
org.glite.lb.types/types.T

index f07fcf6..a9ddd3b 100644 (file)
@@ -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);
index 1a198b6..1aa05b3 100644 (file)
@@ -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. */
index 89a89ac..9b24a03 100644 (file)
        OLDSUBSTATE
        NEWSTATE
        NEWSUBSTATE
+       RESOURCES
 /;
index 88eddcf..df5af9e 100644 (file)
@@ -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;
index 4e894b1..1118239 100644 (file)
@@ -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 {
index ed7c22c..2cf2a47 100644 (file)
@@ -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} }
index dc94115..315f735 100644 (file)
@@ -33,6 +33,8 @@ limitations under the License.
 #include <inttypes.h>
 
 #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
  */
index 0f31cbb..b8b7139 100644 (file)
@@ -110,6 +110,7 @@ extern edg_wll_LogLine edg_wll_UnparseNotifEvent(
        edg_wll_Event * event
 );
 
+
 #ifdef __cplusplus
 }
 #endif
index c870a84..de517a2 100644 (file)
@@ -32,6 +32,7 @@ limitations under the License.
 #include <sys/time.h>
 
 #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;
-
 
 /*!
  *
index f07cf0b..3e88a53 100644 (file)
@@ -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);
index 5173199..002c2c8 100644 (file)
@@ -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"
 }
index 438c769..93dea0f 100644 (file)
@@ -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); ";
                }
        }
index 413bd5b..b17ca93 100644 (file)
@@ -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";
                        }
                }
 @@@}
index 6c69c02..221cf22 100644 (file)
@@ -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;
 }
 
 /************************************************************************/
index 34b64dc..a69d827 100644 (file)
@@ -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/
index 4fc010d..fc9ad19 100644 (file)
        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 (file)
index 0000000..07e433b
--- /dev/null
@@ -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
index 21aec7b..000d0a4 100644 (file)
@@ -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
 
index 7b727f5..eecdb3c 100644 (file)
                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 = (
 #              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);}',
        }
 );
 
                logsrc=>'"($a) == ($b)"',
                timeval=>'"($a).tv_sec == ($b).tv_sec && ($a).tv_usec == ($b).tv_usec"',
                cclassad=>'"($a == $b)"',
+               taglist=>'"($a == $b)"',
        }
 );
 
                notifid=>'"%s"',
                logsrc=>'"%s"',
                timeval=>'"%s"',
+               taglist=>'"%s"',
        }
 );