1
0
Fork 0

Make _vpack of AgencyCommResult abstract.

This commit is contained in:
Max Neunhoeffer 2016-05-04 16:49:02 +02:00
parent cd39a884f9
commit cae72d0d61
6 changed files with 37 additions and 24 deletions

View File

@ -67,7 +67,7 @@ void AgencyCallback::refetchAndUpdate() {
kv.erase(std::remove(kv.begin(), kv.end(), ""), kv.end());
std::shared_ptr<VPackBuilder> newData = std::make_shared<VPackBuilder>();
newData->add(result._vpack->slice()[0].get(kv));
newData->add(result.slice()[0].get(kv));
checkValue(newData);

View File

@ -453,6 +453,13 @@ VPackSlice AgencyCommResult::parse(std::string const& path) {
return _vpack->slice()[0].get(pv);
}
////////////////////////////////////////////////////////////////////////////////
/// get results of query as slice
////////////////////////////////////////////////////////////////////////////////
VPackSlice AgencyCommResult::slice() {
return _vpack->slice();
}
////////////////////////////////////////////////////////////////////////////////
/// @brief the static global URL prefix
@ -1371,14 +1378,14 @@ AgencyCommResult AgencyComm::getValues2(std::string const& key) {
try {
result._vpack = VPackParser::fromJson(result.body().c_str());
result.setVPack(VPackParser::fromJson(result.body().c_str()));
if (!result._vpack->slice().isArray()) {
if (!result.slice().isArray()) {
result._statusCode = 500;
return result;
}
if (result._vpack->slice().length() != 1) {
if (result.slice().length() != 1) {
result._statusCode = 500;
return result;
}

View File

@ -403,13 +403,19 @@ struct AgencyCommResult {
bool parse(std::string const&, bool);
VPackSlice parse(std::string const&);
VPackSlice slice();
void setVPack(std::shared_ptr<velocypack::Builder> vpack) {
_vpack = vpack;
}
private:
std::shared_ptr<velocypack::Builder> _vpack;
public:
std::string _location;
std::string _message;
std::string _body;
std::string _realBody;
std::shared_ptr<velocypack::Builder> _vpack;
std::map<std::string, AgencyCommResultEntry> _values;
uint64_t _index;

View File

@ -474,7 +474,7 @@ void ClusterInfo::loadPlan() {
}
if (result.successful()) {
VPackSlice slice = result._vpack->slice()[0].get(
VPackSlice slice = result.slice()[0].get(
std::vector<std::string>({AgencyComm::prefixStripped(), "Plan"}));
auto planBuilder = std::make_shared<VPackBuilder>();
planBuilder->add(slice);
@ -568,7 +568,7 @@ void ClusterInfo::loadCurrentDatabases() {
if (result.successful()) {
velocypack::Slice databases =
result._vpack->slice()[0].get(std::vector<std::string>(
result.slice()[0].get(std::vector<std::string>(
{AgencyComm::prefixStripped(), "Current", "Databases"}));
if (!databases.isNone()) {
@ -648,7 +648,7 @@ void ClusterInfo::loadPlannedCollections() {
if (result.successful()) {
velocypack::Slice databases =
result._vpack->slice()[0].get(std::vector<std::string>(
result.slice()[0].get(std::vector<std::string>(
{AgencyComm::prefixStripped(), "Plan", "Collections"}));
if (!databases.isNone()) {
@ -850,7 +850,7 @@ void ClusterInfo::loadCurrentCollections() {
if (result.successful()) {
velocypack::Slice databases =
result._vpack->slice()[0].get(std::vector<std::string>(
result.slice()[0].get(std::vector<std::string>(
{AgencyComm::prefixStripped(), "Current", "Collections"}));
if (!databases.isNone()) {
@ -1433,7 +1433,7 @@ int ClusterInfo::setCollectionPropertiesCoordinator(
}
velocypack::Slice collection =
res._vpack->slice()[0]
res.slice()[0]
.get(AgencyComm::prefixStripped())
.get("Plan").get("Collections").get(databaseName).get(collectionID);
@ -1505,7 +1505,7 @@ int ClusterInfo::setCollectionStatusCoordinator(
res = ac.getValues2("Plan/Collections/" + databaseName +"/" + collectionID);
velocypack::Slice col =
res._vpack->slice()[0]
res.slice()[0]
.get(AgencyComm::prefixStripped()).get("Plan").get("Collections")
.get(databaseName).get(collectionID);
@ -1700,7 +1700,7 @@ int ClusterInfo::ensureIndexCoordinator(
bool usePrevious = true;
velocypack::Slice database =
previous._vpack->slice()[0].get(std::vector<std::string>(
previous.slice()[0].get(std::vector<std::string>(
{ AgencyComm::prefixStripped(), "Plan", "Collections", databaseName }));
if (!database.isObject()) {
@ -1850,7 +1850,7 @@ int ClusterInfo::ensureIndexCoordinator(
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
errorMsg);
}
VPackSlice versionSlice = res._vpack->slice()[0].get(
VPackSlice versionSlice = res.slice()[0].get(
std::vector<std::string>({ac.prefixStripped(), "Current", "Version"}));
if (!versionSlice.isInteger()) {
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
@ -1894,7 +1894,7 @@ int ClusterInfo::dropIndexCoordinator(std::string const& databaseName,
AgencyCommResult res = ac.getValues2(key);
velocypack::Slice previous =
res._vpack->slice()[0].get(std::vector<std::string>(
res.slice()[0].get(std::vector<std::string>(
{ AgencyComm::prefixStripped(), "Plan", "Collections", databaseName, collectionID }
));
TRI_ASSERT(VPackObjectIterator(previous).size()>0);
@ -2078,7 +2078,7 @@ int ClusterInfo::dropIndexCoordinator(std::string const& databaseName,
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
errorMsg);
}
VPackSlice versionSlice = res._vpack->slice()[0].get(
VPackSlice versionSlice = res.slice()[0].get(
std::vector<std::string>({ac.prefixStripped(), "Current", "Version"}));
if (!versionSlice.isInteger()) {
return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION,
@ -2124,7 +2124,7 @@ void ClusterInfo::loadServers() {
if (result.successful()) {
velocypack::Slice serversRegistered =
result._vpack->slice()[0].get(std::vector<std::string>(
result.slice()[0].get(std::vector<std::string>(
{AgencyComm::prefixStripped(), "Current", "ServersRegistered"}));
if (!serversRegistered.isNone()) {
@ -2256,7 +2256,7 @@ void ClusterInfo::loadCurrentCoordinators() {
if (result.successful()) {
velocypack::Slice currentCoordinators =
result._vpack->slice()[0].get(std::vector<std::string>(
result.slice()[0].get(std::vector<std::string>(
{AgencyComm::prefixStripped(), "Current", "Coordinators"}));
if (!currentCoordinators.isNone()) {
@ -2313,7 +2313,7 @@ void ClusterInfo::loadCurrentDBServers() {
if (result.successful()) {
velocypack::Slice currentDBServers =
result._vpack->slice()[0].get(std::vector<std::string>(
result.slice()[0].get(std::vector<std::string>(
{AgencyComm::prefixStripped(), "Current", "DBServers"}));
if (!currentDBServers.isNone()) {

View File

@ -193,7 +193,7 @@ void HeartbeatThread::runDBServer() {
LOG(ERR) << "Could not read Current/Version from agency.";
} else {
VPackSlice s
= res._vpack->slice()[0].get(std::vector<std::string>(
= res.slice()[0].get(std::vector<std::string>(
{_agency.prefixStripped(), std::string("Current"),
std::string("Version")}));
if (!s.isInteger()) {
@ -326,7 +326,7 @@ void HeartbeatThread::runCoordinator() {
if (result.successful()) {
VPackSlice versionSlice
= result._vpack->slice()[0].get(std::vector<std::string>(
= result.slice()[0].get(std::vector<std::string>(
{_agency.prefixStripped(), "Plan", "Version"}));
if (versionSlice.isInteger()) {
@ -354,7 +354,7 @@ void HeartbeatThread::runCoordinator() {
if (result.successful()) {
velocypack::Slice slice =
result._vpack->slice()[0].get(std::vector<std::string>(
result.slice()[0].get(std::vector<std::string>(
{_agency.prefixStripped(), "Sync", "UserVersion"}));
if (slice.isInteger()) {
@ -401,7 +401,7 @@ void HeartbeatThread::runCoordinator() {
if (result.successful()) {
VPackSlice versionSlice
= result._vpack->slice()[0].get(std::vector<std::string>(
= result.slice()[0].get(std::vector<std::string>(
{_agency.prefixStripped(), "Plan", "Version"}));
if (versionSlice.isInteger()) {
@ -533,7 +533,7 @@ bool HeartbeatThread::handlePlanChangeCoordinator(uint64_t currentPlanVersion) {
std::vector<TRI_voc_tick_t> ids;
velocypack::Slice databases =
result._vpack->slice()[0].get(std::vector<std::string>(
result.slice()[0].get(std::vector<std::string>(
{AgencyComm::prefixStripped(), "Plan", "Databases"}));
if (!databases.isObject()) {

View File

@ -239,7 +239,7 @@ static void JS_GetAgency(v8::FunctionCallbackInfo<v8::Value> const& args) {
// return just the value for each key
for (auto const& a : VPackArrayIterator(result._vpack->slice())) {
for (auto const& a : VPackArrayIterator(result.slice())) {
for (auto const& o : VPackObjectIterator(a)) {
std::string const key = o.key.copyString();