diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index 54b72e330d..aa3a9159e6 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -311,6 +311,20 @@ bool ClusterInfo::doesDatabaseExist (DatabaseID const& databaseID) { return false; } +//////////////////////////////////////////////////////////////////////////////// +/// @brief get list of databases in the cluster +//////////////////////////////////////////////////////////////////////////////// + +vector ClusterInfo::getDatabases () { + vector res; + + AllCollections::const_iterator it; + for (it = _collections.begin(); it != _collections.end(); ++it) { + res.push_back(it->first); + } + return res; +} + //////////////////////////////////////////////////////////////////////////////// /// @brief (re-)load the information about collections from the agency /// Usually one does not have to call this directly. diff --git a/arangod/Cluster/ClusterInfo.h b/arangod/Cluster/ClusterInfo.h index 6b9714a098..4753485526 100644 --- a/arangod/Cluster/ClusterInfo.h +++ b/arangod/Cluster/ClusterInfo.h @@ -266,6 +266,12 @@ namespace triagens { bool doesDatabaseExist (DatabaseID const& databaseID); +//////////////////////////////////////////////////////////////////////////////// +/// @brief get list of databases in the cluster +//////////////////////////////////////////////////////////////////////////////// + + vector getDatabases (); + //////////////////////////////////////////////////////////////////////////////// /// @brief (re-)load the information about collections from the agency /// Usually one does not have to call this directly. diff --git a/arangod/Cluster/v8-cluster.cpp b/arangod/Cluster/v8-cluster.cpp index 496383e0f0..7297cba43b 100644 --- a/arangod/Cluster/v8-cluster.cpp +++ b/arangod/Cluster/v8-cluster.cpp @@ -670,6 +670,27 @@ static v8::Handle JS_DoesDatabaseExistClusterInfo (v8::Arguments cons return scope.Close(v8::Boolean::New(result)); } +//////////////////////////////////////////////////////////////////////////////// +/// @brief get the list of databases in the cluster +//////////////////////////////////////////////////////////////////////////////// + +static v8::Handle JS_GetDatabases (v8::Arguments const& argv) { + v8::HandleScope scope; + + if (argv.Length() != 0) { + TRI_V8_EXCEPTION_USAGE(scope, "doesDatabaseExist()"); + } + + vector res = ClusterInfo::instance()->getDatabases(); + v8::Handle a = v8::Array::New(res.size()); + vector::iterator it; + int count = 0; + for (it = res.begin(); it != res.end(); it++) { + a->Set(count++, v8::String::New(it->c_str(), it->size())); + } + return scope.Close(a); +} + //////////////////////////////////////////////////////////////////////////////// /// @brief flush the caches (used for testing only) //////////////////////////////////////////////////////////////////////////////// @@ -1494,6 +1515,7 @@ void TRI_InitV8Cluster (v8::Handle context) { rt->SetInternalFieldCount(2); TRI_AddMethodVocbase(rt, "doesDatabaseExist", JS_DoesDatabaseExistClusterInfo); + TRI_AddMethodVocbase(rt, "getDatabases", JS_GetDatabases); TRI_AddMethodVocbase(rt, "flush", JS_FlushClusterInfo, true); TRI_AddMethodVocbase(rt, "getCollectionInfo", JS_GetCollectionInfoClusterInfo); TRI_AddMethodVocbase(rt, "getResponsibleServer", JS_GetResponsibleServerClusterInfo);