calls to JPIS -- untested
authorAleš Křenek <ljocha@ics.muni.cz>
Mon, 3 Oct 2005 17:43:02 +0000 (17:43 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Mon, 3 Oct 2005 17:43:02 +0000 (17:43 +0000)
org.glite.jp.primary/Makefile
org.glite.jp.primary/src/attrs.h
org.glite.jp.primary/src/bones_server.c
org.glite.jp.primary/src/is_client.c
org.glite.jp.primary/src/is_client.h
org.glite.jp.primary/src/new_ftp_backend.c
org.glite.jp.primary/src/soap_ops.c
org.glite.jp.primary/src/soap_util.c [new file with mode: 0644]

index 7a2fb0f..5a918a4 100644 (file)
@@ -93,15 +93,17 @@ ${daemon}: ${OBJS}
 ${example}: ${EXA_OBJS}
        ${LINK} -o $@ ${EXA_OBJS} ${GSOAPLIB} ${GLOBUS_LIBS}
 
-# XXX: piss off
-JobProvenanceIS.xh:
-       touch $@
-
 JobProvenancePS.xh: %.xh: %.wsdl JobProvenanceTypes.wsdl typemap.dat
        cp  ${stagedir}/interface/JobProvenanceTypes.wsdl .
        ${gsoap_prefix}/bin/wsdl2h  -t ${top_srcdir}/src/typemap.dat -c -o $@ $<
        rm -f JobProvenanceTypes.wsdl
 
+JobProvenanceIS.xh: %.xh: %.wsdl JobProvenanceTypes.wsdl typemap.dat
+       cp  ${stagedir}/interface/JobProvenanceTypes.wsdl .
+       ${gsoap_prefix}/bin/wsdl2h  -t ${top_srcdir}/src/typemap.dat -c -o $@ $<
+       rm -f JobProvenanceTypes.wsdl
+
+
 ${ps_prefix}Client.c ${ps_prefix}ClientLib.c  \
 ${ps_prefix}Server.c ${ps_prefix}ServerLib.c  \
 ${ps_prefix}C.c ${ps_prefix}H.h: JobProvenancePS.xh
@@ -111,6 +113,10 @@ ${is_prefix}ClientLib.c ${is_prefix}Client.c \
 ${is_prefix}C.c ${is_prefix}H.h: JobProvenanceIS.xh
        ${gsoap_prefix}/bin/soapcpp2 -n -w -c -p ${is_prefix} JobProvenanceIS.xh
 
+soap_ops.o: ${ps_prefix}ServerLib.c soap_util.c
+
+is_client.o: ${is_prefix}ClientLib.c soap_util.c
+
 env_C.c env_Server.c:
        touch env.xh
        ${gsoap_prefix}/bin/soapcpp2 -w -c -p env_ env.xh
index 5ea6dfd..1f4e311 100644 (file)
@@ -1 +1 @@
-int glite_jpps_get_attrs(glite_jp_context_t,const char *,char const *const *,int,glite_jp_attrval_t **);
+int glite_jpps_get_attrs(glite_jp_context_t,const char *,char **,int,glite_jp_attrval_t **);
index 5ddcd32..fec27ef 100644 (file)
@@ -45,7 +45,7 @@ static glite_jp_context_t     ctx;
 
 static int call_opts(glite_jp_context_t,char *,char *,int (*)(glite_jp_context_t,int,char **));
 
-char *glite_jp_default_namespace;
+const char *glite_jp_default_namespace;
 
 pid_t  master;
 
@@ -56,8 +56,12 @@ int main(int argc, char *argv[])
        struct sockaddr_in      a;
        char    *b_argv[20] = { "backend" },*p_argv[20] = { "plugins" },*com;
        int     b_argc,p_argc;
+       char    buf[1000];
 
        glite_jp_init_context(&ctx);
+       globus_libc_gethostname(buf,sizeof buf);
+       buf[999] = 0;
+       ctx->myURL = buf;
 
        b_argc = p_argc = 1;
 
@@ -176,6 +180,7 @@ static int data_init(void **data)
 static int newconn(int conn,struct timeval *to,void *data)
 {
        struct soap     *soap = (struct soap *) data;
+       glite_jp_context_t      ctx = soap->user;
        glite_gsplugin_Context  plugin_ctx;
 
        gss_cred_id_t           newcred = GSS_C_NO_CREDENTIAL;
@@ -191,13 +196,6 @@ static int newconn(int conn,struct timeval *to,void *data)
        soap_set_namespaces(soap,jpps__namespaces);
        soap->user = (void *) ctx; /* XXX: one instance per slave */
 
-/* not yet: client to JP index
-       ctx->other_soap = soap_new();
-       soap_init(ctx->other_soap);
-       soap_set_namespaces(ctx->other_soap,jpis__namespaces);
-*/
-
-
        glite_gsplugin_init_context(&plugin_ctx);
        plugin_ctx->connection = calloc(1,sizeof *plugin_ctx->connection);
 
@@ -311,7 +309,14 @@ static int reject(int conn)
 static int disconn(int conn,struct timeval *to,void *data)
 {
        struct soap     *soap = (struct soap *) data;
+       glite_jp_context_t      ctx = soap->user;
+
        soap_end(soap); // clean up everything and close socket
+       if (ctx->other_soap) {
+               soap_end(ctx->other_soap);
+               soap_free(ctx->other_soap);
+               ctx->other_soap = NULL;
+       }
 
        return 0;
 }
index c01561d..34d4aaf 100644 (file)
 #include <assert.h>
 
 #include "glite/jp/types.h"
+#include "glite/security/glite_gsplugin.h"
 
 #include "feed.h"
 #include "is_client.h"
-/* FIXME
-#include "jpis_H.h"
+
+#include "jpis_ClientLib.c"
 #include "jpis_.nsmap"
-*/
+
+#include "soap_util.c"
+
+static int check_other_soap(glite_jp_context_t ctx)
+{
+       if (!ctx->other_soap) {
+               ctx->other_soap = soap_new();
+               soap_init(ctx->other_soap);
+               soap_set_namespaces(ctx->other_soap,jpis__namespaces);
+               soap_register_plugin(ctx->other_soap,glite_gsplugin);
+               ctx->other_soap->user = ctx;
+       }
+       return 0;
+}
 
 int glite_jpps_single_feed(
                glite_jp_context_t ctx,
+               const char *feed,
+               int     done,
                const char *destination,
                const char *job,
                glite_jp_attrval_t const *attrs
 )
 {
-       /* TODO: really call JP Index server (via interlogger) */
+       struct _jpelem__UpdateJobs      in;
+       struct _jpelem__UpdateJobsResponse      out;
+       struct jptype__jobRecord        jr, *jrp = &jr;
+       int     i;
+       enum xsd__boolean       false = false_;
+       glite_jp_error_t        err;
+
+       glite_jp_clear_error(ctx);
+       memset(&err,0,sizeof err);
+
+       /* TODO: call JP Index server via interlogger */
+
        printf("feed to %s, job %s\n",destination,job);
 
-/* FIXME */
-#if 0
-       if (soap_call_jpsrv__UpdateJobs(ctx->other_soap,destination,"",
-               /* FIXME: feedId */ "",
-               /* FIXME: UpdateJobsData */ NULL,
-               0,
-               NULL
-       )) fprintf(stderr,"UpdateJobs: %s %s\n",ctx->other_soap->fault->faultcode,
-               ctx->other_soap->fault->faultstring);
-
-#endif
-       return 0;
+       check_other_soap(ctx);
+
+       in.feedId = (char *) feed; /* XXX: const */
+       in.feedDone = done;
+       in.__sizejobAttributes = 1;
+       in.jobAttributes = &jrp;
+
+       for (i=0; attrs[i].name; i++);
+       jr.jobid = (char *) job; /* XXX: const */
+
+       jr.__sizeattributes = jp2s_attrValues(ctx->other_soap,
+                       (glite_jp_attrval_t *) attrs, /* XXX: const */
+                       &jr.attributes,0);
+
+       jr.remove = &false;
+       jr.__sizeprimaryStorage = 1;
+       jr.primaryStorage = &ctx->myURL;
+
+
+       if (soap_call___jpsrv__UpdateJobs(ctx->other_soap,destination,"",
+               &in,&out
+       )) {
+               char    buf[1000];
+               err.code = EIO;
+               err.source = __FUNCTION__;
+               err.desc = buf;
+               snprintf(buf,sizeof buf,"%s %s\n",
+                               ctx->other_soap->fault->faultcode,
+                               ctx->other_soap->fault->faultstring);
+               buf[999] = 0;
+               glite_jp_stack_error(ctx,&err);
+       }
+
+       attrValues_free(ctx->other_soap,jr.attributes,jr.__sizeattributes);
+
+       return err.code;
 }
 
 int glite_jpps_multi_feed(
                glite_jp_context_t ctx,
+               const char *feed,
+               int     done,
                int njobs,
-               const char *dest,
+               const char *destination,
                char **jobs,
                glite_jp_attrval_t **attrs)
 {
        int     i,j;
 
-       printf("multi_feed: %s\n",dest);
+       struct _jpelem__UpdateJobs      in;
+       struct _jpelem__UpdateJobsResponse      out;
+       struct jptype__jobRecord        *jr;
+       enum xsd__boolean       false = false_;
+       glite_jp_error_t        err;
+
+       printf("multi_feed: %s\n",destination);
+
+       glite_jp_clear_error(ctx);
+       memset(&err,0,sizeof err);
+
+       check_other_soap(ctx);
+
+       in.feedId = (char *) feed; /* XXX: const */
+       in.feedDone = done;
+       in.__sizejobAttributes = njobs;
+       in.jobAttributes = malloc(njobs * sizeof *in.jobAttributes);
+
        for (i=0; i<njobs; i++) {
                puts(jobs[i]);
                for (j=0; attrs[i][j].name; j++)
                        printf("%s = %s\n",attrs[i][j].name,attrs[i][j].value);
                putchar(10);
+
+               in.jobAttributes[i] = jr = malloc(sizeof *jr);
+               jr->jobid = jobs[i];
+
+               jr->__sizeattributes = jp2s_attrValues(ctx->other_soap,
+                       attrs[i],
+                       &jr->attributes,0);
+
+               jr->remove = &false;
+               jr->__sizeprimaryStorage = 1;
+               jr->primaryStorage = &ctx->myURL;
        }
-       return 0;
+
+       if (soap_call___jpsrv__UpdateJobs(ctx->other_soap,destination,"",
+               &in,&out
+       )) {
+               char    buf[1000];
+               err.code = EIO;
+               err.source = __FUNCTION__;
+               err.desc = buf;
+               snprintf(buf,sizeof buf,"%s %s\n",
+                               ctx->other_soap->fault->faultcode,
+                               ctx->other_soap->fault->faultstring);
+               buf[999] = 0;
+               glite_jp_stack_error(ctx,&err);
+       }
+
+       for (i=0; i<njobs; i++) {
+               jr = in.jobAttributes[i];
+               attrValues_free(ctx->other_soap,jr->attributes,jr->__sizeattributes);
+               free(jr);
+       }
+       free(in.jobAttributes);
+
+       return err.code;
 }
 
index d99274b..665efc0 100644 (file)
@@ -1,4 +1,4 @@
-int glite_jpps_single_feed(glite_jp_context_t,const char *,const char *,glite_jp_attrval_t const *);
-int glite_jpps_multi_feed(glite_jp_context_t,int, const char *,char **,glite_jp_attrval_t **);
+int glite_jpps_single_feed(glite_jp_context_t,const char *,int,const char *,const char *,glite_jp_attrval_t const *);
+int glite_jpps_multi_feed(glite_jp_context_t,const char *,int,int,const char *,char **,glite_jp_attrval_t **);
 
 
index ff6d315..407b7e2 100644 (file)
@@ -2004,7 +2004,7 @@ cleanup:
                return -ctx->error->code;
        }
 
-       *names_out = out;
+       if (nout) *names_out = out;
        return nout;
 }
 
