From: Michal 'vorner' Vaner Date: Fri, 15 Feb 2013 11:47:12 +0000 (+0100) Subject: [2676] Convert stats to use rpc_call X-Git-Tag: bind10-1.1.0beta1-release~83^2~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=09af4e2b9e9b2840dd475ef112d485e3476badd1;p=thirdparty%2Fkea.git [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. --- diff --git a/src/bin/stats/stats.py.in b/src/bin/stats/stats.py.in index 0af09337ee..925ba53324 100755 --- a/src/bin/stats/stats.py.in +++ b/src/bin/stats/stats.py.in @@ -251,14 +251,9 @@ class Stats: # It counts the number of instances of same module by # examining the third value from the array result of # '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 # of Init is assumed to return the response in this # format: @@ -286,6 +281,10 @@ class Stats: # release. modules = [ v[2] if type(v) is list and len(v) > 2 \ 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 sequences = [] for (module_name, data) in self.get_statistics_data().items(): @@ -296,7 +295,10 @@ class Stats: module_name) cmd = isc.config.ccsession.create_command( "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)) cnt = modules.count(module_name) if cnt > 1: @@ -421,21 +423,17 @@ class Stats: raises StatsError. """ 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() self.modules = modules diff --git a/src/bin/stats/stats_httpd.py.in b/src/bin/stats/stats_httpd.py.in index 367f56e6c1..f42b1d1a44 100755 --- a/src/bin/stats/stats_httpd.py.in +++ b/src/bin/stats/stats_httpd.py.in @@ -459,20 +459,13 @@ class StatsHttpd: if name is not None: param['name'] = name 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, isc.cc.session.SessionError) as err: raise StatsHttpdError("%s: %s" % (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): """Requests statistics data to the Stats daemon and returns @@ -493,15 +486,9 @@ class StatsHttpd: if name is not None: param['name'] = name 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, isc.cc.session.SessionError) as err: raise StatsHttpdError("%s: %s" %