Support collection display in HTML interface.
authorJiří Filipovič <fila@ics.muni.cz>
Thu, 4 Nov 2010 15:35:25 +0000 (15:35 +0000)
committerJiří Filipovič <fila@ics.muni.cz>
Thu, 4 Nov 2010 15:35:25 +0000 (15:35 +0000)
org.glite.lb.server/src/lb_html.c
org.glite.lb.server/src/lb_html.h
org.glite.lb.server/src/lb_proto.c
org.glite.lb.server/src/lb_proto.h
org.glite.lb.server/src/userjobs.c
org.glite.lb.server/src/ws_query.c

index 507b9db..90d3786 100644 (file)
@@ -44,10 +44,12 @@ int edg_wll_QueryToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *eventsOut
 }
 
 /* construct Message-Body of Response-Line for edg_wll_UserJobs */
-int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOut, char **message)
+int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOut, edg_wll_JobStat *statsOut, char **message)
 {
+       //TODO remove quadratic complexity one day...
+
         char *pomA = NULL, *pomB;
-        int i = 0;
+        int i = 0, j;
 
         /* head */
         pomB = strdup("");
@@ -55,12 +57,42 @@ int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOu
         while (jobsOut && jobsOut[i]) {
                 char    *chid = edg_wlc_JobIdUnparse(jobsOut[i]);
 
-                asprintf(&pomA,"%s\t\t <li> <a href=\"%s\">%s</a>\r\n",
-                        pomB, chid,chid);
-
-                free(chid);
+               if (! statsOut[i].parent_job){
+                       asprintf(&pomA,"%s\t\t <li><a href=\"%s\">%s</a></li>\r\n",
+                               pomB, chid,chid);
+                       free(pomB);
+                       pomB = pomA;
+                       if (statsOut[i].jobtype == EDG_WLL_STAT_COLLECTION){
+                               asprintf(&pomA,"%s\t\t <ul>\r\n", pomB);
+                                free(pomB);
+                                pomB = pomA;
+                               j = 0;
+                               while (jobsOut[j]) {
+                                       char *chid_parent = edg_wlc_JobIdUnparse(statsOut[j].parent_job);
+                                       if (chid_parent && (strcmp(chid, chid_parent) == 0)){
+                                               char *chid_children = edg_wlc_JobIdUnparse(jobsOut[j]);
+                                               asprintf(&pomA,"%s\t\t <li><a href=\"%s\">%s</a></li>\r\n",
+                                                       pomB, chid_children,chid_children);
+                                               free(chid_children);
+                                               free(pomB);
+                                               pomB = pomA;
+                                       }
+                                       free(chid_parent);
+                                       j++;
+                               }
+                               asprintf(&pomA,"%s\t\t </ul>\r\n", pomB);
+                                free(pomB);
+                                pomB = pomA;
+                       }
+                       free(chid);
+               }
+
+// stat.jobtype == EDG_WLL_STAT_COLLECTION
+// if (stat.parent_job) chpa = edg_wlc_JobIdUnparse(stat.parent_job);
+
+                /*free(chid);
                 free(pomB);
-                pomB = pomA;
+                pomB = pomA;*/
                 i++;
         }
 
@@ -192,16 +224,20 @@ int edg_wll_GeneralJobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobSt
 {
         char *pomA = NULL, *pomB = NULL;
        int pomL = 0;
-       char    *chid,*chstat,*chis = NULL, *chos = NULL;
-       char    *jdl,*rsl;
+       char    *chid,*chstat,*chis = NULL, *chos = NULL, *chpa = NULL;
+       char    *jdl,*rsl,*children;
+       int     i;
 
        jdl = strdup("");
        rsl = strdup("");
+       children = strdup("");
        
         chid = edg_wlc_JobIdUnparse(stat.jobId);
        if (stat.isb_transfer) chis = edg_wlc_JobIdUnparse(stat.isb_transfer);
        if (stat.osb_transfer) chos = edg_wlc_JobIdUnparse(stat.osb_transfer);
+       if (stat.parent_job) chpa = edg_wlc_JobIdUnparse(stat.parent_job);
 
+       TRL("Parent job", "%s", chpa, NULL);
        TR("Status","%s",(chstat = edg_wll_StatToString(stat.state)), NULL);
        free(chstat);
        TR("Owner","%s",stat.owner, NULL);
@@ -249,13 +285,21 @@ int edg_wll_GeneralJobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobSt
        if (stat.rsl) asprintf(&rsl,"<h3>RSL</h3>\r\n"
                "<pre>%s</pre>\r\n",stat.rsl);
 
+       if ((stat.jobtype == EDG_WLL_STAT_COLLECTION) && (stat.children_num > 0)){
+               asprintf(&children, "<h3>Children</h3>\r\n");
+               for (i = 0; i < stat.children_num; i++){
+                       asprintf(&pomA,"%s\t\t <li/> <a href=\"%s\">%s</a>\r\n",
+                        children, stat.children[i], stat.children[i]);
+                       children = pomA;
+               }
+       }
 
         asprintf(&pomA, "<html>\r\n\t<body>\r\n"
                        "<h2>%s</h2>\r\n"
                        "<table halign=\"left\">%s</table>"
-                       "%s%s"
+                       "%s%s%s"
                        "\t</body>\r\n</html>",
-                       chid,pomB,jdl,rsl);
+                       chid,pomB,jdl,rsl, children);
         free(pomB);
 
         *message = pomA;
@@ -263,8 +307,10 @@ int edg_wll_GeneralJobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobSt
        free(chid);
        if (chis) free(chis);
        if (chos) free(chos);
+       if (chpa) free(chpa);
        free(jdl);
        free(rsl);
+       free(children);
         return 0;
 }
 
