1
0
Fork 0
arangodb/arangosh/Utils/ClientManager.h

118 lines
4.2 KiB
C++

////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2017 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Dan Larkin-York
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGOSH_UTILS_CLIENT_MANAGER_H
#define ARANGOSH_UTILS_CLIENT_MANAGER_H 1
#include <memory>
#include <string>
namespace arangodb {
class LogTopic;
class Result;
namespace httpclient {
class SimpleHttpClient;
class SimpleHttpResult;
} // namespace httpclient
/**
* @brief Helper class providing utilities for client instances
*/
class ClientManager {
public:
/**
* @brief Initialize a client manager using a specific log topic for output
* @param topic Topic to log output to
*/
explicit ClientManager(LogTopic& topic);
virtual ~ClientManager();
public:
/**
* @brief Initializes a client, connects to server, and verifies version
*
* If the client fails to connect to the server, or if the version is
* mismatched, this will result in a fatal error which will terminate the
* running program.
*
* @param httpclient Output pointer will be set on success
* @param force If true, an incompatible version will not result in an
* error result
* @param logServerVersion If true, output the server version to logs
* @param logDatabaseNotFound If true, log errors when database was not found
* @return Status code and possible error message
*/
Result getConnectedClient(std::unique_ptr<httpclient::SimpleHttpClient>&
httpClient, bool force, bool logServerVersion,
bool logDatabaseNotFound);
/**
* @brief Initializes a client, connects to server, and verifies version
*
* If the client fails to connect to the server, or if the version is
* mismatched, this will result in a fatal error which will terminate the
* running program.
*
* @param force If true, an incompatible version will not result in a fatal
* error exit condition
* @param logServerVersion If true, output the server version to logs
* @param logDatabaseNotFound If true, log errors when database was not found
* @return A connected `SimpleHttpClient`
*/
std::unique_ptr<httpclient::SimpleHttpClient> getConnectedClient(
bool force, bool logServerVersion, bool logDatabaseNotFound);
/**
* @brief Conditionally prefixes a relative URI with database-specific path
* @param data Pointer to `ClientFeature` instance
* @param location Relative URI to prefix, if it does not begin with "/_db/"
* @return Propertly prefixed URI
*/
static std::string rewriteLocation(void* data, std::string const& location);
/**
* @brief Determines whether the ArangoDB instance is part of a cluster
* @param client Client to use for request
* @return status result; `true` if successful and part of a cluster
*/
std::pair<Result, bool> getArangoIsCluster(
httpclient::SimpleHttpClient& client);
/**
* Determines whether the ArangoDB instance is using the specified engine
* @param err Reference to store error code if one occurs
* @param client Client to use for request
* @param name Name of storage engine to check against
* @return status result; `true` if successful and specified engine is
* in use
*/
std::pair<Result, bool> getArangoIsUsingEngine(
httpclient::SimpleHttpClient& httpClient, std::string const& name);
private:
LogTopic& _topic;
};
} // namespace arangodb
#endif