From f6ebf4c8f3d29508e5d2b979564b57c84a2ea713 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20K=C5=99enek?= Date: Wed, 10 Dec 2008 11:28:19 +0000 Subject: [PATCH] copy from server --- org.glite.lb.ws-test/Makefile | 67 ++++++++ org.glite.lb.ws-test/examples/ws_fault.c | 88 ++++++++++ org.glite.lb.ws-test/examples/ws_getversion.c | 92 ++++++++++ org.glite.lb.ws-test/examples/ws_joblog.c | 193 +++++++++++++++++++++ org.glite.lb.ws-test/examples/ws_jobstat.c | 237 ++++++++++++++++++++++++++ org.glite.lb.ws-test/examples/ws_query_ex.c | 214 +++++++++++++++++++++++ org.glite.lb.ws-test/examples/ws_typemap.dat | 3 + 7 files changed, 894 insertions(+) create mode 100644 org.glite.lb.ws-test/examples/ws_fault.c create mode 100644 org.glite.lb.ws-test/examples/ws_getversion.c create mode 100644 org.glite.lb.ws-test/examples/ws_joblog.c create mode 100644 org.glite.lb.ws-test/examples/ws_jobstat.c create mode 100644 org.glite.lb.ws-test/examples/ws_query_ex.c create mode 100644 org.glite.lb.ws-test/examples/ws_typemap.dat diff --git a/org.glite.lb.ws-test/Makefile b/org.glite.lb.ws-test/Makefile index e69de29..142e828 100644 --- a/org.glite.lb.ws-test/Makefile +++ b/org.glite.lb.ws-test/Makefile @@ -0,0 +1,67 @@ +top_srcdir=. +stagedir=. +distdir=. +globalprefix=glite +lbprefix=lb +package=glite-lb-server +version=0.2.0 +PREFIX=/opt/glite + +glite_location=/opt/glite +globus_prefix=/opt/globus +nothrflavour=gcc32 +thrflavour=gcc32pthr +expat_prefix=/opt/expat +cares_prefix=/opt/c-ares +gsoap_prefix=/opt/gsoap +classads_prefix=/opt/classads +voms_prefix=/opt/voms + +-include Makefile.inc +-include ../project/version.properties + +version=${module.version} + +CEXAMPLES:=ws_getversion ws_jobstat ws_query_ex ws_joblog + +default all: ${CEXAMPLES} + +VPATH=${top_srcdir}/examples +CC=gcc +CFLAGS=-I${gsoap_prefix}/include -I${gsoap_prefix}/ \ + -I${stagedir}/include -I${top_srcdir}/src -I. \ + -I${globus_prefix}/include/${nothrflavour} + +COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} +LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/lib ${LDFLAGS} + +GSOAP_FILES_PREFIX:= bk_ws_ +dotless_gsoap_ver:=${shell echo ${gsoap_version} | tr -d . } +GSOAP_LIB:=-L${stagedir}/lib -lglite_security_gsoap_plugin_${dotless_gsoap_ver}_${nothrflavour} + +WS_CLIENT_OBJS:= $(GSOAP_FILES_PREFIX)C.o $(GSOAP_FILES_PREFIX)Client.o ws_fault.o ws_typeref.o +WS_CLIENT_LIBS:= ${GSOAP_LIB} -lglite_lb_common_${nothrflavour} \ + -lglite_lb_common_${nothrflavour} + +${GSOAP_FILES_PREFIX}H.h ${GSOAP_FILES_PREFIX}C.c ${GSOAP_FILES_PREFIX}Server.c ${GSOAP_FILES_PREFIX}Client.c ${GSOAP_FILES_PREFIX}ServerLib.c ${GSOAP_FILES_PREFIX}ClientLib.c LoggingAndBookkeeping.nsmap: LB.xh + ${gsoap_bin_prefix}/soapcpp2 -w -c -p ${GSOAP_FILES_PREFIX} LB.xh + +gsoap_bin_prefix:=${shell if [ -x ${gsoap_prefix}/bin/soapcpp2 ]; then echo ${gsoap_prefix}/bin; else echo ${gsoap_prefix}; fi } + + +${CEXAMPLES}: %: %.o ${WS_CLIENT_OBJS} + ${LINK} -o $@ $@.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} + +%.o %.lo: %.c soap_version.h + ${COMPILE} -c $< + +LB.xh: ws_typemap.dat ${stagedir}/interface/LB.wsdl + cp ${stagedir}/interface/LBTypes.wsdl . + ${gsoap_bin_prefix}/wsdl2h -c -t ${top_srcdir}/src/ws_typemap.dat -o $@ ${stagedir}/interface/LB.wsdl + rm -f LBTypes.wsdl + +soap_version.h: + ${gsoap_bin_prefix}/soapcpp2 /dev/null + perl -ne '$$. == 2 && /.*([0-9])\.([0-9])\.([0-9]).*/ && printf "#define GSOAP_VERSION %d%02d%02d\n",$$1,$$2,$$3' soapH.h >$@ + -rm soapC.cpp soapH.h soapStub.h soapClient.cpp soapServer.cpp soapClientLib.cpp soapServerLib.cpp + diff --git a/org.glite.lb.ws-test/examples/ws_fault.c b/org.glite.lb.ws-test/examples/ws_fault.c new file mode 100644 index 0000000..844d9f3 --- /dev/null +++ b/org.glite.lb.ws-test/examples/ws_fault.c @@ -0,0 +1,88 @@ +#include + +#include "glite/lb/context-int.h" +#include "soap_version.h" +#include "glite/security/glite_gscompat.h" + +#include "bk_ws_H.h" +#include "bk_ws_Stub.h" + + +#if GSOAP_VERSION >= 20709 + #define GFITEM reason + #define GFNUM SOAP_TYPE_lbt__genericFault +#else + #define GFITEM lbe__genericFault + #define GFNUM SOAP_TYPE__genericFault +#endif + + +void edg_wll_ErrToFault(const edg_wll_Context ctx,struct soap *soap) +{ + char *et,*ed; + struct SOAP_ENV__Detail *detail = soap_malloc(soap,sizeof *detail); +#if GSOAP_VERSION >= 20709 + struct lbt__genericFault *f = soap_malloc(soap,sizeof *f); +#else + struct _genericFault *f = soap_malloc(soap,sizeof *f); +#endif + + f->GFITEM = soap_malloc(soap,sizeof *f->GFITEM); + memset(f->GFITEM, 0, sizeof(*f->GFITEM)); + + f->GFITEM->code = edg_wll_Error(ctx,&et,&ed); + f->GFITEM->text = soap_malloc(soap,strlen(et)+1); + strcpy(f->GFITEM->text,et); + free(et); + if (ed) { + f->GFITEM->description = soap_malloc(soap,strlen(ed)+1); + strcpy(f->GFITEM->description,ed); + free(ed); + } + + detail->__type = GFNUM; +#if GSOAP_VERSION >= 20700 + detail->fault = f; +#else + detail->value = f; +#endif + detail->__any = NULL; + + soap_receiver_fault(soap,"An error occurred, see detail",NULL); + if (soap->version == 2) soap->fault->SOAP_ENV__Detail = detail; + else soap->fault->detail = detail; +} + + +void edg_wll_FaultToErr(const struct soap *soap,edg_wll_Context ctx) +{ + struct SOAP_ENV__Detail *detail; + struct lbt__genericFault *f; + + if (!soap->fault) { + edg_wll_SetError(ctx,EINVAL,"SOAP: (no error info)"); + return; + } + + detail = soap->version == 2 ? soap->fault->SOAP_ENV__Detail : soap->fault->detail; + if (detail->__type == GFNUM) { +#if GSOAP_VERSION >= 20709 + f = detail->lbe__genericFault; +#elif GSOAP_VERSION >= 20700 + f = ((struct _genericFault *) detail->fault) + ->lbe__genericFault; +#else + f = ((struct _genericFault *) detail->value) + ->lbe__genericFault; +#endif + edg_wll_SetError(ctx,f->code,f->description); + } + else { + char *s; + + asprintf(&s,"SOAP: %s", soap->version == 2 ? + GLITE_SECURITY_GSOAP_REASON(soap) : soap->fault->faultstring); + edg_wll_SetError(ctx,EINVAL,s); + free(s); + } +} diff --git a/org.glite.lb.ws-test/examples/ws_getversion.c b/org.glite.lb.ws-test/examples/ws_getversion.c new file mode 100644 index 0000000..dcd3ae7 --- /dev/null +++ b/org.glite.lb.ws-test/examples/ws_getversion.c @@ -0,0 +1,92 @@ +#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__GetVersion soap_call___ns1__GetVersion +#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__GetVersion in; + struct _lbe__GetVersionResponse out; + int opt, err; + char *server = "http://localhost:9003/", + *name = NULL; + + + 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__GetVersion(&soap, server, "", &in, &out)) + { + case SOAP_OK: printf("Server version: %s\n", out.version); 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.ws-test/examples/ws_joblog.c b/org.glite.lb.ws-test/examples/ws_joblog.c new file mode 100644 index 0000000..a3bff54 --- /dev/null +++ b/org.glite.lb.ws-test/examples/ws_joblog.c @@ -0,0 +1,193 @@ +#include +#include + +#include "glite/lb/consumer.h" +#include "glite/lb/events_parse.h" + +#include "soap_version.h" +#include "glite/security/glite_gsplugin.h" +#include "glite/security/glite_gscompat.h" + +#include "bk_ws_H.h" +#include "ws_typeref.h" +#include "ws_fault.h" + +#if GSOAP_VERSION <= 20602 +#define soap_call___lb__QueryEvents soap_call___ns1__QueryEvents +#endif + +#include "LoggingAndBookkeeping.nsmap" + +static struct option opts[] = { + {"help", 0, NULL, 'h'}, + {"server", 1, NULL, 'm'}, + {"jobid", 1, NULL, 'j'} +}; + +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" + "\t-j, --jobid ID of requested job.\n" + , me); +} + +static void free_events(edg_wll_Event *events); + +int main(int argc,char** argv) +{ + edg_wll_Context ctx; + glite_gsplugin_Context gsplugin_ctx; + struct soap *mydlo = soap_new(); + struct _lbe__QueryEventsResponse out; + struct _lbe__QueryEvents in; + edg_wll_QueryRec **jconds = NULL; + edg_wll_QueryRec j[2], e[1]; + int opt, err, i; + edg_wlc_JobId job; + char *server = "http://localhost:9003/", + *jobid = NULL, + *name = NULL; + + + name = strrchr(argv[0],'/'); + if (name) name++; else name = argv[0]; + + while ((opt = getopt_long(argc, argv, "hm:j:", opts, NULL)) != EOF) switch (opt) + { + case 'h': usage(name); return 0; + case 'm': server = optarg; break; + case 'j': jobid = optarg; break; + case '?': usage(name); return 1; + } + + if ( !jobid ) + { + printf("jobid should be given\n"); + usage(name); + return 1; + } + else if (edg_wlc_JobIdParse(jobid,&job)) { + fprintf(stderr,"%s: can't parse job ID\n",argv[1]); + return 1; + } + + + edg_wll_InitContext(&ctx); + glite_gsplugin_init_context(&gsplugin_ctx); + + soap_set_namespaces(mydlo, namespaces); + if ( soap_register_plugin_arg(mydlo, glite_gsplugin, (void *)gsplugin_ctx) ) + { + soap_print_fault(mydlo, stderr); + return 1; + } + + glite_gsplugin_set_udata(mydlo, ctx); + + /* prepare job log query */ + memset(j,0,sizeof j); + memset(e,0,sizeof e); + + j[0].attr = EDG_WLL_QUERY_ATTR_JOBID; + j[0].op = EDG_WLL_QUERY_OP_EQUAL; + j[0].value.j = job; + + + jconds = (edg_wll_QueryRec **) calloc(2, sizeof(edg_wll_QueryRec *)); + for ( i = 0; i < 1; i++ ) + { + jconds[i] = (edg_wll_QueryRec *) calloc(2, sizeof(edg_wll_QueryRec)); + jconds[i][0] = j[i]; + } + +/* econds = (edg_wll_QueryRec **) calloc(1, sizeof(edg_wll_QueryRec *)); + for ( i = 0; i < 1; i++ ) + { + econds[i] = (edg_wll_QueryRec *) calloc(1, sizeof(edg_wll_QueryRec)); + econds[i][0] = e[i]; + }*/ + + memset(&in, 0, sizeof in); + memset(&out, 0, sizeof out); + + if (edg_wll_QueryCondsExtToSoap(mydlo, (const edg_wll_QueryRec **)jconds, + &in.__sizejobConditions, &in.jobConditions) != SOAP_OK) { + printf("Error converting QueryConds to Soap!\n"); + return(1); + } + + for (i = 0; jconds[i]; i++) { + if (jconds[i]) edg_wlc_JobIdFree(jconds[i][0].value.j); + free(jconds[i]); + } + free(jconds); + + //edg_wll_QueryCondsExtToSoap(mydlo, (const edg_wll_QueryRec **)econds, + // &in.__sizeeventConditions, &in.eventConditions); + + //in.jobConditions = NULL; + //in.__sizejobConditions = 0; + in.eventConditions = NULL; + in.__sizeeventConditions = 0; + + switch (err = soap_call___lb__QueryEvents(mydlo, server, "",&in,&out)) + { + case SOAP_OK: + { + edg_wll_Event *events = NULL; + int i; + + + edg_wll_SoapToEventsQueryRes(mydlo,out,&events); + + for ( i = 0; events && events[i].type != EDG_WLL_EVENT_UNDEF; i++ ) + { + char *e = edg_wll_UnparseEvent(ctx,events+i); + fputs(e,stdout); + fputs("\n",stdout); + free(e); + } + + free_events(events); + printf("\nFound %d events\n",i); + } + break; + case SOAP_FAULT: + case SOAP_SVR_FAULT: + { + char *et,*ed; + + edg_wll_FaultToErr(mydlo,ctx); + edg_wll_Error(ctx,&et,&ed); + fprintf(stderr,"%s: %s (%s)\n",argv[0],et,ed); + soap_done(mydlo); + exit(1); + } + default: + fprintf(stderr,"err = %d\n",err); + soap_print_fault(mydlo,stderr); + } + + soap_end(mydlo/*, out.events*/); + soap_done(mydlo); + free(mydlo); + glite_gsplugin_free_context(gsplugin_ctx); + edg_wll_FreeContext(ctx); + return 0; +} + + +static void free_events(edg_wll_Event *events) +{ + int i; + + if (events) { + for (i=0; events[i].type != EDG_WLL_EVENT_UNDEF; i++) + edg_wll_FreeEvent(&(events[i])); + edg_wll_FreeEvent(&(events[i])); /* free last line */ + free(events); + events = NULL; + } +} diff --git a/org.glite.lb.ws-test/examples/ws_jobstat.c b/org.glite.lb.ws-test/examples/ws_jobstat.c new file mode 100644 index 0000000..2336b46 --- /dev/null +++ b/org.glite.lb.ws-test/examples/ws_jobstat.c @@ -0,0 +1,237 @@ +#include +#include + +#include "soap_version.h" +#include "glite/security/glite_gsplugin.h" +#include "glite/security/glite_gscompat.h" +#include "glite/lb/consumer.h" + +#include "bk_ws_H.h" +#include "ws_typeref.h" +#include "ws_fault.h" + +#if GSOAP_VERSION <= 20602 +#define soap_call___lb__JobStatus soap_call___ns1__JobStatus +#endif + +#include "LoggingAndBookkeeping.nsmap" + +static struct option opts[] = { + {"help", 0, NULL, 'h'}, + {"server", 1, NULL, 'm'}, + {"jobid", 1, NULL, 'j'} +}; + +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" + "\t-j, --jobid ID of requested job.\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 *mydlo = soap_new(); + struct _lbe__JobStatusResponse out; + struct _lbe__JobStatus in; + int opt, err; + char *server = "http://localhost:9003/", + *jobid = NULL, + *name = NULL; + + + name = strrchr(argv[0],'/'); + if (name) name++; else name = argv[0]; + + while ((opt = getopt_long(argc, argv, "hm:j:", opts, NULL)) != EOF) switch (opt) + { + case 'h': usage(name); return 0; + case 'm': server = optarg; break; + case 'j': jobid = optarg; break; + case '?': usage(name); return 1; + } + + if ( !jobid ) + { + printf("jobid should be given\n"); + usage(name); + return 1; + } + + edg_wll_InitContext(&ctx); + soap_set_namespaces(mydlo, namespaces); + glite_gsplugin_init_context(&gsplugin_ctx); + + if ( soap_register_plugin_arg(mydlo, glite_gsplugin, (void *)gsplugin_ctx) ) + { + soap_print_fault(mydlo, stderr); + return 1; + } + + glite_gsplugin_set_udata(mydlo, ctx); + + in.jobid = soap_strdup(mydlo, jobid); + in.flags = soap_malloc(mydlo, sizeof(*in.flags)); + edg_wll_JobStatFlagsToSoap(mydlo, 0, in.flags); + + switch (err = soap_call___lb__JobStatus(mydlo, server, "",&in,&out)) + { + case SOAP_OK: + { + edg_wll_JobStat s; + + edg_wll_SoapToStatus(mydlo,out.stat,&s); + printstat(s, 0); + edg_wll_FreeStatus(&s); + } + break; + case SOAP_FAULT: + case SOAP_SVR_FAULT: + { + char *et,*ed; + + edg_wll_FaultToErr(mydlo,ctx); + edg_wll_Error(ctx,&et,&ed); + fprintf(stderr,"%s: %s (%s)\n",argv[0],et,ed); + exit(1); + } + default: + fprintf(stderr,"err = %d\n",err); + soap_print_fault(mydlo,stderr); + } + + soap_end(mydlo); + soap_done(mydlo); + free(mydlo); + glite_gsplugin_free_context(gsplugin_ctx); + edg_wll_FreeContext(ctx); + + return 0; +} + +static void printstat(edg_wll_JobStat stat, int level) +{ + char *s, *j1,*j2, ind[10]; + int i; + + + for (i=0; i < level; i++) + ind[i]='\t'; + ind[i]='\0'; + + s = edg_wll_StatToString(stat.state); +/* print whole flat structure */ + printf("%sstate : %s\n", ind, s); + printf("%sjobId : %s\n", ind, j1 = edg_wlc_JobIdUnparse(stat.jobId)); + printf("%sowner : %s\n", ind, stat.owner); + switch (stat.jobtype) { + case EDG_WLL_STAT_SIMPLE: + printf("%sjobtype : SIMPLE\n", ind); + break; + case EDG_WLL_STAT_DAG: + printf("%sjobtype : DAG\n", ind); + break; + case EDG_WLL_STAT_COLLECTION: + printf("%sjobtype : COLLECTION\n", ind); + break; + case EDG_WLL_STAT_PBS: + printf("%sjobtype : PBS\n", ind); + break; + default: + break; + } + printf("%sparent_job : %s\n", ind, + j2 = edg_wlc_JobIdUnparse(stat.parent_job)); + if (stat.jobtype) {; + printf("%sseed : %s\n", ind, stat.seed); + printf("%schildren_num : %d\n", ind, stat.children_num); + printf("%schildren :\n", ind); + if (stat.children) + for (i=0; stat.children[i]; i++) + printf("%s\tchildren : %s\n", ind, stat.children[i]); + printf("%schildren_states :\n", ind); + if (stat.children_states) + for (i=0; stat.children_states[i].state; i++) + printstat(stat.children_states[i], level+1); + printf("%schildren_hist :\n",ind); + if (stat.children_hist) + for (i=1; i<=stat.children_hist[0]; i++) + printf("%s%14s %d\n", ind, edg_wll_StatToString(i-1),stat.children_hist[i]); + } + printf("%scondorId : %s\n", ind, stat.condorId); + printf("%sglobusId : %s\n", ind, stat.globusId); + printf("%slocalId : %s\n", ind, stat.localId); + printf("%sjdl : %s\n", ind, stat.jdl); + printf("%smatched_jdl : %s\n", ind, stat.matched_jdl); + printf("%sdestination : %s\n", ind, stat.destination); + printf("%snetwork server : %s\n", ind, stat.network_server); + printf("%scondor_jdl : %s\n", ind, stat.condor_jdl); + printf("%srsl : %s\n", ind, stat.rsl); + printf("%sreason : %s\n", ind, stat.reason); + printf("%slocation : %s\n", ind, stat.location); + printf("%sce_node : %s\n", ind, stat.ce_node); + printf("%ssubjob_failed : %d\n", ind, stat.subjob_failed); + printf("%sdone_code : %s\n", ind, edg_wll_done_codeToString(stat.done_code)); + printf("%sexit_code : %d\n", ind, stat.exit_code); + printf("%sresubmitted : %d\n", ind, stat.resubmitted); + printf("%scancelling : %d\n", ind, stat.cancelling); + printf("%scancelReason : %s\n", ind, stat.cancelReason); + printf("%scpuTime : %d\n", ind, stat.cpuTime); + printf("%suser_tags :\n",ind); + if (stat.user_tags) + for (i=0; stat.user_tags[i].tag; i++) printf("%s%14s = \"%s\"\n", ind, + stat.user_tags[i].tag,stat.user_tags[i].value); + printf("%sstateEnterTime : %ld.%06ld\n", ind, stat.stateEnterTime.tv_sec,stat.stateEnterTime.tv_usec); + printf("%sstateEnterTimes : \n",ind); + if (stat.stateEnterTimes) + for (i=1; i<=stat.stateEnterTimes[0]; i++) { + time_t st = stat.stateEnterTimes[i]; + + printf("%s%14s %s", ind, edg_wll_StatToString(i-1), st == 0 ? + " - not available -\n" : ctime(&st)); + } + printf("%slastUpdateTime : %ld.%06ld\n", ind, stat.lastUpdateTime.tv_sec,stat.lastUpdateTime.tv_usec); + printf("%sexpectUpdate : %d\n", ind, stat.expectUpdate); + printf("%sexpectFrom : %s\n", ind, stat.expectFrom); + printf("%sacl : %s\n", ind, stat.acl); + printf("%spayload_running: %d\n", ind, stat.payload_running); + if (stat.possible_destinations) { + printf("%spossible_destinations : \n", ind); + for (i=0; stat.possible_destinations[i]; i++) + printf("%s\t%s \n", ind, stat.possible_destinations[i]); + } + if (stat.possible_ce_nodes) { + printf("%spossible_ce_nodes : \n", ind); + for (i=0; stat.possible_ce_nodes[i]; i++) + printf("%s\t%s \n", ind, stat.possible_ce_nodes[i]); + } + /* PBS state section */ + if (stat.jobtype == EDG_WLL_STAT_PBS) { + printf("%spbs_state : %s\n", ind, stat.pbs_state); + printf("%spbs_queue : %s\n", ind, stat.pbs_queue); + printf("%spbs_owner : %s\n", ind, stat.pbs_owner); + printf("%spbs_name : %s\n", ind, stat.pbs_name); + printf("%spbs_reason : %s\n", ind, stat.pbs_reason); + printf("%spbs_scheduler : %s\n", ind, stat.pbs_scheduler); + printf("%spbs_dest_host : %s\n", ind, stat.pbs_dest_host); + printf("%spbs_pid : %d\n", ind, stat.pbs_pid); + printf("%spbs_resource_usage : %s%s\n", ind, + (stat.pbs_resource_usage) ? "\n" : "", stat.pbs_resource_usage); + printf("%spbs_exit_status : %d\n", ind, stat.pbs_exit_status); + printf("%spbs_error_desc : %s%s\n", ind, + (stat.pbs_error_desc) ? "\n" : "", stat.pbs_error_desc); + } + + printf("\n"); + + free(j1); + free(j2); + free(s); +} + diff --git a/org.glite.lb.ws-test/examples/ws_query_ex.c b/org.glite.lb.ws-test/examples/ws_query_ex.c new file mode 100644 index 0000000..b20e457 --- /dev/null +++ b/org.glite.lb.ws-test/examples/ws_query_ex.c @@ -0,0 +1,214 @@ +#include +#include + +#include "glite/lb/consumer.h" + +#include "soap_version.h" +#include "glite/security/glite_gsplugin.h" +#include "glite/security/glite_gscompat.h" + +#include "bk_ws_H.h" +#include "ws_fault.h" +#include "ws_typeref.h" + +#if GSOAP_VERSION <= 20602 +#define soap_call___lb__QueryJobs soap_call___ns1__QueryJobs +#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; + edg_wll_QueryRec **conditions = NULL; + struct soap *soap = soap_new(); + struct _lbe__QueryJobs *qjobs = NULL; + struct _lbe__QueryJobsResponse out; + int opt, err; + char *server = "http://localhost:9003/", + *name = NULL; + int i; + + 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_set_namespaces(soap, namespaces); + if ( soap_register_plugin_arg(soap, glite_gsplugin, (void *)gsplugin_ctx) ) + { + soap_print_fault(soap, stderr); + return 1; + } + + glite_gsplugin_set_udata(soap, ctx); + + conditions = (edg_wll_QueryRec **)calloc(3,sizeof(edg_wll_QueryRec *)); + + conditions[0] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); + conditions[0][0].attr = EDG_WLL_QUERY_ATTR_STATUS; + conditions[0][0].op = EDG_WLL_QUERY_OP_UNEQUAL; + conditions[0][0].value.i = EDG_WLL_JOB_DONE; + + conditions[1] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec)); + conditions[1][0].attr = EDG_WLL_QUERY_ATTR_OWNER; +#warning FIXME: NULL should work, use optional in WSDL? +// conditions[1][0].op = EDG_WLL_QUERY_OP_EQUAL; +// conditions[1][0].value.c = NULL; + conditions[1][0].op = EDG_WLL_QUERY_OP_UNEQUAL; + conditions[1][0].value.c = "x"; + + qjobs = soap_malloc(soap, sizeof(*qjobs)); + memset(qjobs, 0, sizeof(*qjobs)); + qjobs->flags = soap_malloc(soap, sizeof(*qjobs->flags)); + memset(qjobs->flags, 0, sizeof(*qjobs->flags)); + if (!qjobs->flags || edg_wll_QueryCondsExtToSoap(soap, (const edg_wll_QueryRec **)conditions, &qjobs->__sizeconditions, &qjobs->conditions) + || edg_wll_JobStatFlagsToSoap(soap, EDG_WLL_STAT_CLASSADS || EDG_WLL_STAT_CHILDREN || EDG_WLL_STAT_CHILDSTAT, qjobs->flags) ) { + char *et,*ed; + + fprintf(stderr, "%s: soap types conversion error...\n", argv[0]); + edg_wll_FaultToErr(soap, ctx); + edg_wll_Error(ctx, &et, &ed); + fprintf(stderr, "%s: %s (%s)\n", argv[0], et, ed); + exit(1); + } + + for (i = 0; conditions[i]; i++) free(conditions[i]); + free(conditions); + + err = soap_call___lb__QueryJobs(soap, server, "", qjobs, &out); + switch ( err ) { + case SOAP_OK: { + int i; + + printf("Query succesfull...\n"); + printf("%-65s%s\n\n", "jobid", "state"); + for ( i = 0; i < out.__sizejobs; i++ ) { + edg_wll_JobStatCode statCode; + + + edg_wll_SoapToJobStatCode(GLITE_SECURITY_GSOAP_LIST_GET(out.states, i)->state, &statCode); + char *s = edg_wll_StatToString(statCode); + printf("%-65s%s\n", out.jobs[i], s); + free(s); + } + } + 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: + fprintf(stderr,"err = %d\n",err); + soap_print_fault(soap,stderr); + } + + soap_end(soap); + soap_done(soap); + free(soap); + glite_gsplugin_free_context(gsplugin_ctx); + edg_wll_FreeContext(ctx); + + return 0; +} + +static void printstat(edg_wll_JobStat stat, int level) +{ + char *s, *j, ind[10]; + int i; + + + for (i=0; i < level; i++) + ind[i]='\t'; + ind[i]='\0'; + + s = edg_wll_StatToString(stat.state); +/* print whole flat structure */ + printf("%sstate : %s\n", ind, s); + printf("%sjobId : %s\n", ind, j = edg_wlc_JobIdUnparse(stat.jobId)); + printf("%sowner : %s\n", ind, stat.owner); + printf("%sjobtype : %s\n", ind, (stat.jobtype ? "DAG" : "SIMPLE") ); + printf("%sparent_job : %s\n", ind, + j = edg_wlc_JobIdUnparse(stat.parent_job)); + if (stat.jobtype) {; + printf("%sseed : %s\n", ind, stat.seed); + printf("%schildren_num : %d\n", ind, stat.children_num); + printf("%schildren :\n", ind); + if (stat.children) + for (i=0; stat.children[i]; i++) + printf("%s\tchildren : %s\n", ind, stat.children[i]); + printf("%schildren_states :\n", ind); + if (stat.children_states) + for (i=0; stat.children_states[i].state; i++) + printstat(stat.children_states[i], level+1); + printf("%schildren_hist :\n",ind); + if (stat.children_hist) + for (i=1; i<=stat.children_hist[0]; i++) + printf("%s%14s %d\n", ind, edg_wll_StatToString(i-1),stat.children_hist[i]); + } + printf("%scondorId : %s\n", ind, stat.condorId); + printf("%sglobusId : %s\n", ind, stat.globusId); + printf("%slocalId : %s\n", ind, stat.localId); + printf("%sjdl : %s\n", ind, stat.jdl); + printf("%smatched_jdl : %s\n", ind, stat.matched_jdl); + printf("%sdestination : %s\n", ind, stat.destination); + printf("%snetwork server : %s\n", ind, stat.network_server); + printf("%scondor_jdl : %s\n", ind, stat.condor_jdl); + printf("%srsl : %s\n", ind, stat.rsl); + printf("%sreason : %s\n", ind, stat.reason); + printf("%slocation : %s\n", ind, stat.location); + printf("%ssubjob_failed : %d\n", ind, stat.subjob_failed); + printf("%sdone_code : %d\n", ind, stat.done_code); + printf("%sexit_code : %d\n", ind, stat.exit_code); + printf("%sresubmitted : %d\n", ind, stat.resubmitted); + printf("%scancelling : %d\n", ind, stat.cancelling); + printf("%scancelReason : %s\n", ind, stat.cancelReason); + printf("%scpuTime : %d\n", ind, stat.cpuTime); + printf("%suser_tags :\n",ind); + if (stat.user_tags) + for (i=0; stat.user_tags[i].tag; i++) printf("%s%14s = \"%s\"\n", ind, + stat.user_tags[i].tag,stat.user_tags[i].value); + printf("%sstateEnterTime : %ld.%06ld\n", ind, stat.stateEnterTime.tv_sec,stat.stateEnterTime.tv_usec); + printf("%sstateEnterTimes : \n",ind); + if (stat.stateEnterTimes) + for (i=1; i<=stat.stateEnterTimes[0]; i++) + printf("%s%14s %s", ind, edg_wll_StatToString(i-1), (stat.stateEnterTimes[i] == 0) ? + " - not available -\n" : ctime((time_t *) &stat.stateEnterTimes[i])); + printf("%slastUpdateTime : %ld.%06ld\n", ind, stat.lastUpdateTime.tv_sec,stat.lastUpdateTime.tv_usec); + printf("%sexpectUpdate : %d\n", ind, stat.expectUpdate); + printf("%sexpectFrom : %s\n", ind, stat.expectFrom); + printf("%sacl : %s\n", ind, stat.acl); + printf("\n"); + + free(j); + free(s); +} diff --git a/org.glite.lb.ws-test/examples/ws_typemap.dat b/org.glite.lb.ws-test/examples/ws_typemap.dat new file mode 100644 index 0000000..0c3e085 --- /dev/null +++ b/org.glite.lb.ws-test/examples/ws_typemap.dat @@ -0,0 +1,3 @@ +lb = http://glite.org/wsdl/services/lb +lbt = http://glite.org/wsdl/types/lb +lbe = http://glite.org/wsdl/elements/lb -- 1.8.2.3