- added parse_eventsfile
authorJan Pospíšil <honik@ntc.zcu.cz>
Sat, 21 Apr 2007 10:36:22 +0000 (10:36 +0000)
committerJan Pospíšil <honik@ntc.zcu.cz>
Sat, 21 Apr 2007 10:36:22 +0000 (10:36 +0000)
- aftermerge cleanup (remove again already removed files, duplicite lines in Makefile, etc.)

org.glite.lb.client/Makefile
org.glite.lb.client/examples/lbmon.c [deleted file]
org.glite.lb.client/examples/parse_eventsfile.c [new file with mode: 0644]

index a49d050..21f31af 100644 (file)
@@ -134,8 +134,7 @@ PLUSLIB:=libglite_lb_clientpp_${nothrflavour}.la
 THRPLUSLIB:=libglite_lb_clientpp_${thrflavour}.la
 
 TOOLS:=dump load purge lb_dump_exporter ${LB_PERF_TOOLS}
-EXAMPLES:=log_usertag_proxy job_log job_reg feed_shark notify query_ext query_seq_code stats abort_job change_acl stresslog
-EXAMPLES:=log_usertag_proxy job_log job_reg feed_shark notify query_ext query_seq_code stats abort_job change_acl stresslog lbmon flood_proxy dagids stress_context
+EXAMPLES:=log_usertag_proxy job_log job_reg feed_shark notify query_ext query_seq_code stats abort_job change_acl stresslog flood_proxy dagids stress_context parse_eventsfile
 
 EXAMPLES_CL=user_jobs job_status 
 EXAMPLES_CL_THR=user_jobs_threaded
diff --git a/org.glite.lb.client/examples/lbmon.c b/org.glite.lb.client/examples/lbmon.c
deleted file mode 100644 (file)
index 2d466b9..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-#ident "$Header$"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <getopt.h>
-#include <time.h>
-
-#include "glite/lb/consumer.h"
-
-static void usage(char *);
-static int query_all(edg_wll_Context, int, struct timeval, edg_wll_JobStat **, edg_wlc_JobId **);
-static void dgerr(edg_wll_Context,char *);
-
-static char    *myname = NULL;
-static int     debug = 0, verbose = 0, lbproxy =0;
-static const char rcsid[] = "@(#)$Id$";
-
-static struct option const long_options[] = {
-        { "help", no_argument, 0, 'h' },
-        { "version", no_argument, 0, 'V' },
-        { "verbose", no_argument, 0, 'v' },
-        { "debug", no_argument, 0, 'd' },
-        { "lbproxy", required_argument, 0, 'x' },
-        { NULL, 0, NULL, 0}
-};
-
-int main(int argc,char *argv[]) {
-       edg_wll_Context         ctx;
-       edg_wll_JobStat         *statesOut = NULL;
-       edg_wlc_JobId           *jobsOut = NULL;
-       struct timeval time_now;
-
-       int i, result, opt, nJobs;
-       i = result = opt = 0;
-       gettimeofday(&time_now,0);
-
-       myname = argv[0];
-       fprintf(stdout,"\n");
-       /* get arguments */
-       while ((opt = getopt_long(argc,argv,
-               "h"  /* help */
-               "V"  /* version */
-               "v"  /* verbose */
-               "d"  /* debug */
-               "x", /* lbproxy */
-               long_options, (int *) 0)) != EOF) {
-
-               switch (opt) {
-                       case 'V': fprintf(stdout,"%s:\t%s\n",argv[0],rcsid); exit(0);
-                       case 'v': verbose = 1; break;
-                       case 'd': debug = 1; break;
-                       case 'x': lbproxy = 1; break;
-                       case 'h':
-                       default:
-                               usage(argv[0]); exit(0);
-               }
-       }
-       if ( edg_wll_InitContext(&ctx) ) {
-               fprintf(stderr,"%s: cannot initialize edg_wll_Context\n ",myname);
-               exit(1);
-       }
-
-       if ( (result = query_all(ctx, EDG_WLL_JOB_CLEARED, time_now, &statesOut, &jobsOut)) ) {
-               dgerr(ctx, "edg_wll_QueryJobs");
-       } else {
-               fprintf(stdout,"Number of jobs... ");
-       }
-
-       nJobs = 0;
-       if ( jobsOut ) {
-               for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]); {
-                       nJobs++;
-                       free(jobsOut);
-               }
-       }
-       if ( statesOut ) {
-               for (i=0; statesOut[i].state; i++) edg_wll_FreeStatus(&statesOut[i]);
-                       free(statesOut);
-                }
-       edg_wll_FreeContext(ctx);
-
-
-       return result;
-}
-
-static void
-usage(char *name) {
-       fprintf(stderr,"Usage: %s [-x]\n", name);
-}
-
-static int
-query_all(edg_wll_Context ctx, int query_status, struct timeval query_time, edg_wll_JobStat **statesOut, edg_wlc_JobId **jobsOut) {
-       edg_wll_QueryRec        jc[3];
-       int                     ret;
-
-       memset(jc, 0, sizeof jc);
-
-       /* jobs in the state 'query_status' within last hour */
-       jc[0].attr = EDG_WLL_QUERY_ATTR_STATUS;
-       jc[0].op = EDG_WLL_QUERY_OP_EQUAL;
-       jc[0].value.i = query_status;
-       jc[1].attr = EDG_WLL_QUERY_ATTR_TIME;
-       jc[1].attr_id.state = query_status;
-       jc[1].op = EDG_WLL_QUERY_OP_WITHIN;
-       jc[1].value.t.tv_sec = query_time.tv_sec - 3600;
-       jc[1].value.t.tv_usec = query_time.tv_usec;
-       jc[1].value2.t.tv_sec = query_time.tv_sec;
-       jc[1].value2.t.tv_usec = query_time.tv_usec;
-       jc[2].attr = EDG_WLL_QUERY_ATTR_UNDEF;
-
-       if ( (ret = edg_wll_QueryJobs(ctx, jc, 0, jobsOut, statesOut)) ) {
-               if ( ret == E2BIG ) {
-                       int r;
-                       if ( edg_wll_GetParam(ctx, EDG_WLL_PARAM_QUERY_RESULTS, &r) ) return ret;
-                       if ( r != EDG_WLL_QUERYRES_LIMITED ) return ret;
-
-                       fprintf(stderr," edg_wll_QueryJobs() Warning: only limited result returned!\n");
-                       return 0;
-               } else return ret;
-       }
-
-       return ret;
-}
-
-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);
-       if(etxt) free(etxt); 
-       if(edsc) free(edsc);
-}
diff --git a/org.glite.lb.client/examples/parse_eventsfile.c b/org.glite.lb.client/examples/parse_eventsfile.c
new file mode 100644 (file)
index 0000000..16e8019
--- /dev/null
@@ -0,0 +1,116 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include "glite/lb/producer.h"
+#include "glite/lb/events.h"
+#include "glite/lb/events_parse.h"
+
+#define        MAXMSGSIZE      10240
+
+extern char *optarg;
+extern int opterr,optind;
+
+static const char *me;
+
+static void usage()
+{
+       fprintf(stderr,"usage: %s [-n] -f file_name\n", me);
+}
+
+int main(int argc, char *argv[])
+{
+       char    *filename = NULL;
+       char    buf[MAXMSGSIZE];
+       int     done = 0,i=0,notif=0;
+       edg_wll_Context ctx;
+       edg_wll_Event   *event = NULL;
+       FILE    *f;
+       edg_wll_ErrorCode (*parse)(edg_wll_Context context,edg_wll_LogLine logline,edg_wll_Event **event);
+       edg_wll_LogLine (*unparse)(edg_wll_Context context,edg_wll_Event *event);
+       const char *parse_str,*unparse_str;
+
+       edg_wll_InitContext(&ctx);
+       opterr = 0;
+
+       me = strdup(argv[0]);
+
+       do {
+               switch (getopt(argc,argv,"nf:")) {
+                       case 'n': notif = 1; break;
+                       case 'f': filename = (char *) strdup(optarg); break;
+                       case '?': usage(); exit(EINVAL);
+                       case -1: done = 1; break;
+               }
+       } while (!done);
+
+       /* choose the right (un)parser */
+       if (notif) {
+               parse = edg_wll_ParseNotifEvent;
+               parse_str = "edg_wll_ParseNotifEvent";
+               unparse = edg_wll_UnparseNotifEvent;
+               unparse_str = "edg_wll_UnparseNotifEvent";
+       } else {
+               parse = edg_wll_ParseEvent;
+               parse_str = "edg_wll_ParseEvent";
+               unparse = edg_wll_UnparseEvent;
+               unparse_str = "edg_wll_UnparseEvent";
+       }
+
+       if (!filename) {
+               fprintf(stderr,"%s: -f required\n",me);
+               usage();
+               exit(1);
+       }
+
+       if ( (f = fopen(filename,"r")) == NULL) {
+               perror(filename);
+               exit(1);
+       } else {
+               fprintf(stderr,"Parsing file '%s' for correctness:\n",filename);
+       }
+       
+       /* parse events */
+       i = 1;
+       while (!feof(f)) {
+               if (!fgets(buf,sizeof(buf),f)) break;
+               if (strcmp(buf,"\n")) {
+                       // fprintf(stdout,"%d: %s\n",i,buf);
+
+                       if (parse(ctx,buf,&event) != 0) {
+                               /* Parse ERROR: */
+                               char    *et=NULL,*ed=NULL;
+
+                               edg_wll_Error(ctx,&et,&ed);
+                               fprintf(stderr,"line %d: %s() error: %s (%s)\n",i,parse_str,et,ed);
+                               if (et) free(et);
+                               if (ed) free(ed);
+                       } else {
+                               /* Parse OK : */
+                               char    *es=NULL;
+                               edg_wll_LogLine logline = NULL;
+
+                               es=edg_wll_EventToString(event->type);
+                               logline = unparse(ctx,event);
+                               fprintf(stderr,"line %d: %s() o.k. (event %s), ",i,parse_str,es);
+                               if (logline) {
+                                       fprintf(stderr,"%s() o.k.\n",unparse_str);
+                                       free(logline);
+                               } else {
+                                       fprintf(stderr,"%s() error\n",unparse_str);
+                               }
+                               if (es) free(es);
+                       }
+                       if (event) edg_wll_FreeEvent(event);
+               }
+               i++;
+       }
+       fclose(f);
+
+       edg_wll_FreeContext(ctx);
+
+       return 0;
+}