Get rid of the dependency in lb plugin on db module.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 13 Dec 2007 11:29:42 +0000 (11:29 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 13 Dec 2007 11:29:42 +0000 (11:29 +0000)
org.glite.lb.server/Makefile
org.glite.lb.server/interface/index.h
org.glite.lb.server/src/bkindex.c
org.glite.lb.server/src/index.c.T
org.glite.lb.server/src/jobstat.c
org.glite.lb.server/src/jobstat.h
org.glite.lb.server/src/jobstat_supp.c
org.glite.lb.server/src/store.c.T

index 0ee4f9b..270540e 100644 (file)
@@ -162,7 +162,7 @@ EXT_LIBS:=  \
 
 COMMON_LIBS:= -L${stagedir}/lib  -lglite_lb_common_${nothrflavour} -lglite_security_gss_${nothrflavour} -lglite_lbu_trio
 PLUGIN_LIBS:= -L${stagedir}/lib -lglite_lb_common_${nothrflavour} -lglite_lbu_trio \
-       ${classadslib} -lstdc++ ${expatlib} -lexpat -lglite_lbu_db\
+       ${classadslib} -lstdc++ ${expatlib} -lexpat
 
 PLUGIN_LOBJS:= lb_plugin.lo jobstat_supp.lo process_event.lo process_event_pbs.lo process_event_condor.lo
 
index 761465c..15f4f34 100644 (file)
@@ -25,6 +25,7 @@ typedef struct _edg_wll_IColumnRec {
 } edg_wll_IColumnRec;
 
 void edg_wll_FreeIColumnRec(edg_wll_IColumnRec *);
+edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context, void *,  edg_wll_JobStat*, int , char **, char **);
 
 int yylex();
 
index 772c289..23d3463 100644 (file)
@@ -46,6 +46,7 @@ static void usage(const char *);
 static void do_exit(edg_wll_Context,int);
 static char *col_list(const edg_wll_QueryRec *);
 static char *db_col_type(const edg_wll_QueryRec *);
+static edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context, void *);
 
 /* XXX: don't bother with malloc() of arrays that are tiny in real life */
 #define CI_MAX 200
@@ -339,7 +340,7 @@ static void usage(const char *me)
  * Set values of index columns in state table (after index reconfiguration)
  */
 
-edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context ctx, void *job_index_cols) {
+static edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context ctx, void *job_index_cols) {
 
        glite_lbu_Statement sh;
        int njobs, ret = -1;
@@ -380,7 +381,7 @@ edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context ctx, void *job_index_c
                                "cannot decode int_status from states DB table");
                }
 
-               edg_wll_IColumnsSQLPart(ctx, job_index_cols, stat, 0, NULL, &icvalues);
+               edg_wll_IColumnsSQLPart(ctx, job_index_cols, &stat->pub, 0, NULL, &icvalues);
                trio_asprintf(&stmt, "update states set seq=%s%s where jobid='%|Ss'", res[2], icvalues, res[0]);
                ret = edg_wll_ExecSQL(ctx, stmt, NULL);
 
index 61c1043..e918aca 100644 (file)
@@ -279,3 +279,118 @@ void edg_wll_FreeIColumnRec(edg_wll_IColumnRec *icrp)
        free(icrp->colname);
 }
 
