Hi all,

the reloading of the config (aka graceful restart) supports the on-th-fly manipulation of the upstream SMSC groups and the corresponding routing constraints for them.

What is doesn't support is the on-the-fly changing of the 'group = smsbox-route' MO direction routing.

The attached patch adds this capability.

Please review. If no objections arise I will commit this within the next days.

Cheers,
Stipe

--
Best Regards,
Stipe Tolj

-------------------------------------------------------------------
Düsseldorf, NRW, Germany

Kannel Foundation                 tolj.org system architecture
http://www.kannel.org/            http://www.tolj.org/

stolj at kannel.org               st at tolj.org
-------------------------------------------------------------------
Index: gw/bb_boxc.c
===================================================================
--- gw/bb_boxc.c        (revision 5267)
+++ gw/bb_boxc.c        (working copy)
@@ -1112,11 +1112,14 @@
     gwlist_remove_producer(flow_threads);
 }
 
+#define RELOAD_PANIC(...) \
+    if (reload) { error(__VA_ARGS__); continue; } \
+    else panic(__VA_ARGS__);
 
 /*
  * Populates the corresponding smsbox_by_foobar dictionary hash tables
  */
-static void init_smsbox_routes(Cfg *cfg)
+static void init_smsbox_routes(Cfg *cfg, int reload)
 {
     CfgGroup *grp;
     List *list, *items;
@@ -1132,7 +1135,7 @@
 
         if ((boxc_id = cfg_get(grp, octstr_imm("smsbox-id"))) == NULL) {
             grp_dump(grp);
-            panic(0,"'smsbox-route' group without valid 'smsbox-id' 
directive!");
+            RELOAD_PANIC(0,"'smsbox-route' group without valid 'smsbox-id' 
directive!");
         }
 
         /*
@@ -1158,9 +1161,10 @@
                 debug("bb.boxc",0,"Adding smsbox routing to id <%s> for smsc 
id <%s>",
                       octstr_get_cstr(boxc_id), octstr_get_cstr(item));
 
-                if (!dict_put_once(smsbox_by_smsc, item, 
octstr_duplicate(boxc_id)))
-                    panic(0, "Routing for smsc-id <%s> already exists!",
-                          octstr_get_cstr(item));
+                if (!dict_put_once(smsbox_by_smsc, item, 
octstr_duplicate(boxc_id))) {
+                    RELOAD_PANIC(0, "Routing for smsc-id <%s> already exists!",
+                                 octstr_get_cstr(item));
+                }
             }
             gwlist_destroy(items, octstr_destroy_item);
             octstr_destroy(smsc_ids);
@@ -1175,9 +1179,10 @@
                 debug("bb.boxc",0,"Adding smsbox routing to id <%s> for 
receiver no <%s>",
                       octstr_get_cstr(boxc_id), octstr_get_cstr(item));
 
-                if (!dict_put_once(smsbox_by_receiver, item, 
octstr_duplicate(boxc_id)))
-                    panic(0, "Routing for receiver no <%s> already exists!",
-                          octstr_get_cstr(item));
+                if (!dict_put_once(smsbox_by_receiver, item, 
octstr_duplicate(boxc_id))) {
+                    RELOAD_PANIC(0, "Routing for receiver no <%s> already 
exists!",
+                                 octstr_get_cstr(item));
+                }
             }
             gwlist_destroy(items, octstr_destroy_item);
             octstr_destroy(shortcuts);
@@ -1202,9 +1207,10 @@
                     /* construct the dict key '<shortcode>:<smsc-id>' */
                     octstr_insert(subitem, item, 0);
                     octstr_insert_char(subitem, octstr_len(item), ':');
-                    if (!dict_put_once(smsbox_by_smsc_receiver, subitem, 
octstr_duplicate(boxc_id)))
-                        panic(0, "Routing for receiver:smsc <%s> already 
exists!",
-                              octstr_get_cstr(subitem));
+                    if (!dict_put_once(smsbox_by_smsc_receiver, subitem, 
octstr_duplicate(boxc_id))) {
+                        RELOAD_PANIC(0, "Routing for receiver:smsc <%s> 
already exists!",
+                                     octstr_get_cstr(subitem));
+                    }
                 }
                 gwlist_destroy(subitems, octstr_destroy_item);
             }
@@ -1217,7 +1223,9 @@
     gwlist_destroy(list, NULL);
 }
 
+#undef RELOAD_PANIC
 
+
 /*-------------------------------------------------------------
  * public functions
  *
@@ -1272,7 +1280,7 @@
     smsbox_by_smsc_receiver = dict_create(50, (void(*)(void *)) 
octstr_destroy);
 
     /* load the defined smsbox routing rules */
-    init_smsbox_routes(cfg);
+    init_smsbox_routes(cfg, 0);
 
     gwlist_add_producer(outgoing_sms);
     gwlist_add_producer(smsbox_list);
