creaming LB
authorMiloš Mulač <mulac@civ.zcu.cz>
Wed, 9 Sep 2009 10:26:45 +0000 (10:26 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Wed, 9 Sep 2009 10:26:45 +0000 (10:26 +0000)
+ first version of state automaton (should compile, not tested)

15 files changed:
org.glite.lb.client/src/Event.cpp.T
org.glite.lb.common/interface/events.h.T
org.glite.lb.common/src/events.c.T
org.glite.lb.common/src/events_parse.c.T
org.glite.lb.common/src/xml_parse.c.T
org.glite.lb.common/test/parse.cpp.T
org.glite.lb.server/src/get_events.c.T
org.glite.lb.server/src/lb_xml_parse.c.T
org.glite.lb.server/src/lb_xml_parse_V21.c.T
org.glite.lb.server/src/store.c.T
org.glite.lb.server/src/ws_typeref.c.T
org.glite.lb.server/test/test_xml.cpp.T
org.glite.lb.state-machine/Makefile
org.glite.lb.state-machine/src/process_event.c
org.glite.lb.state-machine/src/process_event_cream.c [new file with mode: 0644]

index 301d645..598fa5b 100644 (file)
@@ -42,6 +42,7 @@ sub typeswitch {
                if($ctype{$f->{type}}) {
                  my $cstr = $ftype eq '_common_' ? 'any' : lcfirst $ftype;
                  if ($cstr =~ m/^pBS/) { $cstr = ucfirst $cstr; }
+                 if ($cstr =~ m/^cREAM/) { $cstr = ucfirst $cstr; }
                  if ($cstr =~ m/^condor/) { $cstr = ucfirst $cstr; }
                  my $cname = getName $f 'C';
                  gen "$indent\tcase Event::".uc($f->{name}).": return(cev->$cstr.$cname);\n";
@@ -51,6 +52,7 @@ sub typeswitch {
                  # conversion from int to string (well, enum to string)
                  my $cstr = $ftype eq '_common_' ? 'any' : lcfirst $ftype;
                  if ($cstr =~ m/^pBS/) { $cstr = ucfirst $cstr; }
+                 if ($cstr =~ m/^cREAM/) { $cstr = ucfirst $cstr; }
                  if ($cstr =~ m/^condor/) { $cstr = ucfirst $cstr; }
                  my $cname = getName $f 'C';
                  my $fn = $ftype eq '_common_' ? "" : ucfirst $ftype;
index f86b3ac..6339be4 100644 (file)
@@ -341,6 +341,7 @@ for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} }
                $event->getTypes) {
        my $tl = lcfirst $t;
        if ($tl =~ m/^pBS/) { $tl = ucfirst $tl; }
+       if ($tl =~ m/^cREAM/) { $tl = ucfirst $tl; }
        if ($tl =~ m/^condor/) { $tl = ucfirst $tl; }
        gen $indent."edg_wll_${t}Event\t${tl};\n";
 }
index 23febd0..b566047 100644 (file)
@@ -303,6 +303,7 @@ for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} }
        my $tu = uc $t;
        my $tl = lcfirst $t;
        if ($tl =~ m/^pBS/) { $tl = ucfirst $tl; }
+       if ($tl =~ m/^cREAM/) { $tl = ucfirst $tl; }
        if ($tl =~ m/^condor/) { $tl = ucfirst $tl; }
        gen $indent."case EDG_WLL_EVENT_$tu : \n";
        selectType $event $t;
@@ -357,6 +358,7 @@ for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} }
        my $tu = uc $t;
        my $tl = lcfirst $t;
        if ($tl =~ m/^pBS/) { $tl = ucfirst $tl; }
+       if ($tl =~ m/^cREAM/) { $tl = ucfirst $tl; }
        if ($tl =~ m/^condor/) { $tl = ucfirst $tl; }
        gen $indent."case EDG_WLL_EVENT_$tu :\n";
        selectType $event $t;
index 856210a..910d25c 100644 (file)
@@ -130,6 +130,7 @@ for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} }
        my $tu = uc $t;
        my $tl = lcfirst $t;
        if ($tl =~ m/^pBS/) { $tl = ucfirst $tl; }
+       if ($tl =~ m/^cREAM/) { $tl = ucfirst $tl; }
        if ($tl =~ m/^condor/) { $tl = ucfirst $tl; }
        my $misuse = "if (eventcode != EDG_WLL_EVENT_$tu ) MISUSE";
        selectType $event $t;
