Browse Source

let parkinglot receive config_update command and serve the zones from there

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/jelte-datadef@347 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 15 years ago
parent
commit
171781db2c

+ 1 - 1
src/bin/bigtool/run_bigtool.py

@@ -106,7 +106,7 @@ if __name__ == '__main__':
         tool = BigTool(cc)
         cc.group_sendmsg({ "command": ["get_commands"] }, "ConfigManager")
         command_spec, env =  cc.group_recvmsg(False)
-        prepare_commands(tool, command_spec["result"])
+        prepare_commands(tool, command_spec["result"][1])
         prepare_config_commands(tool)
         _prepare_fake_data(tool)   
         tool.cmdloop()

+ 12 - 6
src/bin/parkinglot/ccsession.cc

@@ -81,7 +81,7 @@ CommandSession::CommandSession() :
         // and remove sleep here
         sleep(1);
         session_.establish();
-        session_.subscribe("ParkingLot", "*", "meonly");
+        session_.subscribe("ParkingLot", "*");
         session_.subscribe("Boss", "*", "meonly");
         session_.subscribe("ConfigManager", "*", "meonly");
         session_.subscribe("statistics", "*", "meonly");
@@ -102,11 +102,11 @@ CommandSession::getSocket()
     return (session_.getSocket());
 }
 
-std::pair<std::string, std::string>
+std::pair<std::string, ElementPtr>
 CommandSession::getCommand(int counter) {
     ElementPtr cmd, routing, data, ep;
     string s;
-
+    cout << "[XX] PARKINGLOT GOT MESSAGE" << endl;
     session_.group_recvmsg(routing, data, false);
     string channel = routing->get("group")->string_value();
 
@@ -123,16 +123,21 @@ CommandSession::getCommand(int counter) {
             session_.group_sendmsg(resp, "statistics");
         }
     } else {
+        cout << "[parkinglot] saw message: " << data << endl;
         cmd = data->get("zone_added");
         if (cmd != NULL)
-            return std::pair<string, string>("addzone", cmd->string_value());
+            return std::pair<string, ElementPtr>("addzone", cmd);
         cmd = data->get("zone_deleted");
         if (cmd != NULL) {
-            return std::pair<string, string>("delzone", cmd->string_value());
+            return std::pair<string, ElementPtr>("delzone", cmd);
+        }
+        cmd = data->get("config_update");
+        if (cmd != NULL) {
+            return std::pair<string, ElementPtr>("config_update", cmd);
         }
     }
 
-    return std::pair<string, string>("unknown", "");
+    return std::pair<string, ElementPtr>("unknown", ElementPtr());
 }
 
 // should be replaced by the general config-getter in cc setup