@@ -1293,7 +1301,15 @@
 {
     if (!smsbox_running) return -1;
 
-    /* send new config to clients */
+    gw_rwlock_wrlock(smsbox_list_rwlock);
+    dict_destroy(smsbox_by_smsc);
+    dict_destroy(smsbox_by_receiver);
+    dict_destroy(smsbox_by_smsc_receiver);
+    smsbox_by_smsc = dict_create(30, (void(*)(void *)) octstr_destroy);
+    smsbox_by_receiver = dict_create(50, (void(*)(void *)) octstr_destroy);
+    smsbox_by_smsc_receiver = dict_create(50, (void(*)(void *)) 
octstr_destroy);
+    init_smsbox_routes(cfg, 1);
+    gw_rwlock_unlock(smsbox_list_rwlock);
 
     return 0;
 }
Index: gw/bb_http.c
===================================================================
--- gw/bb_http.c        (revision 5267)
+++ gw/bb_http.c        (working copy)
@@ -247,8 +247,10 @@
         bb_restart();
         return octstr_create("Already in shutdown phase, restarting hard...");
     }
-    bb_graceful_restart();
-    return octstr_create("Restarting gracefully.....");
+    if (bb_graceful_restart() == -1)
+        return octstr_create("Unable to restart gracefully! Please check log 
file.");
+    else
+        return octstr_create("Restarting gracefully.....");
 }
 
 static Octstr *httpd_flush_dlr(List *cgivars, int status_type)
Index: gw/bb_smscconn.c
===================================================================
--- gw/bb_smscconn.c    (revision 5267)
+++ gw/bb_smscconn.c    (working copy)
@@ -1519,7 +1519,7 @@
 }
 
 
-int smsc2_graceful_restart(void)
+int smsc2_graceful_restart(Cfg *cfg)
 {
     CfgGroup *grp;
     SMSCConn *conn;
@@ -1533,10 +1533,8 @@
     gw_rwlock_wrlock(&smsc_list_lock);
 
     /* load the smsc groups from the config resource */
-    if (bb_reload_smsc_groups() != 0) {
-        gw_rwlock_unlock(&smsc_list_lock);
-        return -1;
-    }
+    gwlist_destroy(smsc_groups, NULL);
+    smsc_groups = cfg_get_multi_group(cfg, octstr_imm("smsc"));
 
     /* List of SMSCConn that we keep running */
     keep = gwlist_create();
Index: gw/bearerbox.c
===================================================================
--- gw/bearerbox.c      (revision 5267)
+++ gw/bearerbox.c      (working copy)
@@ -953,7 +953,19 @@
 
 int bb_graceful_restart(void)
 {
-    return smsc2_graceful_restart();
+    Cfg *cfg;
+
+    info(0, "Reloading configuration resource `%s'.", 
octstr_get_cstr(cfg_filename));
+    cfg = cfg_create(cfg_filename);
+    if (cfg_read(cfg) == -1) {
+        error(0, "Error processing configuration resource `%s'. Continue with 
existing configuration.",
+              octstr_get_cstr(cfg_filename));
+        return -1;
+    }
+
+    smsc2_graceful_restart(cfg);
+    smsbox_restart(cfg);
+    return 0;
 }
 
 int bb_reload_lists(void)
Index: gw/bearerbox.h
===================================================================
--- gw/bearerbox.h      (revision 5267)
+++ gw/bearerbox.h      (working copy)
@@ -150,7 +150,7 @@
 
 int smsc2_start(Cfg *config);
 int smsc2_restart(Cfg *config);
-int smsc2_graceful_restart(void);
+int smsc2_graceful_restart(Cfg *config);
 
 void smsc2_suspend(void);    /* suspend (can still send but not receive) */
 void smsc2_resume(int is_init);     /* resume */
Index: ChangeLog
===================================================================
--- ChangeLog   (revision 5267)
+++ ChangeLog   (working copy)
@@ -1,3 +1,16 @@
+2018-10-01  Stipe Tolj  <stolj at kannel.org>
+    * gw/bb_boxc.c: use init_smsbox_routes() for initial and reload cases, use
+      smsbox_restart() to reload smsbox routing.
+    * gw/bb_http.c: interpret bb_graceful_restart() outcome in HTTP admin 
command
+      function httpd_graceful_restart().
+    * gw/bearerbox.c: use gw_log_force() for starting/stopping log evetns that
+      we want to see in the log, no matter waht log-level is used (forced),
+      reload config in bb_graceful_restart() and call the sub-module reload
+      functions.
+    * gw/bearebox.h: change prototype for smsc2_graceful_restart().
+    Thhis patchsets implement the reloading (aka graceful restart) capabilities
+    for the MO direction smsbox routing groups.
+
 2018-09-26 Alexander Malysh <amalysh @ kannnel.org>
     * gwlib/date.[ch]: added handling of fraction
 

Reply via email to