Added useful examples user_jobs and job_status from infn CVS.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Fri, 11 Feb 2005 10:46:08 +0000 (10:46 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Fri, 11 Feb 2005 10:46:08 +0000 (10:46 +0000)
Fix (not importnant) memleak in logevent.

org.glite.lb.client/Makefile
org.glite.lb.client/examples/job_status.c [new file with mode: 0644]
org.glite.lb.client/examples/user_jobs.c [new file with mode: 0644]
org.glite.lb.client/project/.cvsignore [new file with mode: 0644]
org.glite.lb.client/src/logevent.c.T

index e8c58f0..4c7350e 100644 (file)
@@ -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 (file)
index 0000000..3d64ba3
--- /dev/null
@@ -0,0 +1,231 @@
+#ident "$Header$"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+
+#include <expat.h>
+
+#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<argc; i++) {
+               int             j;
+               char            *bserver;
+               edg_wlc_JobId   job;            
+               edg_wll_JobStat status;
+
+               memset(&status,0,sizeof status);
+
+/* parse job ID */
+               if (edg_wlc_JobIdParse(argv[i],&job)) {
+                       fprintf(stderr,"%s: %s: cannot parse jobId\n",
+                               myname,argv[i]);
+                       continue;
+               }
+/* determine bookkeeping server address */
+                bserver = edg_wlc_JobIdGetServer(job);
+                if (!bserver) {
+                        fprintf(stderr,"%s: %s: cannot extract bookkeeping server address\n",
+                                myname,argv[i]);
+                         edg_wlc_JobIdFree(job);
+                        continue;
+                }
+/* use context database */
+                for (j=0; j<nsrv && strcmp(bserver,servers[j]); j++);
+                if (j==nsrv) {
+                        edg_wll_InitContext(&sctx[j]);
+                        nsrv++;
+                        servers[j] = bserver;
+                }
+
+               if (edg_wll_JobStatus(sctx[j], job, EDG_WLL_STAT_CLASSADS | EDG_WLL_STAT_CHILDREN |  EDG_WLL_STAT_CHILDSTAT, &status)) {
+                       dgerr(sctx[j],"edg_wll_JobStatus");
+                       result=1; goto cleanup2;
+               }
+
+/* print job status */
+               printstat(status,0);
+
+cleanup2:      
+               if (job) edg_wlc_JobIdFree(job);
+               if (status.state) edg_wll_FreeStatus(&status);
+           }
+               for (i=0; i<nsrv; i++) edg_wll_FreeContext(sctx[i]);
+       }
+
+       return result;
+}
+
+static void
+dgerr(edg_wll_Context ctx,char *where)
+{
+       char    *etxt,*edsc;
+
+       edg_wll_Error(ctx,&etxt,&edsc);
+       fprintf(stderr,"%s: %s: %s",myname,where,etxt);
+       if (edsc) fprintf(stderr," (%s)",edsc);
+       putc('\n',stderr);
+       free(etxt); free(edsc);
+}
+
+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("%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++) 
+                       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.client/examples/user_jobs.c b/org.glite.lb.client/examples/user_jobs.c
new file mode 100644 (file)
index 0000000..ea0a0f1
--- /dev/null
@@ -0,0 +1,95 @@
+#ident "$Header$"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <expat.h>
+
+#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 (file)
index 0000000..2b56473
--- /dev/null
@@ -0,0 +1,6 @@
+MultiStruct.pm
+StructField.pm
+at3
+events.T
+status.T
+types.T
index 65133fa..e3366ce 100644 (file)
@@ -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;
 }