- changed option to -N std[:max] _seconds_
authorAleš Křenek <ljocha@ics.muni.cz>
Thu, 28 Feb 2008 12:18:16 +0000 (12:18 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Thu, 28 Feb 2008 12:18:16 +0000 (12:18 +0000)
- prepare for passing requested validity over wire

org.glite.lb.server/src/bkserverd.c
org.glite.lb.server/src/notification.c

index 789f365..c0c2b7e 100644 (file)
@@ -151,7 +151,8 @@ static char                         *server_subject = NULL;
 
 
 static time_t                  purge_timeout[EDG_WLL_NUMBER_OF_STATCODES];
-static time_t                  notif_duration = 60*60*24*7;
+static time_t                  notif_duration_max = 60*60*24,
+                               notif_duration = 60*60*2;
 
 static edg_wll_GssCred mycred = NULL;
 time_t                                 cert_mtime = 0;
@@ -245,7 +246,7 @@ static void usage(char *me)
                "\t-l, --semaphores number of semaphores (job locks) to use\n"
                "\t-i, --pidfile\t file to store master pid\n"
                "\t-L, --limits\t query limits numbers in format \"events_limit:jobs_limit:size_limit\"\n"
-               "\t-N, --notif-dur\t Maximal duration of notification registrations in hours\n"
+               "\t-N, --notif-dur default[:max]\t Duration of notification registrations in seconds (default and maximal)\n"
                "\t-S, --purge-prefix\t purge files full-path prefix\n"
                "\t-D, --dump-prefix\t dump files full-path prefix\n"
                "\t-J, --jpreg-dir\t JP registration temporary files prefix (implies '-j')\n"
@@ -431,7 +432,18 @@ int main(int argc, char *argv[])
                                return 1;
                        }
                        break;
-               case 'N': notif_duration = atoi(optarg) * (60*60); break;
+               case 'N': {
+                               int     std,max;
+                               switch (sscanf(optarg,"%d:%d",&std,&max)) {
+                                       case 2: notif_duration_max = max;
+                                               /* fallthrough */
+                                       case 1: notif_duration = std;
+                                               break;
+                                       default: 
+                                               usage(name);
+                                               return 1;
+                               }
+                       }  break;
                case 'X': notif_ilog_socket_path = strdup(optarg); break;
                case 'Y': notif_ilog_file_prefix = strdup(optarg); break;
                case 'i': strcpy(pidfile,optarg); break;
@@ -954,6 +966,7 @@ int bk_handle_connection(int conn, struct timeval *timeout, void *data)
        /*      set globals
         */
        ctx->notifDuration = notif_duration;
+       ctx->notifDurationMax = notif_duration_max;
        ctx->purgeStorage = strdup(purgeStorage);
        ctx->dumpStorage = strdup(dumpStorage);
        if ( jpreg ) ctx->jpreg_dir = strdup(jpregDir); else ctx->jpreg_dir = NULL;
@@ -1214,6 +1227,7 @@ int bk_handle_connection_proxy(int conn, struct timeval *timeout, void *data)
        /*      set globals
         */
        ctx->notifDuration = notif_duration;
+       ctx->notifDurationMax = notif_duration_max;
        if ( jpreg ) ctx->jpreg_dir = strdup(jpregDir); else ctx->jpreg_dir = NULL;
        ctx->allowAnonymous = 1;
        ctx->isProxy = 1;
index 6138881..02bc136 100644 (file)
@@ -25,6 +25,7 @@ static int update_notif(edg_wll_Context, const edg_wll_NotifId,
                                                const char *, const char *, const char *);
 
 static int get_indexed_cols(edg_wll_Context,char const *,edg_wll_QueryRec **,char **);
+static void adjust_validity(edg_wll_Context,time_t *);
 
 
 int edg_wll_NotifNewServer(
@@ -78,12 +79,10 @@ int edg_wll_NotifNewServer(
 
        /*      Format time of validity
         */
-       *valid = time(NULL);
-       if (   ctx->peerProxyValidity
-               && (ctx->peerProxyValidity - *valid) < ctx->notifDuration )
-               *valid = ctx->peerProxyValidity;
-       else
-               *valid += ctx->notifDuration;
+
+/* XXX: until valid works [inout] */
+       *valid = time(NULL) + ctx->notifDuration;       
+       adjust_validity(ctx,valid);
 
        glite_lbu_TimeToDB(*valid, &time_s);
        if ( !time_s )
@@ -191,12 +190,10 @@ int edg_wll_NotifBindServer(
 
        /*      Format time of validity
         */
-       *valid = time(NULL);
-       if (   ctx->peerProxyValidity
-               && (ctx->peerProxyValidity - *valid) < ctx->notifDuration )
-               *valid = ctx->peerProxyValidity;
-       else
-               *valid += ctx->notifDuration;
+
+/* XXX: until valid works [inout] */
+       *valid = time(NULL) + ctx->notifDuration;       
+       adjust_validity(ctx,valid);
 
        glite_lbu_TimeToDB(*valid, &time_s);
        if ( !time_s )
@@ -347,12 +344,10 @@ int edg_wll_NotifRefreshServer(
 
        /*      Format time of validity
         */
-       *valid = time(NULL);
-       if (   ctx->peerProxyValidity
-               && (ctx->peerProxyValidity - *valid) < ctx->notifDuration )
-               *valid = ctx->peerProxyValidity;
-       else
-               *valid += ctx->notifDuration;
+
+/* XXX: until valid works [inout] */
+       *valid = time(NULL) + ctx->notifDuration;       
+       adjust_validity(ctx,valid);
 
        glite_lbu_TimeToDB(*valid, &time_s);
        if ( !time_s )
@@ -716,3 +711,20 @@ static int get_indexed_cols(edg_wll_Context ctx,char const *notif,edg_wll_QueryR
        *update_out = aux;
        return edg_wll_ResetError(ctx);
 }
+
+static void adjust_validity(edg_wll_Context ctx,time_t *valid)
+{
+       time_t  now;
+
+       if (*valid <= 0) {
+               time(&now); 
+               *valid = now + ctx->notifDuration;
+       }
+
+       if (ctx->peerProxyValidity && ctx->peerProxyValidity < *valid)
+               *valid = ctx->peerProxyValidity;
+
+       if (*valid - now > ctx->notifDurationMax) 
+               *valid = now + ctx->notifDurationMax;
+}
+