client side for WS QueryEvents
authorMiloš Mulač <mulac@civ.zcu.cz>
Wed, 29 Jun 2005 09:50:08 +0000 (09:50 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Wed, 29 Jun 2005 09:50:08 +0000 (09:50 +0000)
 -added some queryRecToSoap functions and soapToEvents stubs
 -for sharing - compiles, but not tested

org.glite.lb.server/Makefile
org.glite.lb.server/examples/ws_joblog.c [new file with mode: 0644]
org.glite.lb.server/src/ws_typeref.c.T
org.glite.lb.server/src/ws_typeref.h

index 6483807..47c7e53 100644 (file)
@@ -222,7 +222,7 @@ test_soap_conv: test_soap_conv.cpp ${WS_CLIENT_OBJS}
        ${CXX} -c ${CFLAGS} ${TEST_INC} $<
        ${LINKXX} -o $@ test_soap_conv.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} ${TEST_LIBS}
 
-examples: ws_getversion ws_jobstat ws_query_ex
+examples: ws_getversion ws_jobstat ws_query_ex ws_joblog
 
 ws_getversion: ws_getversion.o ${WS_CLIENT_OBJS}
        ${LINK} -o $@ ws_getversion.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} 
@@ -236,6 +236,9 @@ ws_query_ex: ws_query_ex.o ${WS_CLIENT_OBJS}
 ws_query_ext: ws_query_ext.o ${WS_CLIENT_OBJS}
        ${LINK} -o $@ ws_query_ext.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS}
 
+ws_joblog: ws_joblog.o ${WS_CLIENT_OBJS}
+       ${LINK} -o $@ ws_joblog.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS}
+
 
 ${STATIC_LIB_BK}: ${LIB_OBJS_BK}
        ar crv $@ ${LIB_OBJS_BK}
