You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2013/12/20 20:44:12 UTC

svn commit: r1552793 - in /qpid/dispatch/trunk: etc/qdrouterd.conf python/qpid_dispatch_internal/config/parser.py python/qpid_dispatch_internal/config/schema.py src/config.c src/server.c

Author: tross
Date: Fri Dec 20 19:44:10 2013
New Revision: 1552793

URL: http://svn.apache.org/r1552793
Log:
QPID-5443 - Improvements to configuration processing
 - Added enumerated values to the config schema
 - Added enumeration checking to the config parser
 - Improved reporting (via log) of failures during configuration
 - The process now exits when a configuration failure is encountered
 - Added config syntax for setting fixed address semantics per prefix
 - Added logging of debug mode when built without NDEBUG

Modified:
    qpid/dispatch/trunk/etc/qdrouterd.conf
    qpid/dispatch/trunk/python/qpid_dispatch_internal/config/parser.py
    qpid/dispatch/trunk/python/qpid_dispatch_internal/config/schema.py
    qpid/dispatch/trunk/src/config.c
    qpid/dispatch/trunk/src/server.c

Modified: qpid/dispatch/trunk/etc/qdrouterd.conf
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/etc/qdrouterd.conf?rev=1552793&r1=1552792&r2=1552793&view=diff
==============================================================================
--- qpid/dispatch/trunk/etc/qdrouterd.conf (original)
+++ qpid/dispatch/trunk/etc/qdrouterd.conf Fri Dec 20 19:44:10 2013
@@ -39,3 +39,10 @@ router {
     mode: standalone
     router-id: Router.A
 }
+
+address {
+    prefix: /
+    method: fixed
+    fixed-rule: multicast
+}
+

