From 86e0557d043cc2c20e813ed6b3594f943b36ba43 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Filipovi=C4=8D?= Date: Mon, 27 Apr 2009 13:31:36 +0000 Subject: [PATCH] First version of RSS feed for finished jobs. TODO: - configure time of RSS feed (currently feds all jobs) - only indexed queries - add more feeds... --- org.glite.lb.server/src/lb_proto.c | 57 +++++++++++++++++++++++++- org.glite.lb.server/src/lb_rss.c | 84 ++++++++++++++++++++++++++++++++++++++ org.glite.lb.server/src/lb_rss.h | 9 ++++ 3 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 org.glite.lb.server/src/lb_rss.c create mode 100644 org.glite.lb.server/src/lb_rss.h diff --git a/org.glite.lb.server/src/lb_proto.c b/org.glite.lb.server/src/lb_proto.c index 7a07549..47632b0 100644 --- a/org.glite.lb.server/src/lb_proto.c +++ b/org.glite.lb.server/src/lb_proto.c @@ -286,6 +286,49 @@ static void freeNotifInfo(notifInfo *ni){ if (ni->conditions_text) free(ni->conditions_text); } +static int getJobsRSS(edg_wll_Context ctx, char *feedType, edg_wll_JobStat **statesOut){ + edg_wlc_JobId *jobsOut; + //edg_wll_JobStat *statesOut; + edg_wll_QueryRec **conds; + int i; + + char *can_peername = edg_wll_gss_normalize_subj(ctx->peerName, 0); + + if (strncmp(feedType, "finished", strlen("finished")) == 0){ + conds = malloc(3*sizeof(*conds)); + conds[0] = malloc(2*sizeof(**conds)); + conds[0][0].attr = EDG_WLL_QUERY_ATTR_OWNER; + conds[0][0].op = EDG_WLL_QUERY_OP_EQUAL; + conds[0][0].value.c = can_peername; + conds[0][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; + conds[1] = malloc(4*sizeof(**conds)); + conds[1][0].attr = EDG_WLL_QUERY_ATTR_STATUS; + conds[1][0].op = EDG_WLL_QUERY_OP_EQUAL; + conds[1][0].value.i = EDG_WLL_JOB_DONE; + conds[1][1].attr = EDG_WLL_QUERY_ATTR_STATUS; + conds[1][1].op = EDG_WLL_QUERY_OP_EQUAL; + conds[1][1].value.i = EDG_WLL_JOB_ABORTED; + conds[1][2].attr = EDG_WLL_QUERY_ATTR_STATUS; + conds[1][2].op = EDG_WLL_QUERY_OP_EQUAL; + conds[1][2].value.i = EDG_WLL_JOB_CANCELLED; + conds[1][3].attr = EDG_WLL_QUERY_ATTR_UNDEF; + conds[2] = NULL; + } + else{ + *statesOut = NULL; + return -1; + } + + edg_wll_QueryJobsServer(ctx, conds, 0, &jobsOut, statesOut); + + for (i = 0; conds[i]; i++) + free(conds[i]); + free(conds); + free(can_peername); + + return 0; +} + edg_wll_ErrorCode edg_wll_ProtoV21(edg_wll_Context ctx, char *request,char **headers,char *messageBody, char **response,char ***headersOut,char **bodyOut) @@ -555,7 +598,8 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, } /* GET /[jobId]: Job Status */ - else if (*requestPTR=='/' + else if (*requestPTR=='/' + && strncmp(requestPTR, "/RSS", strlen("/RSS")) && strncmp(requestPTR, "/NOTIF", strlen("/NOTIF")) && *(requestPTR+strlen("/NOTIF")-1) != ':' && !isspace(*(requestPTR+strlen("/NOTIF")-1))) { @@ -635,6 +679,17 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, freeNotifInfo(&ni); + /*GET /RSS:[feed type] RSS feed */ + } else if (strncmp(requestPTR, "/RSS:", strlen("/RSS:")) == 0){ + edg_wll_JobStat *states; + char *feedType = requestPTR + strlen("/RSS:"); + if (getJobsRSS(ctx, feedType, &states) < 0){ + ret = HTTP_INTERNAL; + goto err; + } + edg_wll_RSSFeed(ctx, states, requestPTR, &message); + // freeJobStates + /* GET [something else]: not understood */ } else ret = HTTP_BADREQ; free(requestPTR); requestPTR = NULL; diff --git a/org.glite.lb.server/src/lb_rss.c b/org.glite.lb.server/src/lb_rss.c new file mode 100644 index 0000000..7c36202 --- /dev/null +++ b/org.glite.lb.server/src/lb_rss.c @@ -0,0 +1,84 @@ +#ident "$Header:" + +#include "lb_rss.h" +#include "lb_proto.h" + +#include "glite/lb/context-int.h" + +#include +#include +#include +#include +#include + +#ifdef __GNUC__ +#define UNUSED_VAR __attribute__((unused)) +#else +#define UNUSED_VAR +#endif + +#define TR(type, field) \ + if (field){ \ + int l = asprintf(&pomA, type, (field)); \ + pomB = realloc(pomB, sizeof(*pomB)*(pomL+l+1)); \ + strcpy(pomB+pomL, pomA); \ + pomL += l; \ + free(pomA); pomA = NULL; \ + } + +#define TRC(str) \ + { \ + int l = asprintf(&pomA, str); \ + pomB = realloc(pomB, sizeof(*pomB)*(pomL+l+1)); \ + strcpy(pomB+pomL, pomA); \ + pomL += l; \ + free(pomA); pomA = NULL; \ + } + + +int edg_wll_RSSFeed(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat *states, char *request, char **message){ + char *pomA = NULL, *pomB = NULL; + int pomL = 0; + int i; + char *chid, *chstat, *rss_link, *tmp; + time_t time; + + TRC("\n\n\n"); + TRC("LB feed\n"); + asprintf(&rss_link, "https://%s:%i%s", ctx->srvName, ctx->srvPort, request); + for (tmp = rss_link; *tmp && !isspace(*tmp); tmp++); + *tmp = 0; + TR("%s\n", rss_link); + TRC("List of jobs."); + if (states) for (i = 0; states[i].state != EDG_WLL_JOB_UNDEF; i++){ + TRC("\n"); + TR("%s\n", (chid = edg_wlc_JobIdUnparse(states[i].jobId))); + TR("%s\n", chid); + TR("%s\n", chid); + // strip description to allow new lines + TR("Status: %s\n", (chstat = edg_wll_StatToString(states[i].state))); + TRC("\n\n"); + time = states[i].stateEnterTime.tv_sec; + TR("State entered: %s\n", ctime(&time)); + TRC("\n\n"); + TR("Destination: %s\n", states[i].destination); + TRC("\n"); + + + /*TRC(""); + TR("Status: %s\n", (chstat = edg_wll_StatToString(states[i].state))); + time = states[i].stateEnterTime.tv_sec; + TR("State entered %s\n", ctime(&time)); + TRC("\n"); + TR("%s\n", chid); + TRC("\n");*/ + free(chid); + free(chstat); + } + TRC("\n"); + + *message = pomB; + + return 0; +} + diff --git a/org.glite.lb.server/src/lb_rss.h b/org.glite.lb.server/src/lb_rss.h new file mode 100644 index 0000000..e690ee7 --- /dev/null +++ b/org.glite.lb.server/src/lb_rss.h @@ -0,0 +1,9 @@ +#ifndef GLITE_LB_RSS_H +#define GLITE_LB_RSS_H + +#include "glite/lb/context-int.h" +#include "glite/lb/jobstat.h" + +int edg_wll_RSSFeed(edg_wll_Context ctx, edg_wll_JobStat *states, char *request, char **message); + +#endif /* GLITE_LB_RSS_H */ -- 1.8.2.3