diff --git a/arangod/RestServer/ArangoServer.cpp b/arangod/RestServer/ArangoServer.cpp index 71d73722e3..6d2c33159a 100644 --- a/arangod/RestServer/ArangoServer.cpp +++ b/arangod/RestServer/ArangoServer.cpp @@ -845,6 +845,9 @@ int ArangoServer::startupServer () { if (startServer) { + // start with enabled maintenance mode + HttpHandlerFactory::setMaintenance(true); + // create the server _applicationEndpointServer->buildServers(); @@ -918,6 +921,10 @@ int ArangoServer::startupServer () { //////////////////////////////////////////////////////////////////////////////// int ArangoServer::runServer (TRI_vocbase_t* vocbase) { + + // disabled maintenance mode + HttpHandlerFactory::setMaintenance(false); + // just wait until we are signalled _applicationServer->wait(); @@ -938,6 +945,10 @@ int ArangoServer::runConsole (TRI_vocbase_t* vocbase) { } #endif + // disabled maintenance mode + HttpHandlerFactory::setMaintenance(false); + + // just wait until we are signalled _applicationServer->wait(); #ifdef __APPLE__ diff --git a/lib/HttpServer/HttpHandlerFactory.cpp b/lib/HttpServer/HttpHandlerFactory.cpp index 140e361f14..38616c8719 100644 --- a/lib/HttpServer/HttpHandlerFactory.cpp +++ b/lib/HttpServer/HttpHandlerFactory.cpp @@ -37,13 +37,47 @@ #include "BasicsC/tri-strings.h" #include "HttpServer/HttpHandler.h" #include "Rest/HttpRequest.h" -#include "Rest/MaintenanceCallback.h" #include "Rest/SslInterface.h" using namespace triagens::basics; using namespace triagens::rest; 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 // ----------------------------------------------------------------------------- @@ -108,6 +142,18 @@ HttpHandlerFactory& HttpHandlerFactory::operator= (HttpHandlerFactory const& tha HttpHandlerFactory::~HttpHandlerFactory () { } +// ----------------------------------------------------------------------------- +// --SECTION-- static public methods +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief sets maintenance mode +//////////////////////////////////////////////////////////////////////////////// + +void HttpHandlerFactory::setMaintenance (bool value) { + MaintenanceMode = value ? 1 : 0; +} + // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- @@ -168,14 +214,6 @@ string const& HttpHandlerFactory::authenticationRealm (HttpRequest*) const { HttpRequest* HttpHandlerFactory::createRequest (ConnectionInfo const& info, char const* ptr, 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); if (request != 0) { @@ -190,13 +228,9 @@ HttpRequest* HttpHandlerFactory::createRequest (ConnectionInfo const& info, //////////////////////////////////////////////////////////////////////////////// HttpHandler* HttpHandlerFactory::createHandler (HttpRequest* request) { -#if 0 - READ_LOCKER(_maintenanceLock); - - if (_maintenance) { - return ((S*) this)->createMaintenanceHandler(); + if (MaintenanceMode) { + return new MaintenanceHandler(request); } -#endif map const& ii = _constructors; @@ -306,63 +340,6 @@ HttpHandler* HttpHandlerFactory::createHandler (HttpRequest* request) { return handler; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief removes a handler from the list of active handlers and destroys it -//////////////////////////////////////////////////////////////////////////////// - -#if 0 -void HttpHandlerFactory::unregisterHandler (HttpHandler* handler) { - vector callbacks; - - { - MUTEX_LOCKER(_activeHandlersLock); - _numberActiveHandlers--; - - if (0 == _numberActiveHandlers) { - _maintenanceCallbacks.swap(callbacks); - } - } - - delete handler; - - for (vector::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 //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/HttpServer/HttpHandlerFactory.h b/lib/HttpServer/HttpHandlerFactory.h index 7471bb2bdb..11de630ac2 100644 --- a/lib/HttpServer/HttpHandlerFactory.h +++ b/lib/HttpServer/HttpHandlerFactory.h @@ -46,7 +46,6 @@ namespace triagens { class HttpHandler; class HttpRequest; class HttpResponse; - class MaintenanceCallback; // ----------------------------------------------------------------------------- // --SECTION-- class HttpHandlerFactory @@ -128,6 +127,18 @@ namespace triagens { virtual ~HttpHandlerFactory (); +// ----------------------------------------------------------------------------- +// --SECTION-- static public methods +// ----------------------------------------------------------------------------- + + public: + +//////////////////////////////////////////////////////////////////////////////// +/// @brief sets maintenance mode +//////////////////////////////////////////////////////////////////////////////// + + static void setMaintenance (bool); + // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- @@ -172,14 +183,6 @@ namespace triagens { 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 //////////////////////////////////////////////////////////////////////////////// @@ -271,12 +274,6 @@ namespace triagens { //////////////////////////////////////////////////////////////////////////////// create_fptr _notFound; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief list of maintenance callbacks -//////////////////////////////////////////////////////////////////////////////// - - vector _maintenanceCallbacks; }; } } diff --git a/lib/Rest/MaintenanceCallback.h b/lib/Rest/MaintenanceCallback.h deleted file mode 100644 index ec66d64a00..0000000000 --- a/lib/Rest/MaintenanceCallback.h +++ /dev/null @@ -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: