implementation of RecordMultiTags
authorAleš Křenek <ljocha@ics.muni.cz>
Wed, 4 Jun 2008 20:16:42 +0000 (20:16 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Wed, 4 Jun 2008 20:16:42 +0000 (20:16 +0000)
- test/example -- broken
- not tested at server side
- TODO: extend to feeds
(committing to avoid lost work on unreliable machine)

org.glite.jp.primary/examples/recordmultitags.pl [new file with mode: 0755]
org.glite.jp.primary/src/backend_private.h
org.glite.jp.primary/src/feed.c
org.glite.jp.primary/src/feed.h
org.glite.jp.primary/src/new_ftp_backend.c
org.glite.jp.primary/src/soap_ops.c

diff --git a/org.glite.jp.primary/examples/recordmultitags.pl b/org.glite.jp.primary/examples/recordmultitags.pl
new file mode 100755 (executable)
index 0000000..8a7317f
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+
+use SOAP::Lite;
+use Data::Dumper;
+
+$ENV{HTTPS_CA_DIR}='/etc/grid-security/certificates';
+$ENV{HTTPS_VERSION}='3';
+
+$cred = $ENV{X509_USER_PROXY} ? $ENV{X509_USER_PROXY} : "/tmp/x509up_u$<";
+$ENV{HTTPS_CERT_FILE}= $ENV{HTTPS_KEY_FILE} = $ENV{HTTPS_CA_FILE} = $cred;
+
+$proxy = shift;
+
+die "usage: $0 https://jp.primary.storage.org:8901/jpps https://some.nice.job/id attr=value ...\n\t\thttps://another.nice.job/id attr=value ...\n"
+       unless $ARGV[0];
+
+$c = SOAP::Lite
+       -> proxy($proxy)
+       -> uri('http://glite.org/wsdl/services/jp');
+
+service $c 'http://egee.cesnet.cz/cms/export/sites/egee/en/WSDL/HEAD/JobProvenancePS.wsdl' or die "service: $1\n";
+
+ns $c 'http://glite.org/wsdl/elements/jp';
+
+print "WSDL OK\n";
+
+push @ARGV,'__KONEC__';
+$job = shift;
+while ($_ = shift) {
+       if (! /(.*)=(.*)/) { 
+               push @j,SOAP::Data->name(jobs => \SOAP::Data->value(
+                       SOAP::Data->name(jobid=>$job),
+                       @a
+               ));
+
+               break if $_ eq '__KONEC__';
+
+               $job = $_;
+               @a = ();
+       }
+       else {
+               $name = $1; $value = $2;
+               print "$job: $name = $value\n";
+
+               push @a, SOAP::Data->name(attributes=>\SOAP::Data->value(
+                       SOAP::Data->name(name=>$name),
+                       SOAP::Data->name(value=> SOAP::Data->name(string=>$value))
+               ))
+       }
+}
+
+
+$req = SOAP::Data->value(@j);
+print Dumper($req);
+
+on_fault $c sub { print Dumper($_[1]->fault); $fault = 1; };
+
+$resp = RecordMultiTags $c $req;
+
+print Dumper $resp->body unless $fault;
+
index 67f6e72..39908d9 100644 (file)
@@ -40,6 +40,7 @@ int glite_jppsbe_commit_upload(
        const char *destination
 );
 
+int glite_jppsbe_append_tags(void *fpctx, char *jobid, glite_jp_attrval_t *attr);
 
 /** mark the job as sent to this feed */
 int glite_jppsbe_set_fed(
index 3df25dc..f0d5d2f 100644 (file)
@@ -265,6 +265,16 @@ int glite_jpps_match_attr(
        glite_jp_add_deferred(ctx, match_attr_deferred, ma);
 }
 
+int glite_jpps_match_attr_multi(
+               glite_jp_context_t      ctx,
+               const char      **jobs,
+               const glite_jp_attrval_t        **attrs
+)
+{
+/* TODO */
+       return 0;
+}
+
 static int attr_void_cmp(const void *a, const void *b)
 {
        char const * const *ca = (char const * const *) a;
index 57b3361..597f652 100644 (file)
@@ -29,6 +29,7 @@ struct jpfeed {
 
 int glite_jpps_match_attr(glite_jp_context_t,const char *,const glite_jp_attrval_t[]);
 int glite_jpps_match_file(glite_jp_context_t,const char *,const char *,const char *);
+int glite_jpps_match_attr_multi(glite_jp_context_t,const char **, const glite_jp_attrval_t **);
 int glite_jpps_match_tag(glite_jp_context_t,const char *,const char *,const char *);
 int glite_jpps_run_feed(glite_jp_context_t,const char *,char const * const *,const glite_jp_query_rec_t *,int,char **);
 int glite_jpps_register_feed(glite_jp_context_t,const char *,char const * const *,const glite_jp_query_rec_t *,char **,time_t *);
index 4c33dea..d8b1d02 100644 (file)
@@ -2002,7 +2002,7 @@ cleanup:
        return err.code;
 }
 
-int glite_jppsbe_append_tag(
+int glite_jppsbe_append_tags(
        void *fpctx,
        char *jobid,
        glite_jp_attrval_t *attr
@@ -2011,6 +2011,8 @@ int glite_jppsbe_append_tag(
        void                    *file_be;
        glite_jp_error_t        err;
         glite_jp_context_t      ctx = fpctx;
+       int                     i;
+
        memset(&err,0,sizeof err);
         err.source = __FUNCTION__;
 
@@ -2023,12 +2025,20 @@ int glite_jppsbe_append_tag(
                return glite_jp_stack_error(ctx,&err);
         }
 
-       if (tag_append(ctx,file_be,attr))
-        {
-               err.code = EIO;
-                err.desc = "cannot append tag";
-                return glite_jp_stack_error(ctx,&err);
-        }
+       for (i=0; attr[i].name; i++) {
+               if (tag_append(ctx,file_be,attr+i))
+               {
+                       glite_jp_error_t        *e = ctx->error;
+                       err.code = EIO;
+                               err.desc = "cannot append tag";
+
+                       glite_jppsbe_close_file(ctx,file_be);
+                       glite_jp_clear_error(ctx);
+                       ctx->error = e;
+
+                               return glite_jp_stack_error(ctx,&err);
+               }
+       }
 
        if (glite_jppsbe_close_file(ctx,file_be))
        {
index b67788c..359f9a4 100644 (file)
@@ -241,7 +241,7 @@ SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__RecordTag(
                err2fault(ctx,soap);
                return SOAP_FAULT;
        }*/
-       glite_jppsbe_append_tag(ctx,in->jobid,attr);
+       glite_jppsbe_append_tags(ctx,in->jobid,attr);
 
         /*if (tag_append(ctx,file_be,attr))
        {
@@ -259,6 +259,82 @@ err:
        return SOAP_FAULT;
 }
 
+
+
+SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__RecordMultiTags(
+       struct soap *soap,
+       struct _jpelem__RecordMultiTags *in,
+       struct _jpelem__RecordMultiTagsResponse *out
+)
+{
+       CONTEXT_FROM_SOAP(soap,ctx);
+       int     i,j,ret = SOAP_OK;
+       char    **jobs = NULL;
+       glite_jp_attrval_t      **attrs = NULL,meta[2];
+
+       memset(meta,0,sizeof meta);
+        meta[0].name = strdup(GLITE_JP_ATTR_OWNER);
+
+printf(__FUNCTION__);
+       for (i=0; i<in->__sizejobs; i++) {
+               struct jptype__jobRecord *jr = GLITE_SECURITY_GSOAP_LIST_GET(in->jobs,i);
+
+printf("jobid: %s\n",jr->jobid);
+
+               if (glite_jppsbe_get_job_metadata(ctx,jr->jobid,meta)) {
+                       ret = SOAP_FAULT;
+                       goto cleanup;
+               }
+
+/* XXX: the same as single tag */
+               if (glite_jpps_authz(ctx,SOAP_TYPE___jpsrv__RecordTag,jr->jobid,meta[0].value)) {
+                       ret = SOAP_FAULT;
+                       goto cleanup;
+               }
+
+               jobs = realloc(jobs,sizeof(*jobs) * (i+2));
+               jobs[i] = jr->jobid;
+               jobs[i+1] = NULL;
+
+               attrs = realloc(attrs,sizeof(*attrs) * (i+2));
+               attrs[i+1] = attrs[i] = NULL;
+
+               for (j=0; j < jr->__sizeattributes; j++) {
+                       struct jptype__attrValue        *a = GLITE_SECURITY_GSOAP_LIST_GET(jr->attributes,j);
+
+                       attrs[i][j].name = a->name;
+                       if (GSOAP_ISSTRING(a->value)) {
+                               attrs[i][j].value = GSOAP_STRING(a->value);
+                               attrs[i][j].binary = 0;
+                       }
+                       else {
+                               attrs[i][j].value = GSOAP_BLOB(a->value)->__ptr;
+                               attrs[i][j].size = GSOAP_BLOB(a->value)->__size;
+                               attrs[i][j].binary = 1;
+                       }
+               /* XXX input not favoured */
+                       attrs[i][j].origin = GLITE_JP_ATTR_ORIG_USER;
+                       attrs[i][j].timestamp = time(NULL);
+                       attrs[i][j].origin_detail = NULL;
+               }
+       }
+
+/* XXX: ignore error */
+       glite_jpps_match_attr_multi(ctx,(const char **) jobs,(const glite_jp_attrval_t **) attrs);
+
+cleanup:
+       for (i=0; attrs[i]; i++) {
+               for (j=0; attrs[i][j].name; j++) glite_jp_attrval_free(&attrs[i][j],0);
+               free(attrs[i]);
+       }
+       free(attrs);
+       free(jobs);
+
+       glite_jp_attrval_free(meta,0);
+       err2fault(ctx,soap);
+       return ret;
+}
+
 static void s2jp_qval(const struct jptype__stringOrBlob *in, char **value, int *binary, size_t *size)
 {
        if (GSOAP_ISSTRING(in)) {