From: Aleš Křenek Date: Thu, 21 Dec 2006 11:12:34 +0000 (+0000) Subject: merge _generic branch, resolve conflicts X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=refs%2Fheads%2Fglite-lb-server_branch_generic2;p=jra1mw.git merge _generic branch, resolve conflicts --- diff --git a/org.glite.lb.server/Makefile b/org.glite.lb.server/Makefile index 673d283..6b2aa70 100644 --- a/org.glite.lb.server/Makefile +++ b/org.glite.lb.server/Makefile @@ -48,6 +48,11 @@ ifdef LB_BUF LB_BUF_FLAGS:=-DLB_BUF endif +ifdef DEBUG_INDEX + LB_DEBUG_INDEX_FLAGS:=-DDEBUG_INDEX + BKSERVER_BASE_OBJS:=index_debug.o +endif + ifeq ($(GLITE_LB_SERVER_WITH_WS),yes) WS_CFLAGS=-DGLITE_LB_SERVER_WITH_WS NSMAP=LoggingAndBookkeeping.nsmap @@ -67,7 +72,7 @@ else endif AT3=perl -I${top_srcdir}/project ${top_srcdir}/project/at3 -SUFFIXES = .T +SUFFIXES = .T .xsd DEBUG:=-g -O0 -Wall @@ -89,16 +94,18 @@ CFLAGS:= \ -I${globus_prefix}/include/${nothrflavour} \ $(GRIDSITE_CFLAGS) \ -D_GNU_SOURCE ${LB_STANDALONE_FLAGS} ${LB_PERF_FLAGS} ${LB_DAG_FLAGS} \ - ${LB_BUF_FLAGS} + ${LB_BUF_FLAGS} ${LB_DEBUG_INDEX_FLAGS} ifdef LB_PROF SRVBONES_LIB:= ${stagedir}/lib/libglite_lb_server_bones.la LB_COMMON_LIB:=${stagedir}/lib/libglite_lb_common_${nothrflavour}.la + LB_UTILS_DB_LIB:=${stagedir}/lib/libglite_lbu_db.la CFLAGS:=${CFLAGS} -pg -g LDFLAGS:=${LDFLAGS} -pg else SRVBONES_LIB:= -L${stagedir}/lib -lglite_lb_server_bones LB_COMMON_LIB:=-lglite_lb_common_${nothrflavour} + LB_UTILS_DB_LIB:=-lglite_lbu_db endif ifdef LBS_DB_PROFILE @@ -166,19 +173,20 @@ EXT_LIBS:= \ ${classadslib} \ ${VOMS_LIBS} -COMMON_LIBS:= -L${stagedir}/lib -lglite_lb_common_${nothrflavour} -lglite_security_gss_${nothrflavour} +COMMON_LIBS:= -L${stagedir}/lib -lglite_lb_common_${nothrflavour} \ + -lglite_security_gss_${nothrflavour} -lglite_lbu_trio -lglite_lbu_jobid PLUGIN_LIBS:= -L${stagedir}/lib -lglite_lb_common_${nothrflavour}\ ${classadslib} -lstdc++ ${expatlib} -lexpat\ -PLUGIN_LOBJS:= lb_plugin.lo jobstat_supp.lo process_event.lo lbs_db_supp.lo +PLUGIN_LOBJS:= lb_plugin.lo jobstat_supp.lo process_event.lo -BKSERVER_BASE_OBJS:= \ +BKSERVER_BASE_OBJS:= ${BKSERVER_BASE_OBJS}\ bkserverd.o il_lbproxy.o get_events.o index.o jobstat.o jobstat_supp.o process_event.o \ - seqcode.o write2rgma.o lbs_db.o lbs_db_supp.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \ + seqcode.o write2rgma.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \ lb_xml_parse_V21.o \ - lock.o openserver.o query.o userjobs.o db_store.o request.o store.o \ + lock.o query.o userjobs.o db_store.o request.o store.o \ stored_master.o srv_purge.o server_state.o dump.o lb_authz.o load.o \ - notification.o il_notification.o notif_match.o stats.o + notification.o il_notification.o notif_match.o stats.o db_supp.o dotless_gsoap_ver:=${shell echo ${gsoap_version} | tr -d . } GSOAP_LIB:=-L${stagedir}/lib -lglite_security_gsoap_plugin_${dotless_gsoap_ver}_${nothrflavour} @@ -192,6 +200,7 @@ ifeq ($(GLITE_LB_SERVER_WITH_WS),yes) BKSERVER_LIBS= \ ${SRVBONES_LIB} \ ${LB_COMMON_LIB} \ + ${LB_UTILS_DB_LIB} \ ${GSOAP_LIB} \ ${EXT_LIBS} else @@ -200,16 +209,23 @@ else BKSERVER_LIBS= \ ${SRVBONES_LIB} \ ${LB_COMMON_LIB} \ + ${LB_UTILS_DB_LIB} \ -lglite_security_gss_${nothrflavour} \ ${EXT_LIBS} endif -INDEX_OBJS:= index.o index_parse.o jobstat_supp.o lbs_db.o lbs_db_supp.o openserver.o \ +# for some reason added on HEAD +#<<<<<<< Makefile +# lb_authz.o store.o bkindex.o stats.o\ +# request.o db_store.o srv_purge.o notif_match.o il_lbproxy.o dump.o lb_xml_parse.o il_notification.o lb_proto.o server_state.o lb_xml_parse_V21.o lb_html.o notification.o seqcode.o userjobs.o load.o +#======= +# + +INDEX_OBJS:= index.o index_parse.o jobstat_supp.o \ jobstat.o process_event.o query.o lock.o get_events.o write2rgma.o index_lex.o \ - lb_authz.o store.o bkindex.o stats.o\ - request.o db_store.o srv_purge.o notif_match.o il_lbproxy.o dump.o lb_xml_parse.o il_notification.o lb_proto.o server_state.o lb_xml_parse_V21.o lb_html.o notification.o seqcode.o userjobs.o load.o + lb_authz.o store.o bkindex.o stats.o db_supp.o -INDEX_LIBS:= ${SRVBONES_LIB} ${COMMON_LIBS} ${EXT_LIBS} +INDEX_LIBS:= ${SRVBONES_LIB} ${COMMON_LIBS} ${EXT_LIBS} ${LB_UTILS_DB_LIB} WS_CLIENT_OBJS:= $(GSOAP_FILES_PREFIX)C.o $(GSOAP_FILES_PREFIX)Client.o ws_fault.o ws_typeref.o WS_CLIENT_LIBS:= ${GSOAP_LIB} -lglite_lb_common_${nothrflavour} \ @@ -223,13 +239,13 @@ WS_CLIENT_LIBS:= ${GSOAP_LIB} -lglite_lb_common_${nothrflavour} \ # ${EXT_LIBS} # -HDRS=index.h lb_authz.h lbs_db.h store.h +HDRS=index.h lb_authz.h store.h LIB_OBJS_BK:= \ il_lbproxy.o get_events.o index.o jobstat.o jobstat_supp.o process_event.o \ - seqcode.o lbs_db.o lbs_db_supp.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \ + seqcode.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \ lb_xml_parse_V21.o \ - lock.o openserver.o query.o userjobs.o db_store.o request.o store.o \ + lock.o query.o userjobs.o db_store.o request.o store.o \ stored_master.o srv_purge.o server_state.o dump.o lb_authz.o load.o \ notification.o il_notification.o notif_match.o stats.o @@ -251,7 +267,8 @@ else endif compile: glite_lb_bkserverd glite_lb_bkindex ${STATIC_LIB_BK} ${PLUGIN_LIB} store.c index.c - +compile: glite_lb_bkserverd glite_lb_bkindex ${STATIC_LIB_BK} ${PLUGIN_LIB} store.c index.c \ + job-attrs-common.xsd job-attrs-native.xsd check: compile test.xml test.query -echo check.query not complete yet @@ -292,8 +309,13 @@ test_xml: test_xml.cpp test.query: test_query_events ./test_query_events -#query_events_objs:=`echo ${BKSERVER_BASE_OBJS} |sed 's/lbs_db\.o//;s/lbs_db_supp\.o//;s/bkserverd\.o//;s/db_store\.o//;s/stored_master\.o//;s/store\.o//;s/srv_purge\.o//;s/load\.o//;s/dump\.o//;s/lb_proto\.o//;s/lb_html\.o//;s/lb_http\.o//;'` -query_events_objs:=`echo ${BKSERVER_BASE_OBJS} |sed 's/lbs_db\.o//;s/lbs_db_supp\.o//;s/bkserverd\.o//;'` +# XXX: very strange +#<<<<<<< Makefile +##query_events_objs:=`echo ${BKSERVER_BASE_OBJS} |sed 's/lbs_db\.o//;s/lbs_db_supp\.o//;s/bkserverd\.o//;s/db_store\.o//;s/stored_master\.o//;s/store\.o//;s/srv_purge\.o//;s/load\.o//;s/dump\.o//;s/lb_proto\.o//;s/lb_html\.o//;s/lb_http\.o//;'` +#query_events_objs:=`echo ${BKSERVER_BASE_OBJS} |sed 's/lbs_db\.o//;s/lbs_db_supp\.o//;s/bkserverd\.o//;'` +#======= +#query_events_objs:=`echo ${BKSERVER_BASE_OBJS} |sed 's/bkserverd\.o//;s/db_store\.o//;s/stored_master\.o//;s/request\.o//;s/store\.o//;s/srv_purge\.o//;s/load\.o//;s/dump\.o//;s/lb_proto\.o//;s/lb_html\.o//;s/lb_http\.o//;'` +#>>>>>>> 1.90.2.5 test_query_events: test_query_events.o ${LINKXX} -o $@ test_query_events.o ${query_events_objs} \ @@ -331,6 +353,9 @@ ${STATIC_LIB_BK}: ${LIB_OBJS_BK} jp_job_attrs.h: job-attrs.xsd jp_job_attrs.xsl ${XSLTPROC} ../src/jp_job_attrs.xsl $< >$@ +jp_job_attrs_native.h: job-attrs-native.xsd jp_job_attrs_native.xsl + ${XSLTPROC} ../src/jp_job_attrs_native.xsl $< >$@ + doc: stage: compile @@ -365,6 +390,8 @@ install: ${INSTALL} -m 755 ${top_srcdir}/config/startup ${PREFIX}/etc/init.d/glite-lb-bkserverd ${INSTALL} -m 644 ${top_srcdir}/interface/job-attrs.xsd ${PREFIX}/interface + ${INSTALL} -m 644 job-attrs-native.xsd ${PREFIX}/interface + ${INSTALL} -m 644 attrs-common.xsd ${PREFIX}/interface ${INSTALL} -m 644 ${top_srcdir}/interface/job-record.xsd ${PREFIX}/interface ${INSTALL} -m 644 jp_job_attrs.h ${PREFIX}/include/${globalprefix}/${lbprefix} @@ -388,6 +415,11 @@ clean: ${AT3} $< >$@ || rm -f $@ chmod -w $@ >/dev/null +%.xsd: %.xsd.T + rm -f $@ + ${AT3} $< >$@ || rm -f $@ + chmod -w $@ >/dev/null + %.o: %.y ${YACC} -d ${YFLAGS} $< mv y.tab.c $*.c @@ -410,7 +442,7 @@ test_query_events.o: %.o: %.cpp %.lo: %.c ${COMPILE} -o $@ -c $< -lb_plugin.lo: lb_plugin.c jp_job_attrs.h +lb_plugin.lo: lb_plugin.c jp_job_attrs.h jp_job_attrs_native.h ${COMPILE} -DPLUGIN_DEBUG -o $@ -c $< soap_version.h: diff --git a/org.glite.lb.server/examples/ws_joblog.c b/org.glite.lb.server/examples/ws_joblog.c index fc86a38..5c18f13 100644 --- a/org.glite.lb.server/examples/ws_joblog.c +++ b/org.glite.lb.server/examples/ws_joblog.c @@ -45,7 +45,7 @@ int main(int argc,char** argv) **econds = NULL; edg_wll_QueryRec j[2], e[1]; int opt, err, i; - edg_wlc_JobId job; + glite_lbu_JobId job; char *server = "http://localhost:9003/", *jobid = NULL, *name = NULL; @@ -68,7 +68,7 @@ int main(int argc,char** argv) usage(name); return 1; } - else if (edg_wlc_JobIdParse(jobid,&job)) { + else if (glite_lbu_JobIdParse(jobid,&job)) { fprintf(stderr,"%s: can't parse job ID\n",argv[1]); return 1; } @@ -120,7 +120,7 @@ int main(int argc,char** argv) } for (i = 0; jconds[i]; i++) { - if (jconds[i]) edg_wlc_JobIdFree(jconds[i][0].value.j); + if (jconds[i]) glite_lbu_JobIdFree(jconds[i][0].value.j); free(jconds[i]); } free(jconds); diff --git a/org.glite.lb.server/examples/ws_jobstat.c b/org.glite.lb.server/examples/ws_jobstat.c index 2130a28..e2dec1e 100644 --- a/org.glite.lb.server/examples/ws_jobstat.c +++ b/org.glite.lb.server/examples/ws_jobstat.c @@ -130,11 +130,11 @@ static void printstat(edg_wll_JobStat stat, int level) s = edg_wll_StatToString(stat.state); /* print whole flat structure */ printf("%sstate : %s\n", ind, s); - printf("%sjobId : %s\n", ind, j1 = edg_wlc_JobIdUnparse(stat.jobId)); + printf("%sjobId : %s\n", ind, j1 = glite_lbu_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, - j2 = edg_wlc_JobIdUnparse(stat.parent_job)); + j2 = glite_lbu_JobIdUnparse(stat.parent_job)); if (stat.jobtype) {; printf("%sseed : %s\n", ind, stat.seed); printf("%schildren_num : %d\n", ind, stat.children_num); diff --git a/org.glite.lb.server/examples/ws_query_ex.c b/org.glite.lb.server/examples/ws_query_ex.c index 1b627a4..a6d8c5d 100644 --- a/org.glite.lb.server/examples/ws_query_ex.c +++ b/org.glite.lb.server/examples/ws_query_ex.c @@ -150,11 +150,11 @@ static void printstat(edg_wll_JobStat stat, int level) 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("%sjobId : %s\n", ind, j = glite_lbu_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)); + j = glite_lbu_JobIdUnparse(stat.parent_job)); if (stat.jobtype) {; printf("%sseed : %s\n", ind, stat.seed); printf("%schildren_num : %d\n", ind, stat.children_num); diff --git a/org.glite.lb.server/interface/job-attrs.xsd b/org.glite.lb.server/interface/job-attrs.xsd index 7d08482..cddb1e0 100644 --- a/org.glite.lb.server/interface/job-attrs.xsd +++ b/org.glite.lb.server/interface/job-attrs.xsd @@ -5,12 +5,15 @@ + + + - Job owner according to LB @@ -98,13 +102,13 @@ - + - + diff --git a/org.glite.lb.server/interface/job-record.xsd b/org.glite.lb.server/interface/job-record.xsd index 43b0bab..f01bb38 100644 --- a/org.glite.lb.server/interface/job-record.xsd +++ b/org.glite.lb.server/interface/job-record.xsd @@ -6,7 +6,7 @@ #include -#include "glite/wmsutils/jobid/strmd5.h" +#include "glite/lb-utils/trio.h" +#include "glite/lb-utils/db.h" +#include "glite/lb-utils/strmd5.h" #include "glite/lb/consumer.h" #include "glite/lb/context-int.h" +#include "db_supp.h" #include "index.h" -#include "lbs_db.h" #include "jobstat.h" static struct option opts[] = { @@ -26,6 +28,7 @@ static struct option opts[] = { static void usage(const char *); static void do_exit(edg_wll_Context,int); +static void do_exit_db(edg_wll_Context,int); static char *col_list(const edg_wll_QueryRec *); static char *db_col_type(const edg_wll_QueryRec *); @@ -51,6 +54,7 @@ int main(int argc,char **argv) int i,j,k; int nnew,nold,nadd,ndrop; char *stmt; + int caps; for (i=0; idbctx); + if (!dbstring) dbstring = DEFAULTCS; + if (glite_lbu_DBConnect(ctx->dbctx, dbstring) != 0) { + edg_wll_SetErrorDB(ctx); + glite_lbu_FreeDBContext(ctx->dbctx); + do_exit(ctx, EX_SOFTWARE); + } + if ((caps = glite_lbu_DBQueryCaps(ctx->dbctx)) == -1) do_exit_db(ctx,EX_SOFTWARE); if (edg_wll_QueryJobIndices(ctx,&old_indices,&index_names)) do_exit(ctx,EX_SOFTWARE); if (dump) { @@ -89,7 +99,7 @@ int main(int argc,char **argv) for (i=0; index_names && index_names[i]; i++) { asprintf(&stmt,"alter table states drop index `%s`",index_names[i]); if (verbose) putchar('.'); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) do_exit_db(ctx,EX_SOFTWARE); free(stmt); } if (verbose) puts(" done"); @@ -98,7 +108,7 @@ int main(int argc,char **argv) char *cname = edg_wll_QueryRecToColumn(old_indices[i]); asprintf(&stmt,"alter table states drop column `%s`",cname); if (verbose) putchar('.'); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) do_exit_db(ctx,EX_SOFTWARE); free(stmt); free(cname); } @@ -169,7 +179,7 @@ int main(int argc,char **argv) } if (really) { asprintf(&stmt,"alter table states drop index `%s`",index_names[drop_indices[i]]); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) do_exit_db(ctx,EX_SOFTWARE); free(stmt); } if (verbose) puts(really ? "done" : ""); @@ -183,7 +193,7 @@ int main(int argc,char **argv) if (verbose) printf("\t%s\n",cname); if (really) { asprintf(&stmt,"alter table states drop column `%s`",cname); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) do_exit_db(ctx,EX_SOFTWARE); free(stmt); } free(cname); @@ -201,7 +211,7 @@ int main(int argc,char **argv) if (really) { char *ctype = db_col_type(new_columns[i]); asprintf(&stmt,"alter table states add `%s` %s",cname,ctype); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) do_exit_db(ctx,EX_SOFTWARE); free(stmt); } memcpy(&added_icols[nadd_icols].qrec, new_columns[i], sizeof(edg_wll_QueryRec)); @@ -234,12 +244,15 @@ int main(int argc,char **argv) if (really) { asprintf(&stmt,"create index `%s` on states(%s)",n,l); free(n); free(l); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) do_exit_db(ctx,EX_SOFTWARE); free(stmt); } if (verbose) puts(really ? "done" : ""); } + glite_lbu_DBClose(ctx->dbctx); + glite_lbu_FreeDBContext(ctx->dbctx); + return 0; } @@ -290,6 +303,14 @@ static void do_exit(edg_wll_Context ctx,int code) exit(code); } +static void do_exit_db(edg_wll_Context ctx,int code) +{ + edg_wll_SetErrorDB(ctx); + glite_lbu_DBClose(ctx->dbctx); + glite_lbu_FreeDBContext(ctx->dbctx); + do_exit(ctx,code); +} + static void usage(const char *me) { fprintf(stderr,"usage: %s [file]\n" @@ -310,10 +331,10 @@ static void usage(const char *me) edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context ctx, void *job_index_cols) { - edg_wll_Stmt sh, sh2; + glite_lbu_Statement sh, sh2; int njobs, ret = -1; intJobStat *stat; - edg_wlc_JobId jobid; + glite_lbu_JobId jobid; char *res[5]; char *rest; char *icvalues, *stmt; @@ -322,46 +343,49 @@ edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context ctx, void *job_index_c edg_wll_ResetError(ctx); if (!job_index_cols) return 0; - if ((njobs = edg_wll_ExecStmt(ctx, "select s.jobid,s.int_status,s.seq,s.version,j.dg_jobid" + if ((njobs = glite_lbu_ExecSQL(ctx->dbctx, "select s.jobid,s.int_status,s.seq,s.version,j.dg_jobid" " from states s, jobs j where s.jobid=j.jobid",&sh)) < 0) { - edg_wll_FreeStmt(&sh); - return edg_wll_Error(ctx, NULL, NULL); + glite_lbu_FreeStmt(&sh); + return edg_wll_SetErrorDB(ctx); } - while ((ret=edg_wll_FetchRow(sh,res)) >0) { + while ((ret=glite_lbu_FetchRow(sh,5,NULL,res)) >0) { if (strcmp(res[3], INTSTAT_VERSION)) { stat = NULL; - if (!edg_wlc_JobIdParse(res[4], &jobid)) { + if (!glite_lbu_JobIdParse(res[4], &jobid)) { if ((stat = malloc(sizeof(intJobStat))) != NULL) { if (edg_wll_intJobStatus(ctx, jobid, 0, stat, 1)) { free(stat); stat = NULL; } } - edg_wlc_JobIdFree(jobid); + glite_lbu_JobIdFree(jobid); } } else { stat = dec_intJobStat(res[1], &rest); if (rest == NULL) stat = NULL; } if (stat == NULL) { - edg_wll_FreeStmt(&sh); + glite_lbu_FreeStmt(&sh); return edg_wll_SetError(ctx, EDG_WLL_ERROR_SERVER_RESPONSE, "cannot decode int_status from states DB table"); } edg_wll_IColumnsSQLPart(ctx, job_index_cols, stat, 0, NULL, &icvalues); trio_asprintf(&stmt, "update states set seq=%s%s where jobid='%|Ss'", res[2], icvalues, res[0]); - ret = edg_wll_ExecStmt(ctx, stmt, &sh2); - edg_wll_FreeStmt(&sh2); + ret = glite_lbu_ExecSQL(ctx->dbctx, stmt, &sh2); +#warning FIXME: not needed + glite_lbu_FreeStmt(&sh2); for (i = 0; i < 5; i++) free(res[i]); destroy_intJobStat(stat); free(stat); free(stmt); free(icvalues); - if (ret < 0) return edg_wll_Error(ctx, NULL, NULL); + if (ret < 0) { + glite_lbu_FreeStmt(&sh); + return edg_wll_SetErrorDB(ctx); + } } - edg_wll_FreeStmt(&sh); - return edg_wll_Error(ctx, NULL, NULL); + glite_lbu_FreeStmt(&sh); + return edg_wll_SetErrorDB(ctx); } - diff --git a/org.glite.lb.server/src/bkserverd.c b/org.glite.lb.server/src/bkserverd.c index a5c4dec..4445c46 100644 --- a/org.glite.lb.server/src/bkserverd.c +++ b/org.glite.lb.server/src/bkserverd.c @@ -43,6 +43,7 @@ #include "glite/lb/mini_http.h" #include "glite/lb/context-int.h" #include "glite/lb/lb_maildir.h" +#include "glite/lb-utils/db.h" #ifdef LB_PERF #include "glite/lb/lb_perftest.h" @@ -51,14 +52,18 @@ enum lb_srv_perf_sink sink_mode; #endif +#include "db_supp.h" #include "lb_http.h" #include "lb_proto.h" #include "index.h" -#include "lbs_db.h" #include "lb_authz.h" #include "il_notification.h" #include "stats.h" +#ifdef DEBUG_INDEX +void edg_wll_dump_QueryRecs(FILE *, edg_wll_QueryRec **job_index); +#endif + #ifdef GLITE_LB_SERVER_WITH_WS # if GSOAP_VERSION < 20700 /* defined in and it's includes @@ -71,8 +76,6 @@ enum lb_srv_perf_sink sink_mode; #endif /* GLITE_LB_SERVER_WITH_WS */ extern int edg_wll_StoreProto(edg_wll_Context ctx); -extern edg_wll_ErrorCode edg_wll_Open(edg_wll_Context ctx, char *cs); -extern edg_wll_ErrorCode edg_wll_Close(edg_wll_Context); #ifdef LB_PERF extern void _start (void), etext (void); @@ -122,7 +125,8 @@ static int hardJobsLimit = 0; static int hardEventsLimit = 0; static int hardRespSizeLimit = 0; static char *dbstring = NULL,*fake_host = NULL; -int transactions = -1, use_transactions = -1; +int transactions = -1; +int dbcaps = 0; static int fake_port = 0; static char **super_users = NULL; static int slaves = 10, @@ -238,7 +242,7 @@ static void usage(char *me) ,me); } -static void wait_for_open(edg_wll_Context,const char *); +static void wait_for_open(edg_wll_Context,const char *,glite_lbu_DBContext); static int decrement_timeout(struct timeval *, struct timeval, struct timeval); static int read_roots(const char *); static int asyn_gethostbyaddr(char **, const char *, int, int, struct timeval *); @@ -289,8 +293,7 @@ struct clnt_data_t { #ifdef GLITE_LB_SERVER_WITH_WS struct soap *soap; #endif /* GLITE_LB_SERVER_WITH_WS */ - int use_transactions; - void *mysql; + glite_lbu_DBContext dbctx; edg_wll_QueryRec **job_index; edg_wll_IColumnRec *job_index_cols; }; @@ -317,6 +320,7 @@ int main(int argc, char *argv[]) struct timeval to; int request_timeout = REQUEST_TIMEOUT; int silent = 0; + glite_lbu_DBContext dbctx; @@ -569,29 +573,40 @@ a.sin_addr.s_addr = INADDR_ANY; #endif /* GLITE_LB_SERVER_WITH_WS */ if (!dbstring) dbstring = getenv("LBDB"); + if (!dbstring) dbstring = DEFAULTCS; /* Just check the database and let it be. The slaves do the job. */ edg_wll_InitContext(&ctx); - wait_for_open(ctx, dbstring); + glite_lbu_InitDBContext(&dbctx); + wait_for_open(ctx, dbstring, dbctx); - if (edg_wll_DBCheckVersion(ctx, dbstring)) + if ((dbcaps = glite_lbu_DBQueryCaps(dbctx)) == -1) { char *et,*ed; - edg_wll_Error(ctx,&et,&ed); + glite_lbu_DBError(dbctx,&et,&ed); fprintf(stderr,"%s: open database: %s (%s)\n",argv[0],et,ed); + + free(et); + free(ed); return 1; } - if (count_statistics) edg_wll_InitStatistics(ctx); - if (!ctx->use_transactions && transactions != 0) { - fprintf(stderr, "[%d]: transactions aren't supported!\n", getpid()); + glite_lbu_DBClose(dbctx); + glite_lbu_FreeDBContext(dbctx); + if ((dbcaps & GLITE_LBU_DB_CAP_INDEX) == 0) { + fprintf(stderr,"%s: missing index support in DB layer\n",argv[0]); + return 1; } + if ((dbcaps & GLITE_LBU_DB_CAP_TRANSACTIONS)) + fprintf(stderr, "[%d]: transactions aren't supported!\n", getpid()); if (transactions >= 0) { - fprintf(stderr, "[%d]: transactions forced from %d to %d\n", getpid(), ctx->use_transactions, transactions); - ctx->use_transactions = transactions; + fprintf(stderr, "[%d]: transactions forced from %d to %d\n", getpid(), dbcaps & GLITE_LBU_DB_CAP_TRANSACTIONS ? 1 : 0, transactions); + dbcaps &= ~GLITE_LBU_DB_CAP_TRANSACTIONS; + dbcaps |= transactions ? GLITE_LBU_DB_CAP_TRANSACTIONS : 0; } - use_transactions = ctx->use_transactions; - edg_wll_Close(ctx); + + if (count_statistics) edg_wll_InitStatistics(ctx); +// edg_wll_Close(ctx); edg_wll_FreeContext(ctx); if ( !debug ) { @@ -657,10 +672,11 @@ int bk_clnt_data_init(void **data) } dprintf(("[%d] opening database ...\n", getpid())); + glite_lbu_InitDBContext(&cdata->dbctx); if ( !dbstring ) dbstring = getenv("LBDB"); - wait_for_open(ctx, dbstring); - cdata->mysql = ctx->mysql; - cdata->use_transactions = ctx->use_transactions; + wait_for_open(ctx, dbstring, cdata->dbctx); + glite_lbu_DBSetCaps(cdata->dbctx, dbcaps); + ctx->dbctx = cdata->dbctx; if ( edg_wll_QueryJobIndices(ctx, &job_index, NULL) ) { @@ -675,6 +691,10 @@ int bk_clnt_data_init(void **data) edg_wll_FreeContext(ctx); cdata->job_index = job_index; +#ifdef DEBUG_INDEX + edg_wll_dump_QueryRecs(stdout, job_index); +#endif + if ( job_index ) { int i,j, k, maxncol, ncol; @@ -768,8 +788,7 @@ int bk_handle_connection(int conn, struct timeval *timeout, void *data) /* Shared structures (pointers) */ - ctx->mysql = cdata->mysql; - ctx->use_transactions = cdata->use_transactions; + ctx->dbctx = cdata->dbctx; ctx->job_index_cols = cdata->job_index_cols; ctx->job_index = cdata->job_index; @@ -1248,17 +1267,17 @@ int bk_ws_clnt_reject(int conn) #endif /* GLITE_LB_SERVER_WITH_WS */ -static void wait_for_open(edg_wll_Context ctx, const char *dbstring) +static void wait_for_open(edg_wll_Context ctx, const char *dbstring, glite_lbu_DBContext dbctx) { char *dbfail_string1, *dbfail_string2; dbfail_string1 = dbfail_string2 = NULL; - while (edg_wll_Open(ctx, (char *) dbstring)) { + while (glite_lbu_DBConnect(dbctx, dbstring)) { char *errt,*errd; if (dbfail_string1) free(dbfail_string1); - edg_wll_Error(ctx,&errt,&errd); + glite_lbu_DBError(dbctx,&errt,&errd); asprintf(&dbfail_string1,"%s (%s)\n",errt,errd); if (dbfail_string1 != NULL) { if (dbfail_string2 == NULL || strcmp(dbfail_string1,dbfail_string2)) { @@ -1278,8 +1297,6 @@ static void wait_for_open(edg_wll_Context ctx, const char *dbstring) dprintf(("[%d]: DB connection established\n",getpid())); if (!debug) syslog(LOG_INFO,"DB connection established\n"); } - - ctx->use_transactions = use_transactions; } static void free_hostent(struct hostent *h){ diff --git a/org.glite.lb.server/src/db_store.c b/org.glite.lb.server/src/db_store.c index e749423..1bc61cf 100644 --- a/org.glite.lb.server/src/db_store.c +++ b/org.glite.lb.server/src/db_store.c @@ -12,7 +12,6 @@ #include "glite/lb/purge.h" #include "purge.h" #include "store.h" -#include "lbs_db.h" #include "lock.h" #include "il_lbproxy.h" @@ -232,7 +231,7 @@ static int db_actual_store(edg_wll_Context ctx, char *event, edg_wll_Event *ev, if ( ctx->jpreg_dir && ev->any.type == EDG_WLL_EVENT_REGJOB ) { char *jids, *msg; - if ( !(jids = edg_wlc_JobIdUnparse(ev->any.jobId)) ) { + if ( !(jids = glite_lbu_JobIdUnparse(ev->any.jobId)) ) { return edg_wll_SetError(ctx, errno, "Can't unparse jobid when registering to JP"); } if ( !(msg = realloc(jids, strlen(jids)+strlen(ev->any.user)+2)) ) { diff --git a/org.glite.lb.server/src/db_supp.c b/org.glite.lb.server/src/db_supp.c new file mode 100644 index 0000000..5cb5958 --- /dev/null +++ b/org.glite.lb.server/src/db_supp.c @@ -0,0 +1,20 @@ +#include + +#include "glite/lb-utils/db.h" +#include "glite/lb/context-int.h" + +int edg_wll_SetErrorDB(edg_wll_Context ctx) { + int code; + char *ed; + + if (ctx->dbctx) { + code = glite_lbu_DBError(ctx->dbctx, NULL, &ed); + edg_wll_SetError(ctx, code, ed); + free(ed); + } else { + code = EINVAL; + edg_wll_SetError(ctx, EINVAL, "DB context isn't created"); + } + + return code; +} diff --git a/org.glite.lb.server/src/db_supp.h b/org.glite.lb.server/src/db_supp.h new file mode 100644 index 0000000..88f3597 --- /dev/null +++ b/org.glite.lb.server/src/db_supp.h @@ -0,0 +1,13 @@ +#ifndef EDG_WLL_DB_SUPP_H +#define EDG_WLL_DB_SUPP_H + +#ident "$Header:" + +#define DEFAULTCS "lbserver/@localhost:lbserver20" + +/** + * Set the current database error. + */ +int edg_wll_SetErrorDB(edg_wll_Context ctx); + +#endif diff --git a/org.glite.lb.server/src/dump.c b/org.glite.lb.server/src/dump.c index e14a55c..8afee4c 100644 --- a/org.glite.lb.server/src/dump.c +++ b/org.glite.lb.server/src/dump.c @@ -7,8 +7,9 @@ #include #include -#include "glite/lb/trio.h" -#include "glite/wmsutils/jobid/cjobid.h" +#include "glite/lb-utils/db.h" +#include "glite/lb-utils/trio.h" +#include "glite/lb-utils/cjobid.h" #include "glite/lb/context-int.h" #include "glite/lb/events_parse.h" @@ -17,7 +18,7 @@ #include "glite/lb/purge.h" #include "glite/lb/dump.h" -#include "lbs_db.h" +#include "db_supp.h" #include "query.h" #include "get_events.h" #include "server_state.h" @@ -33,7 +34,7 @@ int edg_wll_DumpEvents(edg_wll_Context ctx,const edg_wll_DumpRequest *req,edg_wl char *from_s, *to_s, *stmt, *time_s, *ptr; char *tmpfname; time_t start,end; - edg_wll_Stmt q = NULL; + glite_lbu_Statement q = NULL; char *res[10]; int event; edg_wll_Event e; @@ -56,8 +57,8 @@ int edg_wll_DumpEvents(edg_wll_Context ctx,const edg_wll_DumpRequest *req,edg_wl return edg_wll_Error(ctx,NULL,NULL); } - from_s = strdup(edg_wll_TimeToDB(from)); - to_s = strdup(edg_wll_TimeToDB(to)); + glite_lbu_TimeToDB(from, &from_s); + glite_lbu_TimeToDB(to, &to_s); trio_asprintf(&stmt, "select event,dg_jobid,code,prog,host,u.cert_subj,time_stamp,usec,level,arrived " @@ -70,9 +71,12 @@ int edg_wll_DumpEvents(edg_wll_Context ctx,const edg_wll_DumpRequest *req,edg_wl ctx->srvName,ctx->srvPort, from_s,to_s); - if (edg_wll_ExecStmt(ctx,stmt,&q) < 0) goto clean; + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,&q) < 0) { + edg_wll_SetErrorDB(ctx); + goto clean; + } - while ((ret = edg_wll_FetchRow(q,res)) > 0) { + while ((ret = glite_lbu_FetchRow(q,10,NULL,res)) > 0) { assert(ret == sizofa(res)); event = atoi(res[0]); free(res[0]); res[0] = NULL; @@ -129,6 +133,7 @@ int edg_wll_DumpEvents(edg_wll_Context ctx,const edg_wll_DumpRequest *req,edg_wl } edg_wll_FreeEvent(&e); memset(&e,0,sizeof e); } + if (ret < 0) edg_wll_SetErrorDB(ctx); time(&end); time_s = time_to_string(start, &ptr); @@ -147,7 +152,7 @@ int edg_wll_DumpEvents(edg_wll_Context ctx,const edg_wll_DumpRequest *req,edg_wl clean: edg_wll_FreeEvent(&e); - edg_wll_FreeStmt(&q); + glite_lbu_FreeStmt(&q); free(stmt); free(from_s); @@ -157,7 +162,7 @@ clean: static int handle_specials(edg_wll_Context ctx,time_t *t) { - char *time_s; + char *time_s = NULL; int ret; edg_wll_ResetError(ctx); @@ -176,7 +181,8 @@ static int handle_specials(edg_wll_Context ctx,time_t *t) case ENOENT: *t = 0; edg_wll_ResetError(ctx); break; - case 0: *t = edg_wll_DBToTime(time_s); + case 0: *t = glite_lbu_DBToTime(time_s); +printf("time_s: %s\n", time_s); assert(*t >= 0); break; default: break; @@ -191,7 +197,7 @@ static int handle_specials(edg_wll_Context ctx,time_t *t) static char *time_to_string(time_t t, char **ptr) { char *s; - s = edg_wll_TimeToDB(t); + glite_lbu_TimeToDB(t, &s); s[strlen(s) - 1] = '\0'; *ptr = s; diff --git a/org.glite.lb.server/src/get_events.c.T b/org.glite.lb.server/src/get_events.c.T index a4b2f6e..0c0b941 100644 --- a/org.glite.lb.server/src/get_events.c.T +++ b/org.glite.lb.server/src/get_events.c.T @@ -17,19 +17,21 @@ #include #include +#include "glite/lb-utils/db.h" +#include "glite/lb-utils/trio.h" #include "get_events.h" #include "glite/lb/context-int.h" -#include "glite/lb/trio.h" #include "glite/lb/events_parse.h" +#include "db_supp.h" static void edg_wll_set_event_field(edg_wll_Event *,char *,char *); static void edg_wll_set_event_field_warn(edg_wll_Event *,char *,char *); int edg_wll_get_event_flesh(edg_wll_Context ctx,int n,edg_wll_Event *e) { - char *jobid = edg_wlc_JobIdGetUnique(e->any.jobId), + char *jobid = glite_lbu_JobIdGetUnique(e->any.jobId), *q = NULL,*nameval[2]; - edg_wll_Stmt sh; + glite_lbu_Statement sh; int ret,t; const char *tables[] = { "short_fields","long_fields" }; @@ -40,9 +42,12 @@ int edg_wll_get_event_flesh(edg_wll_Context ctx,int n,edg_wll_Event *e) "where jobid = '%|Ss' and event = %d ", tables[t],jobid,n); - if ((ret=edg_wll_ExecStmt(ctx,q,&sh)) < 0) goto cleanup; + if ((ret=glite_lbu_ExecSQL(ctx->dbctx,q,&sh)) < 0) { + edg_wll_SetErrorDB(ctx); + goto cleanup; + } - while ((ret=edg_wll_FetchRow(sh,nameval)) > 0) { + while ((ret=glite_lbu_FetchRow(sh,2,NULL,nameval)) > 0) { edg_wll_set_event_field(e,nameval[0],nameval[1]); free(nameval[0]); /* XXX: nameval[1] freed in edg_wll_set_event_field @@ -50,15 +55,17 @@ int edg_wll_get_event_flesh(edg_wll_Context ctx,int n,edg_wll_Event *e) */ } - if (ret<0) goto cleanup; - edg_wll_FreeStmt(&sh); + glite_lbu_FreeStmt(&sh); + if (ret<0) { + ret = edg_wll_SetErrorDB(ctx); + goto cleanup; + } free(q); q=NULL; } ret=edg_wll_CheckEvent(ctx,e); cleanup: - if (sh) edg_wll_FreeStmt(&sh); free(jobid); free(q); diff --git a/org.glite.lb.server/src/get_events.h b/org.glite.lb.server/src/get_events.h index e3b6976..52b7a13 100644 --- a/org.glite.lb.server/src/get_events.h +++ b/org.glite.lb.server/src/get_events.h @@ -1,7 +1,8 @@ #ident "$Header$" -/* Internal functions for getting event sets from the LB database */ -#include "lbs_db.h" +#include "glite/lb/events.h" +#include "glite/lb/context.h" +#include "glite/lb/consumer.h" #ifdef __cplusplus extern "C" { @@ -11,7 +12,7 @@ extern "C" { char *edg_wll_jobid_to_user( edg_wll_Context, char *); void edg_wll_set_event_field_warn( edg_wll_Event *, char *, char *); void edg_wll_set_event_field( edg_wll_Event *, char *, char *); -int edg_wll_get_events_restricted( edg_wll_Context, edg_wlc_JobId, char *, int, int, char *, edg_wll_Event **); +int edg_wll_get_events_restricted( edg_wll_Context, glite_lbu_JobId, char *, int, int, char *, edg_wll_Event **); #define edg_wll_get_events(ctx,job,md5,emin,emax,ret) \ edg_wll_get_events_restricted((ctx),(job),(md5),(emin),(emax),NULL,(ret)) int edg_wll_last_event( edg_wll_Context, char *); @@ -22,7 +23,7 @@ int edg_wll_get_event_flesh(edg_wll_Context,int,edg_wll_Event *); int edg_wll_QueryEventsServer(edg_wll_Context,int,const edg_wll_QueryRec **,const edg_wll_QueryRec **,edg_wll_Event **); -int edg_wll_QueryJobsServer(edg_wll_Context, const edg_wll_QueryRec **, int, edg_wlc_JobId **, edg_wll_JobStat **); +int edg_wll_QueryJobsServer(edg_wll_Context, const edg_wll_QueryRec **, int, glite_lbu_JobId **, edg_wll_JobStat **); void edg_wll_SortEvents(edg_wll_Event *); diff --git a/org.glite.lb.server/src/il_lbproxy.c b/org.glite.lb.server/src/il_lbproxy.c index fd85f92..6189685 100644 --- a/org.glite.lb.server/src/il_lbproxy.c +++ b/org.glite.lb.server/src/il_lbproxy.c @@ -17,7 +17,7 @@ char *lbproxy_ilog_file_prefix = FILE_PREFIX; int edg_wll_EventSendProxy( edg_wll_Context ctx, - const edg_wlc_JobId jobid, + const glite_lbu_JobId jobid, const char *event) { long filepos; @@ -29,9 +29,9 @@ edg_wll_EventSendProxy( edg_wll_ResetError(ctx); - jobid_s = edg_wlc_JobIdGetUnique(jobid); + jobid_s = glite_lbu_JobIdGetUnique(jobid); if ( !jobid_s ) { - edg_wll_SetError(ctx, ENOMEM, "edg_wlc_JobIdGetUnique()"); + edg_wll_SetError(ctx, ENOMEM, "glite_lbu_JobIdGetUnique()"); _err(1); } diff --git a/org.glite.lb.server/src/il_lbproxy.h b/org.glite.lb.server/src/il_lbproxy.h index 4107304..fa7cc97 100644 --- a/org.glite.lb.server/src/il_lbproxy.h +++ b/org.glite.lb.server/src/il_lbproxy.h @@ -8,7 +8,7 @@ extern char *lbproxy_ilog_socket_path; extern char *lbproxy_ilog_file_prefix; -int edg_wll_EventSendProxy(edg_wll_Context ctx, const edg_wlc_JobId jobid, const char *event); +int edg_wll_EventSendProxy(edg_wll_Context ctx, const glite_lbu_JobId jobid, const char *event); #ifdef __cplusplus } diff --git a/org.glite.lb.server/src/il_notification.c b/org.glite.lb.server/src/il_notification.c index 99966d2..f7e813f 100644 --- a/org.glite.lb.server/src/il_notification.c +++ b/org.glite.lb.server/src/il_notification.c @@ -13,10 +13,10 @@ #include #include +#include "glite/lb-utils/escape.h" #include "glite/lb/context-int.h" #include "glite/lb/notifid.h" #include "glite/lb/events_parse.h" -#include "glite/lb/escape.h" #include "glite/lb/log_proto.h" #include "il_notification.h" @@ -154,7 +154,7 @@ edg_wll_NotifJobStatus(edg_wll_Context context, if(edg_wll_JobStatusToXML(context, notif_job_stat, &xml_data)) goto out; - if((xml_esc_data = edg_wll_EscapeXML(xml_data)) == NULL) { + if((xml_esc_data = glite_lbu_EscapeXML(xml_data)) == NULL) { edg_wll_SetError(context, ret=ENOMEM, "edg_wll_EscapeXML()"); goto out; } diff --git a/org.glite.lb.server/src/index.c.T b/org.glite.lb.server/src/index.c.T index b3cbd18..7486e06 100644 --- a/org.glite.lb.server/src/index.c.T +++ b/org.glite.lb.server/src/index.c.T @@ -3,8 +3,9 @@ #include #include +#include "glite/lb-utils/db.h" #include "glite/lb/context-int.h" -#include "lbs_db.h" +#include "db_supp.h" #include "index.h" extern int debug; @@ -19,9 +20,6 @@ extern int debug; int edg_wll_QueryJobIndices(edg_wll_Context ctx,edg_wll_QueryRec *** index_out,char ***keys_out) { edg_wll_QueryRec **idx = NULL; - edg_wll_Stmt stmt = NULL; - - int i,j,ret; static const char *built_in_indices[] = { "PRIMARY", @@ -29,85 +27,59 @@ int edg_wll_QueryJobIndices(edg_wll_Context ctx,edg_wll_QueryRec *** index_out,c NULL }; -/* XXX: "show index from" columns. Matches at least MySQL 4.0.11 */ - - char *showcol[12]; - int Key_name,Seq_in_index,Column_name,Sub_part; - char **keys = NULL; int *cols = NULL; - char **col_names = NULL; + char ***column_names; + int i,j; int nkeys = 0; - Key_name = Seq_in_index = Column_name = Sub_part = -1; - - if (edg_wll_ExecStmt(ctx,"show index from states",&stmt)<0) - return edg_wll_Error(ctx,NULL,NULL); - while ((ret = edg_wll_FetchRow(stmt,showcol))) { - if (ret < 0) return edg_wll_Error(ctx,NULL,NULL); - assert(ret <= sizeof showcol/sizeof showcol[0]); - - if (!col_names) { - col_names = malloc(ret * sizeof col_names[0]); - edg_wll_QueryColumns(stmt,col_names); - for (i=0; i= 0 && Seq_in_index >= 0 && - Column_name >= 0 && Sub_part >= 0); + if (glite_lbu_QueryIndices(ctx->dbctx, "states", &keys, &column_names) != 0) { + edg_wll_SetErrorDB(ctx); + return -1; + } + for (i = 0; keys[i]; i++) { + // skip builtin indices + for (j = 0; built_in_indices[j]; j++) { + if (strcasecmp(keys[i], built_in_indices[j]) == 0) + goto next_index; } + cols = realloc(cols,(nkeys+1) * sizeof cols[0]); + cols[nkeys] = 0; + idx = realloc(idx,(nkeys+2) * sizeof idx[0]); + idx[nkeys] = idx[nkeys+1] = NULL; - for (j=0; built_in_indices[j]; j++) { - if (strcasecmp(showcol[Key_name],built_in_indices[j]) == 0) { - for (i=0; i + + + +@@@LANG: wsdl + + + +@@@{ + for my $stat ($status->getTypesOrdered) { + my $u = uc $stat; + gen qq{\t\t\t\n}; + } +@@@} + + + +@@@{ + for my $n ($status->getAllFieldsOrdered) { + my $f = selectField $status $n; + if ($f->{codes}) { + my $n = getName $f; + while ($n =~ /(.*)_(.*)/) { $n = $1 . ucfirst $2; } + gen qq{\t\n\t\t\n}; + + for (@{$f->{codes}}) { + my $uc = uc $_->{name}; + gen qq{\t\t\t\n}; + } + + gen qq{\t\t\n\t\n\n}; + } + } +@@@} + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.glite.lb.server/src/job-attrs-native.xsd.T b/org.glite.lb.server/src/job-attrs-native.xsd.T new file mode 100644 index 0000000..ed2b53f --- /dev/null +++ b/org.glite.lb.server/src/job-attrs-native.xsd.T @@ -0,0 +1,44 @@ + + + + +@@@LANG: wsdl + + + + + +@@@{ + selectType $status '_common_'; + for (getFieldsOrdered $status) { + my $f = selectField $status $_; + next unless $f->{special}->{JP}; + my $t = getType $f; + my $n = getName $f; + + while ($n =~ /(.*)_(.*)/) { $n = $1 . ucfirst $2; } + if ($f->{codes}) { $t = $n . 'Type'; } + + $n =~ s/[jJ]dl/JDL/; + + gen qq{\t\n}; + } +@@@} + + + + + + + + + + + diff --git a/org.glite.lb.server/src/jobstat-generic.c b/org.glite.lb.server/src/jobstat-generic.c new file mode 100644 index 0000000..c65d043 --- /dev/null +++ b/org.glite.lb.server/src/jobstat-generic.c @@ -0,0 +1,534 @@ +#ident "$Header$" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "glite/lb-utils/db.h" +#include "glite/lb/producer.h" +#include "glite/lb/context-int.h" +#include "glite/lb-utils/trio.h" + +#include "db_supp.h" +#include "get_events.h" +#include "store.h" +#include "lock.h" +#include "index.h" +#include "jobstat.h" +#include "lb_authz.h" +#include "stats.h" + +#define DAG_ENABLE 1 + +/* TBD: share in whole logging or workload */ +#ifdef __GNUC__ +#define UNUSED_VAR __attribute__((unused)) +#else +#define UNUSED_VAR +#endif + + +#define mov(a,b) { free(a); a = b; b = NULL; } + +static void warn (const char* format, ...) UNUSED_VAR ; +static char *job_owner(edg_wll_Context,char *); + + +int js_enable_store = 1; + +/* + * Basic manipulations with the internal representation of job state + */ + +#if 0 +static int eval_expect_update(intJobStat *, int *, char **); +#endif + +static char* matched_substr(char *, regmatch_t) UNUSED_VAR; + +static char* matched_substr(char *in, regmatch_t match) +{ + int len; + char *s; + + len = match.rm_eo - match.rm_so; + s = calloc(1, len + 1); + if (s != NULL) { + strncpy(s, in + (int)match.rm_so, len); + } + + return s; +} + +int glite_lb_JobStatus( + glite_lb_SrvContext ctx, + const char *job, + const glite_lb_StateOpts *opts, + glite_lb_State **stat) +{ + glite_lbu_Blob state_blob; + +/* Local variables */ + char *md5_jobid; + + intJobStat jobstat; + intJobStat *ijsp; + int intErr = 0; + int lockErr; + edg_wll_Acl acl = NULL; +#if DAG_ENABLE + char *stmt = NULL; +#endif + + enum { OK, ERR_DECODE, ERR_COMP } bad_blob = OK; + + edg_wll_ResetError(ctx); + + /* XXX: unused md5_jobid = ctx->flesh->JobIdGetUnique(job); */ + +/* XXX: authz */ +#if 0 + if ( !(jobstat.pub.owner = job_owner(ctx,md5_jobid)) ) { + free(md5_jobid); + free(string_jobid); + return edg_wll_Error(ctx,NULL,NULL); + } + + intErr = edg_wll_GetACL(ctx, job, &acl); + if (intErr) { + free(md5_jobid); + free(string_jobid); + return edg_wll_Error(ctx,NULL,NULL); + } + + /* authorization check */ + if ( !(ctx->noAuth) && + (!(ctx->peerName) || strcmp(ctx->peerName, jobstat.pub.owner))) { + intErr = (acl == NULL) || edg_wll_CheckACL(ctx, acl, EDG_WLL_PERM_READ); + if (intErr) { + free(string_jobid); + free(md5_jobid); + free(jobstat.pub.owner); jobstat.pub.owner = NULL; + if (acl) { + edg_wll_FreeAcl(acl); + return edg_wll_Error(ctx, NULL, NULL); + } else { + return edg_wll_SetError(ctx,EPERM, "not owner, no ACL is set"); + } + } + } +#endif + + intErr = glite_lb_LoadStateBlob(ctx,job,&state_blob); + + if (!intErr) { + if (ctx->flesh->ComputeStateBlob(ctx,&state_blob,opts,stat)) { + glite_lbu_FreeBlob(&state_blob); + bad_blob = ERR_DECODE; + } + } + if (intErr == ENOENT || bad_blob) { + lockErr = edg_wll_LockJob(ctx,job); + if (ctx->flesh->ComputeStateFull(ctx,job,opts,stat,&state_blob) == 0) bad_blob = OK; + else { + bad_blob = ERR_COMP; + compErr = edg_wll_Error(ctx,NULL,&compDesc); + } + if (!lockErr) { + switch (bad_blob) { + case OK: glite_lb_StoreStateBlob(ctx,job,&state_blob); + break; + case ERR_DECODE: glite_lb_DeleteStateBlob(ctx,job); + case ERR_COMP: break; + } + edg_wll_UnlockJob(ctx,job); /* TODO: WARN */ + } + else { + /* TODO: syslog WARN */ + } + + if (bad_blob == ERR_COMP) { + edg_wll_SetError(ctx,compErr,compDesc); + free(compDesc); + } + + } + + glite_lbu_FreeBlob(&state_blob); + +/* TODO */ +#if 0 + if (acl) { + stat->acl = strdup(acl->string); + edg_wll_FreeAcl(acl); + } +#endif + + return edg_wll_Error(ctx); +} + +/* + * Helper for warning printouts + */ + +static void warn(const char* format, ...) +{ + va_list l; + va_start(l, format); + + /* + fprintf(stderr, "Warning: "); + vfprintf(stderr, format, l); + fputc('\n', stderr); + */ + + va_end(l); +} + +static char *job_owner(edg_wll_Context ctx,char *md5_jobid) +{ + char *stmt = NULL,*out = NULL; + glite_lbu_Statement sh; + int f = -1; + + edg_wll_ResetError(ctx); + trio_asprintf(&stmt,"select cert_subj from users,jobs " + "where users.userid = jobs.userid " + "and jobs.jobid = '%|Ss'",md5_jobid); + + if (stmt==NULL) { + edg_wll_SetError(ctx,ENOMEM, NULL); + return NULL; + } + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,&sh) >= 0) { + f=glite_lbu_FetchRow(sh,1,NULL,&out); + if (f == 0) { + if (out) free(out); + out = NULL; + edg_wll_SetError(ctx,ENOENT,md5_jobid); + } + glite_lbu_FreeStmt(&sh); + } + free(stmt); + edg_wll_SetErrorDB(ctx); + + return out; +} + + +#if 0 +/* XXX went_through went out */ +static int eval_expect_update(intJobStat *js, int* went_through, char **expect_from) +{ + int em = 0; + int ft = 0; /* fall through following tests */ + + if (ft || (went_through[ EDG_WLL_JOB_OUTPUTREADY ] && !js->done_failed)) ft = 1; + if (ft || (went_through[ EDG_WLL_JOB_DONE ] && !js->done_failed)) ft = 1; + if (ft || went_through[ EDG_WLL_JOB_CHECKPOINTED ]) ft = 1; + if (ft || went_through[ EDG_WLL_JOB_RUNNING ]) { + if (js->pub.node == NULL) em |= EXPECT_MASK_JOBMGR; + ft = 1; + } + if (ft || went_through[ EDG_WLL_JOB_SCHEDULED ]) { + if (js->pub.jssId == NULL) em |= EXPECT_MASK_JSS; + if (js->pub.rsl == NULL) em |= EXPECT_MASK_JSS; + if (js->pub.globusId == NULL) em |= EXPECT_MASK_JOBMGR; + if (js->pub.localId == NULL) em |= EXPECT_MASK_JOBMGR; + if (js->pub.jss_jdl == NULL) em |= EXPECT_MASK_RB; + ft = 1; + } + if (ft || went_through[ EDG_WLL_JOB_READY ]) { + if (js->pub.destination == NULL) em |= EXPECT_MASK_RB; + ft = 1; + } + if (ft || went_through[ EDG_WLL_JOB_SUBMITTED ]) { + if (js->pub.jdl == NULL) em |= EXPECT_MASK_UI; + ft = 1; + } + + if (em == 0) + *expect_from = NULL; + else { + asprintf(expect_from, "%s%s%s%s%s%s%s", + (em & EXPECT_MASK_UI ) ? EDG_WLL_SOURCE_UI : "", + (em & EXPECT_MASK_UI ) ? " " : "", + (em & EXPECT_MASK_RB ) ? EDG_WLL_SOURCE_RB : "", + (em & EXPECT_MASK_RB ) ? " " : "", + (em & EXPECT_MASK_JSS ) ? EDG_WLL_SOURCE_JSS : "", + (em & EXPECT_MASK_JSS ) ? " " : "", + (em & EXPECT_MASK_JOBMGR ) ? EDG_WLL_SOURCE_JOBMGR : "" + ); + } + + return (em == 0) ? 0 : 1; +} +#endif + +/* XXX more thorough malloc, calloc, and asprintf failure handling */ +/* XXX indexes in {short,long}_fields */ +/* XXX strict mode */ +/* XXX caching */ + +/* + * Store current job state to states and status_tags DB tables. + * Should be called with the job locked. + */ + +edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx, + intJobStat *stat, + int seq) +{ + char *jobid_md5, *stat_enc, *parent_md5 = NULL; + char *stmt; + edg_wll_TagValue *tagp; + int update; + int dbret; + char *icnames, *icvalues; + + update = (seq > 0); + jobid_md5 = glite_lbu_JobIdGetUnique(stat->pub.jobId); + stat_enc = enc_intJobStat(strdup(""), stat); + + tagp = stat->pub.user_tags; + if (tagp) { + while ((*tagp).tag != NULL) { + trio_asprintf(&stmt, "insert into status_tags" + "(jobid,seq,name,value) values " + "('%|Ss',%d,'%|Ss','%|Ss')", + jobid_md5, seq, (*tagp).tag, (*tagp).value); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) { + if (EEXIST == edg_wll_SetErrorDB(ctx)) { + /* XXX: this should not happen */ + edg_wll_ResetError(ctx); + tagp++; + continue; + } + else + goto cleanup; + } + tagp++; + } + } + + parent_md5 = glite_lbu_JobIdGetUnique(stat->pub.parent_job); + if (parent_md5 == NULL) parent_md5 = strdup("*no parent job*"); + + + edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, stat, 0, NULL, &icvalues); + + trio_asprintf(&stmt, + "update states set " + "status=%d,seq=%d,int_status='%|Ss',version='%|Ss'" + ",parent_job='%|Ss'%s " + "where jobid='%|Ss'", + stat->pub.state, seq, stat_enc, INTSTAT_VERSION, + parent_md5, icvalues, + jobid_md5); + free(icvalues); + + if ((dbret = glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL)) < 0) goto dberror; + + if (dbret == 0) { + edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, stat, 1, &icnames, &icvalues); + trio_asprintf(&stmt, + "insert into states" + "(jobid,status,seq,int_status,version" + ",parent_job%s) " + "values ('%|Ss',%d,%d,'%|Ss','%|Ss','%|Ss'%s)", + icnames, + jobid_md5, stat->pub.state, seq, stat_enc, + INTSTAT_VERSION, parent_md5, icvalues); + free(icnames); free(icvalues); + + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) goto dberror; + } + + if (update) { + trio_asprintf(&stmt, "delete from states " + "where jobid ='%|Ss' and ( seq<%d or version !='%|Ss')", + jobid_md5, seq, INTSTAT_VERSION); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) goto dberror; + } + if (update) { + trio_asprintf(&stmt, "delete from status_tags " + "where jobid ='%|Ss' and seq<%d", jobid_md5, seq); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) goto dberror; + } + goto cleanup; + +dberror: + edg_wll_SetErrorDB(ctx); +cleanup: + free(stmt); + free(jobid_md5); free(stat_enc); + free(parent_md5); + return edg_wll_Error(ctx,NULL,NULL); +} + + +edg_wll_ErrorCode edg_wll_StoreIntStateEmbryonic(edg_wll_Context ctx, + glite_lbu_JobId jobid, + char *icnames, + char *values, + glite_lbu_bufInsert bi) +{ + char *stmt = NULL; + +/* TODO + edg_wll_UpdateStatistics(ctx, NULL, e, &jobstat.pub); + if (ctx->rgma_export) write2rgma_status(&jobstat.pub); +*/ + +#ifdef LB_BUF + if (glite_lbu_bufferedInsert(bi, values)) + goto cleanup; +#else + + trio_asprintf(&stmt, + "insert into states" + "(jobid,status,seq,int_status,version" + ",parent_job%s) " + "values (%s)", + icnames, values); + + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) goto cleanup; +#endif + +cleanup: + free(stmt); + + return edg_wll_SetErrorDB(ctx); +} + +/* + * Retrieve stored job state from states and status_tags DB tables. + * Should be called with the job locked. + */ + +edg_wll_ErrorCode edg_wll_LoadIntState(edg_wll_Context ctx, + glite_lbu_JobId jobid, + int seq, + intJobStat **stat) +{ + char *jobid_md5; + char *stmt; + glite_lbu_Statement sh; + char *res, *res_rest; + int nstates; + + edg_wll_ResetError(ctx); + jobid_md5 = glite_lbu_JobIdGetUnique(jobid); + + if (seq == -1) { + /* any sequence number */ + trio_asprintf(&stmt, + "select int_status from states " + "where jobid='%|Ss' and version='%|Ss'", + jobid_md5, INTSTAT_VERSION); + } else { + trio_asprintf(&stmt, + "select int_status from states " + "where jobid='%|Ss' and seq='%d' and version='%|Ss'", + jobid_md5, seq, INTSTAT_VERSION); + } + + if (stmt == NULL) { + return edg_wll_SetError(ctx, ENOMEM, NULL); + } + + if ((nstates = glite_lbu_ExecSQL(ctx->dbctx,stmt,&sh)) < 0) goto dberror; + if (nstates == 0) { + edg_wll_SetError(ctx,ENOENT,"no state in DB"); + goto cleanup; + } + if (glite_lbu_FetchRow(sh,1,NULL,&res) < 0) goto dberror; + + *stat = dec_intJobStat(res, &res_rest); + free(res); + if (res_rest == NULL) { + edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_CALL, + "error decoding DB intJobStatus"); + } + + goto cleanup; +dberror: + edg_wll_SetErrorDB(ctx); +cleanup: + free(jobid_md5); + free(stmt); glite_lbu_FreeStmt(&sh); + return edg_wll_Error(ctx,NULL,NULL); +} + +/* + * update stored state according to the new event + * (must be called with the job locked) + */ + +edg_wll_ErrorCode edg_wll_StepIntState(edg_wll_Context ctx, + glite_lbu_JobId job, + edg_wll_Event *e, + int seq, + edg_wll_JobStat *stat_out) +{ + intJobStat *ijsp; + int intErr = 0; + int flags = 0; + int res; + int be_strict = 0; + char *errstring = NULL; + intJobStat jobstat; + edg_wll_JobStat oldstat; + char *oldstat_rgmaline = NULL; + + memset(&oldstat,0,sizeof oldstat); + if (seq != 0) { + intErr = edg_wll_LoadIntState(ctx, job, seq - 1, &ijsp); + } + if (seq != 0 && !intErr) { + edg_wll_CpyStatus(&ijsp->pub,&oldstat); + + if (ctx->rgma_export) oldstat_rgmaline = write2rgma_statline(&ijsp->pub); + + res = processEvent(ijsp, e, seq, be_strict, &errstring); + if (res == RET_FATAL || res == RET_INTERNAL) { /* !strict */ + edg_wll_FreeStatus(&oldstat); + return edg_wll_SetError(ctx, EINVAL, errstring); + } + edg_wll_StoreIntState(ctx, ijsp, seq); + edg_wll_UpdateStatistics(ctx,&oldstat,e,&ijsp->pub); + + if (ctx->rgma_export) write2rgma_chgstatus(&ijsp->pub, oldstat_rgmaline); + + if (stat_out) { + memcpy(stat_out,&ijsp->pub,sizeof *stat_out); + destroy_intJobStat_extension(ijsp); + } + else destroy_intJobStat(ijsp); + free(ijsp); + edg_wll_FreeStatus(&oldstat); + } + else if (!edg_wll_intJobStatus(ctx, job, flags,&jobstat, js_enable_store)) + { + /* FIXME: we miss state change in the case of seq != 0 + * Does anybody care? */ + + edg_wll_UpdateStatistics(ctx,NULL,e,&jobstat.pub); + + if (ctx->rgma_export) write2rgma_status(&jobstat.pub); + + if (stat_out) { + memcpy(stat_out,&jobstat.pub,sizeof *stat_out); + destroy_intJobStat_extension(&jobstat); + } + else destroy_intJobStat(&jobstat); + } + return edg_wll_Error(ctx, NULL, NULL); +} + diff --git a/org.glite.lb.server/src/jobstat.c b/org.glite.lb.server/src/jobstat.c index ceedc5a..c7fb108 100644 --- a/org.glite.lb.server/src/jobstat.c +++ b/org.glite.lb.server/src/jobstat.c @@ -10,15 +10,16 @@ #include #include +#include "glite/lb-utils/db.h" #include "glite/lb/producer.h" #include "glite/lb/context-int.h" -#include "glite/lb/trio.h" +#include "glite/lb-utils/trio.h" +#include "db_supp.h" #include "get_events.h" #include "store.h" #include "lock.h" #include "index.h" -#include "lbs_db.h" #include "jobstat.h" #include "lb_authz.h" #include "stats.h" @@ -65,94 +66,7 @@ static char* matched_substr(char *in, regmatch_t match) return s; } - -int edg_wll_JobStatus( - edg_wll_Context ctx, - const edg_wlc_JobId job, - int flags, - edg_wll_JobStat *stat) -{ - -/* Local variables */ - char *string_jobid; - char *md5_jobid; - - intJobStat jobstat; - intJobStat *ijsp; - int intErr = 0; - int lockErr; - edg_wll_Acl acl = NULL; -#if DAG_ENABLE - char *stmt = NULL; -#endif - - edg_wll_ResetError(ctx); - - string_jobid = edg_wlc_JobIdUnparse(job); - if (string_jobid == NULL || stat == NULL) - return edg_wll_SetError(ctx,EINVAL, NULL); - md5_jobid = edg_wlc_JobIdGetUnique(job); - - if ( !(jobstat.pub.owner = job_owner(ctx,md5_jobid)) ) { - free(md5_jobid); - free(string_jobid); - return edg_wll_Error(ctx,NULL,NULL); - } - - intErr = edg_wll_GetACL(ctx, job, &acl); - if (intErr) { - free(md5_jobid); - free(string_jobid); - return edg_wll_Error(ctx,NULL,NULL); - } - - /* authorization check */ - if ( !(ctx->noAuth) && - (!(ctx->peerName) || strcmp(ctx->peerName, jobstat.pub.owner))) { - intErr = (acl == NULL) || edg_wll_CheckACL(ctx, acl, EDG_WLL_PERM_READ); - if (intErr) { - free(string_jobid); - free(md5_jobid); - free(jobstat.pub.owner); jobstat.pub.owner = NULL; - if (acl) { - edg_wll_FreeAcl(acl); - return edg_wll_Error(ctx, NULL, NULL); - } else { - return edg_wll_SetError(ctx,EPERM, "not owner, no ACL is set"); - } - } - } - - intErr = edg_wll_LoadIntState(ctx, job, -1 /*all events*/, &ijsp); - if (!intErr) { - *stat = ijsp->pub; - destroy_intJobStat_extension(ijsp); - free(ijsp); - - } else { - lockErr = edg_wll_LockJob(ctx,job); - intErr = edg_wll_intJobStatus(ctx, job, flags,&jobstat, js_enable_store && !lockErr); - if (!lockErr) { - edg_wll_UnlockJob(ctx,job); - } - - *stat = jobstat.pub; - if (intErr) edg_wll_FreeStatus(&jobstat.pub); - destroy_intJobStat_extension(&jobstat); - } - - if (intErr) { - free(string_jobid); - free(md5_jobid); - if (acl) edg_wll_FreeAcl(acl); - return edg_wll_Error(ctx, NULL, NULL); - } - - if (acl) { - stat->acl = strdup(acl->string); - edg_wll_FreeAcl(acl); - } - +#if 0 if ((flags & EDG_WLL_STAT_CLASSADS) == 0) { char *null = NULL; @@ -187,7 +101,7 @@ int edg_wll_JobStatus( if (flags & EDG_WLL_STAT_CHILDHIST_THOROUGH) { /* Full (thorough) Histogram */ char *out[2]; - edg_wll_Stmt sh; + glite_lbu_Statement sh; int num_sub, num_f, i; if (stat->children_hist == NULL) { @@ -212,9 +126,9 @@ int edg_wll_JobStatus( md5_jobid, INTSTAT_VERSION); } if (stmt != NULL) { - num_sub = edg_wll_ExecStmt(ctx, stmt, &sh); + num_sub = glite_lbu_ExecSQL(ctx->dbctx, stmt, &sh); if (num_sub >=0 ) { - while ((num_f = edg_wll_FetchRow(sh, out)) == 1 + while ((num_f = glite_lbu_FetchRow(sh, 2, NULL, out)) == 1 || (num_f == 2)) { num_f = atoi(out[0]); if (num_f > EDG_WLL_JOB_UNDEF && num_f < EDG_WLL_NUMBER_OF_STATCODES) @@ -222,14 +136,14 @@ int edg_wll_JobStatus( if (out[1] !=NULL) add_stringlist(&stat->children, out[1]); free(out[0]); free(out[1]); } - edg_wll_FreeStmt(&sh); + glite_lbu_FreeStmt(&sh); } free(stmt); } else goto dag_enomem; } if (flags & EDG_WLL_STAT_CHILDSTAT) { char *stat_str, *s_out; - edg_wll_Stmt sh; + glite_lbu_Statement sh; int num_sub, num_f, i; intJobStat *js; @@ -237,15 +151,15 @@ int edg_wll_JobStatus( " AND version='%|Ss'", md5_jobid, INTSTAT_VERSION); if (stmt != NULL) { - num_sub = edg_wll_ExecStmt(ctx, stmt, &sh); + num_sub = glite_lbu_ExecSQL(ctx->dbctx, stmt, &sh); if (num_sub >=0 ) { i = 0; stat->children_states = calloc(num_sub+1, sizeof(edg_wll_JobStat)); if (stat->children_states == NULL) { - edg_wll_FreeStmt(&sh); + glite_lbu_FreeStmt(&sh); goto dag_enomem; } - while ((num_f = edg_wll_FetchRow(sh, &stat_str)) == 1 + while ((num_f = glite_lbu_FetchRow(sh, 1, NULL, &stat_str)) == 1 && i < num_sub) { js = dec_intJobStat(stat_str, &s_out); if (s_out != NULL && js != NULL) { @@ -256,7 +170,7 @@ int edg_wll_JobStatus( } free(stat_str); } - edg_wll_FreeStmt(&sh); + glite_lbu_FreeStmt(&sh); } free(stmt); } else goto dag_enomem; @@ -265,7 +179,7 @@ int edg_wll_JobStatus( #endif free(string_jobid); free(md5_jobid); - return edg_wll_Error(ctx, NULL, NULL); + return edg_wll_SetErrorDB(ctx); #if DAG_ENABLE dag_enomem: @@ -277,76 +191,63 @@ dag_enomem: #endif } -int edg_wll_intJobStatus( - edg_wll_Context ctx, - const edg_wlc_JobId job, - int flags, - intJobStat *intstat, - int update_db) +#endif /* 0 */ + +int glite_lb_Legacy_ComputeStateFull( + glite_lb_SrvContext ctx, + const char *jobid, + const glite_lb_StateOpts *opts, + glite_lb_State **state_out, + glite_lbu_Blob *blob_out) { /* Local variables */ - char *string_jobid; char *md5_jobid; int num_events; - edg_wll_Event *events = NULL; + glite_lb_Event **events = NULL; int i, intErr = 0; int res; int be_strict = 0; char *errstring = NULL; - edg_wll_QueryRec jqr[2]; - edg_wll_QueryRec **jqra; + glite_lb_QueryRec jqr[2]; + glite_lb_QueryRec **jqra; /* Processing */ edg_wll_ResetError(ctx); init_intJobStat(intstat); - string_jobid = edg_wlc_JobIdUnparse(job); - if (string_jobid == NULL || intstat == NULL) - return edg_wll_SetError(ctx,EINVAL, NULL); - - /* can be already filled by public edg_wll_JobStat() */ - if (intstat->pub.owner == NULL) { - md5_jobid = edg_wlc_JobIdGetUnique(job); - if ( !(intstat->pub.owner = job_owner(ctx,md5_jobid)) ) { - free(md5_jobid); - free(string_jobid); - return edg_wll_Error(ctx,NULL,NULL); - } + md5_jobid = ctx->flesh->JobIdGetUnique(jobid); + if ( !(intstat->pub.owner = job_owner(ctx,md5_jobid)) ) { free(md5_jobid); + return edg_wll_Error(ctx,NULL,NULL); } + free(md5_jobid); jqr[0].attr = EDG_WLL_QUERY_ATTR_JOBID; jqr[0].op = EDG_WLL_QUERY_OP_EQUAL; - jqr[0].value.j = job; + jqr[0].value.s = jobid; jqr[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - jqra = (edg_wll_QueryRec **) malloc (2 * sizeof(edg_wll_QueryRec **)); + jqra = (glite_lb_QueryRec **) malloc (2 * sizeof(glite_lb_QueryRec **)); jqra[0] = jqr; jqra[1] = NULL; - if (edg_wll_QueryEventsServer(ctx,1, (const edg_wll_QueryRec **)jqra, NULL, &events)) { - free(string_jobid); + if (glite_lb_QueryEventsServer(ctx,1, (const glite_lb_QueryRec **)jqra, NULL, &events, &num_events)) { free(jqra); return edg_wll_Error(ctx, NULL, NULL); } free(jqra); - for (num_events = 0; events[num_events].type != EDG_WLL_EVENT_UNDEF; - num_events++); - - if (num_events == 0) { - free(string_jobid); - return edg_wll_SetError(ctx,ENOENT,NULL); - } + if (num_events == 0) return edg_wll_SetError(ctx,ENOENT,NULL); +/* XXX: nema byt v kostech? */ edg_wll_SortEvents(events); for (i = 0; i < num_events; i++) { - res = processEvent(intstat, &events[i], i, be_strict, &errstring); + res = glite_lb_Legacy_ProcessEvent(intstat, events[i], i, be_strict, &errstring); if (res == RET_FATAL || res == RET_INTERNAL) { /* !strict */ intErr = 1; break; } @@ -355,18 +256,15 @@ int edg_wll_intJobStatus( intstat->pub.state = EDG_WLL_JOB_UNKNOWN; } - free(string_jobid); - - for (i=0; i < num_events ; i++) edg_wll_FreeEvent(&events[i]); + for (i=0; i < num_events ; i++) glite_lb_FreeEvent(events[i]); free(events); - if (intErr) { destroy_intJobStat(intstat); return edg_wll_SetError(ctx, EDG_WLL_ERROR_SERVER_RESPONSE, NULL); } else { /* XXX intstat->pub.expectUpdate = eval_expect_update(intstat, &intstat->pub.expectFrom); */ - intErr = edg_wlc_JobIdDup(job, &intstat->pub.jobId); + intErr = glite_lbu_JobIdDup(job, &intstat->pub.jobId); if (!intErr) { if (update_db) { int tsq = num_events - 1; @@ -405,7 +303,7 @@ static void warn(const char* format, ...) static char *job_owner(edg_wll_Context ctx,char *md5_jobid) { char *stmt = NULL,*out = NULL; - edg_wll_Stmt sh; + glite_lbu_Statement sh; int f = -1; edg_wll_ResetError(ctx); @@ -417,16 +315,17 @@ static char *job_owner(edg_wll_Context ctx,char *md5_jobid) edg_wll_SetError(ctx,ENOMEM, NULL); return NULL; } - if (edg_wll_ExecStmt(ctx,stmt,&sh) >= 0) { - f=edg_wll_FetchRow(sh,&out); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,&sh) >= 0) { + f=glite_lbu_FetchRow(sh,1,NULL,&out); if (f == 0) { if (out) free(out); out = NULL; edg_wll_SetError(ctx,ENOENT,md5_jobid); } + glite_lbu_FreeStmt(&sh); } - edg_wll_FreeStmt(&sh); free(stmt); + edg_wll_SetErrorDB(ctx); return out; } @@ -503,7 +402,7 @@ edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx, char *icnames, *icvalues; update = (seq > 0); - jobid_md5 = edg_wlc_JobIdGetUnique(stat->pub.jobId); + jobid_md5 = glite_lbu_JobIdGetUnique(stat->pub.jobId); stat_enc = enc_intJobStat(strdup(""), stat); tagp = stat->pub.user_tags; @@ -513,8 +412,8 @@ edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx, "(jobid,seq,name,value) values " "('%|Ss',%d,'%|Ss','%|Ss')", jobid_md5, seq, (*tagp).tag, (*tagp).value); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) { - if (EEXIST == edg_wll_Error(ctx, NULL, NULL)) { + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) { + if (EEXIST == edg_wll_SetErrorDB(ctx)) { /* XXX: this should not happen */ edg_wll_ResetError(ctx); tagp++; @@ -527,7 +426,7 @@ edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx, } } - parent_md5 = edg_wlc_JobIdGetUnique(stat->pub.parent_job); + parent_md5 = glite_lbu_JobIdGetUnique(stat->pub.parent_job); if (parent_md5 == NULL) parent_md5 = strdup("*no parent job*"); @@ -543,7 +442,7 @@ edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx, jobid_md5); free(icvalues); - if ((dbret = edg_wll_ExecStmt(ctx,stmt,NULL)) < 0) goto cleanup; + if ((dbret = glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL)) < 0) goto dberror; if (dbret == 0) { edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, stat, 1, &icnames, &icvalues); @@ -557,21 +456,24 @@ edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx, INTSTAT_VERSION, parent_md5, icvalues); free(icnames); free(icvalues); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup; + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) goto dberror; } if (update) { trio_asprintf(&stmt, "delete from states " "where jobid ='%|Ss' and ( seq<%d or version !='%|Ss')", jobid_md5, seq, INTSTAT_VERSION); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup; + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) goto dberror; } if (update) { trio_asprintf(&stmt, "delete from status_tags " "where jobid ='%|Ss' and seq<%d", jobid_md5, seq); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup; + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) goto dberror; } + goto cleanup; +dberror: + edg_wll_SetErrorDB(ctx); cleanup: free(stmt); free(jobid_md5); free(stat_enc); @@ -581,10 +483,10 @@ cleanup: edg_wll_ErrorCode edg_wll_StoreIntStateEmbryonic(edg_wll_Context ctx, - edg_wlc_JobId jobid, + glite_lbu_JobId jobid, char *icnames, char *values, - edg_wll_bufInsert *bi) + glite_lbu_bufInsert bi) { char *stmt = NULL; @@ -594,7 +496,7 @@ edg_wll_ErrorCode edg_wll_StoreIntStateEmbryonic(edg_wll_Context ctx, */ #ifdef LB_BUF - if (edg_wll_bufferedInsert(bi, values)) + if (glite_lbu_bufferedInsert(bi, values)) goto cleanup; #else @@ -605,13 +507,13 @@ edg_wll_ErrorCode edg_wll_StoreIntStateEmbryonic(edg_wll_Context ctx, "values (%s)", icnames, values); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup; + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) goto cleanup; #endif cleanup: free(stmt); - return edg_wll_Error(ctx,NULL,NULL); + return edg_wll_SetErrorDB(ctx); } /* @@ -620,18 +522,18 @@ cleanup: */ edg_wll_ErrorCode edg_wll_LoadIntState(edg_wll_Context ctx, - edg_wlc_JobId jobid, + glite_lbu_JobId jobid, int seq, intJobStat **stat) { char *jobid_md5; char *stmt; - edg_wll_Stmt sh; + glite_lbu_Statement sh; char *res, *res_rest; int nstates; edg_wll_ResetError(ctx); - jobid_md5 = edg_wlc_JobIdGetUnique(jobid); + jobid_md5 = glite_lbu_JobIdGetUnique(jobid); if (seq == -1) { /* any sequence number */ @@ -650,23 +552,26 @@ edg_wll_ErrorCode edg_wll_LoadIntState(edg_wll_Context ctx, return edg_wll_SetError(ctx, ENOMEM, NULL); } - if ((nstates = edg_wll_ExecStmt(ctx,stmt,&sh)) < 0) goto cleanup; + if ((nstates = glite_lbu_ExecSQL(ctx->dbctx,stmt,&sh)) < 0) goto dberror; if (nstates == 0) { edg_wll_SetError(ctx,ENOENT,"no state in DB"); goto cleanup; } - if (edg_wll_FetchRow(sh,&res) < 0) goto cleanup; + if (glite_lbu_FetchRow(sh,1,NULL,&res) < 0) goto dberror; *stat = dec_intJobStat(res, &res_rest); + free(res); if (res_rest == NULL) { edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_CALL, "error decoding DB intJobStatus"); } - free(res); + goto cleanup; +dberror: + edg_wll_SetErrorDB(ctx); cleanup: free(jobid_md5); - free(stmt); edg_wll_FreeStmt(&sh); + free(stmt); glite_lbu_FreeStmt(&sh); return edg_wll_Error(ctx,NULL,NULL); } @@ -943,7 +848,7 @@ edg_wll_ErrorCode edg_wll_StepIntStateParent(edg_wll_Context ctx, */ edg_wll_ErrorCode edg_wll_StepIntState(edg_wll_Context ctx, - edg_wlc_JobId job, + glite_lbu_JobId job, edg_wll_Event *e, int seq, edg_wll_JobStat *stat_out) diff --git a/org.glite.lb.server/src/jobstat.h b/org.glite.lb.server/src/jobstat.h index 2d346db..caeacd4 100644 --- a/org.glite.lb.server/src/jobstat.h +++ b/org.glite.lb.server/src/jobstat.h @@ -3,8 +3,7 @@ #ifndef _LBS_JOBSTAT_H #define _LBS_JOBSTAT_H - -#include "lbs_db.h" +#include "glite/lb-utils/db.h" /* * Internal representation of job state @@ -61,10 +60,10 @@ void destroy_intJobStat_extension(intJobStat *p); edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context, void *, intJobStat *, int , char **, char **); edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context, void *); -int edg_wll_intJobStatus( edg_wll_Context, const edg_wlc_JobId, int, intJobStat *, int); +int edg_wll_intJobStatus( edg_wll_Context, const glite_lbu_JobId, int, intJobStat *, int); edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context, intJobStat *, int); -edg_wll_ErrorCode edg_wll_StoreIntStateEmbryonic(edg_wll_Context, edg_wlc_JobId, char *icnames, char *values, edg_wll_bufInsert *bi); -edg_wll_ErrorCode edg_wll_LoadIntState(edg_wll_Context , edg_wlc_JobId , int, intJobStat **); +edg_wll_ErrorCode edg_wll_StoreIntStateEmbryonic(edg_wll_Context, glite_lbu_JobId, char *icnames, char *values, glite_lbu_bufInsert bi); +edg_wll_ErrorCode edg_wll_LoadIntState(edg_wll_Context , glite_lbu_JobId , int, intJobStat **); intJobStat* dec_intJobStat(char *, char **); diff --git a/org.glite.lb.server/src/jobstat_supp.c b/org.glite.lb.server/src/jobstat_supp.c index c665cf6..a6f2158 100644 --- a/org.glite.lb.server/src/jobstat_supp.c +++ b/org.glite.lb.server/src/jobstat_supp.c @@ -10,14 +10,14 @@ #include #include -#include "glite/wmsutils/jobid/cjobid.h" +#include "glite/lb-utils/db.h" +#include "glite/lb-utils/cjobid.h" #include "glite/lb/producer.h" #include "glite/lb/context-int.h" -#include "glite/lb/trio.h" +#include "glite/lb-utils/trio.h" #include "store.h" #include "index.h" -#include "lbs_db.h" #include "jobstat.h" #include "get_events.h" @@ -161,24 +161,24 @@ static int dec_int_array(char* in, char **rest, int *out) // Returns the number } -static char* enc_jobid(char *old, edg_wlc_JobId item) +static char* enc_jobid(char *old, glite_lbu_JobId item) { char *str; char *out; - str = edg_wlc_JobIdUnparse(item); + str = glite_lbu_JobIdUnparse(item); out = enc_string(old, str); free(str); return out; } -static edg_wlc_JobId dec_jobid(char *in, char **rest) +static glite_lbu_JobId dec_jobid(char *in, char **rest) { char *str; - edg_wlc_JobId jobid; + glite_lbu_JobId jobid; str = dec_string(in, rest); if (str == NULL) return NULL; - edg_wlc_JobIdParse(str, &jobid); + glite_lbu_JobIdParse(str, &jobid); free(str); return jobid; } @@ -673,8 +673,7 @@ edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context ctx, break; case EDG_WLL_QUERY_ATTR_TIME: if (stat->pub.stateEnterTimes) - data = strdup(edg_wll_TimeToDB(stat->pub.stateEnterTimes[ - job_index_cols[i].qrec.attr_id.state+1])); + glite_lbu_TimeToDB(stat->pub.stateEnterTimes[job_index_cols[i].qrec.attr_id.state+1], &data); else data = strdup("0"); break; case EDG_WLL_QUERY_ATTR_RESUBMITTED: diff --git a/org.glite.lb.server/src/jp_job_attrs.xsl b/org.glite.lb.server/src/jp_job_attrs.xsl index 78d77a4..a57c210 100644 --- a/org.glite.lb.server/src/jp_job_attrs.xsl +++ b/org.glite.lb.server/src/jp_job_attrs.xsl @@ -10,14 +10,14 @@ #ifndef __GLITE_LB_JP_JOB_ATTR_H #define __GLITE_LB_JP_JOB_ATTR_H -#define GLITE_JP_LB_NS "http://egee.cesnet.cz/en/Schema/LB/Attributes" +#define GLITE_JP_LB_NS_STAT "http://egee.cesnet.cz/en/Schema/LB/Attributes-Statistics" #endif /** */ -#define GLITE_JP_LB_ GLITE_JP_LB_NS ":" +#define GLITE_JP_LB_STAT_ GLITE_JP_LB_NS_STAT ":" diff --git a/org.glite.lb.server/src/lb_authz.c b/org.glite.lb.server/src/lb_authz.c index cd52c97..304965a 100644 --- a/org.glite.lb.server/src/lb_authz.c +++ b/org.glite.lb.server/src/lb_authz.c @@ -15,11 +15,10 @@ #undef WITHOUT_TRIO #include "glite/security/voms/voms_apic.h" -#include "glite/wmsutils/jobid/strmd5.h" -#include "glite/wmsutils/jobid/cjobid.h" +#include "glite/lb-utils/strmd5.h" +#include "glite/lb-utils/cjobid.h" #include "glite/lb/producer.h" -#include "glite/lb/trio.h" -#include "lbs_db.h" +#include "glite/lb-utils/trio.h" /* XXX should be defined in gridsite-gacl.h */ GRSTgaclEntry *GACLparseEntry(xmlNodePtr cur); @@ -699,10 +698,10 @@ edg_wll_HandleCounterACL(edg_wll_Context ctx, edg_wll_Acl acl, for ( ; ; ) { - if ( edg_wll_ExecStmt(ctx, q1, NULL) > 0 ) + if ( glite_lbu_ExecSQL(ctx->dbctx, q1, NULL) > 0 ) goto end; - if ( edg_wll_Error(ctx,NULL,NULL) != EEXIST ) + if ( edg_wll_SetErrorDB(ctx,NULL,NULL) != EEXIST ) goto end; /* @@ -712,7 +711,7 @@ edg_wll_HandleCounterACL(edg_wll_Context ctx, edg_wll_Acl acl, "update acls set refcnt = refcnt+%d " "where aclid = '%|Ss'", incr, aclid); - if ( edg_wll_ExecStmt(ctx, q2, NULL) < 0 ) + if ( glite_lbu_ExecSQL(ctx->dbctx, q2, NULL) < 0 ) continue; goto end; @@ -725,13 +724,13 @@ edg_wll_HandleCounterACL(edg_wll_Context ctx, edg_wll_Acl acl, "where aclid='%|Ss' and refcnt>=%d", -incr, aclid, -incr); - if ( edg_wll_ExecStmt(ctx, q1, NULL) > 0 ) + if ( glite_lbu_ExecSQL(ctx->dbctx, q1, NULL) > 0 ) { trio_asprintf(&q2, "delete from acls " "where aclid='%|Ss' and refcnt=0", aclid); - edg_wll_ExecStmt(ctx, q2, NULL); + glite_lbu_ExecSQL(ctx->dbctx, q2, NULL); } else { @@ -745,11 +744,11 @@ end: if ( q1 ) free(q1); if ( q2 ) free(q2); - return edg_wll_Error(ctx, NULL, NULL); + return edg_wll_SetErrorDB(ctx); } int -edg_wll_UpdateACL(edg_wll_Context ctx, edg_wlc_JobId job, +edg_wll_UpdateACL(edg_wll_Context ctx, glite_lbu_JobId job, char *user_id, int user_id_type, int permission, int perm_type, int operation) { @@ -762,7 +761,7 @@ edg_wll_UpdateACL(edg_wll_Context ctx, edg_wlc_JobId job, edg_wll_ResetError(ctx); - md5_jobid = edg_wlc_JobIdGetUnique(job); + md5_jobid = glite_lbu_JobIdGetUnique(job); do { if (acl) @@ -786,7 +785,7 @@ edg_wll_UpdateACL(edg_wll_Context ctx, edg_wlc_JobId job, if ( !acl && (ret = edg_wll_InitAcl(&acl)) ) goto end; - old_aclid = acl->string? strdup(strmd5(acl->string, NULL)): NULL; + old_aclid = acl->string? str2md5(acl->string): NULL; ret = edg_wll_change_acl(acl, user_id, user_id_type, permission, perm_type, operation); @@ -802,7 +801,7 @@ edg_wll_UpdateACL(edg_wll_Context ctx, edg_wlc_JobId job, goto end; } - new_aclid = strdup(strmd5(acl->string, NULL)); + new_aclid = str2md5(acl->string); /* store new ACL or increment its counter if already present in db */ ret = edg_wll_HandleCounterACL(ctx, acl, new_aclid, 1); @@ -817,7 +816,8 @@ edg_wll_UpdateACL(edg_wll_Context ctx, edg_wlc_JobId job, trio_asprintf(&stmt, "update jobs set aclid='%|Ss' where jobid='%|Ss' and ISNULL(aclid)", new_aclid, md5_jobid); - updated = edg_wll_ExecStmt(ctx, stmt, NULL); + updated = glite_lbu_ExecSQL(ctx->dbctx, stmt, NULL); + edg_wll_SetErrorDB(ctx); free(stmt); stmt = NULL; if (updated > 0) @@ -843,15 +843,15 @@ end: return ret; } -int edg_wll_GetACL(edg_wll_Context ctx, edg_wlc_JobId jobid, edg_wll_Acl *acl) +int edg_wll_GetACL(edg_wll_Context ctx, glite_lbu_JobId jobid, edg_wll_Acl *acl) { char *q = NULL; char *acl_id = NULL; char *acl_str = NULL; - edg_wll_Stmt stmt = NULL; + glite_lbu_Statement stmt = NULL; int ret; GRSTgaclAcl *gacl = NULL; - char *jobstr = edg_wlc_JobIdGetUnique(jobid); + char *jobstr = glite_lbu_JobIdGetUnique(jobid); if (jobid == NULL || jobstr == NULL) return edg_wll_SetError(ctx,EINVAL,"edg_wll_GetACL()"); @@ -861,11 +861,12 @@ int edg_wll_GetACL(edg_wll_Context ctx, edg_wlc_JobId jobid, edg_wll_Acl *acl) trio_asprintf(&q, "select aclid from jobs where jobid = '%|Ss'", jobstr); - if (edg_wll_ExecStmt(ctx, q, &stmt) < 0 || - edg_wll_FetchRow(stmt, &acl_id) < 0) { + if (glite_lbu_ExecSQL(ctx->dbctx, q, &stmt) < 0 || + glite_lbu_FetchRow(stmt, 1, NULL, &acl_id) < 0) { + edg_wll_SetErrorDB(ctx); goto end; } - edg_wll_FreeStmt(&stmt); stmt = NULL; + glite_lbu_FreeStmt(&stmt); free(q); q = NULL; if (acl_id == NULL || *acl_id == '\0') { @@ -875,8 +876,9 @@ int edg_wll_GetACL(edg_wll_Context ctx, edg_wlc_JobId jobid, edg_wll_Acl *acl) trio_asprintf(&q, "select value from acls where aclid = '%|Ss'", acl_id); - if (edg_wll_ExecStmt(ctx, q, &stmt) < 0 || - edg_wll_FetchRow(stmt, &acl_str) < 0) { + if (glite_lbu_ExecSQL(ctx->dbctx, q, &stmt) < 0 || + glite_lbu_FetchRow(stmt, 1, NULL, &acl_str) < 0) { + edg_wll_SetErrorDB(ctx); goto end; } @@ -900,7 +902,7 @@ int edg_wll_GetACL(edg_wll_Context ctx, edg_wlc_JobId jobid, edg_wll_Acl *acl) end: if (q) free(q); - if (stmt) edg_wll_FreeStmt(&stmt); + glite_lbu_FreeStmt(&stmt); if (acl_id) free(acl_id); if (acl_str) free(acl_str); /* XXX if (gacl) GRSTgaclAclFree(gacl); */ @@ -926,10 +928,10 @@ int edg_wll_InitAcl(edg_wll_Acl *acl) { return 0; } void edg_wll_FreeAcl(edg_wll_Acl acl) { } int edg_wll_HandleCounterACL(edg_wll_Context ctx, edg_wll_Acl acl, char *aclid, int incr) { return 0; } -int edg_wll_UpdateACL(edg_wll_Context ctx, edg_wlc_JobId job, +int edg_wll_UpdateACL(edg_wll_Context ctx, glite_lbu_JobId job, char *user_id, int user_id_type, int permission, int perm_type, int operation) { return 0; } -int edg_wll_GetACL(edg_wll_Context ctx, edg_wlc_JobId jobid, edg_wll_Acl *acl) { return 0; } +int edg_wll_GetACL(edg_wll_Context ctx, glite_lbu_JobId jobid, edg_wll_Acl *acl) { return 0; } #endif diff --git a/org.glite.lb.server/src/lb_html.c b/org.glite.lb.server/src/lb_html.c index e91a3ba..580ff0c 100644 --- a/org.glite.lb.server/src/lb_html.c +++ b/org.glite.lb.server/src/lb_html.c @@ -23,7 +23,7 @@ int edg_wll_QueryToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *eventsOut } /* construct Message-Body of Response-Line for edg_wll_UserJobs */ -int edg_wll_UserJobsToHTML(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **message) +int edg_wll_UserJobsToHTML(edg_wll_Context ctx, glite_lbu_JobId *jobsOut, char **message) { char *pomA, *pomB; int i = 0; @@ -32,7 +32,7 @@ int edg_wll_UserJobsToHTML(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **m pomB = strdup(""); while (jobsOut[i]) { - char *chid = edg_wlc_JobIdUnparse(jobsOut[i]); + char *chid = glite_lbu_JobIdUnparse(jobsOut[i]); asprintf(&pomA,"%s\t\t
  • %s\r\n", pomB, chid,chid); @@ -68,7 +68,7 @@ int edg_wll_JobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat pomB = strdup(""); - chid = edg_wlc_JobIdUnparse(stat.jobId); + chid = glite_lbu_JobIdUnparse(stat.jobId); #define TR(name,type,field) \ if (field) { \ diff --git a/org.glite.lb.server/src/lb_html.h b/org.glite.lb.server/src/lb_html.h index 1cac83f..3dcfc3a 100644 --- a/org.glite.lb.server/src/lb_html.h +++ b/org.glite.lb.server/src/lb_html.h @@ -7,7 +7,7 @@ int edg_wll_QueryToHTML(edg_wll_Context,edg_wll_Event *,char **); int edg_wll_JobStatusToHTML(edg_wll_Context, edg_wll_JobStat, char **); -int edg_wll_UserJobsToHTML(edg_wll_Context, edg_wlc_JobId *, char **); +int edg_wll_UserJobsToHTML(edg_wll_Context, glite_lbu_JobId *, char **); char *edg_wll_ErrorToHTML(edg_wll_Context,int); #endif diff --git a/org.glite.lb.server/src/lb_plugin.c.T b/org.glite.lb.server/src/lb_plugin.c.T new file mode 100644 index 0000000..37b5529 --- /dev/null +++ b/org.glite.lb.server/src/lb_plugin.c.T @@ -0,0 +1,930 @@ +#ident "$Header$" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "glite/lb/context.h" +#include "glite/lb/jobstat.h" +#include "glite/lb/events.h" +#include "glite/lb/events_parse.h" +#include "glite/lb/producer.h" + +#include "glite/lb-utils/trio.h" +#include "glite/lb-utils/cjobid.h" + +#include "jobstat.h" +#include "get_events.h" + +#include "glite/jp/types.h" +#include "glite/jp/context.h" +#include "glite/jp/file_plugin.h" +#include "glite/jp/builtin_plugins.h" +#include "glite/jp/backend.h" +#include "glite/jp/attr.h" +#include "glite/jp/known_attr.h" +#include "jp_job_attrs_native.h" +#include "jp_job_attrs.h" + +#define INITIAL_NUMBER_EVENTS 100 +#define INITIAL_NUMBER_STATES EDG_WLL_NUMBER_OF_STATCODES +#define LB_PLUGIN_NAMESPACE "urn:org.glite.lb" + +typedef struct _lb_buffer_t { + char *buf; + size_t pos, size; + off_t offset; +} lb_buffer_t; + +typedef struct _lb_historyStatus { + edg_wll_JobStatCode state; + struct timeval timestamp; + char *reason; +} lb_historyStatus; + +typedef struct _lb_handle { + edg_wll_Event **events; + edg_wll_JobStat status; + lb_historyStatus **fullStatusHistory, **lastStatusHistory; +} lb_handle; + +#define check_strdup(s) ((s) ? strdup(s) : NULL) + +extern int processEvent(intJobStat *, edg_wll_Event *, int, int, char **); + +static int lb_query(void *fpctx, void *handle, const char *attr, glite_jp_attrval_t **attrval); +static int lb_open(void *fpctx, void *bhandle, const char *uri, void **handle); +static int lb_close(void *fpctx, void *handle); +static int lb_status(void *handle); +static int read_line(glite_jp_context_t ctx, void *handle, lb_buffer_t *buffer, char **line); + +static int lb_dummy(void *fpctx, void *handle, int oper, ...) { + puts("lb_dummy() - generic call not used; for testing purposes only..."); + return -1; +} + + +int init(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data) { + + data->fpctx = ctx; + + data->uris = calloc(2,sizeof *data->uris); + data->uris[0] = strdup(GLITE_JP_FILETYPE_LB); + + data->classes = calloc(2,sizeof *data->classes); + data->classes[0] = strdup("lb"); + + data->ops.open = lb_open; + data->ops.close = lb_close; + data->ops.attr = lb_query; + data->ops.generic = lb_dummy; + +#ifdef PLUGIN_DEBUG + fprintf(stderr,"lb_plugin: init OK\n"); +#endif + return 0; +} + + +void done(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data) { + + free(data->uris[0]); + free(data->classes[0]); + free(data->uris); + free(data->classes); + memset(data, 0, sizeof(*data)); +} + + +static int lb_open(void *fpctx, void *bhandle, const char *uri, void **handle) { + + lb_handle *h; + lb_buffer_t buffer; + glite_jp_context_t ctx = (glite_jp_context_t) fpctx; + char *line; + int retval; + edg_wll_Context context; + int nevents, maxnevents, i; + glite_jp_error_t err; + char *id0 = NULL,*id = NULL; + + glite_jp_clear_error(ctx); + h = calloc(1, sizeof(lb_handle)); + + if ((retval = edg_wll_InitContext(&context)) != 0) return retval; + + // read the file given by bhandle + // parse events into h->events array + memset(&buffer, 0, sizeof(buffer)); + buffer.buf = malloc(BUFSIZ); + maxnevents = INITIAL_NUMBER_EVENTS; + nevents = 0; + h->events = malloc(maxnevents * sizeof(edg_wll_Event *)); + + if ((retval = read_line(ctx, bhandle, &buffer, &line)) != 0) { + err.code = retval; + err.desc = "reading LB logline"; + err.source = "lb_plugin.c:read_line()"; + glite_jp_stack_error(ctx,&err); + goto fail; + } + while (line) { +#ifdef PLUGIN_DEBUG +// fprintf(stderr,"lb_plugin: line read '%s'\n", line); +#endif + + if (line[0]) { + if (nevents >= maxnevents) { + maxnevents <<= 1; + h->events = realloc(h->events, maxnevents * sizeof(edg_wll_Event *)); + } + if ((retval = edg_wll_ParseEvent(context, line, &h->events[nevents])) != 0) { + char *ed; + free(line); + err.code = retval; + edg_wll_Error(context,NULL,&ed); + err.desc = ed; + err.source = "edg_wll_ParseEvent()"; + glite_jp_stack_error(ctx,&err); + free(ed); + goto fail; + } + if (nevents == 0) { + id0 = glite_lbu_JobIdGetUnique(h->events[nevents]->any.jobId ); + } else { + id = glite_lbu_JobIdGetUnique(h->events[nevents]->any.jobId ); + if (strcmp(id0,id) != 0) { + char et[BUFSIZ]; + retval = EINVAL; + err.code = retval; + snprintf(et,sizeof et,"Attempt to process different jobs. Id '%s' (event n.%d) differs from '%s'",id,nevents+1,id0); + et[BUFSIZ-1] = 0; + err.desc = et; + err.source = "lb_plugin.c:glite_lbu_JobIdGetUnique()"; + glite_jp_stack_error(ctx,&err); + goto fail; + } + } + + if (id) free(id); id = NULL; + nevents++; + } + free(line); + + if ((retval = read_line(ctx, bhandle, &buffer, &line)) != 0) { + err.code = retval; + err.desc = "reading LB logline"; + err.source = "lb_plugin.c:read_line()"; + glite_jp_stack_error(ctx,&err); + goto fail; + } + } + free(line); + + free(buffer.buf); + edg_wll_FreeContext(context); + + if (nevents >= maxnevents) { + maxnevents <<= 1; + h->events = realloc(h->events, maxnevents * sizeof(edg_wll_Event *)); + } + h->events[nevents] = NULL; + +#ifdef PLUGIN_DEBUG + fprintf(stderr,"lb_plugin: opened %d events\n", nevents); +#endif + + /* count state and status history of the job given by the loaded events */ + if ((retval = lb_status(h)) != 0) goto fail; + + *handle = (void *)h; + + return 0; + +fail: +#ifdef PLUGIN_DEBUG + fprintf(stderr,"lb_plugin: open ERROR\n"); +#endif + for (i = 0; i < nevents; i++) { + edg_wll_FreeEvent(h->events[i]); + free(h->events[i]); + } + free(h->events); + free(buffer.buf); + if (id0) free(id0); + if (id) free(id); + edg_wll_FreeContext(context); + free(h); + *handle = NULL; + err.code = EIO; + err.desc = NULL; + err.source = __FUNCTION__; + glite_jp_stack_error(ctx,&err); + + return retval; +} + + +static int lb_close(void *fpctx,void *handle) { + + lb_handle *h = (lb_handle *) handle; + int i; + + // Free allocated stuctures + if (h->events) { + i = 0; + while (h->events[i]) { + edg_wll_FreeEvent(h->events[i]); + free(h->events[i]); + i++; + } + free(h->events); + } + + if (h->status.state != EDG_WLL_JOB_UNDEF) + edg_wll_FreeStatus(&h->status); + + if (h->fullStatusHistory) { + i = 0; + while (h->fullStatusHistory[i]) { + if (h->fullStatusHistory[i]->reason) free(h->fullStatusHistory[i]->reason); + free (h->fullStatusHistory[i]); + i++; + } + } + + free(h); + +#ifdef PLUGIN_DEBUG + fprintf(stderr,"lb_plugin: close OK\n"); +#endif + return 0; +} + + +static int lb_query(void *fpctx,void *handle,const char *attr,glite_jp_attrval_t **attrval) { + + lb_handle *h = (lb_handle *) handle; + glite_jp_context_t ctx = (glite_jp_context_t) fpctx; + glite_jp_error_t err; + glite_jp_attrval_t *av = NULL; + int i, n_tags; + const char *tag; + + glite_jp_clear_error(ctx); + memset(&err,0,sizeof err); + err.source = __FUNCTION__; + + if ((h->events == NULL) || + (h->status.state == EDG_WLL_JOB_UNDEF) || + (h->fullStatusHistory == NULL) ) { + *attrval = NULL; + err.code = ENOENT; + err.desc = strdup("There is no job information to query."); + return glite_jp_stack_error(ctx,&err); + } + + if (strcmp(attr, GLITE_JP_LB_STAT_user) == 0) { + if (h->status.owner) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = strdup(h->status.owner); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_jobId) == 0) { + if (h->status.jobId) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = glite_lbu_JobIdUnparse(h->status.jobId); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_parent) == 0) { + if (h->status.parent_job) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = glite_lbu_JobIdUnparse(h->status.parent_job); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_VO) == 0) { + i = 0; + while (h->events[i]) { + if (h->events[i]->type == EDG_WLL_EVENT_REGJOB) { + struct cclassad *ad; + char *string_vo = NULL; + + ad = cclassad_create(h->events[i]->regJob.jdl); + if (ad) { + if (cclassad_evaluate_to_string(ad, "VirtualOrganisation", &string_vo)) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = check_strdup(string_vo); + av[0].timestamp = h->events[i]->any.timestamp.tv_sec; + } + cclassad_delete(ad); + if (string_vo) free(string_vo); + } + break; + } + i++; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_eNodes) == 0) { + i = 0; + while (h->events[i]) { + if (h->events[i]->type == EDG_WLL_EVENT_REGJOB) { + struct cclassad *ad; + char *string_nodes = NULL; + + ad = cclassad_create(h->events[i]->regJob.jdl); + if (ad) { + if (cclassad_evaluate_to_string(ad, "max_nodes_running", &string_nodes)) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = check_strdup(string_nodes); + av[0].timestamp = h->events[i]->any.timestamp.tv_sec; + } + cclassad_delete(ad); + if (string_nodes) free(string_nodes); + } + break; + } + i++; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_eProc) == 0) { + i = 0; + while (h->events[i]) { + if (h->events[i]->type == EDG_WLL_EVENT_REGJOB) { + struct cclassad *ad; + char *string_nodes = NULL; + + ad = cclassad_create(h->events[i]->regJob.jdl); + if (ad) { + if (cclassad_evaluate_to_string(ad, "NodeNumber", &string_nodes)) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = check_strdup(string_nodes); + av[0].timestamp = h->events[i]->any.timestamp.tv_sec; + } + cclassad_delete(ad); + if (string_nodes) free(string_nodes); + } + break; + } + i++; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_aTag) == 0 || + strcmp(attr, GLITE_JP_LB_STAT_rQType) == 0 || + strcmp(attr, GLITE_JP_LB_STAT_eDuration) == 0) { + /* have to be retrieved from JDL, but probably obsolete and not needed at all */ + char et[BUFSIZ]; + *attrval = NULL; + err.code = ENOSYS; + snprintf(et,sizeof et,"Attribute '%s' not implemented yet.",attr); + et[BUFSIZ-1] = 0; + err.desc = et; + return glite_jp_stack_error(ctx,&err); + } else if (strcmp(attr, GLITE_JP_LB_STAT_RB) == 0) { + if (h->status.network_server) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = strdup(h->status.network_server); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_CE) == 0 || + strcmp(attr, GLITE_JP_LB_destination) == 0) + { + if (h->status.destination) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = strdup(h->status.destination); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_host) == 0) { + if (h->status.ce_node) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = strdup(h->status.ce_node); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_UIHost) == 0) { + if (h->status.location) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = strdup(h->status.location); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_CPUTime) == 0) { + if (h->status.cpuTime) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + trio_asprintf(&av[0].value,"%d", h->status.cpuTime); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_NProc) == 0) { + /* currently LB hasn't got the info */ + char et[BUFSIZ]; + *attrval = NULL; + err.code = ENOSYS; + snprintf(et,sizeof et,"Attribute '%s' not implemented yet.",attr); + et[BUFSIZ-1] = 0; + err.desc = et; + return glite_jp_stack_error(ctx,&err); + } else if (strcmp(attr, GLITE_JP_LB_STAT_finalStatus) == 0) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = edg_wll_StatToString(h->status.state); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } else if (strcmp(attr, GLITE_JP_LB_STAT_finalStatusDate) == 0) { + struct tm *t = NULL; + if ((t = gmtime(&h->status.lastUpdateTime.tv_sec)) != NULL) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + /* dateTime format: yyyy-mm-ddThh:mm:ss.uuuuuu */ + trio_asprintf(&av[0].value,"%04d-%02d-%02dT%02d:%02d:%02d.%06d", + 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec, + h->status.lastUpdateTime.tv_usec); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_finalStatusReason) == 0) { + if (h->status.reason) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = strdup(h->status.reason); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_LRMSDoneStatus) == 0) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = edg_wll_DoneStatus_codeToString(h->status.done_code); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } else if (strcmp(attr, GLITE_JP_LB_STAT_LRMSStatusReason) == 0) { + i = 0; + while (h->events[i]) { + if (h->events[i]->type == EDG_WLL_EVENT_DONE) { + if (h->events[i]->done.reason) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = strdup(h->events[i]->done.reason); + av[0].size = -1; + av[0].timestamp = h->events[i]->any.timestamp.tv_sec; + } + break; + } + i++; + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_retryCount) == 0) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + trio_asprintf(&av[0].value,"%d", h->status.resubmitted); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } else if (strcmp(attr, GLITE_JP_LB_STAT_additionalReason) == 0) { + /* what is it? */ + char et[BUFSIZ]; + *attrval = NULL; + err.code = ENOSYS; + snprintf(et,sizeof et,"Attribute '%s' not implemented yet.",attr); + et[BUFSIZ-1] = 0; + err.desc = et; + return glite_jp_stack_error(ctx,&err); + } else if (strcmp(attr, GLITE_JP_LB_STAT_jobType) == 0) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + switch (h->status.jobtype) { + case EDG_WLL_STAT_SIMPLE: + av[0].value = strdup("SIMPLE"); break; + case EDG_WLL_STAT_DAG: + av[0].value = strdup("DAG"); break; + default: + av[0].value = strdup("UNKNOWN"); break; + } + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } else if (strcmp(attr, GLITE_JP_LB_STAT_nsubjobs) == 0) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + trio_asprintf(&av[0].value,"%d", h->status.children_num); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } else if (strcmp(attr, GLITE_JP_LB_STAT_subjobs) == 0) { + if (h->status.children_num > 0) { + char *val = NULL, *old_val; + + old_val = strdup (""); + for (i=0; istatus.children_num; i++) { + trio_asprintf(&val,"%s\t\t%s\n", + old_val, h->status.children[i] ? h->status.children[i] : ""); + if (old_val) free(old_val); + old_val = val; val = NULL; + } + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = check_strdup(old_val); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + } else { + char et[BUFSIZ]; + *attrval = NULL; + err.code = 0; + snprintf(et,sizeof et,"Value unknown for attribute '%s', there are no subjobs.",attr); + et[BUFSIZ-1] = 0; + err.desc = et; + return glite_jp_stack_error(ctx,&err); + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_lastStatusHistory) == 0) { + int i,j; + char *val, *old_val, *s_str, *t_str, *r_str; + struct tm *t; + + val = s_str = t_str = r_str = NULL; + old_val = strdup(""); + t = calloc(1, sizeof(*t)); + /* first record is Submitted - hopefully in fullStatusHistory[0] */ + if ((h->fullStatusHistory[0] && + (h->fullStatusHistory[0]->state == EDG_WLL_JOB_SUBMITTED)) ) { + + s_str = edg_wll_StatToString(h->fullStatusHistory[0]->state); + for (j = 0; s_str[j]; j++) s_str[j] = toupper(s_str[j]); + if (gmtime_r(&h->fullStatusHistory[0]->timestamp.tv_sec,t) != NULL) { + /* dateTime format: yyyy-mm-ddThh:mm:ss.uuuuuu */ + trio_asprintf(&t_str,"timestamp=\"%04d-%02d-%02dT%02d:%02d:%02d.%06d\" ", + 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec, + h->fullStatusHistory[0]->timestamp.tv_usec); + } + if (h->fullStatusHistory[0]->reason) { + trio_asprintf(&r_str,"reason=\"%s\" ",h->fullStatusHistory[0]->reason); + } + trio_asprintf(&val,"%s\t\t\n", + old_val, s_str ? s_str : "", t_str ? t_str : "", r_str ? r_str : ""); + if (s_str) free(s_str); + if (t_str) free(t_str); + if (r_str) free(t_str); + if (old_val) free(old_val); + old_val = val; val = NULL; + } + /* and the rest is from last Waiting to the end - i.e. all lastStatusHistory[] */ + if (h->lastStatusHistory) { + i = 0; + while (h->lastStatusHistory[i]) { + s_str = edg_wll_StatToString(h->lastStatusHistory[i]->state); + for (j = 0; s_str[j]; j++) s_str[j] = toupper(s_str[j]); + if (gmtime_r(&h->lastStatusHistory[i]->timestamp.tv_sec,t) != NULL) { + /* dateTime format: yyyy-mm-ddThh:mm:ss.uuuuuu */ + trio_asprintf(&t_str,"timestamp=\"%04d-%02d-%02dT%02d:%02d:%02d.%06d\" ", + 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec, + h->lastStatusHistory[i]->timestamp.tv_usec); + } + if (h->lastStatusHistory[i]->reason) { + trio_asprintf(&r_str,"reason=\"%s\" ",h->lastStatusHistory[i]->reason); + } + trio_asprintf(&val,"%s\t\t\n", + old_val, s_str ? s_str : "", t_str ? t_str : "", r_str ? r_str : ""); + if (s_str) free(s_str); s_str = NULL; + if (t_str) free(t_str); t_str = NULL; + if (r_str) free(r_str); r_str = NULL; + if (old_val) free(old_val); + old_val = val; val = NULL; + i++; + } + } + val = old_val; old_val = NULL; + if (val) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = strdup(val); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + free(val); + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_fullStatusHistory) == 0) { + int i,j; + char *val, *old_val, *s_str, *t_str, *r_str; + struct tm *t; + + val = s_str = t_str = r_str = NULL; + old_val = strdup(""); + t = calloc(1, sizeof(*t)); + i = 0; + while (h->fullStatusHistory[i]) { + s_str = edg_wll_StatToString(h->fullStatusHistory[i]->state); + for (j = 0; s_str[j]; j++) s_str[j] = toupper(s_str[j]); + if (gmtime_r(&h->fullStatusHistory[i]->timestamp.tv_sec,t) != NULL) { + /* dateTime format: yyyy-mm-ddThh:mm:ss:uuuuuu */ + trio_asprintf(&t_str,"timestamp=\"%04d-%02d-%02dT%02d:%02d:%02d.%06d\" ", + 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec, + h->fullStatusHistory[i]->timestamp.tv_usec); + } + if (h->fullStatusHistory[i]->reason) { + trio_asprintf(&r_str,"reason=\"%s\" ",h->fullStatusHistory[i]->reason); + } + trio_asprintf(&val,"%s\t\t\n", + old_val, s_str ? s_str : "", t_str ? t_str : "", r_str ? r_str : ""); + if (s_str) free(s_str); s_str = NULL; + if (t_str) free(t_str); t_str = NULL; + if (r_str) free(r_str); r_str = NULL; + if (old_val) free(old_val); + old_val = val; val = NULL; + i++; + } + val = old_val; old_val = NULL; + if (val) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = strdup(val); + av[0].size = -1; + av[0].timestamp = h->status.lastUpdateTime.tv_sec; + free(val); + } + } else if (strncmp(attr, GLITE_JP_LBTAG_NS, sizeof(GLITE_JP_LBTAG_NS)-1) == 0) { + tag = strrchr(attr, ':'); + if (h->events && tag) { + tag++; + i = 0; + n_tags = 0; + + while (h->events[i]) { + if ((h->events[i]->type == EDG_WLL_EVENT_USERTAG) && +/* XXX: LB tag names are case-insensitive */ + (strcasecmp(h->events[i]->userTag.name, tag) == 0) ) { + av = realloc(av, (n_tags+2) * sizeof(glite_jp_attrval_t)); + memset(&av[n_tags], 0, 2 * sizeof(glite_jp_attrval_t)); + + av[n_tags].name = strdup(attr); + av[n_tags].value = check_strdup(h->events[i]->userTag.value); + av[n_tags].timestamp = + h->events[i]->any.timestamp.tv_sec; + av[n_tags].size = -1; + + n_tags++; + } + i++; + } + } + } else if (strcmp(attr, GLITE_JP_LB_STAT_JDL) == 0) { + i = 0; + while (h->events[i]) { + if ((h->events[i]->type == EDG_WLL_EVENT_REGJOB) && + (h->events[i]->regJob.jdl) ) { + av = calloc(2, sizeof(glite_jp_attrval_t)); + av[0].name = strdup(attr); + av[0].value = strdup(h->events[i]->regJob.jdl); + av[0].timestamp = h->events[i]->any.timestamp.tv_sec; + av[0].size = -1; + break; + } + i++; + } +@@@{ + selectType $status '_common_'; + for (getFieldsOrdered $status) { + my $f = selectField $status $_; + next unless $f->{special}->{JP}; + my $t = getType $f; + my $n = getName $f; + my $hn = $n; + + while ($hn =~ /(.*)_(.*)/) { $hn = $1 . ucfirst $2; } + $hn =~ s/[jJ]dl/JDL/; + + my $ts = toString $f "h->status.$n","attr_s"; + gen qq{ +! \} else if (strcmp(attr,GLITE_JP_LB_$hn) == 0) \{ +! char *attr_s; +! $ts +! if (attr_s) \{ +! av = calloc(2, sizeof(glite_jp_attrval_t)); +! av[0].name = strdup(attr); +! av[0].value = attr_s; +! av[0].timestamp = h->status.stateEnterTime.tv_sec; +! av[0].size = -1; +! \} +}; + } +@@@} + } else { + char et[BUFSIZ]; + *attrval = NULL; + err.code = EINVAL; + snprintf(et,sizeof et,"No such attribute '%s'.",attr); + et[BUFSIZ-1] = 0; + err.desc = et; + return glite_jp_stack_error(ctx,&err); + } + + if (av && av[0].value) { + for (i=0; av[i].name; i++) av[i].origin = GLITE_JP_ATTR_ORIG_FILE; + *attrval = av; + return 0; + } else { + char et[BUFSIZ]; + *attrval = NULL; + err.code = ENOENT; + snprintf(et,sizeof et,"Value unknown for attribute '%s'.",attr); + et[BUFSIZ-1] = 0; + err.desc = et; + if (av) glite_jp_attrval_free(av,1); // XXX: probably not needed + return glite_jp_stack_error(ctx,&err); + } +} + + +static int lb_status(void *handle) { + + lb_handle *h = (lb_handle *) handle; + intJobStat *js; + int maxnstates, nstates, i, be_strict = 0, retval; + char *errstring; + edg_wll_JobStatCode old_state = EDG_WLL_JOB_UNDEF; + + js = calloc(1, sizeof(intJobStat)); + init_intJobStat(js); + + + edg_wll_SortPEvents(h->events); + + maxnstates = INITIAL_NUMBER_STATES; + nstates = 0; + h->fullStatusHistory = calloc(maxnstates, sizeof(lb_historyStatus *)); + h->lastStatusHistory = NULL; + i = 0; + while (h->events[i]) + { + /* realloc the fullStatusHistory if needed */ + if (nstates >= maxnstates) { + maxnstates <<= 1; + h->fullStatusHistory = realloc(h->fullStatusHistory, maxnstates * sizeof(lb_historyStatus *)); + } + + /* job owner and jobId not filled from events normally */ + if (h->events[i]->any.type == EDG_WLL_EVENT_REGJOB) { + js->pub.owner = check_strdup(h->events[i]->any.user); + if (glite_lbu_JobIdDup(h->events[i]->any.jobId,&js->pub.jobId)) { + goto err; + } + } + /* Process Event and update the state */ + if (processEvent(js, h->events[i], 0, be_strict, &errstring) == RET_FATAL) { + goto err; + } + + /* if the state has changed, update the status history */ + if (js->pub.state != old_state) { + h->fullStatusHistory[nstates] = calloc(1,sizeof(lb_historyStatus)); + h->fullStatusHistory[nstates]->state = js->pub.state; + h->fullStatusHistory[nstates]->timestamp.tv_sec = js->pub.stateEnterTime.tv_sec; + h->fullStatusHistory[nstates]->timestamp.tv_usec = js->pub.stateEnterTime.tv_usec; + h->fullStatusHistory[nstates]->reason = check_strdup(js->pub.reason); + if (js->pub.state == EDG_WLL_JOB_WAITING) { + h->lastStatusHistory = &(h->fullStatusHistory[nstates]); + } + old_state = js->pub.state; + nstates++; + } + + i++; + } + h->fullStatusHistory[nstates] = NULL; + +/* TODO: fill in also subjobs */ + if (js->pub.children_num > 0) { + edg_wll_Context context; + glite_lbu_JobId *subjobs; + + if ((retval = edg_wll_InitContext(&context)) != 0) return retval; + subjobs = calloc(js->pub.children_num, sizeof (*subjobs)); + if ((retval = edg_wll_GenerateSubjobIds(context, + js->pub.jobId, js->pub.children_num, js->pub.seed, &subjobs) ) != 0 ) { + goto err; + } + js->pub.children = calloc(js->pub.children_num + 1, sizeof (*js->pub.children)); + for (i=0; ipub.children_num; i++) { + js->pub.children[i] = glite_lbu_JobIdUnparse(subjobs[i]); + } + edg_wll_FreeContext(context); + free(subjobs); + } + + memcpy(&h->status, &js->pub, sizeof(edg_wll_JobStat)); + + // not very clean, but working + memset(&js->pub, 0, sizeof(edg_wll_JobStat)); + destroy_intJobStat(js); + + return 0; + +err: + destroy_intJobStat(js); + return -1; +} + + +/* + * realloc the line to double size if needed + * + * \return 0 if failed, did nothing + * \return 1 if success + */ +int check_realloc_line(char **line, size_t *maxlen, size_t len) { + void *tmp; + + if (len > *maxlen) { + *maxlen <<= 1; + tmp = realloc(*line, *maxlen); + if (!tmp) return 0; + *line = tmp; + } + + return 1; +} + + +/* + * read next line from stream + * + * \return error code + */ +static int read_line(glite_jp_context_t ctx, void *handle, lb_buffer_t *buffer, char **line) { + + size_t maxlen, len, i; + ssize_t nbytes; + int retval, z, end; + + maxlen = BUFSIZ; + i = 0; + len = 0; + *line = malloc(maxlen); + end = 0; + + do { + /* read next portion */ + if (buffer->pos >= buffer->size) { + buffer->pos = 0; + buffer->size = 0; + if ((retval = glite_jppsbe_pread(ctx, handle, buffer->buf, BUFSIZ, buffer->offset, &nbytes)) == 0) { + if (nbytes < 0) { + retval = EINVAL; + goto fail; + } else { + if (nbytes) { + buffer->size = (size_t)nbytes; + buffer->offset += nbytes; + } else end = 1; + } + } else goto fail; + } + + /* we have buffer->size - buffer->pos bytes */ + i = buffer->pos; + do { + if (i >= buffer->size) z = '\0'; + else { + z = buffer->buf[i]; + if (z == '\n') z = '\0'; + } + len++; + + if (!check_realloc_line(line, &maxlen, len)) { + retval = ENOMEM; + goto fail; + } + (*line)[len - 1] = z; + i++; + } while (z && i < buffer->size); + buffer->pos = i; + } while (len && (*line)[len - 1] != '\0'); + + if ((!len || !(*line)[0]) && end) { + free(*line); + *line = NULL; + } + + return 0; + +fail: + free(*line); + *line = NULL; + return retval; +} + diff --git a/org.glite.lb.server/src/lb_proto.c b/org.glite.lb.server/src/lb_proto.c index 7dba657..d58de86 100644 --- a/org.glite.lb.server/src/lb_proto.c +++ b/org.glite.lb.server/src/lb_proto.c @@ -288,7 +288,7 @@ edg_wll_ErrorCode edg_wll_ProtoV21(edg_wll_Context ctx, } } else if (!strncmp(requestPTR,KEY_QUERY_JOBS,sizeof(KEY_QUERY_JOBS)-1)) { - edg_wlc_JobId *jobsOut = NULL; + glite_lbu_JobId *jobsOut = NULL; edg_wll_JobStat *statesOut = NULL; edg_wll_QueryRec **conditions = NULL; int i,j, flags = 0; @@ -349,7 +349,7 @@ edg_wll_ErrorCode edg_wll_ProtoV21(edg_wll_Context ctx, } if (jobsOut) { - for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]); + for (i=0; jobsOut[i]; i++) glite_lbu_JobIdFree(jobsOut[i]); free(jobsOut); } if (statesOut) { @@ -425,7 +425,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, /* GET /: Current User Jobs */ if (requestPTR[0]=='/' && (requestPTR[1]==' ' || requestPTR[1]=='?')) { - edg_wlc_JobId *jobsOut = NULL; + glite_lbu_JobId *jobsOut = NULL; int i, flags; flags = (requestPTR[1]=='?') ? edg_wll_string_to_stat_flags(requestPTR + 2) : 0; @@ -447,14 +447,14 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, ret = HTTP_INTERNAL; if (jobsOut) { - for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]); + for (i=0; jobsOut[i]; i++) glite_lbu_JobIdFree(jobsOut[i]); free(jobsOut); } } /* GET /[jobId]: Job Status */ else if (*requestPTR=='/') { - edg_wlc_JobId jobId = NULL; + glite_lbu_JobId jobId = NULL; char *pom1,*fullid = NULL; edg_wll_JobStat stat; char *pomCopy; @@ -473,7 +473,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, asprintf(&fullid,GLITE_WMSC_JOBID_PROTO_PREFIX"%s:%u/%s",ctx->srvName,ctx->srvPort,pomCopy); free(pomCopy); - if (edg_wlc_JobIdParse(fullid, &jobId)) { + if (glite_lbu_JobIdParse(fullid, &jobId)) { edg_wll_SetError(ctx,EDG_WLL_ERROR_JOBID_FORMAT,fullid); ret = HTTP_BADREQ; } @@ -491,7 +491,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, ret = HTTP_INTERNAL; free(fullid); - edg_wlc_JobIdFree(jobId); + glite_lbu_JobIdFree(jobId); edg_wll_FreeStatus(&stat); /* GET [something else]: not understood */ @@ -560,7 +560,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, } } else if (!strncmp(requestPTR,KEY_QUERY_JOBS,sizeof(KEY_QUERY_JOBS)-1)) { - edg_wlc_JobId *jobsOut = NULL; + glite_lbu_JobId *jobsOut = NULL; edg_wll_JobStat *statesOut = NULL; edg_wll_QueryRec **conditions = NULL; int i,j, flags = 0; @@ -623,7 +623,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, } if (jobsOut) { - for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]); + for (i=0; jobsOut[i]; i++) glite_lbu_JobIdFree(jobsOut[i]); free(jobsOut); } if (statesOut) { @@ -792,7 +792,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, else if (!strncmp(requestPTR,KEY_QUERY_SEQUENCE_CODE,sizeof(KEY_QUERY_SEQUENCE_CODE)-1)) { char *source = NULL; char *seqCode = NULL; - edg_wlc_JobId jobId = NULL; + glite_lbu_JobId jobId = NULL; if (parseQuerySequenceCodeRequest(ctx, messageBody, &jobId, &source)) @@ -821,7 +821,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, if ( source ) free(source); if ( seqCode ) free(seqCode); - edg_wlc_JobIdFree(jobId); + glite_lbu_JobIdFree(jobId); } else if (!strncmp(requestPTR,KEY_STATS_REQUEST,sizeof(KEY_STATS_REQUEST)-1)) { char *function; diff --git a/org.glite.lb.server/src/lb_xml_parse.c.T b/org.glite.lb.server/src/lb_xml_parse.c.T index 2365cea..64b4fda 100644 --- a/org.glite.lb.server/src/lb_xml_parse.c.T +++ b/org.glite.lb.server/src/lb_xml_parse.c.T @@ -6,12 +6,12 @@ #include #include -#include "glite/wmsutils/jobid/cjobid.h" +#include "glite/lb-utils/cjobid.h" +#include "glite/lb-utils/escape.h" +#include "glite/lb-utils/trio.h" #include "glite/lb/consumer.h" -#include "glite/lb/escape.h" #include "glite/lb/context-int.h" -#include "glite/lb/trio.h" #include "glite/lb/xml_conversions.h" #include "glite/lb/purge.h" @@ -457,6 +457,24 @@ static void char_handler(void *data, const char *s, int len) memcpy(XMLCtx->char_buf + XMLCtx->char_buf_len, s, len); XMLCtx->char_buf[XMLCtx->char_buf_len + len] = '\0'; XMLCtx->char_buf_len += len; +/* orig _generic + temp_s = malloc(len+1); + + /* otherwise use them */ + memcpy(temp_s,s,len); + temp_s[len] = 0; + temp_s1 = glite_lbu_UnescapeXML((const char *) temp_s); + temp_len1 = strlen(temp_s1); + + if (XMLCtx->char_buf_len) XMLCtx->char_buf = + realloc(XMLCtx->char_buf,XMLCtx->char_buf_len+temp_len1 + 1); + else XMLCtx->char_buf = malloc(temp_len1 + 1); + + memcpy(XMLCtx->char_buf+XMLCtx->char_buf_len,temp_s1,temp_len1 + 1); + XMLCtx->char_buf_len += temp_len1; + free(temp_s1); + free(temp_s); +*/ } @@ -1405,7 +1423,7 @@ int parseNotifRequest(edg_wll_Context ctx, char *messageBody, char **function, e /* parse Sequence Code request from client */ -int parseQuerySequenceCodeRequest(edg_wll_Context ctx, char *messageBody, edg_wlc_JobId *jobId, char **source) +int parseQuerySequenceCodeRequest(edg_wll_Context ctx, char *messageBody, glite_lbu_JobId *jobId, char **source) { int ret; edg_wll_XML_ctx XMLCtx; @@ -1438,7 +1456,7 @@ int parseQuerySequenceCodeRequest(edg_wll_Context ctx, char *messageBody, edg_wl if ((ret = edg_wll_Error(ctx,NULL,NULL))) { if (XMLCtx.jobId) - edg_wlc_JobIdFree(XMLCtx.jobId); + glite_lbu_JobIdFree(XMLCtx.jobId); *jobId = NULL; *source = NULL; @@ -1557,7 +1575,7 @@ int edg_wll_QueryEventsToXML(edg_wll_Context ctx, edg_wll_Event *eventsOut, char return 0; } -int edg_wll_QueryJobsToXML(edg_wll_Context ctx, edg_wlc_JobId *jobsIn, edg_wll_JobStat *statesIn, char **message) +int edg_wll_QueryJobsToXML(edg_wll_Context ctx, glite_lbu_JobId *jobsIn, edg_wll_JobStat *statesIn, char **message) { char *pomA, *pomB, *pomC; char **list = NULL; @@ -1574,7 +1592,7 @@ int edg_wll_QueryJobsToXML(edg_wll_Context ctx, edg_wlc_JobId *jobsIn, edg_wll_J if (jobsIn) { trio_asprintf(&pomA,"%s\t\t%|Xs\r\n", - pomB, pomC=edg_wlc_JobIdUnparse(jobsIn[i])); + pomB, pomC=glite_lbu_JobIdUnparse(jobsIn[i])); free(pomC); free(pomB); pomB = pomA; @@ -1649,7 +1667,7 @@ int edg_wll_QueryJobsToXML(edg_wll_Context ctx, edg_wlc_JobId *jobsIn, edg_wll_J } /* construct Message-Body of Response-Line for edg_wll_UserJobs */ -int edg_wll_UserJobsToXML(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **message) +int edg_wll_UserJobsToXML(edg_wll_Context ctx, glite_lbu_JobId *jobsOut, char **message) { char *pomA, *pomB; char **list = NULL; @@ -1659,7 +1677,7 @@ int edg_wll_UserJobsToXML(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **me while (jobsOut[i]) { len = trio_asprintf(&pomA," %|Xs\r\n", - pomB=edg_wlc_JobIdUnparse(jobsOut[i])); + pomB=glite_lbu_JobIdUnparse(jobsOut[i])); free(pomB); @@ -1780,7 +1798,7 @@ int edg_wll_JobStatusToXML(edg_wll_Context ctx, edg_wll_JobStat stat, char **mes selectType $status '_common_'; for (getFieldsOrdered $status) { my $f = selectField $status $_; - next if defined($f->{special}) && $f->{special} eq 'XMLstructured'; + next if defined($f->{special}) && $f->{special}->{XMLstructured}; my $ft = $f->{type}; my $n = $f->{null}; gen "edg_wll_add_$ft\_to_XMLBody(&pomB, stat.$_, \"$_\", $n);\n"; diff --git a/org.glite.lb.server/src/lb_xml_parse.h b/org.glite.lb.server/src/lb_xml_parse.h index 0d2821e..f021512 100644 --- a/org.glite.lb.server/src/lb_xml_parse.h +++ b/org.glite.lb.server/src/lb_xml_parse.h @@ -22,11 +22,11 @@ int parsePurgeRequest(edg_wll_Context ctx, char *messageBody, int (*tagToIndex)( int parseDumpRequest(edg_wll_Context ctx, char *messageBody, edg_wll_DumpRequest *request); int parseLoadRequest(edg_wll_Context ctx, char *messageBody, edg_wll_LoadRequest *request); int parseNotifRequest(edg_wll_Context ctx, char *messageBody, char **function, edg_wll_NotifId *notifId, char **address, edg_wll_NotifChangeOp *op, edg_wll_QueryRec ***conditions); -int parseQuerySequenceCodeRequest(edg_wll_Context ctx, char *messageBody, edg_wlc_JobId *jobId, char **source); +int parseQuerySequenceCodeRequest(edg_wll_Context ctx, char *messageBody, glite_lbu_JobId *jobId, char **source); int edg_wll_QueryEventsToXML(edg_wll_Context, edg_wll_Event *, char **); -int edg_wll_QueryJobsToXML(edg_wll_Context, edg_wlc_JobId *, edg_wll_JobStat *, char **); +int edg_wll_QueryJobsToXML(edg_wll_Context, glite_lbu_JobId *, edg_wll_JobStat *, char **); int edg_wll_JobStatusToXML(edg_wll_Context, edg_wll_JobStat, char **); -int edg_wll_UserJobsToXML(edg_wll_Context, edg_wlc_JobId *, char **); +int edg_wll_UserJobsToXML(edg_wll_Context, glite_lbu_JobId *, char **); int edg_wll_PurgeResultToXML(edg_wll_Context ctx, edg_wll_PurgeResult *result, char **message); int edg_wll_DumpResultToXML(edg_wll_Context ctx, edg_wll_DumpResult *result, char **message); int edg_wll_LoadResultToXML(edg_wll_Context ctx, edg_wll_LoadResult *result, char **message); diff --git a/org.glite.lb.server/src/lb_xml_parse_V21.c.T b/org.glite.lb.server/src/lb_xml_parse_V21.c.T index 8f20082..3b0b780 100644 --- a/org.glite.lb.server/src/lb_xml_parse_V21.c.T +++ b/org.glite.lb.server/src/lb_xml_parse_V21.c.T @@ -6,12 +6,12 @@ #include #include -#include "glite/wmsutils/jobid/cjobid.h" +#include "glite/lb-utils/cjobid.h" +#include "glite/lb-utils/escape.h" +#include "glite/lb-utils/trio.h" #include "glite/lb/consumer.h" -#include "glite/lb/escape.h" #include "glite/lb/context-int.h" -#include "glite/lb/trio.h" #include "glite/lb/xml_conversions.h" #include "glite/lb/purge.h" @@ -937,7 +937,7 @@ int edg_wll_QueryEventsToXMLV21(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *e return 0; } -int edg_wll_QueryJobsToXMLV21(edg_wll_Context ctx, edg_wlc_JobId *jobsIn, edg_wll_JobStat *statesIn, char **message) +int edg_wll_QueryJobsToXMLV21(edg_wll_Context ctx, glite_lbu_JobId *jobsIn, edg_wll_JobStat *statesIn, char **message) { char *pomA, *pomB, *pomC; char **list = NULL; @@ -954,7 +954,7 @@ int edg_wll_QueryJobsToXMLV21(edg_wll_Context ctx, edg_wlc_JobId *jobsIn, edg_wl if (jobsIn) { trio_asprintf(&pomA,"%s\t\t%|Xs\r\n", - pomB, pomC=edg_wlc_JobIdUnparse(jobsIn[i])); + pomB, pomC=glite_lbu_JobIdUnparse(jobsIn[i])); free(pomC); free(pomB); pomB = pomA; @@ -1029,7 +1029,7 @@ int edg_wll_QueryJobsToXMLV21(edg_wll_Context ctx, edg_wlc_JobId *jobsIn, edg_wl } /* construct Message-Body of Response-Line for edg_wll_UserJobs */ -int edg_wll_UserJobsToXMLV21(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOut, char **message) +int edg_wll_UserJobsToXMLV21(edg_wll_Context ctx UNUSED_VAR, glite_lbu_JobId *jobsOut, char **message) { char *pomA, *pomB; char **list = NULL; @@ -1039,7 +1039,7 @@ int edg_wll_UserJobsToXMLV21(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobs while (jobsOut[i]) { len = trio_asprintf(&pomA," %|Xs\r\n", - pomB=edg_wlc_JobIdUnparse(jobsOut[i])); + pomB=glite_lbu_JobIdUnparse(jobsOut[i])); free(pomB); @@ -1159,7 +1159,7 @@ int edg_wll_JobStatusToXMLV21(edg_wll_Context ctx, edg_wll_JobStat stat, char ** selectType $status '_common_'; for (getFieldsOrdered $status) { my $f = selectField $status $_; - next if defined($f->{special}) && $f->{special} eq 'XMLstructured'; + next if defined($f->{special}) && $f->{special}->{XMLstructured}; my $ft = $f->{type}; my $n = $f->{null}; gen "edg_wll_add_$ft\_to_XMLBody(&pomB, stat.$_, \"$_\", $n);\n"; diff --git a/org.glite.lb.server/src/lb_xml_parse_V21.h b/org.glite.lb.server/src/lb_xml_parse_V21.h index ea731dc..3990686 100644 --- a/org.glite.lb.server/src/lb_xml_parse_V21.h +++ b/org.glite.lb.server/src/lb_xml_parse_V21.h @@ -12,9 +12,9 @@ int parseQueryEventsRequestV21(edg_wll_Context ctx, char *messageBody, edg_wll_Q int parsePurgeRequestV21(edg_wll_Context ctx, char *messageBody, edg_wll_PurgeRequest *request); int parseDumpRequestV21(edg_wll_Context ctx, char *messageBody, edg_wll_DumpRequest *request); int edg_wll_QueryEventsToXMLV21(edg_wll_Context, edg_wll_Event *, char **); -int edg_wll_QueryJobsToXMLV21(edg_wll_Context, edg_wlc_JobId *, edg_wll_JobStat *, char **); +int edg_wll_QueryJobsToXMLV21(edg_wll_Context, glite_lbu_JobId *, edg_wll_JobStat *, char **); int edg_wll_JobStatusToXMLV21(edg_wll_Context, edg_wll_JobStat, char **); -int edg_wll_UserJobsToXMLV21(edg_wll_Context, edg_wlc_JobId *, char **); +int edg_wll_UserJobsToXMLV21(edg_wll_Context, glite_lbu_JobId *, char **); int edg_wll_PurgeResultToXMLV21(edg_wll_Context ctx, edg_wll_PurgeResult *result, char **message); int edg_wll_DumpResultToXMLV21(edg_wll_Context ctx, edg_wll_DumpResult *result, char **message); diff --git a/org.glite.lb.server/src/lbs_db.c b/org.glite.lb.server/src/lbs_db.c index b0aa285..261d8d7 100644 --- a/org.glite.lb.server/src/lbs_db.c +++ b/org.glite.lb.server/src/lbs_db.c @@ -15,7 +15,7 @@ #include "lbs_db.h" #include "glite/lb/context-int.h" -#include "glite/lb/trio.h" +#include "glite/lb-utils/trio.h" #define DEFAULTCS "lbserver/@localhost:lbserver20" diff --git a/org.glite.lb.server/src/load.c b/org.glite.lb.server/src/load.c index f1610c1..5771988 100644 --- a/org.glite.lb.server/src/load.c +++ b/org.glite.lb.server/src/load.c @@ -11,7 +11,8 @@ #include #include -#include "glite/lb/trio.h" +#include "glite/lb-utils/db.h" +#include "glite/lb-utils/trio.h" #include "glite/lb/context-int.h" #include "glite/lb/events_parse.h" @@ -22,9 +23,9 @@ #include "glite/lb/dump.h" #include "glite/lb/load.h" +#include "db_supp.h" #include "store.h" #include "purge.h" -#include "lbs_db.h" #include "query.h" #include "get_events.h" #include "server_state.h" @@ -40,7 +41,7 @@ int edg_wll_LoadEvents(edg_wll_Context ctx,const edg_wll_LoadRequest *req,edg_wl char *line = NULL, buff[30]; edg_wll_Event *event; - edg_wlc_JobId jobid = NULL; + glite_lbu_JobId jobid = NULL; edg_wll_ResetError(ctx); @@ -51,8 +52,8 @@ int edg_wll_LoadEvents(edg_wll_Context ctx,const edg_wll_LoadRequest *req,edg_wl if ( (fd = open(req->server_file, O_RDONLY)) == -1 ) return edg_wll_SetError(ctx, errno, "Server can not open the file"); - if (edg_wll_Transaction(ctx) != 0) - return edg_wll_Error(ctx, NULL, NULL); + if (glite_lbu_Transaction(ctx->dbctx) != 0) + return edg_wll_SetErrorDB(ctx); memset(result,0,sizeof(*result)); i = 0; @@ -61,8 +62,9 @@ int edg_wll_LoadEvents(edg_wll_Context ctx,const edg_wll_LoadRequest *req,edg_wl /* Read one line */ if ( (readret = read_line(&line, &maxsize, fd)) == -1 ) { - edg_wll_Rollback(ctx); - return edg_wll_SetError(ctx, errno, "reading dump file"); + edg_wll_SetError(ctx, errno, "reading dump file"); + glite_lbu_Rollback(ctx->dbctx); + return edg_wll_Error(ctx, NULL, NULL); } if ( readret == 0 ) @@ -135,22 +137,22 @@ int edg_wll_LoadEvents(edg_wll_Context ctx,const edg_wll_LoadRequest *req,edg_wl result->to = event->any.arrived.tv_sec; if ( jobid ) { - char *md5_jobid = edg_wlc_JobIdGetUnique(jobid); + char *md5_jobid = glite_lbu_JobIdGetUnique(jobid); - if ( strcmp(md5_jobid, edg_wlc_JobIdGetUnique(event->any.jobId)) ) + if ( strcmp(md5_jobid, glite_lbu_JobIdGetUnique(event->any.jobId)) ) { edg_wll_JobStat st; edg_wll_JobStatus(ctx, jobid, 0, &st); edg_wll_FreeStatus(&st); - edg_wlc_JobIdFree(jobid); - edg_wlc_JobIdDup(event->any.jobId, &jobid); + glite_lbu_JobIdFree(jobid); + glite_lbu_JobIdDup(event->any.jobId, &jobid); } free(md5_jobid); } else - edg_wlc_JobIdDup(event->any.jobId, &jobid); + glite_lbu_JobIdDup(event->any.jobId, &jobid); } @@ -165,14 +167,14 @@ cycle_clean: edg_wll_JobStatus(ctx, jobid, 0, &st); edg_wll_FreeStatus(&st); - edg_wlc_JobIdFree(jobid); + glite_lbu_JobIdFree(jobid); } if ( reject_fd != -1 ) close(reject_fd); - if (edg_wll_Commit(ctx) != 0) - return edg_wll_Error(ctx, NULL, NULL); + if (glite_lbu_Commit(ctx->dbctx) != 0) + return edg_wll_SetErrorDB(ctx); return edg_wll_Error(ctx,NULL,NULL); } diff --git a/org.glite.lb.server/src/lock.c b/org.glite.lb.server/src/lock.c index 27a8ec1..f3bebd0 100644 --- a/org.glite.lb.server/src/lock.c +++ b/org.glite.lb.server/src/lock.c @@ -5,15 +5,15 @@ #include #include -#include "glite/wmsutils/jobid/cjobid.h" +#include "glite/lb-utils/cjobid.h" #include "glite/lb/context-int.h" #include "lock.h" extern int debug; -int edg_wll_JobSemaphore(const edg_wll_Context ctx, const edg_wlc_JobId job) +int edg_wll_JobSemaphore(const edg_wll_Context ctx, const glite_lbu_JobId job) { - char *un = edg_wlc_JobIdGetUnique(job); + char *un = glite_lbu_JobIdGetUnique(job); int n,i; static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; @@ -31,7 +31,7 @@ int edg_wll_JobSemaphore(const edg_wll_Context ctx, const edg_wlc_JobId job) return(n % ctx->semaphores); } -int edg_wll_LockUnlockJob(const edg_wll_Context ctx,const edg_wlc_JobId job,int lock) +int edg_wll_LockUnlockJob(const edg_wll_Context ctx,const glite_lbu_JobId job,int lock) { struct sembuf s; int n; diff --git a/org.glite.lb.server/src/lock.h b/org.glite.lb.server/src/lock.h index b330177..8593aef 100644 --- a/org.glite.lb.server/src/lock.h +++ b/org.glite.lb.server/src/lock.h @@ -1,5 +1,5 @@ #define edg_wll_LockJob(ctx,job) edg_wll_LockUnlockJob((ctx),(job),-1) #define edg_wll_UnlockJob(ctx,job) edg_wll_LockUnlockJob((ctx),(job),1) -int edg_wll_LockUnlockJob(const edg_wll_Context,const edg_wlc_JobId,int); -int edg_wll_JobSemaphore(const edg_wll_Context ctx, const edg_wlc_JobId job); +int edg_wll_JobSemaphore(const edg_wll_Context ctx, const glite_lbu_JobId job); +int edg_wll_LockUnlockJob(const edg_wll_Context,const glite_lbu_JobId,int); diff --git a/org.glite.lb.server/src/notif_match.c b/org.glite.lb.server/src/notif_match.c index 7b23e73..827e7fb 100644 --- a/org.glite.lb.server/src/notif_match.c +++ b/org.glite.lb.server/src/notif_match.c @@ -6,12 +6,13 @@ #include #include +#include "glite/lb-utils/db.h" #include "glite/lb/producer.h" #include "glite/lb/consumer.h" #include "glite/lb/context-int.h" -#include "glite/lb/trio.h" +#include "glite/lb-utils/trio.h" -#include "lbs_db.h" +#include "db_supp.h" #include "lb_authz.h" #include "lb_xml_parse.h" #include "query.h" @@ -26,7 +27,7 @@ int edg_wll_NotifMatch(edg_wll_Context ctx, const edg_wll_JobStat *stat) { edg_wll_NotifId nid = NULL; char *jobq,*ju = NULL,*jobc[5]; - edg_wll_Stmt jobs = NULL; + glite_lbu_Statement jobs = NULL; int ret,i; time_t now = time(NULL); @@ -42,14 +43,17 @@ int edg_wll_NotifMatch(edg_wll_Context ctx, const edg_wll_JobStat *stat) "from notif_jobs j,users u,notif_registrations n " "where j.notifid=n.notifid and n.userid=u.userid " " and (j.jobid = '%|Ss' or j.jobid = '%|Ss')", - ju = edg_wlc_JobIdGetUnique(stat->jobId),NOTIF_ALL_JOBS); + ju = glite_lbu_JobIdGetUnique(stat->jobId),NOTIF_ALL_JOBS); free(ju); - if (edg_wll_ExecStmt(ctx,jobq,&jobs) < 0) goto err; + if (glite_lbu_ExecSQL(ctx->dbctx,jobq,&jobs) < 0) { + edg_wll_SetErrorDB(ctx); + goto err; + } - while ((ret = edg_wll_FetchRow(jobs,jobc)) > 0) { - if (now > edg_wll_DBToTime(jobc[2])) + while ((ret = glite_lbu_FetchRow(jobs,5,NULL,jobc)) > 0) { + if (now > glite_lbu_DBToTime(jobc[2])) edg_wll_NotifExpired(ctx,jobc[0]); else if (notif_match_conditions(ctx,stat,jobc[4]) && notif_check_acl(ctx,stat,jobc[3])) @@ -58,7 +62,7 @@ int edg_wll_NotifMatch(edg_wll_Context ctx, const edg_wll_JobStat *stat) int port; fprintf(stderr,"NOTIFY: %s, job %s\n",jobc[0], - ju = edg_wlc_JobIdGetUnique(stat->jobId)); + ju = glite_lbu_JobIdGetUnique(stat->jobId)); free(ju); dest = strdup(jobc[1]); @@ -92,12 +96,15 @@ int edg_wll_NotifMatch(edg_wll_Context ctx, const edg_wll_JobStat *stat) for (i=0; i #include -#include "glite/wmsutils/jobid/strmd5.h" -#include "glite/lb/trio.h" +#include "glite/lb-utils/db.h" +#include "glite/lb-utils/strmd5.h" +#include "glite/lb-utils/trio.h" #include "glite/lb/context-int.h" #include "glite/lb/xml_parse.h" #include "glite/lb/notification.h" +#include "db_supp.h" #include "il_notification.h" -#include "lbs_db.h" #include "query.h" @@ -78,8 +79,9 @@ int edg_wll_NotifNewServer( *valid = ctx->peerProxyValidity; else *valid += ctx->notifDuration; - - if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) ) + + glite_lbu_TimeToDB(*valid, &time_s); + if ( !time_s ) { edg_wll_SetError(ctx, errno, NULL); goto cleanup; @@ -107,8 +109,10 @@ int edg_wll_NotifNewServer( "values ('%|Ss','%|Ss',%s,'%|Ss', '%|Ss')", nid_s, addr_s? addr_s: address_override, time_s, owner, xml_conds); - if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 ) + if ( glite_lbu_ExecSQL(ctx->dbctx, q, NULL) < 0 ) { + edg_wll_SetErrorDB(ctx); goto cleanup; + } if (jobs) for ( i = 0; jobs[i]; i++ ) { @@ -116,25 +120,28 @@ int edg_wll_NotifNewServer( trio_asprintf(&q, "insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')", nid_s, jobs[i]); - if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 ) + if ( glite_lbu_ExecSQL(ctx->dbctx, q, NULL) < 0 ) { /* XXX: Remove uncoplete registration? * Which error has to be returned? */ free(q); trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s); - edg_wll_ExecStmt(ctx, q, NULL); + glite_lbu_ExecSQL(ctx->dbctx, q, NULL); free(q); trio_asprintf(&q, "delete from notif_registrations where notifid='%|Ss'", nid_s); - edg_wll_ExecStmt(ctx, q, NULL); + glite_lbu_ExecSQL(ctx->dbctx, q, NULL); + edg_wll_SetErrorDB(ctx); goto cleanup; } } else { trio_asprintf(&q,"insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')", nid_s,NOTIF_ALL_JOBS); - if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 ) goto cleanup; - + if ( glite_lbu_ExecSQL(ctx->dbctx, q, NULL) < 0 ) { + edg_wll_SetErrorDB(ctx); + goto cleanup; + } } @@ -185,7 +192,8 @@ int edg_wll_NotifBindServer( else *valid += ctx->notifDuration; - if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) ) + glite_lbu_TimeToDB(*valid, &time_s); + if ( !time_s ) { edg_wll_SetError(ctx, errno, "Formating validity time"); goto cleanup; @@ -271,8 +279,10 @@ int edg_wll_NotifChangeServer( /* Format DB insert statement */ trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s); - if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 ) + if ( glite_lbu_ExecSQL(ctx->dbctx, q, NULL) < 0 ) { + edg_wll_SetErrorDB(ctx); goto cleanup; + } for ( i = 0; jobs[i]; i++ ) { @@ -280,17 +290,18 @@ int edg_wll_NotifChangeServer( trio_asprintf(&q, "insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')", nid_s, jobs[i]); - if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 ) + if ( glite_lbu_ExecSQL(ctx->dbctx, q, NULL) < 0 ) { /* XXX: Remove uncoplete registration? * Which error has to be returned? */ free(q); trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s); - edg_wll_ExecStmt(ctx, q, NULL); + glite_lbu_ExecSQL(ctx->dbctx, q, NULL); free(q); trio_asprintf(&q,"delete from notif_registrations where notifid='%|Ss'", nid_s); - edg_wll_ExecStmt(ctx, q, NULL); + glite_lbu_ExecSQL(ctx->dbctx, q, NULL); + edg_wll_SetErrorDB(ctx); goto cleanup; } } @@ -340,7 +351,8 @@ int edg_wll_NotifRefreshServer( else *valid += ctx->notifDuration; - if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) ) + glite_lbu_TimeToDB(*valid, &time_s); + if ( !time_s ) { edg_wll_SetError(ctx, errno, "Formating validity time"); goto cleanup; @@ -370,11 +382,14 @@ int edg_wll_NotifDropServer( goto cleanup; trio_asprintf(&stmt, "delete from notif_registrations where notifid='%|Ss'", nid_s); - if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 ) + if ( (ret = glite_lbu_ExecSQL(ctx->dbctx, stmt, NULL)) < 0 ) { + edg_wll_SetErrorDB(ctx); goto cleanup; + } free(stmt); trio_asprintf(&stmt, "delete from notif_jobs where notifid='%|Ss'", nid_s); - edg_wll_ExecStmt(ctx, stmt, NULL); + glite_lbu_ExecSQL(ctx->dbctx, stmt, NULL); + edg_wll_SetErrorDB(ctx); edg_wll_NotifCancelRegId(ctx, nid); cleanup: @@ -387,7 +402,7 @@ cleanup: static char *get_user(edg_wll_Context ctx, int create) { - edg_wll_Stmt stmt = NULL; + glite_lbu_Statement stmt = NULL; char *userid = NULL, *q = NULL; int ret; @@ -399,7 +414,7 @@ static char *get_user(edg_wll_Context ctx, int create) goto cleanup; } trio_asprintf(&q, "select userid from users where cert_subj='%|Ss'", ctx->peerName); - if ( edg_wll_ExecStmt(ctx, q, &stmt) < 0 ) + if ( glite_lbu_ExecSQL(ctx->dbctx, q, &stmt) < 0 ) goto cleanup; /* returned value: @@ -407,10 +422,12 @@ static char *get_user(edg_wll_Context ctx, int create) * >0 user found - return selected value * <0 SQL error */ - if ( ((ret = edg_wll_FetchRow(stmt, &userid)) != 0) || !create ) + if ( ((ret = glite_lbu_FetchRow(stmt, 1, NULL, &userid)) != 0) || !create ) { + edg_wll_SetErrorDB(ctx); goto cleanup; + } - if ( !(userid = strdup(strmd5(ctx->peerName, NULL))) ) + if ( !(userid = str2md5(ctx->peerName)) ) { edg_wll_SetError(ctx, errno, "Creating user ID"); goto cleanup; @@ -418,9 +435,9 @@ static char *get_user(edg_wll_Context ctx, int create) free(q); trio_asprintf(&q, "insert into users(userid,cert_subj) values ('%|Ss','%|Ss')", userid, ctx->peerName); - if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 ) + if ( glite_lbu_ExecSQL(ctx->dbctx, q, NULL) < 0 ) { - if ( edg_wll_Error(ctx,NULL,NULL) != EEXIST ) + if ( edg_wll_SetErrorDB(ctx) != EEXIST ) { free(userid); userid = NULL; @@ -431,7 +448,7 @@ static char *get_user(edg_wll_Context ctx, int create) cleanup: if ( q ) free(q); - if ( stmt ) edg_wll_FreeStmt(&stmt); + if ( stmt ) glite_lbu_FreeStmt(&stmt); return userid; } @@ -463,18 +480,22 @@ static int check_notif_request( "where notifid='%|Ss' and userid='%|Ss'", nid_s, user); - if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 ) + if ( (ret = glite_lbu_ExecSQL(ctx->dbctx, stmt, NULL)) < 0 ) { + edg_wll_SetErrorDB(ctx); goto cleanup; + } if ( ret == 0 ) { free(stmt); trio_asprintf(&stmt, "select notifid from notif_registrations where notifid='%|Ss'", nid_s); - ret = edg_wll_ExecStmt(ctx, stmt, NULL); + ret = glite_lbu_ExecSQL(ctx->dbctx, stmt, NULL); if ( ret == 0 ) edg_wll_SetError(ctx, ENOENT, "Unknown notification ID"); else if ( ret > 0 ) edg_wll_SetError(ctx, EPERM, "Only owner could access the notification"); + else + edg_wll_SetErrorDB(ctx); } cleanup: @@ -533,7 +554,7 @@ static int split_cond_list( if ( jobs ) for ( jobs_ct = i = 0; conditions[i]; i++ ) for ( j = 0; conditions[i][j].attr; j++ ) if ( conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID ) - if ( !(jobs[jobs_ct++] = edg_wlc_JobIdGetUnique(conditions[i][j].value.j)) ) + if ( !(jobs[jobs_ct++] = glite_lbu_JobIdGetUnique(conditions[i][j].value.j)) ) { edg_wll_SetError(ctx, errno, NULL); goto cleanup; @@ -616,14 +637,16 @@ static int update_notif( free(stmt); stmt = aux; - if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 ) + if ( (ret = glite_lbu_ExecSQL(ctx->dbctx, stmt, NULL)) < 0 ) { + edg_wll_SetErrorDB(ctx); goto cleanup; + } if ( ret == 0 ) { free(stmt); trio_asprintf(&stmt, "select notifid from notif_registrations where notifid='%|Ss'", nid_s); - ret = edg_wll_ExecStmt(ctx, stmt, NULL); + ret = glite_lbu_ExecSQL(ctx->dbctx, stmt, NULL); if ( ret == 0 ) edg_wll_SetError(ctx, ENOENT, "Unknown notification ID"); /* @@ -632,6 +655,8 @@ static int update_notif( else if ( ret > 0 ) edg_wll_SetError(ctx, EPERM, "Updating notification records"); */ + else if (ret < 0) + edg_wll_SetErrorDB(ctx); } if ( host ) { diff --git a/org.glite.lb.server/src/process_event.c b/org.glite.lb.server/src/process_event.c index 573a163..8883d9c 100644 --- a/org.glite.lb.server/src/process_event.c +++ b/org.glite.lb.server/src/process_event.c @@ -773,8 +773,8 @@ int processEvent(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char } if (USABLE_DATA(res, strict)) { rep(js->pub.jdl, e->regJob.jdl); - edg_wlc_JobIdFree(js->pub.parent_job); - edg_wlc_JobIdDup(e->regJob.parent, + glite_lbu_JobIdFree(js->pub.parent_job); + glite_lbu_JobIdDup(e->regJob.parent, &js->pub.parent_job); rep(js->pub.network_server, e->regJob.ns); js->pub.children_num = e->regJob.nsubjobs; diff --git a/org.glite.lb.server/src/purge.h b/org.glite.lb.server/src/purge.h index 91adb03..58b581d 100644 --- a/org.glite.lb.server/src/purge.h +++ b/org.glite.lb.server/src/purge.h @@ -15,7 +15,7 @@ int edg_wll_PurgeServer( */ int edg_wll_PurgeServerProxy( edg_wll_Context ctx, - edg_wlc_JobId job + glite_lbu_JobId job ); #define FILE_TYPE_ANY "" diff --git a/org.glite.lb.server/src/query.c b/org.glite.lb.server/src/query.c index 0d77044..a6a3dbf 100644 --- a/org.glite.lb.server/src/query.c +++ b/org.glite.lb.server/src/query.c @@ -7,14 +7,15 @@ #include #include -#include "glite/wmsutils/jobid/strmd5.h" +#include "glite/lb-utils/strmd5.h" +#include "glite/lb-utils/db.h" #include "glite/lb/consumer.h" #include "glite/lb/producer.h" #include "glite/lb/context-int.h" -#include "glite/lb/trio.h" - +#include "glite/lb-utils/trio.h" +#include "db_supp.h" #include "get_events.h" #include "index.h" #include "query.h" @@ -53,7 +54,7 @@ int edg_wll_QueryEventsServer( *q = NULL, *res[11]; edg_wll_Event *out = NULL; - edg_wll_Stmt sh = NULL; + glite_lbu_Statement sh = NULL; int i = 0, ret = 0, offset = 0, limit = 0, @@ -124,12 +125,13 @@ int edg_wll_QueryEventsServer( q = qbase; // printf("\nquery: %s\n\n", q); - ret = edg_wll_ExecStmt(ctx, q, &sh); + ret = glite_lbu_ExecSQL(ctx->dbctx, q, &sh); if ( limit ) free(q); if ( ret < 0 ) { - edg_wll_FreeStmt(&sh); + edg_wll_SetErrorDB(ctx); + glite_lbu_FreeStmt(&sh); goto cleanup; } if ( ret == 0 ) @@ -141,7 +143,7 @@ int edg_wll_QueryEventsServer( limit_loop = 0; offset += ret; - while ( (ret = edg_wll_FetchRow(sh, res)) == sizofa(res) ) + while ( (ret = glite_lbu_FetchRow(sh, sizofa(res), NULL, res)) == sizofa(res) ) { int n = atoi(res[0]); free(res[0]); @@ -150,7 +152,7 @@ int edg_wll_QueryEventsServer( { free(res[1]); memset(out+i, 0, sizeof(*out)); - edg_wll_FreeStmt(&sh); + glite_lbu_FreeStmt(&sh); goto cleanup; } @@ -163,10 +165,14 @@ int edg_wll_QueryEventsServer( if ( !noAuth ) { - if (!ctx->peerName || strcmp(res[1],strmd5(ctx->peerName,NULL))) { + char *s; + + s = str2md5(ctx->peerName); + if (!ctx->peerName || strcmp(res[1],s)) { edg_wll_Acl acl = NULL; char *jobid = NULL; + free(s); ret = edg_wll_GetACL(ctx, out[i].any.jobId, &acl); free(jobid); if (ret || acl == NULL) { @@ -184,7 +190,7 @@ int edg_wll_QueryEventsServer( edg_wll_ResetError(ctx); /* XXX: should be reported somewhere at least in debug mode */ goto fetch_cycle_cleanup; } - } + } else free(s); } if ( (ctx->p_query_results != EDG_WLL_QUERYRES_ALL) && limit && (i+1 > limit) ) @@ -207,8 +213,9 @@ fetch_cycle_cleanup: memset(out+i, 0, sizeof(*out)); free(res[1]); } + if (ret < 0) edg_wll_SetErrorDB(ctx); limit_cycle_cleanup: - edg_wll_FreeStmt(&sh); + glite_lbu_FreeStmt(&sh); } while ( limit_loop ); if ( i == 0 && eperm ) @@ -240,7 +247,7 @@ int edg_wll_QueryJobsServer( edg_wll_Context ctx, const edg_wll_QueryRec **conditions, int flags, - edg_wlc_JobId **jobs, + glite_lbu_JobId **jobs, edg_wll_JobStat **states) { char *job_where = NULL, @@ -249,9 +256,9 @@ int edg_wll_QueryJobsServer( *q = NULL, *qbase = NULL, *res[3]; - edg_wlc_JobId *jobs_out = NULL; + glite_lbu_JobId *jobs_out = NULL; edg_wll_JobStat *states_out = NULL; - edg_wll_Stmt sh; + glite_lbu_Statement sh; int i = 0, ret = 0, eperm = 0, @@ -313,12 +320,13 @@ int edg_wll_QueryJobsServer( q = qbase; // printf("\nquery: %s\n\n", q); - ret = edg_wll_ExecStmt(ctx, q, &sh); + ret = glite_lbu_ExecSQL(ctx->dbctx, q, &sh); if ( limit ) free(q); if ( ret < 0 ) { - edg_wll_FreeStmt(&sh); + edg_wll_SetErrorDB(ctx); + glite_lbu_FreeStmt(&sh); goto cleanup; } if ( ret == 0 ) @@ -330,9 +338,9 @@ int edg_wll_QueryJobsServer( limit_loop = 0; offset += ret; - while ( (ret=edg_wll_FetchRow(sh,res)) > 0 ) + while ( (ret=glite_lbu_FetchRow(sh,sizofa(res),NULL,res)) > 0 ) { - if ( (ret = edg_wlc_JobIdParse(res[0], jobs_out+i)) ) + if ( (ret = glite_lbu_JobIdParse(res[0], jobs_out+i)) ) { /* unlikely to happen, internal inconsistency */ char buf[200]; snprintf(buf,sizeof buf,"JobIdParse(%s)",res[0]); @@ -344,20 +352,20 @@ int edg_wll_QueryJobsServer( if ( check_strict_jobid(ctx, jobs_out[i]) ) { - edg_wlc_JobIdFree(jobs_out[i]); + glite_lbu_JobIdFree(jobs_out[i]); goto fetch_cycle_cleanup; } if ( edg_wll_JobStatus(ctx, jobs_out[i], flags, &states_out[i]) ) { - edg_wlc_JobIdFree(jobs_out[i]); + glite_lbu_JobIdFree(jobs_out[i]); if (edg_wll_Error(ctx,NULL,NULL) == EPERM) eperm = 1; goto fetch_cycle_cleanup; } if ( !match_status(ctx, states_out+i, conditions) ) { - edg_wlc_JobIdFree(jobs_out[i]); + glite_lbu_JobIdFree(jobs_out[i]); edg_wll_FreeStatus(states_out+i); edg_wll_ResetError(ctx); /* check_strict_jobid() sets it */ goto fetch_cycle_cleanup; @@ -367,7 +375,7 @@ int edg_wll_QueryJobsServer( if ( !ctx->noAuth && (!ctx->peerName || strcmp(res[1], strmd5(ctx->peerName, NULL))) ) { eperm = 1; - edg_wlc_JobIdFree(jobs_out[i]); + glite_lbu_JobIdFree(jobs_out[i]); edg_wll_FreeStatus(states_out+i); goto fetch_cycle_cleanup; } @@ -388,7 +396,7 @@ int edg_wll_QueryJobsServer( } i++; - jobs_out = (edg_wlc_JobId *) realloc(jobs_out, (i+1) * sizeof(*jobs_out)); + jobs_out = (glite_lbu_JobId *) realloc(jobs_out, (i+1) * sizeof(*jobs_out)); states_out = (edg_wll_JobStat *) realloc(states_out, (i+1) * sizeof(*states_out)); fetch_cycle_cleanup: @@ -396,8 +404,9 @@ fetch_cycle_cleanup: memset(states_out+i, 0, sizeof(*states_out)); jobs_out[i] = NULL; } + if (ret < 0) edg_wll_SetErrorDB(ctx); limit_cycle_cleanup: - edg_wll_FreeStmt(&sh); + glite_lbu_FreeStmt(&sh); } while ( limit_loop ); if ( eperm && !*jobs_out ) @@ -427,7 +436,7 @@ cleanup: if (jobs_out) { for ( i = 0; jobs_out[i]; i++ ) - edg_wlc_JobIdFree(jobs_out[i]); + glite_lbu_JobIdFree(jobs_out[i]); free(jobs_out); } @@ -603,13 +612,14 @@ static char *ec_to_head_where(edg_wll_Context ctx,const edg_wll_QueryRec **ec) for ( n = 0; ec[m][n].attr; n++ ) switch ( ec[m][n].attr ) { case EDG_WLL_QUERY_ATTR_TIME: - dbt = edg_wll_TimeToDB(ec[m][n].value.t.tv_sec); + glite_lbu_TimeToDB(ec[m][n].value.t.tv_sec, &dbt); if ( conds ) { if ( ec[m][n].op == EDG_WLL_QUERY_OP_WITHIN ) { trio_asprintf(&aux, "%s", dbt); - dbt = edg_wll_TimeToDB(ec[m][n].value2.t.tv_sec); + free(dbt); + glite_lbu_TimeToDB(ec[m][n].value2.t.tv_sec, &dbt); trio_asprintf(&out, "%s OR (e.time_stamp >= %s AND e.time_stamp <= %s)", conds, aux, dbt); free(aux); } @@ -625,7 +635,8 @@ static char *ec_to_head_where(edg_wll_Context ctx,const edg_wll_QueryRec **ec) else if ( ec[m][n].op == EDG_WLL_QUERY_OP_WITHIN ) { trio_asprintf(&aux, "%s", dbt); - dbt = edg_wll_TimeToDB(ec[m][n].value2.t.tv_sec); + free(dbt); + glite_lbu_TimeToDB(ec[m][n].value2.t.tv_sec, &dbt); trio_asprintf(&conds, "(e.time_stamp >= %s AND e.time_stamp <= %s)", aux, dbt); free(aux); } @@ -635,6 +646,8 @@ static char *ec_to_head_where(edg_wll_Context ctx,const edg_wll_QueryRec **ec) } else trio_asprintf(&conds, "e.time_stamp %s %s", opToString(ec[m][n].op), dbt); + + free(dbt); break; case EDG_WLL_QUERY_ATTR_LEVEL: @@ -870,13 +883,13 @@ static char *jc_to_head_where( *where_flags |= FL_SEL_STATUS; - dbt = edg_wll_TimeToDB(jc[m][n].value.t.tv_sec); + glite_lbu_TimeToDB(jc[m][n].value.t.tv_sec, &dbt); if ( conds ) { if ( jc[m][n].op == EDG_WLL_QUERY_OP_WITHIN ) { trio_asprintf(&aux, "%s", dbt); - dbt = edg_wll_TimeToDB(jc[m][n].value2.t.tv_sec); + glite_lbu_TimeToDB(jc[m][n].value2.t.tv_sec, &dbt); trio_asprintf(&tmps, "%s OR (s.%s >= %s AND s.%s <= %s)", conds, cname, aux, cname, dbt); free(aux); } @@ -889,7 +902,7 @@ static char *jc_to_head_where( else if ( jc[m][n].op == EDG_WLL_QUERY_OP_WITHIN ) { trio_asprintf(&aux, "%s", dbt); - dbt = edg_wll_TimeToDB(jc[m][n].value2.t.tv_sec); + glite_lbu_TimeToDB(jc[m][n].value2.t.tv_sec, &dbt); trio_asprintf(&conds, "(s.%s >= %s AND s.%s <= %s)", cname, aux, cname, dbt); free(aux); } @@ -901,7 +914,7 @@ static char *jc_to_head_where( case EDG_WLL_QUERY_ATTR_JOBID: *where_flags |= FL_SEL_JOB; - aux = edg_wlc_JobIdGetUnique(jc[m][n].value.j); + aux = glite_lbu_JobIdGetUnique(jc[m][n].value.j); if ( conds ) { trio_asprintf(&tmps, "%s OR j.jobid%s'%|Ss'", conds, opToString(jc[m][n].op), aux); @@ -918,7 +931,7 @@ static char *jc_to_head_where( break; *where_flags |= FL_SEL_STATUS; - aux = edg_wlc_JobIdGetUnique(jc[m][n].value.j); + aux = glite_lbu_JobIdGetUnique(jc[m][n].value.j); if ( conds ) { trio_asprintf(&tmps, "%s OR s.%s%s'%|Ss'", conds, cname, opToString(jc[m][n].op), aux); @@ -1124,10 +1137,11 @@ int convert_event_head(edg_wll_Context ctx,char **f,edg_wll_Event *e) edg_wll_ResetError(ctx); - if ((ret=edg_wlc_JobIdParse(f[0],&e->any.jobId))) { - edg_wll_SetError(ctx,-ret,"edg_wlc_JobIdParse()"); + if ((ret=glite_lbu_JobIdParse(f[0],&e->any.jobId))) { + edg_wll_SetError(ctx,-ret,"glite_lbu_JobIdParse()"); goto err; } + free(f[0]); e->type = atoi(f[1]); free(f[1]); f[1] = NULL; @@ -1141,7 +1155,7 @@ int convert_event_head(edg_wll_Context ctx,char **f,edg_wll_Event *e) e->any.user = f[4]; f[4] = NULL; - e->any.timestamp.tv_sec = edg_wll_DBToTime(f[5]); + e->any.timestamp.tv_sec = glite_lbu_DBToTime(f[5]); free(f[5]); f[5] = NULL; e->any.timestamp.tv_usec = atoi(f[6]); @@ -1150,7 +1164,7 @@ int convert_event_head(edg_wll_Context ctx,char **f,edg_wll_Event *e) e->any.level = atoi(f[7]); free(f[7]); f[7] = NULL; - e->any.arrived.tv_sec = edg_wll_DBToTime(f[8]); + e->any.arrived.tv_sec = glite_lbu_DBToTime(f[8]); e->any.arrived.tv_usec = 0; free(f[8]); f[8] = NULL; @@ -1283,8 +1297,8 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll case EDG_WLL_QUERY_ATTR_JOBID: if ( !stat->jobId ) break; - s = edg_wlc_JobIdUnparse(stat->jobId); - s1 = edg_wlc_JobIdUnparse(conds[i][j].value.j); + s = glite_lbu_JobIdUnparse(stat->jobId); + s1 = glite_lbu_JobIdUnparse(conds[i][j].value.j); if ( s && s1 ) { int r = strcmp(s1, s); @@ -1297,8 +1311,8 @@ int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll case EDG_WLL_QUERY_ATTR_PARENT: if ( !stat->parent_job ) break; - s = edg_wlc_JobIdUnparse(stat->parent_job); - s1 = edg_wlc_JobIdUnparse(conds[i][j].value.j); + s = glite_lbu_JobIdUnparse(stat->parent_job); + s1 = glite_lbu_JobIdUnparse(conds[i][j].value.j); if ( s && s1 ) { int r = strcmp(s1, s); @@ -1381,7 +1395,7 @@ static int cmp_string(const char *s1,edg_wll_QueryOp op,const char *s2) } -int check_strict_jobid(edg_wll_Context ctx, const edg_wlc_JobId job) +int check_strict_jobid(edg_wll_Context ctx, const glite_lbu_JobId job) { char *job_host; unsigned int job_port; @@ -1391,13 +1405,13 @@ int check_strict_jobid(edg_wll_Context ctx, const edg_wlc_JobId job) /* Allow all jobids when server name is not set. */ if ( (ctx->srvName == NULL) || (ctx->isProxy)) return edg_wll_Error(ctx,NULL,NULL); - edg_wlc_JobIdGetServerParts(job,&job_host,&job_port); + glite_lbu_JobIdGetServerParts(job,&job_host,&job_port); if (strcasecmp(job_host,ctx->srvName) || job_port != ctx->srvPort) { char *jobid,msg[300]; - jobid = edg_wlc_JobIdUnparse(job); + jobid = glite_lbu_JobIdUnparse(job); snprintf(msg,sizeof msg,"%s: does not match server address",jobid); msg[sizeof msg - 1] = 0; edg_wll_SetError(ctx,EINVAL,msg); diff --git a/org.glite.lb.server/src/query.h b/org.glite.lb.server/src/query.h index fe9c9e8..dd0a144 100644 --- a/org.glite.lb.server/src/query.h +++ b/org.glite.lb.server/src/query.h @@ -1,5 +1,5 @@ int convert_event_head(edg_wll_Context,char **,edg_wll_Event *); -int check_strict_jobid(edg_wll_Context, const edg_wlc_JobId); +int check_strict_jobid(edg_wll_Context, const glite_lbu_JobId); int match_status(edg_wll_Context, const edg_wll_JobStat *stat,const edg_wll_QueryRec **conditions); #define NOTIF_ALL_JOBS "all_jobs" diff --git a/org.glite.lb.server/src/request.c b/org.glite.lb.server/src/request.c index cb84b1f..de5b6e3 100644 --- a/org.glite.lb.server/src/request.c +++ b/org.glite.lb.server/src/request.c @@ -4,12 +4,13 @@ #include #include +#include "glite/lb-utils/db.h" #include "glite/lb/il_string.h" #include "glite/lb/il_msg.h" #include "glite/lb/context-int.h" +#include "db_supp.h" #include "store.h" -#include "lbs_db.h" #ifdef __GNUC__ #define UNUSED_VAR __attribute__((unused)) @@ -52,7 +53,19 @@ handle_request(edg_wll_Context ctx,char *buf) return EDG_WLL_IL_PROTO; } - ret = trans_db_store(ctx, event.data, NULL, NULL); + if ((ret = glite_lbu_Transaction(ctx->dbctx) != 0)) { + edg_wll_SetErrorDB(ctx); + goto err; + } + ret = db_store(ctx, "NOT USED", event.data); + if (ret == 0) { + if ((ret = glite_lbu_Commit(ctx->dbctx)) != 0) { + edg_wll_SetErrorDB(ctx); + goto err; + } + } else { + glite_lbu_Rollback(ctx->dbctx); + } if(event.data) free(event.data); diff --git a/org.glite.lb.server/src/seqcode.c b/org.glite.lb.server/src/seqcode.c index a6e7596..e007be3 100644 --- a/org.glite.lb.server/src/seqcode.c +++ b/org.glite.lb.server/src/seqcode.c @@ -2,9 +2,11 @@ #include +#include "glite/lb-utils/db.h" #include "glite/lb/context-int.h" -#include "glite/lb/trio.h" +#include "glite/lb-utils/trio.h" +#include "db_supp.h" #include "get_events.h" #include "store.h" #include "lock.h" @@ -15,9 +17,9 @@ -int edg_wll_QuerySequenceCodeServer(edg_wll_Context ctx, edg_wlc_JobId jobid, const char *source, char **seqcode) +int edg_wll_QuerySequenceCodeServer(edg_wll_Context ctx, glite_lbu_JobId jobid, const char *source, char **seqcode) { - edg_wll_Stmt sh; + glite_lbu_Statement sh; intJobStat *istat = NULL; char *jobid_md5 = NULL, *stmt = NULL, @@ -27,7 +29,7 @@ int edg_wll_QuerySequenceCodeServer(edg_wll_Context ctx, edg_wlc_JobId jobid, co edg_wll_ResetError(ctx); - jobid_md5 = edg_wlc_JobIdGetUnique(jobid); + jobid_md5 = glite_lbu_JobIdGetUnique(jobid); trio_asprintf(&stmt, "select int_status from states " @@ -36,12 +38,18 @@ int edg_wll_QuerySequenceCodeServer(edg_wll_Context ctx, edg_wlc_JobId jobid, co if ( stmt == NULL ) return edg_wll_SetError(ctx, ENOMEM, NULL); - if ( (nstates = edg_wll_ExecStmt(ctx, stmt, &sh)) < 0 ) goto cleanup; + if ( (nstates = glite_lbu_ExecSQL(ctx->dbctx, stmt, &sh)) < 0 ) { + edg_wll_SetErrorDB(ctx); + goto cleanup; + } if ( nstates == 0 ) { edg_wll_SetError(ctx, ENOENT, "no state in DB"); goto cleanup; } - if ( edg_wll_FetchRow(sh, &res) < 0 ) goto cleanup; + if ( glite_lbu_FetchRow(sh, 1,NULL,&res) < 0 ) { + edg_wll_SetErrorDB(ctx); + goto cleanup; + } istat = dec_intJobStat(res, &res_rest); if ( res_rest && istat ) { @@ -55,7 +63,7 @@ cleanup: free(res); free(jobid_md5); free(stmt); - edg_wll_FreeStmt(&sh); + glite_lbu_FreeStmt(&sh); if ( istat ) { destroy_intJobStat(istat); free(istat); diff --git a/org.glite.lb.server/src/server_state.c b/org.glite.lb.server/src/server_state.c index d2bf8f0..fb2c449 100644 --- a/org.glite.lb.server/src/server_state.c +++ b/org.glite.lb.server/src/server_state.c @@ -1,30 +1,31 @@ #ident "$Header$" -#include "glite/lb/trio.h" +#include "glite/lb-utils/db.h" +#include "glite/lb-utils/trio.h" #include "glite/lb/context-int.h" -#include "lbs_db.h" +#include "db_supp.h" #include "server_state.h" int edg_wll_GetServerState(edg_wll_Context ctx,const char *name,char **val) { char *stmt = NULL; - edg_wll_Stmt q = NULL; - + glite_lbu_Statement q = NULL; + *val = NULL; trio_asprintf(&stmt,"select value from server_state " "where prefix = 'https://%|Ss:%d' and name = '%|Ss'", ctx->srvName,ctx->srvPort,name); - switch (edg_wll_ExecStmt(ctx,stmt,&q)) { + switch (glite_lbu_ExecSQL(ctx->dbctx,stmt,&q)) { case 0: edg_wll_SetError(ctx,ENOENT,name); break; - case -1: break; - default: edg_wll_FetchRow(q,val); break; + case -1: edg_wll_SetErrorDB(ctx); break; + default: glite_lbu_FetchRow(q,1,NULL,val); break; } - edg_wll_FreeStmt(&q); + glite_lbu_FreeStmt(&q); free(stmt); - return edg_wll_Error(ctx,NULL,NULL); + return edg_wll_Error(ctx, NULL, NULL); } int edg_wll_SetServerState(edg_wll_Context ctx,const char *name,const char *val) @@ -35,7 +36,7 @@ int edg_wll_SetServerState(edg_wll_Context ctx,const char *name,const char *val) "values ('https://%|Ss:%d','%|Ss','%|Ss')", ctx->srvName,ctx->srvPort,name,val); - switch(edg_wll_ExecStmt(ctx,stmt,NULL)) { + switch(glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL)) { case 1: break; case -1: if (edg_wll_Error(ctx,NULL,NULL) == EEXIST) { free(stmt); @@ -43,12 +44,12 @@ int edg_wll_SetServerState(edg_wll_Context ctx,const char *name,const char *val) "where prefix = 'https://%|Ss:%d' " "and name = '%|Ss'", val,ctx->srvName,ctx->srvPort,name); - edg_wll_ExecStmt(ctx,stmt,NULL); + glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL); } break; default: abort(); } free(stmt); - return edg_wll_Error(ctx,NULL,NULL); + return edg_wll_SetErrorDB(ctx); } diff --git a/org.glite.lb.server/src/srv-context.h b/org.glite.lb.server/src/srv-context.h new file mode 100644 index 0000000..e76a9ac --- /dev/null +++ b/org.glite.lb.server/src/srv-context.h @@ -0,0 +1,18 @@ + +typedef struct _glite_lb_SrvContext { + glite_lb_SrvFlesh *flesh; +} * glite_lb_SrvContext; + +typedef struct _glite_lb_SrvFlesh { + int (*JobIdGetUnique)(char *jobid); + +/** compute state from blob, retrive whatever else is required */ + int (*ComputeStateBlob)(glite_lb_SrvContext ctx,glite_lbu_Blob *state_blob,const glite_lb_StateOpts *opts,glite_lb_Status **state_out); + +/** retrieve necessary events via bones, compute state */ + int (*ComputeStateFull)(glite_lb_SrvContext ctx,const char *job, + const glite_lb_StateOpts *opts, + glite_lb_State **state_out, + glite_lbu_Blob *blob_out); + +} glite_lb_SrvFlesh; diff --git a/org.glite.lb.server/src/srv_purge.c b/org.glite.lb.server/src/srv_purge.c index 5a625bd..c537b78 100644 --- a/org.glite.lb.server/src/srv_purge.c +++ b/org.glite.lb.server/src/srv_purge.c @@ -10,19 +10,20 @@ #include #include -#include "glite/wmsutils/jobid/cjobid.h" +#include "glite/lb-utils/cjobid.h" -#include "glite/lb/trio.h" +#include "glite/lb-utils/db.h" +#include "glite/lb-utils/trio.h" #include "glite/lb/context-int.h" #include "glite/lb/events_parse.h" #include "glite/lb/mini_http.h" #include "glite/lb/ulm_parse.h" +#include "db_supp.h" #include "lb_html.h" #include "lb_proto.h" #include "store.h" #include "lock.h" -#include "lbs_db.h" #include "query.h" #include "get_events.h" #include "glite/lb/purge.h" @@ -44,7 +45,7 @@ static const char* const resp_headers[] = { NULL }; -static int purge_one(edg_wll_Context ctx,const edg_wlc_JobId,int,int); +static int purge_one(edg_wll_Context ctx,const glite_lbu_JobId,int,int); int edg_wll_CreateTmpFileStorage(edg_wll_Context ctx, char *prefix, char **fname) { @@ -183,7 +184,7 @@ int edg_wll_CreateFileStorage(edg_wll_Context ctx, char *file_type, char *prefix return retfd; } -int edg_wll_PurgeServerProxy(edg_wll_Context ctx, edg_wlc_JobId job) +int edg_wll_PurgeServerProxy(edg_wll_Context ctx, glite_lbu_JobId job) { switch ( purge_one(ctx, job, -1, 1) ) { case 0: @@ -199,7 +200,7 @@ int edg_wll_PurgeServerProxy(edg_wll_Context ctx, edg_wlc_JobId job) int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request) { int i,parse = 0,dumpfile = -1; - edg_wlc_JobId job; + glite_lbu_JobId job; char *message = NULL, *response = NULL; char *tmpfname = NULL; int naffected_jobs = 0; @@ -235,7 +236,7 @@ int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request) } if (request->jobs) for (i=0; request->jobs[i]; i++) { - if (edg_wlc_JobIdParse(request->jobs[i],&job)) { + if (glite_lbu_JobIdParse(request->jobs[i],&job)) { fprintf(stderr,"%s: parse error\n",request->jobs[i]); parse = 1; } @@ -260,11 +261,11 @@ int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request) } } - edg_wlc_JobIdFree(job); + glite_lbu_JobIdFree(job); } } else { - edg_wll_Stmt s; + glite_lbu_Statement s; char *job_s; int res; time_t timeout[EDG_WLL_NUMBER_OF_STATCODES], @@ -273,9 +274,12 @@ int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request) for (i=0; itimeout[i] < 0 ? ctx->purge_timeout[i] : request->timeout[i]; - if (edg_wll_ExecStmt(ctx,"select dg_jobid from jobs",&s) < 0) goto abort; - while ((res = edg_wll_FetchRow(s,&job_s)) > 0) { - if (edg_wlc_JobIdParse(job_s,&job)) { + if (glite_lbu_ExecSQL(ctx->dbctx,"select dg_jobid from jobs",&s) < 0) { + edg_wll_SetErrorDB(ctx); + goto abort; + } + while ((res = glite_lbu_FetchRow(s,1,NULL,&job_s)) > 0) { + if (glite_lbu_JobIdParse(job_s,&job)) { fprintf(stderr,"%s: parse error (internal inconsistency !)\n",job_s); parse = 1; } @@ -283,7 +287,7 @@ int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request) edg_wll_JobStat stat; if (check_strict_jobid(ctx,job)) { - edg_wlc_JobIdFree(job); + glite_lbu_JobIdFree(job); free(job_s); parse = 1; continue; @@ -317,15 +321,13 @@ int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request) naffected_jobs++; } - edg_wlc_JobIdFree(job); + glite_lbu_JobIdFree(job); edg_wll_FreeStatus(&stat); free(job_s); } } - edg_wll_FreeStmt(&s); abort: - // just for escaping from nested cycles - ; /* prevent compiler to complain */ + glite_lbu_FreeStmt(&s); } if (parse && !edg_wll_Error(ctx,NULL,NULL)) @@ -385,12 +387,12 @@ abort: return edg_wll_Error(ctx,NULL,NULL); } -static void unlock_and_check(edg_wll_Context ctx,edg_wlc_JobId job) +static void unlock_and_check(edg_wll_Context ctx,glite_lbu_JobId job) { char *job_s,*et,*ed; if (edg_wll_UnlockJob(ctx,job)) { - job_s = edg_wlc_JobIdUnparse(job); + job_s = glite_lbu_JobIdUnparse(job); edg_wll_Error(ctx,&et,&ed); fprintf(stderr,"%s: edg_wll_UnlockJob(): %s (%s) -- expect bogus things\n", @@ -402,23 +404,23 @@ static void unlock_and_check(edg_wll_Context ctx,edg_wlc_JobId job) } -int purge_one(edg_wll_Context ctx,const edg_wlc_JobId job,int dump, int purge) +int purge_one(edg_wll_Context ctx,const glite_lbu_JobId job,int dump, int purge) { char *dbjob; char *stmt = NULL; - edg_wll_Stmt q; + glite_lbu_Statement q; int ret,dumped = 0; edg_wll_ResetError(ctx); if ( !purge && dump < 0 ) return 0; - dbjob = edg_wlc_JobIdGetUnique(job); /* XXX: strict jobid already checked */ + dbjob = glite_lbu_JobIdGetUnique(job); /* XXX: strict jobid already checked */ if (edg_wll_LockJob(ctx,job)) goto clean; if ( purge ) { trio_asprintf(&stmt,"delete from jobs where jobid = '%|Ss'",dbjob); - ret = edg_wll_ExecStmt(ctx,stmt,NULL); + ret = glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL); if (ret <= 0) { unlock_and_check(ctx,job); if (ret == 0) { @@ -430,7 +432,7 @@ int purge_one(edg_wll_Context ctx,const edg_wlc_JobId job,int dump, int purge) free(stmt); stmt = NULL; trio_asprintf(&stmt,"delete from states where jobid = '%|Ss'",dbjob); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) { + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) { unlock_and_check(ctx,job); goto clean; } @@ -438,7 +440,7 @@ int purge_one(edg_wll_Context ctx,const edg_wlc_JobId job,int dump, int purge) /* Why on earth ? trio_asprintf(&stmt,"delete from states where jobid = '%|Ss'",dbjob); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) { + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) { unlock_and_check(ctx,job); goto clean; } @@ -452,7 +454,7 @@ int purge_one(edg_wll_Context ctx,const edg_wlc_JobId job,int dump, int purge) if ( purge ) { trio_asprintf(&stmt,"delete from status_tags where jobid = '%|Ss'",dbjob); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto unlock; + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) goto unlock; free(stmt); stmt = NULL; } @@ -469,11 +471,11 @@ int purge_one(edg_wll_Context ctx,const edg_wlc_JobId job,int dump, int purge) "order by event", dbjob); /* check for events repeatedly -- new one may have arrived in the meantime */ - while ((ret = edg_wll_ExecStmt(ctx,stmt,&q)) > 0) { + while ((ret = glite_lbu_ExecSQL(ctx->dbctx,stmt,&q)) > 0) { char *res[9]; dumped = 1; - while ((ret = edg_wll_FetchRow(q,res)) > 0) { + while ((ret = glite_lbu_FetchRow(q,dump >= 0 ? 9 : 1,NULL,res)) > 0) { int event; event = atoi(res[0]); @@ -483,7 +485,7 @@ int purge_one(edg_wll_Context ctx,const edg_wlc_JobId job,int dump, int purge) edg_wll_Event e; assert(ret == 9); - res[0] = edg_wlc_JobIdUnparse(job); + res[0] = glite_lbu_JobIdUnparse(job); if (convert_event_head(ctx,res,&e) || edg_wll_get_event_flesh(ctx,event,&e)) { char *et,*ed; @@ -515,6 +517,7 @@ int purge_one(edg_wll_Context ctx,const edg_wlc_JobId job,int dump, int purge) written = write(dump,arr_s+total,len-total); if (written < 0 && errno != EAGAIN) { edg_wll_SetError(ctx,errno,"writing dump file"); + glite_lbu_FreeStmt(&q); free(event_s); goto clean; } @@ -554,17 +557,20 @@ int purge_one(edg_wll_Context ctx,const edg_wlc_JobId job,int dump, int purge) } } } - edg_wll_FreeStmt(&q); - if (ret < 0 || !purge) break; + glite_lbu_FreeStmt(&q); + if (ret < 0 || !purge) { + edg_wll_SetErrorDB(ctx); + break; + } } - edg_wll_FreeStmt(&q); if (ret == 0 && dumped == 0) { if (ctx->strict_locking) unlock_and_check(ctx,job); fprintf(stderr,"%s: no events, i.e. no such job or internal inconsistency\n",dbjob); edg_wll_SetError(ctx,ENOENT,dbjob); goto clean; } + if (ret < 0) edg_wll_SetErrorDB(ctx); unlock: if (ctx->strict_locking) unlock_and_check(ctx,job); diff --git a/org.glite.lb.server/src/stats.c b/org.glite.lb.server/src/stats.c index 45d799d..25a38c1 100644 --- a/org.glite.lb.server/src/stats.c +++ b/org.glite.lb.server/src/stats.c @@ -11,7 +11,7 @@ #include "glite/lb/jobstat.h" #include "glite/lb/context-int.h" -#include "glite/wmsutils/jobid/strmd5.h" +#include "glite/lb-utils/strmd5.h" #include "stats.h" static int stats_inc_counter(edg_wll_Context,const edg_wll_JobStat *,edg_wll_Stats *); diff --git a/org.glite.lb.server/src/store.c.T b/org.glite.lb.server/src/store.c.T index 1f4fcd3..5ef96e9 100644 --- a/org.glite.lb.server/src/store.c.T +++ b/org.glite.lb.server/src/store.c.T @@ -19,30 +19,36 @@ #include -#include "glite/wmsutils/jobid/strmd5.h" +#include "glite/lb-utils/strmd5.h" +#include "glite/lb-utils/db.h" #include "glite/lb/events_parse.h" #include "glite/lb/context-int.h" #include "glite/lb/producer.h" #include "glite/lb/log_proto.h" /* for EDG_WLL_LOG_USER_DEFAULT */ -#include "glite/lb/trio.h" +#include "glite/lb-utils/trio.h" +#include "db_supp.h" #include "store.h" #include "get_events.h" -#include "lbs_db.h" #include "lock.h" #include "lb_authz.h" #include "jobstat.h" static int store_user(edg_wll_Context,const char *,const char *); -static int store_job(edg_wll_Context,const edg_wlc_JobId,const char *); -static int store_job_block(edg_wll_Context, const edg_wlc_JobId, const char *, edg_wll_bufInsert *); +static int store_job(edg_wll_Context,const glite_lbu_JobId,const char *); +#ifdef LB_BUF +static int store_job_block(edg_wll_Context, const glite_lbu_JobId, const char *, glite_lbu_bufInsert); +#endif static int store_flesh(edg_wll_Context,edg_wll_Event *,char *,int); static int store_seq(edg_wll_Context,edg_wll_Event *,int); static int check_dup(edg_wll_Context,edg_wll_Event *); static int check_auth(edg_wll_Context,edg_wll_Event *e); -static int register_subjobs(edg_wll_Context,const edg_wll_RegJobEvent *); +#ifdef LB_DAG_EMBRIONIC static int register_subjobs_embryonic(edg_wll_Context,const edg_wll_RegJobEvent *); +#else +static int register_subjobs(edg_wll_Context,const edg_wll_RegJobEvent *); +#endif void edg_wll_StoreAnonymous(edg_wll_Context ctx,int anon) { ctx->allowAnonymous = anon; @@ -53,7 +59,7 @@ int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq) edg_wll_ErrorCode err = 0; char *userid = NULL,*jobid,*stmt; char *select_max,*ssrc; - edg_wll_Stmt sh = NULL; + glite_lbu_Statement sh; int next = 0xDEAD; int lbproxy_notreg = 0; char *now_s = NULL; @@ -61,10 +67,9 @@ int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq) ssrc = jobid = stmt = select_max = NULL; if ( ctx->event_load ) - now_s = strdup(edg_wll_TimeToDB(e->any.arrived.tv_sec)); + glite_lbu_TimeToDB(e->any.arrived.tv_sec, &now_s); else - now_s = strdup(edg_wll_TimeToDB(time(NULL))); - + glite_lbu_TimeToDB(time(NULL), &now_s); edg_wll_ResetError(ctx); switch (err = check_auth(ctx,e)) { case 0: break; @@ -81,12 +86,12 @@ int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq) } if ((err = check_dup(ctx,e))) goto clean; - userid = strdup(strmd5(e->any.user,NULL)); + userid = str2md5(e->any.user); /* make sure user record is there */ if ((err = store_user(ctx,userid,e->any.user))) goto clean; - jobid = edg_wlc_JobIdGetUnique(e->any.jobId); + jobid = glite_lbu_JobIdGetUnique(e->any.jobId); /* only REGJOB events determine job owner now */ if ( (e->type == EDG_WLL_EVENT_REGJOB || lbproxy_notreg) @@ -102,15 +107,15 @@ int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq) /* try to insert (someone else may be doing the same) */ while (1) { - char *max; + char *max, *stamp; - if (edg_wll_ExecStmt(ctx,select_max,&sh) < 0 || - edg_wll_FetchRow(sh,&max) < 0) + if (glite_lbu_ExecSQL(ctx->dbctx,select_max,&sh) < 0 || + glite_lbu_FetchRow(sh,1,NULL,&max) < 0) { - err = edg_wll_Error(ctx,NULL,NULL); + err = edg_wll_SetErrorDB(ctx); goto clean; } - edg_wll_FreeStmt(&sh); + glite_lbu_FreeStmt(&sh); next = max && *max ? atoi(max)+1 : 0; @@ -118,21 +123,23 @@ int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq) * 1) when using transactions: * Store the whole event right now. * - * 2) when not using transaction: + * 2) when not using transactions: * Store an UNDEF event first in order to prevent race condition * with readers and update event code later. */ + glite_lbu_TimeToDB(e->any.timestamp.tv_sec, &stamp); trio_asprintf(&stmt, "insert into events(jobid,event,code,prog,host,time_stamp,usec,arrived,level,userid) " "values ('%|Ss',%d,%d,'%|Ss','%|Ss',%s,%d,%s,%d,'%|Ss')", jobid,next, - ctx->use_transactions ? (int) e->any.type : EDG_WLL_EVENT_UNDEF, + glite_lbu_DBQueryCaps(ctx->dbctx) & GLITE_LBU_DB_CAP_TRANSACTIONS ? (int) e->any.type : EDG_WLL_EVENT_UNDEF, ssrc,e->any.host, - edg_wll_TimeToDB(e->any.timestamp.tv_sec),e->any.timestamp.tv_usec, + stamp,e->any.timestamp.tv_usec, now_s, e->any.level,userid); + free(stamp); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) { - if ((err = edg_wll_Error(ctx,NULL,NULL)) != EEXIST) + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) { + if ((err = edg_wll_SetErrorDB(ctx)) != EEXIST) goto clean; } else break; /* successful insert */ @@ -151,14 +158,14 @@ int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq) edg_wll_SetError(ctx,oerr,desc); free(desc); } else - if (!ctx->use_transactions) { + if ((glite_lbu_DBQueryCaps(ctx->dbctx) & GLITE_LBU_DB_CAP_TRANSACTIONS) == 0) { /* emulate commit, i.e. swith to a real event type to make * the record valid */ trio_asprintf(&stmt, "update events set code=%d " "where jobid='%|Ss' and event=%d", (int) e->any.type,jobid,next); - switch (edg_wll_ExecStmt(ctx,stmt,NULL)) { + switch (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL)) { case 0: if (ctx->strict_locking) err = edg_wll_SetError(ctx,ENOENT,"event disappeared on store while strict locking"); /* purge in progres: drop the garbage, ignore errors */ @@ -176,26 +183,26 @@ int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq) trio_asprintf(&stmt, "select 'x' from jobs where jobid='%|Ss'", jobid); - switch (edg_wll_ExecStmt(ctx,stmt,NULL)) { + switch (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL)) { case 1: break; case 0: /* purge in progres */ edg_wll_delete_event(ctx,jobid,next); err = edg_wll_SetError(ctx,ENOENT,"job being purged"); break; + case -1: err = edg_wll_SetErrorDB(ctx); break; default: err = edg_wll_SetError(ctx,EDG_WLL_ERROR_DB_CALL, "more job records, what is that?"); break; } } break; - case -1: err = edg_wll_Error(ctx,NULL,NULL); + case -1: err = edg_wll_SetErrorDB(ctx); break; - default: err = edg_wll_SetError(ctx,EDG_WLL_ERROR_DB_CALL, "more event records, what is that?"); break; } - } /* if !ctx->use_transactions */ + } /* !transactions */ if (err == 0 && e->any.type == EDG_WLL_EVENT_REGJOB && @@ -218,7 +225,6 @@ clean: free(stmt); free(ssrc); free(select_max); - if (sh) edg_wll_FreeStmt(&sh); if (!err && seq) *seq = next; return err; } @@ -230,8 +236,8 @@ static int store_user(edg_wll_Context ctx,const char *userid,const char *subj) trio_asprintf(&stmt,"insert into users(userid,cert_subj) " "values ('%|Ss','%|Ss')",userid,subj); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) { - if (edg_wll_Error(ctx,NULL,NULL) == EEXIST) + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) { + if (edg_wll_SetErrorDB(ctx) == EEXIST) edg_wll_ResetError(ctx); } @@ -239,10 +245,10 @@ static int store_user(edg_wll_Context ctx,const char *userid,const char *subj) return edg_wll_Error(ctx,NULL,NULL); } -static int store_job(edg_wll_Context ctx,const edg_wlc_JobId job,const char *userid) +static int store_job(edg_wll_Context ctx,const glite_lbu_JobId job,const char *userid) { - char *jobstr = edg_wlc_JobIdUnparse(job); - char *jobid = edg_wlc_JobIdGetUnique(job); + char *jobstr = glite_lbu_JobIdUnparse(job); + char *jobid = glite_lbu_JobIdGetUnique(job); char *stmt; /* debug Duplicate key on index: Duplicate entry '(nil)' for key 1 @@ -254,8 +260,8 @@ static int store_job(edg_wll_Context ctx,const edg_wlc_JobId job,const char *use trio_asprintf(&stmt,"insert into jobs(jobid,dg_jobid,userid) " "values ('%|Ss','%|Ss','%|Ss')",jobid,jobstr,userid); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) { - if (edg_wll_Error(ctx,NULL,NULL) == EEXIST) + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) { + if (edg_wll_SetErrorDB(ctx) == EEXIST) edg_wll_ResetError(ctx); } free(stmt); @@ -264,10 +270,11 @@ static int store_job(edg_wll_Context ctx,const edg_wlc_JobId job,const char *use return edg_wll_Error(ctx,NULL,NULL); } -static int store_job_block(edg_wll_Context ctx,const edg_wlc_JobId job,const char *userid, edg_wll_bufInsert *bi) +#ifdef LB_BUF +static int store_job_block(edg_wll_Context ctx,const glite_lbu_JobId job,const char *userid, glite_lbu_bufInsert bi) { - char *jobstr = edg_wlc_JobIdUnparse(job); - char *jobid = edg_wlc_JobIdGetUnique(job); + char *jobstr = glite_lbu_JobIdUnparse(job); + char *jobid = glite_lbu_JobIdGetUnique(job); char *row; /* debug Duplicate key on index: Duplicate entry '(nil)' for key 1 @@ -278,12 +285,14 @@ static int store_job_block(edg_wll_Context ctx,const edg_wlc_JobId job,const cha edg_wll_ResetError(ctx); trio_asprintf(&row, "'%|Ss','%|Ss','%|Ss'", jobid,jobstr,userid); - edg_wll_bufferedInsert(bi, row); // no need to free row + glite_lbu_bufferedInsert(bi, row); // no need to free row + edg_wll_SetErrorDB(ctx); free(jobstr); free(jobid); return edg_wll_Error(ctx,NULL,NULL); } +#endif /* * XXX: store it in SHORT_FIELDS for now despite it should go to dedicated @@ -296,14 +305,16 @@ static int store_seq(edg_wll_Context ctx,edg_wll_Event *e,int no) { int ret; char *stmt; - char *jobid = edg_wlc_JobIdGetUnique(e->any.jobId); + char *jobid = glite_lbu_JobIdGetUnique(e->any.jobId); edg_wll_ResetError(ctx); trio_asprintf(&stmt,"insert into short_fields(jobid,event,name,value) " "values ('%|Ss',%d,'SEQCODE','%|Ss')", jobid,no,e->any.seqcode); - ret = edg_wll_ExecStmt(ctx,stmt,NULL); + ret = glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL); + edg_wll_SetErrorDB(ctx); + free(stmt); free(jobid); @@ -367,7 +378,7 @@ static int store_flesh(edg_wll_Context ctx,edg_wll_Event *e,char *jobid,int no) strlen(f[i].val) <= SHORT_LEN ? "short_fields" : "long_fields", jobid,no,f[i].key,f[i].val); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) err = edg_wll_SetErrorDB(ctx); free(stmt); } for (i=0; iany.src_instance); - if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL); + if (glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL) < 0) err = edg_wll_SetErrorDB(ctx); free(stmt); } @@ -454,9 +465,9 @@ static int check_dup(edg_wll_Context ctx,edg_wll_Event *e) static int check_auth(edg_wll_Context ctx,edg_wll_Event *e) { - char *jobid = edg_wlc_JobIdGetUnique(e->any.jobId); + char *jobid = glite_lbu_JobIdGetUnique(e->any.jobId); char *q = NULL,*owner = NULL; - edg_wll_Stmt stmt = NULL; + glite_lbu_Statement stmt = NULL; char *user; edg_wll_ResetError(ctx); @@ -467,9 +478,12 @@ static int check_auth(edg_wll_Context ctx,edg_wll_Event *e) trio_asprintf(&q,"select userid from jobs where jobid='%|Ss'",jobid); - if (edg_wll_ExecStmt(ctx,q,&stmt) < 0 - || edg_wll_FetchRow(stmt,&owner) < 0 - ) goto clean; + if (glite_lbu_ExecSQL(ctx->dbctx,q,&stmt) < 0 + || glite_lbu_FetchRow(stmt,1,NULL,&owner) < 0 + ) { + edg_wll_SetErrorDB(ctx); + goto clean; + } if (!owner) { if ( ctx->isProxy && !e->any.seqcode ) @@ -487,8 +501,9 @@ static int check_auth(edg_wll_Context ctx,edg_wll_Event *e) case EDG_WLL_SOURCE_USER_INTERFACE: case EDG_WLL_SOURCE_LRMS: case EDG_WLL_SOURCE_APPLICATION: - user = strmd5(e->any.user,NULL); + user = str2md5(e->any.user); if (strcmp(owner,user)) edg_wll_SetError(ctx,EPERM,"check_auth()"); + free(user); break; default: /* XXX: just don't allow anonymous */ @@ -499,16 +514,17 @@ static int check_auth(edg_wll_Context ctx,edg_wll_Event *e) clean: - if (stmt) edg_wll_FreeStmt(&stmt); + if (stmt) glite_lbu_FreeStmt(&stmt); free(q); free(owner); return edg_wll_Error(ctx,NULL,NULL); } +#ifndef LB_DAG_EMBRIONIC static int register_subjobs(edg_wll_Context ctx,const edg_wll_RegJobEvent *e) { int i,err; - edg_wlc_JobId *subjobs; + glite_lbu_JobId *subjobs; struct timeval now; edg_wll_ResetError(ctx); @@ -542,7 +558,7 @@ static int register_subjobs(edg_wll_Context ctx,const edg_wll_RegJobEvent *e) e2.any.src_instance = strdup(ctx->isProxy ? "L&B proxy" : "L&B server"); e2.regJob.ns = strdup(e->ns); - edg_wlc_JobIdDup(e->jobId,&e2.regJob.parent); + glite_lbu_JobIdDup(e->jobId,&e2.regJob.parent); e2.regJob.jobtype = EDG_WLL_REGJOB_SIMPLE; e2.regJob.jdl = strdup(""); @@ -553,7 +569,7 @@ static int register_subjobs(edg_wll_Context ctx,const edg_wll_RegJobEvent *e) default: edg_wll_Error(ctx,&et,&ed); - job_s = edg_wlc_JobIdUnparse(e2.any.jobId); + job_s = glite_lbu_JobIdUnparse(e2.any.jobId); fprintf(stderr,"register subjob %s: %s (%s)\n",job_s,et,ed); syslog(LOG_ERR,"register subjob %s: %s (%s)",job_s,et,ed); free(job_s); free(et); free(ed); @@ -563,7 +579,7 @@ static int register_subjobs(edg_wll_Context ctx,const edg_wll_RegJobEvent *e) } if (edg_wll_LockJob(ctx,e2.any.jobId)) { - job_s = edg_wlc_JobIdUnparse(e2.any.jobId); + job_s = glite_lbu_JobIdUnparse(e2.any.jobId); fprintf(stderr,"lock job %s: %s (%s)\n",job_s,et,ed); syslog(LOG_ERR,"lock job %s: %s (%s)",job_s,et,ed); free(job_s); free(et); free(ed); @@ -579,7 +595,7 @@ static int register_subjobs(edg_wll_Context ctx,const edg_wll_RegJobEvent *e) edg_wll_ResetError(ctx); if (err) { - job_s = edg_wlc_JobIdUnparse(e2.any.jobId); + job_s = glite_lbu_JobIdUnparse(e2.any.jobId); fprintf(stderr,"%s: %s (%s)\n",job_s,et,ed); syslog(LOG_ERR,"%s: %s (%s)",job_s,et,ed); free(job_s); free(et); free(ed); @@ -592,6 +608,7 @@ static int register_subjobs(edg_wll_Context ctx,const edg_wll_RegJobEvent *e) free(subjobs); return edg_wll_Error(ctx,NULL,NULL); } +#endif /* @@ -600,7 +617,7 @@ static int register_subjobs(edg_wll_Context ctx,const edg_wll_RegJobEvent *e) static edg_wll_ErrorCode states_values_embryonic( edg_wll_Context ctx, - edg_wlc_JobId jobid, + glite_lbu_JobId jobid, const edg_wll_RegJobEvent *e, char **icnames, char **values) @@ -612,14 +629,14 @@ static edg_wll_ErrorCode states_values_embryonic( intJobStat *stat = &stat_rec; init_intJobStat(stat); - if (edg_wlc_JobIdDup(jobid, &stat->pub.jobId) || - edg_wlc_JobIdDup(e->jobId, &stat->pub.parent_job)) goto err; + if (glite_lbu_JobIdDup(jobid, &stat->pub.jobId) || + glite_lbu_JobIdDup(e->jobId, &stat->pub.parent_job)) goto err; stat->pub.state = EDG_WLL_JOB_SUBMITTED; stat->pub.owner = strdup(e->user); stat->pub.stateEnterTimes[1 + EDG_WLL_JOB_SUBMITTED] = (int)e->timestamp.tv_sec; - jobid_md5 = edg_wlc_JobIdGetUnique(jobid); - parent_md5 = edg_wlc_JobIdGetUnique(e->jobId); + jobid_md5 = glite_lbu_JobIdGetUnique(jobid); + parent_md5 = glite_lbu_JobIdGetUnique(e->jobId); stat_enc = enc_intJobStat(strdup(""), stat); if (jobid_md5 == NULL || parent_md5 == NULL || stat_enc == NULL) goto err; @@ -643,15 +660,17 @@ err: static int register_subjobs_embryonic(edg_wll_Context ctx,const edg_wll_RegJobEvent *e) { int i, err = 0; - edg_wlc_JobId *subjobs; + glite_lbu_JobId *subjobs; struct timeval now; - char *userid = strdup(strmd5(e->user,NULL)); - char *jobid_md5, *jobid_md5_old, *states_cols; + char *userid = str2md5(e->user); + char *jobid_md5, *jobid_md5_old; size_t jobid_len; - edg_wll_bufInsert bi_j, bi_s; - edg_wll_bufInsert *bi_jobs = &bi_j, *bi_states = &bi_s; char *icnames, *values; - + glite_lbu_bufInsert bi_states; +#ifdef LB_BUF + char *states_cols; + glite_lbu_bufInsert bi_jobs; +#endif edg_wll_ResetError(ctx); @@ -663,22 +682,22 @@ static int register_subjobs_embryonic(edg_wll_Context ctx,const edg_wll_RegJobEv /* find out icnames and values once, then only change jobids */ if (states_values_embryonic(ctx, subjobs[0], e, &icnames, &values)) edg_wll_Error(ctx, NULL, NULL); - jobid_md5_old = edg_wlc_JobIdGetUnique(subjobs[0]); + jobid_md5_old = glite_lbu_JobIdGetUnique(subjobs[0]); jobid_len = strlen(jobid_md5_old); #ifdef LB_BUF /* init multirows insert mechanism for tables used here */ - if (edg_wll_bufferedInsertInit(ctx, bi_jobs, NULL, "jobs", 4000, 1000, + if (glite_lbu_bufferedInsertInit(ctx->dbctx, &bi_jobs, NULL, "jobs", 4000, 1000, "jobid, dg_jobid, userid")) { - return edg_wll_SetError(ctx, EINVAL, "edg_wll_bufferedInsertInit()"); + return edg_wll_SetErrorDB(ctx); } asprintf(&states_cols,"jobid, status, seq,int_status, version, parent_job%s", icnames); - if (edg_wll_bufferedInsertInit(ctx, bi_states, NULL, "states", 4000, 1000, states_cols)) + if (glite_lbu_bufferedInsertInit(ctx->dbctx, &bi_states, NULL, "states", 4000, 1000, states_cols)) { - return edg_wll_SetError(ctx, EINVAL, "edg_wll_bufferedInsertInit()"); + return edg_wll_SetErrorDB(ctx); } free(states_cols); #endif @@ -703,7 +722,7 @@ static int register_subjobs_embryonic(edg_wll_Context ctx,const edg_wll_RegJobEv /* interchange variable parts (jobids) in values */ /* there are only two occurences of subjob jobid */ - jobid_md5 = edg_wlc_JobIdGetUnique(subjobs[i]); + jobid_md5 = glite_lbu_JobIdGetUnique(subjobs[i]); if (i) { p = strstr(values, jobid_md5_old); assert(p); @@ -719,18 +738,18 @@ static int register_subjobs_embryonic(edg_wll_Context ctx,const edg_wll_RegJobEv if (!err && (err = edg_wll_StoreIntStateEmbryonic(ctx, subjobs[i], icnames, values, bi_states))) edg_wll_Error(ctx,&et,&ed); -//job_s = edg_wlc_JobIdUnparse(subjobs[i]); +//job_s = glite_lbu_JobIdUnparse(subjobs[i]); //printf("%s\n", job_s); //free(job_s); if (err) { - job_s = edg_wlc_JobIdUnparse(subjobs[i]); + job_s = glite_lbu_JobIdUnparse(subjobs[i]); fprintf(stderr,"%s: %s (%s)\n",job_s,et,ed); syslog(LOG_ERR,"%s: %s (%s)",job_s,et,ed); free(job_s); free(et); free(ed); edg_wll_ResetError(ctx); } - edg_wlc_JobIdFree(subjobs[i]); + glite_lbu_JobIdFree(subjobs[i]); } free(jobid_md5_old); //free the last one @@ -740,8 +759,8 @@ static int register_subjobs_embryonic(edg_wll_Context ctx,const edg_wll_RegJobEv #ifdef LB_BUF /* commit the rest of multirows insert and clean structures */ - edg_wll_bufferedInsertClose(bi_jobs); - edg_wll_bufferedInsertClose(bi_states); + glite_lbu_bufferedInsertClose(bi_jobs); + glite_lbu_bufferedInsertClose(bi_states); #endif return edg_wll_Error(ctx,NULL,NULL); @@ -761,20 +780,20 @@ int edg_wll_delete_event(edg_wll_Context ctx,const char *jobid,int event) trio_asprintf(&stmt, "delete from short_fields where jobid='%|Ss' and event=%d", jobid,event); - edg_wll_ExecStmt(ctx,stmt,NULL); + glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL); free(stmt); trio_asprintf(&stmt, "delete from long_fields where jobid='%|Ss' and event=%d", jobid,event); - edg_wll_ExecStmt(ctx,stmt,NULL); + glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL); free(stmt); trio_asprintf(&stmt, "delete from events where jobid='%|Ss' and event=%d", jobid,event); - edg_wll_ExecStmt(ctx,stmt,NULL); + glite_lbu_ExecSQL(ctx->dbctx,stmt,NULL); free (stmt); - return edg_wll_Error(ctx,NULL,NULL); + return edg_wll_SetErrorDB(ctx); } diff --git a/org.glite.lb.server/src/userjobs.c b/org.glite.lb.server/src/userjobs.c index 66448f0..d277583 100644 --- a/org.glite.lb.server/src/userjobs.c +++ b/org.glite.lb.server/src/userjobs.c @@ -5,56 +5,63 @@ #include #include -#include "glite/wmsutils/jobid/cjobid.h" -#include "glite/wmsutils/jobid/strmd5.h" +#include "glite/lb-utils/db.h" +#include "glite/lb-utils/cjobid.h" +#include "glite/lb-utils/strmd5.h" #include "glite/lb/context-int.h" -#include "glite/lb/trio.h" +#include "glite/lb-utils/trio.h" -#include "lbs_db.h" +#include "db_supp.h" int edg_wll_UserJobs( edg_wll_Context ctx, - edg_wlc_JobId **jobs, + glite_lbu_JobId **jobs, edg_wll_JobStat **states) { - char *userid = strmd5(ctx->peerName,NULL),*stmt = NULL, + char *userid = str2md5(ctx->peerName),*stmt = NULL, *res = NULL; int njobs = 0,ret,i; - edg_wlc_JobId *out = NULL; - edg_wll_Stmt sth = NULL; + glite_lbu_JobId *out = NULL; + glite_lbu_Statement sth = NULL; edg_wll_ErrorCode err = 0; edg_wll_ResetError(ctx); trio_asprintf(&stmt,"select cert_subj from users where userid = '%|Ss'",userid); - switch (edg_wll_ExecStmt(ctx,stmt,&sth)) { + switch (glite_lbu_ExecSQL(ctx->dbctx,stmt,&sth)) { case 0: edg_wll_SetError(ctx,ENOENT,ctx->peerName); - case -1: goto err; + case -1: edg_wll_SetErrorDB(ctx); goto err; default: - if (edg_wll_FetchRow(sth,&res) < 0) goto err; + if (glite_lbu_FetchRow(sth,1,NULL,&res) < 0) { + edg_wll_SetErrorDB(ctx); + goto err; + } if (strcmp(ctx->peerName,res)) { edg_wll_SetError(ctx,EDG_WLL_ERROR_MD5_CLASH,ctx->peerName); goto err; } } - edg_wll_FreeStmt(&sth); + glite_lbu_FreeStmt(&sth); free(stmt); stmt = NULL; free(res); res = NULL; trio_asprintf(&stmt,"select dg_jobid from jobs where userid = '%|Ss'",userid); - switch (njobs = edg_wll_ExecStmt(ctx,stmt,&sth)) { + switch (njobs = glite_lbu_ExecSQL(ctx->dbctx,stmt,&sth)) { case 0: edg_wll_SetError(ctx,ENOENT,ctx->peerName); - case -1: goto err; + case -1: edg_wll_SetErrorDB(ctx); goto err; } out = malloc(sizeof(*out)*(njobs+1)); memset(out,0,sizeof(*out)*(njobs+1)); - for (i=0; (ret = edg_wll_FetchRow(sth,&res)); i++) { - if (ret < 0) goto err; - if ((ret = edg_wlc_JobIdParse(res,out+i))) { + for (i=0; (ret = glite_lbu_FetchRow(sth,1,NULL,&res)); i++) { + if (ret < 0) { + edg_wll_SetErrorDB(ctx); + goto err; + } + if ((ret = glite_lbu_JobIdParse(res,out+i))) { edg_wll_SetError(ctx,errno,res); goto err; } @@ -64,11 +71,12 @@ int edg_wll_UserJobs( err: free(res); free(stmt); - edg_wll_FreeStmt(&sth); + free(userid); + glite_lbu_FreeStmt(&sth); if ((err = edg_wll_Error(ctx,NULL,NULL))) { if (out) { for (i=0; i -#include "glite/lb/trio.h" +#include "glite/lb-utils/trio.h" #include "glite/lb/producer.h" #include "glite/lb/context-int.h" #include "glite/lb/jobstat.h" @@ -156,9 +156,9 @@ char* write2rgma_statline(edg_wll_JobStat *stat) char *string_jobid, *string_stat, *string_server; char *string_vo = NULL; - string_jobid = edg_wlc_JobIdUnparse(stat->jobId); + string_jobid = glite_lbu_JobIdUnparse(stat->jobId); string_stat = edg_wll_StatToString(stat->state); - string_server = edg_wlc_JobIdGetServer(stat->jobId); + string_server = glite_lbu_JobIdGetServer(stat->jobId); if (stat->jdl != NULL) { struct cclassad *ad; diff --git a/org.glite.lb.server/src/ws_query.c b/org.glite.lb.server/src/ws_query.c index 814f0ad..55c01f2 100644 --- a/org.glite.lb.server/src/ws_query.c +++ b/org.glite.lb.server/src/ws_query.c @@ -24,7 +24,7 @@ static void freeQueryRecsExt(edg_wll_QueryRec **qr); -static void freeJobIds(edg_wlc_JobId *jobs); +static void freeJobIds(glite_lbu_JobId *jobs); static void freeJobStats(edg_wll_JobStat *stats); static void freeEvents(edg_wll_Event *events); @@ -46,28 +46,24 @@ SOAP_FMAC5 int SOAP_FMAC6 __lb__JobStatus( struct _lbe__JobStatusResponse *out) { edg_wll_Context ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap); - edg_wlc_JobId j; - edg_wll_JobStat s; + glite_lb_Status *s = NULL; + glite_lb_StatusOpts *opts = NULL; int flags; + + glite_lb_Legacy_SetFlesh(ctx); - - if ( edg_wlc_JobIdParse(in->jobid, &j) ) + if (glite_lb_Legacy_SoapToJobStatOpts(in->flags, &opts) || + glite_lb_JobStatus(ctx, in->jobid, opts, &s) || + glite_lb_Legacy_StatusToSoap(soap, s, &(out->stat)) ) { - edg_wll_SetError(ctx, EINVAL, in->jobid); edg_wll_ErrToFault(ctx, soap); + if (s) glite_lb_FreeStatus(ctx,s); + if (opts) glite_lb_FreeStatusOpts(ctx,opts); return SOAP_FAULT; } - edg_wll_SoapToJobStatFlags(in->flags, &flags); - - if ( edg_wll_JobStatus(ctx, j, flags, &s) ) - { - edg_wll_ErrToFault(ctx, soap); - return SOAP_FAULT; - } - - edg_wll_StatusToSoap(soap, &s, &(out->stat)); - + glite_lb_FreeStatusOpts(ctx,opts); + glite_lb_FreeStatus(ctx,s); return SOAP_OK; } @@ -80,7 +76,7 @@ SOAP_FMAC5 int SOAP_FMAC6 __lb__QueryJobs( edg_wll_Context ctx; edg_wll_QueryRec **conditions; int flags; - edg_wlc_JobId *jobs; + glite_lbu_JobId *jobs; edg_wll_JobStat *states; int ret; @@ -210,12 +206,12 @@ static void freeQueryRecsExt(edg_wll_QueryRec **qr) { } -static void freeJobIds(edg_wlc_JobId *jobs) { +static void freeJobIds(glite_lbu_JobId *jobs) { int i; if ( jobs ) { for ( i = 0; jobs[i]; i++ ) - edg_wlc_JobIdFree(jobs[i]); + glite_lbu_JobIdFree(jobs[i]); free(jobs); } } diff --git a/org.glite.lb.server/src/ws_typeref.c.T b/org.glite.lb.server/src/ws_typeref.c.T index 9106493..8741582 100644 --- a/org.glite.lb.server/src/ws_typeref.c.T +++ b/org.glite.lb.server/src/ws_typeref.c.T @@ -66,7 +66,7 @@ sub eventFieldAssign { gen $indent."$dest->tvSec = $source.tv_sec;\n"; gen $indent."$dest->tvUsec = $source.tv_usec;\n"; } elsif ($tn eq 'jobid') { - gen $indent."s = edg_wlc_JobIdUnparse($source);\n"; + gen $indent."s = glite_lbu_JobIdUnparse($source);\n"; gen $indent."$dest = soap_strdup(soap, s);\n"; } elsif ($tn eq 'usertag') { gen $indent."$dest = soap_malloc(soap, sizeof(*$dst->$soap_fn));\n"; @@ -164,7 +164,7 @@ int edg_wll_StatusToSoap(struct soap *soap,edg_wll_JobStat const *src,struct lbt my $usuc = $_; $usuc = $1.uc($2).$3 while ($usuc =~ /([^_]*)_([a-z])(.*)/); if ($ft eq 'jobid') { - gen "\ts = edg_wlc_JobIdUnparse(src->$_);\n"; + gen "\ts = glite_lbu_JobIdUnparse(src->$_);\n"; gen "\tjs->$usuc = soap_strdup(soap,s); free(s);\n"; } elsif ($ft eq 'strlist') { @@ -251,7 +251,7 @@ void edg_wll_SoapToStatus(struct soap *soap,struct lbt__jobStatus const *src,edg $usuc = $1.uc($2).$3 while ($usuc =~ /([^_]*)_([a-z])(.*)/); if ($ft eq 'jobid') { - gen "\tif (src->$usuc) edg_wlc_JobIdParse(src->$usuc,&dest->$_);\n"; + gen "\tif (src->$usuc) glite_lbu_JobIdParse(src->$usuc,&dest->$_);\n"; } elsif ($ft eq 'strlist') { gen "\tfor (i=0; i__size$usuc; i++) soap_unlink(soap,src->$usuc\[i]);\n"; gen "\tsoap_unlink(soap,src->$usuc);\n"; @@ -423,7 +423,7 @@ int edg_wll_SoapToQueryVal( assert(in); assert(out); if ( in->c ) { if ( attr == EDG_WLL_QUERY_ATTR_JOBID || attr == EDG_WLL_QUERY_ATTR_PARENT ) { - if ( edg_wlc_JobIdParse(in->c, &(out->j)) ) return -1; + if ( glite_lbu_JobIdParse(in->c, &(out->j)) ) return -1; } else { if ( !(out->c = strdup(in->c)) ) return -1; } @@ -456,7 +456,7 @@ int edg_wll_QueryValToSoap( break; case EDG_WLL_QUERY_ATTR_JOBID: case EDG_WLL_QUERY_ATTR_PARENT: { - char *s = edg_wlc_JobIdUnparse(in->j); + char *s = glite_lbu_JobIdUnparse(in->j); out->c = soap_strdup(soap, s); free(s); if ( !out->c ) return SOAP_FAULT; @@ -695,7 +695,7 @@ ret: int edg_wll_JobsQueryResToSoap( struct soap *soap, - const edg_wlc_JobId *jobs, + const glite_lbu_JobId *jobs, const edg_wll_JobStat *states, struct _lbe__QueryJobsResponse *out) { @@ -715,7 +715,7 @@ int edg_wll_JobsQueryResToSoap( out->__sizejobs = i; for ( i = 0; jobs[i]; i++ ) { char *s; - if ( !(s = edg_wlc_JobIdUnparse(jobs[i])) ) return SOAP_FAULT; + if ( !(s = glite_lbu_JobIdUnparse(jobs[i])) ) return SOAP_FAULT; if ( !(out->jobs[i] = soap_strdup(soap, s)) ) return SOAP_FAULT; free(s); } @@ -1069,7 +1069,7 @@ static int edg_wll_SoapToEvent( if ($ft eq 'jobid') { gen "\t\t\tif (in->$name->$usuc)\n"; - gen "\t\t\t\tedg_wlc_JobIdParse(in->$name->$usuc,&out->$act.$fn);\n"; + gen "\t\t\t\tglite_lbu_JobIdParse(in->$name->$usuc,&out->$act.$fn);\n"; } elsif ($ft eq 'timeval') { gen "\t\t\tout->$act.$fn.tv_sec = in->$name->$usuc->tvSec;\n"; gen "\t\t\tout->$act.$fn.tv_usec = in->$name->$usuc->tvUsec;\n"; diff --git a/org.glite.lb.server/src/ws_typeref.h b/org.glite.lb.server/src/ws_typeref.h index e458ab9..084fb8a 100644 --- a/org.glite.lb.server/src/ws_typeref.h +++ b/org.glite.lb.server/src/ws_typeref.h @@ -59,7 +59,7 @@ extern int edg_wll_QueryCondsExtToSoap(struct soap *, struct lbt__queryConditions ***); extern int edg_wll_JobsQueryResToSoap(struct soap *, - edg_wlc_JobId *, + glite_lbu_JobId *, edg_wll_JobStat *, struct _lbe__QueryJobsResponse *); diff --git a/org.glite.lb.server/test/test_query_events.cpp b/org.glite.lb.server/test/test_query_events.cpp index 1bc7c74..ac33a72 100644 --- a/org.glite.lb.server/test/test_query_events.cpp +++ b/org.glite.lb.server/test/test_query_events.cpp @@ -8,7 +8,6 @@ #include #include -#include "lbs_db.h" #include "get_events.h" using namespace std; @@ -30,11 +29,15 @@ private: public: void oneJob(); - int ExecStmt(const char *, edg_wll_Stmt *); + int ExecStmt(const char *, glite_lbu_Statement *); void setUp() { edg_wll_InitContext(&ctx); - ctx->mysql = (void *) this; /* XXX */ + ctx->dbctx = (glite_lbu_DBContext) this; /* XXX */ + } + + void tearDown() { + edg_wll_FreeContext(ctx); } }; @@ -44,10 +47,11 @@ void QueryEventsTest::oneJob() edg_wll_QueryRec job[2]; const edg_wll_QueryRec *jobs[2] = { job,NULL} ; edg_wll_Event *events; + int i; job[0].attr = EDG_WLL_QUERY_ATTR_JOBID; job[0].op = EDG_WLL_QUERY_OP_EQUAL ; - edg_wlc_JobIdParse("https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw", + glite_lbu_JobIdParse("https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw", &job[0].value.j); job[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; @@ -76,9 +80,13 @@ void QueryEventsTest::oneJob() qry_file.close(); CPPUNIT_ASSERT(!edg_wll_QueryEventsServer(ctx,1,jobs,NULL,&events)); + + glite_lbu_JobIdFree(job[0].value.j); + for (i = 0; events[i].type; i++) edg_wll_FreeEvent(&events[i]); + free(events); } -int QueryEventsTest::ExecStmt(const char *qry, edg_wll_Stmt *stmt_out) +int QueryEventsTest::ExecStmt(const char *qry, glite_lbu_Statement *stmt_out) { vector > >::iterator stmt = queries.begin(); @@ -95,21 +103,21 @@ int QueryEventsTest::ExecStmt(const char *qry, edg_wll_Stmt *stmt_out) } vector::iterator *rows = new vector::iterator(stmt->second.begin()); - *stmt_out = (edg_wll_Stmt) rows; + *stmt_out = (glite_lbu_Statement) rows; return stmt->second.size()-1; } extern "C" { -int edg_wll_ExecStmt(edg_wll_Context ctx,char *qry,edg_wll_Stmt *stmt) +int glite_lbu_ExecSQL(glite_lbu_DBContext ctx,const char *qry,glite_lbu_Statement *stmt) { - cout << "edg_wll_ExecStmt: " << qry << endl; + cout << "glite_lbu_ExecSQL: " << qry << endl; - class QueryEventsTest *tst = (class QueryEventsTest *)(ctx->mysql); + class QueryEventsTest *tst = (class QueryEventsTest *)ctx; return tst->ExecStmt(qry, stmt); } -int edg_wll_FetchRow(edg_wll_Stmt stmt, char **cols) +int glite_lbu_FetchRow(glite_lbu_Statement stmt, unsigned int n, unsigned long int *lengths, char **cols) { vector::iterator *rows = (vector::iterator *) stmt; char *row,*p,i=0; @@ -119,28 +127,34 @@ int edg_wll_FetchRow(edg_wll_Stmt stmt, char **cols) (*rows)++; for (p = strtok(row,"\t"); p; p = strtok(NULL,"\t")) cols[i++] = strdup(p); + free(row); return i; } -void edg_wll_FreeStmt(edg_wll_Stmt *) {} +void glite_lbu_FreeStmt(glite_lbu_Statement *stmt) { + vector::iterator *rows = (vector::iterator *) *stmt; + + delete rows; + *stmt = NULL; +} int debug; -int edg_wll_QueryColumns(edg_wll_Stmt stmt, char**cols) { return 0; } -char *edg_wll_TimeToDB(long t) { return NULL; } +int glite_lbu_QueryColumns(glite_lbu_Statement stmt, char**cols) { return 0; } +void glite_lbu_TimeToDB(long t, char **s) { *s = NULL; } +time_t glite_lbu_DBToTime(const char *c) { return (time_t)-1; } +int glite_lbu_DBConnect(glite_lbu_DBContext *ctx, const char*str) { return 0; } -time_t edg_wll_DBToTime(char *c) { return (time_t)-1; } -edg_wll_ErrorCode edg_wll_DBConnect(edg_wll_Context ctx, const char*str) { - return (edg_wll_ErrorCode)0; -} +int glite_lbu_Transaction(glite_lbu_DBContext ctx) { return 0; } +int glite_lbu_Commit(glite_lbu_DBContext ctx) { return 0; } +int glite_lbu_Rollback(glite_lbu_DBContext ctx) { return 0; } -int edg_wll_Transaction(edg_wll_Context ctx) { return 0; } -int edg_wll_Commit(edg_wll_Context ctx) { return 0; } -int edg_wll_Rollback(edg_wll_Context ctx) { return 0; } +int glite_lbu_bufferedInsert(glite_lbu_bufInsert bi, const char *row) { return 0; } + +int glite_lbu_QueryIndices(glite_lbu_DBContext ctx, const char *table, char ***key_names, char ****column_names) { return 0; } +int glite_lbu_DBError(glite_lbu_DBContext ctx, char **s1, char **s2) { return 0; } -edg_wll_ErrorCode edg_wll_bufferedInsert(edg_wll_bufInsert *bi, char *row) { return (edg_wll_ErrorCode) 0; }; - } CPPUNIT_TEST_SUITE_REGISTRATION(QueryEventsTest); diff --git a/org.glite.lb.server/test/test_xml.cpp.T b/org.glite.lb.server/test/test_xml.cpp.T index d52cd61..d1a3601 100644 --- a/org.glite.lb.server/test/test_xml.cpp.T +++ b/org.glite.lb.server/test/test_xml.cpp.T @@ -116,7 +116,7 @@ void XMLParseTest::protoEventTest() e1->any.host = strdup("some.host"); e1->any.level = 7; e1->any.priority = 0; - edg_wlc_JobIdParse("https://some.host:1234/x67qr549qc",&e1->any.jobId); + glite_lbu_JobIdParse("https://some.host:1234/x67qr549qc",&e1->any.jobId); e1->any.seqcode = EDG_WLL_SEQ_BIGHELPER_INITIAL; e1->any.user = strdup("/O=Grid/CN=This User"); e1->any.source = EDG_WLL_SOURCE_USER_INTERFACE; @@ -151,7 +151,7 @@ void XMLParseTest::protoStatusTest() edg_wll_InitStatus(&s1); s1.state = EDG_WLL_JOB_SUBMITTED; - edg_wlc_JobIdParse("https://some.host:1234/x67qr549qc",&s1.jobId); + glite_lbu_JobIdParse("https://some.host:1234/x67qr549qc",&s1.jobId); s1.owner = strdup("/O=Grid/CN=This User"); s1.jobtype = EDG_WLL_STAT_SIMPLE; s1.seed = strdup("4321");