- make slaves to compete for contacting PS and asking for feeds
authorMiloš Mulač <mulac@civ.zcu.cz>
Tue, 6 Sep 2005 07:20:55 +0000 (07:20 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Tue, 6 Sep 2005 07:20:55 +0000 (07:20 +0000)
- prototypes of some DB functions

org.glite.jp.index/Makefile
org.glite.jp.index/src/bones_server.c
org.glite.jp.index/src/db_ops.c [new file with mode: 0644]
org.glite.jp.index/src/db_ops.h [new file with mode: 0644]
org.glite.jp.index/src/soap_ps_calls.c

index 57927be..861846c 100644 (file)
@@ -46,7 +46,7 @@ example:=jpis-test
 is_prefix:=jpis_
 ps_prefix:=jpps_
 
-SRCS:= conf.c bones_server.c soap_ops.c soap_ps_calls.c ws_typeref.c\
+SRCS:= conf.c bones_server.c soap_ops.c soap_ps_calls.c ws_typeref.c db_ops.c\
        ${is_prefix}ServerLib.c \
        ${ps_prefix}ClientLib.c ${ps_prefix}C.c
 
index 6c78082..ce15f30 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <errno.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -13,6 +14,7 @@
 #include "glite/security/glite_gsplugin.h"
 
 #include "conf.h"
+#include "db_ops.h"
 #include "soap_ps_calls.h"
 
 #include "soap_version.h"
@@ -50,11 +52,8 @@ static char          *port = "8902";
 static int             debug = 1;
 
 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;
-
+static char                    *glite_jp_default_namespace;
+static glite_jp_is_conf                *conf;  // Let's make configuration visible to all slaves
 
 
 int main(int argc, char *argv[])
@@ -62,7 +61,6 @@ int main(int argc, char *argv[])
        int                     one = 1,opt,i;
        edg_wll_GssStatus       gss_code;
        struct sockaddr_in      a;
-       glite_jp_is_conf        *conf;
        char                    *config_file;
 
 
@@ -118,11 +116,6 @@ int main(int argc, char *argv[])
                fprintf(stderr,"Server idenity: %s\n",mysubj);
        else fputs("WARNING: Running unauthenticated\n",stderr);
 
-       // ask PS server for data
-       // XXX: should come after glite_srvbones_run(), when listening
-       for (i=0; conf->PS_list[i]; i++)
-               MyFeedIndex(conf,conf->PS_list[i]);
-
        /* XXX: daemonise */
 
        glite_srvbones_set_param(GLITE_SBPARAM_SLAVES_COUNT,1);
@@ -134,15 +127,35 @@ int main(int argc, char *argv[])
        return 0;
 }
 
+/* slave's init comes here */  
 static int data_init(void **data)
 {
-       *data = (void *) soap_new();
+       char    *PS_URL = NULL;
 
-       printf("[%d] slave started\n",getpid());
 
-       /* slave's init comes here */   
+       *data = (void *) soap_new();
+       printf("[%d] slave started\n",getpid());
 
-       return 0;
+       /* ask PS server for data */
+       do {
+               switch (glite_jpis_lockUninitializedFeed(&PS_URL)) {
+                       case ENOENT:
+                               // no more feeds to initialize
+                               return 0;
+                       case ENOLCK:
+                               // error during locking
+                               printf("[%d] slave_init(): Locking error.\n",getpid());
+                               free(PS_URL);
+                               return -1;
+                       default:
+                               // contact PS server, ask for data, save feedId and expiration
+                               // to DB and unlock feed
+                               MyFeedIndex(conf, PS_URL);
+                               free(PS_URL);
+                               PS_URL = NULL;
+                               break;
+               }
+       } while (1);
 }
 
 static int newconn(int conn,struct timeval *to,void *data)
diff --git a/org.glite.jp.index/src/db_ops.c b/org.glite.jp.index/src/db_ops.c
new file mode 100644 (file)
index 0000000..1c95a9d
--- /dev/null
@@ -0,0 +1,29 @@
+#ident "$Header$"
+
+#include <time.h>
+
+/* Find first unitialized feed, lock it and return URL of corresponding PS 
+ *
+ * Return value:
+ *      0      - OK
+ *      ENOENT - no more feeds to initialize
+ *      ENOLCK - error during locking */
+
+int glite_jpis_lockUninitializedFeed(char **PS_URL)
+{
+       return 0;
+}
+
+
+/* Store feed ID and expiration time returned by PS for locked feed. */
+
+void glite_jpis_feedInit(char *PS_URL, char *feedId, time_t feedExpires)
+{
+}
+
+/* Unlock given feed */
+
+void glite_jpis_unlockFeed(char *PS_URL)
+{
+}
+
diff --git a/org.glite.jp.index/src/db_ops.h b/org.glite.jp.index/src/db_ops.h
new file mode 100644 (file)
index 0000000..5575967
--- /dev/null
@@ -0,0 +1,10 @@
+#ident "$Header$"
+
+#ifndef _DB_OPS_H
+#define _DB_OPS_H
+
+int glite_jpis_lockUninitializedFeed(char **PS_URL);
+void glite_jpis_feedInit(char *PS_URL, char *feedId, time_t feedExpires);
+void glite_jpis_unlockFeed(char *PS_URL);
+
+#endif
index ed0755b..19a68f3 100644 (file)
@@ -9,6 +9,7 @@
 #include "soap_version.h"
 
 #include "conf.h"
+#include "db_ops.h"
 
 #include "stdsoap2.h"
 
@@ -104,10 +105,14 @@ printf("MyFeedIndex for %s called\n", dest);
        //if (!check_fault(soap,soap_call_jpsrv___FeedIndex(soap,dest,"",
        if (soap_call___jpsrv__FeedIndex(soap,dest,"", &in, &out)) {
                printf("soap_call___jpsrv__FeedIndex() returned error\n");
+               glite_jpis_unlockFeed(dest);
                goto err;
        }
-       else
+       else {
                printf("FeedId: %s\nExpires: %s\n",out.feedId,ctime(&out.feedExpires));
+               glite_jpis_feedInit(dest, out.feedId, out.feedExpires);
+               glite_jpis_unlockFeed(dest);
+       }
        
 err:
        soap_end(soap);