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
+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
MANS1:=glite-jpis-client.1
MANS8:=glite-jp-indexd.8
http://egee.cesnet.cz/en/Schema/LB/Attributes:user
OK
-<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>
+Result 0 jobs:
http://egee.cesnet.cz/en/Schema/LB/Attributes:user
OK
-<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><jobs><jobid>https://localhost:7846/pokus2</jobid><owner>OwnerName</owner><attributes><name>http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus</name><value><string>Ready</string></value><timestamp>1970-01-01T02:00:01Z</timestamp><origin>SYSTEM</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>SYSTEM</origin></attributes><primaryStorage>http://localhost:8901</primaryStorage></jobs></jpisclient:QueryJobsResponse>
+Result 2 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
+ jobid = https://localhost:7846/pokus2, owner = OwnerName
+ http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus
+ value = Ready
+ origin = SYSTEM (no detail)
+ time = Thu Jan 1 02:00:01 1970
+ http://egee.cesnet.cz/en/Schema/LB/Attributes:user
+ value = CertSubj
+ origin = SYSTEM (no detail)
+ time = Thu Jan 1 02:00:01 1970
/*!40000 ALTER TABLE `attr_c47f78255056386d2b3da6d506d1f244` DISABLE KEYS */;
LOCK TABLES `attr_c47f78255056386d2b3da6d506d1f244` WRITE;
+INSERT INTO `attr_c47f78255056386d2b3da6d506d1f244` VALUES ('593e62a063231f8c623b74406b3e12b0','VOCE','S:7201:F::VOCE',3);
UNLOCK TABLES;
/*!40000 ALTER TABLE `attr_c47f78255056386d2b3da6d506d1f244` ENABLE KEYS */;
--- /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:CE</attr>
+ <record>
+ <op>EXISTS</op>
+ </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>
+ <attributes>http://egee.cesnet.cz/en/Schema/LB/Attributes:CE</attributes>
+
+</jpisclient:QueryJobs>
--- /dev/null
+query: using JPIS http://localhost:10000
+
+Conditions:
+ http://egee.cesnet.cz/en/Schema/LB/Attributes:CE
+ origin IS ANY
+ value exists
+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
-query: using JPIS http://localhost:12002
+query: using JPIS http://localhost:10000
Conditions:
http://egee.cesnet.cz/en/Schema/JP/System:jobId
http://egee.cesnet.cz/en/Schema/LB/Attributes:user
OK
-<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>
+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
-query: using JPIS http://localhost:12002
+query: using JPIS http://localhost:10000
Conditions:
http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus
http://egee.cesnet.cz/en/Schema/LB/Attributes:user
OK
-<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>
+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
import_db() {
# import database
+ echo -n "D"
+ # delay (if JP IS downloads something...)
+ sleep 1
cat $1 | sed "s/jpis1test/$DB_NAME/" | mysql -u $DB_USER -h $DB_HOST
if [ x"$?" != x"0" ]; then
echo "FAILED to import database."
drop_db;
exit 1
fi
+ echo -n "B "
}
drop_db() {
exit 1
fi
+ echo -n "I"
# run index server
X509_USER_KEY=${X509_USER_KEY} X509_USER_CERT=${X509_USER_CERT} \
$GLITE_LOCATION/bin/glite-jp-indexd -m $GLITE_JPIS_TEST_DB -p $GLITE_JPIS_TEST_PORT \
i=$(($i+1))
LC_ALL=C sleep 0.1
done
+ echo -n "S "
}
kill_is() {
}
run_test_query() {
+ echo -n "Q"
X509_USER_KEY=${X509_USER_KEY} X509_USER_CERT=${X509_USER_CERT} \
- $GLITE_LOCATION/examples/glite-jpis-client -f strippedxml -q $1 \
- -i http://localhost:$GLITE_JPIS_TEST_PORT 2>&1 | sed -e 's,<?xml version="1.0" encoding="UTF-8"?>,,' -e 's, SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/",,' > /tmp/result
+ $GLITE_LOCATION/examples/glite-jpis-client -f hr -q $1 \
+ -i http://localhost:$GLITE_JPIS_TEST_PORT > /tmp/result 2>&1
+ echo -n "R "
DIFF=`diff -b -B --ignore-matching-lines="query: using JPIS" $2 /tmp/result`
if [ -z "$DIFF" -a "$?" -eq "0" ] ; then
echo "OK."
run_test_query $GLITE_LOCATION/examples/query-tests/origin_query.in $GLITE_LOCATION/examples/query-tests/origin_query.out;
drop_db;
kill_is;
+
+echo -n "EXISTS operation 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;
http://egee.cesnet.cz/en/Schema/LB/Attributes:user
OK
-<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/pokus2</jobid><owner>OwnerName</owner><attributes><name>http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus</name><value><string>Ready</string></value><timestamp>1970-01-01T02:00:01Z</timestamp><origin>SYSTEM</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>SYSTEM</origin></attributes><primaryStorage>http://localhost:8901</primaryStorage></jobs></jpisclient:QueryJobsResponse>
+Result 1 jobs:
+ jobid = https://localhost:7846/pokus2, owner = OwnerName
+ http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus
+ value = Ready
+ origin = SYSTEM (no detail)
+ time = Thu Jan 1 02:00:01 1970
+ http://egee.cesnet.cz/en/Schema/LB/Attributes:user
+ value = CertSubj
+ origin = SYSTEM (no detail)
+ time = Thu Jan 1 02:00:01 1970
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;
+ if ((glite_jp_db_execstmt(jpctx, sql, NULL)) == -1) {
+ glite_jp_error_t err;
+
+ memset(&err,0,sizeof err);
+ err.code = EAGAIN;
+ err.source = __FUNCTION__;
+ err.desc = "If the atribute table already exists, restart may help.";
+ glite_jp_stack_error(ctx, &err);
+ goto fail;
+ }
i++;
}
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;
+ int j;
+
+ sql = strdup("");
+ for (j=0; j < condition->__sizerecord; j++) {
+ record = GLITE_SECURITY_GSOAP_LIST_GET(condition->record, j);
+ 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);
+ } 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));
+ }
+ free(qop);
+ free(sql); sql = s;
+ }
+ }
+
+ return sql;
+}
+
+
/* get all jobids matching the query conditions */
static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpelem__QueryJobs *in, char ***jobids, char *** ps_list)
{
- char *qa = NULL, *qb = NULL, *qop = NULL, *attr_md5,
+ char *qa = NULL, *qb = NULL, *qor, *attr_md5,
*qwhere = NULL, *query = NULL, *res[2],
**jids = NULL, **pss = NULL, **attr_tables = NULL;
- int i, j, ret;
+ int i, ret;
glite_jp_db_stmt_t stmt;
- glite_jp_attrval_t attr;
glite_jp_attr_orig_t orig;
if (strcmp(condition->attr, GLITE_JP_ATTR_JOBID) == 0) {
/* no subset from attr_ table, used jobs table instead */
attr_md5 = NULL;
- qa = strdup("(");
+ qa = strdup("");
} else {
attr_md5 = str2md5(condition->attr);
+ add_attr_table(attr_md5, &attr_tables);
/* origin */
if (condition->origin) {
trio_asprintf(&qb, "");
/* select given records in attr_ table */
- trio_asprintf(&qa,"%s%s jobs.jobid = attr_%|Ss.jobid AND (",
+ trio_asprintf(&qa,"%s%s jobs.jobid = attr_%|Ss.jobid",
(i ? "AND" : ""), qb, attr_md5);
free(qb);
}
/* inside part of the condition: record list (ORs) */
- for (j=0; j < condition->__sizerecord; j++) {
- struct jptype__indexQueryRecord *record;
-
- record = GLITE_SECURITY_GSOAP_LIST_GET(condition->record, j);
- if (get_op(record->op, &qop)) goto err;
- if (attr_md5) add_attr_table(attr_md5, &attr_tables);
-
- 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(&qb,"%s%sjobs.dg_jobid %s \"%|Ss\"",
- qa, (j ? " OR " : ""), qop, attr.value);
- } else {
- trio_asprintf(&qb,"%s%sattr_%|Ss.value %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;
+ if ((qor = get_sql_or(soap, ctx, condition, attr_md5)) == NULL) goto err;
+ if (qor[0]) {
+ asprintf(&qb, "%s%s(%s)", qa, qa[0] ? " AND " : "", qor);
+ free(qa);
+ qa = qb;
}
- trio_asprintf(&qb,"%s %s)", qwhere, qa);
+ free(qor);
+
+ trio_asprintf(&qb,"%s %s", qwhere, qa);
free(qa); qwhere = qb; qb = NULL; qa = NULL;
free(attr_md5);
}
}
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);