Improved the behavior of jobstat calculations (reactions to various flags).
authorZdeněk Šustr <sustr4@cesnet.cz>
Thu, 15 Feb 2007 09:36:30 +0000 (09:36 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Thu, 15 Feb 2007 09:36:30 +0000 (09:36 +0000)
org.glite.lb.server/src/jobstat.c

index ceedc5a..436a999 100644 (file)
@@ -176,17 +176,46 @@ int edg_wll_JobStatus(
 //                     
 //             }
 
-                if (flags & EDG_WLL_STAT_CHILDHIST_FAST) { /* Fast Histogram */
-                        if (stat->children_hist == NULL) {
-                               // If the histogram exists, assume that it was already filled during job state retrieval
-                                stat->children_hist = (int*) calloc(1+EDG_WLL_NUMBER_OF_STATCODES, sizeof(int));
-                               edg_wll_GetSubjobHistogram(ctx, job, stat->children_hist);
-                       }
+
+               if (flags & EDG_WLL_STAT_CHILDSTAT) {
+                       char *stat_str, *s_out;
+                       edg_wll_Stmt sh;
+                       int num_sub, num_f, i;
+                       intJobStat *js;
+
+                       trio_asprintf(&stmt, "SELECT int_status FROM states WHERE parent_job='%|Ss'"
+                                               " AND version='%|Ss'",
+                                       md5_jobid, INTSTAT_VERSION);
+                       if (stmt != NULL) {
+                               num_sub = edg_wll_ExecStmt(ctx, stmt, &sh);
+                               if (num_sub >=0 ) {
+                                       i = 0;
+                                       stat->children_states = calloc(num_sub+1, sizeof(edg_wll_JobStat));
+                                       if (stat->children_states == NULL) {
+                                               edg_wll_FreeStmt(&sh);
+                                               goto dag_enomem;
+                                       }
+                                       while ((num_f = edg_wll_FetchRow(sh, &stat_str)) == 1
+                                               && i < num_sub) {
+                                               js = dec_intJobStat(stat_str, &s_out);
+                                               if (s_out != NULL && js != NULL) {
+                                                       stat->children_states[i] = js->pub;
+                                                       destroy_intJobStat_extension(js);
+                                                       free(js);
+                                                       i++;
+                                               }
+                                               free(stat_str);
+                                       }
+                                       edg_wll_FreeStmt(&sh);
+                               }
+                               free(stmt);
+                       } else goto dag_enomem;
                }
 
+
                if (flags & EDG_WLL_STAT_CHILDHIST_THOROUGH) { /* Full (thorough) Histogram */
 
-                       char *out[2];
+                       char *out[1];
                        edg_wll_Stmt sh;
                        int num_sub, num_f, i;
 
@@ -201,66 +230,65 @@ int edg_wll_JobStatus(
                                for (i=1; i<=EDG_WLL_NUMBER_OF_STATCODES; i++)
                                        stat->children_hist[i] = 0;
                        }       
-                       if ((flags & EDG_WLL_STAT_CHILDREN) == 0) {
-                               trio_asprintf(&stmt, "SELECT status FROM states "
-                                                       "WHERE parent_job='%|Ss' AND version='%|Ss'",
-                                       md5_jobid, INTSTAT_VERSION);
-                               out[1] = NULL;
-                       } else {
-                               trio_asprintf(&stmt, "SELECT s.status,j.dg_jobid FROM states s,jobs j "
-                                               "WHERE s.parent_job='%|Ss' AND s.version='%|Ss' AND s.jobid=j.jobid",
-                                       md5_jobid, INTSTAT_VERSION);
-                       }
+                       trio_asprintf(&stmt, "SELECT status FROM states "
+                                               "WHERE parent_job='%|Ss' AND version='%|Ss'",
+                                               md5_jobid, INTSTAT_VERSION);
+                       out[1] = NULL;
                        if (stmt != NULL) {
                                num_sub = edg_wll_ExecStmt(ctx, stmt, &sh);
                                if (num_sub >=0 ) {
-                                       while ((num_f = edg_wll_FetchRow(sh, out)) == 1
-                                                       || (num_f == 2)) {
+                                       while ((num_f = edg_wll_FetchRow(sh, out)) == 1 ) {
                                                num_f = atoi(out[0]);
                                                if (num_f > EDG_WLL_JOB_UNDEF && num_f < EDG_WLL_NUMBER_OF_STATCODES)
                                                        stat->children_hist[num_f+1]++;
-                                               if (out[1] !=NULL) add_stringlist(&stat->children, out[1]);
-                                               free(out[0]); free(out[1]);
+                                               free(out[0]); 
                                        }
                                        edg_wll_FreeStmt(&sh);
                                }
                                free(stmt);
                        } else goto dag_enomem;
                }
-               if (flags & EDG_WLL_STAT_CHILDSTAT) {
-                       char *stat_str, *s_out;
+               else {
+                       if (flags & EDG_WLL_STAT_CHILDHIST_FAST) { /* Fast Histogram */
+                               
+                               if (stat->children_hist == NULL) {
+                                       // If the histogram exists, assume that it was already filled during job state retrieval
+                                       stat->children_hist = (int*) calloc(1+EDG_WLL_NUMBER_OF_STATCODES, sizeof(int));
+                                       edg_wll_GetSubjobHistogram(ctx, job, stat->children_hist);
+                               }
+                       }
+                       else {
+                               if (stat->children_hist) {
+                                       free (stat->children_hist);
+                                       stat->children_hist = NULL;
+                               }
+                       }
+
+               }
+
+
+               if (flags & EDG_WLL_STAT_CHILDREN) {
+                       char *out[1];
                        edg_wll_Stmt sh;
-                       int num_sub, num_f, i;
-                       intJobStat *js;
+                       int num_sub, i;
 
-                       trio_asprintf(&stmt, "SELECT int_status FROM states WHERE parent_job='%|Ss'"
-                                               " AND version='%|Ss'",
-                                       md5_jobid, INTSTAT_VERSION);
+                       trio_asprintf(&stmt, "SELECT j.dg_jobid FROM states s,jobs j "
+                                       "WHERE s.parent_job='%|Ss' AND s.version='%|Ss' AND s.jobid=j.jobid",
+                               md5_jobid, INTSTAT_VERSION);
                        if (stmt != NULL) {
                                num_sub = edg_wll_ExecStmt(ctx, stmt, &sh);
                                if (num_sub >=0 ) {
-                                       i = 0;
-                                       stat->children_states = calloc(num_sub+1, sizeof(edg_wll_JobStat));
-                                       if (stat->children_states == NULL) {
-                                               edg_wll_FreeStmt(&sh);
-                                               goto dag_enomem;
-                                       }
-                                       while ((num_f = edg_wll_FetchRow(sh, &stat_str)) == 1
-                                               && i < num_sub) {
-                                               js = dec_intJobStat(stat_str, &s_out);
-                                               if (s_out != NULL && js != NULL) {
-                                                       stat->children_states[i] = js->pub;
-                                                       destroy_intJobStat_extension(js);
-                                                       free(js);
-                                                       i++;
-                                               }
-                                               free(stat_str);
+                                       while (edg_wll_FetchRow(sh, out) == 1 ) {
+                                               add_stringlist(&stat->children, out[0]);
+                                               free(out[0]); 
                                        }
                                        edg_wll_FreeStmt(&sh);
                                }
                                free(stmt);
                        } else goto dag_enomem;
+
                }
+
        }
 #endif
        free(string_jobid);