html interface for VM jobs (unfinished)
authorJiří Filipovič <fila@ics.muni.cz>
Fri, 3 Aug 2012 09:28:00 +0000 (09:28 +0000)
committerJiří Filipovič <fila@ics.muni.cz>
Fri, 3 Aug 2012 09:28:00 +0000 (09:28 +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

index f651c13..a025696 100644 (file)
@@ -632,6 +632,37 @@ int edg_wll_StatisticsToHTML(edg_wll_Context ctx, char **message, int text) {
        return 0;
 }
 
+int edg_wll_VMHostToHTML(edg_wll_Context ctx UNUSED_VAR, char *hostname, edg_wll_JobStat *states, char **message){
+        char *pomA = NULL, *pomB = NULL;
+       int i;
+
+        if (states) for (i = 0; states[i].state != EDG_WLL_JOB_UNDEF; i++){
+               char *status = edg_wll_VMStatToString(states[i].vm_state);
+               char *chid = edg_wlc_JobIdUnparse(states[i].jobId);
+               if (pomB)
+                       asprintf(&pomA, "%s\t\t <li> <a href=\"%s\">%s</a> (%s)\r\n",
+                               pomB, chid, chid, status);
+               else
+                       asprintf(&pomA, "<li> <a href=\"%s\">%s</a> (%s)\r\n",
+                                chid, chid, status);
+               free(pomB);
+               pomB = pomA;
+                free(chid);
+               free(status);
+        }
+
+       asprintf(&pomA, "<html>\r\n\t<body>\r\n"
+                        "<h2>%s</h2>\r\n"
+                        "<table halign=\"left\">%s</table>"
+                        "\t</body>\r\n</html>",
+                        hostname,pomB);
+        free(pomB);
+
+        *message = pomA;
+
+        return 0;
+}
+
 char *edg_wll_ErrorToHTML(edg_wll_Context ctx,int code)
 {
        char    *out,*et,*ed,*header = NULL;
index de054a1..2446a30 100644 (file)
@@ -39,6 +39,7 @@ int edg_wll_UserNotifsToHTML(edg_wll_Context ctx, char **notifids, char **messag
 int edg_wll_NotificationToHTML(edg_wll_Context ctx, notifInfo *ni, char **message);
 char *edg_wll_ErrorToHTML(edg_wll_Context,int);
 int edg_wll_FileTransferStatusToHTML(edg_wll_Context ctx, edg_wll_JobStat stat, char **message);
+int edg_wll_VMHostToHTML(edg_wll_Context ctx, char *hostname, edg_wll_JobStat *states, char **message);
 int edg_wll_StatisticsToHTML(edg_wll_Context ctx, char **message, int text);
 
 #endif /* GLITE_LB_HTML_H */
index a951f85..950f10d 100644 (file)
@@ -435,6 +435,33 @@ static int getJobsRSS(edg_wll_Context ctx, char *feedType, edg_wll_JobStat **sta
        return 0;
 }
 
+static int getVMsOnHost(edg_wll_Context ctx, char *hostname, edg_wll_JobStat **statesOut){
+        edg_wlc_JobId *jobsOut;
+        edg_wll_QueryRec **conds;
+        int i;
+
+                conds = malloc(2*sizeof(*conds));
+                conds[0] = malloc(2*sizeof(**conds));
+                conds[0][0].attr = EDG_WLL_QUERY_ATTR_DESTINATION;
+                conds[0][0].op = EDG_WLL_QUERY_OP_EQUAL;
+                conds[0][0].value.c = hostname;
+                conds[0][1].attr = EDG_WLL_QUERY_ATTR_UNDEF;
+                conds[1] = NULL;
+       
+
+        if (edg_wll_QueryJobsServer(ctx, (const edg_wll_QueryRec **)conds, 0, &jobsOut, statesOut)){
+                *statesOut = NULL;
+        }
+
+        for (i = 0; conds[i]; i++)
+                free(conds[i]);
+        free(conds);
+
+        return 0;
+}
+
+
+
 static void hup_handler(int sig) {
        purge_quit = 1;
 }
@@ -754,6 +781,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                else if (strcmp(requestMeat, "/RSS:")
                        && strcmp(requestMeat, "/NOTIF")
                        && strncmp(requestMeat, "/NOTIF:", 7)
+                       && strncmp(requestMeat, "/VMHOST:", 8)
                        && strcmp(requestMeat, "/favicon.ico")
                        && extra_opt == HTTP_EXTRA_OPTION_NONE
                        ) {
@@ -889,6 +917,22 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                                edg_wll_RSSFeed(ctx, states, requestPTR, &message);
                                edg_wll_ServerStatisticsIncrement(ctx, SERVER_STATS_RSS_VIEWS);
                        }
+       /*GET /VMHOST:[hostname] all VMs associated with hostname */
+               } else if (strncmp(requestMeat, "/VMHOST:", strlen("/VMHOST:")) == 0) {
+                       char *host = requestMeat + strlen("/VMHOST:");
+                       edg_wll_JobStat *states;
+                       if (getVMsOnHost(ctx, host, &states)){
+                               ret = HTTP_INTERNAL;
+                                goto err;
+                       }
+                       if (text){
+//                             edg_wll_VMHostToText(ctx, requestPTR + strlen("/VMHOST:"), states, &message);
+//                             edg_wll_ServerStatisticsIncrement(ctx, SERVER_STATS_TEXT_VIEWS);
+                       }
+                       else{
+                               edg_wll_VMHostToHTML(ctx, host, states, &message);
+                               edg_wll_ServerStatisticsIncrement(ctx, SERVER_STATS_HTML_VIEWS);
+                       }
                } else if (!strcmp(requestMeat, "/favicon.ico")) {
                        message=NULL;
                        ret = HTTP_NOTFOUND;