Skip to content

Commit

Permalink
Merge "Additional Sandesh Api to connect to different set of Collectors"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Nov 10, 2016
2 parents 8b6c138 + 7a5c113 commit f9c7f96
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
11 changes: 7 additions & 4 deletions library/cpp/sandesh.cc
Expand Up @@ -202,6 +202,13 @@ bool Sandesh::ConnectToCollector(const std::string &collector_ip,
return true;
}

void Sandesh::ReConfigCollectors(std::vector<std::string> list) {
if (client_) {
client_->ReConfigCollectors(list);
}
}


static bool make_endpoint(TcpServer::Endpoint& ep,const std::string& epstr) {

typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions library/cpp/sandesh.h
Expand Up @@ -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<std::string> list);
static void Uninit();

// Disk Usage
Expand Down
45 changes: 43 additions & 2 deletions library/cpp/sandesh_client.cc
Expand Up @@ -31,15 +31,14 @@
#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;
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";
Expand Down Expand Up @@ -100,6 +99,48 @@ void SandeshClient::CollectorHandler(std::vector<DSResponse> resp) {
}
}

void SandeshClient::ReConfigCollectors(std::vector<std::string> collector_list) {

Endpoint primary = Endpoint();
Endpoint secondary = Endpoint();

std::vector<std::string> 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())
Expand Down
1 change: 1 addition & 0 deletions library/cpp/sandesh_client.h
Expand Up @@ -91,6 +91,7 @@ class SandeshClient : public TcpServer, public SandeshClientSM::Mgr {
void ResetSessionWaterMarkInfo();
void GetSessionWaterMarkInfo(
std::vector<Sandesh::QueueWaterMarkInfo> &scwm_info) const;
void ReConfigCollectors(std::vector<std::string>);

friend class CollectorInfoRequest;
protected:
Expand Down

0 comments on commit f9c7f96

Please sign in to comment.