From 72625e80a587251a4f06e654a94a3bcba5122636 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Filipovi=C4=8D?= Date: Fri, 3 Aug 2012 09:28:00 +0000 Subject: [PATCH] html interface for VM jobs (unfinished) --- org.glite.lb.server/src/lb_html.c | 31 +++++++++++++++++++++++++++ org.glite.lb.server/src/lb_html.h | 1 + org.glite.lb.server/src/lb_proto.c | 44 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/org.glite.lb.server/src/lb_html.c b/org.glite.lb.server/src/lb_html.c index f651c13..a025696 100644 --- a/org.glite.lb.server/src/lb_html.c +++ b/org.glite.lb.server/src/lb_html.c @@ -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
  • %s (%s)\r\n", + pomB, chid, chid, status); + else + asprintf(&pomA, "
  • %s (%s)\r\n", + chid, chid, status); + free(pomB); + pomB = pomA; + free(chid); + free(status); + } + + asprintf(&pomA, "\r\n\t\r\n" + "

    %s

    \r\n" + "%s
    " + "\t\r\n", + hostname,pomB); + free(pomB); + + *message = pomA; + + return 0; +} + char *edg_wll_ErrorToHTML(edg_wll_Context ctx,int code) { char *out,*et,*ed,*header = NULL; diff --git a/org.glite.lb.server/src/lb_html.h b/org.glite.lb.server/src/lb_html.h index de054a1..2446a30 100644 --- a/org.glite.lb.server/src/lb_html.h +++ b/org.glite.lb.server/src/lb_html.h @@ -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 */ diff --git a/org.glite.lb.server/src/lb_proto.c b/org.glite.lb.server/src/lb_proto.c index a951f85..950f10d 100644 --- a/org.glite.lb.server/src/lb_proto.c +++ b/org.glite.lb.server/src/lb_proto.c @@ -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; -- 1.8.2.3