1
0
Fork 0

agency configuration persisted to state machine

This commit is contained in:
Kaveh Vahedipour 2016-08-30 14:41:28 +02:00
parent c3ed09f642
commit c8178239e1
5 changed files with 42 additions and 1 deletions

View File

@ -559,6 +559,23 @@ bool Agent::lead() {
guard.broadcast();
}
// Agency configuration
auto agency = std::make_shared<Builder>();
agency->openArray();
agency->openArray();
agency->openObject();
agency->add(".agency", VPackValue(VPackValueType::Object));
agency->add("term", VPackValue(term()));
agency->add("id", VPackValue(id()));
agency->add("active", _config.activeToBuilder()->slice());
agency->add("pool", _config.poolToBuilder()->slice());
agency->close();
agency->close();
agency->close();
agency->close();
write(agency);
// Wake up supervision
_supervision.wakeUp();

View File

@ -243,6 +243,19 @@ query_t config_t::activeToBuilder () const {
return ret;
}
query_t config_t::activeAgentsToBuilder () const {
query_t ret = std::make_shared<arangodb::velocypack::Builder>();
ret->openObject();
{
READ_LOCKER(readLocker, _lock);
for (auto const& i : _active) {
ret->add(i, VPackValue(_pool.at(i)));
}
}
ret->close();
return ret;
}
query_t config_t::poolToBuilder () const {
query_t ret = std::make_shared<arangodb::velocypack::Builder>();
ret->openObject();

View File

@ -142,6 +142,7 @@ struct config_t {
/// @brief of active agents
query_t activeToBuilder () const;
query_t activeAgentsToBuilder () const;
query_t poolToBuilder () const;

View File

@ -130,6 +130,9 @@ RestHandler::status RestAgencyPrivHandler::execute() {
return reportBadQuery(); // bad query
}
} else if (_request->suffix()[0] == "gossip") {
if (_request->requestType() != GeneralRequest::RequestType::POST) {
return reportMethodNotAllowed();
}
arangodb::velocypack::Options options;
query_t query = _request->toVelocyPackBuilderPtr(&options);
try {
@ -140,6 +143,11 @@ RestHandler::status RestAgencyPrivHandler::execute() {
} catch (std::exception const& e) {
return reportBadQuery(e.what());
}
} else if (_request->suffix()[0] == "activeAgents") {
if (_request->requestType() != GeneralRequest::RequestType::GET) {
return reportMethodNotAllowed();
}
result.add("active", _agent->config().activeAgentsToBuilder()->slice());
} else if (_request->suffix()[0] == "inform") {
arangodb::velocypack::Options options;
query_t query = _request->toVelocyPackBuilderPtr(&options);

View File

@ -316,7 +316,9 @@ bool Supervision::updateSnapshot() {
if (_agent == nullptr || this->isStopping()) {
return false;
}
_snapshot = _agent->readDB().get(_agencyPrefix);
try {
_snapshot = _agent->readDB().get(_agencyPrefix);
} catch (...) {}
return true;
}