From ec10fee3bd3f7fb61391ad656647de34fe12721c Mon Sep 17 00:00:00 2001 From: Jelte Jansen Date: Tue, 22 Dec 2009 09:38:48 +0000 Subject: [PATCH] don't send config if it is None removed catch-all in ccsession (i want to get the original exception) check result size after get_config in parkinglot git-svn-id: svn://bind10.isc.org/svn/bind10/branches/jelte-datadef@397 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/parkinglot/ccsession.cc | 56 +++++++++++++-------------- src/lib/bind-cfgd/python/bind-cfgd.py | 6 ++- src/lib/cc/cpp/data.h | 2 + 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/bin/parkinglot/ccsession.cc b/src/bin/parkinglot/ccsession.cc index bd4d3c5be3..b8ac747a20 100644 --- a/src/bin/parkinglot/ccsession.cc +++ b/src/bin/parkinglot/ccsession.cc @@ -82,39 +82,37 @@ CommandSession::CommandSession(std::string module_name, config_handler_ = config_handler; command_handler_ = command_handler; - try { - // todo: workaround, let boss wait until msgq is started - // and remove sleep here - sleep(1); + // todo: workaround, let boss wait until msgq is started + // and remove sleep here + sleep(1); - ElementPtr answer, env; + ElementPtr answer, env; - session_.establish(); - session_.subscribe(module_name, "*"); - session_.subscribe("Boss", "*", "meonly"); - session_.subscribe("ConfigManager", "*", "meonly"); - session_.subscribe("statistics", "*", "meonly"); - read_data_definition(spec_file_name); - sleep(1); - // send the data specification - session_.group_sendmsg(data_definition_.getDefinition(), "ConfigManager"); + session_.establish(); + session_.subscribe(module_name, "*"); + session_.subscribe("Boss", "*", "meonly"); + session_.subscribe("ConfigManager", "*", "meonly"); + session_.subscribe("statistics", "*", "meonly"); + read_data_definition(spec_file_name); + sleep(1); + // send the data specification + session_.group_sendmsg(data_definition_.getDefinition(), "ConfigManager"); + session_.group_recvmsg(env, answer, false); + + // get any stored configuration from the manager + if (config_handler_) { + ElementPtr cmd = Element::create_from_string("{ \"command\": [ \"get_config\", \"" + module_name + "\" ] }"); + session_.group_sendmsg(cmd, "ConfigManager"); session_.group_recvmsg(env, answer, false); - - // get any stored configuration from the manager - if (config_handler_) { - ElementPtr cmd = Element::create_from_string("{ \"command\": [ \"get_config\", \"" + module_name + "\" ] }"); - session_.group_sendmsg(cmd, "ConfigManager"); - session_.group_recvmsg(env, answer, false); - cout << "[XX] got config: " << endl << answer->str() << endl; - // replace string_value and "0" with int_value and 0 with new cc after merge */ - if (answer->contains("result") && answer->get("result")->get(0)->string_value() == "0") { - config_handler(answer->get("result")->get(1)); - } else { - cout << "[XX] no result in answer" << endl; - } + cout << "[XX] got config: " << endl << answer->str() << endl; + // replace string_value and "0" with int_value and 0 with new cc after merge */ + if (answer->contains("result") && + answer->get("result")->get(0)->string_value() == "0" && + answer->get("result")->size() > 1) { + config_handler(answer->get("result")->get(1)); + } else { + cout << "[XX] no result in answer" << endl; } - } catch (...) { - throw std::runtime_error("SessionManager: failed to open sessions"); } } diff --git a/src/lib/bind-cfgd/python/bind-cfgd.py b/src/lib/bind-cfgd/python/bind-cfgd.py index 8697ebde80..ea7f5375ea 100644 --- a/src/lib/bind-cfgd/python/bind-cfgd.py +++ b/src/lib/bind-cfgd/python/bind-cfgd.py @@ -108,7 +108,10 @@ class ConfigManager: pass else: conf_part = self.config.data - answer["result"] = [ 0, conf_part ] + if conf_part: + answer["result"] = [ 0, conf_part ] + else: + answer["result"] = [ 0 ] elif cmd[0] == "set_config": if len(cmd) == 3: # todo: use api (and check types?) @@ -162,7 +165,6 @@ class ConfigManager: if "config_data" in spec: self.set_config(spec["module_name"], spec["config_data"]) self.cc.group_sendmsg({ "specification_update": [ spec["module_name"], spec["config_data"] ] }, "BigTool") - print("[XX] sent spec_update") if "commands" in spec: self.set_commands(spec["module_name"], spec["commands"]) self.cc.group_sendmsg({ "commands_update": [ spec["module_name"], spec["commands"] ] }, "BigTool") diff --git a/src/lib/cc/cpp/data.h b/src/lib/cc/cpp/data.h index 39bce5f503..d1bed27656 100644 --- a/src/lib/cc/cpp/data.h +++ b/src/lib/cc/cpp/data.h @@ -99,6 +99,7 @@ namespace ISC { namespace Data { virtual void set(const int i, ElementPtr element) { throw TypeError(); }; virtual void add(ElementPtr element) { throw TypeError(); }; virtual void remove(ElementPtr element) { throw TypeError(); }; + virtual size_t size() { throw TypeError(); }; // for maps virtual ElementPtr get(const std::string& name) { throw TypeError(); } ; @@ -236,6 +237,7 @@ namespace ISC { namespace Data { std::string str(); std::string str_xml(size_t prefix = 0); std::string to_wire(int omit_length = 1); + size_t size() { return l.size(); } }; class MapElement : public Element {