index 909b27f..fbdeef9 100644 (file)
@@ -18,6 +18,8 @@
 #include "jpps_ServerLib.c"
 #include "jpps_.nsmap"
 
+#include "soap_util.c"
+
 static struct jptype__genericFault *jp2s_error(struct soap *soap,
                const glite_jp_error_t *err)
 {
@@ -414,16 +416,6 @@ SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__GetJobFiles(
        return SOAP_OK;
 }
 
-static enum jptype__attrOrig jp2s_origin(glite_jp_attr_orig_t o)
-{
-       switch (o) {
-               case GLITE_JP_ATTR_ORIG_SYSTEM: return jptype__attrOrig__SYSTEM;
-               case GLITE_JP_ATTR_ORIG_USER: return jptype__attrOrig__USER;
-               case GLITE_JP_ATTR_ORIG_FILE: return jptype__attrOrig__FILE_;
-               default: abort(); /* XXX */
-       }
-}
-
 SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__GetJobAttributes(
                struct soap *soap,
                struct _jpelem__GetJobAttributes *in,
@@ -434,43 +426,15 @@ SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__GetJobAttributes(
 
        CONTEXT_FROM_SOAP(soap,ctx);
 
-
-
-       if (glite_jpps_get_attrs(ctx,in->jobid,in->attributes,in->__sizeattributes,&attr)) {
+       if (glite_jpps_get_attrs(ctx,in->jobid,
+                       in->attributes,
+                       in->__sizeattributes,&attr)) {
                err2fault(ctx,soap);
                return SOAP_FAULT;
        }
 
        for (i=0; attr[i].name; i++);
-       out->__sizeattrValues = n = i;
-
-       out->attrValues = soap_malloc(soap,n * sizeof *out->attrValues);
-       for (i=0; attr[i].name; i++) {
-               struct jptype__attrValue        *a = soap_malloc(soap,sizeof *a);
-               out->attrValues[i] = a;
-
-               a->name = soap_strdup(soap,attr[i].name); free(attr[i].name);
-               a->value = soap_malloc(soap,sizeof *a->value);
-               if (attr[i].binary) {
-                       a->value->blob = soap_malloc(soap,sizeof *a->value->blob);
-                       memset(a->value->blob,0,sizeof *a->value->blob);
-                       a->value->blob->__ptr = soap_malloc(soap,attr[i].size);
-                       a->value->blob->__size = attr[i].size;
-                       memcpy(a->value->blob->__ptr,attr[i].value,attr[i].size);
-
-                       a->value->string = NULL;
-               }
-               else {
-                       a->value->string = soap_strdup(soap,attr[i].value);
-                       a->value->blob = NULL;
-               }
-               free(attr[i].value);
-               a->origin = jp2s_origin(attr[i].origin);
-               a->originDetail = attr[i].origin_detail ? soap_strdup(soap,attr[i].origin_detail) : NULL;
-               free(attr[i].origin_detail);
-               a->timestamp = attr[i].timestamp;
-       }
-       free(attr);
+       out->__sizeattrValues = jp2s_attrValues(soap,attr,&out->attrValues,1);
 
        return SOAP_OK;
 }
diff --git a/org.glite.jp.primary/src/soap_util.c b/org.glite.jp.primary/src/soap_util.c
new file mode 100644 (file)
index 0000000..eebbd1a
--- /dev/null
@@ -0,0 +1,74 @@
+static enum jptype__attrOrig jp2s_origin(glite_jp_attr_orig_t o)
+{
+       switch (o) {
+               case GLITE_JP_ATTR_ORIG_SYSTEM: return jptype__attrOrig__SYSTEM;
+               case GLITE_JP_ATTR_ORIG_USER: return jptype__attrOrig__USER;
+               case GLITE_JP_ATTR_ORIG_FILE: return jptype__attrOrig__FILE_;
+               default: abort(); /* XXX */
+       }
+}
+
+static int jp2s_attrValues(
+       struct soap *soap,
+       glite_jp_attrval_t *in,
+       struct jptype__attrValue ***outp,
+       int freeit)
+{
+       struct jptype__attrValue **out;
+       int     i,cnt;
+
+       for (cnt=0; in[cnt].name; cnt++);
+              
+       out = soap_malloc(soap,cnt * sizeof *out);
+       for (i=0; in[i].name; i++) {
+               struct jptype__attrValue        *a = soap_malloc(soap,sizeof *a);
+               out[i] = a;
+
+               a->name = soap_strdup(soap,in[i].name); 
+               if (freeit) free(in[i].name);
+               a->value = soap_malloc(soap,sizeof *a->value);
+               if (in[i].binary) {
+                       a->value->blob = soap_malloc(soap,sizeof *a->value->blob);
+                       memset(a->value->blob,0,sizeof *a->value->blob);
+                       a->value->blob->__ptr = soap_malloc(soap,in[i].size);
+                       a->value->blob->__size = in[i].size;
+                       memcpy(a->value->blob->__ptr,in[i].value,in[i].size);
+
+                       a->value->string = NULL;
+               }
+               else {
+                       a->value->string = soap_strdup(soap,in[i].value);
+                       a->value->blob = NULL;
+               }
+               if (freeit) free(in[i].value);
+               a->origin = jp2s_origin(in[i].origin);
+               a->originDetail = in[i].origin_detail ? soap_strdup(soap,in[i].origin_detail) : NULL;
+               if (freeit) free(in[i].origin_detail);
+               a->timestamp = in[i].timestamp;
+       }
+       if (freeit) free(in);
+
+       *outp = out;
+       return cnt;
+}
+
+static void attrValues_free(
+       struct soap *soap,
+       struct jptype__attrValue **a,
+       int     na)
+{
+       int     i;
+
+       for (i=0; i<na; i++) {
+               soap_dealloc(soap,a[i]->name);
+               if (a[i]->value->string) soap_dealloc(soap,a[i]->value->string);
+               if (a[i]->value->blob) {
+                       soap_dealloc(soap,a[i]->value->blob->__ptr);
+                       soap_dealloc(soap,a[i]->value->blob);
+               }
+               soap_dealloc(soap,a[i]->value);
+               if (a[i]->originDetail) soap_dealloc(soap,a[i]->originDetail);
+               soap_dealloc(soap,a[i]);
+       }
+       soap_dealloc(soap,a);
+}