From ff8cb314a9c398d619944b367f71b6430eb7c432 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Mon, 2 Apr 2007 10:45:45 +0000 Subject: [PATCH] implemented >, < and within operations on index added test for WITHIN on query operation testing w/o distractions from running JPPS (w/o feeds) cosmetic changes in tests --- org.glite.jp.index/Makefile | 3 +- .../config/glite-jpis-test-config.xml | 34 +++++++ org.glite.jp.index/examples/jpis-client.c | 6 +- .../examples/query-tests/exists_query.out | 2 +- .../examples/query-tests/run-test.sh | 41 ++++++-- .../examples/query-tests/within_query.in | 19 ++++ .../examples/query-tests/within_query.out | 28 ++++++ org.glite.jp.index/src/soap_ops.c | 111 ++++++++++++++++----- 8 files changed, 201 insertions(+), 43 deletions(-) create mode 100644 org.glite.jp.index/config/glite-jpis-test-config.xml create mode 100644 org.glite.jp.index/examples/query-tests/within_query.in create mode 100644 org.glite.jp.index/examples/query-tests/within_query.out diff --git a/org.glite.jp.index/Makefile b/org.glite.jp.index/Makefile index b7c028c..b43cc0a 100644 --- a/org.glite.jp.index/Makefile +++ b/org.glite.jp.index/Makefile @@ -49,7 +49,7 @@ INSTALL:=libtool --mode=install install daemon:=glite-jp-indexd examples:=glite-jpis-test glite-jpis-client test:=run-test.sh -test_files:=dump1.sql simple_query.in simple_query.out complex_query.in complex_query.out authz.out jobid_query.in jobid_query.out origin_query.in origin_query.out exists_query.in exists_query.out +test_files:=dump1.sql simple_query.in simple_query.out complex_query.in complex_query.out authz.out jobid_query.in jobid_query.out origin_query.in origin_query.out exists_query.in exists_query.out within_query.in within_query.out MANS1:=glite-jpis-client.1 MANS8:=glite-jp-indexd.8 @@ -169,6 +169,7 @@ install: ${INSTALL} -m 755 ${top_srcdir}/config/startup ${PREFIX}/etc/init.d/glite-jp-indexd ${INSTALL} -m 755 ${top_srcdir}/config/glite-jp-index-dbsetup.sql ${PREFIX}/etc ${INSTALL} -m 755 ${top_srcdir}/config/glite-jpis-config.xml ${PREFIX}/etc + ${INSTALL} -m 755 ${top_srcdir}/config/glite-jpis-test-config.xml ${PREFIX}/etc ${INSTALL} -m 644 ${top_srcdir}/doc/README ${HTMLS} ${PREFIX}/share/doc/${package}-${version} ${INSTALL} -m 644 ${MANS1} ${PREFIX}/share/man/man1 ${INSTALL} -m 644 ${MANS8} ${PREFIX}/share/man/man8 diff --git a/org.glite.jp.index/config/glite-jpis-test-config.xml b/org.glite.jp.index/config/glite-jpis-test-config.xml new file mode 100644 index 0000000..b81b342 --- /dev/null +++ b/org.glite.jp.index/config/glite-jpis-test-config.xml @@ -0,0 +1,34 @@ + + + + + http://egee.cesnet.cz/en/Schema/JP/System:owner + http://egee.cesnet.cz/en/Schema/JP/System:jobId + http://egee.cesnet.cz/en/Schema/JP/System:regtime + http://egee.cesnet.cz/en/Schema/LB/Attributes:user + http://egee.cesnet.cz/en/Schema/LB/Attributes:aTag + http://egee.cesnet.cz/en/Schema/LB/Attributes:eNodes + http://egee.cesnet.cz/en/Schema/LB/Attributes:RB + http://egee.cesnet.cz/en/Schema/LB/Attributes:CE + http://egee.cesnet.cz/en/Schema/LB/Attributes:UIHost + http://egee.cesnet.cz/en/Schema/LB/Attributes:CPUTime + http://egee.cesnet.cz/en/Schema/LB/Attributes:NProc + http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus + http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatusDate + http://egee.cesnet.cz/en/Schema/LB/Attributes:retryCount + http://egee.cesnet.cz/en/Schema/LB/Attributes:jobType + http://egee.cesnet.cz/en/Schema/LB/Attributes:nsubjobs + http://egee.cesnet.cz/en/Schema/LB/Attributes:lastStatusHistory + http://egee.cesnet.cz/en/Schema/LB/Attributes:fullStatusHistory + + + + http://egee.cesnet.cz/en/Schema/JP/System:owner + http://egee.cesnet.cz/en/Schema/JP/System:jobId + http://egee.cesnet.cz/en/Schema/LB/Attributes:user + http://egee.cesnet.cz/en/Schema/LB/Attributes:CE + http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus + + + + diff --git a/org.glite.jp.index/examples/jpis-client.c b/org.glite.jp.index/examples/jpis-client.c index 50c7875..e7cbff0 100644 --- a/org.glite.jp.index/examples/jpis-client.c +++ b/org.glite.jp.index/examples/jpis-client.c @@ -55,8 +55,8 @@ struct { {jptype__queryOp__UNEQUAL, "<>"}, {jptype__queryOp__LESS, "<"}, {jptype__queryOp__GREATER, ">"}, - {jptype__queryOp__WITHIN, "in"}, - {jptype__queryOp__EXISTS, "exists"}, + {jptype__queryOp__WITHIN, "WITHIN"}, + {jptype__queryOp__EXISTS, "EXISTS"}, {0, "unknown"} }; @@ -227,7 +227,7 @@ static void query_print(FILE *out, const struct _jpisclient__QueryJobs *in) { } if (rec->value2) { if (!rec->value) fprintf(out, "-"); - fprintf(out, " "); + fprintf(out, " AND "); value_print(out, rec->value2); } fprintf(out, "\n"); diff --git a/org.glite.jp.index/examples/query-tests/exists_query.out b/org.glite.jp.index/examples/query-tests/exists_query.out index 04f2c48..2fbebf3 100644 --- a/org.glite.jp.index/examples/query-tests/exists_query.out +++ b/org.glite.jp.index/examples/query-tests/exists_query.out @@ -3,7 +3,7 @@ query: using JPIS http://localhost:10000 Conditions: http://egee.cesnet.cz/en/Schema/LB/Attributes:CE origin IS ANY - value exists + value EXISTS Attributes: http://egee.cesnet.cz/en/Schema/JP/System:owner http://egee.cesnet.cz/en/Schema/JP/System:jobId diff --git a/org.glite.jp.index/examples/query-tests/run-test.sh b/org.glite.jp.index/examples/query-tests/run-test.sh index ad2e381..9c0335a 100755 --- a/org.glite.jp.index/examples/query-tests/run-test.sh +++ b/org.glite.jp.index/examples/query-tests/run-test.sh @@ -6,6 +6,8 @@ # requires running mysql # +LC_ALL=C + usage() { cat </dev/null | grep "\<$GLITE_JPIS_TEST_PORT\>" > /dev/null + netstat -tap 2>/dev/null | grep "\<$GLITE_JPIS_TEST_PORT\>" > /dev/null ret=$? i=$(($i+1)) - LC_ALL=C sleep 0.1 + sleep 0.1 done + if [ x"$ret" != x"0" ]; then + echo "Index server not started." + kill_is; + drop_db; + exit 1; + fi echo -n "S " } @@ -252,7 +263,7 @@ run_test_query $GLITE_LOCATION/examples/query-tests/simple_query.in $GLITE_LOCAT drop_db; kill_is; -echo -n "Query jobId test........... " +echo -n "Query jobId test..... " create_db; run_is "-n"; import_db $GLITE_LOCATION/examples/query-tests/dump1.sql; @@ -260,7 +271,7 @@ run_test_query $GLITE_LOCATION/examples/query-tests/jobid_query.in $GLITE_LOCATI drop_db; kill_is; -echo -n "Origin test........... " +echo -n "Origin test.......... " create_db; run_is "-n"; import_db $GLITE_LOCATION/examples/query-tests/dump1.sql; @@ -268,10 +279,18 @@ run_test_query $GLITE_LOCATION/examples/query-tests/origin_query.in $GLITE_LOCAT drop_db; kill_is; -echo -n "EXISTS operation test........... " +echo -n "EXISTS test.......... " create_db; run_is "-n"; import_db $GLITE_LOCATION/examples/query-tests/dump1.sql; run_test_query $GLITE_LOCATION/examples/query-tests/exists_query.in $GLITE_LOCATION/examples/query-tests/exists_query.out; drop_db; kill_is; + +echo -n "WITHIN test.......... " +create_db; +run_is "-n"; +import_db $GLITE_LOCATION/examples/query-tests/dump1.sql; +run_test_query $GLITE_LOCATION/examples/query-tests/within_query.in $GLITE_LOCATION/examples/query-tests/exists_query.out; +drop_db; +kill_is; diff --git a/org.glite.jp.index/examples/query-tests/within_query.in b/org.glite.jp.index/examples/query-tests/within_query.in new file mode 100644 index 0000000..99d5a51 --- /dev/null +++ b/org.glite.jp.index/examples/query-tests/within_query.in @@ -0,0 +1,19 @@ + + + + + http://egee.cesnet.cz/en/Schema/LB/Attributes:CE + + WITHIN + VOCA + VOCI + + + + http://egee.cesnet.cz/en/Schema/JP/System:owner + http://egee.cesnet.cz/en/Schema/JP/System:jobId + http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus + http://egee.cesnet.cz/en/Schema/LB/Attributes:user + http://egee.cesnet.cz/en/Schema/LB/Attributes:CE + + diff --git a/org.glite.jp.index/examples/query-tests/within_query.out b/org.glite.jp.index/examples/query-tests/within_query.out new file mode 100644 index 0000000..c1d7251 --- /dev/null +++ b/org.glite.jp.index/examples/query-tests/within_query.out @@ -0,0 +1,28 @@ +query: using JPIS http://localhost:12002 + +Conditions: + http://egee.cesnet.cz/en/Schema/LB/Attributes:CE + origin IS ANY + value WITHIN VOCA AND VOCI +Attributes: + http://egee.cesnet.cz/en/Schema/JP/System:owner + http://egee.cesnet.cz/en/Schema/JP/System:jobId + http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus + http://egee.cesnet.cz/en/Schema/LB/Attributes:user + http://egee.cesnet.cz/en/Schema/LB/Attributes:CE + +OK +Result 1 jobs: + jobid = https://localhost:7846/pokus1, owner = /O=CESNET/O=Masaryk University/CN=Milos Mulac + http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus + value = Done + origin = FILE (no detail) + time = Thu Jan 1 02:00:01 1970 + http://egee.cesnet.cz/en/Schema/LB/Attributes:user + value = CertSubj + origin = FILE (no detail) + time = Thu Jan 1 02:00:01 1970 + http://egee.cesnet.cz/en/Schema/LB/Attributes:CE + value = VOCE + origin = FILE (no detail) + time = Thu Jan 1 02:00:01 1970 diff --git a/org.glite.jp.index/src/soap_ops.c b/org.glite.jp.index/src/soap_ops.c index 354d26b..000082d 100644 --- a/org.glite.jp.index/src/soap_ops.c +++ b/org.glite.jp.index/src/soap_ops.c @@ -189,6 +189,16 @@ static int get_op(const enum jptype__queryOp in, char **out) case GLITE_JP_QUERYOP_UNEQUAL: qop = strdup("!="); break; +// FIXME: has index the same metrics? + case GLITE_JP_QUERYOP_GREATER: + qop = strdup(">"); + break; + case GLITE_JP_QUERYOP_LESS: + qop = strdup("<"); + break; + case GLITE_JP_QUERYOP_WITHIN: + qop = strdup("BETWEEN"); + break; default: // unsupported query operator return(1); @@ -200,10 +210,61 @@ static int get_op(const enum jptype__queryOp in, char **out) } +static char *get_sql_stringvalue(glite_jpis_context_t ctx, struct jptype__stringOrBlob *value) { + if (!value) return NULL; + if (!GSOAP_ISSTRING(value)) return NULL; + return GSOAP_STRING(value); +} + + +static int get_sql_indexvalue(char **sql, struct soap *soap, glite_jpis_context_t ctx, struct jptype__indexQuery *condition, struct jptype__stringOrBlob *value) { + glite_jp_attrval_t attr; + + *sql = NULL; + if (!value) return 0; + memset(&attr, 0, sizeof attr); + attr.name = condition->attr; + if (GSOAP_ISSTRING(value)) { + attr.value = GSOAP_STRING(value); + attr.binary = 0; + } else if (GSOAP_ISBLOB(value)) { + attr.value = GSOAP_BLOB(value)->__ptr; + attr.size = GSOAP_BLOB(value)->__size; + attr.binary = 1; + } else return 0; + glite_jpis_SoapToAttrOrig(soap, condition->origin, &(attr.origin)); + + *sql = glite_jp_attrval_to_db_index(ctx->jpctx, &attr, 255); + return 0; +} + + +static int get_sql_cond(char **sql, const char *attr_md5, enum jptype__queryOp op, char *value, char *value2) { + char *s, *qop, *column; + + *sql = NULL; + if (get_op(op, &qop) != 0) return 0; + if (attr_md5) trio_asprintf(&column, "attr_%|Ss.value", attr_md5); + else asprintf(&column, "jobs.dg_jobid"); + trio_asprintf(sql, "%s %s \"%|Ss\"", column, qop, value); + free(column); + free(qop); + if (op == jptype__queryOp__WITHIN) { + if (!value) { + free(*sql); + *sql = NULL; + return EINVAL; + } + trio_asprintf(&s, "%s AND \"%|Ss\"", *sql, value2); + free(*sql); *sql = s; + } + return 0; +} + + static char *get_sql_or(struct soap *soap, glite_jpis_context_t ctx, struct jptype__indexQuery *condition, const char *attr_md5) { struct jptype__indexQueryRecord *record; - glite_jp_attrval_t attr; - char *qop, *sql, *s; + char *sql, *cond, *s = NULL, *value, *value2; int j; sql = strdup(""); @@ -212,34 +273,30 @@ static char *get_sql_or(struct soap *soap, glite_jpis_context_t ctx, struct jpty if (record->op == jptype__queryOp__EXISTS) { /* no additional conditions needed when existing is enough */ } else { - if (get_op(record->op, &qop)) return NULL; - - memset(&attr, 0, sizeof(attr)); - attr.name = condition->attr; - if (GSOAP_ISSTRING(record->value)) { - attr.value = GSOAP_STRING(record->value); - attr.binary = 0; - } else { - attr.value = GSOAP_BLOB(record->value)->__ptr; - attr.size = GSOAP_BLOB(record->value)->__size; - attr.binary = 1; - } - glite_jpis_SoapToAttrOrig(soap, - condition->origin, &(attr.origin)); if (strcmp(condition->attr, GLITE_JP_ATTR_JOBID) == 0) { - trio_asprintf(&s,"%s%sjobs.dg_jobid %s \"%|Ss\"", - sql, (sql[0] ? " OR " : ""), qop, attr.value); + value = get_sql_stringvalue(ctx, record->value); + if (!value) goto err; + value2 = get_sql_stringvalue(ctx, record->value2); + if (get_sql_cond(&cond, attr_md5, record->op, value, value2) != 0) goto err; } else { - trio_asprintf(&s,"%s%sattr_%|Ss.value %s \"%|Ss\"", - sql, (sql[0] ? " OR " : ""), attr_md5, qop, - glite_jp_attrval_to_db_index(ctx->jpctx, &attr, 255)); + get_sql_indexvalue(&value, soap, ctx, condition, record->value); + get_sql_indexvalue(&value2, soap, ctx, condition, record->value2); + get_sql_cond(&cond, attr_md5, record->op, value, value2); + free(value); + free(value2); + if (!cond) goto err; } - free(qop); + trio_asprintf(&s,"%s%s%s", sql, (sql[0] ? " OR " : ""), cond); + free(cond); free(sql); sql = s; } } return sql; +err: + free(sql); + free(s); + return NULL; } @@ -250,7 +307,7 @@ static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpele *qwhere = NULL, *query = NULL, *res[2], **jids = NULL, **pss = NULL, **attr_tables = NULL; int i, ret; - glite_jp_db_stmt_t stmt; + glite_jp_db_stmt_t stmt = NULL; glite_jp_attr_orig_t orig; @@ -277,8 +334,8 @@ static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpele trio_asprintf(&qb, ""); /* select given records in attr_ table */ - trio_asprintf(&qa,"%s%s jobs.jobid = attr_%|Ss.jobid", - (i ? "AND" : ""), qb, attr_md5); + trio_asprintf(&qa,"%s%sjobs.jobid = attr_%|Ss.jobid", + (i ? "AND " : ""), qb, attr_md5); free(qb); } @@ -292,7 +349,7 @@ static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpele } free(qor); - trio_asprintf(&qb,"%s %s", qwhere, qa); + trio_asprintf(&qb,"%s%s%s", qwhere, qa[0] ? " " : "", qa); free(qa); qwhere = qb; qb = NULL; qa = NULL; free(attr_md5); } @@ -308,7 +365,7 @@ static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpele trio_asprintf(&query, "SELECT DISTINCT dg_jobid,ps FROM jobs%s WHERE%s", qa, qwhere); } else { - trio_asprintf(&query, "SELECT DISTINCT dg_jobid,ps FROM jobs,users%s WHERE (jobs.ownerid = users.userid AND users.cert_subj='%s') AND %s", qa, ctx->jpctx->peer, qwhere); + trio_asprintf(&query, "SELECT DISTINCT dg_jobid,ps FROM jobs,users%s WHERE (jobs.ownerid = users.userid AND users.cert_subj='%s') AND%s", qa, ctx->jpctx->peer, qwhere); } printf("Incomming QUERY:\n %s\n", query); free(qwhere); -- 1.8.2.3