mirror of https://gitee.com/bigwinds/arangodb
WIP
This commit is contained in:
parent
3f9dd62d4c
commit
0fa6435731
|
@ -234,6 +234,7 @@ add_executable(${BIN_ARANGOD}
|
|||
Scheduler/Task.cpp
|
||||
Scheduler/TaskManager.cpp
|
||||
Scheduler/TimerTask.cpp
|
||||
Statistics/StatisticsFeature.cpp
|
||||
Statistics/statistics.cpp
|
||||
Storage/Marker.cpp
|
||||
Storage/Options.cpp
|
||||
|
|
|
@ -31,10 +31,8 @@
|
|||
using namespace arangodb;
|
||||
using namespace arangodb::rest;
|
||||
|
||||
RestShardHandler::RestShardHandler(arangodb::HttpRequest* request,
|
||||
Dispatcher* data)
|
||||
: RestBaseHandler(request), _dispatcher(data) {
|
||||
TRI_ASSERT(_dispatcher != nullptr);
|
||||
RestShardHandler::RestShardHandler(arangodb::HttpRequest* request)
|
||||
: RestBaseHandler(request) {
|
||||
}
|
||||
|
||||
bool RestShardHandler::isDirect() const { return true; }
|
||||
|
|
|
@ -38,7 +38,7 @@ class Dispatcher;
|
|||
|
||||
class RestShardHandler : public RestBaseHandler {
|
||||
public:
|
||||
RestShardHandler(HttpRequest* request, rest::Dispatcher*);
|
||||
RestShardHandler(HttpRequest* request);
|
||||
|
||||
public:
|
||||
bool isDirect() const override;
|
||||
|
@ -48,13 +48,6 @@ class RestShardHandler : public RestBaseHandler {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
status_t execute() override;
|
||||
|
||||
private:
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief dispatcher
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
rest::Dispatcher* TRI_UNUSED _dispatcher;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "Basics/conversions.h"
|
||||
#include "Basics/StringUtils.h"
|
||||
#include "Dispatcher/Dispatcher.h"
|
||||
#include "Dispatcher/DispatcherFeature.h"
|
||||
#include "HttpServer/AsyncJobManager.h"
|
||||
#include "Rest/HttpRequest.h"
|
||||
#include "Rest/HttpResponse.h"
|
||||
|
@ -37,10 +38,8 @@ using namespace arangodb::basics;
|
|||
using namespace arangodb::rest;
|
||||
|
||||
RestJobHandler::RestJobHandler(HttpRequest* request,
|
||||
std::pair<Dispatcher*, AsyncJobManager*>* data)
|
||||
: RestBaseHandler(request),
|
||||
_dispatcher(data->first),
|
||||
_jobManager(data->second) {}
|
||||
AsyncJobManager* jobManager)
|
||||
: RestBaseHandler(request), _jobManager(jobManager) {}
|
||||
|
||||
bool RestJobHandler::isDirect() const { return true; }
|
||||
|
||||
|
@ -58,7 +57,8 @@ HttpHandler::status_t RestJobHandler::execute() {
|
|||
} else if (suffix.size() == 2) {
|
||||
putJobMethod();
|
||||
} else {
|
||||
generateError(GeneralResponse::ResponseCode::BAD, TRI_ERROR_HTTP_BAD_PARAMETER);
|
||||
generateError(GeneralResponse::ResponseCode::BAD,
|
||||
TRI_ERROR_HTTP_BAD_PARAMETER);
|
||||
}
|
||||
} else if (type == GeneralRequest::RequestType::DELETE_REQ) {
|
||||
deleteJob();
|
||||
|
@ -122,7 +122,7 @@ void RestJobHandler::putJobMethod() {
|
|||
uint64_t jobId = StringUtils::uint64(value);
|
||||
|
||||
if (method == "cancel") {
|
||||
bool status = _dispatcher->cancelJob(jobId);
|
||||
bool status = DispatcherFeature::DISPATCHER->cancelJob(jobId);
|
||||
|
||||
// unknown or already fetched job
|
||||
if (!status) {
|
||||
|
|
|
@ -40,8 +40,7 @@ class Dispatcher;
|
|||
|
||||
class RestJobHandler : public RestBaseHandler {
|
||||
public:
|
||||
RestJobHandler(HttpRequest* request,
|
||||
std::pair<rest::Dispatcher*, rest::AsyncJobManager*>*);
|
||||
RestJobHandler(HttpRequest* request, rest::AsyncJobManager*);
|
||||
|
||||
public:
|
||||
bool isDirect() const override;
|
||||
|
@ -89,12 +88,6 @@ class RestJobHandler : public RestBaseHandler {
|
|||
void deleteJob();
|
||||
|
||||
private:
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief dispatcher
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
rest::Dispatcher* _dispatcher;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief async job manager
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -32,11 +32,8 @@ using namespace arangodb;
|
|||
using namespace arangodb::application_features;
|
||||
using namespace arangodb::rest;
|
||||
|
||||
RestShutdownHandler::RestShutdownHandler(HttpRequest* request,
|
||||
void* applicationServer)
|
||||
: RestBaseHandler(request),
|
||||
_applicationServer(
|
||||
static_cast<ApplicationServer*>(applicationServer)) {}
|
||||
RestShutdownHandler::RestShutdownHandler(HttpRequest* request)
|
||||
: RestBaseHandler(request) {}
|
||||
|
||||
bool RestShutdownHandler::isDirect() const { return true; }
|
||||
|
||||
|
@ -45,7 +42,7 @@ bool RestShutdownHandler::isDirect() const { return true; }
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
HttpHandler::status_t RestShutdownHandler::execute() {
|
||||
_applicationServer->beginShutdown();
|
||||
ApplicationServer::server->beginShutdown();
|
||||
|
||||
try {
|
||||
VPackBuilder json;
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace arangodb {
|
|||
|
||||
class RestShutdownHandler : public RestBaseHandler {
|
||||
public:
|
||||
RestShutdownHandler(HttpRequest*, void* applicationServer);
|
||||
RestShutdownHandler(HttpRequest*);
|
||||
|
||||
public:
|
||||
bool isDirect() const override;
|
||||
|
@ -47,13 +47,6 @@ class RestShutdownHandler : public RestBaseHandler {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
status_t execute() override;
|
||||
|
||||
private:
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief application server
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
application_features::ApplicationServer* _applicationServer;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "ProgramOptions/ProgramOptions.h"
|
||||
#include "ProgramOptions/Section.h"
|
||||
#include "Rest/Version.h"
|
||||
#include "RestServer/RestServerFeature.h"
|
||||
#include "V8Server/V8DealerFeature.h"
|
||||
#include "V8Server/v8-query.h"
|
||||
#include "V8Server/v8-vocbase.h"
|
||||
|
@ -309,13 +310,19 @@ void DatabaseFeature::openDatabases() {
|
|||
defaults.defaultWaitForSync = _defaultWaitForSync;
|
||||
defaults.forceSyncProperties = _forceSyncProperties;
|
||||
|
||||
#warning TODO
|
||||
#if 0
|
||||
defaults.requireAuthentication = !_disableAuthentication;
|
||||
defaults.requireAuthenticationUnixSockets =
|
||||
!_disableAuthenticationUnixSockets;
|
||||
defaults.authenticateSystemOnly = _authenticateSystemOnly;
|
||||
#endif
|
||||
// get authentication (if available)
|
||||
RestServerFeature* rest = dynamic_cast<RestServerFeature*>(
|
||||
ApplicationServer::lookupFeature("RestServer"));
|
||||
|
||||
if (rest != nullptr) {
|
||||
defaults.requireAuthentication = rest->authentication();
|
||||
defaults.requireAuthenticationUnixSockets = rest->authenticationUnixSockets();
|
||||
defaults.authenticateSystemOnly = rest->authenticationSystemOnly();
|
||||
} else {
|
||||
defaults.requireAuthentication = true;
|
||||
defaults.requireAuthenticationUnixSockets = true;
|
||||
defaults.authenticateSystemOnly = false;
|
||||
}
|
||||
|
||||
TRI_ASSERT(_server != nullptr);
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ class DatabaseFeature final : public application_features::ApplicationFeature {
|
|||
public:
|
||||
TRI_vocbase_t* vocbase() const { return _vocbase; }
|
||||
TRI_server_t* server() const { return _server.get(); }
|
||||
aql::QueryRegistry* queryRegistry() const { return _queryRegistry.get(); }
|
||||
|
||||
bool ignoreDatafileErrors() const { return _ignoreDatafileErrors; }
|
||||
bool isInitiallyEmpty() const { return _isInitiallyEmpty; }
|
||||
|
|
|
@ -23,10 +23,6 @@
|
|||
|
||||
#include "EndpointFeature.h"
|
||||
|
||||
#include "ApplicationFeatures/SslFeature.h"
|
||||
#include "Dispatcher/DispatcherFeature.h"
|
||||
#include "HttpServer/HttpServer.h"
|
||||
#include "HttpServer/HttpsServer.h"
|
||||
#include "ProgramOptions/ProgramOptions.h"
|
||||
#include "ProgramOptions/Section.h"
|
||||
#include "RestServer/ServerFeature.h"
|
||||
|
@ -41,8 +37,7 @@ EndpointFeature::EndpointFeature(
|
|||
application_features::ApplicationServer* server)
|
||||
: ApplicationFeature(server, "Endpoint"),
|
||||
_reuseAddress(true),
|
||||
_backlogSize(64),
|
||||
_keepAliveTimeout(300.0) {
|
||||
_backlogSize(64) {
|
||||
setOptional(true);
|
||||
requiresElevatedPrivileges(true);
|
||||
startsAfter("Ssl");
|
||||
|
@ -73,12 +68,6 @@ void EndpointFeature::collectOptions(std::shared_ptr<ProgramOptions> options) {
|
|||
|
||||
options->addHiddenOption("--tcp.backlog-size", "listen backlog size",
|
||||
new UInt64Parameter(&_backlogSize));
|
||||
|
||||
options->addSection("http", "HttpServer features");
|
||||
|
||||
options->addOption("--http.keep-alive-timeout",
|
||||
"keep-alive timeout in seconds",
|
||||
new DoubleParameter(&_keepAliveTimeout));
|
||||
}
|
||||
|
||||
void EndpointFeature::validateOptions(std::shared_ptr<ProgramOptions>) {
|
||||
|
@ -109,6 +98,11 @@ void EndpointFeature::start() {
|
|||
_endpointList.dump();
|
||||
}
|
||||
|
||||
std::vector<std::string> EndpointFeature::httpEndpoints() {
|
||||
#warning TODO
|
||||
return {};
|
||||
}
|
||||
|
||||
void EndpointFeature::buildEndpointLists() {
|
||||
for (std::vector<std::string>::const_iterator i = _endpoints.begin();
|
||||
i != _endpoints.end(); ++i) {
|
||||
|
|
|
@ -24,9 +24,9 @@
|
|||
#ifndef ARANGOD_HTTP_SERVER_ENDPOINT_FEATURE_H
|
||||
#define ARANGOD_HTTP_SERVER_ENDPOINT_FEATURE_H 1
|
||||
|
||||
#include "Basics/Common.h"
|
||||
|
||||
#include "ApplicationFeatures/ApplicationFeature.h"
|
||||
#include "ApplicationFeatures/HttpEndpointProvider.h"
|
||||
|
||||
#include "Endpoint/EndpointList.h"
|
||||
|
||||
namespace arangodb {
|
||||
|
@ -35,7 +35,8 @@ class HttpServer;
|
|||
class HttpsServer;
|
||||
}
|
||||
|
||||
class EndpointFeature final : public application_features::ApplicationFeature {
|
||||
class EndpointFeature final : public application_features::ApplicationFeature,
|
||||
public HttpEndpointProvider {
|
||||
public:
|
||||
explicit EndpointFeature(application_features::ApplicationServer* server);
|
||||
|
||||
|
@ -45,14 +46,17 @@ class EndpointFeature final : public application_features::ApplicationFeature {
|
|||
void prepare() override final;
|
||||
void start() override final;
|
||||
|
||||
private:
|
||||
void buildEndpointLists();
|
||||
|
||||
private:
|
||||
std::vector<std::string> _endpoints;
|
||||
bool _reuseAddress;
|
||||
uint64_t _backlogSize;
|
||||
double _keepAliveTimeout;
|
||||
|
||||
public:
|
||||
std::vector<std::string> httpEndpoints() override;
|
||||
EndpointList const& endpointList() const { return _endpointList; }
|
||||
|
||||
private:
|
||||
void buildEndpointLists();
|
||||
|
||||
private:
|
||||
EndpointList _endpointList;
|
||||
|
|
|
@ -22,148 +22,101 @@
|
|||
|
||||
#include "RestServerFeature.h"
|
||||
|
||||
#include "ApplicationFeatures/SslFeature.h"
|
||||
#include "Aql/RestAqlHandler.h"
|
||||
#include "Cluster/ClusterComm.h"
|
||||
#include "Cluster/RestShardHandler.h"
|
||||
#include "Dispatcher/DispatcherFeature.h"
|
||||
#include "HttpServer/HttpHandlerFactory.h"
|
||||
#include "HttpServer/HttpServer.h"
|
||||
#include "HttpServer/HttpsServer.h"
|
||||
#include "ProgramOptions/ProgramOptions.h"
|
||||
#include "ProgramOptions/Section.h"
|
||||
#include "Rest/Version.h"
|
||||
#include "RestHandler/RestAdminLogHandler.h"
|
||||
#include "RestHandler/RestBatchHandler.h"
|
||||
#include "RestHandler/RestCursorHandler.h"
|
||||
#include "RestHandler/RestDebugHandler.h"
|
||||
#include "RestHandler/RestDocumentHandler.h"
|
||||
#include "RestHandler/RestEdgeHandler.h"
|
||||
#include "RestHandler/RestEdgesHandler.h"
|
||||
#include "RestHandler/RestExportHandler.h"
|
||||
#include "RestHandler/RestHandlerCreator.h"
|
||||
#include "RestHandler/RestImportHandler.h"
|
||||
#include "RestHandler/RestJobHandler.h"
|
||||
#include "RestHandler/RestPleaseUpgradeHandler.h"
|
||||
#include "RestHandler/RestQueryCacheHandler.h"
|
||||
#include "RestHandler/RestQueryHandler.h"
|
||||
#include "RestHandler/RestReplicationHandler.h"
|
||||
#include "RestHandler/RestShutdownHandler.h"
|
||||
#include "RestHandler/RestSimpleHandler.h"
|
||||
#include "RestHandler/RestSimpleQueryHandler.h"
|
||||
#include "RestHandler/RestUploadHandler.h"
|
||||
#include "RestHandler/RestVersionHandler.h"
|
||||
#include "RestHandler/WorkMonitorHandler.h"
|
||||
#include "RestServer/DatabaseFeature.h"
|
||||
#include "RestServer/EndpointFeature.h"
|
||||
#include "RestServer/ServerFeature.h"
|
||||
#include "Scheduler/SchedulerFeature.h"
|
||||
#include "V8Server/V8DealerFeature.h"
|
||||
|
||||
using namespace arangodb;
|
||||
using namespace arangodb::application_features;
|
||||
using namespace arangodb::rest;
|
||||
using namespace arangodb::options;
|
||||
|
||||
RestServerFeature::RestServerFeature(application_features::ApplicationServer* server)
|
||||
: ApplicationFeature(server, "RestServer") {
|
||||
RestServerFeature::RestServerFeature(
|
||||
application_features::ApplicationServer* server,
|
||||
std::string const& authenticationRealm)
|
||||
: ApplicationFeature(server, "RestServer"),
|
||||
_keepAliveTimeout(300.0),
|
||||
_authenticationRealm(authenticationRealm),
|
||||
_defaultApiCompatibility(Version::getNumericServerVersion()),
|
||||
_allowMethodOverride(false),
|
||||
_handlerFactory(nullptr),
|
||||
_jobManager(nullptr) {
|
||||
setOptional(true);
|
||||
requiresElevatedPrivileges(false);
|
||||
startsAfter("Dispatcher");
|
||||
startsAfter("Endpoint");
|
||||
startsAfter("Scheduler");
|
||||
startsAfter("Server");
|
||||
}
|
||||
|
||||
void RestServerFeature::start() {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::start";
|
||||
void RestServerFeature::collectOptions(
|
||||
std::shared_ptr<ProgramOptions> options) {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::collectOptions";
|
||||
|
||||
options->addSection("server", "Server features");
|
||||
|
||||
options->addHiddenOption("--server.default-api-compatibility",
|
||||
"default API compatibility version",
|
||||
new Int32Parameter(&_defaultApiCompatibility));
|
||||
|
||||
options->addSection("http", "HttpServer features");
|
||||
|
||||
options->addSection("http", "HttpServer features");
|
||||
|
||||
options->addHiddenOption("--http.allow-method-override",
|
||||
"allow HTTP method override using special headers",
|
||||
new BooleanParameter(&_allowMethodOverride));
|
||||
|
||||
options->addOption("--http.keep-alive-timeout",
|
||||
"keep-alive timeout in seconds",
|
||||
new DoubleParameter(&_keepAliveTimeout));
|
||||
}
|
||||
|
||||
void RestServerFeature::stop() {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::stop";
|
||||
void RestServerFeature::validateOptions(std::shared_ptr<ProgramOptions>) {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::validateOptions";
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
_jobManager(nullptr),
|
||||
|
||||
rest::AsyncJobManager* jobManager() const { return _jobManager; }
|
||||
|
||||
_handlerFactory(nullptr),
|
||||
rest::AsyncJobManager* _jobManager;
|
||||
|
||||
|
||||
defineHandlers();
|
||||
|
||||
// disabled maintenance mode
|
||||
HttpHandlerFactory::setMaintenance(false);
|
||||
|
||||
|
||||
void buildServers();
|
||||
|
||||
std::vector<rest::HttpServer*> _servers;
|
||||
|
||||
|
||||
|
||||
prepare:
|
||||
buildHandlerFactory();
|
||||
HttpHandlerFactory::setMaintenance(true);
|
||||
|
||||
|
||||
start:
|
||||
buildServers();
|
||||
|
||||
for (auto& server : _servers) {
|
||||
server->startListening();
|
||||
}
|
||||
|
||||
#warning TODO
|
||||
#if 0
|
||||
_jobManager = new AsyncJobManager(ClusterCommRestCallback);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
stop:
|
||||
|
||||
for (auto& server : _servers) {
|
||||
server->stopListening();
|
||||
}
|
||||
|
||||
for (auto& server : _servers) {
|
||||
server->stop();
|
||||
}
|
||||
|
||||
for (auto& server : _servers) {
|
||||
delete server;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void EndpointFeature::buildServers() {
|
||||
ServerFeature* server = dynamic_cast<ServerFeature*>(
|
||||
application_features::ApplicationServer::lookupFeature("Server"));
|
||||
|
||||
TRI_ASSERT(server != nullptr);
|
||||
|
||||
HttpHandlerFactory* handlerFactory = server->httpHandlerFactory();
|
||||
AsyncJobManager* jobManager = server->jobManager();
|
||||
|
||||
#warning TODO filter list
|
||||
HttpServer* httpServer;
|
||||
|
||||
// unencrypted HTTP endpoints
|
||||
httpServer =
|
||||
new HttpServer(SchedulerFeature::SCHEDULER, DispatcherFeature::DISPATCHER,
|
||||
handlerFactory, jobManager, _keepAliveTimeout);
|
||||
|
||||
httpServer->setEndpointList(&_endpointList);
|
||||
_servers.push_back(httpServer);
|
||||
|
||||
// ssl endpoints
|
||||
if (_endpointList.hasSsl()) {
|
||||
SslFeature* ssl = dynamic_cast<SslFeature*>(
|
||||
application_features::ApplicationServer::lookupFeature("Ssl"));
|
||||
|
||||
// check the ssl context
|
||||
if (ssl == nullptr || ssl->sslContext() == nullptr) {
|
||||
LOG(FATAL) << "no ssl context is known, cannot create https server, "
|
||||
"please use the '--ssl.keyfile' option";
|
||||
if (_defaultApiCompatibility < HttpRequest::MIN_COMPATIBILITY) {
|
||||
LOG(FATAL) << "invalid value for --server.default-api-compatibility. "
|
||||
"minimum allowed value is "
|
||||
<< HttpRequest::MIN_COMPATIBILITY;
|
||||
FATAL_ERROR_EXIT();
|
||||
}
|
||||
|
||||
SSL_CTX* sslContext = ssl->sslContext();
|
||||
|
||||
// https
|
||||
httpServer = new HttpsServer(SchedulerFeature::SCHEDULER,
|
||||
DispatcherFeature::DISPATCHER, handlerFactory,
|
||||
jobManager, _keepAliveTimeout, sslContext);
|
||||
|
||||
httpServer->setEndpointList(&_endpointList);
|
||||
_servers.push_back(httpServer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
std::unique_ptr<rest::HttpHandlerFactory> _handlerFactory;
|
||||
|
||||
void buildHandlerFactory();
|
||||
void defineHandlers();
|
||||
|
||||
rest::HttpHandlerFactory* httpHandlerFactory() const {
|
||||
return _handlerFactory.get();
|
||||
}
|
||||
|
||||
static TRI_vocbase_t* LookupDatabaseFromRequest(HttpRequest* request,
|
||||
TRI_server_t* server) {
|
||||
// get database name from request
|
||||
|
@ -205,15 +158,102 @@ static bool SetRequestContext(HttpRequest* request, void* data) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void ServerFeature::buildHandlerFactory() {
|
||||
_handlerFactory.reset(new HttpHandlerFactory(
|
||||
_authenticationRealm, _defaultApiCompatibility, _allowMethodOverride,
|
||||
&SetRequestContext, nullptr));
|
||||
void RestServerFeature::prepare() {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::prepare";
|
||||
|
||||
HttpHandlerFactory::setMaintenance(true);
|
||||
}
|
||||
|
||||
void ServerFeature::defineHandlers() {
|
||||
#warning TODO
|
||||
#if 0
|
||||
void RestServerFeature::start() {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::start";
|
||||
|
||||
LOG(DEBUG) << "using default API compatibility: "
|
||||
<< (long int)_defaultApiCompatibility;
|
||||
|
||||
_jobManager.reset(new AsyncJobManager(ClusterCommRestCallback));
|
||||
|
||||
auto vocbase = DatabaseFeature::DATABASE->vocbase();
|
||||
V8DealerFeature::DEALER->loadJavascript(vocbase, "server/server.js");
|
||||
_httpOptions._vocbase = vocbase;
|
||||
|
||||
auto server = DatabaseFeature::DATABASE->server();
|
||||
_handlerFactory.reset(new HttpHandlerFactory(
|
||||
_authenticationRealm, _defaultApiCompatibility, _allowMethodOverride,
|
||||
&SetRequestContext, server));
|
||||
|
||||
defineHandlers();
|
||||
buildServers();
|
||||
|
||||
for (auto& server : _servers) {
|
||||
server->startListening();
|
||||
}
|
||||
|
||||
// disabled maintenance mode
|
||||
HttpHandlerFactory::setMaintenance(false);
|
||||
}
|
||||
|
||||
void RestServerFeature::stop() {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::stop";
|
||||
|
||||
for (auto& server : _servers) {
|
||||
server->stopListening();
|
||||
}
|
||||
|
||||
for (auto& server : _servers) {
|
||||
server->stop();
|
||||
}
|
||||
|
||||
for (auto& server : _servers) {
|
||||
delete server;
|
||||
}
|
||||
|
||||
_httpOptions._vocbase = nullptr;
|
||||
}
|
||||
|
||||
void RestServerFeature::buildServers() {
|
||||
EndpointFeature* endpoint = dynamic_cast<EndpointFeature*>(
|
||||
application_features::ApplicationServer::lookupFeature("Endpoint"));
|
||||
|
||||
HttpServer* httpServer;
|
||||
|
||||
// unencrypted HTTP endpoints
|
||||
httpServer = new HttpServer(
|
||||
SchedulerFeature::SCHEDULER, DispatcherFeature::DISPATCHER,
|
||||
_handlerFactory.get(), _jobManager.get(), _keepAliveTimeout);
|
||||
|
||||
#warning TODO filter list
|
||||
auto const& endpointList = endpoint->endpointList();
|
||||
httpServer->setEndpointList(&endpointList);
|
||||
_servers.push_back(httpServer);
|
||||
|
||||
// ssl endpoints
|
||||
if (endpointList.hasSsl()) {
|
||||
SslFeature* ssl = dynamic_cast<SslFeature*>(
|
||||
application_features::ApplicationServer::lookupFeature("Ssl"));
|
||||
|
||||
// check the ssl context
|
||||
if (ssl == nullptr || ssl->sslContext() == nullptr) {
|
||||
LOG(FATAL) << "no ssl context is known, cannot create https server, "
|
||||
"please use the '--ssl.keyfile' option";
|
||||
FATAL_ERROR_EXIT();
|
||||
}
|
||||
|
||||
SSL_CTX* sslContext = ssl->sslContext();
|
||||
|
||||
// https
|
||||
httpServer =
|
||||
new HttpsServer(SchedulerFeature::SCHEDULER,
|
||||
DispatcherFeature::DISPATCHER, _handlerFactory.get(),
|
||||
_jobManager.get(), _keepAliveTimeout, sslContext);
|
||||
|
||||
httpServer->setEndpointList(&endpointList);
|
||||
_servers.push_back(httpServer);
|
||||
}
|
||||
}
|
||||
|
||||
void RestServerFeature::defineHandlers() {
|
||||
auto queryRegistry = DatabaseFeature::DATABASE->queryRegistry();
|
||||
|
||||
// ...........................................................................
|
||||
// /_msg
|
||||
// ...........................................................................
|
||||
|
@ -232,9 +272,8 @@ void ServerFeature::defineHandlers() {
|
|||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
RestVocbaseBaseHandler::CURSOR_PATH,
|
||||
RestHandlerCreator<RestCursorHandler>::createData<
|
||||
std::pair<ApplicationV8*, aql::QueryRegistry*>*>,
|
||||
_pairForAqlHandler);
|
||||
RestHandlerCreator<RestCursorHandler>::createData<aql::QueryRegistry*>,
|
||||
queryRegistry);
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
RestVocbaseBaseHandler::DOCUMENT_PATH,
|
||||
|
@ -248,62 +287,48 @@ void ServerFeature::defineHandlers() {
|
|||
RestVocbaseBaseHandler::EDGES_PATH,
|
||||
RestHandlerCreator<RestEdgesHandler>::createNoData);
|
||||
|
||||
#warning TODO
|
||||
#if 0
|
||||
_handlerFactory->addPrefixHandler(
|
||||
RestVocbaseBaseHandler::EXPORT_PATH,
|
||||
RestHandlerCreator<RestExportHandler>::createNoData);
|
||||
#endif
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
RestVocbaseBaseHandler::IMPORT_PATH,
|
||||
RestHandlerCreator<RestImportHandler>::createNoData);
|
||||
|
||||
#warning TODO
|
||||
#if 0
|
||||
_handlerFactory->addPrefixHandler(
|
||||
RestVocbaseBaseHandler::REPLICATION_PATH,
|
||||
RestHandlerCreator<RestReplicationHandler>::createNoData);
|
||||
#endif
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
RestVocbaseBaseHandler::SIMPLE_QUERY_ALL_PATH,
|
||||
RestHandlerCreator<RestSimpleQueryHandler>::createData<
|
||||
std::pair<ApplicationV8*, aql::QueryRegistry*>*>,
|
||||
_pairForAqlHandler);
|
||||
aql::QueryRegistry*>,
|
||||
queryRegistry);
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
RestVocbaseBaseHandler::SIMPLE_LOOKUP_PATH,
|
||||
RestHandlerCreator<RestSimpleHandler>::createData<
|
||||
std::pair<ApplicationV8*, aql::QueryRegistry*>*>,
|
||||
_pairForAqlHandler);
|
||||
RestHandlerCreator<RestSimpleHandler>::createData<aql::QueryRegistry*>,
|
||||
queryRegistry);
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
RestVocbaseBaseHandler::SIMPLE_REMOVE_PATH,
|
||||
RestHandlerCreator<RestSimpleHandler>::createData<
|
||||
std::pair<ApplicationV8*, aql::QueryRegistry*>*>,
|
||||
_pairForAqlHandler);
|
||||
RestHandlerCreator<RestSimpleHandler>::createData<aql::QueryRegistry*>,
|
||||
queryRegistry);
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
RestVocbaseBaseHandler::UPLOAD_PATH,
|
||||
RestHandlerCreator<RestUploadHandler>::createNoData);
|
||||
|
||||
#warning TODO
|
||||
#if 0
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_api/shard-comm",
|
||||
RestHandlerCreator<RestShardHandler>::createNoData);
|
||||
#endif
|
||||
"/_api/shard-comm", RestHandlerCreator<RestShardHandler>::createNoData);
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_api/aql", RestHandlerCreator<aql::RestAqlHandler>::createData<
|
||||
std::pair<ApplicationV8*, aql::QueryRegistry*>*>,
|
||||
_pairForAqlHandler);
|
||||
"/_api/aql",
|
||||
RestHandlerCreator<aql::RestAqlHandler>::createData<aql::QueryRegistry*>,
|
||||
queryRegistry);
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_api/query",
|
||||
RestHandlerCreator<RestQueryHandler>::createData<ApplicationV8*>,
|
||||
_applicationV8);
|
||||
"/_api/query", RestHandlerCreator<RestQueryHandler>::createNoData);
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_api/query-cache",
|
||||
|
@ -312,12 +337,11 @@ void ServerFeature::defineHandlers() {
|
|||
// And now some handlers which are registered in both /_api and /_admin
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_api/job", RestHandlerCreator<arangodb::RestJobHandler>::createData<
|
||||
std::pair<Dispatcher*, AsyncJobManager*>*>,
|
||||
_pairForJobHandler);
|
||||
AsyncJobManager*>,
|
||||
_jobManager.get());
|
||||
|
||||
_handlerFactory->addHandler(
|
||||
"/_api/version", RestHandlerCreator<RestVersionHandler>::createNoData,
|
||||
nullptr);
|
||||
"/_api/version", RestHandlerCreator<RestVersionHandler>::createNoData);
|
||||
|
||||
// ...........................................................................
|
||||
// /_admin
|
||||
|
@ -325,36 +349,30 @@ void ServerFeature::defineHandlers() {
|
|||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_admin/job", RestHandlerCreator<arangodb::RestJobHandler>::createData<
|
||||
std::pair<Dispatcher*, AsyncJobManager*>*>,
|
||||
_pairForJobHandler);
|
||||
AsyncJobManager*>,
|
||||
_jobManager.get());
|
||||
|
||||
_handlerFactory->addHandler(
|
||||
"/_admin/version", RestHandlerCreator<RestVersionHandler>::createNoData,
|
||||
nullptr);
|
||||
"/_admin/version", RestHandlerCreator<RestVersionHandler>::createNoData);
|
||||
|
||||
// further admin handlers
|
||||
_handlerFactory->addHandler(
|
||||
"/_admin/log",
|
||||
RestHandlerCreator<arangodb::RestAdminLogHandler>::createNoData, nullptr);
|
||||
RestHandlerCreator<arangodb::RestAdminLogHandler>::createNoData);
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_admin/work-monitor",
|
||||
RestHandlerCreator<WorkMonitorHandler>::createNoData, nullptr);
|
||||
RestHandlerCreator<WorkMonitorHandler>::createNoData);
|
||||
|
||||
// This handler is to activate SYS_DEBUG_FAILAT on DB servers
|
||||
#ifdef ARANGODB_ENABLE_FAILURE_TESTS
|
||||
// This handler is to activate SYS_DEBUG_FAILAT on DB servers
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_admin/debug", RestHandlerCreator<RestDebugHandler>::createNoData,
|
||||
nullptr);
|
||||
"/_admin/debug", RestHandlerCreator<RestDebugHandler>::createNoData);
|
||||
#endif
|
||||
|
||||
#warning TODO
|
||||
#if 0
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_admin/shutdown",
|
||||
RestHandlerCreator<arangodb::RestShutdownHandler>::createData<void*>,
|
||||
static_cast<void*>(_applicationServer));
|
||||
#endif
|
||||
RestHandlerCreator<arangodb::RestShutdownHandler>::createNoData);
|
||||
|
||||
// ...........................................................................
|
||||
// /_admin
|
||||
|
@ -363,8 +381,5 @@ void ServerFeature::defineHandlers() {
|
|||
_handlerFactory->addPrefixHandler(
|
||||
"/", RestHandlerCreator<RestActionHandler>::createData<
|
||||
RestActionHandler::action_options_t*>,
|
||||
(void*)&httpOptions);
|
||||
#endif
|
||||
(void*)&_httpOptions);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -25,16 +25,51 @@
|
|||
|
||||
#include "ApplicationFeatures/ApplicationFeature.h"
|
||||
|
||||
#include "Actions/RestActionHandler.h"
|
||||
|
||||
namespace arangodb {
|
||||
namespace rest {
|
||||
class AsyncJobManager;
|
||||
class HttpHandlerFactory;
|
||||
class HttpServer;
|
||||
}
|
||||
|
||||
class RestServerThread;
|
||||
|
||||
class RestServerFeature final : public application_features::ApplicationFeature {
|
||||
class RestServerFeature final
|
||||
: public application_features::ApplicationFeature {
|
||||
public:
|
||||
explicit RestServerFeature(application_features::ApplicationServer* server);
|
||||
RestServerFeature(application_features::ApplicationServer*,
|
||||
std::string const&);
|
||||
|
||||
public:
|
||||
void collectOptions(std::shared_ptr<options::ProgramOptions>) override final;
|
||||
void validateOptions(std::shared_ptr<options::ProgramOptions>) override final;
|
||||
void prepare() override final;
|
||||
void start() override final;
|
||||
void stop() override final;
|
||||
|
||||
private:
|
||||
double _keepAliveTimeout;
|
||||
std::string const _authenticationRealm;
|
||||
int32_t _defaultApiCompatibility;
|
||||
bool _allowMethodOverride;
|
||||
|
||||
public:
|
||||
#warning TODO
|
||||
bool authentication() const { return false; }
|
||||
bool authenticationUnixSockets() const { return false; }
|
||||
bool authenticationSystemOnly() const { return false; }
|
||||
|
||||
private:
|
||||
void buildServers();
|
||||
void defineHandlers();
|
||||
|
||||
private:
|
||||
std::unique_ptr<rest::HttpHandlerFactory> _handlerFactory;
|
||||
std::unique_ptr<rest::AsyncJobManager> _jobManager;
|
||||
std::vector<rest::HttpServer*> _servers;
|
||||
RestActionHandler::action_options_t _httpOptions;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -22,43 +22,22 @@
|
|||
|
||||
#include "ServerFeature.h"
|
||||
|
||||
#include "Aql/RestAqlHandler.h"
|
||||
#include "Basics/ArangoGlobalContext.h"
|
||||
#include "Basics/process-utils.h"
|
||||
#include "Cluster/HeartbeatThread.h"
|
||||
#include "Cluster/RestShardHandler.h"
|
||||
#include "HttpServer/HttpHandlerFactory.h"
|
||||
#include "Cluster/ServerState.h"
|
||||
#include "Logger/Logger.h"
|
||||
#include "ProgramOptions/ProgramOptions.h"
|
||||
#include "ProgramOptions/Section.h"
|
||||
#include "Rest/HttpRequest.h"
|
||||
#include "Rest/Version.h"
|
||||
#include "RestHandler/RestAdminLogHandler.h"
|
||||
#include "RestHandler/RestBatchHandler.h"
|
||||
#include "RestHandler/RestCursorHandler.h"
|
||||
#include "RestHandler/RestDebugHandler.h"
|
||||
#include "RestHandler/RestDocumentHandler.h"
|
||||
#include "RestHandler/RestEdgeHandler.h"
|
||||
#include "RestHandler/RestEdgesHandler.h"
|
||||
#include "RestHandler/RestExportHandler.h"
|
||||
#include "RestHandler/RestHandlerCreator.h"
|
||||
#include "RestHandler/RestImportHandler.h"
|
||||
#include "RestHandler/RestJobHandler.h"
|
||||
#include "RestHandler/RestPleaseUpgradeHandler.h"
|
||||
#include "RestHandler/RestQueryCacheHandler.h"
|
||||
#include "RestHandler/RestQueryHandler.h"
|
||||
#include "RestHandler/RestReplicationHandler.h"
|
||||
#include "RestHandler/RestShutdownHandler.h"
|
||||
#include "RestHandler/RestSimpleHandler.h"
|
||||
#include "RestHandler/RestSimpleQueryHandler.h"
|
||||
#include "RestHandler/RestUploadHandler.h"
|
||||
#include "RestHandler/RestVersionHandler.h"
|
||||
#include "RestHandler/WorkMonitorHandler.h"
|
||||
#include "RestServer/DatabaseFeature.h"
|
||||
#include "Scheduler/SchedulerFeature.h"
|
||||
#include "Statistics/StatisticsFeature.h"
|
||||
#include "V8/v8-conv.h"
|
||||
#include "V8/v8-globals.h"
|
||||
#include "V8/v8-utils.h"
|
||||
#include "V8Server/V8Context.h"
|
||||
#include "V8Server/V8DealerFeature.h"
|
||||
|
||||
using namespace arangodb;
|
||||
|
@ -66,15 +45,11 @@ using namespace arangodb::application_features;
|
|||
using namespace arangodb::options;
|
||||
using namespace arangodb::rest;
|
||||
|
||||
ServerFeature::ServerFeature(application_features::ApplicationServer* server,
|
||||
std::string const& authenticationRealm, int* res)
|
||||
ServerFeature::ServerFeature(application_features::ApplicationServer* server, int* res)
|
||||
: ApplicationFeature(server, "Server"),
|
||||
_defaultApiCompatibility(Version::getNumericServerVersion()),
|
||||
_allowMethodOverride(false),
|
||||
_console(false),
|
||||
_restServer(true),
|
||||
_authentication(false),
|
||||
_authenticationRealm(authenticationRealm),
|
||||
_result(res),
|
||||
_operationMode(OperationMode::MODE_SERVER) {
|
||||
setOptional(true);
|
||||
|
@ -83,8 +58,9 @@ ServerFeature::ServerFeature(application_features::ApplicationServer* server,
|
|||
startsAfter("Database");
|
||||
startsAfter("Dispatcher");
|
||||
startsAfter("Scheduler");
|
||||
startsAfter("WorkMonitor");
|
||||
startsAfter("Statistics");
|
||||
startsAfter("V8Dealer");
|
||||
startsAfter("WorkMonitor");
|
||||
}
|
||||
|
||||
void ServerFeature::collectOptions(std::shared_ptr<ProgramOptions> options) {
|
||||
|
@ -95,10 +71,6 @@ void ServerFeature::collectOptions(std::shared_ptr<ProgramOptions> options) {
|
|||
|
||||
options->addSection("server", "Server features");
|
||||
|
||||
options->addHiddenOption("--server.default-api-compatibility",
|
||||
"default API compatibility version",
|
||||
new Int32Parameter(&_defaultApiCompatibility));
|
||||
|
||||
options->addHiddenOption("--server.rest-server", "start a rest-server",
|
||||
new BooleanParameter(&_restServer));
|
||||
|
||||
|
@ -134,12 +106,6 @@ void ServerFeature::collectOptions(std::shared_ptr<ProgramOptions> options) {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
options->addSection("http", "HttpServer features");
|
||||
|
||||
options->addHiddenOption("--http.allow-method-override",
|
||||
"allow HTTP method override using special headers",
|
||||
new BooleanParameter(&_allowMethodOverride));
|
||||
|
||||
options->addSection("javascript", "Configure the Javascript engine");
|
||||
|
||||
options->addHiddenOption("--javascript.unit-tests", "run unit-tests and exit",
|
||||
|
@ -155,16 +121,6 @@ void ServerFeature::collectOptions(std::shared_ptr<ProgramOptions> options) {
|
|||
void ServerFeature::validateOptions(std::shared_ptr<ProgramOptions>) {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::validateOptions";
|
||||
|
||||
if (_defaultApiCompatibility < HttpRequest::MIN_COMPATIBILITY) {
|
||||
LOG(FATAL) << "invalid value for --server.default-api-compatibility. "
|
||||
"minimum allowed value is "
|
||||
<< HttpRequest::MIN_COMPATIBILITY;
|
||||
FATAL_ERROR_EXIT();
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "using default API compatibility: "
|
||||
<< (long int)_defaultApiCompatibility;
|
||||
|
||||
int count = 0;
|
||||
|
||||
if (_console) {
|
||||
|
@ -195,14 +151,17 @@ void ServerFeature::validateOptions(std::shared_ptr<ProgramOptions>) {
|
|||
}
|
||||
|
||||
if (!_restServer) {
|
||||
ApplicationServer::disableFeatures(
|
||||
{"Daemon", "Dispatcher", "Endpoint", "Scheduler", "Ssl", "Supervisor"});
|
||||
ApplicationServer::disableFeatures({"Daemon", "Dispatcher", "Endpoint",
|
||||
"RestServer", "Scheduler", "Ssl",
|
||||
"Supervisor"});
|
||||
|
||||
DatabaseFeature* database = dynamic_cast<DatabaseFeature*>(
|
||||
ApplicationServer::lookupFeature("Database"));
|
||||
database->disableReplicationApplier();
|
||||
|
||||
TRI_ENABLE_STATISTICS = false;
|
||||
StatisticsFeature* statistics = dynamic_cast<StatisticsFeature*>(
|
||||
ApplicationServer::lookupFeature("Statistics"));
|
||||
statistics->disableStatistics();
|
||||
}
|
||||
|
||||
V8DealerFeature* v8dealer = dynamic_cast<V8DealerFeature*>(
|
||||
|
@ -230,10 +189,6 @@ void ServerFeature::validateOptions(std::shared_ptr<ProgramOptions>) {
|
|||
void ServerFeature::start() {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::start";
|
||||
|
||||
auto vocbase = DatabaseFeature::DATABASE->vocbase();
|
||||
V8DealerFeature::DEALER->loadJavascript(vocbase, "server/server.js");
|
||||
_httpOptions._vocbase = vocbase;
|
||||
|
||||
if (_operationMode != OperationMode::MODE_CONSOLE) {
|
||||
auto scheduler = dynamic_cast<SchedulerFeature*>(
|
||||
ApplicationServer::lookupFeature("Scheduler"));
|
||||
|
@ -271,13 +226,6 @@ void ServerFeature::beginShutdown() {
|
|||
|
||||
void ServerFeature::stop() {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::stop";
|
||||
|
||||
_httpOptions._vocbase = nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::string> ServerFeature::httpEndpoints() {
|
||||
#warning TODO
|
||||
return {};
|
||||
}
|
||||
|
||||
void ServerFeature::waitForHeartbeat() {
|
||||
|
@ -436,4 +384,3 @@ int ServerFeature::runScript() {
|
|||
|
||||
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,7 @@
|
|||
#define REST_SERVER_SERVER_FEATURE_H 1
|
||||
|
||||
#include "ApplicationFeatures/ApplicationFeature.h"
|
||||
#include "ApplicationFeatures/HttpEndpointProvider.h"
|
||||
|
||||
#include "Actions/RestActionHandler.h"
|
||||
#include "Rest/OperationMode.h"
|
||||
|
||||
namespace arangodb {
|
||||
|
@ -35,11 +33,9 @@ class HttpHandlerFactory;
|
|||
class AsyncJobManager;
|
||||
}
|
||||
|
||||
class ServerFeature final : public application_features::ApplicationFeature,
|
||||
public HttpEndpointProvider {
|
||||
class ServerFeature final : public application_features::ApplicationFeature {
|
||||
public:
|
||||
ServerFeature(application_features::ApplicationServer* server,
|
||||
std::string const&, int*);
|
||||
ServerFeature(application_features::ApplicationServer* server, int*);
|
||||
|
||||
public:
|
||||
void collectOptions(std::shared_ptr<options::ProgramOptions>) override final;
|
||||
|
@ -50,11 +46,8 @@ class ServerFeature final : public application_features::ApplicationFeature,
|
|||
|
||||
public:
|
||||
OperationMode operationMode() const { return _operationMode; }
|
||||
std::vector<std::string> httpEndpoints() override;
|
||||
|
||||
private:
|
||||
int32_t _defaultApiCompatibility;
|
||||
bool _allowMethodOverride;
|
||||
bool _console;
|
||||
bool _restServer;
|
||||
bool _authentication;
|
||||
|
@ -68,10 +61,8 @@ class ServerFeature final : public application_features::ApplicationFeature,
|
|||
int runScript();
|
||||
|
||||
private:
|
||||
std::string const _authenticationRealm;
|
||||
int* _result;
|
||||
OperationMode _operationMode;
|
||||
RestActionHandler::action_options_t _httpOptions;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
bool disableStatistics = false;
|
||||
|
||||
additional["Server Options:help-admin"]("server.disable-statistics",
|
||||
&disableStatistics,
|
||||
"turn off statistics gathering");
|
||||
|
||||
if (disableStatistics) {
|
||||
TRI_ENABLE_STATISTICS = false;
|
||||
}
|
||||
|
||||
TRI_InitializeStatistics();
|
||||
|
||||
TRI_ShutdownStatistics();
|
|
@ -52,6 +52,7 @@
|
|||
#include "RestServer/ServerFeature.h"
|
||||
#include "RestServer/UpgradeFeature.h"
|
||||
#include "Scheduler/SchedulerFeature.h"
|
||||
#include "Statistics/StatisticsFeature.h"
|
||||
#include "V8Server/V8DealerFeature.h"
|
||||
|
||||
using namespace arangodb;
|
||||
|
@ -120,11 +121,12 @@ int main(int argc, char* argv[]) {
|
|||
server.addFeature(new LoggerFeature(&server, true));
|
||||
server.addFeature(new NonceFeature(&server));
|
||||
server.addFeature(new RandomFeature(&server));
|
||||
server.addFeature(new RestServerFeature(&server));
|
||||
server.addFeature(new RestServerFeature(&server, "arangodb"));
|
||||
server.addFeature(new SchedulerFeature(&server));
|
||||
server.addFeature(new ServerFeature(&server, "arangod", &ret));
|
||||
server.addFeature(new ServerFeature(&server, &ret));
|
||||
server.addFeature(new ShutdownFeature(&server, "Server"));
|
||||
server.addFeature(new SslFeature(&server));
|
||||
server.addFeature(new StatisticsFeature(&server));
|
||||
server.addFeature(new TempFeature(&server, name));
|
||||
server.addFeature(new UpgradeFeature(&server, &ret, nonServerFeatures));
|
||||
server.addFeature(new V8DealerFeature(&server));
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "Basics/Common.h"
|
||||
|
||||
#include "Statistics/StatisticsFeature.h"
|
||||
#include "Statistics/statistics.h"
|
||||
|
||||
namespace arangodb {
|
||||
|
@ -173,7 +174,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetRequestType(GeneralRequest::RequestType b) {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_requestType = b;
|
||||
}
|
||||
|
@ -185,7 +186,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetAsync() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_async = true;
|
||||
}
|
||||
|
@ -197,7 +198,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetReadStart() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr && _statistics->_readStart == 0.0) {
|
||||
_lastReadStart = _statistics->_readStart = TRI_StatisticsTime();
|
||||
}
|
||||
|
@ -209,7 +210,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetReadEnd() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_readEnd = TRI_StatisticsTime();
|
||||
}
|
||||
|
@ -221,7 +222,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetWriteStart() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_writeStart = TRI_StatisticsTime();
|
||||
}
|
||||
|
@ -233,7 +234,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetWriteEnd() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_writeEnd = TRI_StatisticsTime();
|
||||
}
|
||||
|
@ -245,7 +246,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetQueueStart() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_queueStart = TRI_StatisticsTime();
|
||||
}
|
||||
|
@ -257,7 +258,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetQueueEnd() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_queueEnd = TRI_StatisticsTime();
|
||||
}
|
||||
|
@ -269,7 +270,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetRequestStart() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_requestStart = TRI_StatisticsTime();
|
||||
}
|
||||
|
@ -281,7 +282,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetRequestEnd() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_requestEnd = TRI_StatisticsTime();
|
||||
}
|
||||
|
@ -293,7 +294,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetExecuteError() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_executeError = true;
|
||||
}
|
||||
|
@ -305,7 +306,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentSetIgnore() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_ignore = true;
|
||||
}
|
||||
|
@ -317,7 +318,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentAddReceivedBytes(size_t b) {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_receivedBytes += b;
|
||||
}
|
||||
|
@ -329,7 +330,7 @@ class RequestStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void requestStatisticsAgentAddSentBytes(size_t b) {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_sentBytes += b;
|
||||
}
|
||||
|
@ -369,7 +370,7 @@ class ConnectionStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void connectionStatisticsAgentSetHttp() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_http = true;
|
||||
}
|
||||
|
@ -381,7 +382,7 @@ class ConnectionStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void connectionStatisticsAgentSetStart() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_connStart = TRI_StatisticsTime();
|
||||
}
|
||||
|
@ -393,7 +394,7 @@ class ConnectionStatisticsAgent
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void connectionStatisticsAgentSetEnd() {
|
||||
if (TRI_ENABLE_STATISTICS) {
|
||||
if (StatisticsFeature::enabled()) {
|
||||
if (_statistics != nullptr) {
|
||||
_statistics->_connEnd = TRI_StatisticsTime();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2016 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 Dr. Frank Celler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "StatisticsFeature.h"
|
||||
|
||||
#include "ProgramOptions/ProgramOptions.h"
|
||||
#include "ProgramOptions/Section.h"
|
||||
#include "Statistics/statistics.h"
|
||||
|
||||
using namespace arangodb;
|
||||
using namespace arangodb::application_features;
|
||||
using namespace arangodb::options;
|
||||
|
||||
StatisticsFeature* StatisticsFeature::STATISTICS = nullptr;
|
||||
|
||||
StatisticsFeature::StatisticsFeature(application_features::ApplicationServer* server)
|
||||
: ApplicationFeature(server, "Statistics"),
|
||||
_statistics(true) {
|
||||
startsAfter("Logger");
|
||||
}
|
||||
|
||||
void StatisticsFeature::collectOptions(std::shared_ptr<ProgramOptions> options) {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::collectOptions";
|
||||
|
||||
options->addSection("server", "Server features");
|
||||
|
||||
options->addHiddenOption(
|
||||
"--server.statistics",
|
||||
"turn statistics gathering on or off",
|
||||
new BooleanParameter(&_statistics));
|
||||
}
|
||||
|
||||
void StatisticsFeature::start() {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::start";
|
||||
|
||||
STATISTICS = this;
|
||||
TRI_InitializeStatistics();
|
||||
}
|
||||
|
||||
void StatisticsFeature::stop() {
|
||||
LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::stop";
|
||||
|
||||
TRI_ShutdownStatistics();
|
||||
STATISTICS = nullptr;
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2016 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 Dr. Frank Celler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef APPLICATION_FEATURES_STATISTICS_FEATURE_H
|
||||
#define APPLICATION_FEATURES_STATISTICS_FEATURE_H 1
|
||||
|
||||
#include "ApplicationFeatures/ApplicationFeature.h"
|
||||
|
||||
namespace arangodb {
|
||||
class StatisticsFeature final
|
||||
: public application_features::ApplicationFeature {
|
||||
public:
|
||||
static bool enabled() {
|
||||
return STATISTICS != nullptr && STATISTICS->_statistics;
|
||||
}
|
||||
|
||||
private:
|
||||
static StatisticsFeature* STATISTICS;
|
||||
|
||||
public:
|
||||
explicit StatisticsFeature(application_features::ApplicationServer* server);
|
||||
|
||||
public:
|
||||
void collectOptions(std::shared_ptr<options::ProgramOptions>) override final;
|
||||
void start() override final;
|
||||
void stop() override final;
|
||||
|
||||
public:
|
||||
void disableStatistics() { _statistics = false; }
|
||||
|
||||
private:
|
||||
bool _statistics;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -22,13 +22,16 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "statistics.h"
|
||||
|
||||
#include <boost/lockfree/queue.hpp>
|
||||
|
||||
#include "Logger/Logger.h"
|
||||
#include "Basics/Mutex.h"
|
||||
#include "Basics/MutexLocker.h"
|
||||
#include "Basics/threads.h"
|
||||
#include "Statistics/StatisticsFeature.h"
|
||||
|
||||
#include <boost/lockfree/queue.hpp>
|
||||
|
||||
using namespace arangodb;
|
||||
using namespace arangodb::basics;
|
||||
|
||||
static size_t const QUEUE_SIZE = 1000;
|
||||
|
@ -135,7 +138,7 @@ static size_t ProcessAllRequestStatistics() {
|
|||
TRI_request_statistics_t* TRI_AcquireRequestStatistics() {
|
||||
TRI_request_statistics_t* statistics = nullptr;
|
||||
|
||||
if (TRI_ENABLE_STATISTICS && RequestFreeList.pop(statistics)) {
|
||||
if (StatisticsFeature::enabled() && RequestFreeList.pop(statistics)) {
|
||||
return statistics;
|
||||
}
|
||||
|
||||
|
@ -213,7 +216,7 @@ static boost::lockfree::queue<TRI_connection_statistics_t*,
|
|||
TRI_connection_statistics_t* TRI_AcquireConnectionStatistics() {
|
||||
TRI_connection_statistics_t* statistics = nullptr;
|
||||
|
||||
if (TRI_ENABLE_STATISTICS && ConnectionFreeList.pop(statistics)) {
|
||||
if (StatisticsFeature::enabled() && ConnectionFreeList.pop(statistics)) {
|
||||
return statistics;
|
||||
}
|
||||
|
||||
|
@ -309,7 +312,7 @@ static void StatisticsQueueWorker(void* data) {
|
|||
uint64_t const MaxSleepTime = 250 * 1000;
|
||||
int nothingHappened = 0;
|
||||
|
||||
while (!Shutdown.load(std::memory_order_relaxed) && TRI_ENABLE_STATISTICS) {
|
||||
while (!Shutdown.load(std::memory_order_relaxed) && StatisticsFeature::enabled()) {
|
||||
size_t count = ProcessAllRequestStatistics();
|
||||
|
||||
if (count == 0) {
|
||||
|
@ -367,12 +370,6 @@ static void StatisticsQueueWorker(void* data) {
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief statistics enabled flags
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TRI_ENABLE_STATISTICS = true;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief number of http connections
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -174,12 +174,6 @@ void TRI_FillConnectionStatistics(
|
|||
|
||||
TRI_server_statistics_t TRI_GetServerStatistics();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief statistics enabled flags
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern bool TRI_ENABLE_STATISTICS;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief number of http connections
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "Rest/Version.h"
|
||||
#include "RestServer/ConsoleThread.h"
|
||||
#include "RestServer/VocbaseContext.h"
|
||||
#include "Statistics/StatisticsFeature.h"
|
||||
#include "Utils/V8ResolverGuard.h"
|
||||
#include "Utils/transactions.h"
|
||||
#include "V8/JSLoader.h"
|
||||
|
@ -72,8 +73,6 @@ using namespace arangodb::basics;
|
|||
using namespace arangodb::rest;
|
||||
using namespace arangodb::traverser;
|
||||
|
||||
extern bool TRI_ENABLE_STATISTICS;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief wrapped class for TRI_vocbase_t
|
||||
///
|
||||
|
@ -3872,7 +3871,7 @@ void TRI_InitV8VocBridge(v8::Isolate* isolate, v8::Handle<v8::Context> context,
|
|||
|
||||
// whether or not statistics are enabled
|
||||
context->Global()->ForceSet(TRI_V8_ASCII_STRING("ENABLE_STATISTICS"),
|
||||
v8::Boolean::New(isolate, TRI_ENABLE_STATISTICS),
|
||||
v8::Boolean::New(isolate, StatisticsFeature::enabled()),
|
||||
v8::ReadOnly);
|
||||
|
||||
// a thread-global variable that will is supposed to contain the AQL module
|
||||
|
|
|
@ -142,8 +142,8 @@ add_library(${LIB_ARANGO} STATIC
|
|||
ApplicationFeatures/ConsoleFeature.cpp
|
||||
ApplicationFeatures/LanguageFeature.cpp
|
||||
ApplicationFeatures/LoggerFeature.cpp
|
||||
ApplicationFeatures/RandomFeature.cpp
|
||||
ApplicationFeatures/NonceFeature.cpp
|
||||
ApplicationFeatures/RandomFeature.cpp
|
||||
ApplicationFeatures/ShutdownFeature.cpp
|
||||
ApplicationFeatures/SslFeature.cpp
|
||||
ApplicationFeatures/TempFeature.cpp
|
||||
|
|
|
@ -551,7 +551,7 @@ static void JS_Download(v8::FunctionCallbackInfo<v8::Value> const& args) {
|
|||
|
||||
// check if we are a server
|
||||
HttpEndpointProvider* server = dynamic_cast<HttpEndpointProvider*>(
|
||||
ApplicationServer::lookupFeature("Server"));
|
||||
ApplicationServer::lookupFeature("Endpoint"));
|
||||
|
||||
if (server != nullptr) {
|
||||
endpoints = server->httpEndpoints();
|
||||
|
|
Loading…
Reference in New Issue