From 2a903b0bc7191de28c52edac2f7b15ba08500fdd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Thu, 29 Mar 2007 18:20:27 +0000 Subject: [PATCH] Stick primary storage URL with feeds. --- org.glite.jp.index/src/conf.c | 1 + org.glite.jp.index/src/conf.h | 5 +- org.glite.jp.index/src/db_ops.c | 12 ++-- org.glite.jp.index/src/soap_ps_calls.c | 110 ++++-------------------------- org.glite.jp.server-common/interface/db.h | 8 +++ org.glite.jp.server-common/src/db.c | 10 +++ 6 files changed, 46 insertions(+), 100 deletions(-) diff --git a/org.glite.jp.index/src/conf.c b/org.glite.jp.index/src/conf.c index 2769fed..566a07f 100644 --- a/org.glite.jp.index/src/conf.c +++ b/org.glite.jp.index/src/conf.c @@ -217,6 +217,7 @@ static int read_conf(glite_jp_is_conf *conf, char *conf_file) conf->feeds[i]->history = feed->history; conf->feeds[i]->continuous = feed->continuous; + conf->feeds[i]->uniqueid = -1; } } diff --git a/org.glite.jp.index/src/conf.h b/org.glite.jp.index/src/conf.h index 228ef07..a23bc7c 100644 --- a/org.glite.jp.index/src/conf.h +++ b/org.glite.jp.index/src/conf.h @@ -9,7 +9,9 @@ //#define lprintf #define lprintf(args...) glite_jp_lprintf(__FUNCTION__, ##args) - +#define llprintf(MODULE, args...) do { \ + if ((MODULE)) glite_jp_lprintf(__FUNCTION__, ##args); \ +} while(0) typedef struct _glite_jp_is_feed { @@ -17,6 +19,7 @@ typedef struct _glite_jp_is_feed { glite_jp_query_rec_t **query; // query to Primary Server (aka filter) int history, // type of query continuous; + long int uniqueid; // internal ID } glite_jp_is_feed; typedef struct _glite_jp_is_conf { diff --git a/org.glite.jp.index/src/db_ops.c b/org.glite.jp.index/src/db_ops.c index 3f2f24d..f1c0eb6 100644 --- a/org.glite.jp.index/src/db_ops.c +++ b/org.glite.jp.index/src/db_ops.c @@ -19,6 +19,8 @@ #include "db_ops.h" +#define LOG_SQL 0 + #define TABLE_PREFIX_DATA "attr_" #define SQLCMD_DROP_DATA_TABLE "DROP TABLE " TABLE_PREFIX_DATA "%s" #define SQLCMD_CREATE_DATA_TABLE "CREATE TABLE " TABLE_PREFIX_DATA "%s (\n\ @@ -306,8 +308,9 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) { // insert if (glite_jp_db_execute(stmt) == -1) goto fail; - snprintf(sql, sizeof(sql), SQLCMD_CREATE_DATA_TABLE, attrid, type_index, type_full); - lprintf("creating table: '%s'\n", sql); + sql[sizeof(sql) - 1] = '\0'; + snprintf(sql, sizeof(sql) - 1, SQLCMD_CREATE_DATA_TABLE, attrid, type_index, type_full); + llprintf(LOG_SQL, "creating table: '%s'\n", sql); if ((glite_jp_db_execstmt(jpctx, sql, NULL)) == -1) goto fail; i++; @@ -334,6 +337,7 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) { memcpy(dbconds, conds, conds_len); free(conds); if (glite_jp_db_execute(stmt) == -1) goto fail_conds; + feeds[i]->uniqueid = glite_jp_db_lastid(stmt); i++; } @@ -369,7 +373,7 @@ int glite_jpis_dropDatabase(glite_jpis_context_t ctx) { if (glite_jp_db_execute(stmt_tabs) == -1) goto fail; while ((ret = glite_jp_db_fetch(stmt_tabs)) == 0) { snprintf(sql, sizeof(sql), SQLCMD_DROP_DATA_TABLE, attrid); - lprintf("dropping '%s' ==> '%s'\n", attrid, sql); + llprintf(LOG_SQL, "dropping '%s' ==> '%s'\n", attrid, sql); if (glite_jp_db_execstmt(jpctx, sql, NULL) == -1) printf("warning: can't drop table '" TABLE_PREFIX_DATA "%s': %s (%s)\n", attrid, jpctx->error->desc, jpctx->error->source); } if (ret != ENODATA) goto fail; @@ -588,7 +592,7 @@ int glite_jpis_insertAttrVal(glite_jpis_context_t ctx, const char *jobid, glite_ free(table); free(value); free(full_value); - lprintf("(%s) sql=%s\n", av->name, sql); + llprintf(LOG_SQL, "(%s) sql=%s\n", av->name, sql); if (glite_jp_db_execstmt(ctx->jpctx, sql, NULL) != 1) { free(sql); return ctx->jpctx->error->code; diff --git a/org.glite.jp.index/src/soap_ps_calls.c b/org.glite.jp.index/src/soap_ps_calls.c index e54defb..f839245 100644 --- a/org.glite.jp.index/src/soap_ps_calls.c +++ b/org.glite.jp.index/src/soap_ps_calls.c @@ -23,107 +23,22 @@ /* Helper functions */ /*------------------*/ -#define dprintf(FMT, ARGS...) +int debug = 0; +#define dprintf(FMT, ARGS...) if (debug) fprintf(stderr, FMT, ##ARGS) #include "glite/jp/ws_fault.c" #define check_fault(SOAP, ERR) glite_jp_clientCheckFault((SOAP), (ERR), NULL, 0) -#if 0 - -static struct jptype__genericFault *jp2s_error(struct soap *soap, - const glite_jp_error_t *err) -{ - struct jptype__genericFault *ret = NULL; - if (err) { - ret = soap_malloc(soap,sizeof *ret); - memset(ret,0,sizeof *ret); - ret->code = err->code; - ret->source = soap_strdup(soap,err->source); - ret->text = soap_strdup(soap,strerror(err->code)); - ret->description = soap_strdup(soap,err->desc); - ret->reason = jp2s_error(soap,err->reason); - } - return ret; -} - -static void err2fault(const glite_jp_context_t ctx,struct soap *soap) -{ - struct SOAP_ENV__Detail *detail = soap_malloc(soap,sizeof *detail); - struct _genericFault *f = soap_malloc(soap,sizeof *f); - - - f->jpelem__genericFault = jp2s_error(soap,ctx->error); - - detail->__type = SOAP_TYPE__genericFault; -#if GSOAP_VERSION >= 20700 - detail->fault = f; -#else - detail->value = f; -#endif - detail->__any = NULL; - - soap_receiver_fault(soap,"Oh, shit!",NULL); - if (soap->version == 2) soap->fault->SOAP_ENV__Detail = detail; - else soap->fault->detail = detail; -} - - -static int check_fault(struct soap *soap,int err) { - struct SOAP_ENV__Detail *detail; - struct jptype__genericFault *f; - char *reason,indent[200] = " "; - - switch(err) { - case SOAP_OK: puts("OK"); - break; - case SOAP_FAULT: - case SOAP_SVR_FAULT: - if (soap->version == 2) { - detail = soap->fault->SOAP_ENV__Detail; -#if GSOAP_VERSION >= 20706 - reason = soap->fault->SOAP_ENV__Reason->SOAP_ENV__Text; -#else - reason = soap->fault->SOAP_ENV__Reason; -#endif - } - else { - detail = soap->fault->detail; - reason = soap->fault->faultstring; - } - fputs(reason,stderr); - putc('\n',stderr); - assert(detail->__type == SOAP_TYPE__genericFault); -#if GSOAP_VERSION >= 20700 - f = ((struct _genericFault *) detail->fault) -#else - f = ((struct _genericFault *) detail->value) -#endif - -> jpelem__genericFault; - - while (f) { - fprintf(stderr,"%s%s: %s (%s)\n",indent, - f->source,f->text,f->description); - f = f->reason; - strcat(indent," "); - } - return -1; - - default: soap_print_fault(soap,stderr); - return -1; - } - return 0; -} -#endif /*----------------------*/ /* PS WSDL client calls */ /*----------------------*/ -static int find_dest_index(glite_jp_is_conf *conf, char *dest) +static int find_dest_index(glite_jp_is_conf *conf, long int uniqueid) { int i; for (i=0; conf->feeds[i]; i++) - if (!strcmp(dest, conf->feeds[i]->PS_URL)) return(i); + if (conf->feeds[i]->uniqueid == uniqueid) return(i); return -1; } @@ -141,9 +56,11 @@ int MyFeedIndex(glite_jpis_context_t ctx, glite_jp_is_conf *conf, long int uniqu struct soap *soap = soap_new(); glite_gsplugin_Context plugin_ctx; glite_jp_error_t err; - char *src; + char *src, *desc = NULL; + + lprintf("(%ld) for %s called\n", uniqueid, dest); + debug = conf->debug; -lprintf("MyFeedIndex for %s called\n", dest); glite_gsplugin_init_context(&plugin_ctx); if (ctx->conf->server_key) plugin_ctx->key_filename = strdup(ctx->conf->server_key); if (ctx->conf->server_cert) plugin_ctx->cert_filename = strdup(ctx->conf->server_cert); @@ -161,7 +78,7 @@ lprintf("MyFeedIndex for %s called\n", dest); in.__sizeattributes = i; in.attributes = conf->attrs; - if ((dest_index = find_dest_index(conf, dest)) < 0) goto err; + if ((dest_index = find_dest_index(conf, uniqueid)) < 0) goto err; for (i=0; conf->feeds[dest_index]->query[i]; i++); GLITE_SECURITY_GSOAP_LIST_CREATE(soap, &in, conditions, struct jptype__primaryQuery, i); @@ -180,19 +97,21 @@ lprintf("MyFeedIndex for %s called\n", dest); in.history = conf->feeds[dest_index]->history; in.continuous = conf->feeds[dest_index]->continuous; in.destination = ctx->hname; - fprintf(stderr, "%s:%s\n", __FUNCTION__, ctx->hname); + lprintf("(%ld) destination IS: %s\n", uniqueid, ctx->hname); if (check_fault(soap,soap_call___jpsrv__FeedIndex(soap,dest,"", &in, &out)) != 0) { fprintf(stderr, "\n"); glite_jpis_unlockFeed(ctx, uniqueid); err.code = EIO; - err.desc = "soap_call___jpsrv__FeedIndex() returned error"; + asprintf(&desc, "soap_call___jpsrv__FeedIndex() returned error %d", soap->error); + err.desc = desc; asprintf(&src, "%s/%s():%d", __FILE__, __FUNCTION__, __LINE__); fprintf(stderr, "%s\n", err.desc); goto err; } else { - lprintf("FeedId: %s\nExpires: %s\n",out.feedId,ctime(&out.feedExpires)); + lprintf("(%ld) FeedId: %s\n", uniqueid, out.feedId); + lprintf("(%ld) Expires: %s", uniqueid, ctime(&out.feedExpires)); glite_jpis_initFeed(ctx, uniqueid, out.feedId, out.feedExpires); glite_jpis_unlockFeed(ctx, uniqueid); } @@ -206,6 +125,7 @@ err: err.source = src; glite_jp_stack_error(ctx->jpctx, &err); free(src); + free(desc); soap_end(soap); soap_done(soap); diff --git a/org.glite.jp.server-common/interface/db.h b/org.glite.jp.server-common/interface/db.h index 7e51553..d3ad2a8 100644 --- a/org.glite.jp.server-common/interface/db.h +++ b/org.glite.jp.server-common/interface/db.h @@ -240,6 +240,14 @@ int glite_jp_db_execute(glite_jp_db_stmt_t jpstmt); */ int glite_jp_db_fetch(glite_jp_db_stmt_t jpstmt); +/** + * + * \param[inout] jpstmt JP SQL statement + * + * \return value of autoincremented field after last insert/update + */ +long int glite_jp_db_lastid(glite_jp_db_stmt_t jpstmt); + #ifdef __cplusplus } #endif diff --git a/org.glite.jp.server-common/src/db.c b/org.glite.jp.server-common/src/db.c index 3ef2738..380daa3 100644 --- a/org.glite.jp.server-common/src/db.c +++ b/org.glite.jp.server-common/src/db.c @@ -659,3 +659,13 @@ int glite_jp_db_fetch(glite_jp_db_stmt_t jpstmt) { failed: return jpstmt->ctx->error->code; } + + +long int glite_jp_db_lastid(glite_jp_db_stmt_t jpstmt) { + my_ulonglong i; + + glite_jp_clear_error(jpstmt->ctx); + i = mysql_stmt_insert_id(jpstmt->stmt); + assert(i < ((unsigned long int)-1) >> 1); + return (long int)i; +} -- 1.8.2.3