@@ -144,6 +149,7 @@ CommandSession::getZones() {
     session_.group_sendmsg(cmd, "ConfigManager");
     session_.group_recvmsg(env, result, false);
     BOOST_FOREACH(ElementPtr zone_name, result->get("result")->list_value()) {
+        cout << "[XX] add zone: " << zone_name->string_value() << endl;
         zone_names.push_back(zone_name->string_value());
     }
     return zone_names;

+ 1 - 1
src/bin/parkinglot/ccsession.h

@@ -27,7 +27,7 @@ class CommandSession {
 public:
     CommandSession();
     int getSocket();
-    std::pair<std::string, std::string> getCommand(int counter);
+    std::pair<std::string, ISC::Data::ElementPtr> getCommand(int counter);
     std::vector<std::string> getZones();
 private:
 	void read_data_definition(const std::string& filename);

+ 2 - 1
src/bin/parkinglot/main.cc

@@ -31,6 +31,7 @@
 #include <dns/message.h>
 
 #include <cc/cpp/session.h>
+#include <cc/cpp/data.h>
 
 #include "zoneset.h"
 #include "parkinglot.h"
@@ -100,7 +101,7 @@ main(int argc, char* argv[]) {
         }
 
         if (FD_ISSET(ss, &fds)) {
-            pair<string,string> cmd = cs.getCommand(counter);
+            pair<string, ISC::Data::ElementPtr> cmd = cs.getCommand(counter);
             plot.command(cmd);
         }
     }

+ 18 - 3
src/bin/parkinglot/parkinglot.cc

@@ -28,14 +28,19 @@
 #include <dns/rrset.h>
 #include <dns/message.h>
 
+#include <cc/cpp/data.h>
+
 #include "common.h"
 #include "parkinglot.h"
 
+#include <boost/foreach.hpp>
+
 using namespace std;
 
 using namespace isc::dns;
 using namespace isc::dns::Rdata::IN;
 using namespace isc::dns::Rdata::Generic;
+using namespace ISC::Data;
 
 ParkingLot::ParkingLot(int port) {
     ns1 = Rdata::RdataPtr(new NS("ns1.parking.example"));
@@ -184,13 +189,23 @@ ParkingLot::processMessage() {
 }
 
 void
-ParkingLot::command(pair<string,string> cmd) {
+ParkingLot::command(pair<string,ElementPtr> cmd) {
     if (cmd.first == "addzone")
-        serve(cmd.second);
+        serve(cmd.second->string_value());
     else if (cmd.first == "delzone")
-        zones.forget(cmd.second);
+        zones.forget(cmd.second->string_value());
     else if (cmd.first == "shutdown")
         exit(0);
+    else if (cmd.first == "config_update") {
+        // what to do with port settings?
+        ElementPtr zonelist_el = (cmd.second)->get("zones");
+        // We could walk through both lists and remove and serve
+        // accordingly, or simply clear all and add everything
+        zones.clear_zones();
+        BOOST_FOREACH(ElementPtr zone, zonelist_el->list_value()) {
+            zones.serve(zone->string_value());
+        }
+    }
 }
 
 void

+ 2 - 1
src/bin/parkinglot/parkinglot.h

@@ -18,6 +18,7 @@
 #define __PARKINGLOT_H 1
 
 #include "zoneset.h"
+#include <cc/cpp/data.h>
 
 class ParkingLot {
 public:
@@ -25,7 +26,7 @@ public:
     virtual ~ParkingLot() {}
     int getSocket() { return (sock); }
     void processMessage();
-    void command(std::pair<std::string,std::string>);
+    void command(std::pair<std::string,ISC::Data::ElementPtr>);
     void serve(std::string zone_name);
     
 private:

+ 3 - 0
src/bin/parkinglot/zoneset.h

@@ -29,6 +29,9 @@ class ZoneSet : std::set<std::string> {
             std::cout << "no longer serving: " << s << std::endl;
             this->erase(s);
         }
+        void clear_zones() {
+            this->clear();
+        }
         bool contains(std::string s) {
             return (this->find(s) != this->end());
         }

+ 8 - 5
src/lib/bind-cfgd/python/bind-cfgd.py

@@ -86,7 +86,7 @@ class ConfigManager:
             cmd = msg["command"]
             try:
                 if cmd[0] == "get_commands":
-                    answer["result"] = self.commands
+                    answer["result"] = [ 0, self.commands ]
                 elif cmd[0] == "get_data_spec":
                     if len(cmd) > 1 and cmd[1] != "":
                         try:
@@ -107,10 +107,6 @@ class ConfigManager:
                         conf_part = self.config.data
                     answer["result"] = [ 0, conf_part ]
                 elif cmd[0] == "set_config":
-                    print("[XX] cmd len: " + str(len(cmd)))
-                    print("[XX] cmd 0: " + str(cmd[0]))
-                    print("[XX] cmd 1: " + str(cmd[1]))
-                    print("[XX] cmd 2: " + str(cmd[2]))
                     if len(cmd) == 3:
                         # todo: use api (and check types?)
                         if cmd[1] != "":
@@ -121,10 +117,16 @@ class ConfigManager:
                             conf_part = self.config.data
                         conf_part.update(cmd[2])
                         # send out changed info
+                        print("[XX][bind-cfgd] send update of part: " + cmd[1])
+                        self.cc.group_sendmsg({ "config_update": conf_part }, cmd[1])
                         answer["result"] = [ 0 ]
                     elif len(cmd) == 2:
                         self.config.data.update(cmd[1])
                         # send out changed info
+                        print("[XX][bind-cfgd] send update of all")
+                        for module in self.config.data:
+                            print("[XX][bind-cfgd] send update of part: " + module)
+                            self.cc.group_sendmsg({ "config_update": self.config.data[module] }, module)
                         answer["result"] = [ 0 ]
                     else:
                         answer["result"] = [ 1, "Wrong number of arguments" ]
@@ -145,6 +147,7 @@ class ConfigManager:
             except IndexError as ie:
                 print("missing argument")
                 answer["result"] = [ 1, "Missing argument in command: " + str(ie) ]
+                raise ie
         elif "data_specification" in msg:
             # todo: validate? (no direct access to spec as
             spec = msg["data_specification"]

+ 4 - 1
src/lib/cc/python/ISC/CC/data.py

@@ -187,7 +187,10 @@ class UIConfigData():
         """Sends the changes configuration values to the config manager.
            If the command succeeds, the changes are re-requested and
            the changed list is reset"""
-        cc.group_sendmsg({ "command": [ "set_config", self.module_name, self.config_changes ]}, "ConfigManager")
+        if self.module_name and self.module_name != "":
+            cc.group_sendmsg({ "command": [ "set_config", self.module_name, self.config_changes ]}, "ConfigManager")
+        else:
+            cc.group_sendmsg({ "command": [ "set_config", self.config_changes ]}, "ConfigManager")
         answer, env = cc.group_recvmsg(False)
         if 'result' in answer and type(answer['result']) == list:
             # TODO: with the new cc implementation, replace "0" by 0