Child job histogram encoding, storing and retrieval. Firt versions - retrieval not...
authorZdeněk Šustr <sustr4@cesnet.cz>
Fri, 20 Oct 2006 13:41:07 +0000 (13:41 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Fri, 20 Oct 2006 13:41:07 +0000 (13:41 +0000)
org.glite.lb.client/Makefile
org.glite.lb.server/src/jobstat.c
org.glite.lb.server/src/jobstat_supp.c

index 63b749c..8d2fe16 100644 (file)
@@ -248,9 +248,9 @@ examples: ${EXAMPLES} ${EXAMPLES_CL} ${sh_PROGS}
 
 fake: ${FAKE_EXAMPLES}
 
-check: compile check.producer
+#check: compile check.producer
 
-check.producer: producer_test
+ check.producer: producer_test
        ./producer_test
 
 producer_test: producer_test.o prod_proto_test.o
index 2a303e7..d3661c0 100644 (file)
@@ -711,11 +711,68 @@ edg_wll_ErrorCode edg_wll_StepIntState(edg_wll_Context ctx,
 
 edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context ctx, edg_wlc_JobId parent_jobid, intJobStat **ijs)
 {
-       // XXX: to be done
+
+        char    *stmt = NULL,*out = NULL;
+        edg_wll_Stmt    sh;
+        int     f = -1;
+
+        edg_wll_ResetError(ctx);
+        trio_asprintf(&stmt,"select int_status from states where jobid='%|Ss'", parent_jobid);
+
+        if (stmt==NULL) {
+                return edg_wll_SetError(ctx,ENOMEM, NULL);
+        }
+
+/* XXX: Untested  */
+
+/* XXX: This positively does not work, needs finishing: */
+
+        if (edg_wll_ExecStmt(ctx,stmt,&sh) >= 0) {
+                f=edg_wll_FetchRow(sh,&out);
+                if (f == 0) {
+                        if (out) free(out);
+                        out = NULL;
+                        edg_wll_SetError(ctx, ENOENT, NULL);
+                }
+        }
+        edg_wll_FreeStmt(&sh);
+        free(stmt);
+
        return edg_wll_Error(ctx, NULL, NULL);
 }
+
+/* Make a histogram of all subjobs belonging to the parent job */
+
 edg_wll_ErrorCode edg_wll_SetSubjobHistogram(edg_wll_Context ctx, edg_wlc_JobId parent_jobid, intJobStat *ijs)
 {
-       // XXX: to be done
+        char *stat_enc = NULL;
+        char *stmt;
+        int dbret;
+
+        stat_enc = enc_intJobStat(strdup(""), ijs);
+
+        trio_asprintf(&stmt,
+                "update states set "
+                "status=%d,int_status='%|Ss',version='%|Ss'"
+                "where jobid='%|Ss'",
+                ijs->pub.state, stat_enc, INTSTAT_VERSION, parent_jobid);
+
+       if (stmt==NULL) {
+               return edg_wll_SetError(ctx,ENOMEM, NULL);
+       }
+
+/* XXX: Untested  */
+
+//printf ("Would like to run SQL statament: %s\n", stmt);
+
+        if ((dbret = edg_wll_ExecStmt(ctx,stmt,NULL)) < 0) goto cleanup;
+
+       assert(dbret);  /* update should come through OK as the record exists */
+
+cleanup:
+        free(stmt);
+        free(stat_enc);
+
        return edg_wll_Error(ctx, NULL, NULL);
+
 }
index 2261dcf..1623536 100644 (file)
@@ -82,6 +82,16 @@ static char *enc_int(char *old, int item)
         return out;
 }
 
+static char *enc_int_array(char *old, int *item, int itemsNo)
+{
+        char *out;
+       int index;
+       for (index=0; index <= itemsNo; index++) asprintf(&out,"%s%d%s", out, item[index],index==itemsNo?"":";");
+        asprintf(&out,"%s%s ", old, out);
+        free(old);
+        return out;
+}
+
 static int dec_int(char* in, char **rest)
 {
        int scret;
@@ -97,6 +107,49 @@ static int dec_int(char* in, char **rest)
        return out;
 }
 
