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
endif
AT3=perl -I${top_srcdir}/project ${top_srcdir}/project/at3
-SUFFIXES = .T
+SUFFIXES = .T .xsd
DEBUG:=-g -O0 -Wall
-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
${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}
BKSERVER_LIBS= \
${SRVBONES_LIB} \
${LB_COMMON_LIB} \
+ ${LB_UTILS_DB_LIB} \
${GSOAP_LIB} \
${EXT_LIBS}
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} \
# ${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
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
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} \
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
${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}
${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
%.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:
**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;
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;
}
}
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);
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);
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);
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:a="http://egee.cesnet.cz/en/Schema/LB/Attributes"
- targetNamespace="http://egee.cesnet.cz/en/Schema/LB/Attributes"
+ xmlns:a="http://egee.cesnet.cz/en/Schema/LB/Attributes-Statistics"
+ targetNamespace="http://egee.cesnet.cz/en/Schema/LB/Attributes-Statistics"
version="1.0"
elementFormDefault="unqualified"
attributeFormDefault="unqualified"
>
+
+<!-- XXX: from HEAD
+
<xs:simpleType name="statusType">
<xs:restriction base="xs:string">
<xs:enumeration value="SUBMITTED" />
</xs:sequence>
</xs:complexType>
+-->
+ <xs:include location="job-attrs-common.xsd"/>
<xs:element name="jobId" type="xs:string" />
-
<xs:element name="user" type="xs:string">
<xs:annotation> <xs:documentation>Job owner according to LB</xs:documentation> </xs:annotation>
</xs:element>
<xs:element name="finalStatus" type="a:statusType" />
<xs:element name="finalStatusDate" type="xs:dateTime" />
<xs:element name="finalStatusReason" type="xs:string" />
- <xs:element name="LRMSDoneStatus" type="a:doneType" />
+ <xs:element name="LRMSDoneStatus" type="a:doneCodeType" />
<xs:element name="LRMSStatusReason" type="xs:string" />
<xs:element name="retryCount" type="xs:int" />
<xs:element name="additionalReason" type="xs:string" />
- <xs:element name="jobType" type="a:jobTypeType" />
+ <xs:element name="jobType" type="a:jobtypeType" />
<xs:element name="nsubjobs" type="xs:int" />
<xs:element name="subjobs" type="a:jobIdSequenceType" />
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jr="http://egee.cesnet.cz/en/Schema/LB/JobRecord"
- xmlns:a="http://egee.cesnet.cz/en/Schema/LB/Attributes"
+ xmlns:a="http://egee.cesnet.cz/en/Schema/LB/Attributes-Statistics"
targetNamespace="http://egee.cesnet.cz/en/Schema/LB/JobRecord"
version="1.0"
elementFormDefault="unqualified"
edg_wll_FreeAcl(edg_wll_Acl);
extern int
-edg_wll_UpdateACL(edg_wll_Context, edg_wlc_JobId, char *, int, int, int, int);
+edg_wll_UpdateACL(edg_wll_Context, glite_lbu_JobId, char *, int, int, int, int);
extern int
edg_wll_CheckACL(edg_wll_Context, edg_wll_Acl, int);
extern int
-edg_wll_GetACL(edg_wll_Context, edg_wlc_JobId, edg_wll_Acl *);
+edg_wll_GetACL(edg_wll_Context, glite_lbu_JobId, edg_wll_Acl *);
extern int
edg_wll_SetVomsGroups(edg_wll_Context, edg_wll_GssConnection *, char *, char *, char *, char *);
edg_wll_ErrorCode edg_wll_StepIntState(
edg_wll_Context, /* INOUT */
- edg_wlc_JobId, /* IN */
+ glite_lbu_JobId, /* IN */
edg_wll_Event *, /* IN */
int, /* IN */
edg_wll_JobStat *
#include <sysexits.h>
#include <assert.h>
-#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[] = {
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 *);
int i,j,k;
int nnew,nold,nadd,ndrop;
char *stmt;
+ int caps;
for (i=0; i<CI_MAX; i++) add_indices[i] = drop_indices[i] = -1;
memset(new_columns,0,sizeof new_columns);
}
edg_wll_InitContext(&ctx);
- if (edg_wll_Open(ctx,dbstring)) do_exit(ctx,EX_UNAVAILABLE);
- if (edg_wll_DBCheckVersion(ctx,dbstring)) do_exit(ctx,EX_SOFTWARE);
+ glite_lbu_InitDBContext(&ctx->dbctx);
+ 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) {
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");
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);
}
}
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" : "");
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);
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));
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;
}
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 <options> [file]\n"
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;
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);
}
-
#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"
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 <arpa/nameser.h> and it's includes
#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);
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,
,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 *);
#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;
};
struct timeval to;
int request_timeout = REQUEST_TIMEOUT;
int silent = 0;
+ glite_lbu_DBContext dbctx;
#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 ) {
}
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) )
{
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;
/* 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;
#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)) {
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){
#include "glite/lb/purge.h"
#include "purge.h"
#include "store.h"
-#include "lbs_db.h"
#include "lock.h"
#include "il_lbproxy.h"
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)) ) {
--- /dev/null
+#include <stdlib.h>
+
+#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;
+}
--- /dev/null
+#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
#include <assert.h>
#include <unistd.h>
-#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"
#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"
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;
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 "
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;
}
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);
clean:
edg_wll_FreeEvent(&e);
- edg_wll_FreeStmt(&q);
+ glite_lbu_FreeStmt(&q);
free(stmt);
free(from_s);
static int handle_specials(edg_wll_Context ctx,time_t *t)
{
- char *time_s;
+ char *time_s = NULL;
int ret;
edg_wll_ResetError(ctx);
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;
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;
#include <errno.h>
#include <syslog.h>
+#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" };
"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
*/
}
- 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);
#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" {
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 *);
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 *);
int
edg_wll_EventSendProxy(
edg_wll_Context ctx,
- const edg_wlc_JobId jobid,
+ const glite_lbu_JobId jobid,
const char *event)
{
long filepos;
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);
}
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
}
#include <string.h>
#include <errno.h>
+#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"
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;
}
#include <string.h>
#include <assert.h>
+#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;
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",
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<ret; i++)
- if (!strcasecmp(col_names[i],"Key_name")) Key_name = i;
- else if (!strcasecmp(col_names[i],"Seq_in_index")) Seq_in_index = i;
- else if (!strcasecmp(col_names[i],"Column_name")) Column_name = i;
- else if (!strcasecmp(col_names[i],"Sub_part")) Sub_part = i;
-
- assert(Key_name >= 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<ret; i++) free(showcol[i]);
- goto continue_fetch_index;
+ for (j = 0; column_names[i][j]; j++) {
+ if (cols[nkeys] <= j) {
+ cols[nkeys] = j+1;
+ idx[nkeys] = realloc(idx[nkeys],(j+2)*sizeof idx[nkeys][0]);
+ memset(&idx[nkeys][j+1],0,sizeof idx[nkeys][0]);
}
- }
-
- for (i=0; i<nkeys && strcasecmp(showcol[Key_name],keys[i]); i++);
-
- if (i == nkeys) {
- keys = realloc(keys,(i+2) * sizeof keys[0]);
- keys[i] = showcol[Key_name];
- keys[i+1] = NULL;
- cols = realloc(cols,(i+1) * sizeof cols[0]);
- cols[i] = 0;
- idx = realloc(idx,(i+2) * sizeof idx[0]);
- idx[i] = idx[i+1] = NULL;
- showcol[Key_name] = NULL;
- nkeys++;
- }
- j = atoi(showcol[Seq_in_index])-1;
- if (cols[i] <= j) {
- cols[i] = j+1;
- idx[i] = realloc(idx[i],(j+2)*sizeof idx[i][0]);
- memset(&idx[i][j+1],0,sizeof idx[i][0]);
- }
+ if (edg_wll_ColumnToQueryRec(column_names[i][j],&idx[nkeys][j])) {
+ int code;
+ char *ed;
- if (edg_wll_ColumnToQueryRec(showcol[Column_name],&idx[i][j])) {
- char ed[300];
- sprintf(ed,"%s(%s): unsupported column",keys[i],showcol[Column_name]);
- return edg_wll_SetError(ctx,EINVAL,ed);
+ asprintf(&ed, "%s(%s): unsupported column", keys[i], column_names[i][j]);
+ code = edg_wll_SetError(ctx, EINVAL, ed);
+ free(ed);
+ return code;
+ }
+#warning: TODO: needed Sub_part in value???
+// else idx[nkeys][j].value.i = atoi(showcol[Sub_part]);
}
- else idx[i][j].value.i = atoi(showcol[Sub_part]);
-
- for (i=0; i<ret; i++) free(showcol[i]);
-continue_fetch_index:
- // just for escaping from nested cycles
- ; /* prevent compiler to complain */
- }
- edg_wll_FreeStmt(&stmt);
+ nkeys++;
+next_index:
+ for (j = 0; column_names[i][j]; j++) free(column_names[i][j]);
+ free(column_names[i]);
+ column_names[i] = NULL;
+ ;
+ }
free(cols);
- free(col_names);
if (keys_out) *keys_out = keys; else free(keys);
*index_out = idx;
#include "glite/lb/context-int.h"
-#include "lbs_db.h"
#include "index.h"
#define yyerror(x) {}
--- /dev/null
+<?xml version="1.0"?>
+
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ version="1.0"
+ elementFormDefault="unqualified"
+ attributeFormDefault="unqualified"
+>
+
+@@@LANG: wsdl
+
+ <xs:simpleType name="statusType">
+ <xs:restriction base="xs:string">
+@@@{
+ for my $stat ($status->getTypesOrdered) {
+ my $u = uc $stat;
+ gen qq{\t\t\t<xs:enumeration value="$u" />\n};
+ }
+@@@}
+ </xs:restriction>
+ </xs:simpleType>
+
+@@@{
+ 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<xs:simpleType name="${n}Type">\n\t\t<xs:restriction base="xs:string">\n};
+
+ for (@{$f->{codes}}) {
+ my $uc = uc $_->{name};
+ gen qq{\t\t\t<xs:enumeration value="$uc"/>\n};
+ }
+
+ gen qq{\t\t</xs:restriction>\n\t</xs:simpleType>\n\n};
+ }
+ }
+@@@}
+
+ <xs:complexType name="historyStatusType">
+ <xs:complexContent>
+ <xs:restriction base="xs:anyType">
+ <xs:attribute name="status" type="statusType" use="required"/>
+ <xs:attribute name="timestamp" type="xs:dateTime" use="required"/>
+ <xs:attribute name="reason" type="xs:string" use="optional"/>
+ </xs:restriction>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="statusSequenceType">
+ <xs:sequence>
+ <xs:element name="status" type="historyStatusType" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="jobIdSequenceType">
+ <xs:sequence>
+ <xs:element name="jobId" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+
+</xs:schema>
--- /dev/null
+<?xml version="1.0"?>
+
+<!-- $Header$ -->
+
+@@@LANG: wsdl
+
+<xsd:schema
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:a="http://egee.cesnet.cz/en/Schema/LB/Attributes-Native"
+ version="1.0"
+ targetNamespace="http://egee.cesnet.cz/en/Schema/LB/Attributes-Native"
+ elementFormDefault="unqualified"
+ attributeFormDefault="unqualified"
+>
+
+ <xsd:include location="job-attrs-common.xsd"/>
+
+@@@{
+ 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<xsd:element name="$n" type="$t"/>\n};
+ }
+@@@}
+
+ <element name="UIHost" type="xsd:string" />
+
+ <element name="finalStatus" type="a:statusType" />
+ <element name="finalStatusDate" type="a:statusType" />
+ <element name="finalStatusReason" type="a:statusType" />
+
+ <element name="lastStatusHistory" type="a:statusSequenceType" />
+ <element name="finalStatusHistory" type="a:statusSequenceType" />
+
+</xsd:schema>
--- /dev/null
+#ident "$Header$"
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+#include <stdarg.h>
+#include <regex.h>
+#include <syslog.h>
+
+#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);
+}
+
#include <regex.h>
#include <syslog.h>
+#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"
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;
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) {
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)
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;
" 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) {
}
free(stat_str);
}
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
}
free(stmt);
} else goto dag_enomem;
#endif
free(string_jobid);
free(md5_jobid);
- return edg_wll_Error(ctx, NULL, NULL);
+ return edg_wll_SetErrorDB(ctx);
#if DAG_ENABLE
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;
}
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;
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);
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;
}
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;
"(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++;
}
}
- 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*");
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);
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);
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;
*/
#ifdef LB_BUF
- if (edg_wll_bufferedInsert(bi, values))
+ if (glite_lbu_bufferedInsert(bi, values))
goto cleanup;
#else
"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);
}
/*
*/
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 */
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);
}
*/
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)
#ifndef _LBS_JOBSTAT_H
#define _LBS_JOBSTAT_H
-
-#include "lbs_db.h"
+#include "glite/lb-utils/db.h"
/*
* Internal representation of job state
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 **);
#include <regex.h>
#include <syslog.h>
-#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"
}
-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;
}
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:
<xsl:template match="xs:schema">
#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"
<xsl:apply-templates select="xs:element"/>
#endif
</xsl:template>
<xsl:template match="xs:element">
/** <xsl:value-of select="xs:documentation/text()"/> */
-#define GLITE_JP_LB_<xsl:value-of select="@name"/> GLITE_JP_LB_NS ":<xsl:value-of select="@name"/>"
+#define GLITE_JP_LB_STAT_<xsl:value-of select="@name"/> GLITE_JP_LB_NS_STAT ":<xsl:value-of select="@name"/>"
</xsl:template>
</xsl:stylesheet>
#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);
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;
/*
"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;
"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
{
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)
{
edg_wll_ResetError(ctx);
- md5_jobid = edg_wlc_JobIdGetUnique(job);
+ md5_jobid = glite_lbu_JobIdGetUnique(job);
do {
if (acl)
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);
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);
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)
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()");
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') {
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;
}
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); */
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
}
/* 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;
pomB = strdup("");
while (jobsOut[i]) {
- char *chid = edg_wlc_JobIdUnparse(jobsOut[i]);
+ char *chid = glite_lbu_JobIdUnparse(jobsOut[i]);
asprintf(&pomA,"%s\t\t <li> <a href=\"%s\">%s</a>\r\n",
pomB, chid,chid);
pomB = strdup("");
- chid = edg_wlc_JobIdUnparse(stat.jobId);
+ chid = glite_lbu_JobIdUnparse(stat.jobId);
#define TR(name,type,field) \
if (field) { \
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
--- /dev/null
+#ident "$Header$"
+
+#include <stdlib.h>
+#include <assert.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <time.h>
+#include <ctype.h>
+
+#include <cclassad.h>
+
+#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; i<h->status.children_num; i++) {
+ trio_asprintf(&val,"%s\t\t<jobId>%s</jobId>\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<status name=\"%s\" %s%s/>\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<status name=\"%s\" %s%s/>\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<status name=\"%s\" %s%s/>\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; i<js->pub.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;
+}
+
}
}
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;
}
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) {
/* 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;
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;
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;
}
ret = HTTP_INTERNAL;
free(fullid);
- edg_wlc_JobIdFree(jobId);
+ glite_lbu_JobIdFree(jobId);
edg_wll_FreeStatus(&stat);
/* GET [something else]: not understood */
}
}
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;
}
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) {
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))
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;
#include <ctype.h>
#include <expat.h>
-#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"
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);
+*/
}
/* 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;
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;
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;
if (jobsIn) {
trio_asprintf(&pomA,"%s\t\t<jobId>%|Xs</jobId>\r\n",
- pomB, pomC=edg_wlc_JobIdUnparse(jobsIn[i]));
+ pomB, pomC=glite_lbu_JobIdUnparse(jobsIn[i]));
free(pomC);
free(pomB);
pomB = pomA;
}
/* 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;
while (jobsOut[i]) {
len = trio_asprintf(&pomA," <jobId>%|Xs</jobId>\r\n",
- pomB=edg_wlc_JobIdUnparse(jobsOut[i]));
+ pomB=glite_lbu_JobIdUnparse(jobsOut[i]));
free(pomB);
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";
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);
#include <ctype.h>
#include <expat.h>
-#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"
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;
if (jobsIn) {
trio_asprintf(&pomA,"%s\t\t<jobId>%|Xs</jobId>\r\n",
- pomB, pomC=edg_wlc_JobIdUnparse(jobsIn[i]));
+ pomB, pomC=glite_lbu_JobIdUnparse(jobsIn[i]));
free(pomC);
free(pomB);
pomB = pomA;
}
/* 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;
while (jobsOut[i]) {
len = trio_asprintf(&pomA," <jobId>%|Xs</jobId>\r\n",
- pomB=edg_wlc_JobIdUnparse(jobsOut[i]));
+ pomB=glite_lbu_JobIdUnparse(jobsOut[i]));
free(pomB);
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";
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);
#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"
#include <fcntl.h>
#include <ctype.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/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"
char *line = NULL,
buff[30];
edg_wll_Event *event;
- edg_wlc_JobId jobid = NULL;
+ glite_lbu_JobId jobid = NULL;
edg_wll_ResetError(ctx);
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;
/* 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 )
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);
}
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);
}
#include <sys/sem.h>
#include <errno.h>
-#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-_";
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;
#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);
#include <stdio.h>
#include <syslog.h>
+#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"
{
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);
"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]))
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]);
for (i=0; i<sizeof(jobc)/sizeof(jobc[0]); i++) free(jobc[i]);
}
- if (ret < 0) goto err;
+ if (ret < 0) {
+ edg_wll_SetErrorDB(ctx);
+ goto err;
+ }
err:
if ( nid ) edg_wll_NotifIdFree(nid);
free(jobq);
- edg_wll_FreeStmt(&jobs);
+ glite_lbu_FreeStmt(&jobs);
return edg_wll_Error(ctx,NULL,NULL);
}
{
edg_wll_Acl acl = calloc(1,sizeof *acl);
/* XXX: NO_GACL GACLacl *gacl; */
- void *gacl;
+ GRSTgaclAcl *gacl;
int ret;
edg_wll_ResetError(ctx);
#include <stdlib.h>
#include <stdio.h>
-#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"
*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;
"values ('%|Ss','%|Ss',%s,'%|Ss', '<and>%|Ss</and>')",
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++ )
{
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;
+ }
}
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;
/* 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++ )
{
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
*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;
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:
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;
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:
* >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;
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;
cleanup:
if ( q ) free(q);
- if ( stmt ) edg_wll_FreeStmt(&stmt);
+ if ( stmt ) glite_lbu_FreeStmt(&stmt);
return userid;
}
"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:
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;
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");
/*
else if ( ret > 0 )
edg_wll_SetError(ctx, EPERM, "Updating notification records");
*/
+ else if (ret < 0)
+ edg_wll_SetErrorDB(ctx);
}
if ( host ) {
}
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;
*/
int edg_wll_PurgeServerProxy(
edg_wll_Context ctx,
- edg_wlc_JobId job
+ glite_lbu_JobId job
);
#define FILE_TYPE_ANY ""
#include <time.h>
#include <assert.h>
-#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"
*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,
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 )
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]);
{
free(res[1]);
memset(out+i, 0, sizeof(*out));
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
goto cleanup;
}
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) {
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) )
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 )
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,
*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,
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 )
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]);
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;
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;
}
}
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:
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 )
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);
}
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);
}
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);
}
}
else
trio_asprintf(&conds, "e.time_stamp %s %s", opToString(ec[m][n].op), dbt);
+
+ free(dbt);
break;
case EDG_WLL_QUERY_ATTR_LEVEL:
*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);
}
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);
}
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);
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);
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;
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]);
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;
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);
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);
}
-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;
/* 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);
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"
#include <stdlib.h>
#include <string.h>
+#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))
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);
#include <errno.h>
+#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"
-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,
edg_wll_ResetError(ctx);
- jobid_md5 = edg_wlc_JobIdGetUnique(jobid);
+ jobid_md5 = glite_lbu_JobIdGetUnique(jobid);
trio_asprintf(&stmt,
"select int_status from states "
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 ) {
free(res);
free(jobid_md5);
free(stmt);
- edg_wll_FreeStmt(&sh);
+ glite_lbu_FreeStmt(&sh);
if ( istat ) {
destroy_intJobStat(istat);
free(istat);
#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)
"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);
"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);
}
--- /dev/null
+
+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;
#include <time.h>
#include <errno.h>
-#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"
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)
{
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:
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;
}
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;
}
}
}
- 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],
for (i=0; i<EDG_WLL_NUMBER_OF_STATCODES; i++)
timeout[i] = request->timeout[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;
}
edg_wll_JobStat stat;
if (check_strict_jobid(ctx,job)) {
- edg_wlc_JobIdFree(job);
+ glite_lbu_JobIdFree(job);
free(job_s);
parse = 1;
continue;
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))
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",
}
-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) {
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;
}
/* 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;
}
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;
}
"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]);
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;
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;
}
}
}
}
- 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);
#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 *);
#include <globus_config.h>
-#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;
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;
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;
}
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)
/* 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;
* 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 */
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 */
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 &&
free(stmt);
free(ssrc);
free(select_max);
- if (sh) edg_wll_FreeStmt(&sh);
if (!err && seq) *seq = next;
return err;
}
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);
}
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
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);
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
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
{
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);
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; i<sizeof(f)/sizeof(f[0]); i++) free(f[i].val);
trio_asprintf(&stmt,"insert into short_fields(jobid,event,name,value) "
"values ('%|Ss',%d,'SRC_INSTANCE','%|Ss')",
jobid,no,e->any.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);
}
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);
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 )
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 */
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);
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("");
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);
}
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);
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);
free(subjobs);
return edg_wll_Error(ctx,NULL,NULL);
}
+#endif
/*
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)
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;
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);
/* 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
/* 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);
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
#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);
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);
}
#include <stdlib.h>
#include <errno.h>
-#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;
}
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<njobs; i++)
- edg_wlc_JobIdFree(out[i]);
+ glite_lbu_JobIdFree(out[i]);
free(out);
}
} else *jobs = out;
#include <cclassad.h>
-#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"
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;
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);
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;
}
edg_wll_Context ctx;
edg_wll_QueryRec **conditions;
int flags;
- edg_wlc_JobId *jobs;
+ glite_lbu_JobId *jobs;
edg_wll_JobStat *states;
int ret;
}
-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);
}
}
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";
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') {
$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<src->__size$usuc; i++) soap_unlink(soap,src->$usuc\[i]);\n";
gen "\tsoap_unlink(soap,src->$usuc);\n";
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;
}
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;
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)
{
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);
}
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";
struct lbt__queryConditions ***);
extern int edg_wll_JobsQueryResToSoap(struct soap *,
- edg_wlc_JobId *,
+ glite_lbu_JobId *,
edg_wll_JobStat *,
struct _lbe__QueryJobsResponse *);
#include <glite/lb/consumer.h>
#include <glite/lb/context-int.h>
-#include "lbs_db.h"
#include "get_events.h"
using namespace std;
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);
}
};
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;
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<pair<string,vector<string> > >::iterator stmt = queries.begin();
}
vector<string>::iterator *rows = new vector<string>::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<string>::iterator *rows = (vector<string>::iterator *) stmt;
char *row,*p,i=0;
(*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<string>::iterator *rows = (vector<string>::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);
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;
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");