diff --git a/org.glite.lb.server/examples/ws_joblog.c b/org.glite.lb.server/examples/ws_joblog.c
new file mode 100644 (file)
index 0000000..2440a11
--- /dev/null
@@ -0,0 +1,152 @@
+#include <getopt.h>
+#include <stdsoap2.h>
+
+#include "glite/security/glite_gsplugin.h"
+#include "glite/lb/consumer.h"
+#include "glite/lb/events_parse.h"
+
+#include "bk_ws_H.h"
+#include "ws_typeref.h"
+#include "ws_fault.h"
+
+#include "soap_version.h"
+
+#if GSOAP_VERSION <= 20602
+#define soap_call___lb__QueryEvents soap_call___ns1__QueryEvents
+#endif
+
+#include "LoggingAndBookkeeping.nsmap"
+
+static struct option opts[] = {
+       {"help",        0,      NULL,   'h'},
+       {"server",      1,      NULL,   'm'},
+       {"jobid",       1,      NULL,   'j'}
+};
+
+static void usage(char *me)
+{
+       fprintf(stderr,"usage: %s [option]\n"
+               "\t-h, --help      Shows this screen.\n"
+               "\t-m, --server    BK server address:port.\n"
+               "\t-j, --jobid     ID of requested job.\n"
+               , me);
+}
+
+static void free_events(edg_wll_Event *events);
+
+int main(int argc,char** argv)
+{
+       edg_wll_Context                         ctx;
+       glite_gsplugin_Context                  gsplugin_ctx;
+       struct soap                             *mydlo = soap_new();
+       struct _lbe__QueryEventsResponse        out;
+       struct _lbe__QueryEvents                in;     
+       edg_wll_QueryRec                        j[2], e[1];
+       int                                     opt, err;
+       edg_wlc_JobId                           job;
+       char                                    *server = "http://localhost:9003/",
+                                               *jobid = NULL,
+                                               *name = NULL;
+
+
+       name = strrchr(argv[0],'/');
+       if (name) name++; else name = argv[0];
+
+       while ((opt = getopt_long(argc, argv, "hm:j:", opts, NULL)) != EOF) switch (opt)
+       {
+       case 'h': usage(name); return 0;
+       case 'm': server = strdup(optarg); break;
+       case 'j': jobid = strdup(optarg); break;
+       case '?': usage(name); return 1;
+       }
+
+       if ( !jobid )
+       {
+               printf("jobid should be given\n");
+               usage(name);
+               return 1;
+       }
+       else if (edg_wlc_JobIdParse(jobid,&job)) {
+                fprintf(stderr,"%s: can't parse job ID\n",argv[1]);
+                return 1;
+        }
+
+               
+       edg_wll_InitContext(&ctx);
+       glite_gsplugin_init_context(&gsplugin_ctx);
+
+       if ( soap_register_plugin_arg(mydlo, glite_gsplugin, (void *)gsplugin_ctx) )
+       {
+               soap_print_fault(mydlo, stderr);
+               return 1;
+       }
+
+       glite_gsplugin_set_udata(mydlo, ctx);
+
+
+       /* prepare job log quary */
+       memset(j,0,sizeof j);
+       memset(e,0,sizeof e);
+
+       j[0].attr = EDG_WLL_QUERY_ATTR_JOBID;
+       j[0].op = EDG_WLL_QUERY_OP_EQUAL;
+       j[0].value.j = job;
+
+       edg_wll_QueryCondsExtToSoap(mydlo, (const edg_wll_QueryRec **)j,
+               &in.__sizejobConditions, &in.jobConditions);
+       edg_wll_QueryCondsExtToSoap(mydlo, (const edg_wll_QueryRec **)e,
+               &in.__sizeeventConditions, &in.eventConditions);
+
+       switch (err = soap_call___lb__QueryEvents(mydlo, server, "",&in,&out))
+       {
+       case SOAP_OK:
+               {
+               edg_wll_Event   *events;
+               int             i;
+
+
+               edg_wll_SoapToEvents(mydlo,out,&events);
+
+               for ( i = 0; events[i].type != EDG_WLL_EVENT_UNDEF; i++ )
+               {
+                       char    *e = edg_wll_UnparseEvent(ctx,events+i);
+                       fputs(e,stdout);
+                       fputs("\n",stdout);
+                       free(e);
+               }
+
+               free_events(events);
+               printf("\nFound %d events\n",i);
+               }
+               break;
+       case SOAP_FAULT: 
+       case SOAP_SVR_FAULT:
+               {
+               char    *et,*ed;
+
+               edg_wll_FaultToErr(mydlo,ctx);
+               edg_wll_Error(ctx,&et,&ed);
+               fprintf(stderr,"%s: %s (%s)\n",argv[0],et,ed);
+               exit(1);
+               }
+       default:
+               fprintf(stderr,"err = %d\n",err);
+               soap_print_fault(mydlo,stderr);
+       }
+
+       return 0;
+}
+
+
+static void free_events(edg_wll_Event *events)
+{
+       int     i;
+
+       if (events) {
+               for (i=0; events[i].type != EDG_WLL_EVENT_UNDEF; i++) 
+                       edg_wll_FreeEvent(&(events[i]));
+               edg_wll_FreeEvent(&(events[i])); /* free last line */
+               free(events);   
+               events = NULL;
+       }
+}
index d7a3ed6..1998647 100644 (file)
@@ -417,14 +417,13 @@ err:
        edg_wll_QueryRecFree(out);
        return -1;
 }