+static int dec_int_array(char* in, char **rest, int *out)
+{
+       int charNo, itemsNo = 0, cindex, iindex = 0;
+       char *tempstr;
+
+        /* Find out the number of items in the field first */
+
+       for (charNo = 0;charNo<strlen(in);charNo++)     {
+               if (in[charNo] == ' ') {        /* Only ' ' (space) is accepted as a separator. Should not be a broblem. */
+                       itemsNo++;
+                       break;
+               }
+               if (in[charNo] == ';') {
+                       itemsNo++;
+               }
+       }
+       if (!itemsNo) {         /* No separator has been found. This is the last input string */
+               itemsNo = 1;    /* - consider it an one-item array */
+               *rest = NULL;
+       }
+       else *rest = charNo + 1;
+
+//     out = (int*)calloc(itemsNo,sizeof(int));
+       tempstr = (char*)calloc(charNo+1,sizeof(char));
+
+       strcpy(tempstr,"");
+
+       for (cindex = 0; cindex<charNo; cindex++) {
+               if ((in[cindex] == ';') || (in[cindex] == ' ')) {
+                       out[iindex] = atoi(tempstr);
+                       strcpy(tempstr,"");
+                       iindex++;
+               }
+               else tempstr = strcat(tempstr, in[cindex]); 
+       }
+       if (in[cindex] != ' ') out[iindex] = atoi(tempstr);     /* string not terminated with a separator */
+
+       free(tempstr);
+
+        return out;
+}
+
+
 static char* enc_jobid(char *old, edg_wlc_JobId item)
 {
        char *str;
@@ -404,7 +457,7 @@ static char *enc_JobStat(char *old, edg_wll_JobStat* stat)
        if (ret) ret = enc_jobid(ret, stat->parent_job);
        if (ret) ret = enc_string(ret, stat->seed);
        if (ret) ret = enc_int(ret, stat->children_num);
-               /* children data are not stored in DB */
+               /* children histogram also stored in the DB, see bellow. Other children data not stored. */
        if (ret) ret = enc_string(ret, stat->condorId);
        if (ret) ret = enc_string(ret, stat->globusId);
        if (ret) ret = enc_string(ret, stat->localId);
@@ -433,6 +486,7 @@ static char *enc_JobStat(char *old, edg_wll_JobStat* stat)
        if (ret) ret = enc_int(ret, stat->payload_running);
        if (ret) ret = enc_strlist(ret, stat->possible_destinations);
        if (ret) ret = enc_strlist(ret, stat->possible_ce_nodes);
+       if (ret) ret = enc_int_array(ret, stat->children_hist, EDG_WLL_NUMBER_OF_STATCODES);
 
        return ret;
 }
@@ -452,7 +506,7 @@ static edg_wll_JobStat* dec_JobStat(char *in, char **rest)
         if (tmp_in != NULL) stat->parent_job = dec_jobid(tmp_in, &tmp_in);
         if (tmp_in != NULL) stat->seed = dec_string(tmp_in, &tmp_in);
         if (tmp_in != NULL) stat->children_num = dec_int(tmp_in, &tmp_in);
-                /* children data are not stored in DB */
+                /* children histogram also stored in the DB, see bellow. Other children data not stored. */
         if (tmp_in != NULL) stat->condorId = dec_string(tmp_in, &tmp_in);
         if (tmp_in != NULL) stat->globusId = dec_string(tmp_in, &tmp_in);
         if (tmp_in != NULL) stat->localId = dec_string(tmp_in, &tmp_in);
@@ -481,7 +535,10 @@ static edg_wll_JobStat* dec_JobStat(char *in, char **rest)
         if (tmp_in != NULL) stat->payload_running = dec_int(tmp_in, &tmp_in);
         if (tmp_in != NULL) stat->possible_destinations = dec_strlist(tmp_in, &tmp_in);
         if (tmp_in != NULL) stat->possible_ce_nodes = dec_strlist(tmp_in, &tmp_in);
-       
+        if (tmp_in != NULL) {
+                           stat->children_hist = (int*)calloc(EDG_WLL_NUMBER_OF_STATCODES, sizeof(int));
+                           dec_int_array(tmp_in, &tmp_in, stat->children_hist); }
+
        *rest = tmp_in;
        return stat;
 }
@@ -498,6 +555,7 @@ char *enc_intJobStat(char *old, intJobStat* stat)
        if (ret) ret = enc_string(ret, stat->last_branch_seqcode);
        if (ret) ret = enc_string(ret, stat->deep_resubmit_seqcode);
        if (ret) ret = enc_branch_states(ret, stat->branch_states);
+       if (ret) ret = enc_int_array(ret, stat->children_done_hist, EDG_WLL_NUMBER_OF_DONE_CODES-1);
        return ret;
 }
 
@@ -533,6 +591,9 @@ intJobStat* dec_intJobStat(char *in, char **rest)
                if (tmp_in != NULL) {
                        stat->branch_states = dec_branch_states(tmp_in, &tmp_in);
                }
+               if (tmp_in != NULL) {
+                       dec_int_array(tmp_in, &tmp_in, &stat->children_done_hist);
+               }
        } else if (tmp_in != NULL) {
                edg_wll_FreeStatus(pubstat);
                free(pubstat);