BIND 10 trac2136, updated. 3f922de50497aaac2c1454e8614db268fd45cdd1 [2136] Updated the do_polling method

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Aug 1 11:48:40 UTC 2012


The branch, trac2136 has been updated
       via  3f922de50497aaac2c1454e8614db268fd45cdd1 (commit)
       via  58b6810a302a68dffdfc64ed991011d339246feb (commit)
       via  99b60989f294af3d7711176f31a487760318065d (commit)
       via  082d6a9435c0bf4eb31e334b0c527a277c6e7b30 (commit)
       via  f8f9de23f77e701057ca03eed7388b6d1e050794 (commit)
      from  0472e39d599fb08acd60141a51a1839caaa2165d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3f922de50497aaac2c1454e8614db268fd45cdd1
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Wed Aug 1 16:54:54 2012 +0900

    [2136] Updated the do_polling method
    
    A list of instances for stats to request is obtained from the show_processes
    command of Boss instead of asking the components config of Boss.

commit 58b6810a302a68dffdfc64ed991011d339246feb
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Wed Aug 1 16:19:38 2012 +0900

    [2136] Updated the "show_processes" to provide address of each module
    
    This information is used for other module e.g. stats to count running instances
    of same module. The address information is seen in the third index of the
    array.

commit 99b60989f294af3d7711176f31a487760318065d
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Wed Aug 1 19:13:08 2012 +0900

    [2136] Introduced an address() method for the Component classes
    
    It returns the "_address" attribute of the classes. This is used for the
    "show_processes" command of Boss to provide address information.

commit 082d6a9435c0bf4eb31e334b0c527a277c6e7b30
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Wed Aug 1 15:47:21 2012 +0900

    [2136] Updated the 'show' command handler
    
    The stats module decides if polling should be done by the the last time of
    polling. If more than one seconds past since the last request to each module,
    the stats module requests each module statistics data and then shows the latest
    result. Otherwise, the stats module just shows statistics data which it has.

commit f8f9de23f77e701057ca03eed7388b6d1e050794
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Wed Aug 1 15:37:23 2012 +0900

    [2136] Separated the updating process from the receiving process
    
    In the updating process, it communicates with the cfgmgr module for updating
    statistics specification of each module. This fix is for separating such mixed
    communication process.

-----------------------------------------------------------------------

Summary of changes:
 src/bin/bind10/bind10.8                           |    2 +-
 src/bin/bind10/bind10.xml                         |    2 +-
 src/bin/bind10/bind10_src.py.in                   |    3 +-
 src/bin/bind10/tests/bind10_test.py.in            |    9 +--
 src/bin/stats/stats.py.in                         |   61 +++++++++++++--------
 src/bin/stats/tests/test_utils.py                 |    4 +-
 src/lib/python/isc/bind10/component.py            |   14 +++++
 src/lib/python/isc/bind10/tests/component_test.py |    7 +++
 8 files changed, 71 insertions(+), 31 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/bind10/bind10.8 b/src/bin/bind10/bind10.8
index 9e085e3..e99f2b9 100644
--- a/src/bin/bind10/bind10.8
+++ b/src/bin/bind10/bind10.8
@@ -236,7 +236,7 @@ daemon immediately\&.
 
 \fBshow_processes\fR
 lists the current processes managed by
-\fBbind10\fR\&. The output is an array in JSON format containing the process ID and the name for each\&.
+\fBbind10\fR\&. The output is an array in JSON format containing the process ID, the name for each and the address name used on each message bus\&.
 
 
 .PP
diff --git a/src/bin/bind10/bind10.xml b/src/bin/bind10/bind10.xml
index 4053783..ee60458 100644
--- a/src/bin/bind10/bind10.xml
+++ b/src/bin/bind10/bind10.xml
@@ -425,7 +425,7 @@ xfrin
       <command>show_processes</command> lists the current processes
       managed by <command>bind10</command>.
       The output is an array in JSON format containing the process
-      ID and the name for each.
+      ID, the name for each and the address name used on each message bus.
 <!-- TODO: what is name? -->
 <!-- TODO: change to JSON object format? -->
 <!-- TODO: ticket #1406 -->
