From: František Dvořák Date: Fri, 11 Feb 2005 10:46:08 +0000 (+0000) Subject: Added useful examples user_jobs and job_status from infn CVS. X-Git-Tag: gridsite-core_R_1_1_5~14 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=e4c21f3f6a39da6e78366ca8412c9713b9c04ca6;p=jra1mw.git Added useful examples user_jobs and job_status from infn CVS. Fix (not importnant) memleak in logevent. --- diff --git a/org.glite.lb.client/Makefile b/org.glite.lb.client/Makefile index e8c58f0..4c7350e 100644 --- a/org.glite.lb.client/Makefile +++ b/org.glite.lb.client/Makefile @@ -97,6 +97,8 @@ EXT_LIB:= ${EXPAT_LIBS} \ TEST_LIBS:=-L${cppunit_prefix}/lib -lcppunit TEST_INC:=-I${cppunit_prefix}/include +COMMON_LIB=-lglite_lb_common_${nothrflavour} + LDFLAGS:=-L${stagedir}/lib \ ${COVERAGE_FLAGS} @@ -136,6 +138,7 @@ THRPLUSLIB:=libglite_lb_clientpp_${thrflavour}.la TOOLS:=dump load purge EXAMPLES:=log_usertag_proxy job_log job_reg feed_shark notify query_ext query_seq_code stats abort_job +EXAMPLES_CL=user_jobs job_status FAKE_EXAMPLES:=job_log_fake MAN_GZ:=glite-lb-logevent.1.gz @@ -167,6 +170,9 @@ logevent: logevent.o args.o ${TOOLS} ${EXAMPLES}: %: %.o ${LINK} -o $@ $< ${LIB} ${EXT_LIB} ${GLOBUS_LIBS} +${EXAMPLES_CL}: %: %.o + ${LINK} -o $@ $< ${LIB} ${COMMON_LIB} ${EXT_LIB} ${GLOBUS_LIBS} + ${FAKE_EXAMPLES}: %: %.o ${FAKELIB} ${LINK} -o $@ $< ${FAKELIB} ${TEST_LIBS} ${EXT_LIB} ${GLOBUS_LIBS} @@ -219,7 +225,7 @@ default: all compile all: check_version ${LIB} ${THRLIB} ${TOOLS} logevent ${PLUSLIB} ${THRPLUSLIB} examples ${MAN_GZ} -examples: ${EXAMPLES} ${sh_PROGS} +examples: ${EXAMPLES} ${EXAMPLES_CL} ${sh_PROGS} fake: ${FAKE_EXAMPLES} @@ -265,7 +271,7 @@ install: for p in ${TOOLS} logevent; do \ ${INSTALL} -m 755 "$$p" "${PREFIX}/bin/glite-lb-$$p"; \ done - for p in ${TOOLS} logevent ${EXAMPLES} ${sh_PROGS}; do \ + for p in ${TOOLS} logevent ${EXAMPLES} ${EXAMPLES_CL} ${sh_PROGS}; do \ ${INSTALL} -m 755 "$$p" "${PREFIX}/examples/glite-lb-$$p"; \ done ${INSTALL} -m 644 ${MAN_GZ} ${PREFIX}/share/man/man1 diff --git a/org.glite.lb.client/examples/job_status.c b/org.glite.lb.client/examples/job_status.c new file mode 100644 index 0000000..3d64ba3 --- /dev/null +++ b/org.glite.lb.client/examples/job_status.c @@ -0,0 +1,231 @@ +#ident "$Header$" + +#include +#include +#include +#include +#include + +#include + +#include "glite/lb/consumer.h" +#include "glite/lb/xml_conversions.h" + +static void dgerr(edg_wll_Context,char *); +static void printstat(edg_wll_JobStat,int); + +#define MAX_SERVERS 20 + +static char *myname; + + +int main(int argc,char *argv[]) +{ + edg_wll_Context ctx, sctx[MAX_SERVERS]; + int i, result=0, nsrv=0; + char *servers[MAX_SERVERS]; + char *errstr = NULL; + + + myname = argv[0]; + printf("\n"); + + if (argc < 2 || strcmp(argv[1],"--help") == 0) { + fprintf(stderr,"Usage: %s job_id [job_id [...]]\n",argv[0]); + fprintf(stderr," %s -all\n",argv[0]); + return 1; + } + else if (argc >= 2 && strcmp(argv[1],"-all") == 0) { + edg_wll_JobStat *statesOut; + edg_wlc_JobId *jobsOut; + edg_wll_QueryRec jc[2]; + + jobsOut = NULL; + statesOut = NULL; +/* init context */ + if (edg_wll_InitContext(&ctx)) { + fprintf(stderr,"%s: cannot initialize edg_wll_Context\n",myname); + exit(1); + } +/* retrieve job ID's */ + memset(jc,0,sizeof jc); + + jc[0].attr = EDG_WLL_QUERY_ATTR_OWNER; + jc[0].op = EDG_WLL_QUERY_OP_EQUAL; + jc[0].value.c = NULL; /* is NULL, peerName filled in on server side */ + jc[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; + + //if (edg_wll_QueryJobs(ctx,jc,EDG_WLL_STAT_CLASSADS | EDG_WLL_STAT_CHILDREN | EDG_WLL_STAT_CHILDSTAT, + result = edg_wll_QueryJobs(ctx,jc,0,&jobsOut, &statesOut); + if (result == E2BIG) { + int r; + edg_wll_Error(ctx, NULL, &errstr); + if (edg_wll_GetParam(ctx, EDG_WLL_PARAM_QUERY_RESULTS, &r)) { + dgerr(ctx,"edg_wll_GetParam(EDG_WLL_PARAM_QUERY_RESULTS)"); + free(errstr); + result=1; goto cleanup; + } + if (r != EDG_WLL_QUERYRES_LIMITED) goto late_error; + } else if (result) { + dgerr(ctx,"edg_wll_QueryJobs"); + result=1; goto cleanup; + } + +/* retrieve and print status of each job */ + for (i=0; statesOut[i].state; i++) + printstat(statesOut[i],0); + +late_error: if (result) { + edg_wll_SetError(ctx, result, errstr); + free(errstr); + dgerr(ctx,"edg_wll_QueryJobs"); + result=1; + } + +cleanup: + if (jobsOut) + { + for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]); + free(jobsOut); + } + if (statesOut) + { + for (i=0; statesOut[i].state; i++) edg_wll_FreeStatus(&statesOut[i]); + free(statesOut); + } + edg_wll_FreeContext(ctx); + } + else { + for (i=1; i +#include +#include + +#include + +#include "glite/lb/context.h" +#include "glite/lb/xml_conversions.h" +#include "glite/lb/consumer.h" + +int main(int argc,char **argv) +{ + edg_wll_Context ctx; + char *errt,*errd; + edg_wlc_JobId *jobs = NULL; + edg_wll_JobStat *states = NULL; + int i,j; + char *owner = NULL; + + switch (argc) { + case 1 : break; + + case 2 : /* fprintf(stderr,"\'userid\' option not implemented yet.\n"); */ + if ( strcmp(argv[1],"--help")) { + owner = strdup(argv[1]); + break; + } + /* else : fall through */ + + default: fprintf(stderr,"usage: %s [userid]\n",argv[0]); + return 1; + } + + + edg_wll_InitContext(&ctx); + + if (edg_wll_UserJobs(ctx,&jobs,&states)) goto err; + for (i=0; states[i].state != EDG_WLL_JOB_UNDEF; i++) { + char *id = edg_wlc_JobIdUnparse(states[i].jobId), + *st = edg_wll_StatToString(states[i].state); + + if (!states[i].parent_job) { + if (states[i].jobtype == EDG_WLL_STAT_SIMPLE) { + printf(" %s .... %s %s\n", id, st, (states[i].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[i].done_code) : "" ); + } + else if (states[i].jobtype == EDG_WLL_STAT_DAG) { + printf("DAG %s .... %s %s\n", id, st, (states[i].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[i].done_code) : ""); + for (j=0; states[j].state != EDG_WLL_JOB_UNDEF; j++) { + if (states[j].parent_job) { + char *par_id = edg_wlc_JobIdUnparse(states[j].parent_job); + + if (!strcmp(id,par_id)) { + char *sub_id = edg_wlc_JobIdUnparse(states[j].jobId), + *sub_st = edg_wll_StatToString(states[j].state); + + printf(" `- %s .... %s %s\n", sub_id, sub_st, (states[j].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[j].done_code) : ""); + free(sub_id); + free(sub_st); + } + free(par_id); + } + } + } + } + + free(id); + free(st); + } + + printf("\nFound %d jobs\n",i); + +err: + free(owner); + if (jobs) { + for (i=0; jobs[i]; i++) edg_wlc_JobIdFree(jobs[i]); + free(jobs); + } + + if (states) { + for (i=0; states[i].state; i++) edg_wll_FreeStatus(&states[i]); + free(states); + } + + if (edg_wll_Error(ctx,&errt,&errd)) { + fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); + edg_wll_FreeContext(ctx); + return 1; + } + + edg_wll_FreeContext(ctx); + return 0; +} + diff --git a/org.glite.lb.client/project/.cvsignore b/org.glite.lb.client/project/.cvsignore new file mode 100644 index 0000000..2b56473 --- /dev/null +++ b/org.glite.lb.client/project/.cvsignore @@ -0,0 +1,6 @@ +MultiStruct.pm +StructField.pm +at3 +events.T +status.T +types.T diff --git a/org.glite.lb.client/src/logevent.c.T b/org.glite.lb.client/src/logevent.c.T index 65133fa..e3366ce 100644 --- a/org.glite.lb.client/src/logevent.c.T +++ b/org.glite.lb.client/src/logevent.c.T @@ -282,6 +282,9 @@ gen qq{\t //edg_wll_Log$t(); if (ff) free(ff); if (fmt_arg) free(fmt_arg); +#ifdef ENABLE_REASON_LENGTH + if (reason) free(reason); +#endif return err; }