+
+/*
+ * Compute part of SQL command used for indexed state table columns
+ */
+
+edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context ctx,
+                                       void *job_index_cols_v,
+                                       edg_wll_JobStat *stat,
+                                       int is_insert,
+                                       char **names_out,
+                                       char **values_out)
+{
+       int i;
+       char *names, *values;
+       char *data;
+       char *tmp;
+       char *tmpval;
+       edg_wll_IColumnRec *job_index_cols = (edg_wll_IColumnRec *)job_index_cols_v;
+
+       edg_wll_ResetError(ctx);
+
+       if (is_insert) names = strdup(""); else names = NULL;
+       values = strdup("");
+
+       if (job_index_cols != NULL)
+       for (i=0; job_index_cols[i].colname; i++) {
+               data = NULL;
+               switch (job_index_cols[i].qrec.attr) {
+                       case EDG_WLL_QUERY_ATTR_OWNER:
+                               if (stat->owner) {
+                                       tmpval = edg_wll_gss_normalize_subj(stat->owner, 0);
+                                       trio_asprintf(&data, "'%|Ss'", tmpval);
+                                       free(tmpval);
+                               } else data = strdup("''");
+                               break;
+                       case EDG_WLL_QUERY_ATTR_LOCATION:
+                               if (stat->location)
+                                       trio_asprintf(&data, "'%|Ss'", stat->location);
+                               else data = strdup("''");
+                               break;
+                       case EDG_WLL_QUERY_ATTR_DESTINATION:
+                               if (stat->destination)
+                                       trio_asprintf(&data, "'%|Ss'", stat->destination);
+                               else data = strdup("''");
+                               break;
+                       case EDG_WLL_QUERY_ATTR_DONECODE:
+                               asprintf(&data, "%d", stat->done_code);
+                               break;
+                       case EDG_WLL_QUERY_ATTR_USERTAG:
+                               if (stat->user_tags) {
+                                       int k;
+                                       for (k=0; stat->user_tags[k].tag &&
+                                                       strcmp(stat->user_tags[k].tag,job_index_cols[i].qrec.attr_id.tag);
+                                               k++);
+                                       if (stat->user_tags[k].tag != NULL) {
+                                               trio_asprintf(&data, "'%|Ss'", stat->user_tags[k].value);
+                                       } else data = strdup("''");
+                               } else data = strdup("''");
+                               break;
+                       case EDG_WLL_QUERY_ATTR_TIME:
+                               if (stat->stateEnterTimes)
+                                       glite_lbu_TimeToDB(stat->stateEnterTimes[job_index_cols[i].qrec.attr_id.state+1], &data);
+                               else data = strdup("0");
+                               break;
+                       case EDG_WLL_QUERY_ATTR_RESUBMITTED:
+                               asprintf(&data, "%d", stat->resubmitted);
+                               break;
+                       case EDG_WLL_QUERY_ATTR_STATEENTERTIME:
+                               glite_lbu_TimeToDB(stat->stateEnterTime.tv_sec, &data);
+                               break;
+                       case EDG_WLL_QUERY_ATTR_LASTUPDATETIME:
+                               glite_lbu_TimeToDB(stat->lastUpdateTime.tv_sec, &data);
+                               break;
+                       case EDG_WLL_QUERY_ATTR_JDL_ATTR: // XXX: It's not clear how this is supposed to work
+                               if (stat->jdl)
+                                       trio_asprintf(&data, "'%|Ss'", stat->destination);
+                               else data = strdup("''");
+                               break;
+/*                     case EDG_WLL_QUERY_ATTR_STATEENTERTIME: /// XXX: Which way of handling this is correct?
+                               if (stat->stateEnterTime)
+                                       glite_lbu_TimeToDB(stat->stateEnterTime, &data);
+                               else data = strdup("0");
+                               break;
+                       case EDG_WLL_QUERY_ATTR_LASTUPDATETIME:
+                               if (stat->lastUpdateTime)
+                                       glite_lbu_TimeToDB(stat->lastUpdateTime, &data);
+                               else data = strdup("0");
+                               break;*/
+
+                               /* XXX add more attributes when defined */
+                       default:
+                               /* do not use */
+                               break;
+               }
+
+               if (!data) continue;
+
+               if (is_insert) {
+                       asprintf(&tmp, "%s,`%s`", names, job_index_cols[i].colname);
+                       free(names); names = tmp;
+                       asprintf(&tmp, "%s,%s", values, data);
+                       free(values); values = tmp;
+               } else {
+                       /* update */
+                       asprintf(&tmp, "%s,`%s`=%s", values, job_index_cols[i].colname, data);
+                       free(values); values = tmp;
+               }
+               free(data);
+       }
+
+       if (is_insert) *names_out = names;
+       *values_out = values;
+
+       return edg_wll_Error(ctx, NULL, NULL);
+}
index b8b58d4..e274e96 100644 (file)
@@ -568,7 +568,7 @@ edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx,
        if (parent_md5 == NULL) parent_md5 = strdup("*no parent job*");
 
 
-       edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, stat, 0, NULL, &icvalues);
+       edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, &stat->pub, 0, NULL, &icvalues);
 
        trio_asprintf(&stmt,
                "update states set "
@@ -583,7 +583,7 @@ edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx,
        if ((dbret = edg_wll_ExecSQL(ctx,stmt,NULL)) < 0) goto cleanup;
 
        if (dbret == 0) {
-               edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, stat, 1, &icnames, &icvalues);
+               edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, &stat->pub, 1, &icnames, &icvalues);
                trio_asprintf(&stmt,
                        "insert into states"
                        "(jobid,status,seq,int_status,version"
index faca87c..f32f0f1 100644 (file)
@@ -97,8 +97,6 @@ void destroy_intJobStat(intJobStat *);
 void destroy_intJobStat_extension(intJobStat *p);
 
 
-edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context, void *, intJobStat *, int , char **, char **);
-edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context, void *);
 int edg_wll_intJobStatus( edg_wll_Context, const edg_wlc_JobId, int, intJobStat *, int);
 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, glite_lbu_bufInsert *bi);
index 78a6c29..0ad1adb 100644 (file)
@@ -674,121 +674,6 @@ intJobStat* dec_intJobStat(char *in, char **rest)
        return stat;
 }
 