@@ -258,6 +259,7 @@ for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} }
        my $tu = uc $t;
        my $tl = lcfirst $t;
        if ($tl =~ m/^pBS/) { $tl = ucfirst $tl; }
+       if ($tl =~ m/^cREAM/) { $tl = ucfirst $tl; }
        if ($tl =~ m/^condor/) { $tl = ucfirst $tl; }
        my $free = "";
        gen $indent."case EDG_WLL_EVENT_$tu :\n";
@@ -392,6 +394,7 @@ for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} }
        my $tu = uc $t;
        my $tl = lcfirst $t;
        if ($tl =~ m/^pBS/) { $tl = ucfirst $tl; }
+       if ($tl =~ m/^cREAM/) { $tl = ucfirst $tl; }
        if ($tl =~ m/^condor/) { $tl = ucfirst $tl; }
        gen $indent."case EDG_WLL_EVENT_$tu :\n";
        selectType $event $t;
@@ -453,6 +456,7 @@ edg_wll_ErrorCode edg_wll_CompareEvents(
                my $tu = uc $t;
                my $tl = lcfirst $t;
                if ($tl =~ m/^pBS/) { $tl = ucfirst $tl; }
+               if ($tl =~ m/^cREAM/) { $tl = ucfirst $tl; }
                if ($tl =~ m/^condor/) { $tl = ucfirst $tl; }
 
                selectType $event $t;
@@ -624,6 +628,7 @@ for (i=0; i<table->num; i++) {
        my $tu = uc $t;
        my $tl = lcfirst $t;
        if ($tl =~ m/^pBS/) { $tl = ucfirst $tl; }
+       if ($tl =~ m/^cREAM/) { $tl = ucfirst $tl; }
        if ($tl =~ m/^condor/) { $tl = ucfirst $tl; }
        my $misuse = "if (eventcode != EDG_WLL_EVENT_$tu ) MISUSE";
        selectType $event $t;
index 5e0a326..a26857f 100644 (file)
@@ -811,6 +811,7 @@ static void endQueryEvents(void *data, const char *el UNUSED_VAR)
                         my $ft = $f->{type};
                        $fo[0] = $fo[0] eq '_common_' ? 'any' : lcfirst $fo[0];
                        if ($fo[0] =~ m/^pBS/) { $fo[0] = ucfirst $fo[0]; }
+                       if ($fo[0] =~ m/^cREAM/) { $fo[0] = ucfirst $fo[0]; }
                        if ($fo[0] =~ m/^condor/) { $fo[0] = ucfirst $fo[0]; }
                         gen "$bi   XMLCtx->eventsOutGlobal[XMLCtx->position].$fo[0].$t =\n";
                         gen "$bi \tedg_wll_from_string_to_$ft(XMLCtx);\n";
@@ -825,6 +826,7 @@ static void endQueryEvents(void *data, const char *el UNUSED_VAR)
                                my $u = uc $_;
                                $_ = lcfirst $_;
                                if ($_ =~ m/^pBS/) { $_ = ucfirst $_; }
+                               if ($_ =~ m/^cREAM/) { $_ = ucfirst $_; }
                                if ($_ =~ m/^condor/) { $_ = ucfirst $_; }
                                gen "$bi     case EDG_WLL_EVENT_$u :\n";
                                gen "$bi \t  XMLCtx->eventsOutGlobal[XMLCtx->position].$_.$t =\n";
index d8c7e9b..c7e97d1 100644 (file)
@@ -16,6 +16,7 @@ class EventParseTest: public  CppUnit::TestFixture
         for my $e ($event->getTypesOrdered) {
                 my $u = lcfirst $e;
                if ($u =~ m/^pBS/) { $u = ucfirst $u; }
+               if ($u =~ m/^cREAM/) { $u = ucfirst $u; }
                if ($u =~ m/^condor/) { $u = ucfirst $u; }
                 my $c = getTypeComment $event $e;
                 gen "\tCPPUNIT_TEST($u);\n";
@@ -28,6 +29,7 @@ public:
         for my $e ($event->getTypesOrdered) {
                 my $u = lcfirst $e;
                if ($u =~ m/^pBS/) { $u = ucfirst $u; }
+               if ($u =~ m/^cREAM/) { $u = ucfirst $u; }
                if ($u =~ m/^condor/) { $u = ucfirst $u; }
                 my $c = getTypeComment $event $e;
                 gen "\tvoid $u();\n";
@@ -40,6 +42,7 @@ public:
         for my $e ($event->getTypesOrdered) {
                 my $l = lcfirst $e;
                if ($l =~ m/^pBS/) { $l = ucfirst $l; }
+               if ($l =~ m/^cREAM/) { $l = ucfirst $l; }
                if ($l =~ m/^condor/) { $l = ucfirst $l; }
                 my $u = uc $e;
                 my $c = getTypeComment $event $e;
index c7c245e..c3636dc 100644 (file)
@@ -145,6 +145,7 @@ static void edg_wll_set_event_field(
                        my $uctype = uc $_;
                        my $flctype = lcfirst $_;
                        if ($flctype =~ m/^pBS/) { $flctype = ucfirst $flctype; }
+                       if ($flctype =~ m/^cREAM/) { $flctype = ucfirst $flctype; }
                        if ($flctype =~ m/^condor/) { $flctype = ucfirst $flctype; }
                        my $frs = $f->{codes} ?
                                "event->$flctype.$name = edg_wll_StringTo$_${fucname}(value);" :
index 88178dc..287d2d3 100644 (file)
@@ -1513,6 +1513,7 @@ int edg_wll_QueryEventsToXML(edg_wll_Context ctx, edg_wll_Event *eventsOut, char
                                my $n = $f->{null};
                                $t = lcfirst $t;
                                if ($t =~ m/^pBS/) { $t = ucfirst $t; }
+                               if ($t =~ m/^cREAM/) { $t = ucfirst $t; }
                                if ($t =~ m/^condor/) { $t = ucfirst $t; }
                                 gen "\t\tedg_wll_add_$ft\_to_XMLBody(&pomB, eventsOut[i].$t.$_, \"$_\", $n);\n";
                         }
index 0aa51e5..a726d0b 100644 (file)
@@ -869,6 +869,7 @@ int edg_wll_QueryEventsToXMLV21(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *e
                                my $n = $f->{null};
                                $t = lcfirst $t;
                                if ($t =~ m/^pBS/) { $t = ucfirst $t; }
+                               if ($t =~ m/^cREAM/) { $t = ucfirst $t; }
                                if ($t =~ m/^condor/) { $t = ucfirst $t; }
                                 gen "\t\tedg_wll_add_$ft\_to_XMLBody(&pomB, eventsOut[i].$t.$_, \"$_\", $n);\n";
                         }
index 365268f..b64dd78 100644 (file)
@@ -419,6 +419,7 @@ static int store_flesh(edg_wll_Context ctx,edg_wll_Event *e,const char *ulm,char
                my $uctype = uc $type;
                my $flctype = lcfirst $type;
                if ($flctype =~ m/^pBS/) { $flctype = ucfirst $flctype; }
+               if ($flctype =~ m/^cREAM/) { $flctype = ucfirst $flctype; }
                if ($flctype =~ m/^condor/) { $flctype = ucfirst $flctype; }
                gen qq{
 !              case EDG_WLL_EVENT_$uctype:
index b07cbb5..0c08d8c 100644 (file)
@@ -34,6 +34,7 @@ sub eventFieldAssign {
        $tn = $f->{type};
        $native_en = lcfirst $e;
        if ($native_en =~ m/^pBS/) { $native_en = ucfirst $native_en; }
+       if ($native_en =~ m/^cREAM/) { $native_en = ucfirst $native_en; }
        if ($native_en =~ m/^condor/) { $native_en = ucfirst $native_en; }
        $native_fn = $f->{name};
        $soap_en = $e;
@@ -1114,6 +1115,7 @@ static int edg_wll_SoapToEvent(
                                } else {
                                        $act = lcfirst $name;
                                        if ($act =~ m/^pBS/) { $act = ucfirst $act; }
+                                       if ($act =~ m/^cREAM/) { $act = ucfirst $act; }
                                        if ($act =~ m/^condor/) { $act = ucfirst $act; }
                                }
                                my $usuc = $fn;
index b4c5d00..b23cffa 100644 (file)
@@ -49,6 +49,7 @@ static char * compare_events(const edg_wll_Event *e1, const edg_wll_Event *e2)
                my $tu = uc $t;
                my $tl = lcfirst $t;
                if ($tl =~ m/^pBS/) { $tl = ucfirst $tl; }
+               if ($tl =~ m/^cREAM/) { $tl = ucfirst $tl; }
                if ($tl =~ m/^condor/) { $tl = ucfirst $tl; }
 
                selectType $event $t;
index a8618bf..1ba7761 100644 (file)
@@ -53,8 +53,8 @@ COMMON_LIBS:= -L${stagedir}/lib  -lglite_lb_common_${nothrflavour} -lglite_secur
 PLUGIN_LIBS:= -L${stagedir}/lib -lglite_lb_common_${nothrflavour}\
        ${classadslib} -lstdc++ ${expatlib} -lexpat\
 
-PLUGIN_LOBJS:=seqcode_aux.lo process_event.lo process_event_pbs.lo process_event_condor.lo lb_plugin.lo
-MACHINE_OBJS:=seqcode_aux.o process_event.o process_event_pbs.o process_event_condor.o
+PLUGIN_LOBJS:=seqcode_aux.lo process_event.lo process_event_pbs.lo process_event_condor.lo process_event_cream.lo lb_plugin.lo
+MACHINE_OBJS:=seqcode_aux.o process_event.o process_event_pbs.o process_event_condor.o process_event_cream.o
 
 PLUGIN_LIB=glite_lb_plugin.la
 MACHINE_LIB=libglite_lb_statemachine.a
index 0230b8d..deb0449 100644 (file)
@@ -69,8 +69,8 @@ int processEvent(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char
                        return processEvent_PBS(js,e,ev_seq,strict,errstring);
                case EDG_WLL_STAT_CONDOR: 
                        return processEvent_Condor(js,e,ev_seq,strict,errstring);
-               case EDG_WLL_STAT_CREAM:
-                       return RET_OK;          /* TODO: mulac */
+               case EDG_WLL_STAT_CREAM: 
+                       return processEvent_Cream(js,e,ev_seq,strict,errstring);
                case -1: return RET_UNREG;
                default: 
                        trio_asprintf(errstring,"undefined job type %d",js->pub.jobtype);
diff --git a/org.glite.lb.state-machine/src/process_event_cream.c b/org.glite.lb.state-machine/src/process_event_cream.c
new file mode 100644 (file)
index 0000000..b4b83e4
--- /dev/null
@@ -0,0 +1,180 @@
+#ident "$Header$"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+#include <syslog.h>
+
+#include "glite/lb/context-int.h"
+
+#include "glite/lbu/trio.h"
+
+#include "intjobstat.h"
+#include "seqcode_aux.h"
+
+/* TBD: share in whole logging or workload */
+#ifdef __GNUC__
+#define UNUSED_VAR __attribute__((unused))
+#else
+#define UNUSED_VAR
+#endif
+
+static int compare_timestamps(struct timeval a, struct timeval b)
+{
+       if ( (a.tv_sec > b.tv_sec) || 
+               ((a.tv_sec == b.tv_sec) && (a.tv_usec > b.tv_usec)) ) return 1;
+       if ( (a.tv_sec < b.tv_sec) ||
+                ((a.tv_sec == b.tv_sec) && (a.tv_usec < b.tv_usec)) ) return -1;
+       return 0;
+}
+
+
+// XXX move this defines into some common place to be reusable
+#define USABLE(res) ((res) == RET_OK)
+#define USABLE_DATA(res) (1)
+#define rep(a,b) { free(a); a = (b == NULL) ? NULL : strdup(b); }
+#define rep_cond(a,b) { if (b) { free(a); a = strdup(b); } }
+
+int processEvent_Cream(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char **errstring)
+{
+       edg_wll_JobStatCode     old_state = js->pub.state;
+       int                     res = RET_OK;
+
+
+/*     not used in CREAM
+       if ((js->last_seqcode != NULL) &&
+                       (edg_wll_compare_pbs_seq(js->last_seqcode, e->any.seqcode) > 0) ) {
+               res = RET_LATE; 
+       }
+*/
+       switch (e->any.type) {
+               case EDG_WLL_EVENT_REGJOB:
+                       if (USABLE(res)) {
+                               js->pub.state = EDG_WLL_JOB_SUBMITTED;
+                               js->pub.cream_state = EDG_WLL_STAT_REGISTERED;
+                       }
+                       if (USABLE_DATA(res)) {
+                       }
+                       break;
+               case EDG_WLL_EVENT_CREAMSTART:
+                       // nothing to be done
+                       break;
+               case EDG_WLL_EVENT_CREAMPURGE:
+                       // no state transition
+               case EDG_WLL_EVENT_CREAMSTORE:
+                       if (USABLE(res)) {
+                               switch (e->CREAMStore.command) {
+                                       case EDG_WLL_CREAMSTORE_CMDSTART:
+                                               if (e->CREAMStore.result == EDG_WLL_CREAMSTORE_OK) {
+                                                       js->pub.state = EDG_WLL_JOB_WAITING;
+                                                       js->pub.cream_state = EDG_WLL_STAT_PENDING;
+                                               }
+                                               break;
+                                       case EDG_WLL_CREAMSTORE_CMDSUSPEND:
+                                               if (e->CREAMStore.result == EDG_WLL_CREAMSTORE_OK) {
+                                                       js->pub.suspended = 1;
+                                               }
+                                               break;
+                                       case EDG_WLL_CREAMSTORE_CMDRESUME:
+                                               if (e->CREAMStore.result == EDG_WLL_CREAMSTORE_OK) {
+                                                       js->pub.suspended = 0;
+                                               }
+                                               break;
+                                       default:
+                                               break;
+                               }
+                       }
+                       if (USABLE_DATA(res)) {
+                       }
+                       break;
+               case EDG_WLL_EVENT_CREAMCALL:
+                       if (USABLE(res)) {
+                               if (e->CREAMCall.callee == EDG_WLL_SOURCE_LRMS && e->any.source == EDG_WLL_SOURCE_LRMS)
+                                       js->pub.state = EDG_WLL_JOB_SCHEDULED;
+                                       js->pub.cream_state = EDG_WLL_STAT_IDLE;
+
+                       }
+                       if (USABLE_DATA(res)) {
+                               js->pub.cream_reason = e->CREAMCall.reason;
+                       }
+                       break;
+
+               case EDG_WLL_EVENT_CREAMRUNNING:
+                       if (USABLE(res)) {
+                               js->pub.state = EDG_WLL_JOB_RUNNING;
+                               js->pub.cream_state = EDG_WLL_STAT_RUNNING;
+                       }
+                       if (USABLE_DATA(res)) {
+                               js->pub.cream_node = e->CREAMRunning.node;
+                       }
+                       break;
+               case EDG_WLL_EVENT_CREAMREALLYRUNNING:
+                       if (USABLE(res)) {
+                               js->pub.state = EDG_WLL_JOB_RUNNING;
+                               js->pub.cream_state = EDG_WLL_STAT_REALLYRUNNING;
+                       }
+                       if (USABLE_DATA(res)) {
+                       }
+                       break;
+               case EDG_WLL_EVENT_CREAMDONE:
+                       if (USABLE(res)) {
+                               js->pub.state = EDG_WLL_JOB_DONE;
+                               js->pub.cream_state = (e->CREAMDone.status_code == EDG_WLL_DONE_OK) ? EDG_WLL_STAT_DONEOK : EDG_WLL_STAT_DONEFAILED;
+                       }
+                       if (USABLE_DATA(res)) {
+                               js->pub.cream_done_code = e->CREAMDone.status_code;
+                               js->pub.cream_exit_code = e->CREAMDone.exit_code;
+                               js->pub.cream_reason = e->CREAMDone.reason;
+                       }
+                       break;
+               case EDG_WLL_EVENT_CREAMCANCEL:
+                       if (USABLE(res)) {
+                               if (e->CREAMCancel.status_code == EDG_WLL_CANCEL_DONE) {
+                                       js->pub.state = EDG_WLL_JOB_CANCELLED;
+                                       js->pub.cream_state = EDG_WLL_STAT_ABORTED;
+                               }
+                       }
+                       if (USABLE_DATA(res)) {
+                               js->pub.cream_cancel_reason = e->CREAMCancel.reason;
+                       }
+                       break;
+               case EDG_WLL_EVENT_CREAMABORT:
+                       if (USABLE(res)) {
+                               js->pub.state = EDG_WLL_JOB_ABORTED;
+                               js->pub.cream_state = EDG_WLL_STAT_ABORTED;
+                       }
+                       if (USABLE_DATA(res)) {
+                               js->pub.cream_reason = e->CREAMAbort.reason;
+                       }
+                       break;
+
+               case EDG_WLL_EVENT_USERTAG:
+                       if (USABLE_DATA(res)) {
+                               if (e->userTag.name != NULL && e->userTag.value != NULL) {
+                                       add_taglist(e->userTag.name, e->userTag.value, e->any.seqcode, js);
+                               }
+                       }
+                       break;
+
+               default:
+                       break;
+       }
+
+       if (USABLE(res)) {
+               rep(js->last_seqcode, e->any.seqcode);
+
+               js->pub.lastUpdateTime = e->any.timestamp;
+               if (old_state != js->pub.state) {
+                       js->pub.stateEnterTime = js->pub.lastUpdateTime;
+                       js->pub.stateEnterTimes[1 + js->pub.state]
+                               = (int)js->pub.lastUpdateTime.tv_sec;
+               }
+       }
+       if (! js->pub.location) js->pub.location = strdup("this is CREAM");
+
+
+       return RET_OK;
+}
+