pass intJobStat from update_parent_status to db_parent_state and to StepInStateParent
authorMiloš Mulač <mulac@civ.zcu.cz>
Wed, 1 Nov 2006 09:26:42 +0000 (09:26 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Wed, 1 Nov 2006 09:26:42 +0000 (09:26 +0000)
- some code rearangement
- partialy working (subjob Running state only)

org.glite.lb.server/interface/store.h
org.glite.lb.server/src/db_store.c
org.glite.lb.server/src/jobstat.c
org.glite.lb.server/src/jobstat.h
org.glite.lb.server/src/process_event.c
org.glite.lb.server/src/request.c

index 1a66bf0..c42bef2 100644 (file)
@@ -4,6 +4,7 @@
 #ident "$Header$"
 
 #include "glite/lb/consumer.h"
+#include "jobstat.h"
 #include "lb_authz.h"
 
 #ifdef __cplusplus
@@ -41,7 +42,7 @@ edg_wll_ErrorCode edg_wll_StepIntStateEmbriotic(
 );
 
 int db_store(edg_wll_Context,char *, char *);
-int db_parent_store(edg_wll_Context, edg_wll_Event *);
+int db_parent_store(edg_wll_Context, edg_wll_Event *, intJobStat *);
 int handle_request(edg_wll_Context,char *);
 int create_reply(const edg_wll_Context,char **);
 
index 4bcc190..e749423 100644 (file)
@@ -112,7 +112,7 @@ err:
 
 
 int
-db_parent_store(edg_wll_Context ctx, edg_wll_Event *ev)
+db_parent_store(edg_wll_Context ctx, edg_wll_Event *ev, intJobStat *is)
 {
   char  *event = NULL;
   int  seq;
@@ -165,7 +165,7 @@ db_parent_store(edg_wll_Context ctx, edg_wll_Event *ev)
     }
 #endif
 
-    err = edg_wll_StepIntState(ctx,ev->any.jobId, ev, seq, ctx->isProxy? NULL: &newstat);
+    err = edg_wll_StepIntStateParent(ctx,ev->any.jobId, ev, seq, is, ctx->isProxy? NULL: &newstat);
   }
 
   if (err) goto err;
index 72cc1ca..1c41004 100644 (file)
@@ -37,7 +37,6 @@
 
 static void warn (const char* format, ...) UNUSED_VAR ;
 static char *job_owner(edg_wll_Context,char *);
-static int set_job_state(edg_wll_Context ctx, edg_wll_JobStatCode state, intJobStat *cis, intJobStat *pis, edg_wll_Event *ce); 
 
 
 int js_enable_store = 1;
@@ -710,6 +709,33 @@ err:
 
 }
 
