From: František Dvořák Date: Thu, 13 Oct 2005 17:22:23 +0000 (+0000) Subject: UpdateJobs update: X-Git-Tag: glite-jp-client_R_1_0_0~59 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=237f9410d81784f34803ba56132f66eb86ad6cc3;p=jra1mw.git UpdateJobs update: - more elaborate DB error - added owner to jobs - added ps to jobs Fixed inserting string. --- diff --git a/org.glite.jp.index/src/context.h b/org.glite.jp.index/src/context.h index 0ca9551..6e87fb1 100644 --- a/org.glite.jp.index/src/context.h +++ b/org.glite.jp.index/src/context.h @@ -12,8 +12,8 @@ typedef struct _glite_jpis_context { glite_jp_is_conf *conf; glite_jp_db_stmt_t select_unlocked_feed_stmt, lock_feed_stmt, init_feed_stmt, unlock_feed_stmt, select_info_feed_stmt, update_state_feed_stmt, update_error_feed_stmt, select_info_attrs_indexed, select_jobid_stmt, insert_job_stmt; long int param_uniqueid, param_state; - char param_feedid[33], param_ps[256], param_indexed[256], param_jobid[33], param_dg_jobid[256]; - unsigned long param_ps_len, param_feedid_len, param_indexed_len, param_jobid_len, param_dg_jobid_len; + char param_feedid[33], param_ps[256], param_indexed[256], param_jobid[33], param_dg_jobid[256], param_ownerid[33]; + unsigned long param_ps_len, param_feedid_len, param_indexed_len, param_jobid_len, param_dg_jobid_len, param_ownerid_len; void *param_expires; char *hname; diff --git a/org.glite.jp.index/src/db_ops.c b/org.glite.jp.index/src/db_ops.c index 576377b..94bb30d 100644 --- a/org.glite.jp.index/src/db_ops.c +++ b/org.glite.jp.index/src/db_ops.c @@ -386,6 +386,9 @@ int glite_jpis_dropDatabase(glite_jpis_context_t ctx) { // drop feeds and atributes if (glite_jp_db_execstmt(jpctx, "DELETE FROM attrs", NULL) == -1) goto fail; if (glite_jp_db_execstmt(jpctx, "DELETE FROM feeds", NULL) == -1) goto fail; + if (glite_jp_db_execstmt(jpctx, "DELETE FROM jobs", NULL) == -1) goto fail; + if (glite_jp_db_execstmt(jpctx, "DELETE FROM users", NULL) == -1) goto fail; + if (glite_jp_db_execstmt(jpctx, "DELETE FROM acls", NULL) == -1) goto fail; return 0; @@ -459,12 +462,13 @@ int glite_jpis_init_db(glite_jpis_context_t isctx) { if ((glite_jp_db_prepare(jpctx, "SELECT jobid FROM jobs WHERE jobid=?", &isctx->select_jobid_stmt, myparam, NULL)) != 0) goto fail; // sql command: insert the job - glite_jp_db_create_params(&myparam, 3, + glite_jp_db_create_params(&myparam, 4, GLITE_JP_DB_TYPE_CHAR, &isctx->param_jobid, &isctx->param_jobid_len, GLITE_JP_DB_TYPE_VARCHAR, &isctx->param_dg_jobid, &isctx->param_dg_jobid_len, - GLITE_JP_DB_TYPE_VARCHAR, &isctx->param_ps, &isctx->param_ps_len); + GLITE_JP_DB_TYPE_CHAR, &isctx->param_ownerid, &isctx->param_ownerid_len, + GLITE_JP_DB_TYPE_CHAR, &isctx->param_feedid, &isctx->param_feedid_len); // XXX: as attribute? - if ((glite_jp_db_prepare(jpctx, "INSERT INTO jobs (jobid, dg_jobid, ownerid, ps) VALUES (?, ?, 'XXX: unknown', ?)", &isctx->insert_job_stmt, myparam, NULL)) != 0) goto fail; + if ((glite_jp_db_prepare(jpctx, "INSERT INTO jobs (jobid, dg_jobid, ownerid, ps) VALUES (?, ?, ?, (SELECT source FROM feeds WHERE feedid=?))", &isctx->insert_job_stmt, myparam, NULL)) != 0) goto fail; return 0; @@ -531,7 +535,7 @@ int glite_jpis_initFeed(glite_jpis_context_t ctx, long int uniqueid, char *feedI memset(ctx->param_feedid, 0, sizeof(ctx->param_feedid)); strncpy(ctx->param_feedid, feedId, sizeof(ctx->param_feedid) - 1); - ctx->param_feedid_len = strlen(ctx->param_feedid) + 1; + ctx->param_feedid_len = strlen(ctx->param_feedid); glite_jp_db_set_time(ctx->param_expires, feedExpires); ctx->param_uniqueid = uniqueid; @@ -588,8 +592,9 @@ int glite_jpis_insertAttrVal(glite_jpis_context_t ctx, const char *jobid, glite_ } -int glite_jpis_lazyInsertJob(glite_jpis_context_t ctx, const char *jobid) { +int glite_jpis_lazyInsertJob(glite_jpis_context_t ctx, const char *feedid, const char *jobid, const char *owner) { int ret; + char *md5_jobid; lprintf("%s\n", __FUNCTION__); @@ -597,6 +602,20 @@ int glite_jpis_lazyInsertJob(glite_jpis_context_t ctx, const char *jobid) { case -1: return ctx->jpctx->error->code; case 0: lprintf("inserting jobid '%s'\n", jobid); + memset(ctx->param_jobid, 0, sizeof(ctx->param_jobid)); + memset(ctx->param_dg_jobid, 0, sizeof(ctx->param_dg_jobid)); + memset(ctx->param_feedid, 0, sizeof(ctx->param_feedid)); + memset(ctx->param_ownerid, 0, sizeof(ctx->param_ownerid)); + md5_jobid = str2md5(jobid); + strncpy(ctx->param_dg_jobid, jobid, sizeof(ctx->param_dg_jobid)); + strncpy(ctx->param_jobid, md5_jobid, sizeof(ctx->param_jobid)); + strncpy(ctx->param_feedid, feedid, sizeof(ctx->param_feedid)); + strncpy(ctx->param_ownerid, owner, sizeof(ctx->param_ownerid)); + ctx->param_jobid_len = strlen(ctx->param_jobid); + ctx->param_dg_jobid_len = strlen(ctx->param_dg_jobid); + ctx->param_feedid_len = strlen(ctx->param_feedid); + ctx->param_ownerid_len = strlen(ctx->param_ownerid); + free(md5_jobid); if (glite_jp_db_execute(ctx->insert_job_stmt) != 1) return ctx->jpctx->error->code; break; case 1: lprintf("jobid '%s' found\n", jobid); break; diff --git a/org.glite.jp.index/src/db_ops.h b/org.glite.jp.index/src/db_ops.h index 9ebbab2..6beac34 100644 --- a/org.glite.jp.index/src/db_ops.h +++ b/org.glite.jp.index/src/db_ops.h @@ -33,4 +33,6 @@ int glite_jpis_tryReconnectFeed(glite_jpis_context_t ctx, long int uniqueid, tim int glite_jpis_insertAttrVal(glite_jpis_context_t ctx, const char *jobid, glite_jp_attrval_t *av); +int glite_jpis_lazyInsertJob(glite_jpis_context_t ctx, const char *feedid, const char *jobid, const char *owner); + #endif diff --git a/org.glite.jp.index/src/soap_ops.c b/org.glite.jp.index/src/soap_ops.c index 5f71570..45e05c0 100644 --- a/org.glite.jp.index/src/soap_ops.c +++ b/org.glite.jp.index/src/soap_ops.c @@ -76,7 +76,7 @@ static void err2fault(const glite_jp_context_t ctx,struct soap *soap) #define CONTEXT_FROM_SOAP(soap,ctx) glite_jpis_context_t ctx = (glite_jpis_context_t) ((slave_data_t *) (soap->user))->ctx -static int updateJob(glite_jpis_context_t ctx, struct jptype__jobRecord *jobAttrs) { +static int updateJob(glite_jpis_context_t ctx, const char *feedid, struct jptype__jobRecord *jobAttrs) { glite_jp_attrval_t av; struct jptype__attrValue *attr; int ret, iattrs; @@ -85,7 +85,7 @@ static int updateJob(glite_jpis_context_t ctx, struct jptype__jobRecord *jobAttr if (jobAttrs->remove) assert(*(jobAttrs->remove) == 0); - if ((ret = glite_jpis_lazyInsertJob(ctx, jobAttrs->jobid)) != 0) return ret; + if ((ret = glite_jpis_lazyInsertJob(ctx, feedid, jobAttrs->jobid, jobAttrs->owner)) != 0) return ret; for (iattrs = 0; iattrs < jobAttrs->__sizeattributes; iattrs++) { attr = jobAttrs->attributes[iattrs]; @@ -107,6 +107,7 @@ SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__UpdateJobs( int status, done; CONTEXT_FROM_SOAP(soap, ctx); glite_jp_context_t jpctx = ctx->jpctx; + char *err; // XXX: test client in examples/jpis-test // sends to this function some data for testing @@ -118,7 +119,7 @@ SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__UpdateJobs( strncpy(ctx->param_feedid, feedid, sizeof(ctx->param_feedid) - 1); if ((ret = glite_jp_db_execute(ctx->select_info_feed_stmt)) != 1) { fprintf(stderr, "can't get info about '%s', returned %d records: %s (%s)\n", feedid, ret, jpctx->error->desc, jpctx->error->source); - return SOAP_FAULT; + goto fail; } // update status, if needed (only oring) status = ctx->param_state; @@ -127,16 +128,23 @@ SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__UpdateJobs( ctx->param_state |= done; if ((ret = glite_jp_db_execute(ctx->update_state_feed_stmt)) != 1) { fprintf(stderr, "can't update state of '%s', returned %d records: %s (%s)\n", feedid, ret, jpctx->error->desc, jpctx->error->source); - return SOAP_FAULT; + goto fail; } } // insert all attributes for (ijobs = 0; ijobs < jpelem__UpdateJobs->__sizejobAttributes; ijobs++) { - if (updateJob(ctx, jpelem__UpdateJobs->jobAttributes[ijobs]) != 0) return SOAP_FAULT; + if (updateJob(ctx, feedid, jpelem__UpdateJobs->jobAttributes[ijobs]) != 0) goto fail; } return SOAP_OK; + +fail: +// TODO: bubble up + err = glite_jp_error_chain(ctx->jpctx); + printf("%s:%s\n", __FUNCTION__, err); + free(err); + return SOAP_FAULT; } diff --git a/org.glite.jp.index/src/soap_ps_calls.c b/org.glite.jp.index/src/soap_ps_calls.c index 930a322..1a61362 100644 --- a/org.glite.jp.index/src/soap_ps_calls.c +++ b/org.glite.jp.index/src/soap_ps_calls.c @@ -166,6 +166,7 @@ printf("MyFeedIndex for %s called\n", dest); in.history = conf->feeds[dest_index]->history; in.continuous = conf->feeds[dest_index]->continuous; in.destination = ctx->hname; + printf("%s:%s\n", __FUNCTION__, ctx->hname); if (check_fault(soap,soap_call___jpsrv__FeedIndex(soap,dest,"", &in, &out)) != 0) { printf("\n");