diff --git a/src/bin/bind10/bind10_src.py.in b/src/bin/bind10/bind10_src.py.in
index b9dbc36..818a08f 100755
--- a/src/bin/bind10/bind10_src.py.in
+++ b/src/bin/bind10/bind10_src.py.in
@@ -282,7 +282,8 @@ class BoB:
         pids.sort()
         process_list = [ ]
         for pid in pids:
-            process_list.append([pid, self.components[pid].name()])
+            process_list.append([pid, self.components[pid].name(),
+                                 self.components[pid].address()])
         return process_list
 
     def _get_stats_data(self):
diff --git a/src/bin/bind10/tests/bind10_test.py.in b/src/bin/bind10/tests/bind10_test.py.in
index 6ed7411..a2f4e66 100644
--- a/src/bin/bind10/tests/bind10_test.py.in
+++ b/src/bin/bind10/tests/bind10_test.py.in
@@ -940,9 +940,10 @@ class TestStartStopProcessesBob(unittest.TestCase):
         #self.check_started_dhcp(bob, True, True)
 
 class MockComponent:
-    def __init__(self, name, pid):
+    def __init__(self, name, pid, address=None):
         self.name = lambda: name
         self.pid = lambda: pid
+        self.address = lambda: address
 
 
 class TestBossCmd(unittest.TestCase):
@@ -968,10 +969,10 @@ class TestBossCmd(unittest.TestCase):
         """
         bob = MockBob()
         bob.register_process(1, MockComponent('first', 1))
-        bob.register_process(2, MockComponent('second', 2))
+        bob.register_process(2, MockComponent('second', 2, 'Second'))
         answer = bob.command_handler("show_processes", None)
-        processes = [[1, 'first'],
-                     [2, 'second']]
+        processes = [[1, 'first', None],
+                     [2, 'second', 'Second']]
         self.assertEqual(answer, {'result': [0, processes]})
 
 class TestParseArgs(unittest.TestCase):
diff --git a/src/bin/stats/stats.py.in b/src/bin/stats/stats.py.in
index 34f2555..7135084 100755
--- a/src/bin/stats/stats.py.in
+++ b/src/bin/stats/stats.py.in
@@ -164,6 +164,8 @@ class Stats:
              'last_update_time': get_datetime()}):
             logger.warn(STATS_RECEIVED_INVALID_STATISTICS_DATA,
                         self.module_name)
+        # define the variable of the last time of polling
+        self._lasttime_poll = 0.0
         # try to do polling firstly
         self.do_polling()
 
@@ -177,20 +179,19 @@ class Stats:
            each module to invoke 'getstats'. Finally updates internal
            statistics data every time it gets from each instance."""
 
-        # count the number of instances of same module by examing
-        # 'components' of Boss via ConfigManager
+        # It counts the number of instances of same module by
+        # examining the third value from the array result of
+        # 'show_processes' of Boss
         seq = self.cc_session.group_sendmsg(
-            isc.config.ccsession.create_command(
-                isc.config.ccsession.COMMAND_GET_CONFIG,
-                {"module_name": "Boss"}), 'ConfigManager')
+            isc.config.ccsession.create_command("show_processes"),
+            'Boss')
         (answer, env) = self.cc_session.group_recvmsg(False, seq)
         modules = []
         if answer:
             (rcode, value) = isc.config.ccsession.parse_answer(answer)
-            if rcode == 0 and 'components' in value:
-                modules = [ c['special'].capitalize() \
-                                for c in value['components'].values() \
-                                if 'special' in c ]
+            if rcode == 0 and type(value) is list:
+                modules = [ v[2] if type(v) is list and len(v) > 2 \
+                                else None for v in value ]
         # start requesting each module to collect statistics data
         sequences = []
         for (module_name, data) in self.get_statistics_data().items():
@@ -207,6 +208,7 @@ class Stats:
                 sequences = sequences + [ (module_name, seq) \
                                               for i in range(cnt-1) ]
         # start receiving statistics data
+        _statistics_data = []
         while len(sequences) > 0:
             try:
                 (module_name, seq) = sequences.pop(0)
@@ -216,23 +218,30 @@ class Stats:
                     rcode, args = isc.config.ccsession.parse_answer(
                         answer)
                     if rcode == 0:
