1
0
Fork 0
arangodb/arangod/RestServer/VocbaseManager.h

316 lines
12 KiB
C++

////////////////////////////////////////////////////////////////////////////////
/// @brief vocbase manager
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-2013 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 triAGENS GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef TRIAGENS_REST_SERVER_VOCBASE_MANAGER_H
#define TRIAGENS_REST_SERVER_VOCBASE_MANAGER_H 1
#ifdef _WIN32
#include "BasicsC/win-utils.h"
#endif
#include "VocBase/vocbase.h"
#include "Rest/HttpRequest.h"
#include "Basics/ReadLocker.h"
#include "Basics/WriteLocker.h"
#include <map>
#include <string>
#include "v8.h"
namespace triagens {
namespace rest {
class ApplicationEndpointServer;
}
}
namespace triagens {
namespace arango {
class VocbaseContext;
class JSLoader;
// -----------------------------------------------------------------------------
// --SECTION-- class ArangoServer
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup ArangoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief ArangoDB VocbaseManager
////////////////////////////////////////////////////////////////////////////////
class VocbaseManager {
private:
VocbaseManager () : _vocbase(0), _startupLoader(0), _endpointServer(0) {};
VocbaseManager (const VocbaseManager&);
VocbaseManager& operator= (const VocbaseManager&);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup ArangoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief add system vocbase
////////////////////////////////////////////////////////////////////////////////
void addSystemVocbase (TRI_vocbase_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief get system vocbase
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_t* getSystemVocbase () {
return _vocbase;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief add user vocbase
////////////////////////////////////////////////////////////////////////////////
void addUserVocbase (TRI_vocbase_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief close user vocbases
////////////////////////////////////////////////////////////////////////////////
void closeUserVocbases ();
////////////////////////////////////////////////////////////////////////////////
/// @brief lookup vocbase by name
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_t* lookupVocbaseByName (std::string const&);
////////////////////////////////////////////////////////////////////////////////
/// @brief check name and path
////////////////////////////////////////////////////////////////////////////////
int canAddVocbase (std::string const&,
std::string const&,
bool);
////////////////////////////////////////////////////////////////////////////////
/// @brief check if a collection name is valid
////////////////////////////////////////////////////////////////////////////////
bool isValidName (std::string const&) const;
////////////////////////////////////////////////////////////////////////////////
/// @brief add the startup loader
////////////////////////////////////////////////////////////////////////////////
void setStartupLoader (JSLoader* startupLoader) {
_startupLoader = startupLoader;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief add the application enpoint server
////////////////////////////////////////////////////////////////////////////////
void setApplicationEndpointServer (triagens::rest::ApplicationEndpointServer* endpointServer) {
_endpointServer = endpointServer;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief run version check
/// @return bool returns false if the version check fails
////////////////////////////////////////////////////////////////////////////////
bool runVersionCheck (TRI_vocbase_t* vocbase, v8::Handle<v8::Context> context);
////////////////////////////////////////////////////////////////////////////////
/// @brief initialize foxx
////////////////////////////////////////////////////////////////////////////////
void initializeFoxx (TRI_vocbase_t* vocbase, v8::Handle<v8::Context> context);
////////////////////////////////////////////////////////////////////////////////
/// @brief add an endpoint
////////////////////////////////////////////////////////////////////////////////
bool addEndpoint (std::string const& name);
////////////////////////////////////////////////////////////////////////////////
/// @brief lookup vocbase by http request
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_t* lookupVocbaseByHttpRequest (triagens::rest::HttpRequest*);
////////////////////////////////////////////////////////////////////////////////
/// @brief lookup vocbase by http request
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_t* lookupVocbaseByPrefix (std::string const& prefix);
////////////////////////////////////////////////////////////////////////////////
/// @brief add prefix to database mapping
////////////////////////////////////////////////////////////////////////////////
void addPrefixMapping (std::string const& prefix, std::string const& name);
////////////////////////////////////////////////////////////////////////////////
/// @brief authenticate a request
////////////////////////////////////////////////////////////////////////////////
bool authenticate (TRI_vocbase_t* vocbase, triagens::rest::HttpRequest*);
////////////////////////////////////////////////////////////////////////////////
/// @brief reload auth info
////////////////////////////////////////////////////////////////////////////////
bool reloadAuthInfo (TRI_vocbase_t* vocbase);
////////////////////////////////////////////////////////////////////////////////
/// @brief get list of database names
////////////////////////////////////////////////////////////////////////////////
vector<TRI_vocbase_t*> vocbases ();
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public static methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup ArangoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
public:
static VocbaseManager manager;
static bool setRequestContext (triagens::rest::HttpRequest*);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- private methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup ArangoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
private:
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup ArangoDB
/// @{
////////////////////////////////////////////////////////////////////////////////
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief system vocbase
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_t* _vocbase;
////////////////////////////////////////////////////////////////////////////////
/// @brief user vocbase
////////////////////////////////////////////////////////////////////////////////
std::map<std::string, TRI_vocbase_t*> _vocbases;
////////////////////////////////////////////////////////////////////////////////
/// @brief prefix to vocbase mapping
////////////////////////////////////////////////////////////////////////////////
std::map<std::string, TRI_vocbase_t*> _prefix2Vocbases;
////////////////////////////////////////////////////////////////////////////////
/// @brief authentication lock for cache
////////////////////////////////////////////////////////////////////////////////
basics::ReadWriteLock _rwLock;
////////////////////////////////////////////////////////////////////////////////
/// @brief authentication cache
////////////////////////////////////////////////////////////////////////////////
std::map<TRI_vocbase_t*, std::map<std::string, std::string> > _authCache;
////////////////////////////////////////////////////////////////////////////////
/// @brief the javascript startup file loader (used for the version check)
////////////////////////////////////////////////////////////////////////////////
JSLoader* _startupLoader;
////////////////////////////////////////////////////////////////////////////////
/// @brief the application enpoint server
////////////////////////////////////////////////////////////////////////////////
triagens::rest::ApplicationEndpointServer* _endpointServer;
};
}
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
#endif
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End: