some improvements of state automaton
authorMiloš Mulač <mulac@civ.zcu.cz>
Thu, 22 Feb 2007 15:10:52 +0000 (15:10 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Thu, 22 Feb 2007 15:10:52 +0000 (15:10 +0000)
org.glite.lb.server/src/bkserverd.c
org.glite.lb.server/src/jobstat.h
org.glite.lb.server/src/jobstat_supp.c
org.glite.lb.server/src/process_event_pbs.c

index a5c4dec..00ccabf 100644 (file)
@@ -925,7 +925,7 @@ int bk_handle_connection(int conn, struct timeval *timeout, void *data)
                edg_wll_Error(ctx, &errt, &errd);
                dprintf(("[%d] %s (%s)\n[%d]\tignored, continuing without VOMS\n", getpid(), errt, errd,getpid()));
                free(errt); free(errd);
-               edg_wll_ResetError(ctx);
+               edg_wll_ResetError(ctx); 
        }
        if (debug && ctx->vomsGroups.len > 0)
        {
index 464393e..9fc07ab 100644 (file)
@@ -56,6 +56,15 @@ typedef struct _intJobStat {
                struct timeval  last_pbs_event_timestamp;
        } intJobStat;
 
+typedef enum _edg_wll_PBSEventSource {
+       EDG_WLL_PBS_EVENT_SOURCE_UNDEF = 0,
+       EDG_WLL_PBS_EVENT_SOURCE_SCHEDULER,
+       EDG_WLL_PBS_EVENT_SOURCE_SERVER,
+       EDG_WLL_PBS_EVENT_SOURCE_MOM,
+       EDG_WLL_PBS_EVENT_SOURCE_ACCOUNTING,
+       EDG_WLL_PBS_EVENT_SOURCE__LAST
+} edg_wll_PBSEventSource;
+
 void destroy_intJobStat(intJobStat *);
 void destroy_intJobStat_extension(intJobStat *p);
 
@@ -84,6 +93,8 @@ int processEvent_PBS(intJobStat *, edg_wll_Event *, int, int, char **);
 
 int add_stringlist(char ***, const char *);
 int edg_wll_compare_seq(const char *, const char *);
+int edg_wll_compare_pbs_seq(const char *,const char *);
+edg_wll_PBSEventSource get_pbs_event_source(const char *pbs_seq_num);
 
 void init_intJobStat(intJobStat *p);
 
index e585128..ff55d29 100644 (file)
@@ -822,7 +822,7 @@ int same_branch(const char *a, const char *b)
                return(0);
 }
 
-int edg_wll_compare_pbs_seq(const char *a, const char *b)
+int edg_wll_compare_pbs_seq(const char *a,const char *b)
 {
        char    timestamp_a[14], pos_a[10], src_a;
        char    timestamp_b[14], pos_b[10], src_b;
@@ -863,6 +863,10 @@ int edg_wll_compare_pbs_seq(const char *a, const char *b)
                        if (src_a == 'm') return 1;
                        if (src_b == 'm') return -1;
 
+                       /* then prioritize events from pbs_server */
+                       if (src_a == 's') return 1;
+                       if (src_b == 's') return -1;
+
                        /* other priorities comes here... */
                }       
        }
@@ -870,6 +874,16 @@ int edg_wll_compare_pbs_seq(const char *a, const char *b)
        return 0;
 }
 
+edg_wll_PBSEventSource get_pbs_event_source(const char *pbs_seq_num) {
+       switch (pbs_seq_num[EDG_WLL_SEQ_PBS_SIZE-1]) {
+               case 'c': return(EDG_WLL_PBS_EVENT_SOURCE_SCHEDULER);
+               case 's': return(EDG_WLL_PBS_EVENT_SOURCE_SERVER);
+               case 'm': return(EDG_WLL_PBS_EVENT_SOURCE_MOM);
+               case 'a': return(EDG_WLL_PBS_EVENT_SOURCE_ACCOUNTING);
+               default: return(EDG_WLL_PBS_EVENT_SOURCE_UNDEF);
+       }
+}
+
 int edg_wll_compare_seq(const char *a, const char *b)
 {
        unsigned int    c[EDG_WLL_SOURCE__LAST];
@@ -878,7 +892,7 @@ int edg_wll_compare_seq(const char *a, const char *b)
        char            sca[EDG_WLL_SEQ_SIZE], scb[EDG_WLL_SEQ_SIZE];
 
 
-       if ( (strstr(a,"TIMESTAMP=") == a) && (strstr(b,"TIMESTAMP=") == b) )
+       if ( (strstr(a,"TIMESTAMP=") == a) && (strstr(b,"TIMESTAMP=") == b) ) 
                return edg_wll_compare_pbs_seq(a,b);
 
        if (!strstr(a, "LBS")) snprintf(sca,EDG_WLL_SEQ_SIZE,"%s:LBS=000000",a);
@@ -934,6 +948,7 @@ static int compare_events_by_seq(const void *a, const void *b)
         const edg_wll_Event *f = (edg_wll_Event *) b;
        int ret;
 
+
        ret = edg_wll_compare_seq(e->any.seqcode, f->any.seqcode);
        if (ret) return ret;
        
index dd816c9..c703756 100644 (file)
@@ -44,14 +44,13 @@ int processEvent_PBS(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, c
        int                     res = RET_OK;
 
 
-       fputs("processEvent_PBS()",stderr);
-
-       //if (compare_timestamps(js->last_pbs_event_timestamp, e->any.timestamp) > 0)
        if ((js->last_seqcode != NULL) &&
                        (edg_wll_compare_pbs_seq(js->last_seqcode, e->any.seqcode) > 0) ) {
                res = RET_LATE; 
        }
 
+       printf("processEvent_PBS(): %s, %s\n\t %s, old_state=%s, ", edg_wll_EventToString(e->any.type), e->any.seqcode, (res == RET_LATE) ? "RET_LATE" : "RET_OK", edg_wll_StatToString(old_state));
+
        switch (e->any.type) {
                case EDG_WLL_EVENT_REGJOB:
                        if (USABLE(res)) {
@@ -94,8 +93,19 @@ int processEvent_PBS(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, c
                        break;
                case EDG_WLL_EVENT_PBSRUN:
                        if (USABLE(res)) {
-                               js->pub.state = EDG_WLL_JOB_RUNNING;
-                               rep(js->pub.pbs_state, "R");
+                               switch (get_pbs_event_source(e->any.seqcode)) {
+                                       case EDG_WLL_PBS_EVENT_SOURCE_SERVER:
+                                               js->pub.state = EDG_WLL_JOB_SCHEDULED;
+                                               rep(js->pub.pbs_state, "Q");
+                                               break;
+                                       case EDG_WLL_PBS_EVENT_SOURCE_MOM:
+                                               js->pub.state = EDG_WLL_JOB_RUNNING;
+                                               rep(js->pub.pbs_state, "R");
+                                               break;
+                                       default:
+                                               assert(0); // running event from strande source
+                                               break;
+                               }
                        }
                        if (USABLE_DATA(res)) {
                                rep_cond(js->pub.pbs_scheduler, e->PBSRun.scheduler);
@@ -170,6 +180,9 @@ int processEvent_PBS(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, c
                }
        }
        if (! js->pub.location) js->pub.location = strdup("this is PBS");
+
+       printf("new_state=%s\n", edg_wll_StatToString(js->pub.state));
+
        return RET_OK;
 }