JPIS:
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 7 May 2008 14:02:58 +0000 (14:02 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 7 May 2008 14:02:58 +0000 (14:02 +0000)
 - small reshuffle of the code in JPIS (reuse error handling, certificates before feeding)
 - more concrete errors
 - owner used for feeding from the optional certificate
 - warning fix
DB module:
 - proper error detection

org.glite.jp.index/src/bones_server.c
org.glite.jp.index/src/db_ops.c
org.glite.jp.index/src/db_ops.h
org.glite.jp.index/src/soap_ops.c
org.glite.jp.server-common/src/db.c

index b52ffa0..8cbc2c8 100644 (file)
@@ -75,6 +75,7 @@ int main(int argc, char *argv[])
        struct sockaddr_in      a;
        glite_jpis_context_t    isctx;
        int retval = 0;
+       char *err;
 
        glite_jp_init_context(&ctx);
 
@@ -104,28 +105,36 @@ int main(int argc, char *argv[])
 
        if (conf->delete_db) {
                if (glite_jpis_dropDatabase(isctx) != 0) {
-                       fprintf(stderr, "Drop DB failed: %s (%s)\n", ctx->error->desc, ctx->error->source);
+                       fprintf(stderr, "Drop DB failed: ");
                        retval = 1;
                        goto quit;
                }
        }
 
        if (glite_jpis_initDatabase(isctx) != 0) {
-               fprintf(stderr, "Init DB failed: %s (%s)\n", ctx->error->desc, ctx->error->source);
+               fprintf(stderr, "Init DB failed: ");
                retval = 1;
                goto quit;
        }
 
-       if (conf->feeding) {
-               char *err;
+       server_cert = conf->server_cert;
+       server_key = conf->server_key;
+
+       if (!server_cert || !server_key)
+               fprintf(stderr, "%s: WARNING: key or certificate file not specified, "
+                               "can't watch them for changes\n",
+                               argv[0]);
 
+       if ( cadir ) setenv("X509_CERT_DIR", cadir, 1);
+       edg_wll_gss_watch_creds(server_cert, &cert_mtime);
+
+       if ( !edg_wll_gss_acquire_cred_gsi(server_cert, server_key, &mycred, &gss_code)) 
+               fprintf(stderr,"Server identity: %s\n",mycred ? mycred->name : "NULL");
+       else fputs("WARNING: Running unauthenticated\n",stderr);
+
+       if (conf->feeding) {
                fprintf(stderr, "%s: Feeding from '%s'\n", argv[0], conf->feeding);
-               retval = glite_jpis_feeding(isctx, conf->feeding);
-               if (retval) {
-                       err = glite_jp_error_chain(isctx->jpctx);
-                       fprintf(stderr, "%s: %s\n", argv[0], err);
-                       free(err);
-               }
+               retval = glite_jpis_feeding(isctx, conf->feeding, mycred ? mycred->name : NULL);
                goto quit;
        }
 
@@ -154,21 +163,6 @@ int main(int argc, char *argv[])
                return 1;
        }
 
-       server_cert = conf->server_cert;
-       server_key = conf->server_key;
-
-       if (!server_cert || !server_key)
-               fprintf(stderr, "%s: WARNING: key or certificate file not specified, "
-                               "can't watch them for changes\n",
-                               argv[0]);
-
-       if ( cadir ) setenv("X509_CERT_DIR", cadir, 1);
-       edg_wll_gss_watch_creds(server_cert, &cert_mtime);
-
-       if ( !edg_wll_gss_acquire_cred_gsi(server_cert, server_key, &mycred, &gss_code)) 
-               fprintf(stderr,"Server idenity: %s\n",mycred ? mycred->name : "NULL");
-       else fputs("WARNING: Running unauthenticated\n",stderr);
-
        // XXX: more tests needed
        if (conf->feeds)
                for (nfeeds=0; conf->feeds[nfeeds]; nfeeds++);
@@ -198,6 +192,12 @@ int main(int argc, char *argv[])
        glite_srvbones_run(data_init,&stab,1 /* XXX: entries in stab */,debug);
 
 quit:
+       if (isctx->jpctx->error) {
+               err = glite_jp_error_chain(isctx->jpctx);
+               fprintf(stderr, "%s: %s\n", argv[0], err);
+               free(err);
+       }
+
        glite_jpis_free_db(isctx);
        glite_jp_free_conf(conf);
        glite_jpis_free_context(isctx);
index 415400b..dac59f5 100644 (file)
@@ -316,7 +316,10 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) {
                return 0;
        }
 
-       if (glite_jp_db_PrepareStmt(jpctx, "INSERT INTO attrs (attrid, name, indexed, type) VALUES (?, ?, ?, ?)", &stmt) != 0) goto fail;
+       if (glite_jp_db_PrepareStmt(jpctx, "INSERT INTO attrs (attrid, name, indexed, type) VALUES (?, ?, ?, ?)", &stmt) != 0) {
+               glite_jpis_stack_error(ctx->jpctx, EIO, "can't create insert attributes statement");
+               goto fail;
+       }
 
        // attrs table and attrid_* tables
        attrs = ctx->conf->attrs;
@@ -331,13 +334,17 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) {
                  GLITE_LBU_DB_TYPE_VARCHAR, attrid,
                  GLITE_LBU_DB_TYPE_VARCHAR, attrs[i],
                  GLITE_LBU_DB_TYPE_INT, indexed,
-                 GLITE_LBU_DB_TYPE_VARCHAR, type_full) == -1) goto fail;
+                 GLITE_LBU_DB_TYPE_VARCHAR, type_full) == -1) {
+                       glite_jpis_stack_error(ctx->jpctx, EIO, "can't create '%s' attribute", attrs[i]);
+                       goto fail;
+               }
 
                // silently drop
                sql[sizeof(sql) - 1] = '\0';
                snprintf(sql, sizeof(sql), SQLCMD_DROP_DATA_TABLE, attrid);
                llprintf(LOG_SQL, "preventive dropping '%s' ==> '%s'\n", attrid, sql);
                glite_jp_db_ExecSQL(jpctx, sql, NULL);
+               glite_jp_clear_error(ctx->jpctx);
 
                // create table
                sql[sizeof(sql) - 1] = '\0';
@@ -354,7 +361,10 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) {
        glite_jp_db_FreeStmt(&stmt);
 
        // feeds table
-       if (glite_jp_db_PrepareStmt(jpctx, "INSERT INTO feeds (state, locked, source, condition) VALUES (?, ?, ?, ?)", &stmt) != 0) goto fail;
+       if (glite_jp_db_PrepareStmt(jpctx, "INSERT INTO feeds (`state`, `locked`, `source`, `condition`) VALUES (?, ?, ?, ?)", &stmt) != 0) {
+               glite_jpis_stack_error(ctx->jpctx, EIO, "can't create insert feeds statement");
+               goto fail;
+       }
        feeds = ctx->conf->feeds;
        i = 0;
        if (feeds) while (feeds[i]) {
@@ -709,13 +719,14 @@ fail:
 #define FEEDING_JOBID_BKSERVER "localhost-test"
 #define FEEDING_JOBID_PORT 0
 #define FEEDING_PRIMARY_STORAGE "localhost:8901"
-#define FEEDING_OWNER "God"
-int glite_jpis_feeding(glite_jpis_context_t ctx, const char *fname) {
+#define FEEDING_DEFAULT_OWNER "God"
+int glite_jpis_feeding(glite_jpis_context_t ctx, const char *fname, const char *dn) {
        FILE *f;
        char line[1024], *token, *lasts, *jobid = NULL;
        int nattrs, lno, i, iname, c;
        glite_jp_attrval_t *avs;
        glite_jobid_t j;
+       const char *owner = dn ? dn : FEEDING_DEFAULT_OWNER;
 
        if ((f = fopen(fname, "rt")) == NULL) {
                glite_jpis_stack_error(ctx->jpctx, errno, "can't open csv dump file");
@@ -755,7 +766,7 @@ int glite_jpis_feeding(glite_jpis_context_t ctx, const char *fname) {
                        } while (strcasecmp(avs[i].name, GLITE_JP_ATTR_JOBID) == 0 || strcasecmp(avs[i].name, GLITE_JP_ATTR_OWNER) == 0);
                        avs[i].value = token;
                        avs[i].timestamp = time(NULL);
-                       fprintf(stderr, "\t %d: %s = '%s'\n", i, avs[i].name, avs[i].value);
+//                     printf(stderr, "\t %d: %s = '%s'\n", i, avs[i].name, avs[i].value);
                        i++;
 
                        token = strtok_r(NULL, FEEDING_SEPARATORS, &lasts);
@@ -771,7 +782,7 @@ int glite_jpis_feeding(glite_jpis_context_t ctx, const char *fname) {
                        goto err;
                }
                glite_jobid_free(j);
-               if (glite_jpis_lazyInsertJob(ctx, FEEDING_PRIMARY_STORAGE, jobid, FEEDING_OWNER)) goto err;
+               if (glite_jpis_lazyInsertJob(ctx, FEEDING_PRIMARY_STORAGE, jobid, owner)) goto err;
                for (i = 0; i < nattrs && avs[i].name; i++) {
                        if (glite_jpis_insertAttrVal(ctx, jobid, &avs[i])) goto err;
                }
index d95cda5..a9de808 100644 (file)
@@ -42,6 +42,6 @@ int glite_jpis_insertAttrVal(glite_jpis_context_t ctx, const char *jobid, glite_
 
 int glite_jpis_lazyInsertJob(glite_jpis_context_t ctx, const char *ps, const char *jobid, const char *owner);
 
-int glite_jpis_feeding(glite_jpis_context_t ctx, const char *fname);
+int glite_jpis_feeding(glite_jpis_context_t ctx, const char *fname, const char *dn);
 
 #endif
index 350b372..6c98b36 100644 (file)
@@ -266,7 +266,7 @@ static int get_sql_indexvalue(char **sql, glite_jpis_context_t ctx, struct jptyp
                attr.value = GSOAP_STRING(value);
                attr.binary = 0;
        } else if (GSOAP_ISBLOB(value)) {
-               attr.value = GSOAP_BLOB(value)->__ptr;
+               attr.value = (char *)GSOAP_BLOB(value)->__ptr;
                attr.size = GSOAP_BLOB(value)->__size;
                attr.binary = 1;
        } else return 0;
index 57826b6..3b2eeef 100644 (file)
@@ -59,7 +59,7 @@ int glite_jp_db_PrepareStmt(glite_jp_context_t ctx, const char *sql, glite_lbu_S
        int ret;
 
        ret = glite_lbu_PrepareStmt(ctx->dbhandle, sql, stmt);
-       if (ret < 0) glite_jp_db_SetError(ctx, __FUNCTION__);
+       if (ret != 0) glite_jp_db_SetError(ctx, __FUNCTION__);
        return ret;
 }