Switch L&B server to new API. (lazy approach with generic time convert functions)
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 29 Oct 2009 16:22:30 +0000 (16:22 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 29 Oct 2009 16:22:30 +0000 (16:22 +0000)
org.glite.lb.server/src/dump.c
org.glite.lb.server/src/index.c.T
org.glite.lb.server/src/notif_match.c
org.glite.lb.server/src/notification.c
org.glite.lb.server/src/openserver.c
org.glite.lb.server/src/query.c
org.glite.lb.server/src/store.c.T
org.glite.lbjp-common.db/interface/db-int.h
org.glite.lbjp-common.db/interface/db.h
org.glite.lbjp-common.db/src/db.c

index e4889a8..91dc0f5 100644 (file)
@@ -55,8 +55,8 @@ int edg_wll_DumpEventsServer(edg_wll_Context ctx,const edg_wll_DumpRequest *req,
                return edg_wll_Error(ctx,NULL,NULL);
        }
 
-       glite_lbu_TimeToDB(from, &from_s);
-       glite_lbu_TimeToDB(to, &to_s);
+       glite_lbu_TimeToStr(from, &from_s);
+       glite_lbu_TimeToStr(to, &to_s);
 
        trio_asprintf(&stmt,
                        "select event,dg_jobid,code,prog,host,u.cert_subj,time_stamp,usec,level,arrived "
@@ -175,7 +175,7 @@ static int handle_specials(edg_wll_Context ctx,time_t *t)
                                case ENOENT: *t = 0; 
                                             edg_wll_ResetError(ctx);
                                             break;
-                               case 0: *t = glite_lbu_DBToTime(time_s); 
+                               case 0: *t = glite_lbu_StrToTime(time_s); 
                                        assert(*t >= 0);
                                        break;
                                default: break;
@@ -190,7 +190,7 @@ static int handle_specials(edg_wll_Context ctx,time_t *t)
 static char *time_to_string(time_t t, char **ptr) {
        char *s;
 
-       glite_lbu_TimeToDB(t, &s);
+       glite_lbu_TimeToStr(t, &s);
        s[strlen(s) - 1] = '\0';
        *ptr = s;
 
index de8a715..3e471b5 100644 (file)
@@ -170,7 +170,7 @@ static char *to_sql_string(edg_wll_JobStat const *stat,int offset)
 static char *to_sql_timeval(edg_wll_JobStat const *stat,int offset)
 {
        char    *out;
-       glite_lbu_TimeToDB( ((struct timeval *) (((char *) stat) + offset))->tv_sec, &out );
+       glite_lbu_TimeToStr( ((struct timeval *) (((char *) stat) + offset))->tv_sec, &out );
        return out;
 }
 
@@ -378,17 +378,17 @@ edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context ctx,
                                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);
+                                       glite_lbu_TimeToStr(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);
+                               glite_lbu_TimeToStr(stat->stateEnterTime.tv_sec, &data);
                                break;
                        case EDG_WLL_QUERY_ATTR_LASTUPDATETIME:
-                               glite_lbu_TimeToDB(stat->lastUpdateTime.tv_sec, &data);
+                               glite_lbu_TimeToStr(stat->lastUpdateTime.tv_sec, &data);
                                break;
                        case EDG_WLL_QUERY_ATTR_JDL_ATTR: // This is not the correct way to handle jdl searches.
                                 /* There's no way to index individual JDL attributes */
@@ -398,12 +398,12 @@ edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context ctx,
                                break;
 /*                     case EDG_WLL_QUERY_ATTR_STATEENTERTIME: /// XXX: Which way of handling this is correct?
                                if (stat->stateEnterTime)
-                                       glite_lbu_TimeToDB(stat->stateEnterTime, &data);
+                                       glite_lbu_TimeToStr(stat->stateEnterTime, &data);
                                else data = strdup("0");
                                break;
                        case EDG_WLL_QUERY_ATTR_LASTUPDATETIME:
                                if (stat->lastUpdateTime)
-                                       glite_lbu_TimeToDB(stat->lastUpdateTime, &data);
+                                       glite_lbu_TimeToStr(stat->lastUpdateTime, &data);
                                else data = strdup("0");
                                break;*/
 
index 91986d1..5810271 100644 (file)
@@ -94,7 +94,7 @@ int edg_wll_NotifMatch(edg_wll_Context ctx, const edg_wll_JobStat *oldstat, cons
        if (edg_wll_ExecSQL(ctx,jobq,&jobs) < 0) goto err;
 
        while ((ret = edg_wll_FetchRow(ctx,jobs,sizeof(jobc)/sizeof(jobc[0]),NULL,jobc)) > 0) {
-               if (now > (expires = glite_lbu_DBToTime(jobc[2]))) {
+               if (now > (expires = glite_lbu_StrToTime(jobc[2]))) {
                        edg_wll_NotifExpired(ctx,jobc[0]);
                        glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_DEBUG, "[%d] NOTIFY:%s expired at %s UTC", 
                                getpid(),jobc[0],asctime(gmtime(&expires)));
index f6fc2e9..971df95 100644 (file)
@@ -89,7 +89,7 @@ int edg_wll_NotifNewServer(
                *valid = time(NULL) + ctx->notifDuration;       
        adjust_validity(ctx,valid);
 
-       glite_lbu_TimeToDB(*valid, &time_s);
+       glite_lbu_TimeToStr(*valid, &time_s);
        if ( !time_s )
        {
                edg_wll_SetError(ctx, errno, NULL);
@@ -211,7 +211,7 @@ int edg_wll_NotifBindServer(
                        *valid = time(NULL) + ctx->notifDuration;       
                adjust_validity(ctx,valid);
 
-               glite_lbu_TimeToDB(*valid, &time_s);
+               glite_lbu_TimeToStr(*valid, &time_s);
                if ( !time_s )
                {
                        edg_wll_SetError(ctx, errno, "Formating validity time");
@@ -390,7 +390,7 @@ int edg_wll_NotifRefreshServer(
                        *valid = time(NULL) + ctx->notifDuration;       
                adjust_validity(ctx,valid);
 
-               glite_lbu_TimeToDB(*valid, &time_s);
+               glite_lbu_TimeToStr(*valid, &time_s);
                if ( !time_s )
                {
                        edg_wll_SetError(ctx, errno, "Formating validity time");
@@ -703,7 +703,7 @@ static int update_notif(
                int     expires;
                
                *v2 = 0;
-               expires = glite_lbu_DBToTime(v+1);
+               expires = glite_lbu_StrToTime(v+1);
 /*
                printf("edg_wll_NotifChangeIL(ctx, %s, %s, %d)\n",
                                nid_s? nid_s: "nid", host, port);
@@ -840,7 +840,7 @@ static int check_notif_age(edg_wll_Context ctx, const edg_wll_NotifId nid) {
        if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) )
                goto cleanup;
 
-       glite_lbu_TimeToDB(now, &time_s);
+       glite_lbu_TimeToStr(now, &time_s);
        if ( !time_s )
        {
                edg_wll_SetError(ctx, errno, NULL);
index 40e2e08..e352dde 100644 (file)
@@ -15,7 +15,7 @@ edg_wll_ErrorCode edg_wll_Open(edg_wll_Context ctx, char *cs)
        char *cols[20];
        glite_lbu_Statement stmt;
 
-       if (glite_lbu_InitDBContext((glite_lbu_DBContext*) &ctx->dbctx) != 0) {
+       if (glite_lbu_InitDBContext((glite_lbu_DBContext*) &ctx->dbctx, GLITE_LBU_DB_BACKEND_MYSQL) != 0) {
                char *ed;
 
                glite_lbu_DBError(ctx->dbctx, NULL, &ed);
index 79a7447..41b3c60 100644 (file)
@@ -784,14 +784,14 @@ static char *ec_to_head_where(edg_wll_Context ctx,const edg_wll_QueryRec **ec)
                case EDG_WLL_QUERY_ATTR_TIME:
                case EDG_WLL_QUERY_ATTR_STATEENTERTIME:
                case EDG_WLL_QUERY_ATTR_LASTUPDATETIME:
-                       glite_lbu_TimeToDB(ec[m][n].value.t.tv_sec, &dbt);
+                       glite_lbu_TimeToStr(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);
                                        free(dbt);
-                                       glite_lbu_TimeToDB(ec[m][n].value2.t.tv_sec, &dbt);
+                                       glite_lbu_TimeToStr(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);
                                }
@@ -808,7 +808,7 @@ static char *ec_to_head_where(edg_wll_Context ctx,const edg_wll_QueryRec **ec)
                        {
                                trio_asprintf(&aux, "%s", dbt);
                                free(dbt);
-                               glite_lbu_TimeToDB(ec[m][n].value2.t.tv_sec, &dbt);
+                               glite_lbu_TimeToStr(ec[m][n].value2.t.tv_sec, &dbt);
                                trio_asprintf(&conds, "(e.time_stamp >= %s AND e.time_stamp <= %s)", aux, dbt);
                                free(aux);
                        }
@@ -1072,14 +1072,14 @@ static char *jc_to_head_where(
 
                        *where_flags |= FL_SEL_STATUS;
 
-                       glite_lbu_TimeToDB(jc[m][n].value.t.tv_sec, &dbt);
+                       glite_lbu_TimeToStr(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);
                                        free(dbt);
-                                       glite_lbu_TimeToDB(jc[m][n].value2.t.tv_sec, &dbt);
+                                       glite_lbu_TimeToStr(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(dbt);
                                        free(aux);
@@ -1094,7 +1094,7 @@ static char *jc_to_head_where(
                        {
                                trio_asprintf(&aux, "%s", dbt);
                                free(dbt);
-                               glite_lbu_TimeToDB(jc[m][n].value2.t.tv_sec, &dbt);
+                               glite_lbu_TimeToStr(jc[m][n].value2.t.tv_sec, &dbt);
                                trio_asprintf(&conds, "(s.%s >= %s AND s.%s <= %s)", cname, aux, cname, dbt);
                                free(dbt);
                                free(aux);
@@ -1368,7 +1368,7 @@ int convert_event_head(edg_wll_Context ctx,char **f,edg_wll_Event *e)
        e->any.user = f[4];
        f[4] = NULL;
        
-       e->any.timestamp.tv_sec = glite_lbu_DBToTime(f[5]);
+       e->any.timestamp.tv_sec = glite_lbu_StrToTime(f[5]);
        free(f[5]); f[5] = NULL;
        
        e->any.timestamp.tv_usec = atoi(f[6]);
@@ -1377,7 +1377,7 @@ int convert_event_head(edg_wll_Context ctx,char **f,edg_wll_Event *e)
        e->any.level = atoi(f[7]); 
        free(f[7]); f[7] = NULL;
 
-       e->any.arrived.tv_sec = glite_lbu_DBToTime(f[8]); 
+       e->any.arrived.tv_sec = glite_lbu_StrToTime(f[8]); 
        e->any.arrived.tv_usec = 0;
        free(f[8]); f[8] = NULL;
 
index 6f614cd..e77328b 100644 (file)
@@ -61,13 +61,13 @@ int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,const char *ulm,int
 
        lowercase_usertag(e);
        jobid = edg_wlc_JobIdGetUnique(e->any.jobId);
-       glite_lbu_TimeToDB(e->any.timestamp.tv_sec, &stamp);
+       glite_lbu_TimeToStr(e->any.timestamp.tv_sec, &stamp);
        ssrc = edg_wll_SourceToString(e->any.source);
 
        if ( ctx->event_load )
-               glite_lbu_TimeToDB(e->any.arrived.tv_sec, &now_s);
+               glite_lbu_TimeToStr(e->any.arrived.tv_sec, &now_s);
        else
-               glite_lbu_TimeToDB(time(NULL), &now_s);
+               glite_lbu_TimeToStr(time(NULL), &now_s);
 
        edg_wll_ResetError(ctx);
        switch (check_auth(ctx,e)) {
index 4df0a9a..0d9d919 100644 (file)
@@ -53,7 +53,3 @@ int glite_lbu_DBSetError(glite_lbu_DBContext ctx, int code, const char *func, in
 
 void glite_lbu_TimeToStrGeneric(time_t t, char **str, const char *amp);
 void glite_lbu_TimestampToStrGeneric(double t, char **str, const char *amp);
-void glite_lbu_TimeToStr(time_t t, char **str);
-void glite_lbu_TimestampToStr(double t, char **str);
-time_t glite_lbu_StrToTime(const char *str);
-double glite_lbu_StrToTimestamp(const char *str);
index 6c36a4d..46a17ae 100644 (file)
@@ -311,6 +311,13 @@ time_t glite_lbu_DBToTime(glite_lbu_DBContext ctx, const char *str);
 double glite_lbu_DBToTimestamp(glite_lbu_DBContext ctx, const char *str);
 
 
+/* Generic helper time convert functions. */
+void glite_lbu_TimeToStr(time_t t, char **str);
+void glite_lbu_TimestampToStr(double t, char **str);
+time_t glite_lbu_StrToTime(const char *str);
+double glite_lbu_StrToTimestamp(const char *str);
+
+
 /**
  * Init data structure for buffered insert
  *
index 59cab6c..db60d2d 100644 (file)
@@ -222,7 +222,7 @@ int glite_lbu_FetchRow(glite_lbu_Statement stmt, unsigned int n, unsigned long *
 
 
 void glite_lbu_FreeStmt(glite_lbu_Statement *stmt) {
-       if (!stmt || !VALID((*stmt)->ctx->backend)) return;
+       if (!stmt || !*stmt || !VALID((*stmt)->ctx->backend)) return;
        return backends[(*stmt)->ctx->backend]->freeStmt(stmt);
 }