Browse Source

[2676] Convert stats to use rpc_call

Most parts are converted, with one exception.

There's a place where many messages are sent at once and then it waits
for all the answers. This allows the other modules to process the
commands in parallel. The rpc_call is not flexible enough to allow this
(we'll need the rpc_call_async for that), so we stay with the original,
just adding the want_answer parameter.
Michal 'vorner' Vaner 12 years ago
parent
commit
09af4e2b9e
2 changed files with 28 additions and 43 deletions
  1. 22 24
      src/bin/stats/stats.py.in
  2. 6 19
      src/bin/stats/stats_httpd.py.in

+ 22 - 24
src/bin/stats/stats.py.in

@@ -251,14 +251,9 @@ class Stats:
         # It counts the number of instances of same module by
         # It counts the number of instances of same module by
         # examining the third value from the array result of
         # examining the third value from the array result of
         # 'show_processes' of Init
         # 'show_processes' of Init
-        seq = self.cc_session.group_sendmsg(
-            isc.config.ccsession.create_command("show_processes"),
-            'Init')
-        (answer, env) = self.cc_session.group_recvmsg(False, seq)
-        modules = []
-        if answer:
-            (rcode, value) = isc.config.ccsession.parse_answer(answer)
-            if rcode == 0 and type(value) is list:
+        try:
+            value = self.mccs.rpc_call('show_processes', 'Init')
+            if type(value) is list:
                 # NOTE: For example, the "show_processes" command
                 # NOTE: For example, the "show_processes" command
                 # of Init is assumed to return the response in this
                 # of Init is assumed to return the response in this
                 # format:
                 # format:
@@ -286,6 +281,10 @@ class Stats:
                 # release.
                 # release.
                 modules = [ v[2] if type(v) is list and len(v) > 2 \
                 modules = [ v[2] if type(v) is list and len(v) > 2 \
                                 else None for v in value ]
                                 else None for v in value ]
+        except isc.config.RPCError:
+            # TODO: Is it OK to just pass? As part of refactoring, preserving
+            # the original behaviour.
+            pass
         # start requesting each module to collect statistics data
         # start requesting each module to collect statistics data
         sequences = []
         sequences = []
         for (module_name, data) in self.get_statistics_data().items():
         for (module_name, data) in self.get_statistics_data().items():
@@ -296,7 +295,10 @@ class Stats:
                          module_name)
                          module_name)
             cmd = isc.config.ccsession.create_command(
             cmd = isc.config.ccsession.create_command(
                 "getstats", None) # no argument
                 "getstats", None) # no argument
-            seq = self.cc_session.group_sendmsg(cmd, module_name)
+            # Not using rpc_call here, we query a lot of modules in parallel
+            # here
+            seq = self.cc_session.group_sendmsg(cmd, module_name,
+                                                want_answer=True)
             sequences.append((module_name, seq))
             sequences.append((module_name, seq))
             cnt = modules.count(module_name)
             cnt = modules.count(module_name)
             if cnt > 1:
             if cnt > 1:
@@ -421,21 +423,17 @@ class Stats:
         raises StatsError.
         raises StatsError.
         """
         """
         modules = {}
         modules = {}
-        seq = self.cc_session.group_sendmsg(
-            isc.config.ccsession.create_command(
-                isc.config.ccsession.COMMAND_GET_STATISTICS_SPEC),
-            'ConfigManager')
-        (answer, env) = self.cc_session.group_recvmsg(False, seq)
-        if answer:
-            (rcode, value) = isc.config.ccsession.parse_answer(answer)
-            if rcode == 0:
-                for mod in value:
-                    spec = { "module_name" : mod }
-                    if value[mod] and type(value[mod]) is list:
-                        spec["statistics"] = value[mod]
-                    modules[mod] = isc.config.module_spec.ModuleSpec(spec)
-            else:
-                raise StatsError("Updating module spec fails: " + str(value))
+        try:
+            value = self.mccs.rpc_call(isc.config.ccsession. \
+                                       COMMAND_GET_STATISTICS_SPEC,
+                                       'ConfigManager')
+        except isc.config.RPCError as e:
+            raise StatsError("Updating module spec fails: " + str(e))
+        for mod in value:
+            spec = { "module_name" : mod }
+            if value[mod] and type(value[mod]) is list:
+                spec["statistics"] = value[mod]
+            modules[mod] = isc.config.module_spec.ModuleSpec(spec)
         modules[self.module_name] = self.mccs.get_module_spec()
         modules[self.module_name] = self.mccs.get_module_spec()
         self.modules = modules
         self.modules = modules
 
 

+ 6 - 19
src/bin/stats/stats_httpd.py.in

@@ -459,20 +459,13 @@ class StatsHttpd:
         if name is not None:
         if name is not None:
             param['name'] = name
             param['name'] = name
         try:
         try:
-            seq = self.cc_session.group_sendmsg(
-                isc.config.ccsession.create_command('show', param), 'Stats')
-            (answer, env) = self.cc_session.group_recvmsg(False, seq)
-            if answer:
-                (rcode, value) = isc.config.ccsession.parse_answer(answer)
+            return self.mccs.rpc_call('show', 'Stats', params=param)
+        except isc.config.RPCError as e:
+            raise StatsHttpdDataError("Stats module: %s" % str(e))
         except (isc.cc.session.SessionTimeout,
         except (isc.cc.session.SessionTimeout,
                 isc.cc.session.SessionError) as err:
                 isc.cc.session.SessionError) as err:
             raise StatsHttpdError("%s: %s" %
             raise StatsHttpdError("%s: %s" %
                                   (err.__class__.__name__, err))
                                   (err.__class__.__name__, err))
-        else:
-            if rcode == 0:
-                return value
-            else:
-                raise StatsHttpdDataError("Stats module: %s" % str(value))
 
 
     def get_stats_spec(self, owner=None, name=None):
     def get_stats_spec(self, owner=None, name=None):
         """Requests statistics data to the Stats daemon and returns
         """Requests statistics data to the Stats daemon and returns
@@ -493,15 +486,9 @@ class StatsHttpd:
         if name is not None:
         if name is not None:
             param['name'] = name
             param['name'] = name
         try:
         try:
-            seq = self.cc_session.group_sendmsg(
-                isc.config.ccsession.create_command('showschema', param), 'Stats')
-            (answer, env) = self.cc_session.group_recvmsg(False, seq)
-            if answer:
-                (rcode, value) = isc.config.ccsession.parse_answer(answer)
-                if rcode == 0:
-                    return value
-                else:
-                    raise StatsHttpdDataError("Stats module: %s" % str(value))
+            return self.mccs.rpc_call('showschema', 'Stats', params=param)
+        except isc.config.RPCError as e:
+            raise StatsHttpdDataError("Stats module: %s" % str(e))
         except (isc.cc.session.SessionTimeout,
         except (isc.cc.session.SessionTimeout,
                 isc.cc.session.SessionError) as err:
                 isc.cc.session.SessionError) as err:
             raise StatsHttpdError("%s: %s" %
             raise StatsHttpdError("%s: %s" %