mirror of https://gitee.com/bigwinds/arangodb
added maintenance mode
This commit is contained in:
parent
c88291d955
commit
e1b9e343bb
|
@ -845,6 +845,9 @@ int ArangoServer::startupServer () {
|
||||||
|
|
||||||
if (startServer) {
|
if (startServer) {
|
||||||
|
|
||||||
|
// start with enabled maintenance mode
|
||||||
|
HttpHandlerFactory::setMaintenance(true);
|
||||||
|
|
||||||
// create the server
|
// create the server
|
||||||
_applicationEndpointServer->buildServers();
|
_applicationEndpointServer->buildServers();
|
||||||
|
|
||||||
|
@ -918,6 +921,10 @@ int ArangoServer::startupServer () {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int ArangoServer::runServer (TRI_vocbase_t* vocbase) {
|
int ArangoServer::runServer (TRI_vocbase_t* vocbase) {
|
||||||
|
|
||||||
|
// disabled maintenance mode
|
||||||
|
HttpHandlerFactory::setMaintenance(false);
|
||||||
|
|
||||||
// just wait until we are signalled
|
// just wait until we are signalled
|
||||||
_applicationServer->wait();
|
_applicationServer->wait();
|
||||||
|
|
||||||
|
@ -938,6 +945,10 @@ int ArangoServer::runConsole (TRI_vocbase_t* vocbase) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// disabled maintenance mode
|
||||||
|
HttpHandlerFactory::setMaintenance(false);
|
||||||
|
|
||||||
|
// just wait until we are signalled
|
||||||
_applicationServer->wait();
|
_applicationServer->wait();
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
|
@ -37,13 +37,47 @@
|
||||||
#include "BasicsC/tri-strings.h"
|
#include "BasicsC/tri-strings.h"
|
||||||
#include "HttpServer/HttpHandler.h"
|
#include "HttpServer/HttpHandler.h"
|
||||||
#include "Rest/HttpRequest.h"
|
#include "Rest/HttpRequest.h"
|
||||||
#include "Rest/MaintenanceCallback.h"
|
|
||||||
#include "Rest/SslInterface.h"
|
#include "Rest/SslInterface.h"
|
||||||
|
|
||||||
using namespace triagens::basics;
|
using namespace triagens::basics;
|
||||||
using namespace triagens::rest;
|
using namespace triagens::rest;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- private variables
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
sig_atomic_t MaintenanceMode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- MaintenanceHandler
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
class MaintenanceHandler : public HttpHandler {
|
||||||
|
public:
|
||||||
|
MaintenanceHandler (HttpRequest* request)
|
||||||
|
: HttpHandler(request) {
|
||||||
|
};
|
||||||
|
|
||||||
|
bool isDirect () {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
status_t execute () {
|
||||||
|
_response = createResponse(HttpResponse::SERVICE_UNAVAILABLE);
|
||||||
|
|
||||||
|
return status_t(HANDLER_DONE);
|
||||||
|
};
|
||||||
|
|
||||||
|
void handleError (TriagensError const& error) {
|
||||||
|
_response = createResponse(HttpResponse::SERVICE_UNAVAILABLE);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- constructors and destructors
|
// --SECTION-- constructors and destructors
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -108,6 +142,18 @@ HttpHandlerFactory& HttpHandlerFactory::operator= (HttpHandlerFactory const& tha
|
||||||
HttpHandlerFactory::~HttpHandlerFactory () {
|
HttpHandlerFactory::~HttpHandlerFactory () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- static public methods
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief sets maintenance mode
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void HttpHandlerFactory::setMaintenance (bool value) {
|
||||||
|
MaintenanceMode = value ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- public methods
|
// --SECTION-- public methods
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -168,14 +214,6 @@ string const& HttpHandlerFactory::authenticationRealm (HttpRequest*) const {
|
||||||
HttpRequest* HttpHandlerFactory::createRequest (ConnectionInfo const& info,
|
HttpRequest* HttpHandlerFactory::createRequest (ConnectionInfo const& info,
|
||||||
char const* ptr,
|
char const* ptr,
|
||||||
size_t length) {
|
size_t length) {
|
||||||
#if 0
|
|
||||||
READ_LOCKER(_maintenanceLock);
|
|
||||||
|
|
||||||
if (_maintenance) {
|
|
||||||
return ((S*) this)->createMaintenanceRequest(ptr, length);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
HttpRequest* request = new HttpRequest(info, ptr, length, _minCompatibility, _allowMethodOverride);
|
HttpRequest* request = new HttpRequest(info, ptr, length, _minCompatibility, _allowMethodOverride);
|
||||||
|
|
||||||
if (request != 0) {
|
if (request != 0) {
|
||||||
|
@ -190,13 +228,9 @@ HttpRequest* HttpHandlerFactory::createRequest (ConnectionInfo const& info,
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
HttpHandler* HttpHandlerFactory::createHandler (HttpRequest* request) {
|
HttpHandler* HttpHandlerFactory::createHandler (HttpRequest* request) {
|
||||||
#if 0
|
if (MaintenanceMode) {
|
||||||
READ_LOCKER(_maintenanceLock);
|
return new MaintenanceHandler(request);
|
||||||
|
|
||||||
if (_maintenance) {
|
|
||||||
return ((S*) this)->createMaintenanceHandler();
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
map<string, create_fptr> const& ii = _constructors;
|
map<string, create_fptr> const& ii = _constructors;
|
||||||
|
@ -306,63 +340,6 @@ HttpHandler* HttpHandlerFactory::createHandler (HttpRequest* request) {
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief removes a handler from the list of active handlers and destroys it
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
void HttpHandlerFactory::unregisterHandler (HttpHandler* handler) {
|
|
||||||
vector<MaintenanceCallback*> callbacks;
|
|
||||||
|
|
||||||
{
|
|
||||||
MUTEX_LOCKER(_activeHandlersLock);
|
|
||||||
_numberActiveHandlers--;
|
|
||||||
|
|
||||||
if (0 == _numberActiveHandlers) {
|
|
||||||
_maintenanceCallbacks.swap(callbacks);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete handler;
|
|
||||||
|
|
||||||
for (vector<MaintenanceCallback*>::iterator i = callbacks.begin(); i != callbacks.end(); ++i) {
|
|
||||||
MaintenanceCallback* callback = *i;
|
|
||||||
|
|
||||||
callback->completed();
|
|
||||||
delete callback;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief adds a maintenance handler
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void HttpHandlerFactory::addMaintenanceCallback (MaintenanceCallback* callback) {
|
|
||||||
#if 0
|
|
||||||
bool direct = false;
|
|
||||||
|
|
||||||
{
|
|
||||||
MUTEX_LOCKER(_activeHandlersLock);
|
|
||||||
|
|
||||||
if (0 < _numberActiveHandlers) {
|
|
||||||
_maintenanceCallbacks.push_back(callback);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
direct = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// during maintainance the number of active handlers is
|
|
||||||
// decreasing, so if we reached 0, we will stay there
|
|
||||||
|
|
||||||
if (direct) {
|
|
||||||
callback->completed();
|
|
||||||
delete callback;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief adds a path and constructor to the factory
|
/// @brief adds a path and constructor to the factory
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -46,7 +46,6 @@ namespace triagens {
|
||||||
class HttpHandler;
|
class HttpHandler;
|
||||||
class HttpRequest;
|
class HttpRequest;
|
||||||
class HttpResponse;
|
class HttpResponse;
|
||||||
class MaintenanceCallback;
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- class HttpHandlerFactory
|
// --SECTION-- class HttpHandlerFactory
|
||||||
|
@ -128,6 +127,18 @@ namespace triagens {
|
||||||
|
|
||||||
virtual ~HttpHandlerFactory ();
|
virtual ~HttpHandlerFactory ();
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- static public methods
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief sets maintenance mode
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
static void setMaintenance (bool);
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- public methods
|
// --SECTION-- public methods
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -172,14 +183,6 @@ namespace triagens {
|
||||||
|
|
||||||
virtual HttpHandler* createHandler (HttpRequest*);
|
virtual HttpHandler* createHandler (HttpRequest*);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief adds a maintenance handler
|
|
||||||
///
|
|
||||||
/// Note the maintenance callback is deleted, after it is fired.
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void addMaintenanceCallback (MaintenanceCallback*);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief adds a path and constructor to the factory
|
/// @brief adds a path and constructor to the factory
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -271,12 +274,6 @@ namespace triagens {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
create_fptr _notFound;
|
create_fptr _notFound;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief list of maintenance callbacks
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
vector<MaintenanceCallback*> _maintenanceCallbacks;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief maintenance mode callback
|
|
||||||
///
|
|
||||||
/// @file
|
|
||||||
///
|
|
||||||
/// DISCLAIMER
|
|
||||||
///
|
|
||||||
/// Copyright 2014 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 Copyright 2014, ArangoDB GmbH, Cologne, Germany
|
|
||||||
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef ARANGODB_REST_MAINTENANCE_CALLBACK_H
|
|
||||||
#define ARANGODB_REST_MAINTENANCE_CALLBACK_H 1
|
|
||||||
|
|
||||||
#include "Basics/Common.h"
|
|
||||||
|
|
||||||
namespace triagens {
|
|
||||||
namespace rest {
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief maintenance mode callback
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class MaintenanceCallback {
|
|
||||||
public:
|
|
||||||
virtual void completed () = 0;
|
|
||||||
virtual ~MaintenanceCallback(){}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// --SECTION-- END-OF-FILE
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Variables:
|
|
||||||
// mode: outline-minor
|
|
||||||
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
|
|
||||||
// End:
|
|
Loading…
Reference in New Issue