From 5ef22b1bd4979e7634355b864eb140973fcf3098 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20=C5=A0kr=C3=A1bal?= Date: Fri, 19 Nov 2004 08:21:21 +0000 Subject: [PATCH] - simple 'log user tag to proxy' example --- org.glite.lb.client/Makefile | 3 + org.glite.lb.client/examples/log_usertag_proxy.c | 103 +++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 org.glite.lb.client/examples/log_usertag_proxy.c diff --git a/org.glite.lb.client/Makefile b/org.glite.lb.client/Makefile index 17e4784..bd7695a 100644 --- a/org.glite.lb.client/Makefile +++ b/org.glite.lb.client/Makefile @@ -154,6 +154,9 @@ ${THRPLUSLIB}: ${PLUSTHROBJS} logevent: logevent.o args.o ${LINK} -o $@ logevent.o args.o ${LIB} ${EXT_LIB} ${GLOBUS_LIBS} +log_usertag_proxy: log_usertag_proxy.o + ${LINK} -o $@ log_usertag_proxy.o ${LIB} ${EXT_LIB} ${GLOBUS_LIBS} + logevent_fake: logevent_fake.o args.o ${LINK} -o $@ logevent_fake.o args.o ${TESTLIB} ${EXT_LIB} ${GLOBUS_LIBS} diff --git a/org.glite.lb.client/examples/log_usertag_proxy.c b/org.glite.lb.client/examples/log_usertag_proxy.c new file mode 100644 index 0000000..7891893 --- /dev/null +++ b/org.glite.lb.client/examples/log_usertag_proxy.c @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include + +#include + +#include "glite/wmsutils/jobid/cjobid.h" +#include "glite/lb/notifid.h" +#include "glite/lb/producer.h" +#include "glite/lb/events.h" + + +static struct option opts[] = { + {"help", 0, NULL, 'h'}, + {"sock", 1, NULL, 's'}, + {"jobid", 1, NULL, 'j'}, + {"seq", 1, NULL, 'c'}, + {"name", 1, NULL, 'n'}, + {"value", 1, NULL, 'v'} +}; + +static void usage(char *me) +{ + fprintf(stderr, "usage: %s [option]\n" + "\t-h, --help Shows this screen.\n" + "\t-s, --server LB Proxy socket.\n" + "\t-j, --jobid ID of requested job.\n" + "\t-c, --seq Sequence code.\n" + "\t-n, --name Name of the tag.\n" + "\t-v, --value Value of the tag.\n" + , me); +} + + +int main(int argc, char *argv[]) +{ + edg_wll_Context ctx; + edg_wlc_JobId jobid = NULL; + char *server, *code, *jobid_s, *name, *value; + int opt, err = 0; + + + server = code = jobid_s = name = value = NULL; + while ( (opt = getopt_long(argc, argv, "hs:j:c:n:v:", opts, NULL)) != EOF) + switch (opt) { + case 'h': usage(name); return 0; + case 's': server = strdup(optarg); break; + case 'j': jobid_s = strdup(optarg); break; + case 'c': code = strdup(optarg); break; + case 'n': name = strdup(optarg); break; + case 'v': value = strdup(optarg); break; + case '?': usage(name); return 1; + } + + if ( !jobid_s ) { fprintf(stderr, "JobId not given\n"); return 1; } + if ( !code ) { fprintf(stderr, "Sequence code not given\n"); return 1; } + if ( !server ) { fprintf(stderr, "LB proxy socket not given\n"); return 1; } + if ( !name ) { fprintf(stderr, "Tag name not given\n"); return 1; } + if ( !value ) { fprintf(stderr, "Tag value not given\n"); return 1; } + + if ( (errno = edg_wlc_JobIdParse(jobid_s, &jobid)) ) { perror(jobid_s); return 1; } + + if (globus_module_activate(GLOBUS_COMMON_MODULE) != GLOBUS_SUCCESS) { + fprintf(stderr, "Cannot initialize Globus common module\n"); + exit(1); + } + + edg_wll_InitContext(&ctx); + + edg_wll_SetParam(ctx, EDG_WLL_PARAM_SOURCE, EDG_WLL_SOURCE_USER_INTERFACE); + edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_STORE_SOCK, server); + + if (edg_wll_SetLoggingJob(ctx, jobid, code, EDG_WLL_SEQ_NORMAL)) { + char *et,*ed; + edg_wll_Error(ctx,&et,&ed); + fprintf(stderr,"SetLoggingJob(%s,%s): %s (%s)\n",jobid_s,code,et,ed); + exit(1); + } + + err = edg_wll_LogEventProxy(ctx, + EDG_WLL_EVENT_USERTAG, EDG_WLL_FORMAT_USERTAG, + name, value); + + if (err) { + char *et,*ed; + + edg_wll_Error(ctx,&et,&ed); + fprintf(stderr,"%s: edg_wll_LogEvent*(): %s (%s)\n", + argv[0],et,ed); + free(et); free(ed); + } + + code = edg_wll_GetSequenceCode(ctx); + puts(code); + free(code); + + edg_wll_FreeContext(ctx); + + return err; +} -- 1.8.2.3