-                        if self.update_statistics_data(
-                            module_name, env['from'], args):
-                            logger.warn(
-                                STATS_RECEIVED_INVALID_STATISTICS_DATA,
-                                module_name)
-                        else:
-                            if self.update_statistics_data(
-                                self.module_name,
-                                self.cc_session.lname,
-                                {'last_update_time': get_datetime()}):
-                                logger.warn(
-                                    STATS_RECEIVED_INVALID_STATISTICS_DATA,
-                                    self.module_name)
+                        _statistics_data.append(
+                            (module_name, env['from'], args))
             # skip this module if SessionTimeout raised
             except isc.cc.session.SessionTimeout:
                 pass
 
+        # update statistics data
+        while len(_statistics_data) > 0:
+            (_module_name, _lname, _args) = _statistics_data.pop(0)
+            if self.update_statistics_data(_module_name, _lname, _args):
+                logger.warn(
+                STATS_RECEIVED_INVALID_STATISTICS_DATA,
+                _module_name)
+            else:
+                if self.update_statistics_data(
+                    self.module_name,
+                    self.cc_session.lname,
+                    {'last_update_time': get_datetime()}):
+                    logger.warn(
+                        STATS_RECEIVED_INVALID_STATISTICS_DATA,
+                        self.module_name)
+        # if successfully done, set the last time of polling
+        self._lasttime_poll = get_timestamp()
+
     def start(self):
         """
         Start stats module
@@ -481,6 +490,14 @@ class Stats:
         """
         handle show command
         """
+        # decide if polling should be done by the the last time of
+        # polling. If more than one seconds past since the last
+        # request to each module, the stats module requests each
+        # module statistics data and then shows the latest
+        # result. Otherwise, the stats module just shows statistics
+        # data which it has.
+        if get_timestamp() - self._lasttime_poll > 1.0:
+            self.do_polling()
         if owner or name:
             logger.debug(DBG_STATS_MESSAGING,
                          STATS_RECEIVED_SHOW_NAME_COMMAND,
diff --git a/src/bin/stats/tests/test_utils.py b/src/bin/stats/tests/test_utils.py
index d094047..a9f0a33 100644
--- a/src/bin/stats/tests/test_utils.py
+++ b/src/bin/stats/tests/test_utils.py
@@ -245,8 +245,8 @@ class MockBoss:
         self.spec_file.close()
         self.cc_session = self.mccs._session
         self.got_command_name = ''
-        self.pid_list = [[ 9999, "b10-auth"   ],
-                         [ 9998, "b10-auth-2" ]]
+        self.pid_list = [[ 9999, "b10-auth", "Auth" ],
+                         [ 9998, "b10-auth-2", "Auth" ]]
         self.statistics_data = {
             'boot_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', self._BASETIME)
             }
diff --git a/src/lib/python/isc/bind10/component.py b/src/lib/python/isc/bind10/component.py
index da2730c..9c29ace 100644
--- a/src/lib/python/isc/bind10/component.py
+++ b/src/lib/python/isc/bind10/component.py
@@ -371,6 +371,14 @@ class BaseComponent:
         """
         pass
 
+    def address(self):
+        """
+        Provides the name of the address used on the message bus
+
+        You need to provide this method in a concrete implementation.
+        """
+        pass
+
 class Component(BaseComponent):
     """
     The most common implementation of a component. It can be used either
@@ -454,6 +462,12 @@ class Component(BaseComponent):
             else:
                 self._procinfo.process.terminate()
 
+    def address(self):
+        """
+        Returns the name of the address used on the message bus
+        """
+        return self._address
+
 class Configurator:
     """
     This thing keeps track of configuration changes and starts and stops
diff --git a/src/lib/python/isc/bind10/tests/component_test.py b/src/lib/python/isc/bind10/tests/component_test.py
index af529f8..3f26870 100644
--- a/src/lib/python/isc/bind10/tests/component_test.py
+++ b/src/lib/python/isc/bind10/tests/component_test.py
@@ -164,6 +164,13 @@ class ComponentTests(BossUtils, unittest.TestCase):
         component = self.__create_component('core')
         self.assertEqual('No process', component.name())
 
+    def test_address(self):
+        """
+        Test the address provides whatever we passed to the constructor as process.
+        """
+        component = self.__create_component('core')
+        self.assertEqual("homeless", component.address())
+
     def test_guts(self):
         """
         Test the correct data are stored inside the component.



More information about the bind10-changes mailing list