Modified: qpid/dispatch/trunk/python/qpid_dispatch_internal/config/parser.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/config/parser.py?rev=1552793&r1=1552792&r2=1552793&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/config/parser.py (original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/config/parser.py Fri Dec 20 19:44:10 2013
@@ -19,7 +19,7 @@
 
 import json
 from schema   import config_schema
-from dispatch import LogAdapter, LOG_TRACE, LOG_ERROR, LOG_INFO
+from dispatch import LogAdapter, LOG_TRACE, LOG_ERROR, LOG_INFO, LOG_CRITICAL
 
 class Section:
   """
@@ -93,6 +93,7 @@ VALUE_TYPE    = 0
 VALUE_INDEX   = 1
 VALUE_FLAGS   = 2
 VALUE_DEFAULT = 3
+VALUE_ENUMS   = 4
 
 
 class SchemaSection:
@@ -131,6 +132,16 @@ class SchemaSection:
     return self.values[key][VALUE_DEFAULT]
 
 
+  def is_valid_enum(self, key, value):
+    if self.values[key][VALUE_ENUMS] == None:
+      return True
+    return value in self.values[key][VALUE_ENUMS]
+
+
+  def enums(self, key):
+    return self.values[key][VALUE_ENUMS]
+
+
   def check_and_default(self, kv_map):
     copy = {}
     for k,v in self.values.items():
@@ -143,6 +154,10 @@ class SchemaSection:
       if k not in self.values:
         raise Exception("In section '%s', unknown key '%s'" % (self.name, k))
       copy[k] = v
+    for k,v in kv_map.items():
+      if not self.is_valid_enum(k, v):
+        raise Exception("In section '%s', unknown value '%s' for key '%s'.  Expected one of %r" %
+                        (self.name, v, k, self.enums(k)))
     return copy
 
 
@@ -212,7 +227,7 @@ class DispatchConfig:
       self._validate_raw_config()
       self._process_schema()
     except Exception, E:
-      print "Exception in read_file: %r" % E
+      self.log.log(LOG_CRITICAL, "Exception in Configuration File Processing: %r" % E)
       raise
 
 

Modified: qpid/dispatch/trunk/python/qpid_dispatch_internal/config/schema.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/config/schema.py?rev=1552793&r1=1552792&r2=1552793&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/config/schema.py (original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/config/schema.py Fri Dec 20 19:44:10 2013
@@ -21,7 +21,7 @@
 # config_schema =
 #    { <section_name> :
 #        (<singleton>,
-#         {<key> : (<value-type>, <index>, <flags>, <default-value>)
+#         {<key> : (<value-type>, <index>, <flags>, <default-value>, <choices>)
 #        )
 #    }
 #
@@ -38,48 +38,55 @@
 #                    S = During expansion, this key should be copied
 #  <default-value> = If not mandatory and not specified, the value defaults to this
 #                    value
+#  <choices>       = If the value is enumerated, this is a list of valid enumerations.
 #
 
 config_schema = {
-  'container' : (True, {
-    'worker-threads' : (int, None, "", 1),
-    'container-name' : (str, None, "", None)
+    'container' : (True, {
+        'worker-threads' : (int, None, '', 1,    None),
+        'container-name' : (str, None, '', None, None)
     }),
-  'ssl-profile' : (False, {
-    'name'          : (str, 0,    "M"),
-    'cert-db'       : (str, None, "S", None),
-    'cert-file'     : (str, None, "S", None),
-    'key-file'      : (str, None, "S", None),
-    'password-file' : (str, None, "S", None),
-    'password'      : (str, None, "S", None)
+    'ssl-profile' : (False, {
+        'name'          : (str, 0,    'M', None, None),
+        'cert-db'       : (str, None, 'S', None, None),
+        'cert-file'     : (str, None, 'S', None, None),
+        'key-file'      : (str, None, 'S', None, None),
+        'password-file' : (str, None, 'S', None, None),
+        'password'      : (str, None, 'S', None, None)
     }),
-  'listener' : (False, {
-    'addr'              : (str,  0,    "M"),
-    'port'              : (str,  1,    "M"),
-    'label'             : (str,  None, "",  None),
-    'role'              : (str,  None, "",  'normal'),
-    'sasl-mechanisms'   : (str,  None, "M"),
-    'ssl-profile'       : (str,  None, "E", None),
-    'require-peer-auth' : (bool, None, "",  True),
-    'allow-unsecured'   : (bool, None, "",  False)
+    'listener' : (False, {
+        'addr'              : (str,  0,    'M', None,  None),
+        'port'              : (str,  1,    'M', None,  None),
+        'label'             : (str,  None, '',  None,  None),
+        'role'              : (str,  None, '',  'normal', ['normal', 'inter-router']),
+        'sasl-mechanisms'   : (str,  None, 'M', None,  None),
+        'ssl-profile'       : (str,  None, 'E', None,  None),
+        'require-peer-auth' : (bool, None, '',  True,  None),
+        'allow-unsecured'   : (bool, None, '',  False, None)
     }),
-  'connector' : (False, {
-    'addr'            : (str,  0,    "M"),
-    'port'            : (str,  1,    "M"),
-    'label'           : (str,  None, "",  None),
-    'role'            : (str,  None, "",  'normal'),
-    'sasl-mechanisms' : (str,  None, "M"),
-    'ssl-profile'     : (str,  None, "E", None),
-    'allow-redirect'  : (bool, None, "",  True)
+    'connector' : (False, {
+        'addr'            : (str,  0,    'M', None, None),
+        'port'            : (str,  1,    'M', None, None),
+        'label'           : (str,  None, '',  None, None),
+        'role'            : (str,  None, '',  'normal', ['normal', 'inter-router']),
+        'sasl-mechanisms' : (str,  None, 'M', None, None),
+        'ssl-profile'     : (str,  None, 'E', None, None),
+        'allow-redirect'  : (bool, None, '',  True, None)
     }),
-  'router' : (True, {
-    'mode'                : (str, None, "", 'standalone'),
-    'router-id'           : (str, None, "M"),
-    'area'                : (str, None, "", None),
-    'hello-interval'      : (int, None, "", 1),
-    'hello-max-age'       : (int, None, "", 3),
-    'ra-interval'         : (int, None, "", 30),
-    'remote-ls-max-age'   : (int, None, "", 60),
-    'mobile-addr-max-age' : (int, None, "", 60)
-    })}
+    'router' : (True, {
+        'mode'                : (str, None, '', 'standalone', ['standalone', 'interior']),
+        'router-id'           : (str, None, 'M', None, None),
+        'area'                : (str, None, '',  None, None),
+        'hello-interval'      : (int, None, '',  1, None),
+        'hello-max-age'       : (int, None, '',  3, None),
+        'ra-interval'         : (int, None, '',  30, None),
+        'remote-ls-max-age'   : (int, None, '',  60, None),
+        'mobile-addr-max-age' : (int, None, '',  60, None)
+    }),
+    'address' : (False, {
+        'prefix'     : (str, 0,    'M', None, None),
+        'method'     : (str, None, '',  'fixed',     ['fixed', 'dist-mode', 'lookup']),
+        'fixed-rule' : (str, None, '',  'multicast', ['multicast', 'lowest-cost', 'round-robin', 'balanced'])
+    })
+}
 

Modified: qpid/dispatch/trunk/src/config.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/config.c?rev=1552793&r1=1552792&r2=1552793&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/config.c (original)
+++ qpid/dispatch/trunk/src/config.c Fri Dec 20 19:44:10 2013
@@ -87,7 +87,6 @@ qd_config_t *qd_config(const char *filen
         PyErr_Print();
         Py_DECREF(config->pModule);
         free_qd_config_t(config);
-        qd_log(log_module, LOG_ERROR, "Configuration file '%s' could not be read", filename);
         return 0;
     }
 
@@ -106,7 +105,7 @@ void qd_config_read(qd_config_t *config)
 
     pMethod = PyObject_GetAttrString(config->pObject, "read_file");
     if (!pMethod || !PyCallable_Check(pMethod)) {
-        qd_log(log_module, LOG_ERROR, "Problem with configuration module: No callable 'item_count'");
+        qd_log(log_module, LOG_ERROR, "Problem with configuration module: No callable 'read_file'");
         if (pMethod) {
             Py_DECREF(pMethod);
         }
@@ -119,7 +118,11 @@ void qd_config_read(qd_config_t *config)
     if (pResult) {
         Py_DECREF(pResult);
     } else {
+#ifndef NDEBUG
         PyErr_Print();
+#endif
+        qd_log(log_module, LOG_CRITICAL, "Configuration Failed, Exiting");
+        exit(1);
     }
     Py_DECREF(pMethod);
 }

Modified: qpid/dispatch/trunk/src/server.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/server.c?rev=1552793&r1=1552792&r2=1552793&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/server.c (original)
+++ qpid/dispatch/trunk/src/server.c Fri Dec 20 19:44:10 2013
@@ -731,6 +731,15 @@ void qd_server_set_user_fd_handler(qd_di
 }
 
 
+static void qd_server_announce(qd_server_t* qd_server)
+{
+    qd_log(module, LOG_INFO, "Operational, %d Threads Running", qd_server->thread_count);
+#ifndef NDEBUG
+    qd_log(module, LOG_INFO, "Running in DEBUG Mode");
+#endif
+}
+
+
 void qd_server_run(qd_dispatch_t *qd)
 {
     qd_server_t *qd_server = qd->server;
@@ -744,7 +753,7 @@ void qd_server_run(qd_dispatch_t *qd)
     for (i = 1; i < qd_server->thread_count; i++)
         thread_start(qd_server->threads[i]);
 
-    qd_log(module, LOG_INFO, "Operational, %d Threads Running", qd_server->thread_count);
+    qd_server_announce(qd_server);
 
     thread_run((void*) qd_server->threads[0]);
 
@@ -768,7 +777,7 @@ void qd_server_start(qd_dispatch_t *qd)
     for (i = 0; i < qd_server->thread_count; i++)
         thread_start(qd_server->threads[i]);
 
-    qd_log(module, LOG_INFO, "Operational, %d Threads Running", qd_server->thread_count);
+    qd_server_announce(qd_server);
 }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org