- New structure to describe inter-job relationship
authorZdeněk Šustr <sustr4@cesnet.cz>
Wed, 29 Aug 2012 08:15:38 +0000 (08:15 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Wed, 29 Aug 2012 08:15:38 +0000 (08:15 +0000)
- Related jobs, if any, are now displayed in HTML output

org.glite.lb.server/interface/store.h
org.glite.lb.server/src/jobstat.c
org.glite.lb.server/src/jobstat.h
org.glite.lb.server/src/lb_html.c

index 77ff546..15762c1 100644 (file)
@@ -50,9 +50,9 @@ int is_job_local(edg_wll_Context, glite_jobid_const_t jobId);
 int store_job_server_proxy(edg_wll_Context ctx, edg_wll_Event *event, int *register_to_JP);
 int register_subjobs_embryonic(edg_wll_Context,const edg_wll_RegJobEvent *);
 edg_wll_ErrorCode intJobStat_embryonic(edg_wll_Context ctx, glite_jobid_const_t jobid, const edg_wll_RegJobEvent *e, intJobStat *stat);
-int edg_wll_jobsconnection_create(edg_wll_Context ctx, glite_jobid_const_t jobid_from, glite_jobid_const_t jobid_to, enum edg_wll_StatJobtype jobtype, enum edg_wll_JobConnectionType connectiontype);
-int edg_wll_jobsconnection_modify(edg_wll_Context ctx, glite_jobid_const_t jobid_from, glite_jobid_const_t jobid_to, enum edg_wll_JobConnectionType);
-int edg_wll_jobsconnection_modifyall(edg_wll_Context ctx, glite_jobid_const_t jobid, enum edg_wll_JobConnectionType oldtype, enum edg_wll_JobConnectionType newtype);
+int edg_wll_jobsconnection_create(edg_wll_Context ctx, glite_jobid_const_t jobid_from, glite_jobid_const_t jobid_to, enum edg_wll_StatJobtype jobtype, edg_wll_JobConnectionType connectiontype);
+int edg_wll_jobsconnection_modify(edg_wll_Context ctx, glite_jobid_const_t jobid_from, glite_jobid_const_t jobid_to, edg_wll_JobConnectionType);
+int edg_wll_jobsconnection_modifyall(edg_wll_Context ctx, glite_jobid_const_t jobid, edg_wll_JobConnectionType oldtype, edg_wll_JobConnectionType newtype);
 int edg_wll_jobsconnection_purgeall(edg_wll_Context ctx, glite_jobid_const_t jobid);
 
 int edg_wll_delete_event(edg_wll_Context,const char *, int);
index 95c7f13..14a5679 100644 (file)
@@ -1542,12 +1542,14 @@ cleanup:
 
 }
 
