diff --git a/library/cpp/sandesh.cc b/library/cpp/sandesh.cc index 04892f51..680439f4 100644 --- a/library/cpp/sandesh.cc +++ b/library/cpp/sandesh.cc @@ -202,6 +202,13 @@ bool Sandesh::ConnectToCollector(const std::string &collector_ip, return true; } +void Sandesh::ReConfigCollectors(std::vector list) { + if (client_) { + client_->ReConfigCollectors(list); + } +} + + static bool make_endpoint(TcpServer::Endpoint& ep,const std::string& epstr) { typedef boost::tokenizer > tokenizer; @@ -245,10 +252,6 @@ bool Sandesh::InitClient(EventManager *evm, } } } - if (collectors.size()>2) { - SANDESH_LOG(ERROR, __func__ << " Too many collectors"); - return false; - } client_ = new SandeshClient(evm, primary, secondary, csf, true); diff --git a/library/cpp/sandesh.h b/library/cpp/sandesh.h index 1824a502..dc2f4fa6 100644 --- a/library/cpp/sandesh.h +++ b/library/cpp/sandesh.h @@ -186,6 +186,7 @@ class Sandesh { SandeshContext *client_context = NULL); static bool ConnectToCollector(const std::string &collector_ip, int collector_port, bool periodicuve = false); + static void ReConfigCollectors(std::vector list); static void Uninit(); // Disk Usage diff --git a/library/cpp/sandesh_client.cc b/library/cpp/sandesh_client.cc index 320a59a6..8dacaf40 100644 --- a/library/cpp/sandesh_client.cc +++ b/library/cpp/sandesh_client.cc @@ -31,6 +31,7 @@ #include "sandesh_client.h" #include "sandesh_uve.h" +using boost::asio::ip::address; using namespace boost::asio; using boost::system::error_code; using std::string; @@ -38,8 +39,6 @@ using std::map; using std::make_pair; using std::vector; -using boost::system::error_code; - const std::string SandeshClient::kSMTask = "sandesh::SandeshClientSM"; const std::string SandeshClient::kSessionWriterTask = "sandesh::SandeshClientSession"; const std::string SandeshClient::kSessionReaderTask = "sandesh::SandeshClientReader"; @@ -100,6 +99,48 @@ void SandeshClient::CollectorHandler(std::vector resp) { } } +void SandeshClient::ReConfigCollectors(std::vector collector_list) { + + Endpoint primary = Endpoint(); + Endpoint secondary = Endpoint(); + + std::vector ep; + uint32_t port; + address addr; + boost::system::error_code ec; + if (collector_list.size()>=1) { + boost::split(ep, collector_list[0], boost::is_any_of(":")); + + addr = address::from_string(ep[0], ec); + if (ec) { + SANDESH_LOG(ERROR, "ReConfig for primary failed Error: " << ec); + return; + } + primary.address(addr); + port = strtoul(ep[1].c_str(), NULL, 0); + primary.port(port); + + SANDESH_LOG(INFO, "ReConfig for primary " << primary); + } + if (collector_list.size()>=2) { + boost::split(ep, collector_list[1], boost::is_any_of(":")); + + addr = address::from_string(ep[0], ec); + if (ec) { + SANDESH_LOG(ERROR, "ReConfig for secondary failed Error: " << ec); + return; + } + secondary.address(addr); + port = strtoul(ep[1].c_str(), NULL, 0); + secondary.port(port); + + SANDESH_LOG(INFO, "ReConfig for secondary " << secondary); + } + if (primary!=Endpoint()) { + sm_->SetCandidates(primary, secondary); + } +} + void SandeshClient::Initiate() { sm_->SetAdminState(false); if (primary_ != Endpoint()) diff --git a/library/cpp/sandesh_client.h b/library/cpp/sandesh_client.h index 39dfdc82..65fc8e80 100644 --- a/library/cpp/sandesh_client.h +++ b/library/cpp/sandesh_client.h @@ -91,6 +91,7 @@ class SandeshClient : public TcpServer, public SandeshClientSM::Mgr { void ResetSessionWaterMarkInfo(); void GetSessionWaterMarkInfo( std::vector &scwm_info) const; + void ReConfigCollectors(std::vector); friend class CollectorInfoRequest; protected: