added:
authorJan Pospíšil <honik@ntc.zcu.cz>
Wed, 8 Mar 2006 09:21:03 +0000 (09:21 +0000)
committerJan Pospíšil <honik@ntc.zcu.cz>
Wed, 8 Mar 2006 09:21:03 +0000 (09:21 +0000)
lbmon-db.c - monitoring nuber of jobs on the bserver or lbproxy
stresslog.c - stress test logging utility

org.glite.lb.client/Makefile
org.glite.lb.client/examples/lbmon-db.c [new file with mode: 0644]
org.glite.lb.client/examples/stresslog.c [new file with mode: 0644]

index e25e248..a02c3dd 100644 (file)
@@ -132,9 +132,9 @@ PLUSLIB:=libglite_lb_clientpp_${nothrflavour}.la
 THRPLUSLIB:=libglite_lb_clientpp_${thrflavour}.la
 
 TOOLS:=dump load purge lb_dump_exporter
-EXAMPLES:=log_usertag_proxy job_log job_reg feed_shark notify query_ext query_seq_code stats abort_job change_acl lbmon
+EXAMPLES:=log_usertag_proxy job_log job_reg feed_shark notify query_ext query_seq_code stats abort_job change_acl lbmon stresslog
 
-EXAMPLES_CL=user_jobs job_status
+EXAMPLES_CL=user_jobs job_status 
 FAKE_EXAMPLES:=job_log_fake
 
 MAN_GZ:=glite-lb-logevent.1.gz
@@ -174,6 +174,9 @@ ${THRPLUSLIB}: ${PLUSTHROBJS}
 logevent: logevent.o args.o
        ${LINK} -o $@ logevent.o args.o ${LIB} ${EXT_LIB} 
 
+lbmon-db: lbmon-db.o
+       ${LINK} -o $@ lbmon-db.o -lmysqlclient -lglite_lb_bkserver ${LIB} ${EXT_LIB} 
+
 ${TOOLS} ${EXAMPLES}: %: %.o
        ${LINK} -o $@ $< ${LIB} ${EXT_LIB} 
 
@@ -230,7 +233,7 @@ ${MAN_GZ}: ${MAN}
 default: all
 
 
-compile all: check_version ${LIB} ${THRLIB} ${TOOLS} logevent ${PLUSLIB} ${THRPLUSLIB} examples ${MAN_GZ}
+compile all: check_version ${LIB} ${THRLIB} ${TOOLS} logevent lbmon-db ${PLUSLIB} ${THRPLUSLIB} examples ${MAN_GZ}
 
 examples: ${EXAMPLES} ${EXAMPLES_CL} ${sh_PROGS}
 
@@ -276,13 +279,13 @@ install:
        ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version}
        ${INSTALL} -m 644 ${top_srcdir}/doc/README-fake ${top_srcdir}/doc/README-notify ${PREFIX}/share/doc/${package}-${version}
        mkdir -p ${PREFIX}/examples
-       for p in logevent; do \
+       for p in logevent ; do \
                ${INSTALL} -m 755 "$$p" "${PREFIX}/bin/glite-lb-$$p"; \
        done
        for p in ${TOOLS} ; do \
                ${INSTALL} -m 755 "$$p" "${PREFIX}/sbin/glite-lb-$$p"; \
        done
-       for p in ${EXAMPLES} ${EXAMPLES_CL} ${sh_PROGS}; do \
+       for p in ${EXAMPLES} lbmon-db ${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/lbmon-db.c b/org.glite.lb.client/examples/lbmon-db.c
new file mode 100644 (file)
index 0000000..fee46cd
--- /dev/null
@@ -0,0 +1,90 @@
+#ident "$Header$"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sysexits.h>
+#include <assert.h>
+
+#include "glite/wmsutils/jobid/strmd5.h"
+#include "glite/lb/consumer.h"
+#include "glite/lb/context-int.h"
+#include "glite/lb/lbs_db.h"
+#include "glite/lb/jobstat.h"
+
+static struct option opts[] = {
+       { "mysql",1,NULL,'m' },
+       { "verbose",0,NULL,'v' },
+       { NULL, 0, NULL, 0 }
+};
+
+static void usage();
+static void do_exit(edg_wll_Context,int);
+static const char *me;
+
+int main(int argc,char **argv)
+{
+       int     opt;
+       char    *dbstring = getenv("LBDB");
+       int     verbose = 0, rows = 0, fields = 0, jobs = 0, i;
+       edg_wll_Context ctx;
+       char    *stmt = NULL, *status = NULL;
+       char    *str[2];
+       edg_wll_Stmt sh;
+
+       me = strdup(argv[0]);
+
+       while ((opt = getopt_long(argc,argv,"m:v",opts,NULL)) != EOF) switch (opt) {
+               case 'm': dbstring = optarg; break;
+               case 'v': verbose++; break;
+               case '?': usage(); exit(EX_USAGE);
+       }
+
+       edg_wll_InitContext(&ctx);
+       if (edg_wll_Open(ctx,dbstring)) do_exit(ctx,EX_UNAVAILABLE);
+       if (edg_wll_DBCheckVersion(ctx)) do_exit(ctx,EX_SOFTWARE);
+       if (asprintf(&stmt,"SELECT status,count(status) FROM states GROUP BY status;") < 0) do_exit(ctx,EX_OSERR);
+       if (verbose) fprintf(stderr,"mysql query: %s\n",stmt);
+       if ((rows = edg_wll_ExecStmt(ctx,stmt,&sh)) < 0) do_exit(ctx,EX_SOFTWARE);
+       if (verbose) fprintf(stderr,"number of states returned: %d\n",rows);
+       if (rows > 0) fprintf(stdout,"Number of jobs in each state: \n");
+       for (i = 0; i < rows; i++) {
+               fields = edg_wll_FetchRow(sh, str);
+               if (fields != 2) {
+                       edg_wll_FreeStmt(&sh);
+                       do_exit(ctx,EX_SOFTWARE);
+               }
+               status = edg_wll_StatToString((edg_wll_JobStatCode) atoi(str[0]));
+               jobs += atoi(str[1]);
+               fprintf(stdout,"%s: %s\n",status,str[1]);
+               if (str[0]) free(str[0]);
+               if (str[1]) free(str[1]);
+               if (status) free(status);
+       }
+       fprintf(stdout,"Total number of jobs: %d\n",jobs);
+
+       if (stmt) free(stmt);
+       edg_wll_FreeStmt(&sh);
+       edg_wll_FreeContext(ctx);
+
+       return 0;
+}
+
+static void do_exit(edg_wll_Context ctx,int code)
+{
+       char    *et,*ed;
+
+       edg_wll_Error(ctx,&et,&ed);
+       fprintf(stderr,"%s: %s (%s)\n",me,et,ed);
+       exit(code);
+}
+
+static void usage()
+{
+       fprintf(stderr,"usage: %s <options>\n"
+                       "       -m,--mysql <dbstring>   use non-default database connection\n"
+                       "       -v,--verbose            be verbose\n",
+                       me);
+}
diff --git a/org.glite.lb.client/examples/stresslog.c b/org.glite.lb.client/examples/stresslog.c
new file mode 100644 (file)
index 0000000..8f47414
--- /dev/null
@@ -0,0 +1,165 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include "glite/wmsutils/jobid/cjobid.h"
+#include "glite/lb/producer.h"
+#include "glite/lb/events.h"
+
+#define        MAXMSGSIZE      10240
+
+extern char *optarg;
+extern int opterr,optind;
+
+extern int edg_wll_DoLogEvent(edg_wll_Context context, edg_wll_LogLine logline);
+extern int edg_wll_DoLogEventProxy(edg_wll_Context context, edg_wll_LogLine logline);
+
+static const char *me;
+
+static void usage()
+{
+       fprintf(stderr,"usage: %s [-m bkserver] [-x] [-n jobs] [-f file_name]\n", me);
+}
+
+int main(int argc, char *argv[])
+{
+       char    *job = NULL,*server = NULL,*seq = NULL,*filename = NULL;
+       char    buf[MAXMSGSIZE];
+       int     lbproxy = 0, num_subjobs = 0;
+       int     done = 0, njobs = 1,i;
+       edg_wll_Context ctx;
+       edg_wlc_JobId   jobid,*subjobs;
+       FILE    *f;
+
+       edg_wll_InitContext(&ctx);
+       opterr = 0;
+
+       me = strdup(argv[0]);
+
+       do {
+               switch (getopt(argc,argv,"m:xn:f:")) {
+                       case 'm': server = strdup(optarg); break;
+                       case 'x': lbproxy = 1; break;
+                       case 'n': 
+                               njobs = atoi(optarg); 
+                               fprintf(stderr,"WARNING: -n option not implemented yet\n");
+                               break;
+                       case 'f': filename = (char *) strdup(optarg); break;
+                       case '?': usage(); exit(EINVAL);
+                       case -1: done = 1; break;
+               }
+       } while (!done);
+
+       if (!server) {
+               fprintf(stderr,"%s: -m required\n",me);
+               usage();
+               exit(1);
+       }
+
+       if (njobs <= 0) {
+               fprintf(stderr,"%s: wrong number of jobs\n",me);
+               usage();
+               exit(1);
+       }
+
+       if (!filename) {
+               fprintf(stderr,"%s: -f required\n",me);
+               usage();
+               exit(1);
+       }
+
+       if ( (f = fopen(filename,"r")) == NULL) {
+               perror(filename);
+               exit(1);
+       }
+       
+       /* create jobid */
+       if (!job) {
+               char *p = strchr(server,':');
+               if (p) *p=0;
+               edg_wlc_JobIdCreate(server,p?atoi(p+1):0,&jobid);
+               job = edg_wlc_JobIdUnparse(jobid);
+               // fprintf(stdout,"new jobid: %s\n",job);
+       }
+       else if ((errno = edg_wlc_JobIdParse(job,&jobid))) {
+               perror(job);
+               exit(1);
+       }
+
+       /* register */
+       edg_wll_SetParam(ctx,EDG_WLL_PARAM_SOURCE,EDG_WLL_SOURCE_USER_INTERFACE);
+       // edg_wll_SetParam(ctx,EDG_WLL_PARAM_SOURCE,edg_wll_StringToSource(src));
+       if (lbproxy) {
+               if (edg_wll_RegisterJobProxy(ctx,jobid,
+                       num_subjobs?EDG_WLL_REGJOB_DAG:EDG_WLL_REGJOB_SIMPLE,
+                       "JDL: blabla", "NNNSSSS",
+                       num_subjobs,NULL,&subjobs))
+               {
+                       char    *et,*ed;
+                       edg_wll_Error(ctx,&et,&ed);
+                       fprintf(stderr,"edg_wll_RegisterJobProxy(%s): %s (%s)\n",job,et,ed);
+                       exit(1);
+               }
+       } else {
+               if (edg_wll_RegisterJobSync(ctx,jobid,
+                       num_subjobs?EDG_WLL_REGJOB_DAG:EDG_WLL_REGJOB_SIMPLE,
+                       "JDL: blabla", "NNNSSSS",
+                       num_subjobs,NULL,&subjobs))
+               {
+                       char    *et,*ed;
+                       edg_wll_Error(ctx,&et,&ed);
+                       fprintf(stderr,"edg_wll_RegisterJobSync(%s): %s (%s)\n",job,et,ed);
+                       exit(1);
+               }
+       }
+
+       /* log events */
+       i = 1;
+       while (!feof(f)) {
+               edg_wll_LogLine logline;
+
+               if (!fgets(buf,sizeof(buf),f)) break;
+               if (strcmp(buf,"\n")) {
+                       // fprintf(stdout,"%d: %s\n",i,buf);
+                       asprintf(&logline,"DG.JOBID=\"%s\" %s",job,buf);
+                       if (lbproxy) {
+                               if (edg_wll_DoLogEventProxy(ctx,logline)) {
+                                       char    *et,*ed;
+                                       edg_wll_Error(ctx,&et,&ed);
+                                       fprintf(stderr,"edg_wll_DoLogEventProxy(): %s (%s)\n",et,ed);
+                                       exit(1);
+                               }
+                       } else {
+                               if (edg_wll_DoLogEvent(ctx,logline)) {
+                                       char    *et,*ed;
+                                       edg_wll_Error(ctx,&et,&ed);
+                                       fprintf(stderr,"edg_wll_DoLogEvent(): %s (%s)\n",et,ed);
+                                       exit(1);
+                               }
+                       }
+                       if (logline) free(logline);
+               }
+               i++;
+       }
+       fclose(f);
+
+       /* seq. code */
+       seq = edg_wll_GetSequenceCode(ctx);
+       fprintf(stdout,"\n%s=\"%s\"\n",num_subjobs?"EDG_WL_DAG_JOBID":"EDG_JOBID",job);
+       fprintf(stdout,"EDG_WL_SEQUENCE=\"%s\"\n",seq);
+       free(seq);
+       free(job);
+
+       if (num_subjobs) for (i=0; subjobs[i]; i++) {
+               char    *job_s = edg_wlc_JobIdUnparse(subjobs[i]);
+               fprintf(stdout,"EDG_WL_SUB_JOBID[%d]=\"%s\"\n",i,job_s);
+               free(job_s);
+       }
+
+       edg_wll_FreeContext(ctx);
+
+       return 0;
+}