Child histogram saving/retreival. Retreival not tested yet. Encoding/Decoding works...
authorZdeněk Šustr <sustr4@cesnet.cz>
Tue, 24 Oct 2006 15:22:45 +0000 (15:22 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Tue, 24 Oct 2006 15:22:45 +0000 (15:22 +0000)
org.glite.lb.server/src/jobstat.c
org.glite.lb.server/src/jobstat_supp.c

index 9a4efae..1eb5507 100644 (file)
@@ -712,37 +712,32 @@ 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)
 {
 
-        char    *stmt = NULL,*out = NULL, *res_rest;
+        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);
+        trio_asprintf(&stmt,"select int_status from states where (jobid='%|Ss') AND (version='%|Ss')", parent_jobid, INTSTAT_VERSION);
 
         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;
-                        return edg_wll_SetError(ctx, ENOENT, NULL);
+                        edg_wll_SetError(ctx, ENOENT, NULL);
                 }
         }
         edg_wll_FreeStmt(&sh);
         free(stmt);
 
-/* XXX: Untested  */
-
-        *ijs = dec_intJobStat(out, &res_rest);
-        if (res_rest == NULL) {
-                edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_CALL,
-                                "error decoding DB intJobStatus");
-        }
-
-
        return edg_wll_Error(ctx, NULL, NULL);
 }
 
@@ -766,6 +761,10 @@ edg_wll_ErrorCode edg_wll_SetSubjobHistogram(edg_wll_Context ctx, edg_wlc_JobId
                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 */
index 1623536..8da4349 100644 (file)
@@ -86,9 +86,16 @@ 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);
+       char *strpom;
+
+       strpom=(char*)calloc(strlen(old)+1,sizeof(char));
+
+       for (index=0; index <= itemsNo; index++) sprintf(strpom,"%s%d%s", strpom, item[index],index==itemsNo?"":";");
+
+        asprintf(&out,"%s%s ", old, strpom);
+       free(strpom);
         free(old);
+
         return out;
 }
 
@@ -109,7 +116,7 @@ static int dec_int(char* in, char **rest)
 
 static int dec_int_array(char* in, char **rest, int *out)
 {
-       int charNo, itemsNo = 0, cindex, iindex = 0;
+       int charNo, itemsNo = 0, cindex, iindex = 0, lenindex;
        char *tempstr;
 
         /* Find out the number of items in the field first */
@@ -129,7 +136,6 @@ static int dec_int_array(char* in, char **rest, int *out)
        }
        else *rest = charNo + 1;
 
-//     out = (int*)calloc(itemsNo,sizeof(int));
        tempstr = (char*)calloc(charNo+1,sizeof(char));
 
        strcpy(tempstr,"");
@@ -140,11 +146,16 @@ static int dec_int_array(char* in, char **rest, int *out)
                        strcpy(tempstr,"");
                        iindex++;
                }
-               else tempstr = strcat(tempstr, in[cindex]); 
+               else {
+                       lenindex=strlen(tempstr);
+                       tempstr[lenindex]=in[cindex];
+                       tempstr[lenindex+1]=0;
+               }
        }
        if (in[cindex] != ' ') out[iindex] = atoi(tempstr);     /* string not terminated with a separator */
 
        free(tempstr);
+       *rest = in + charNo + 1;
 
         return out;
 }
@@ -497,8 +508,8 @@ static edg_wll_JobStat* dec_JobStat(char *in, char **rest)
 
        stat = (edg_wll_JobStat *) calloc(1,sizeof(edg_wll_JobStat));
        if (!stat) return stat;
-
        tmp_in = in;
+
         stat->state = dec_int(tmp_in, &tmp_in);
         if (tmp_in != NULL) stat->jobId = dec_jobid(tmp_in, &tmp_in);
         if (tmp_in != NULL) stat->owner = dec_string(tmp_in, &tmp_in);
@@ -540,6 +551,7 @@ static edg_wll_JobStat* dec_JobStat(char *in, char **rest)
                            dec_int_array(tmp_in, &tmp_in, stat->children_hist); }
 
        *rest = tmp_in;
+
        return stat;
 }
 
@@ -566,6 +578,7 @@ intJobStat* dec_intJobStat(char *in, char **rest)
        char *tmp_in;
 
        pubstat = dec_JobStat(in, &tmp_in);
+
        if (tmp_in != NULL) {
                stat = (intJobStat *)calloc(1,sizeof(intJobStat));
        }