Exemplo n.º 1
0
int RestoreFeature::sendRestoreIndexes(VPackSlice const& slice,
                                       std::string& errorMsg) {
  std::string const url = "/_api/replication/restore-indexes?force=" +
                          std::string(_force ? "true" : "false");
  std::string const body = slice.toJson();

  std::unique_ptr<SimpleHttpResult> response(_httpClient->request(
      GeneralRequest::RequestType::PUT, url, body.c_str(), body.size()));

  if (response == nullptr || !response->isComplete()) {
    errorMsg =
        "got invalid response from server: " + _httpClient->getErrorMessage();

    return TRI_ERROR_INTERNAL;
  }

  if (response->wasHttpError()) {
    int err;
    errorMsg = getHttpErrorMessage(response.get(), &err);

    if (err != TRI_ERROR_NO_ERROR) {
      return err;
    }

    return TRI_ERROR_INTERNAL;
  }

  return TRI_ERROR_NO_ERROR;
}
Exemplo n.º 2
0
/// Comparison with slice
bool Node::operator==(VPackSlice const& rhs) const {
  if (rhs.isObject()) {
    return rhs.toJson() == toJson();
  } else {
    return rhs.equals(slice());
  }
}
Exemplo n.º 3
0
int RestoreFeature::sendRestoreCollection(VPackSlice const& slice,
                                          std::string const& name,
                                          std::string& errorMsg) {
  std::string url =
      "/_api/replication/restore-collection"
      "?overwrite=" +
      std::string(_overwrite ? "true" : "false") + "&recycleIds=" +
      std::string(_recycleIds ? "true" : "false") + "&force=" +
      std::string(_force ? "true" : "false");

  if (_clusterMode) {
    if (!slice.hasKey(std::vector<std::string>({"parameters", "shards"})) &&
        !slice.hasKey(
            std::vector<std::string>({"parameters", "numberOfShards"}))) {
      // no "shards" and no "numberOfShards" attribute present. now assume
      // default value from --default-number-of-shards
      std::cerr << "# no sharding information specified for collection '"
                << name << "', using default number of shards "
                << _defaultNumberOfShards << std::endl;
      url += "&numberOfShards=" + std::to_string(_defaultNumberOfShards);
    }
    if (!slice.hasKey(std::vector<std::string>({"parameters", "replicationFactor"}))) {
      // No replication factor given, so take the default:
      std::cerr << "# no replication information specified for collection '"
                << name << "', using default replication factor "
                << _defaultReplicationFactor << std::endl;
      url += "&replicationFactor=" + std::to_string(_defaultReplicationFactor);
    }

  }

  std::string const body = slice.toJson();

  std::unique_ptr<SimpleHttpResult> response(_httpClient->request(
      rest::RequestType::PUT, url, body.c_str(), body.size()));

  if (response == nullptr || !response->isComplete()) {
    errorMsg =
        "got invalid response from server: " + _httpClient->getErrorMessage();

    return TRI_ERROR_INTERNAL;
  }

  if (response->wasHttpError()) {
    int err;
    errorMsg = getHttpErrorMessage(response.get(), &err);

    if (err != TRI_ERROR_NO_ERROR) {
      return err;
    }

    return TRI_ERROR_INTERNAL;
  }

  return TRI_ERROR_NO_ERROR;
}
Exemplo n.º 4
0
bool Node::handle<PREPEND>(VPackSlice const& slice) {
  if (!slice.hasKey("new")) {
    LOG_TOPIC(WARN, Logger::AGENCY)
        << "Operator prepend without new value: " << slice.toJson();
    return false;
  }
  Builder tmp;
  tmp.openArray();
  tmp.add(slice.get("new"));
  if (this->slice().isArray()) {
    for (auto const& old : VPackArrayIterator(this->slice())) tmp.add(old);
  }
  tmp.close();
  *this = tmp.slice();
  return true;
}