Implemented origin queries with according tests.
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
+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
+
MANS1:=glite-jpis-client.1
MANS8:=glite-jp-indexd.8
MANS:=${MANS1} ${MANS8}
#define soap_serialize__jpisclient__QueryJobsResponse soap_serialize__jpelem__QueryJobsResponse
#define DEFAULT_JPIS "http://localhost:8902"
-//#define USE_GMT 1
+#define USE_GMT 1
/* namespaces[] not used here but needed to prevent linker to complain... */
cond = soap_malloc(soap, sizeof(*cond));
memset(cond, 0, sizeof(*cond));
cond->attr = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus");
- cond->origin = NULL;
+ cond->origin = soap_malloc(soap, sizeof(*(cond->origin)));
+ *(cond->origin) = jptype__attrOrig__SYSTEM;
cond->__sizerecord = 2;
cond->record = soap_malloc(soap, cond->__sizerecord * sizeof(*(cond->record)));
fprintf(out, "Conditions:\n");
for (i = 0; i < in->__sizeconditions; i++) {
fprintf(out, "\t%s\n", in->conditions[i]->attr);
+ if (in->conditions[i]->origin) {
+ for (k = 0; k <= NUMBER_ORIG; k++)
+ if (origins[k].orig == *(in->conditions[i]->origin)) break;
+ fprintf(out, "\t\torigin == %s\n", origins[k].name);
+ } else {
+ fprintf(out, "\t\torigin IS ANY\n");
+ }
for (j = 0; j < in->conditions[i]->__sizerecord; j++) {
rec = in->conditions[i]->record[j];
for (k = 0; k <= NUMBER_OP; k++)
if (operations[k].op == rec->op) break;
- fprintf(out, "\t\t%s", operations[k].name);
+ fprintf(out, "\t\tvalue %s", operations[k].name);
if (rec->value) {
fprintf(out, " ");
value_print(out, rec->value);
Conditions:
http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus
- == Ready
+ origin IS ANY
+ value == Ready
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:user
OK
-<?xml version="1.0" encoding="UTF-8"?><jpisclient:QueryJobsResponse xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jptype="http://glite.org/wsdl/types/jp" xmlns:jpsrv="http://glite.org/wsdl/services/jp" xmlns:jpelem="http://glite.org/wsdl/elements/jp" xmlns:jpisclient="http://glite.org/xsd/types/jpisclient"></jpisclient:QueryJobsResponse>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?><jpisclient:QueryJobsResponse xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jptype="http://glite.org/wsdl/types/jp" xmlns:jpsrv="http://glite.org/wsdl/services/jp" xmlns:jpelem="http://glite.org/wsdl/elements/jp" xmlns:jpisclient="http://glite.org/xsd/types/jpisclient"></jpisclient:QueryJobsResponse>
Conditions:
http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus
- == Done
- == Ready
+ origin IS ANY
+ value == Done
+ value == Ready
http://egee.cesnet.cz/en/Schema/LB/Attributes:user
- <> God
+ origin IS ANY
+ value <> God
Attributes:
http://egee.cesnet.cz/en/Schema/JP/System:owner
http://egee.cesnet.cz/en/Schema/JP/System:jobId
/*!40000 ALTER TABLE `attr_9892f81a8175c09bd00afcb152f510ad` DISABLE KEYS */;
LOCK TABLES `attr_9892f81a8175c09bd00afcb152f510ad` WRITE;
-INSERT INTO `attr_9892f81a8175c09bd00afcb152f510ad` VALUES ('593e62a063231f8c623b74406b3e12b0','CertSubj','S:3601:F::CertSubj',1),('9276789a0093ad44457655ef03ade36a','CertSubj','S:3601:S::CertSubj',2);
+INSERT INTO `attr_9892f81a8175c09bd00afcb152f510ad` VALUES ('593e62a063231f8c623b74406b3e12b0','CertSubj','S:7201:F::CertSubj',3),('9276789a0093ad44457655ef03ade36a','CertSubj','S:7201:S::CertSubj',2);
UNLOCK TABLES;
/*!40000 ALTER TABLE `attr_9892f81a8175c09bd00afcb152f510ad` ENABLE KEYS */;
/*!40000 ALTER TABLE `attr_a1e9e0a1b7943cc041fefb5da65868f9` DISABLE KEYS */;
LOCK TABLES `attr_a1e9e0a1b7943cc041fefb5da65868f9` WRITE;
-INSERT INTO `attr_a1e9e0a1b7943cc041fefb5da65868f9` VALUES ('593e62a063231f8c623b74406b3e12b0','Done','S:3601:F::Done',1),('9276789a0093ad44457655ef03ade36a','Ready','S:3601:S::Ready',1);
+INSERT INTO `attr_a1e9e0a1b7943cc041fefb5da65868f9` VALUES ('593e62a063231f8c623b74406b3e12b0','Done','S:7201:F::Done',3),('9276789a0093ad44457655ef03ade36a','Ready','S:7201:S::Ready',1);
UNLOCK TABLES;
/*!40000 ALTER TABLE `attr_a1e9e0a1b7943cc041fefb5da65868f9` ENABLE KEYS */;
Conditions:
http://egee.cesnet.cz/en/Schema/JP/System:jobId
- == https://localhost:7846/pokus1
+ origin IS ANY
+ value == https://localhost:7846/pokus1
Attributes:
http://egee.cesnet.cz/en/Schema/JP/System:owner
http://egee.cesnet.cz/en/Schema/JP/System:jobId
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<jpisclient:QueryJobs xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jptype="http://glite.org/wsdl/types/jp" xmlns:jpsrv="http://glite.org/wsdl/services/jp" xmlns:jpelem="http://glite.org/wsdl/elements/jp" xmlns:jpisclient="http://glite.org/xsd/types/jpisclient">
+
+ <conditions>
+ <attr>http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus</attr>
+ <origin>FILE</origin>
+ <record>
+ <op>EQUAL</op>
+ <value>
+ <string>Done</string>
+ </value>
+ </record>
+ </conditions>
+
+ <attributes>http://egee.cesnet.cz/en/Schema/JP/System:owner</attributes>
+ <attributes>http://egee.cesnet.cz/en/Schema/JP/System:jobId</attributes>
+ <attributes>http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus</attributes>
+ <attributes>http://egee.cesnet.cz/en/Schema/LB/Attributes:user</attributes>
+
+</jpisclient:QueryJobs>
--- /dev/null
+query: using JPIS http://localhost:12002
+
+Conditions:
+ http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus
+ origin == FILE
+ value == Done
+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
+
+OK
+<?xml version="1.0" encoding="UTF-8"?><jpisclient:QueryJobsResponse xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jptype="http://glite.org/wsdl/types/jp" xmlns:jpsrv="http://glite.org/wsdl/services/jp" xmlns:jpelem="http://glite.org/wsdl/elements/jp" xmlns:jpisclient="http://glite.org/xsd/types/jpisclient"><jobs><jobid>https://localhost:7846/pokus1</jobid><owner>/O=CESNET/O=Masaryk University/CN=Milos Mulac</owner><attributes><name>http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus</name><value><string>Done</string></value><timestamp>1970-01-01T02:00:01Z</timestamp><origin>FILE</origin></attributes><attributes><name>http://egee.cesnet.cz/en/Schema/LB/Attributes:user</name><value><string>CertSubj</string></value><timestamp>1970-01-01T02:00:01Z</timestamp><origin>FILE</origin></attributes><primaryStorage>http://localhost:8901</primaryStorage></jobs></jpisclient:QueryJobsResponse>
\ No newline at end of file
run_test_query $GLITE_LOCATION/examples/query-tests/jobid_query.in $GLITE_LOCATION/examples/query-tests/jobid_query.out;
drop_db;
kill_is;
+
+echo -n "Origin test........... "
+create_db;
+run_is "-n";
+import_db $GLITE_LOCATION/examples/query-tests/dump1.sql;
+run_test_query $GLITE_LOCATION/examples/query-tests/origin_query.in $GLITE_LOCATION/examples/query-tests/origin_query.out;
+drop_db;
+kill_is;
Conditions:
http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus
- == Ready
+ origin IS ANY
+ value == Ready
Attributes:
http://egee.cesnet.cz/en/Schema/JP/System:owner
http://egee.cesnet.cz/en/Schema/JP/System:jobId
int glite_jpis_init_context(glite_jpis_context_t *isctx, glite_jp_context_t jpctx, glite_jp_is_conf *conf) {
char hname[512];
+ char *op_args;
if ((*isctx = calloc(sizeof(**isctx), 1)) != NULL) {
(*isctx)->jpctx = jpctx;
(*isctx)->conf = conf;
globus_libc_gethostname(hname, sizeof hname);
asprintf(&(*isctx)->hname, "https://%s:%s", hname, (conf && conf->port) ? conf->port : GLITE_JPIS_DEFAULT_PORT_STR);
+
+ op_args = (*isctx)->op_args;
+ op_args[GLITE_JP_QUERYOP_WITHIN] = 2;
+ op_args[GLITE_JP_QUERYOP_UNDEF] = 0;
+ op_args[GLITE_JP_QUERYOP_EQUAL] = 1;
+ op_args[GLITE_JP_QUERYOP_LESS] = 1;
+ op_args[GLITE_JP_QUERYOP_GREATER] = 1;
+ op_args[GLITE_JP_QUERYOP_EXISTS] = 0;
return 0;
} else return ENOMEM;
}
void *param_expires;
char *hname;
+
+ char op_args[GLITE_JP_QUERYOP__LAST];
} *glite_jpis_context_t;
typedef struct _slave_data_t{
}
-static size_t db_arg2_length(glite_jp_query_rec_t *query) {
+static size_t db_arg1_length(glite_jpis_context_t isctx, glite_jp_query_rec_t *query) {
size_t len;
assert(query->op > GLITE_JP_QUERYOP_UNDEF && query->op <= GLITE_JP_QUERYOP__LAST);
- len = 0;
- switch (query->op) {
- case GLITE_JP_QUERYOP_WITHIN:
- len = query->binary ? query->size2 : strlen(query->value2) + 1;
- case GLITE_JP_QUERYOP_UNDEF:
- case GLITE_JP_QUERYOP_EQUAL:
- case GLITE_JP_QUERYOP_UNEQUAL:
- case GLITE_JP_QUERYOP_LESS:
- case GLITE_JP_QUERYOP_GREATER:
- case GLITE_JP_QUERYOP_EXISTS:
- case GLITE_JP_QUERYOP__LAST:
- len = 0;
- }
+ if (isctx->op_args[query->op] >= 1)
+ len = query->binary ? query->size : (query->value ? strlen(query->value) + 1 : 0);
+ else len = 0;
+
+ return len;
+}
+
+static size_t db_arg2_length(glite_jpis_context_t isctx, glite_jp_query_rec_t *query) {
+ size_t len;
+
+ assert(query->op > GLITE_JP_QUERYOP_UNDEF && query->op <= GLITE_JP_QUERYOP__LAST);
+ if (isctx->op_args[query->op] >= 1)
+ len = query->binary ? query->size2 : (query->value2 ? strlen(query->value2) + 1 : 0);
+ else len = 0;
return len;
}
}
-static int glite_jpis_db_queries_serialize(void **blob, size_t *len, glite_jp_query_rec_t **queries) {
+static int glite_jpis_db_queries_serialize(glite_jpis_context_t isctx, void **blob, size_t *len, glite_jp_query_rec_t **queries) {
size_t maxlen;
glite_jp_query_rec_t *query;
int ret;
if ((ret = array_add_long(blob, len, &maxlen, query->op)) != 0) goto fail;
if ((ret = array_add_long(blob, len, &maxlen, query->binary ? 1 : 0)) != 0) goto fail;
- datalen = query->binary ? query->size : strlen(query->value) + 1;
+ datalen = db_arg1_length(isctx, query);
if ((ret = array_add_long(blob, len, &maxlen, datalen)) != 0) goto fail;
if (datalen)
if ((ret = array_add(blob, len, &maxlen, query->value, datalen)) != 0) goto fail;
- datalen = db_arg2_length(query);
+ datalen = db_arg2_length(isctx, query);
if ((ret = array_add_long(blob, len, &maxlen, datalen)) != 0) goto fail;
if (datalen)
if ((ret = array_add(blob, len, &maxlen, query->value2, datalen)) != 0) goto fail;
(feeds[i]->continuous ? GLITE_JP_IS_STATE_CONT : 0);
locked = 0;
GLITE_JPIS_PARAM(source, source_len, feeds[i]->PS_URL);
- assert(glite_jpis_db_queries_serialize(&conds, &conds_len, feeds[i]->query) == 0);
+ assert(glite_jpis_db_queries_serialize(ctx, &conds, &conds_len, feeds[i]->query) == 0);
assert(conds_len <= sizeof(dbconds));
dbconds_len = conds_len;
memcpy(dbconds, conds, conds_len);
int i, j, ret;
glite_jp_db_stmt_t stmt;
glite_jp_attrval_t attr;
+ glite_jp_attr_orig_t orig;
qwhere = strdup("");
for (i=0; i < in->__sizeconditions; i++) {
-/* XXX: deal with jobIds diferently (they are not in attr_X table, but in jobs)
- if (strcmp(in->conditions[i]->attr,GLITE_JP_ATTR_JOBID)) {
- trio_asprintf(&qa,"%s (", (i ? "AND" : "") );
-
- for (j=0; j < in->conditions[i]->__sizerecord; j++) {
- if (get_op(in->conditions[i]->record[j]->op, &qop)) goto err;
-
- attr.name = in->conditions[i]->attr;
- attr.value = in->conditions[i]->record[j]->value->string;
- attr.binary = 0;
- glite_jpis_SoapToAttrOrig(soap,
- in->conditions[i]->origin, &(attr.origin));
- trio_asprintf(&qb,"%s%sjobs.dg_jobid %s \"%|Ss\"",
- qa, (j ? " OR " : ""), attr_md5, qop,
- glite_jp_attrval_to_db_index(ctx->jpctx, &attr, 255));
- free(qop);
- free(qa); qa = qb; qb = NULL;
-
- }
- else
-*/
{
+ /* attr name */
if (strcmp(in->conditions[i]->attr, GLITE_JP_ATTR_JOBID) == 0) {
/* no subset from attr_ table, used jobs table instead */
attr_md5 = NULL;
qa = strdup("(");
} else {
- /* select given records in attr_ table */
attr_md5 = str2md5(in->conditions[i]->attr);
- trio_asprintf(&qa,"%s jobs.jobid = attr_%|Ss.jobid AND (",
- (i ? "AND" : ""), attr_md5);
+
+ /* origin */
+ if (in->conditions[i]->origin) {
+ glite_jpis_SoapToAttrOrig(soap, in->conditions[i]->origin, &orig);
+ trio_asprintf(&qb, "attr_%|Ss.origin = %d AND ", attr_md5, orig);
+ } else
+ trio_asprintf(&qb, "");
+
+ /* select given records in attr_ table */
+ trio_asprintf(&qa,"%s%s jobs.jobid = attr_%|Ss.jobid AND (",
+ (i ? "AND" : ""), qb, attr_md5);
+
+ free(qb);
}
- /* inside part of the condition - ORs */
+ /* inside part of the condition: record list (ORs) */
for (j=0; j < in->conditions[i]->__sizerecord; j++) {
if (get_op(in->conditions[i]->record[j]->op, &qop)) goto err;
if (attr_md5) add_attr_table(attr_md5, &attr_tables);
}
if (ctx->conf->no_auth) {
- trio_asprintf(&query, "SELECT DISTINCT dg_jobid,ps FROM jobs%s WHERE %s;", qa, qwhere);
+ 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);