From a92add0a9f31dbc701f20f4c84c86b4e06f79a39 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sat, 23 Jul 2016 14:16:10 +0200 Subject: [PATCH] renamed RestServerFeature to GeneralServerFeature --- arangod/CMakeLists.txt | 14 +- arangod/Cluster/AgencyComm.cpp | 280 +++++++++--------- arangod/Cluster/HeartbeatThread.cpp | 4 +- arangod/GeneralServer/GeneralCommTask.cpp | 2 +- arangod/GeneralServer/GeneralServer.cpp | 5 +- .../GeneralServerFeature.cpp} | 46 +-- .../GeneralServerFeature.h} | 22 +- arangod/GeneralServer/HttpCommTask.cpp | 39 ++- arangod/GeneralServer/HttpServerJob.cpp | 6 +- arangod/RestHandler/RestAuthHandler.cpp | 4 +- arangod/RestHandler/RestBatchHandler.cpp | 6 +- arangod/RestServer/BootstrapFeature.cpp | 2 +- arangod/RestServer/ConsoleFeature.cpp | 2 +- arangod/RestServer/DatabaseFeature.cpp | 6 +- arangod/RestServer/ScriptFeature.cpp | 2 +- arangod/RestServer/ServerFeature.cpp | 29 +- arangod/RestServer/UnitTestsFeature.cpp | 2 +- arangod/RestServer/VocbaseContext.cpp | 8 +- arangod/RestServer/arangod.cpp | 37 +-- arangod/V8Server/v8-vocbase.cpp | 57 ++-- arangod/VocBase/AuthInfo.cpp | 4 +- arangod/VocBase/server.cpp | 7 +- 22 files changed, 303 insertions(+), 281 deletions(-) rename arangod/{RestServer/RestServerFeature.cpp => GeneralServer/GeneralServerFeature.cpp} (93%) rename arangod/{RestServer/RestServerFeature.h => GeneralServer/GeneralServerFeature.h} (84%) diff --git a/arangod/CMakeLists.txt b/arangod/CMakeLists.txt index e6f23f93cc..da1c8bc248 100644 --- a/arangod/CMakeLists.txt +++ b/arangod/CMakeLists.txt @@ -184,18 +184,19 @@ add_executable(${BIN_ARANGOD} FulltextIndex/fulltext-list.cpp FulltextIndex/fulltext-query.cpp FulltextIndex/fulltext-result.cpp - GeoIndex/GeoIndex.cpp GeneralServer/AsyncJobManager.cpp - GeneralServer/HttpCommTask.cpp - GeneralServer/HttpServerJob.cpp GeneralServer/GeneralCommTask.cpp - GeneralServer/HttpCommTask.cpp - GeneralServer/HttpsCommTask.cpp GeneralServer/GeneralListenTask.cpp GeneralServer/GeneralServer.cpp + GeneralServer/GeneralServerFeature.cpp + GeneralServer/HttpCommTask.cpp + GeneralServer/HttpCommTask.cpp + GeneralServer/HttpServerJob.cpp + GeneralServer/HttpsCommTask.cpp + GeneralServer/PathHandler.cpp GeneralServer/RestHandler.cpp GeneralServer/RestHandlerFactory.cpp - GeneralServer/PathHandler.cpp + GeoIndex/GeoIndex.cpp Indexes/EdgeIndex.cpp Indexes/FulltextIndex.cpp Indexes/GeoIndex2.cpp @@ -245,7 +246,6 @@ add_executable(${BIN_ARANGOD} RestServer/FrontendFeature.cpp RestServer/InitDatabaseFeature.cpp RestServer/QueryRegistryFeature.cpp - RestServer/RestServerFeature.cpp RestServer/ScriptFeature.cpp RestServer/ServerFeature.cpp RestServer/UnitTestsFeature.cpp diff --git a/arangod/Cluster/AgencyComm.cpp b/arangod/Cluster/AgencyComm.cpp index 809e1183f9..649b6c52f4 100644 --- a/arangod/Cluster/AgencyComm.cpp +++ b/arangod/Cluster/AgencyComm.cpp @@ -35,30 +35,31 @@ #include "Basics/json.h" #include "Cluster/ServerState.h" #include "Endpoint/Endpoint.h" +#include "GeneralServer/GeneralServerFeature.h" #include "Logger/Logger.h" #include "Random/RandomGenerator.h" #include "Rest/HttpRequest.h" #include "Rest/HttpResponse.h" -#include "RestServer/RestServerFeature.h" #include "SimpleHttpClient/GeneralClientConnection.h" #include "SimpleHttpClient/SimpleHttpClient.h" #include "SimpleHttpClient/SimpleHttpResult.h" - using namespace arangodb; using namespace arangodb::application_features; using namespace basics::StringUtils; -static void addEmptyVPackObject(std::string const& name, VPackBuilder& builder) { +static void addEmptyVPackObject(std::string const& name, + VPackBuilder& builder) { builder.add(VPackValue(name)); VPackObjectBuilder c(&builder); } - + ////////////////////////////////////////////////////////////////////////////// /// @brief constructs an operation ////////////////////////////////////////////////////////////////////////////// -AgencyOperation::AgencyOperation(std::string const& key, AgencySimpleOperationType opType) +AgencyOperation::AgencyOperation(std::string const& key, + AgencySimpleOperationType opType) : _key(AgencyComm::prefixPath() + key), _opType() { _opType.type = AgencyOperationType::SIMPLE; _opType.simple = opType; @@ -68,13 +69,14 @@ AgencyOperation::AgencyOperation(std::string const& key, AgencySimpleOperationTy /// @brief constructs an operation ////////////////////////////////////////////////////////////////////////////// -AgencyOperation::AgencyOperation(std::string const& key, AgencyValueOperationType opType, - VPackSlice value) +AgencyOperation::AgencyOperation(std::string const& key, + AgencyValueOperationType opType, + VPackSlice value) : _key(AgencyComm::prefixPath() + key), _opType(), _value(value) { _opType.type = AgencyOperationType::VALUE; _opType.value = opType; } - + ////////////////////////////////////////////////////////////////////////////// /// @brief adds the operation formatted as an attribute in a vpack object ////////////////////////////////////////////////////////////////////////////// @@ -85,8 +87,8 @@ void AgencyOperation::toVelocyPack(VPackBuilder& builder) const { VPackObjectBuilder valueOperation(&builder); builder.add("op", VPackValue(_opType.toString())); if (_opType.type == AgencyOperationType::VALUE) { - if (_opType.value == AgencyValueOperationType::OBSERVE - || _opType.value == AgencyValueOperationType::UNOBSERVE) { + if (_opType.value == AgencyValueOperationType::OBSERVE || + _opType.value == AgencyValueOperationType::UNOBSERVE) { builder.add("url", _value); } else { builder.add("new", _value); @@ -103,8 +105,7 @@ void AgencyOperation::toVelocyPack(VPackBuilder& builder) const { ////////////////////////////////////////////////////////////////////////////// AgencyPrecondition::AgencyPrecondition(std::string const& key, Type t, bool e) - : key(AgencyComm::prefixPath() + key), type(t), empty(e) { -} + : key(AgencyComm::prefixPath() + key), type(t), empty(e) {} ////////////////////////////////////////////////////////////////////////////// /// @brief constructs a precondition @@ -112,8 +113,7 @@ AgencyPrecondition::AgencyPrecondition(std::string const& key, Type t, bool e) AgencyPrecondition::AgencyPrecondition(std::string const& key, Type t, VPackSlice s) - : key(AgencyComm::prefixPath() + key), type(t), empty(false), value(s) { -} + : key(AgencyComm::prefixPath() + key), type(t), empty(false), value(s) {} ////////////////////////////////////////////////////////////////////////////// /// @brief adds the precondition formatted as an attribute in a vpack obj @@ -124,7 +124,7 @@ void AgencyPrecondition::toVelocyPack(VPackBuilder& builder) const { builder.add(VPackValue(key)); { VPackObjectBuilder preconditionDefinition(&builder); - switch(type) { + switch (type) { case AgencyPrecondition::EMPTY: builder.add("oldEmpty", VPackValue(empty)); break; @@ -157,13 +157,13 @@ void AgencyWriteTransaction::toVelocyPack(VPackBuilder& builder) const { VPackArrayBuilder guard(&builder); { VPackObjectBuilder guard2(&builder); - for (AgencyOperation const& operation: operations) { + for (AgencyOperation const& operation : operations) { operation.toVelocyPack(builder); } } if (preconditions.size() > 0) { VPackObjectBuilder guard3(&builder); - for (AgencyPrecondition const& precondition: preconditions) { + for (AgencyPrecondition const& precondition : preconditions) { precondition.toVelocyPack(builder); } } @@ -185,7 +185,7 @@ std::string AgencyReadTransaction::toJson() const { void AgencyReadTransaction::toVelocyPack(VPackBuilder& builder) const { VPackArrayBuilder guard2(&builder); - for (std::string const& key: keys) { + for (std::string const& key : keys) { builder.add(VPackValue(key)); } } @@ -287,8 +287,8 @@ std::string AgencyCommResult::errorMessage() const { return arangodb::basics::VelocyPackHelper::getStringValue(body, "message", ""); } catch (VPackException const& e) { - std::string message("VPackException parsing body ("+ _body + "): " - + e.what()); + std::string message("VPackException parsing body (" + _body + "): " + + e.what()); return std::string(message); } } @@ -326,9 +326,7 @@ void AgencyCommResult::clear() { /// get results of query as slice //////////////////////////////////////////////////////////////////////////////// -VPackSlice AgencyCommResult::slice() { - return _vpack->slice(); -} +VPackSlice AgencyCommResult::slice() { return _vpack->slice(); } //////////////////////////////////////////////////////////////////////////////// /// @brief the static global URL prefix @@ -415,7 +413,7 @@ bool AgencyComm::tryConnect() { // mop: not sure if a timeout makes sense here while (true) { - LOG_TOPIC(DEBUG, Logger::AGENCYCOMM) + LOG_TOPIC(DEBUG, Logger::AGENCYCOMM) << "Trying to find an active agency. Checking " << endpointsStr; std::list::iterator it = _globalEndpoints.begin(); @@ -463,7 +461,7 @@ bool AgencyComm::initialize() { /// @brief will try to initialize a new agency ////////////////////////////////////////////////////////////////////////////// -bool AgencyComm::tryInitializeStructure(std::string const& jwtSecret) { +bool AgencyComm::tryInitializeStructure(std::string const& jwtSecret) { VPackBuilder builder; try { VPackObjectBuilder b(&builder); @@ -544,9 +542,7 @@ bool AgencyComm::tryInitializeStructure(std::string const& jwtSecret) { builder.add("NumberOfCoordinators", VPackSlice::nullSlice()); builder.add("NumberOfDBServers", VPackSlice::nullSlice()); builder.add(VPackValue("CleanedServers")); - { - VPackArrayBuilder dd(&builder); - } + { VPackArrayBuilder dd(&builder); } builder.add("Lock", VPackValue("UNLOCKED")); addEmptyVPackObject("MapLocalToID", builder); addEmptyVPackObject("Failed", builder); @@ -565,7 +561,8 @@ bool AgencyComm::tryInitializeStructure(std::string const& jwtSecret) { builder.add("InitDone", VPackValue(true)); builder.add("Secret", VPackValue(encodeHex(jwtSecret))); } catch (std::exception const& e) { - LOG_TOPIC(ERR, Logger::STARTUP) << "Couldn't create initializing structure " << e.what(); + LOG_TOPIC(ERR, Logger::STARTUP) << "Couldn't create initializing structure " + << e.what(); return false; } catch (...) { LOG_TOPIC(ERR, Logger::STARTUP) << "Couldn't create initializing structure"; @@ -573,16 +570,17 @@ bool AgencyComm::tryInitializeStructure(std::string const& jwtSecret) { } try { - LOG_TOPIC(TRACE, Logger::STARTUP) - << "Initializing agency with " << builder.toJson(); + LOG_TOPIC(TRACE, Logger::STARTUP) << "Initializing agency with " + << builder.toJson(); - AgencyOperation initOperation("", AgencyValueOperationType::SET, builder.slice()); + AgencyOperation initOperation("", AgencyValueOperationType::SET, + builder.slice()); AgencyWriteTransaction initTransaction; initTransaction.operations.push_back(initOperation); - + auto result = sendTransactionWithFailover(initTransaction); - + return result.successful(); } catch (std::exception const& e) { LOG(FATAL) << "Fatal error initializing agency " << e.what(); @@ -604,14 +602,14 @@ bool AgencyComm::shouldInitializeStructure() { double timeout = _globalConnectionOptions._requestTimeout; // "InitDone" key should not previously exist auto result = casValue("InitDone", builder.slice(), false, 60.0, timeout); - + if (!result.successful()) { // somebody else has or is initializing the agency - LOG_TOPIC(TRACE, Logger::STARTUP) + LOG_TOPIC(TRACE, Logger::STARTUP) << "someone else is initializing the agency"; return false; } - + return true; } @@ -621,48 +619,49 @@ bool AgencyComm::shouldInitializeStructure() { bool AgencyComm::ensureStructureInitialized() { LOG_TOPIC(TRACE, Logger::STARTUP) << "Checking if agency is initialized"; - - RestServerFeature* restServer = - application_features::ApplicationServer::getFeature("RestServer"); + + GeneralServerFeature* restServer = + application_features::ApplicationServer::getFeature( + "GeneralServer"); while (true) { while (shouldInitializeStructure()) { - LOG_TOPIC(TRACE, Logger::STARTUP) + LOG_TOPIC(TRACE, Logger::STARTUP) << "Agency is fresh. Needs initial structure."; // mop: we initialized it .. great success if (tryInitializeStructure(restServer->jwtSecret())) { LOG_TOPIC(TRACE, Logger::STARTUP) << "Successfully initialized agency"; break; - } + } - LOG_TOPIC(WARN, Logger::STARTUP) + LOG_TOPIC(WARN, Logger::STARTUP) << "Initializing agency failed. We'll try again soon"; // We should really have exclusive access, here, this is strange! sleep(1); } - + AgencyCommResult result = getValues("InitDone"); - + if (result.successful()) { - VPackSlice value = result.slice()[0].get(std::vector( - {prefix(), "InitDone"})); + VPackSlice value = result.slice()[0].get( + std::vector({prefix(), "InitDone"})); if (value.isBoolean() && value.getBoolean()) { // expecting a value of "true" LOG_TOPIC(TRACE, Logger::STARTUP) << "Found an initialized agency"; break; } } - - LOG_TOPIC(TRACE, Logger::STARTUP) + + LOG_TOPIC(TRACE, Logger::STARTUP) << "Waiting for agency to get initialized"; sleep(1); - } // next attempt - + } // next attempt + AgencyCommResult secretResult = getValues("Secret"); - VPackSlice secretValue = secretResult.slice()[0].get(std::vector( - {prefix(), "Secret"})); - + VPackSlice secretValue = secretResult.slice()[0].get( + std::vector({prefix(), "Secret"})); + if (!secretValue.isString()) { LOG(ERR) << "Couldn't find secret in agency!"; return false; @@ -701,8 +700,8 @@ void AgencyComm::disconnect() { bool AgencyComm::addEndpoint(std::string const& endpointSpecification, bool toFront) { - LOG_TOPIC(TRACE, Logger::AGENCYCOMM) - << "adding global agency-endpoint '" << endpointSpecification << "'"; + LOG_TOPIC(TRACE, Logger::AGENCYCOMM) << "adding global agency-endpoint '" + << endpointSpecification << "'"; { WRITE_LOCKER(writeLocker, AgencyComm::_globalLock); @@ -757,7 +756,7 @@ bool AgencyComm::hasEndpoint(std::string const& endpointSpecification) { while (it != _globalEndpoints.end()) { AgencyEndpoint const* agencyEndpoint = (*it); - + if (agencyEndpoint->_endpoint->specification() == endpointSpecification) { return true; } @@ -871,7 +870,6 @@ std::string AgencyComm::getEndpointsString() { //////////////////////////////////////////////////////////////////////////////// bool AgencyComm::setPrefix(std::string const&) { - // agency prefix must not be changed _globalPrefix = "/arango/"; _globalPrefixStripped = "arango"; @@ -963,10 +961,9 @@ AgencyCommResult AgencyComm::sendServerState(double ttl) { //////////////////////////////////////////////////////////////////////////////// std::string AgencyComm::getVersion() { - AgencyCommResult result - = sendWithFailover(arangodb::GeneralRequest::RequestType::GET, - _globalConnectionOptions._requestTimeout, "version", - "", false); + AgencyCommResult result = sendWithFailover( + arangodb::GeneralRequest::RequestType::GET, + _globalConnectionOptions._requestTimeout, "version", "", false); if (result.successful()) { return result._body; @@ -981,11 +978,10 @@ std::string AgencyComm::getVersion() { AgencyCommResult AgencyComm::createDirectory(std::string const& key) { VPackBuilder builder; - { - VPackObjectBuilder dir(&builder); - } - - AgencyOperation operation(key, AgencyValueOperationType::SET, builder.slice()); + { VPackObjectBuilder dir(&builder); } + + AgencyOperation operation(key, AgencyValueOperationType::SET, + builder.slice()); AgencyWriteTransaction transaction(operation); return sendTransactionWithFailover(transaction); @@ -996,12 +992,12 @@ AgencyCommResult AgencyComm::createDirectory(std::string const& key) { //////////////////////////////////////////////////////////////////////////////// AgencyCommResult AgencyComm::setValue(std::string const& key, - std::string const& value, - double ttl) { + std::string const& value, double ttl) { VPackBuilder builder; builder.add(VPackValue(value)); - - AgencyOperation operation(key, AgencyValueOperationType::SET, builder.slice()); + + AgencyOperation operation(key, AgencyValueOperationType::SET, + builder.slice()); operation._ttl = static_cast(ttl); AgencyWriteTransaction transaction(operation); @@ -1015,7 +1011,6 @@ AgencyCommResult AgencyComm::setValue(std::string const& key, AgencyCommResult AgencyComm::setValue(std::string const& key, arangodb::velocypack::Slice const& slice, double ttl) { - AgencyOperation operation(key, AgencyValueOperationType::SET, slice); operation._ttl = static_cast(ttl); AgencyWriteTransaction transaction(operation); @@ -1046,10 +1041,8 @@ bool AgencyComm::exists(std::string const& key) { //////////////////////////////////////////////////////////////////////////////// AgencyCommResult AgencyComm::increment(std::string const& key) { - AgencyWriteTransaction transaction( - AgencyOperation(key, AgencySimpleOperationType::INCREMENT_OP) - ); + AgencyOperation(key, AgencySimpleOperationType::INCREMENT_OP)); return sendTransactionWithFailover(transaction); } @@ -1060,7 +1053,7 @@ AgencyCommResult AgencyComm::increment(std::string const& key) { AgencyCommResult AgencyComm::getValues(std::string const& key) { std::string url(buildUrl()); - + url += "/read"; VPackBuilder builder; { @@ -1071,17 +1064,15 @@ AgencyCommResult AgencyComm::getValues(std::string const& key) { } } - AgencyCommResult result - = sendWithFailover(arangodb::GeneralRequest::RequestType::POST, - _globalConnectionOptions._requestTimeout, url, - builder.toJson(), false); + AgencyCommResult result = sendWithFailover( + arangodb::GeneralRequest::RequestType::POST, + _globalConnectionOptions._requestTimeout, url, builder.toJson(), false); if (!result.successful()) { return result; } - - try { + try { result.setVPack(VPackParser::fromJson(result.body().c_str())); if (!result.slice().isArray()) { @@ -1093,16 +1084,16 @@ AgencyCommResult AgencyComm::getValues(std::string const& key) { result._statusCode = 500; return result; } - + result._body.clear(); result._statusCode = 200; - - } catch(std::exception &e) { - LOG_TOPIC(ERR, Logger::AGENCYCOMM) - << "Error transforming result. " << e.what(); + + } catch (std::exception& e) { + LOG_TOPIC(ERR, Logger::AGENCYCOMM) << "Error transforming result. " + << e.what(); result.clear(); - } catch(...) { - LOG_TOPIC(ERR, Logger::AGENCYCOMM) + } catch (...) { + LOG_TOPIC(ERR, Logger::AGENCYCOMM) << "Error transforming result. Out of memory"; result.clear(); } @@ -1118,8 +1109,7 @@ AgencyCommResult AgencyComm::removeValues(std::string const& key, bool recursive) { AgencyWriteTransaction transaction( AgencyOperation(key, AgencySimpleOperationType::DELETE_OP), - AgencyPrecondition(key, AgencyPrecondition::EMPTY, false) - ); + AgencyPrecondition(key, AgencyPrecondition::EMPTY, false)); return sendTransactionWithFailover(transaction); } @@ -1133,16 +1123,16 @@ AgencyCommResult AgencyComm::casValue(std::string const& key, arangodb::velocypack::Slice const& json, bool prevExist, double ttl, double timeout) { - VPackBuilder newBuilder; newBuilder.add(json); - AgencyOperation operation(key, AgencyValueOperationType::SET, newBuilder.slice()); + AgencyOperation operation(key, AgencyValueOperationType::SET, + newBuilder.slice()); AgencyPrecondition precondition(key, AgencyPrecondition::EMPTY, !prevExist); if (ttl >= 0.0) { operation._ttl = static_cast(ttl); } - + VPackBuilder preBuilder; precondition.toVelocyPack(preBuilder); @@ -1162,17 +1152,18 @@ AgencyCommResult AgencyComm::casValue(std::string const& key, double timeout) { VPackBuilder newBuilder; newBuilder.add(newJson); - + VPackBuilder oldBuilder; oldBuilder.add(oldJson); - - AgencyOperation operation(key, AgencyValueOperationType::SET, newBuilder.slice()); + + AgencyOperation operation(key, AgencyValueOperationType::SET, + newBuilder.slice()); AgencyPrecondition precondition(key, AgencyPrecondition::VALUE, oldBuilder.slice()); if (ttl >= 0.0) { operation._ttl = static_cast(ttl); } - + AgencyWriteTransaction transaction(operation, precondition); return sendTransactionWithFailover(transaction, timeout); } @@ -1181,13 +1172,15 @@ AgencyCommResult AgencyComm::casValue(std::string const& key, /// @brief registers a callback on a key //////////////////////////////////////////////////////////////////////////////// -bool AgencyComm::registerCallback(std::string const& key, std::string const& endpoint) { +bool AgencyComm::registerCallback(std::string const& key, + std::string const& endpoint) { VPackBuilder builder; builder.add(VPackValue(endpoint)); - - AgencyOperation operation(key, AgencyValueOperationType::OBSERVE, builder.slice()); + + AgencyOperation operation(key, AgencyValueOperationType::OBSERVE, + builder.slice()); AgencyWriteTransaction transaction(operation); - + auto result = sendTransactionWithFailover(transaction); return result.successful(); } @@ -1200,10 +1193,11 @@ bool AgencyComm::unregisterCallback(std::string const& key, std::string const& endpoint) { VPackBuilder builder; builder.add(VPackValue(endpoint)); - - AgencyOperation operation(key, AgencyValueOperationType::UNOBSERVE, builder.slice()); + + AgencyOperation operation(key, AgencyValueOperationType::UNOBSERVE, + builder.slice()); AgencyWriteTransaction transaction(operation); - + auto result = sendTransactionWithFailover(transaction); return result.successful(); } @@ -1285,11 +1279,11 @@ uint64_t AgencyComm::uniqid(uint64_t count, double timeout) { continue; } - VPackSlice oldSlice = result.slice()[0].get(std::vector( - {prefix(), "Sync", "LatestID"})); + VPackSlice oldSlice = result.slice()[0].get( + std::vector({prefix(), "Sync", "LatestID"})); if (!(oldSlice.isSmallInt() || oldSlice.isUInt())) { - LOG_TOPIC(WARN, Logger::AGENCYCOMM) + LOG_TOPIC(WARN, Logger::AGENCYCOMM) << "Sync/LatestID in agency is not an unsigned integer, fixing..."; try { VPackBuilder builder; @@ -1309,8 +1303,7 @@ uint64_t AgencyComm::uniqid(uint64_t count, double timeout) { oldValue = 0; try { oldValue = oldSlice.getUInt(); - } - catch (...) { + } catch (...) { } uint64_t const newValue = oldValue + count; @@ -1322,8 +1315,8 @@ uint64_t AgencyComm::uniqid(uint64_t count, double timeout) { continue; } - result = casValue("Sync/LatestID", oldSlice, newBuilder.slice(), - 0.0, timeout); + result = + casValue("Sync/LatestID", oldSlice, newBuilder.slice(), 0.0, timeout); if (result.successful()) { break; @@ -1527,14 +1520,13 @@ void AgencyComm::requeueEndpoint(AgencyEndpoint* agencyEndpoint, std::string AgencyComm::buildUrl() const { return AgencyComm::AGENCY_URL_PREFIX; } - + ////////////////////////////////////////////////////////////////////////////// /// @brief sends a write HTTP request to the agency, handling failover ////////////////////////////////////////////////////////////////////////////// AgencyCommResult AgencyComm::sendTransactionWithFailover( AgencyTransaction const& transaction, double timeout) { - std::string url(buildUrl()); url += transaction.isWriteTransaction() ? "/write" : "/read"; @@ -1553,12 +1545,12 @@ AgencyCommResult AgencyComm::sendTransactionWithFailover( if (!result.successful()) { return result; } - + try { result.setVPack(VPackParser::fromJson(result.body().c_str())); if (transaction.isWriteTransaction()) { - if (!result.slice().isObject() || + if (!result.slice().isObject() || !result.slice().get("results").isArray()) { result._statusCode = 500; return result; @@ -1579,19 +1571,19 @@ AgencyCommResult AgencyComm::sendTransactionWithFailover( return result; } } - + result._body.clear(); - - } catch(std::exception &e) { - LOG_TOPIC(ERR, Logger::AGENCYCOMM) - << "Error transforming result. " << e.what(); + + } catch (std::exception& e) { + LOG_TOPIC(ERR, Logger::AGENCYCOMM) << "Error transforming result. " + << e.what(); result.clear(); - } catch(...) { - LOG_TOPIC(ERR, Logger::AGENCYCOMM) + } catch (...) { + LOG_TOPIC(ERR, Logger::AGENCYCOMM) << "Error transforming result. Out of memory"; result.clear(); } - + return result; } @@ -1600,11 +1592,8 @@ AgencyCommResult AgencyComm::sendTransactionWithFailover( //////////////////////////////////////////////////////////////////////////////// AgencyCommResult AgencyComm::sendWithFailover( - arangodb::GeneralRequest::RequestType method, - double const timeout, - std::string const& url, - std::string const& body, bool isWatch) { - + arangodb::GeneralRequest::RequestType method, double const timeout, + std::string const& url, std::string const& body, bool isWatch) { size_t numEndpoints; { @@ -1633,7 +1622,8 @@ AgencyCommResult AgencyComm::sendWithFailover( TRI_ASSERT(agencyEndpoint != nullptr); try { - result = send(agencyEndpoint->_connection, method, timeout, realUrl, body); + result = + send(agencyEndpoint->_connection, method, timeout, realUrl, body); } catch (...) { result._connected = false; result._statusCode = 0; @@ -1645,8 +1635,8 @@ AgencyCommResult AgencyComm::sendWithFailover( break; } -// LOG(WARN) << result._statusCode; - + // LOG(WARN) << result._statusCode; + if (result._statusCode == (int)arangodb::GeneralResponse::ResponseCode::TEMPORARY_REDIRECT) { // sometimes the agency will return a 307 (temporary redirect) @@ -1686,8 +1676,8 @@ AgencyCommResult AgencyComm::sendWithFailover( if (!AgencyComm::hasEndpoint(endpoint)) { AgencyComm::addEndpoint(endpoint, true); - LOG_TOPIC(DEBUG, Logger::AGENCYCOMM) - << "adding agency-endpoint '" << endpoint << "'"; + LOG_TOPIC(DEBUG, Logger::AGENCYCOMM) << "adding agency-endpoint '" + << endpoint << "'"; // re-check the new endpoint if (AgencyComm::hasEndpoint(endpoint)) { @@ -1695,7 +1685,7 @@ AgencyCommResult AgencyComm::sendWithFailover( continue; } - LOG_TOPIC(ERR, Logger::AGENCYCOMM) + LOG_TOPIC(ERR, Logger::AGENCYCOMM) << "found redirection to unknown endpoint '" << endpoint << "'. Will not follow!"; @@ -1736,9 +1726,9 @@ AgencyCommResult AgencyComm::sendWithFailover( //////////////////////////////////////////////////////////////////////////////// AgencyCommResult AgencyComm::send( - arangodb::httpclient::GeneralClientConnection* connection, - arangodb::GeneralRequest::RequestType method, - double timeout, std::string const& url, std::string const& body) { + arangodb::httpclient::GeneralClientConnection* connection, + arangodb::GeneralRequest::RequestType method, double timeout, + std::string const& url, std::string const& body) { TRI_ASSERT(connection != nullptr); if (method == arangodb::GeneralRequest::RequestType::GET || @@ -1753,7 +1743,7 @@ AgencyCommResult AgencyComm::send( result._connected = false; result._statusCode = 0; - LOG_TOPIC(TRACE, Logger::AGENCYCOMM) + LOG_TOPIC(TRACE, Logger::AGENCYCOMM) << "sending " << arangodb::HttpRequest::translateMethod(method) << " request to agency at endpoint '" << connection->getEndpoint()->specification() << "', url '" << url @@ -1791,7 +1781,7 @@ AgencyCommResult AgencyComm::send( } result._connected = true; - + if (response->getHttpReturnCode() == (int)arangodb::GeneralResponse::ResponseCode::TEMPORARY_REDIRECT) { // temporary redirect. now save location header @@ -1799,8 +1789,8 @@ AgencyCommResult AgencyComm::send( bool found = false; result._location = response->getHeaderField(StaticStrings::Location, found); - LOG_TOPIC(TRACE, Logger::AGENCYCOMM) - << "redirecting to location: '" << result._location << "'"; + LOG_TOPIC(TRACE, Logger::AGENCYCOMM) << "redirecting to location: '" + << result._location << "'"; if (!found) { // a 307 without a location header does not make any sense @@ -1816,10 +1806,10 @@ AgencyCommResult AgencyComm::send( result._body = std::string(sb.c_str(), sb.length()); result._statusCode = response->getHttpReturnCode(); - LOG_TOPIC(TRACE, Logger::AGENCYCOMM) + LOG_TOPIC(TRACE, Logger::AGENCYCOMM) << "request to agency returned status code " << result._statusCode - << ", message: '" << result._message << "', body: '" - << result._body << "'"; + << ", message: '" << result._message << "', body: '" << result._body + << "'"; if (result.successful()) { return result; diff --git a/arangod/Cluster/HeartbeatThread.cpp b/arangod/Cluster/HeartbeatThread.cpp index 184f129cff..9180879e93 100644 --- a/arangod/Cluster/HeartbeatThread.cpp +++ b/arangod/Cluster/HeartbeatThread.cpp @@ -39,9 +39,9 @@ #include "Dispatcher/Dispatcher.h" #include "Dispatcher/DispatcherFeature.h" #include "Dispatcher/Job.h" +#include "GeneralServer/GeneralServerFeature.h" #include "GeneralServer/RestHandlerFactory.h" #include "Logger/Logger.h" -#include "RestServer/RestServerFeature.h" #include "V8/v8-globals.h" #include "VocBase/AuthInfo.h" #include "VocBase/server.h" @@ -375,7 +375,7 @@ void HeartbeatThread::runCoordinator() { if (userVersion > 0 && userVersion != oldUserVersion) { oldUserVersion = userVersion; - RestServerFeature::AUTH_INFO.outdate(); + GeneralServerFeature::AUTH_INFO.outdate(); } } diff --git a/arangod/GeneralServer/GeneralCommTask.cpp b/arangod/GeneralServer/GeneralCommTask.cpp index ab5eec91b9..30edd20376 100644 --- a/arangod/GeneralServer/GeneralCommTask.cpp +++ b/arangod/GeneralServer/GeneralCommTask.cpp @@ -29,10 +29,10 @@ #include "Basics/StaticStrings.h" #include "Basics/StringBuffer.h" #include "GeneralServer/GeneralServer.h" +#include "GeneralServer/GeneralServerFeature.h" #include "GeneralServer/RestHandler.h" #include "GeneralServer/RestHandlerFactory.h" #include "Logger/Logger.h" -#include "RestServer/RestServerFeature.h" #include "Scheduler/Scheduler.h" #include "Scheduler/SchedulerFeature.h" #include "VocBase/server.h" diff --git a/arangod/GeneralServer/GeneralServer.cpp b/arangod/GeneralServer/GeneralServer.cpp index 23c6fa78c7..4e32b24256 100644 --- a/arangod/GeneralServer/GeneralServer.cpp +++ b/arangod/GeneralServer/GeneralServer.cpp @@ -32,10 +32,10 @@ #include "GeneralServer/AsyncJobManager.h" #include "GeneralServer/GeneralCommTask.h" #include "GeneralServer/GeneralListenTask.h" +#include "GeneralServer/GeneralServerFeature.h" #include "GeneralServer/HttpServerJob.h" #include "GeneralServer/RestHandler.h" #include "Logger/Logger.h" -#include "RestServer/RestServerFeature.h" #include "Scheduler/ListenTask.h" #include "Scheduler/Scheduler.h" #include "Scheduler/SchedulerFeature.h" @@ -78,6 +78,7 @@ GeneralServer::GeneralServer( _verificationMode(SSL_VERIFY_NONE), _verificationCallback(nullptr), _sslAllowed(ctx != nullptr) {} + //////////////////////////////////////////////////////////////////////////////// /// @brief destructs a general server //////////////////////////////////////////////////////////////////////////////// @@ -233,7 +234,7 @@ bool GeneralServer::handleRequestAsync(GeneralCommTask* task, // register the job with the job manager if (jobId != nullptr) { - RestServerFeature::JOB_MANAGER->initAsyncJob( + GeneralServerFeature::JOB_MANAGER->initAsyncJob( static_cast(job.get()), hdr); *jobId = job->jobId(); } diff --git a/arangod/RestServer/RestServerFeature.cpp b/arangod/GeneralServer/GeneralServerFeature.cpp similarity index 93% rename from arangod/RestServer/RestServerFeature.cpp rename to arangod/GeneralServer/GeneralServerFeature.cpp index a95d44a9e6..db73195075 100644 --- a/arangod/RestServer/RestServerFeature.cpp +++ b/arangod/GeneralServer/GeneralServerFeature.cpp @@ -20,7 +20,7 @@ /// @author Dr. Frank Celler //////////////////////////////////////////////////////////////////////////////// -#include "RestServerFeature.h" +#include "GeneralServerFeature.h" #include "Agency/AgencyFeature.h" #include "Agency/RestAgencyHandler.h" @@ -79,14 +79,14 @@ using namespace arangodb; using namespace arangodb::rest; using namespace arangodb::options; -rest::RestHandlerFactory* RestServerFeature::HANDLER_FACTORY = nullptr; -rest::AsyncJobManager* RestServerFeature::JOB_MANAGER = nullptr; -RestServerFeature* RestServerFeature::REST_SERVER = nullptr; -AuthInfo RestServerFeature::AUTH_INFO; +rest::RestHandlerFactory* GeneralServerFeature::HANDLER_FACTORY = nullptr; +rest::AsyncJobManager* GeneralServerFeature::JOB_MANAGER = nullptr; +GeneralServerFeature* GeneralServerFeature::GENERAL_SERVER = nullptr; +AuthInfo GeneralServerFeature::AUTH_INFO; -RestServerFeature::RestServerFeature( +GeneralServerFeature::GeneralServerFeature( application_features::ApplicationServer* server) - : ApplicationFeature(server, "RestServer"), + : ApplicationFeature(server, "GeneralServer"), _keepAliveTimeout(300.0), _allowMethodOverride(false), _authentication(true), @@ -111,7 +111,7 @@ RestServerFeature::RestServerFeature( startsAfter("Upgrade"); } -void RestServerFeature::collectOptions( +void GeneralServerFeature::collectOptions( std::shared_ptr options) { options->addSection("server", "Server features"); @@ -180,7 +180,7 @@ void RestServerFeature::collectOptions( new VectorParameter(&_trustedProxies)); } -void RestServerFeature::validateOptions(std::shared_ptr) { +void GeneralServerFeature::validateOptions(std::shared_ptr) { if (!_accessControlAllowOrigins.empty()) { // trim trailing slash from all members for (auto& it : _accessControlAllowOrigins) { @@ -210,9 +210,9 @@ void RestServerFeature::validateOptions(std::shared_ptr) { } if (!_jwtSecret.empty()) { - if (_jwtSecret.length() > RestServerFeature::_maxSecretLength) { + if (_jwtSecret.length() > GeneralServerFeature::_maxSecretLength) { LOG(ERR) << "Given JWT secret too long. Max length is " - << RestServerFeature::_maxSecretLength; + << GeneralServerFeature::_maxSecretLength; FATAL_ERROR_EXIT(); } } @@ -256,32 +256,32 @@ static bool SetRequestContext(GeneralRequest* request, void* data) { } VocbaseContext* ctx = new arangodb::VocbaseContext( - request, vocbase, RestServerFeature::getJwtSecret()); + request, vocbase, GeneralServerFeature::getJwtSecret()); request->setRequestContext(ctx, true); // the "true" means the request is the owner of the context return true; } -void RestServerFeature::generateNewJwtSecret() { +void GeneralServerFeature::generateNewJwtSecret() { _jwtSecret = ""; uint16_t m = 254; - for (size_t i = 0; i < RestServerFeature::_maxSecretLength; i++) { + for (size_t i = 0; i < GeneralServerFeature::_maxSecretLength; i++) { _jwtSecret += (1 + RandomGenerator::interval(m)); } } -void RestServerFeature::prepare() { +void GeneralServerFeature::prepare() { if (_jwtSecret.empty()) { generateNewJwtSecret(); } RestHandlerFactory::setMaintenance(true); - REST_SERVER = this; + GENERAL_SERVER = this; } -void RestServerFeature::start() { +void GeneralServerFeature::start() { _jobManager.reset(new AsyncJobManager(ClusterCommRestCallback)); JOB_MANAGER = _jobManager.get(); @@ -313,10 +313,10 @@ void RestServerFeature::start() { // populate the authentication cache. otherwise no one can access the new // database - RestServerFeature::AUTH_INFO.outdate(); + GeneralServerFeature::AUTH_INFO.outdate(); } -void RestServerFeature::stop() { +void GeneralServerFeature::stop() { for (auto& server : _servers) { server->stopListening(); } @@ -326,17 +326,17 @@ void RestServerFeature::stop() { } } -void RestServerFeature::unprepare() { +void GeneralServerFeature::unprepare() { for (auto& server : _servers) { delete server; } - REST_SERVER = nullptr; + GENERAL_SERVER = nullptr; JOB_MANAGER = nullptr; HANDLER_FACTORY = nullptr; } -void RestServerFeature::buildServers() { +void GeneralServerFeature::buildServers() { TRI_ASSERT(_jobManager != nullptr); EndpointFeature* endpoint = @@ -367,7 +367,7 @@ void RestServerFeature::buildServers() { _servers.push_back(server); } -void RestServerFeature::defineHandlers() { +void GeneralServerFeature::defineHandlers() { TRI_ASSERT(_jobManager != nullptr); AgencyFeature* agency = diff --git a/arangod/RestServer/RestServerFeature.h b/arangod/GeneralServer/GeneralServerFeature.h similarity index 84% rename from arangod/RestServer/RestServerFeature.h rename to arangod/GeneralServer/GeneralServerFeature.h index 34b8ca18e1..732eb945ec 100644 --- a/arangod/RestServer/RestServerFeature.h +++ b/arangod/GeneralServer/GeneralServerFeature.h @@ -20,8 +20,8 @@ /// @author Dr. Frank Celler //////////////////////////////////////////////////////////////////////////////// -#ifndef APPLICATION_FEATURES_REST_SERVER_FEATURE_H -#define APPLICATION_FEATURES_REST_SERVER_FEATURE_H 1 +#ifndef APPLICATION_FEATURES_GENERAL_SERVER_FEATURE_H +#define APPLICATION_FEATURES_GENERAL_SERVER_FEATURE_H 1 #include "ApplicationFeatures/ApplicationFeature.h" @@ -37,7 +37,7 @@ class GeneralServer; class RestServerThread; -class RestServerFeature final +class GeneralServerFeature final : public application_features::ApplicationFeature { public: static rest::RestHandlerFactory* HANDLER_FACTORY; @@ -46,33 +46,33 @@ class RestServerFeature final public: static bool authenticationEnabled() { - return REST_SERVER != nullptr && REST_SERVER->authentication(); + return GENERAL_SERVER != nullptr && GENERAL_SERVER->authentication(); } static bool hasProxyCheck() { - return REST_SERVER != nullptr && REST_SERVER->proxyCheck(); + return GENERAL_SERVER != nullptr && GENERAL_SERVER->proxyCheck(); } static std::vector getTrustedProxies() { - if (REST_SERVER == nullptr) { + if (GENERAL_SERVER == nullptr) { return std::vector(); } - return REST_SERVER->trustedProxies(); + return GENERAL_SERVER->trustedProxies(); } static std::string getJwtSecret() { - if (REST_SERVER == nullptr) { + if (GENERAL_SERVER == nullptr) { return std::string(); } - return REST_SERVER->jwtSecret(); + return GENERAL_SERVER->jwtSecret(); } private: - static RestServerFeature* REST_SERVER; + static GeneralServerFeature* GENERAL_SERVER; static const size_t _maxSecretLength = 64; public: - explicit RestServerFeature(application_features::ApplicationServer*); + explicit GeneralServerFeature(application_features::ApplicationServer*); public: void collectOptions(std::shared_ptr) override final; diff --git a/arangod/GeneralServer/HttpCommTask.cpp b/arangod/GeneralServer/HttpCommTask.cpp index 7a15f27207..3004e099a2 100644 --- a/arangod/GeneralServer/HttpCommTask.cpp +++ b/arangod/GeneralServer/HttpCommTask.cpp @@ -1,13 +1,38 @@ -#include "GeneralServer/HttpCommTask.h" +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany +/// Copyright 2004-2014 triAGENS 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 Dr. Frank Celler +/// @author Achim Brandt +//////////////////////////////////////////////////////////////////////////////// +#include "HttpCommTask.h" + +#include "Basics/HybridLogicalClock.h" #include "GeneralServer/GeneralServer.h" +#include "GeneralServer/GeneralServerFeature.h" #include "GeneralServer/RestHandler.h" #include "GeneralServer/RestHandlerFactory.h" -#include "RestServer/RestServerFeature.h" #include "Scheduler/Scheduler.h" #include "Scheduler/SchedulerFeature.h" -#include "Basics/HybridLogicalClock.h" #include "VocBase/server.h" //clock + //////////////////////////////////////////////////////////////////////////////// /// @brief reads data from the socket //////////////////////////////////////////////////////////////////////////////// @@ -243,7 +268,7 @@ bool HttpCommTask::processRead() { return false; } - RestServerFeature::HANDLER_FACTORY->setRequestContext(_request); + GeneralServerFeature::HANDLER_FACTORY->setRequestContext(_request); _request->setClientTaskId(_taskId); // check HTTP protocol version @@ -586,8 +611,8 @@ void HttpCommTask::processRequest() { // execute response WorkItem::uptr handler( - RestServerFeature::HANDLER_FACTORY->createHandler(_request, - response.get())); + GeneralServerFeature::HANDLER_FACTORY->createHandler(_request, + response.get())); // ab hier generell if (handler == nullptr) { @@ -915,7 +940,7 @@ GeneralResponse::ResponseCode HttpCommTask::authenticateRequest() { auto context = (_request == nullptr) ? nullptr : _request->requestContext(); if (context == nullptr && _request != nullptr) { - bool res = RestServerFeature::HANDLER_FACTORY->setRequestContext(_request); + bool res = GeneralServerFeature::HANDLER_FACTORY->setRequestContext(_request); if (!res) { return GeneralResponse::ResponseCode::NOT_FOUND; diff --git a/arangod/GeneralServer/HttpServerJob.cpp b/arangod/GeneralServer/HttpServerJob.cpp index 4dcc1151f7..146aa4b886 100644 --- a/arangod/GeneralServer/HttpServerJob.cpp +++ b/arangod/GeneralServer/HttpServerJob.cpp @@ -29,9 +29,9 @@ #include "GeneralServer/AsyncJobManager.h" #include "GeneralServer/GeneralCommTask.h" #include "GeneralServer/GeneralServer.h" +#include "GeneralServer/GeneralServerFeature.h" #include "GeneralServer/RestHandler.h" #include "Logger/Logger.h" -#include "RestServer/RestServerFeature.h" #include "Scheduler/Scheduler.h" #include "Scheduler/SchedulerFeature.h" @@ -81,8 +81,8 @@ void HttpServerJob::work() { if (_isAsync) { _handler->RequestStatisticsAgent::release(); - RestServerFeature::JOB_MANAGER->finishAsyncJob(_jobId, - _handler->stealResponse()); + GeneralServerFeature::JOB_MANAGER->finishAsyncJob( + _jobId, _handler->stealResponse()); } else { auto data = std::make_unique(); diff --git a/arangod/RestHandler/RestAuthHandler.cpp b/arangod/RestHandler/RestAuthHandler.cpp index 60eb0587ac..e7067e84c1 100644 --- a/arangod/RestHandler/RestAuthHandler.cpp +++ b/arangod/RestHandler/RestAuthHandler.cpp @@ -27,9 +27,9 @@ #include #include "Basics/StringUtils.h" +#include "GeneralServer/GeneralServerFeature.h" #include "Logger/Logger.h" #include "Rest/HttpRequest.h" -#include "RestServer/RestServerFeature.h" #include "Ssl/SslInterface.h" #include "VocBase/AuthInfo.h" @@ -111,7 +111,7 @@ RestHandler::status RestAuthHandler::execute() { std::string const password = passwordSlice.copyString(); AuthResult auth = - RestServerFeature::AUTH_INFO.checkPassword(username, password); + GeneralServerFeature::AUTH_INFO.checkPassword(username, password); if (auth._authorized) { VPackBuilder resultBuilder; diff --git a/arangod/RestHandler/RestBatchHandler.cpp b/arangod/RestHandler/RestBatchHandler.cpp index b6c38eeaf6..0526a459f0 100644 --- a/arangod/RestHandler/RestBatchHandler.cpp +++ b/arangod/RestHandler/RestBatchHandler.cpp @@ -25,11 +25,11 @@ #include "Basics/StaticStrings.h" #include "Basics/StringUtils.h" -#include "Logger/Logger.h" #include "GeneralServer/GeneralServer.h" +#include "GeneralServer/GeneralServerFeature.h" #include "GeneralServer/RestHandlerFactory.h" +#include "Logger/Logger.h" #include "Rest/HttpRequest.h" -#include "RestServer/RestServerFeature.h" using namespace arangodb; using namespace arangodb::basics; @@ -176,7 +176,7 @@ RestHandler::status RestBatchHandler::execute() { { std::unique_ptr response( new HttpResponse(GeneralResponse::ResponseCode::SERVER_ERROR)); - handler = RestServerFeature::HANDLER_FACTORY->createHandler( + handler = GeneralServerFeature::HANDLER_FACTORY->createHandler( request, response.get()); if (handler == nullptr) { diff --git a/arangod/RestServer/BootstrapFeature.cpp b/arangod/RestServer/BootstrapFeature.cpp index 19ed7f3a82..a4db36e610 100644 --- a/arangod/RestServer/BootstrapFeature.cpp +++ b/arangod/RestServer/BootstrapFeature.cpp @@ -53,7 +53,7 @@ BootstrapFeature::BootstrapFeature( startsAfter("Upgrade"); startsAfter("CheckVersion"); startsAfter("FoxxQueues"); - startsAfter("RestServer"); + startsAfter("GeneralServer"); } void BootstrapFeature::collectOptions(std::shared_ptr options) { diff --git a/arangod/RestServer/ConsoleFeature.cpp b/arangod/RestServer/ConsoleFeature.cpp index 184aa07bdb..e682a32a28 100644 --- a/arangod/RestServer/ConsoleFeature.cpp +++ b/arangod/RestServer/ConsoleFeature.cpp @@ -38,7 +38,7 @@ ConsoleFeature::ConsoleFeature(application_features::ApplicationServer* server) _operationMode(OperationMode::MODE_SERVER), _consoleThread(nullptr) { startsAfter("Server"); - startsAfter("RestServer"); + startsAfter("GeneralServer"); startsAfter("Bootstrap"); } diff --git a/arangod/RestServer/DatabaseFeature.cpp b/arangod/RestServer/DatabaseFeature.cpp index 95b87ea563..4385dc20aa 100644 --- a/arangod/RestServer/DatabaseFeature.cpp +++ b/arangod/RestServer/DatabaseFeature.cpp @@ -25,13 +25,13 @@ #include "Basics/StringUtils.h" #include "Cluster/ServerState.h" #include "Cluster/v8-cluster.h" +#include "GeneralServer/GeneralServerFeature.h" #include "Logger/Logger.h" #include "ProgramOptions/ProgramOptions.h" #include "ProgramOptions/Section.h" #include "Rest/Version.h" #include "RestServer/DatabaseServerFeature.h" #include "RestServer/QueryRegistryFeature.h" -#include "RestServer/RestServerFeature.h" #include "V8Server/V8DealerFeature.h" #include "V8Server/v8-query.h" #include "V8Server/v8-vocbase.h" @@ -245,8 +245,8 @@ void DatabaseFeature::openDatabases() { defaults.forceSyncProperties = _forceSyncProperties; // get authentication (if available) - RestServerFeature* rest = - ApplicationServer::getFeature("RestServer"); + GeneralServerFeature* rest = + ApplicationServer::getFeature("GeneralServer"); defaults.requireAuthentication = rest->authentication(); defaults.requireAuthenticationUnixSockets = rest->authenticationUnixSockets(); diff --git a/arangod/RestServer/ScriptFeature.cpp b/arangod/RestServer/ScriptFeature.cpp index 7a6308be4e..34dea20184 100644 --- a/arangod/RestServer/ScriptFeature.cpp +++ b/arangod/RestServer/ScriptFeature.cpp @@ -43,7 +43,7 @@ ScriptFeature::ScriptFeature(application_features::ApplicationServer* server, in _result(result) { startsAfter("Nonce"); startsAfter("Server"); - startsAfter("RestServer"); + startsAfter("GeneralServer"); } void ScriptFeature::collectOptions(std::shared_ptr options) { diff --git a/arangod/RestServer/ServerFeature.cpp b/arangod/RestServer/ServerFeature.cpp index 7f9ec1482d..0dd1debd90 100644 --- a/arangod/RestServer/ServerFeature.cpp +++ b/arangod/RestServer/ServerFeature.cpp @@ -84,7 +84,6 @@ void ServerFeature::collectOptions(std::shared_ptr options) { options->addOption("--javascript.script", "run scripts and exit", new VectorParameter(&_scripts)); - } void ServerFeature::validateOptions(std::shared_ptr) { @@ -119,19 +118,19 @@ void ServerFeature::validateOptions(std::shared_ptr) { if (!_restServer) { ApplicationServer::disableFeatures({"Daemon", "Dispatcher", "Endpoint", - "RestServer", "Scheduler", "SslServer", - "Supervisor"}); + "GeneralServer", "Scheduler", + "SslServer", "Supervisor"}); - DatabaseFeature* database = + DatabaseFeature* database = ApplicationServer::getFeature("Database"); database->disableReplicationApplier(); - StatisticsFeature* statistics = + StatisticsFeature* statistics = ApplicationServer::getFeature("Statistics"); statistics->disableStatistics(); } - V8DealerFeature* v8dealer = + V8DealerFeature* v8dealer = ApplicationServer::getFeature("V8Dealer"); if (_operationMode == OperationMode::MODE_SCRIPT || @@ -154,7 +153,7 @@ void ServerFeature::validateOptions(std::shared_ptr) { void ServerFeature::start() { if (_operationMode != OperationMode::MODE_CONSOLE && _restServer) { - auto scheduler = + auto scheduler = ApplicationServer::getFeature("Scheduler"); scheduler->buildControlCHandler(); @@ -166,9 +165,9 @@ void ServerFeature::start() { // flush all log output before we go on... this is sensible because any // of the following options may print or prompt, and pending log entries - // might overwrite that + // might overwrite that Logger::flush(); - + switch (_operationMode) { case OperationMode::MODE_UNITTESTS: case OperationMode::MODE_SCRIPT: @@ -200,18 +199,18 @@ void ServerFeature::waitForHeartbeat() { usleep(100 * 1000); } } - + std::string ServerFeature::operationModeString(OperationMode mode) { switch (mode) { - case OperationMode::MODE_CONSOLE: + case OperationMode::MODE_CONSOLE: return "console"; - case OperationMode::MODE_UNITTESTS: + case OperationMode::MODE_UNITTESTS: return "unittests"; - case OperationMode::MODE_SCRIPT: + case OperationMode::MODE_SCRIPT: return "script"; - case OperationMode::MODE_SERVER: + case OperationMode::MODE_SERVER: return "server"; - default: + default: return "unknown"; } } diff --git a/arangod/RestServer/UnitTestsFeature.cpp b/arangod/RestServer/UnitTestsFeature.cpp index 99f5832db7..017e90b2cf 100644 --- a/arangod/RestServer/UnitTestsFeature.cpp +++ b/arangod/RestServer/UnitTestsFeature.cpp @@ -43,7 +43,7 @@ UnitTestsFeature::UnitTestsFeature(application_features::ApplicationServer* serv _result(result) { startsAfter("Nonce"); startsAfter("Server"); - startsAfter("RestServer"); + startsAfter("GeneralServer"); startsAfter("Bootstrap"); } diff --git a/arangod/RestServer/VocbaseContext.cpp b/arangod/RestServer/VocbaseContext.cpp index 8130fd77c9..4d452ebcdb 100644 --- a/arangod/RestServer/VocbaseContext.cpp +++ b/arangod/RestServer/VocbaseContext.cpp @@ -32,8 +32,8 @@ #include "Basics/tri-strings.h" #include "Cluster/ServerState.h" #include "Endpoint/ConnectionInfo.h" +#include "GeneralServer/GeneralServerFeature.h" #include "Logger/Logger.h" -#include "RestServer/RestServerFeature.h" #include "Ssl/SslInterface.h" #include "VocBase/AuthInfo.h" #include "VocBase/server.h" @@ -113,7 +113,7 @@ GeneralResponse::ResponseCode VocbaseContext::authenticate() { if (!username.empty() || !dbname.empty()) { AuthLevel level = - RestServerFeature::AUTH_INFO.canUseDatabase(username, dbname); + GeneralServerFeature::AUTH_INFO.canUseDatabase(username, dbname); if (level != AuthLevel::RW) { result = GeneralResponse::ResponseCode::UNAUTHORIZED; @@ -221,7 +221,7 @@ GeneralResponse::ResponseCode VocbaseContext::basicAuthentication( return GeneralResponse::ResponseCode::OK; } - AuthResult result = RestServerFeature::AUTH_INFO.checkAuthentication( + AuthResult result = GeneralServerFeature::AUTH_INFO.checkAuthentication( AuthInfo::AuthType::BASIC, auth); if (!result._authorized) { @@ -250,7 +250,7 @@ GeneralResponse::ResponseCode VocbaseContext::basicAuthentication( GeneralResponse::ResponseCode VocbaseContext::jwtAuthentication( std::string const& auth) { - AuthResult result = RestServerFeature::AUTH_INFO.checkAuthentication( + AuthResult result = GeneralServerFeature::AUTH_INFO.checkAuthentication( AuthInfo::AuthType::JWT, auth); if (!result._authorized) { diff --git a/arangod/RestServer/arangod.cpp b/arangod/RestServer/arangod.cpp index 2575ee5aa2..2ad7bb1a45 100644 --- a/arangod/RestServer/arangod.cpp +++ b/arangod/RestServer/arangod.cpp @@ -43,6 +43,7 @@ #include "Basics/ArangoGlobalContext.h" #include "Cluster/ClusterFeature.h" #include "Dispatcher/DispatcherFeature.h" +#include "GeneralServer/GeneralServerFeature.h" #include "Logger/LoggerBufferFeature.h" #include "Logger/LoggerFeature.h" #include "ProgramOptions/ProgramOptions.h" @@ -58,7 +59,6 @@ #include "RestServer/FrontendFeature.h" #include "RestServer/InitDatabaseFeature.h" #include "RestServer/QueryRegistryFeature.h" -#include "RestServer/RestServerFeature.h" #include "RestServer/ScriptFeature.h" #include "RestServer/ServerFeature.h" #include "RestServer/UnitTestsFeature.h" @@ -92,18 +92,21 @@ static int runServer(int argc, char** argv) { application_features::ApplicationServer server(options); std::vector nonServerFeatures = { - "Action", "Affinity", "Agency", - "Cluster", "Daemon", "Dispatcher", - "Endpoint", "FoxxQueues", "LoggerBufferFeature", - "RestServer", "Server", "Scheduler", - "SslServer", "Statistics", "Supervisor"}; + "Action", "Affinity", + "Agency", "Cluster", + "Daemon", "Dispatcher", + "Endpoint", "FoxxQueues", + "GeneralServer", "LoggerBufferFeature", + "Server", "Scheduler", + "SslServer", "Statistics", + "Supervisor"}; int ret = EXIT_FAILURE; - + #ifdef _WIN32 server.addFeature(new WindowsServiceFeature(&server)); #endif - + server.addFeature(new ActionFeature(&server)); server.addFeature(new AffinityFeature(&server)); server.addFeature(new AgencyFeature(&server)); @@ -119,6 +122,7 @@ static int runServer(int argc, char** argv) { server.addFeature(new FileDescriptorsFeature(&server)); server.addFeature(new FoxxQueuesFeature(&server)); server.addFeature(new FrontendFeature(&server)); + server.addFeature(new GeneralServerFeature(&server)); server.addFeature(new InitDatabaseFeature(&server, nonServerFeatures)); server.addFeature(new LanguageFeature(&server)); server.addFeature(new LogfileManager(&server)); @@ -129,7 +133,6 @@ static int runServer(int argc, char** argv) { server.addFeature(new QueryRegistryFeature(&server)); server.addFeature(new RandomFeature(&server)); server.addFeature(new RecoveryFeature(&server)); - server.addFeature(new RestServerFeature(&server)); server.addFeature(new SchedulerFeature(&server)); server.addFeature(new ScriptFeature(&server, &ret)); server.addFeature(new ServerFeature(&server, &ret)); @@ -179,12 +182,13 @@ static int runServer(int argc, char** argv) { static int ARGC; static char** ARGV; -static void WINAPI ServiceMain (DWORD dwArgc, LPSTR *lpszArgv) { +static void WINAPI ServiceMain(DWORD dwArgc, LPSTR* lpszArgv) { if (!TRI_InitWindowsEventLog()) { return; } // register the service ctrl handler, lpszArgv[0] contains service name - ServiceStatus = RegisterServiceCtrlHandlerA(lpszArgv[0], (LPHANDLER_FUNCTION) ServiceCtrl); + ServiceStatus = + RegisterServiceCtrlHandlerA(lpszArgv[0], (LPHANDLER_FUNCTION)ServiceCtrl); // set start pending SetServiceStatus(SERVICE_START_PENDING, 0, 1, 10000); @@ -203,17 +207,16 @@ int main(int argc, char* argv[]) { if (argc > 1 && TRI_EqualString("--start-service", argv[1])) { ARGC = argc; ARGV = argv; - - SERVICE_TABLE_ENTRY ste[] = {{TEXT(""), (LPSERVICE_MAIN_FUNCTION)ServiceMain}, - {nullptr, nullptr}}; - + + SERVICE_TABLE_ENTRY ste[] = { + {TEXT(""), (LPSERVICE_MAIN_FUNCTION)ServiceMain}, {nullptr, nullptr}}; + if (!StartServiceCtrlDispatcher(ste)) { std::cerr << "FATAL: StartServiceCtrlDispatcher has failed with " << GetLastError() << std::endl; exit(EXIT_FAILURE); } - } - else + } else #endif return runServer(argc, argv); } diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index 63147619e7..22de96c643 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -23,9 +23,9 @@ #include "v8-vocbaseprivate.h" -#include -#include #include +#include +#include #include #include @@ -50,9 +50,9 @@ #include "Cluster/ClusterInfo.h" #include "Cluster/ClusterMethods.h" #include "Cluster/ServerState.h" +#include "GeneralServer/GeneralServerFeature.h" #include "Rest/Version.h" #include "RestServer/ConsoleThread.h" -#include "RestServer/RestServerFeature.h" #include "RestServer/VocbaseContext.h" #include "Statistics/StatisticsFeature.h" #include "Utils/ExplicitTransaction.h" @@ -555,8 +555,7 @@ static void JS_WaitCollectorWal( std::string const name = TRI_ObjectToString(args[0]); - TRI_vocbase_col_t* col = - TRI_LookupCollectionByNameVocBase(vocbase, name); + TRI_vocbase_col_t* col = TRI_LookupCollectionByNameVocBase(vocbase, name); if (col == nullptr) { TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); @@ -942,7 +941,7 @@ static void JS_ReloadAuth(v8::FunctionCallbackInfo const& args) { TRI_V8_THROW_EXCEPTION_USAGE("RELOAD_AUTH()"); } - RestServerFeature::AUTH_INFO.outdate(); + GeneralServerFeature::AUTH_INFO.outdate(); TRI_V8_RETURN_TRUE(); TRI_V8_TRY_CATCH_END @@ -1196,7 +1195,7 @@ static void JS_ExecuteAqlJson(v8::FunctionCallbackInfo const& args) { TRI_V8_THROW_EXCEPTION(res); } } - + TRI_GET_GLOBALS(); arangodb::aql::Query query(true, vocbase, queryBuilder, options, arangodb::aql::PART_MAIN); @@ -2639,31 +2638,34 @@ static void JS_GetTimers(v8::FunctionCallbackInfo const& args) { static void JS_TrustedProxies(v8::FunctionCallbackInfo const& args) { TRI_V8_TRY_CATCH_BEGIN(isolate); - - if (RestServerFeature::hasProxyCheck()) { + + if (GeneralServerFeature::hasProxyCheck()) { v8::Handle result = v8::Array::New(isolate); uint32_t i = 0; - for (auto const& proxyDef: RestServerFeature::getTrustedProxies()) { + for (auto const& proxyDef : GeneralServerFeature::getTrustedProxies()) { result->Set(i++, TRI_V8_STD_STRING(proxyDef)); } TRI_V8_RETURN(result); } else { TRI_V8_RETURN(v8::Null(isolate)); } - + TRI_V8_TRY_CATCH_END } -static void JS_AuthenticationEnabled(v8::FunctionCallbackInfo const& args) { - // mop: one could argue that this is a function because this might be changable on the fly - // at some time but the sad truth is server startup order :S v8 is initialized after RestServerFeature - // :weglaecheln: +static void JS_AuthenticationEnabled( + v8::FunctionCallbackInfo const& args) { + // mop: one could argue that this is a function because this might be + // changable on the fly at some time but the sad truth is server startup + // order + // v8 is initialized after GeneralServerFeature TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - v8::Handle result = v8::Boolean::New(isolate, RestServerFeature::authenticationEnabled()); - + v8::Handle result = + v8::Boolean::New(isolate, GeneralServerFeature::authenticationEnabled()); + TRI_V8_RETURN(result); TRI_V8_TRY_CATCH_END } @@ -2860,7 +2862,7 @@ void TRI_InitV8VocBridge(v8::Isolate* isolate, v8::Handle context, TRI_AddGlobalFunctionVocbase( isolate, context, TRI_V8_ASCII_STRING("AQL_QUERY_CACHE_INVALIDATE"), JS_QueryCacheInvalidateAql, true); - + TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("OBJECT_HASH"), JS_ObjectHash, true); @@ -2888,9 +2890,8 @@ void TRI_InitV8VocBridge(v8::Isolate* isolate, v8::Handle context, TRI_V8_ASCII_STRING("PARSE_DATETIME"), JS_ParseDatetime); - TRI_AddGlobalFunctionVocbase(isolate, context, - TRI_V8_ASCII_STRING("ENDPOINTS"), - JS_Endpoints, true); + TRI_AddGlobalFunctionVocbase( + isolate, context, TRI_V8_ASCII_STRING("ENDPOINTS"), JS_Endpoints, true); TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("RELOAD_AUTH"), JS_ReloadAuth, true); @@ -2923,11 +2924,13 @@ void TRI_InitV8VocBridge(v8::Isolate* isolate, v8::Handle context, TRI_AddGlobalFunctionVocbase( isolate, context, TRI_V8_ASCII_STRING("GET_TIMERS"), JS_GetTimers, true); - TRI_AddGlobalFunctionVocbase( - isolate, context, TRI_V8_ASCII_STRING("AUTHENTICATION_ENABLED"), JS_AuthenticationEnabled, true); - - TRI_AddGlobalFunctionVocbase( - isolate, context, TRI_V8_ASCII_STRING("TRUSTED_PROXIES"), JS_TrustedProxies, true); + TRI_AddGlobalFunctionVocbase(isolate, context, + TRI_V8_ASCII_STRING("AUTHENTICATION_ENABLED"), + JS_AuthenticationEnabled, true); + + TRI_AddGlobalFunctionVocbase(isolate, context, + TRI_V8_ASCII_STRING("TRUSTED_PROXIES"), + JS_TrustedProxies, true); // ............................................................................. // create global variables // ............................................................................. @@ -2948,7 +2951,7 @@ void TRI_InitV8VocBridge(v8::Isolate* isolate, v8::Handle context, context->Global()->ForceSet(TRI_V8_ASCII_STRING("THREAD_NUMBER"), v8::Number::New(isolate, (double)threadNumber), v8::ReadOnly); - + // whether or not statistics are enabled context->Global()->ForceSet( TRI_V8_ASCII_STRING("ENABLE_STATISTICS"), diff --git a/arangod/VocBase/AuthInfo.cpp b/arangod/VocBase/AuthInfo.cpp index 8365ab4da8..6f2293d6f2 100644 --- a/arangod/VocBase/AuthInfo.cpp +++ b/arangod/VocBase/AuthInfo.cpp @@ -33,9 +33,9 @@ #include "Basics/VelocyPackHelper.h" #include "Basics/WriteLocker.h" #include "Basics/tri-strings.h" +#include "GeneralServer/GeneralServerFeature.h" #include "Logger/Logger.h" #include "RestServer/DatabaseFeature.h" -#include "RestServer/RestServerFeature.h" #include "Ssl/SslInterface.h" #include "Utils/SingleCollectionTransaction.h" #include "Utils/StandaloneTransactionContext.h" @@ -544,7 +544,7 @@ bool AuthInfo::validateJwtHMAC256Signature(std::string const& message, std::string const& signature) { std::string decodedSignature = StringUtils::decodeBase64U(signature); - std::string const& jwtSecret = RestServerFeature::getJwtSecret(); + std::string const& jwtSecret = GeneralServerFeature::getJwtSecret(); return verifyHMAC(jwtSecret.c_str(), jwtSecret.length(), message.c_str(), message.length(), decodedSignature.c_str(), decodedSignature.length(), diff --git a/arangod/VocBase/server.cpp b/arangod/VocBase/server.cpp index 9c0719583b..0eccd20340 100644 --- a/arangod/VocBase/server.cpp +++ b/arangod/VocBase/server.cpp @@ -41,9 +41,9 @@ #include "Basics/memory-map.h" #include "Basics/tri-strings.h" #include "Cluster/ServerState.h" +#include "GeneralServer/GeneralServerFeature.h" #include "Logger/Logger.h" #include "Random/RandomGenerator.h" -#include "RestServer/RestServerFeature.h" #include "Utils/CursorRepository.h" #include "V8Server/V8DealerFeature.h" #include "VocBase/replication-applier.h" @@ -425,7 +425,7 @@ static int OpenDatabases(TRI_server_t* server, bool isUpgrade) { if (!TRI_ExistsFile(parametersFile.c_str())) { // no parameter.json file - + if (TRI_FilesDirectory(databaseDirectory.c_str()).empty()) { // directory is otherwise empty, continue! LOG(WARN) << "ignoring empty database directory '" << databaseDirectory @@ -1998,7 +1998,8 @@ int TRI_GetUserDatabasesServer(TRI_server_t* server, char const* username, char const* dbName = p.second->_name; TRI_ASSERT(dbName != nullptr); - auto level = RestServerFeature::AUTH_INFO.canUseDatabase(username, dbName); + auto level = + GeneralServerFeature::AUTH_INFO.canUseDatabase(username, dbName); if (level == AuthLevel::NONE) { continue;