From e082a47bfa07e78b3f4559eeafdd781f5a3d7a32 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20=C5=A0kr=C3=A1bal?= Date: Tue, 22 Mar 2005 14:16:23 +0000 Subject: [PATCH] - logging to the LBProxy via example programs now possible --- org.glite.lb.client/examples/gen_begin | 10 +- org.glite.lb.client/examples/job_status.c | 170 ++++++++++++++++-------------- org.glite.lb.client/examples/user_jobs.c | 42 +++++--- org.glite.lb.client/src/logevent.c.T | 38 ++++--- 4 files changed, 149 insertions(+), 111 deletions(-) diff --git a/org.glite.lb.client/examples/gen_begin b/org.glite.lb.client/examples/gen_begin index a7565a4..79e7bc0 100755 --- a/org.glite.lb.client/examples/gen_begin +++ b/org.glite.lb.client/examples/gen_begin @@ -8,10 +8,11 @@ LOGFD=${LOGFD:-2} LOGEV=glite-lb-logevent${SUFFIX} JOB_REG=${JOB_REG:-`dirname $0`/glite-lb-job_reg}${SUFFIX} EDG_JOBID= +LBPROXY= usage() { - echo "Usage : $0 [-m bkserver_machine_name][-j job_id]" + echo "Usage : $0 [-x] [-m bkserver_machine_name][-j job_id]" exit 4 } @@ -20,6 +21,7 @@ while test -n "$1" do case "$1" in "-m") shift; BKSERVER_HOST="$1" ;; + "-x") shift; LBPROXY="-x" ;; "-j") shift; EDG_JOBID="$1" ;; "*") usage ;; esac @@ -32,7 +34,7 @@ if [ -z "$EDG_JOBID" ] then # initial sequence code & jobid (normaly returned by job_reg) EDG_JOBID= - SCRIPT=`$JOB_REG -m $BKSERVER_HOST -s UserInterface | tail -n 2` + SCRIPT=`$JOB_REG $LBPROXY -m $BKSERVER_HOST -s UserInterface | tail -n 2` eval $SCRIPT test -z "$EDG_JOBID" && exit 4 echo EDG_JOBID=$EDG_JOBID @@ -42,8 +44,8 @@ fi send_log_ev() { - echo $LOGEV -j "$EDG_JOBID" -c "$EDG_WL_SEQUENCE" "$@" 1>&$LOGFD - EDG_WL_SEQUENCE=`$LOGEV -j $EDG_JOBID -c $EDG_WL_SEQUENCE "$@" 2>/dev/null` + echo $LOGEV $LBPROXY -j "$EDG_JOBID" -c "$EDG_WL_SEQUENCE" "$@" 1>&$LOGFD + EDG_WL_SEQUENCE=`$LOGEV $LBPROXY -j $EDG_JOBID -c $EDG_WL_SEQUENCE "$@" 2>/dev/null` test $? -ne 0 -o -z "$EDG_WL_SEQUENCE" && exit 4 true } diff --git a/org.glite.lb.client/examples/job_status.c b/org.glite.lb.client/examples/job_status.c index dd25c45..489d194 100644 --- a/org.glite.lb.client/examples/job_status.c +++ b/org.glite.lb.client/examples/job_status.c @@ -19,85 +19,78 @@ static void printstat(edg_wll_JobStat,int); static char *myname; +static void usage(char *); +static int query_all(edg_wll_Context, edg_wll_JobStat **, edg_wlc_JobId **); int main(int argc,char *argv[]) { - edg_wll_Context ctx, sctx[MAX_SERVERS]; - int i, result=0, nsrv=0; + edg_wll_Context sctx[MAX_SERVERS]; char *servers[MAX_SERVERS]; - char *errstr = NULL; + int i, result=0, nsrv=0; 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) { + if ( argc < 2 || strcmp(argv[1],"--help") == 0 ) { usage(argv[0]); return 0; } + + if ( edg_wll_InitContext(&sctx[0]) ) { + fprintf(stderr,"cannot initialize edg_wll_Context\n"); + exit(1); + } + + if ( !strcmp(argv[1], "-all" ) ) { 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); + if ( (result = query_all(sctx[0], &statesOut, &jobsOut)) ) dgerr(sctx[0], "edg_wll_QueryJobs"); + else for ( i = 0; statesOut[i].state; i++ ) printstat(statesOut[i],0); + + 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); } -/* retrieve job ID's */ - memset(jc,0,sizeof jc); + edg_wll_FreeContext(sctx[0]); - 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; + return result; + } - //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 ( !strcmp(argv[1], "-x") ) { + edg_wlc_JobId job; + edg_wll_JobStat status; + + if ( argc < 3 ) { usage(argv[0]); return 1; } + if ( edg_wll_InitContext(&sctx[0]) ) { + fprintf(stderr,"%s: cannot initialize edg_wll_Context\n",myname); + exit(1); + } + edg_wll_SetParam(sctx[0], EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, argv[2]); + for ( i = 3; i < argc; i++ ) { + memset(&status, 0, sizeof status); + if (edg_wlc_JobIdParse(argv[i],&job)) { + fprintf(stderr,"%s: %s: cannot parse jobId\n", myname, argv[i]); + continue; } - if (r != EDG_WLL_QUERYRES_LIMITED) goto late_error; - } else if (result) { - dgerr(ctx,"edg_wll_QueryJobs"); - result=1; goto cleanup; + if ( edg_wll_JobStatusProxy(sctx[0], job, EDG_WLL_STAT_CLASSADS | EDG_WLL_STAT_CHILDREN | EDG_WLL_STAT_CHILDSTAT, &status)) { + dgerr(sctx[0], "edg_wll_JobStatusProxy"); result = 1; + } else printstat(status, 0); + + if ( job ) edg_wlc_JobIdFree(job); + if ( status.state ) edg_wll_FreeStatus(&status); } + edg_wll_FreeContext(sctx[0]); -/* retrieve and print status of each job */ - for (i=0; statesOut[i].state; i++) - printstat(statesOut[i],0); + return result; + } -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 0 ) 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); + dgerr(sctx[j],"edg_wll_JobStatus"); result = 1; + } else printstat(status,0); -cleanup2: if (job) edg_wlc_JobIdFree(job); if (status.state) edg_wll_FreeStatus(&status); - } - for (i=0; i +#include "glite/security/glite_gss.h" #include "glite/wmsutils/jobid/cjobid.h" #include "glite/lb/notifid.h" #include "glite/lb/producer.h" @@ -35,7 +36,9 @@ int main(int argc, char *argv[]) char *src_instance = NULL; int err = 0/*,i,done = 0,fmtlen*/; int pri = 0; - char *lbproxy = NULL; + int use_lbproxy = 0; + char *lbproxy_user = NULL; + char *lbproxy_store_sock = NULL; int deb = 0; #ifdef ENABLE_REASON_LENGTH int elength = 0; @@ -76,7 +79,10 @@ int main(int argc, char *argv[]) edg_wll_Args parray[] = { { EDG_WLL_ARGS_EVENT, "e", "event", "select event type (see -e help)", &event }, { EDG_WLL_ARGS_BOOL, "p", "priority", "send as priority event", &pri }, - { EDG_WLL_ARGS_STRING, "x", "lbproxy", "send directly to L&B Proxy (not locallogger) with given credentials", &lbproxy }, + { EDG_WLL_ARGS_BOOL, "x", "lbproxy", "send directly to L&B Proxy (not locallogger)", &use_lbproxy }, + { EDG_WLL_ARGS_STRING, "S", "lbproxy-store-sock", "L&B Proxy store socket path", &lbproxy_store_sock }, + { EDG_WLL_ARGS_STRING, "U", "lbproxy-user-dn", "User certificate DN L&B Proxy store socket path", &lbproxy_user }, + { EDG_WLL_ARGS_STRING, "m", "machine", 0, &server }, { EDG_WLL_ARGS_SOURCE, "s", "source", "event source (see -s help)", &src }, { EDG_WLL_ARGS_STRING, "i", "source-instance", "event source instance", &src_instance }, @@ -119,21 +125,15 @@ int main(int argc, char *argv[]) { EDG_WLL_ARGS_NONE }, }; edg_wll_ParseArgs(&argc, argv, parray, - "Usage: %s [-d] [-p] [-x] [-l eventlen] [-j dg_jobid]" + "Usage: %s [-d] [-p] [[-x] [-S sock] [-U user_dn]] [-l eventlen] [-j dg_jobid]" "[-s source_id] -e event [key=value ...]"); -/* XXX: Obsolete? - if (globus_module_activate(GLOBUS_COMMON_MODULE) != GLOBUS_SUCCESS) { - fprintf(stderr, "Cannot initialize Globus common module\n"); - exit(1); - } -*/ edg_wll_InitContext(&ctx); /* log the event - priority/normal/proxy */ logev = (pri) ? edg_wll_LogEventSync : edg_wll_LogEvent; - logev = (lbproxy) ? edg_wll_LogEventProxy : logev; + logev = (use_lbproxy) ? edg_wll_LogEventProxy : logev; /* if no job given - generate some */ if (jobid_s == 0) { @@ -161,13 +161,21 @@ int main(int argc, char *argv[]) edg_wll_SetParam(ctx, EDG_WLL_PARAM_LEVEL, (deb) ? EDG_WLL_LEVEL_DEBUG : EDG_WLL_LEVEL_SYSTEM); - if (lbproxy) { - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_STORE_SOCK, "/tmp/lb_proxy_store.sock"); - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, "/tmp/lb_proxy_serve.sock"); - if (edg_wll_SetLoggingJobProxy(ctx,jobid,code,lbproxy,EDG_WLL_SEQ_NORMAL)) { + if ( use_lbproxy ) { + if ( !lbproxy_user ) { + gss_cred_id_t gss_cred = GSS_C_NO_CREDENTIAL; + edg_wll_GssStatus gss_stat; + OM_uint32 min_stat; + if ( edg_wll_gss_acquire_cred_gsi(NULL, NULL, &gss_cred, &lbproxy_user, &gss_stat) ) + lbproxy_user = "anonymous"; + if ( gss_cred != GSS_C_NO_CREDENTIAL ) gss_release_cred(&min_stat, &gss_cred); + } + if ( lbproxy_store_sock ) + edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_STORE_SOCK, lbproxy_store_sock); + if (edg_wll_SetLoggingJobProxy(ctx,jobid,code,lbproxy_user,EDG_WLL_SEQ_NORMAL)) { char *et,*ed; edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"SetLoggingJobProxy(%s,%s,%s): %s (%s)\n",jobid_s,code,lbproxy,et,ed); + fprintf(stderr,"SetLoggingJobProxy(%s,%s,%s): %s (%s)\n",jobid_s,code,lbproxy_user,et,ed); exit(1); } } else { -- 1.8.2.3