From ffa0567e62d3c416f009319d84d571e0ee55619c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Thu, 10 Apr 2008 12:08:33 +0000 Subject: [PATCH] Fix due to bug# 35334 - don't give up userjobs on missing events in DB. --- org.glite.lb.server/Makefile | 13 ++-- org.glite.lb.server/examples/ws_userjobs.c | 103 +++++++++++++++++++++++++++++ org.glite.lb.server/src/userjobs.c | 11 +-- org.glite.lb.server/src/ws_typeref.c.T | 13 ++-- 4 files changed, 121 insertions(+), 19 deletions(-) create mode 100644 org.glite.lb.server/examples/ws_userjobs.c diff --git a/org.glite.lb.server/Makefile b/org.glite.lb.server/Makefile index 05a5c38..e7a85d2 100644 --- a/org.glite.lb.server/Makefile +++ b/org.glite.lb.server/Makefile @@ -301,19 +301,22 @@ test_soap_conv: test_soap_conv.cpp ${WS_CLIENT_OBJS} ${CXX} -c ${CFLAGS} ${TEST_INC} $< ${LINKXX} -o $@ test_soap_conv.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} ${TEST_LIBS} -examples: ws_getversion ws_jobstat ws_query_ex ws_joblog +examples: ws_getversion ws_jobstat ws_query_ex ws_joblog ws_userjobs ws_getversion: ws_getversion.o ${WS_CLIENT_OBJS} - ${LINK} -o $@ ws_getversion.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} + ${LINK} -o $@ $< ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} ws_jobstat: ws_jobstat.o ${WS_CLIENT_OBJS} - ${LINK} -o $@ ws_jobstat.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} + ${LINK} -o $@ $< ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} ws_query_ex: ws_query_ex.o ${WS_CLIENT_OBJS} - ${LINK} -o $@ ws_query_ex.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} + ${LINK} -o $@ $< ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} ws_joblog: ws_joblog.o ${WS_CLIENT_OBJS} - ${LINK} -o $@ ws_joblog.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} + ${LINK} -o $@ $< ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} + +ws_userjobs: ws_userjobs.o ${WS_CLIENT_OBJS} + ${LINK} -o $@ $< ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} ${STATIC_LIB_BK}: ${LIB_OBJS_BK} ar crv $@ ${LIB_OBJS_BK} diff --git a/org.glite.lb.server/examples/ws_userjobs.c b/org.glite.lb.server/examples/ws_userjobs.c new file mode 100644 index 0000000..e830abb --- /dev/null +++ b/org.glite.lb.server/examples/ws_userjobs.c @@ -0,0 +1,103 @@ +#include +#include +#include + +#include "glite/security/glite_gsplugin.h" +#include "glite/lb/consumer.h" + +#include "bk_ws_H.h" +#include "ws_fault.h" + +#include "soap_version.h" +#if GSOAP_VERSION <= 20602 +#define soap_call___lb__UserJobs soap_call___ns1__UserJobs +#endif + +#include "LoggingAndBookkeeping.nsmap" + +static struct option opts[] = { + {"help", 0, NULL, 'h'}, + {"server", 1, NULL, 'm'}, +}; + +static void usage(char *me) +{ + fprintf(stderr,"usage: %s [option]\n" + "\t-h, --help Shows this screen.\n" + "\t-m, --server BK server address:port.\n" + , me); +} + +//static void printstat(edg_wll_JobStat stat, int level); + +int main(int argc,char** argv) +{ + edg_wll_Context ctx; + glite_gsplugin_Context gsplugin_ctx; + struct soap soap; + struct _lbe__UserJobs in; + struct _lbe__UserJobsResponse out; + int opt, err, i; + char *server = "http://localhost:9003/", + *name = NULL, + *st; + + + name = strrchr(argv[0],'/'); + if (name) name++; else name = argv[0]; + + while ((opt = getopt_long(argc, argv, "hm:", opts, NULL)) != EOF) switch (opt) + { + case 'h': usage(name); return 0; + case 'm': server = optarg; break; + case '?': usage(name); return 1; + } + + edg_wll_InitContext(&ctx); + glite_gsplugin_init_context(&gsplugin_ctx); + + soap_init(&soap); + soap_set_namespaces(&soap, namespaces); + + if ( soap_register_plugin_arg(&soap, glite_gsplugin, (void *)gsplugin_ctx) ) + { + soap_print_fault(&soap, stderr); + return 1; + } + + memset(&in, 0, sizeof(in)); + memset(&out, 0, sizeof(out)); + switch (err = soap_call___lb__UserJobs(&soap, server, "", &in, &out)) + { + case SOAP_OK: + printf("Server version: %p\n", &out); + assert(out.__sizejobs == out.__sizestates); + for (i = 0; i < out.__sizejobs; i++) { + st = edg_wll_StatToString(out.states[i]->state); + printf("\t%s\t%s\n", out.jobs[i], st); + free(st); + } + + break; + case SOAP_FAULT: + case SOAP_SVR_FAULT: + { + char *et,*ed; + + edg_wll_FaultToErr(&soap,ctx); + edg_wll_Error(ctx,&et,&ed); + fprintf(stderr,"%s: %s (%s)\n",argv[0],et,ed); + exit(1); + } + default: + printf("???, err=%d\n", err); + soap_print_fault(&soap, stderr); + } + + soap_end(&soap); + soap_done(&soap); + glite_gsplugin_free_context(gsplugin_ctx); + edg_wll_FreeContext(ctx); + + return 0; +} diff --git a/org.glite.lb.server/src/userjobs.c b/org.glite.lb.server/src/userjobs.c index 1ded648..1af2a50 100644 --- a/org.glite.lb.server/src/userjobs.c +++ b/org.glite.lb.server/src/userjobs.c @@ -22,7 +22,7 @@ int edg_wll_UserJobsServer( char *userid, *stmt = NULL, *res = NULL; char *can_peername; - int njobs = 0,ret,i,j,idx; + int njobs = 0,ret,i,idx; edg_wlc_JobId *out = NULL; glite_lbu_Statement sth = NULL; edg_wll_ErrorCode err = 0; @@ -86,13 +86,8 @@ 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_Error(ctx, NULL, NULL) == ENOENT) { - /* some jobs may be purged meanwhile, ignore */ - continue; - } - else break; - } + if (edg_wll_JobStatusServer(ctx, out[idx], -1, &(*states)[idx]) != 0) + edg_wll_ResetError(ctx); idx++; } } diff --git a/org.glite.lb.server/src/ws_typeref.c.T b/org.glite.lb.server/src/ws_typeref.c.T index b016442..b21aa80 100644 --- a/org.glite.lb.server/src/ws_typeref.c.T +++ b/org.glite.lb.server/src/ws_typeref.c.T @@ -711,7 +711,7 @@ ret: #define edg_wll_CommonJobsResponseToSoap do { \ - int i; \ + int count, i; \ \ assert(out); \ out->__sizejobs = 0; \ @@ -719,11 +719,13 @@ ret: out->__sizestates = 0; \ out->states = NULL; \ \ + count = 0; \ if ( jobs ) { \ for ( i = 0; jobs[i]; i++ ) ; \ - out->jobs = soap_malloc(soap, sizeof(*(out->jobs))*i); \ + count = i; \ + out->jobs = soap_malloc(soap, sizeof(*(out->jobs))*count); \ if ( !out->jobs ) return SOAP_FAULT; \ - out->__sizejobs = i; \ + out->__sizejobs = count; \ for ( i = 0; jobs[i]; i++ ) { \ char *s; \ if ( !(s = edg_wlc_JobIdUnparse(jobs[i])) ) return SOAP_FAULT; \ @@ -732,11 +734,10 @@ ret: } \ } \ if ( states ) { \ - for ( i = 0; states[i].state; i++ ) ; \ - GLITE_SECURITY_GSOAP_LIST_CREATE(soap, out, states, struct lbt__jobStatus, i); \ + GLITE_SECURITY_GSOAP_LIST_CREATE(soap, out, states, struct lbt__jobStatus, count); \ if ( !out->states ) return SOAP_FAULT; \ \ - for ( i = 0; states[i].state; i++ ) \ + for ( i = 0; i < count; i++ ) \ if ( edg_wll_StatusToSoap(soap, states+i, GLITE_SECURITY_GSOAP_LIST_GET(out->states, i)) ) \ return SOAP_FAULT; \ } \ -- 1.8.2.3