-/*
- * Compute part of SQL command used for indexed state table columns
- */
-
-edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context ctx,
-                                       void *job_index_cols_v,
-                                       intJobStat *stat,
-                                       int is_insert,
-                                       char **names_out,
-                                       char **values_out)
-{
-       int i;
-       char *names, *values;
-       char *data;
-       char *tmp;
-       char *tmpval;
-       edg_wll_IColumnRec *job_index_cols = (edg_wll_IColumnRec *)job_index_cols_v;
-
-       edg_wll_ResetError(ctx);
-
-       if (is_insert) names = strdup(""); else names = NULL;
-       values = strdup("");
-
-       if (job_index_cols != NULL)
-       for (i=0; job_index_cols[i].colname; i++) {
-               data = NULL;
-               switch (job_index_cols[i].qrec.attr) {
-                       case EDG_WLL_QUERY_ATTR_OWNER:
-                               if (stat->pub.owner) {
-                                       tmpval = edg_wll_gss_normalize_subj(stat->pub.owner, 0);
-                                       trio_asprintf(&data, "'%|Ss'", tmpval);
-                                       free(tmpval);
-                               } else data = strdup("''");
-                               break;
-                       case EDG_WLL_QUERY_ATTR_LOCATION:
-                               if (stat->pub.location)
-                                       trio_asprintf(&data, "'%|Ss'", stat->pub.location);
-                               else data = strdup("''");
-                               break;
-                       case EDG_WLL_QUERY_ATTR_DESTINATION:
-                               if (stat->pub.destination)
-                                       trio_asprintf(&data, "'%|Ss'", stat->pub.destination);
-                               else data = strdup("''");
-                               break;
-                       case EDG_WLL_QUERY_ATTR_DONECODE:
-                               asprintf(&data, "%d", stat->pub.done_code);
-                               break;
-                       case EDG_WLL_QUERY_ATTR_USERTAG:
-                               if (stat->pub.user_tags) {
-                                       int k;
-                                       for (k=0; stat->pub.user_tags[k].tag &&
-                                                       strcmp(stat->pub.user_tags[k].tag,job_index_cols[i].qrec.attr_id.tag);
-                                               k++);
-                                       if (stat->pub.user_tags[k].tag != NULL) {
-                                               trio_asprintf(&data, "'%|Ss'", stat->pub.user_tags[k].value);
-                                       } else data = strdup("''");
-                               } else data = strdup("''");
-                               break;
-                       case EDG_WLL_QUERY_ATTR_TIME:
-                               if (stat->pub.stateEnterTimes)
-                                       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:
-                               asprintf(&data, "%d", stat->pub.resubmitted);
-                               break;
-                       case EDG_WLL_QUERY_ATTR_STATEENTERTIME:
-                               glite_lbu_TimeToDB(stat->pub.stateEnterTime.tv_sec, &data);
-                               break;
-                       case EDG_WLL_QUERY_ATTR_LASTUPDATETIME:
-                               glite_lbu_TimeToDB(stat->pub.lastUpdateTime.tv_sec, &data);
-                               break;
-                       case EDG_WLL_QUERY_ATTR_JDL_ATTR: // XXX: It's not clear how this is supposed to work
-                               if (stat->pub.jdl)
-                                       trio_asprintf(&data, "'%|Ss'", stat->pub.destination);
-                               else data = strdup("''");
-                               break;
-/*                     case EDG_WLL_QUERY_ATTR_STATEENTERTIME: /// XXX: Which way of handling this is correct?
-                               if (stat->pub.stateEnterTime)
-                                       glite_lbu_TimeToDB(stat->pub.stateEnterTime, &data);
-                               else data = strdup("0");
-                               break;
-                       case EDG_WLL_QUERY_ATTR_LASTUPDATETIME:
-                               if (stat->pub.lastUpdateTime)
-                                       glite_lbu_TimeToDB(stat->pub.lastUpdateTime, &data);
-                               else data = strdup("0");
-                               break;*/
-
-                               /* XXX add more attributes when defined */
-                       default:
-                               /* do not use */
-                               break;
-               }
-
-               if (!data) continue;
-
-               if (is_insert) {
-                       asprintf(&tmp, "%s,`%s`", names, job_index_cols[i].colname);
-                       free(names); names = tmp;
-                       asprintf(&tmp, "%s,%s", values, data);
-                       free(values); values = tmp;
-               } else {
-                       /* update */
-                       asprintf(&tmp, "%s,`%s`=%s", values, job_index_cols[i].colname, data);
-                       free(values); values = tmp;
-               }
-               free(data);
-       }
-
-       if (is_insert) *names_out = names;
-       *values_out = values;
-
-       return edg_wll_Error(ctx, NULL, NULL);
-}
-
 
 int component_seqcode(const char *a, edg_wll_Source index)
 {
index c5b2913..c409918 100644 (file)
@@ -843,7 +843,7 @@ static edg_wll_ErrorCode states_values_embryonic(
        if (jobid_md5 == NULL || parent_md5 == NULL || stat_enc == NULL) goto err;
 
 
-       if (edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, stat, 1, icnames, &icvalues)) goto err;
+       if (edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, stat->pub, 1, icnames, &icvalues)) goto err;
        trio_asprintf(&stmt,
                "'%|Ss',%d,%d,'%|Ss','%|Ss','%|Ss'%s",
                jobid_md5, stat->pub.state, 1, stat_enc,