struct sockaddr_in a;
glite_jpis_context_t isctx;
int retval = 0;
+ char *err;
glite_jp_init_context(&ctx);
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;
}
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++);
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);
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;
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';
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]) {
#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");
} 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);
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;
}