+
+static int log_collectionState_event(edg_wll_Context ctx, edg_wll_JobStatCode state, intJobStat *cis, intJobStat *pis, edg_wll_Event *ce) {
+       edg_wll_Event  *event = 
+               edg_wll_InitEvent(EDG_WLL_EVENT_COLLECTIONSTATE);
+
+       // XXX: fill in event->any part of event...
+       event->any.user = strdup(pis->pub.owner);       // XXX: use this identity?
+       event->any.seqcode = strdup(ce->any.seqcode);   // XXX: nonsense, just something..
+       edg_wlc_JobIdDup(pis->pub.jobId, &(event->any.jobId));
+       gettimeofday(&event->any.timestamp,0);
+       if (ctx->p_host) event->any.host = strdup(ctx->p_host);
+       event->any.level = ctx->p_level;
+       event->any.source = EDG_WLL_SOURCE_USER_INTERFACE; // XXX: is it meaningfull?
+               
+                                       
+       event->collectionState.state = state;
+       event->collectionState.histogram = hist_to_string(pis->pub.children_hist);
+       edg_wlc_JobIdDup(cis->pub.jobId, &(event->collectionState.child));
+       event->collectionState.child_event = edg_wll_EventToString(ce->any.type);
+
+       trans_db_store(ctx, NULL, event, pis);
+
+       edg_wll_FreeEvent(event);
+       free(event);    
+}
+
+
 static edg_wll_ErrorCode update_parent_status(edg_wll_Context ctx, edg_wll_JobStatCode old_state, enum edg_wll_StatDone_code old_done_code, intJobStat *cis, edg_wll_Event *ce)
 {
        intJobStat      *pis = NULL;
@@ -741,7 +767,7 @@ static edg_wll_ErrorCode update_parent_status(edg_wll_Context ctx, edg_wll_JobSt
                        if (pis->pub.jobtype == EDG_WLL_STAT_COLLECTION) {
                                /* not RUNNING yet? */
                                if (pis->pub.state < EDG_WLL_JOB_RUNNING) {
-                                       set_job_state(ctx, cis->pub.state, cis, pis, ce);
+                                       log_collectionState_event(ctx, cis->pub.state, cis, pis, ce);
                                }
                        }
                        break;
@@ -797,6 +823,54 @@ err:
 }
 
 
+/*
+ * update stored state according to the new event
+ * (must be called with the job locked)
+ */
+
+edg_wll_ErrorCode edg_wll_StepIntStateParent(edg_wll_Context ctx,
+                                       edg_wlc_JobId job,
+                                       edg_wll_Event *e,
+                                       int seq,
+                                       intJobStat *ijsp,
+                                       edg_wll_JobStat *stat_out)
+{
+       int             flags = 0;
+       int             res;
+       int             be_strict = 0;
+       char            *errstring = NULL;
+       intJobStat      jobstat;
+       edg_wll_JobStat oldstat;
+       char            *oldstat_rgmaline = NULL;
+
+
+       memset(&oldstat,0,sizeof oldstat);
+
+       edg_wll_CpyStatus(&ijsp->pub,&oldstat);
+
+       if (ctx->rgma_export) oldstat_rgmaline = write2rgma_statline(&ijsp->pub);
+
+       res = processEvent(ijsp, e, seq, be_strict, &errstring);
+       if (res == RET_FATAL || res == RET_INTERNAL) { /* !strict */
+               edg_wll_FreeStatus(&oldstat);
+               return edg_wll_SetError(ctx, EINVAL, errstring);
+       }
+       // XXX: store it in update_parent status ?? 
+       edg_wll_StoreIntState(ctx, ijsp, seq);
+
+       edg_wll_UpdateStatistics(ctx,&oldstat,e,&ijsp->pub);
+
+       if (ctx->rgma_export) write2rgma_chgstatus(&ijsp->pub, oldstat_rgmaline);
+
+       if (stat_out) {
+               edg_wll_CpyStatus(&ijsp->pub, stat_out);
+       }
+       edg_wll_FreeStatus(&oldstat);
+
+       return edg_wll_Error(ctx, NULL, NULL);
+}
+
+
 
 /*
  * update stored state according to the new event
@@ -941,27 +1015,4 @@ cleanup:
 
 }
 
-static int set_job_state(edg_wll_Context ctx, edg_wll_JobStatCode state, intJobStat *cis, intJobStat *pis, edg_wll_Event *ce) {
-       edg_wll_Event  *event = 
-               edg_wll_InitEvent(EDG_WLL_EVENT_COLLECTIONSTATE);
-
-       // XXX: fill in event->any part of event...
-       event->any.user = strdup(pis->pub.owner);       // XXX: use this identity?
-       event->any.seqcode = strdup(ce->any.seqcode);   // XXX: nonsense, just something..
-       edg_wlc_JobIdDup(pis->pub.jobId, &(event->any.jobId));
-       gettimeofday(&event->any.timestamp,0);
-       if (ctx->p_host) event->any.host = strdup(ctx->p_host);
-       event->any.level = ctx->p_level;
-       event->any.source = EDG_WLL_SOURCE_USER_INTERFACE; // XXX: is it meaningfull?
-               
-                                       
-       event->collectionState.state = state;
-       event->collectionState.histogram = hist_to_string(pis->pub.children_hist);
-       edg_wlc_JobIdDup(cis->pub.jobId, &(event->collectionState.child));
-       event->collectionState.child_event = edg_wll_EventToString(ce->any.type);
-
-       trans_db_store(ctx, NULL, event);
 
-       edg_wll_FreeEvent(event);
-       free(event);    
-}
index 37af664..1a380a6 100644 (file)
@@ -1,5 +1,9 @@
 /* $Header$ */
 
+#ifndef _LBS_JOBSTAT_H
+#define _LBS_JOBSTAT_H
+
+
 #include "lbs_db.h"
 
 /*
@@ -84,3 +88,4 @@ void init_intJobStat(intJobStat *p);
 edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context, edg_wlc_JobId parent_jobid, intJobStat **ijs);
 edg_wll_ErrorCode edg_wll_SetSubjobHistogram(edg_wll_Context, edg_wlc_JobId parent_jobid, intJobStat *ijs);
 
+#endif
index 42eb820..b73e2ba 100644 (file)
@@ -810,7 +810,13 @@ int processEvent(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char
                case EDG_WLL_EVENT_CHANGEACL:
                        /* ignore, only for event log */
                        break;
-               
+               case EDG_WLL_EVENT_COLLECTIONSTATE:
+                       new_state = e->collectionState.state;
+//XXX: will be usefull with some meaningfull seq. code from COLLECTIONSTATE event
+//                     if (USABLE(res, strict)) {
+                                js->pub.state = new_state;
+//                     }
+                       break;
                default:
                        goto bad_event;
                        break;
index c2b4e1e..cb84b1f 100644 (file)
 
 
 int
-trans_db_store(edg_wll_Context ctx, char *event_data, edg_wll_Event *e)
+trans_db_store(edg_wll_Context ctx, char *event_data, edg_wll_Event *e, intJobStat *is)
 {
   int ret;
 
   if ((ret = edg_wll_Transaction(ctx) != 0)) goto err;
 
-  if (e) ret = db_parent_store(ctx, e);
+  if (e) ret = db_parent_store(ctx, e, is);
   else ret = db_store(ctx, "NOT USED", event_data);
 
   if (ret == 0) {
@@ -52,7 +52,7 @@ handle_request(edg_wll_Context ctx,char *buf)
     return EDG_WLL_IL_PROTO;
   }
 
-  ret = trans_db_store(ctx, event.data, NULL);
+  ret = trans_db_store(ctx, event.data, NULL, NULL);
 
   if(event.data)
     free(event.data);