index e5c4eeb..faea17d 100644 (file)
@@ -28,7 +28,7 @@ limitations under the License.
 int edg_wll_QueryToHTML(edg_wll_Context,edg_wll_Event *,char **);
 int edg_wll_GeneralJobStatusToHTML(edg_wll_Context, edg_wll_JobStat, char **);
 int edg_wll_CreamJobStatusToHTML(edg_wll_Context, edg_wll_JobStat, char **);
-int edg_wll_UserInfoToHTML(edg_wll_Context, edg_wlc_JobId *, char **);
+int edg_wll_UserInfoToHTML(edg_wll_Context, edg_wlc_JobId *, edg_wll_JobStat *, char **);
 int edg_wll_UserNotifsToHTML(edg_wll_Context ctx, char **notifids, char **message);
 int edg_wll_NotificationToHTML(edg_wll_Context ctx, notifInfo *ni, char **message);
 char *edg_wll_ErrorToHTML(edg_wll_Context,int);
index 8dc453a..3116d8d 100644 (file)
@@ -642,16 +642,16 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
        /* GET /: Current User Jobs */
                else if (requestPTR[0]=='/' && (requestPTR[1]==' ' || requestPTR[1]=='?')) {
                        edg_wlc_JobId *jobsOut = NULL;
+                       edg_wll_JobStat *statesOut = NULL;
                        int     i, flags;
                        
                        flags = (requestPTR[1]=='?') ? edg_wll_string_to_stat_flags(requestPTR + 2) : 0;
 
-// FIXME: edg_wll_UserJobs should take flags as parameter
-                       switch (edg_wll_UserJobsServer(ctx,&jobsOut,NULL)) {
+                       switch (edg_wll_UserJobsServer(ctx, EDG_WLL_STAT_CHILDREN, &jobsOut, &statesOut)) {
                                case 0: if (text)
                                                edg_wll_UserInfoToText(ctx, jobsOut, &message);
                                        else if (html)
-                                               edg_wll_UserInfoToHTML(ctx, jobsOut, &message);
+                                               edg_wll_UserInfoToHTML(ctx, jobsOut, statesOut, &message);
                                        else ret = HTTP_OK;
                                        break;
                                case ENOENT: ret = HTTP_NOTFOUND; break;
@@ -699,7 +699,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                                edg_wll_SetError(ctx,EDG_WLL_ERROR_JOBID_FORMAT,fullid);
                                ret = HTTP_BADREQ;
                        }
-                       else switch (edg_wll_JobStatusServer(ctx,jobId,EDG_WLL_STAT_CLASSADS,&stat)) {
+                       else switch (edg_wll_JobStatusServer(ctx,jobId,EDG_WLL_STAT_CLASSADS | EDG_WLL_STAT_CHILDREN,&stat)) {
                                case 0: if (text) 
                                                edg_wll_JobStatusToText(ctx,stat,&message); 
                                        else if (html)
index a89417f..4b0eebe 100644 (file)
@@ -50,7 +50,7 @@ typedef struct _notifInfo{
 
 extern char *edg_wll_HTTPErrorMessage(int);
 
-extern int edg_wll_UserJobsServer(edg_wll_Context ctx, edg_wlc_JobId  **jobs, edg_wll_JobStat **states);
+extern int edg_wll_UserJobsServer(edg_wll_Context ctx, int flags, edg_wlc_JobId  **jobs, edg_wll_JobStat **states);
 
 extern int edg_wll_QuerySequenceCodeServer(edg_wll_Context ctx, edg_wlc_JobId jobid, const char *source, char **seqcode);
 
index d859a51..4fd24b9 100644 (file)
@@ -35,8 +35,10 @@ limitations under the License.
 
 int edg_wll_UserJobsServer(
        edg_wll_Context ctx,
+       int flags,
        edg_wlc_JobId   **jobs,
-       edg_wll_JobStat **states)
+       edg_wll_JobStat **states
+)
 {
        char    *userid, *stmt = NULL,
                *res = NULL;
@@ -118,7 +120,7 @@ int edg_wll_UserJobsServer(
                *states = calloc(njobs+1, sizeof(**states));
                idx = 0;
                for (i = 0; i < njobs; i++) {
-                       if (edg_wll_JobStatusServer(ctx, out[idx], -1, &(*states)[idx]) != 0)
+                       if (edg_wll_JobStatusServer(ctx, out[idx], flags, &(*states)[idx]) != 0)
                                edg_wll_ResetError(ctx);
                        idx++;
                }
index 8c6a7e4..d392836 100644 (file)
@@ -193,7 +193,7 @@ SOAP_FMAC5 int SOAP_FMAC6 __lb__UserJobs(
 
        ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap);
        memset(out, 0, sizeof *out);
-       if (edg_wll_UserJobsServer(ctx, &jobs, &states) != 0) goto fault;
+       if (edg_wll_UserJobsServer(ctx, -1, &jobs, &states) != 0) goto fault;
        if (edg_wll_UserJobsResToSoap(soap, (glite_jobid_const_t *)jobs, (const edg_wll_JobStat *)states, out) != SOAP_OK) {
                edg_wll_SetError(ctx, ENOMEM, "Couldn't create internal structures");
                goto freefault;