-#if 0
 
 int edg_wll_QueryRecToSoap(
-       struct soap                                *soap,
-       const edg_wll_QueryRec     *in,
-       struct lbt__queryRecord   **out)
+       struct soap                     *soap,
+       const edg_wll_QueryRec          *in,
+       struct lbt__queryRecord         **out)
 {
-       struct lbt__queryRecord    *qr;
+       struct lbt__queryRecord         *qr;
 
 
        assert(in); assert(out);
@@ -432,20 +431,7 @@ int edg_wll_QueryRecToSoap(
        memset(qr, 0, sizeof(*qr));
        if ( !in ) goto ret;
        edg_wll_QueryOpToSoap(in->op, &(qr->op));
-       if (   in->attr == EDG_WLL_QUERY_ATTR_TIME
-               || in->attr == EDG_WLL_QUERY_ATTR_USERTAG ) {
-               if ( !(qr->attrid = soap_malloc(soap, sizeof(*(qr->attrid)))) ) return SOAP_FAULT;
-               memset(qr->attrid, 0, sizeof(*(qr->attrid)));
-               if ( in->attr == EDG_WLL_QUERY_ATTR_TIME ) {
-                       qr->attrid->state = soap_malloc(soap, sizeof(*(qr->attrid->state)));
-                       if ( !qr->attrid->state ) return SOAP_FAULT;
-                       edg_wll_JobStatCodeToSoap(in->attr_id.state, qr->attrid->state);
-               }
-               else {
-                       qr->attrid->tag = soap_strdup(soap, in->attr_id.tag);
-                       if ( !qr->attrid->tag ) return SOAP_FAULT;
-               }
-       }
+
        switch ( in->op ) {
        case EDG_WLL_QUERY_OP_WITHIN:
                if ( !(qr->value2 = soap_malloc(soap, sizeof(*(qr->value2)))) ) return SOAP_FAULT;
@@ -460,7 +446,6 @@ ret:
        *out = qr;
        return SOAP_OK;
 }
-#endif
 
 /**
  * Translate query conditions from Soap form to query rec structure
@@ -488,34 +473,52 @@ err:
        return -1;
 }
 
-#if 0
 int edg_wll_QueryCondsToSoap(
-       struct soap                                        *soap,
-       const edg_wll_QueryRec             *in,
-       struct lbt__queryConditions **out)
+       struct soap                     *soap,
+       const edg_wll_QueryRec          *in,
+       struct lbt__queryConditions     **out)
 {
-       int                                                             i;
-       struct lbt__queryConditions  *qc;
+       int                             i;
+       struct lbt__queryConditions     *qc;
 
 
        assert(out);
-       if ( !(qc = soap_malloc(soap, sizeof(*qc))) ) return SOAP_FAULT;
+       if ( !(qc = soap_malloc(soap, sizeof(*qc))) )
+               return SOAP_FAULT;
        memset(qc, 0, sizeof(*qc));
-       if ( !in ) goto ret;
-       while ( in[qc->__sizerecords].attr ) qc->__sizerecords++;
-       if ( !qc->__sizerecords ) goto ret;
-       qc->records = soap_malloc(soap, sizeof(*(qc->records))*qc->__sizerecords);
-       if ( !qc->records ) return SOAP_FAULT;
+       if ( !in )
+               goto ret;
+
        edg_wll_AttrToSoap(in[0].attr, &(qc->attr));
+
+       if ( in->attr == EDG_WLL_QUERY_ATTR_TIME ) {
+               qc->statName = soap_malloc(soap, sizeof(*(qc->statName)));
+               if ( !qc->statName ) return SOAP_FAULT;
+               edg_wll_JobStatCodeToSoap(in->attr_id.state, qc->statName);
+       }
+       else {
+               qc->tagName = soap_strdup(soap, in->attr_id.tag);
+               if ( !qc->tagName ) return SOAP_FAULT;
+       }
+
+       i = 0;
+       while ( in[i].attr ) qc->__sizerecord++;
+
+       if ( !qc->__sizerecord )
+               goto ret;
+
+       qc->record = soap_malloc(soap, sizeof(*(qc->record)) * qc->__sizerecord);
+       if ( !qc->record )
+               return SOAP_FAULT;
+
        for ( i = 0; in[i].attr; i++ )
-               if ( edg_wll_QueryRecToSoap(soap, in+i, qc->records+i) )
+               if ( edg_wll_QueryRecToSoap(soap, &in[i], &(qc->record[i])) )
                        return SOAP_FAULT;
 
 ret:
        *out = qc;
        return SOAP_OK;
 }
-#endif
 
 /**
  * Translate extended query conditions from Soap form to query rec structure
@@ -523,7 +526,7 @@ ret:
  * \param IN in array of soap query condition
  * \param OUT out target array of queryRec
  */
-int edg_wll_SoapToQueryCondsExt(const struct lbt__queryConditions *in, int __sizecondition, edg_wll_QueryRec ***out)
+int edg_wll_SoapToQueryCondsExt(const struct lbt__queryConditions **in, int __sizecondition, edg_wll_QueryRec ***out)
 {
        int                                     i;
        edg_wll_QueryRec  **qr;
@@ -532,7 +535,7 @@ int edg_wll_SoapToQueryCondsExt(const struct lbt__queryConditions *in, int __siz
        assert(in); assert(out);
        if ( !(qr = calloc(__sizecondition, sizeof(*qr))) ) return -1;
        for ( i = 0; i < __sizecondition; i++ )
-               if ( edg_wll_SoapToQueryConds(&in[i], qr+i) ) goto err;
+               if ( edg_wll_SoapToQueryConds(in[i], qr+i) ) goto err;
 
        *out = qr;
        return 0;
@@ -550,33 +553,44 @@ err:
        return -1;
 }
 
-#if 0
+
+/**
+ * Translate extended query conditions from Soap form to query rec structure
+ *
+ * \param IN in target array of queryRec 
+ * \param OUT out_size number of array elements
+ * \param OUT out array of soap query condition
+ */
 int edg_wll_QueryCondsExtToSoap(
-       struct soap                                                        *soap,
-       const edg_wll_QueryRec                            **in,
-       struct lbt__queryConditions               **out)
+       struct soap                     *soap,
+       const edg_wll_QueryRec          **in,
+       int                             *out_size,
+       struct lbt__queryConditions     ***out)
 {
-       int                                                             i;
-       struct lbt__queryConditions *qc;
+       int                             i, size;
+       struct lbt__queryConditions     **qc;
 
 
-       assert(out);
-       if ( !(qc = soap_malloc(soap, sizeof(*qc))) ) return SOAP_FAULT;
-       memset(qc, 0, sizeof(*qc));
-       if ( !in ) goto ret;
-       while ( in[qc->__sizecondition] ) qc->__sizecondition++;
-       if ( !qc->__sizecondition ) goto ret;
-       qc->condition = soap_malloc(soap, sizeof(*(qc->condition))*qc->__sizecondition);
-       if ( !qc->condition ) return SOAP_FAULT;
+       assert(in); assert(out);
+
+       i = 0;
+       while ( in[i] ) size++;
+
+       if ( !size ) 
+               goto ret;
+
+       qc = soap_malloc(soap, sizeof(*qc) * size);
+       if ( !qc ) return SOAP_FAULT;
+
        for ( i = 0; in[i]; i++ )
-               if ( edg_wll_QueryCondsToSoap(soap, in[i], qc->condition+i) )
+               if ( edg_wll_QueryCondsToSoap(soap, in[i], qc[i]) )
                        return SOAP_FAULT;
 
 ret:
        *out = qc;
+       *out_size = size;
        return SOAP_OK;
 }
-#endif
 
 int edg_wll_JobsQueryResToSoap(
        struct soap           *soap,
@@ -629,3 +643,13 @@ int edg_wll_EventsQueryResToSoap(
 
        return SOAP_OK;
 }
+
+int edg_wll_SoapToEvents(
+       struct soap *soap,
+       struct _lbe__QueryEventsResponse in,
+       edg_wll_Event **out)
+{
+       //XXX: needs flash
+
+       return 0;
+}      
index e2518ee..0fc36fb 100644 (file)
@@ -39,7 +39,7 @@ extern int edg_wll_SoapToQueryRec(
                        edg_wll_QueryRec *out);
 extern int edg_wll_QueryRecToSoap(struct soap *,
                        const edg_wll_QueryRec *,
-                       struct lbt__queryRecord *);
+                       struct lbt__queryRecord **);
 
 
 extern int edg_wll_SoapToQueryConds(
@@ -50,12 +50,13 @@ extern int edg_wll_QueryCondsToSoap(struct soap *,
                        struct lbt__queryConditions **);
 
 extern int edg_wll_SoapToQueryCondsExt(
-                       const struct lbt__queryConditions *,
+                       const struct lbt__queryConditions **,
                        int __sizecondition,
                        edg_wll_QueryRec ***);
 extern int edg_wll_QueryCondsExtToSoap(struct soap *,
                        const edg_wll_QueryRec **,
-                       struct lbt__queryConditions **);
+                       int *,
+                       struct lbt__queryConditions ***);
 
 extern int edg_wll_JobsQueryResToSoap(struct soap *,
                        edg_wlc_JobId *,
@@ -65,6 +66,11 @@ extern int edg_wll_JobsQueryResToSoap(struct soap *,
 extern int edg_wll_EventsQueryResToSoap(struct soap *,
                        edg_wll_Event *,
                        struct _lbe__QueryEventsResponse *);
+extern int edg_wll_SoapToEvents(
+                       struct soap *,
+                       struct _lbe__QueryEventsResponse,
+                       edg_wll_Event **);
+
 
 #ifdef __cplusplus
 }