-edg_wll_ErrorCode edg_wll_getConnectedJobs(edg_wll_Context ctx, glite_jobid_const_t job,  enum edg_wll_JobConnectionType connection, glite_jobid_t *connected_jobs, enum edg_wll_StatJobtype *job_types, enum edg_wll_JobConnectionType *connection_types) {
+edg_wll_ErrorCode edg_wll_getConnectedJobs(edg_wll_Context ctx, glite_jobid_const_t job, edg_wll_JobConnectionType connection, edg_wll_RelationshipRecord **connections) {
        char *stmt;
        glite_lbu_Statement sh = NULL;
-       int i, n;
+       int i = 0, n;
        char *job_u;
        char *out_stat[3];
+       glite_jobid_t   tempjobid;
+       edg_wll_RelationshipRecord *conns = NULL;
 
        job_u = edg_wlc_JobIdGetUnique(job);
 
@@ -1561,25 +1563,24 @@ edg_wll_ErrorCode edg_wll_getConnectedJobs(edg_wll_Context ctx, glite_jobid_cons
        n = edg_wll_ExecSQL(ctx,stmt,&sh);
        free(stmt);
 
-       connected_jobs = (glite_jobid_t*)malloc((n+1)*sizeof(glite_jobid_t));
-       job_types = (enum edg_wll_StatJobtype*)malloc((n+1)*sizeof(enum edg_wll_StatJobtype));
-       connection_types = (enum edg_wll_JobConnectionType*)malloc((n+1)*sizeof(enum edg_wll_JobConnectionType));
-
-       i = 0;
        if (n > 0) {
+               conns = (edg_wll_RelationshipRecord*)malloc((n+1)*sizeof(edg_wll_RelationshipRecord));
                while (edg_wll_FetchRow(ctx, sh, sizeof(out_stat)/sizeof(out_stat[0]), NULL, out_stat) == 3) {
-                       glite_jobid_recreate((const char*) ctx->srvName, ctx->srvPort, out_stat[0], &(connected_jobs[i]));
-                       job_types[i] = atoi(out_stat[1]);
-                       connection_types[i] = atoi(out_stat[2]);
+                       glite_jobid_recreate((const char*) ctx->srvName, ctx->srvPort, out_stat[0], &tempjobid);
+                       conns[i].jobid = tempjobid;
+                       conns[i].jobtype = atoi(out_stat[1]);
+                       conns[i].reltype = atoi(out_stat[2]);
                        free(out_stat[0]);
                        free(out_stat[1]);
                        free(out_stat[2]);
                        i++;
                }
+               conns[i].jobid = NULL;
+               conns[i].jobtype = -1; 
+               conns[i].reltype = EDG_WLL_JOBCONNECTION_UNDEFINED;
        }
-       connected_jobs[i] = NULL;
-       job_types[i] = EDG_WLL_NUMBER_OF_JOBTYPES; /* no undefined value */
-       connection_types[i] = EDG_WLL_JOBCONNECTION_UNDEFINED;
+
+       *connections = conns;
 
        return edg_wll_Error(ctx, NULL, NULL);
 }
index efd9fe7..9918cb1 100644 (file)
@@ -34,13 +34,6 @@ limitations under the License.
 #define HISTORY_SEPARATOR_SIZE 2
 
 
-enum edg_wll_JobConnectionType {
-        EDG_WLL_JOBCONNECTION_UNDEFINED,
-        EDG_WLL_JOBCONNECTION_ACTIVE,
-        EDG_WLL_JOBCONNECTION_INACTIVE,
-        EDG_WLL_JOBCONNECTION_CANCELLED
-};
-
 int edg_wll_JobStatusServer(edg_wll_Context, glite_jobid_const_t, int, edg_wll_JobStat *);
 
 
@@ -80,6 +73,6 @@ edg_wll_ErrorCode edg_wll_StoreSubjobHistogram(edg_wll_Context, glite_jobid_cons
 edg_wll_Event* fetch_history(edg_wll_Context ctx, edg_wll_JobStat *stat);
 int collate_history(edg_wll_Context ctx, edg_wll_JobStat *stat, edg_wll_Event* events, int authz_flags);
 //int clear_history();
-edg_wll_ErrorCode edg_wll_getConnectedJobs(edg_wll_Context ctx, glite_jobid_const_t job,  enum edg_wll_JobConnectionType connection, glite_jobid_t *connected_jobs, enum edg_wll_StatJobtype *job_types, enum edg_wll_JobConnectionType *connection_types);
+edg_wll_ErrorCode edg_wll_getConnectedJobs(edg_wll_Context ctx, glite_jobid_const_t job, edg_wll_JobConnectionType connection, edg_wll_RelationshipRecord **connections);
 
 #endif /* GLITE_LB_LBS_JOBSTAT_H*/
index bfd0b87..d2a1db0 100644 (file)
@@ -26,6 +26,7 @@ limitations under the License.
 #include "index.h"
 #include "server_state.h"
 #include "lb_authz.h"
+#include "jobstat.h"
 
 #include "glite/lb/context-int.h"
 #include "glite/lb/xml_conversions.h"
@@ -105,6 +106,15 @@ int jobstat_cmp (const void *a, const void *b) {
        return strcmp(((JobIdSorter*)a)->id_unparsed, ((JobIdSorter*)b)->id_unparsed);
 }
 
+int relationship_cmp (const void *a, const void *b) {
+       // This code should sort IDs by parent ID first, then by JobID.
+       if (((edg_wll_RelationshipRecord*)a)->reltype > ((edg_wll_RelationshipRecord*)b)->reltype) return (1);
+       if (((edg_wll_RelationshipRecord*)a)->reltype < ((edg_wll_RelationshipRecord*)b)->reltype) return (-1);
+       if (((edg_wll_RelationshipRecord*)a)->jobtype > ((edg_wll_RelationshipRecord*)b)->jobtype) return (1);
+       if (((edg_wll_RelationshipRecord*)a)->jobtype < ((edg_wll_RelationshipRecord*)b)->jobtype) return (-1);
+       return (0);
+}
+
 int edg_wll_ConfigurationToHTML(edg_wll_Context ctx, int admin, char **message, int text){
         char *a = NULL, *b, *header, *out, *out_tmp;
         int i = 0;
@@ -419,11 +429,12 @@ int edg_wll_NotificationToHTML(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, ch
 /* construct Message-Body of Response-Line for edg_wll_JobStatus */
 int edg_wll_GeneralJobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat, char **message, int text)
 {
-        char *out_tmp = NULL, *header = NULL, *out, *history = NULL, *jdl = NULL, *cream_jdl = NULL, *rsl = NULL, *children = NULL, *chtemp;
+        char *out_tmp = NULL, *header = NULL, *out, *history = NULL, *jdl = NULL, *cream_jdl = NULL, *rsl = NULL, *children = NULL, *relations = NULL, *chtemp;
        time_t time;
 
         char *pomA = NULL;
        int     i;
+       size_t  linlen, outlen;
 
         chtemp = edg_wlc_JobIdUnparse(stat.jobId);
 
@@ -684,8 +695,45 @@ int edg_wll_GeneralJobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobSt
                }
        }
 
-       asprintf(&pomA, "%s%s%s%s%s%s%s", 
+       if (!text) {
+               edg_wll_RelationshipRecord *connections;
+               int total = 0;
+
+               edg_wll_getConnectedJobs(ctx, stat.jobId, EDG_WLL_JOBCONNECTION_UNDEFINED, &connections);
+
+               if (connections) {
+                       outlen = asprintf(&relations, "<h3>Related Jobs</h3>\n<UL>\n");
+                       for( total = 0; connections[total].jobid; total++ );
+               
+                       qsort(connections, total, sizeof(edg_wll_RelationshipRecord), relationship_cmp); 
+
+                       for( i = 0; connections[i].jobid; i++ ) {
+                               chtemp = edg_wlc_JobIdUnparse(connections[i].jobid);
+
+                               linlen = asprintf(&pomA, "<li><a href=\"%s\">%s</a> <span class=\"jobtype\">&mdash; %s</span> <span class=\"jobstate\">%s</span></li>\n%s",
+                                       chtemp,
+                                       chtemp,
+                                       connections[i].jobtype >= 0 && connections[i].jobtype < EDG_WLL_NUMBER_OF_JOBTYPES ?
+                                               edg_wll_StatusJobtypeNames[connections[i].jobtype] : "Unknown!",
+                                       edg_wll_JobConnectionTypeNames[connections[i].reltype],
+                                       connections[i+1].jobid ? "" : "</UL>\n");
+
+                               relations = realloc(relations, sizeof(char) * (outlen + linlen + 1));
+                               strcat(relations, pomA);
+                               outlen = outlen + linlen;
+                               free(pomA);
+
+                               free(chtemp);
+                               edg_wlc_JobIdFree(connections[i].jobid);
+                       }
+                       free(connections);
+                       
+               }
+       }
+
+       asprintf(&pomA, "%s%s%s%s%s%s%s%s", 
                        out,
+                       relations ? relations : "",
                        history ? history : "",
                        jdl ? jdl : "",
                        cream_jdl ? cream_jdl : "",
@@ -699,6 +747,7 @@ int edg_wll_GeneralJobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobSt
        free(jdl);
        free(rsl);
        free(children);
+       free(relations);
         return 0;
 }