1
0
Fork 0

First stab at get info about cluster databases.

This commit is contained in:
Max Neunhoeffer 2014-01-08 16:09:43 +01:00
parent ec8ee2f526
commit d9ca01c31d
3 changed files with 42 additions and 0 deletions

View File

@ -311,6 +311,20 @@ bool ClusterInfo::doesDatabaseExist (DatabaseID const& databaseID) {
return false; return false;
} }
////////////////////////////////////////////////////////////////////////////////
/// @brief get list of databases in the cluster
////////////////////////////////////////////////////////////////////////////////
vector<DatabaseID> ClusterInfo::getDatabases () {
vector<DatabaseID> 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 /// @brief (re-)load the information about collections from the agency
/// Usually one does not have to call this directly. /// Usually one does not have to call this directly.

View File

@ -266,6 +266,12 @@ namespace triagens {
bool doesDatabaseExist (DatabaseID const& databaseID); bool doesDatabaseExist (DatabaseID const& databaseID);
////////////////////////////////////////////////////////////////////////////////
/// @brief get list of databases in the cluster
////////////////////////////////////////////////////////////////////////////////
vector<DatabaseID> getDatabases ();
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief (re-)load the information about collections from the agency /// @brief (re-)load the information about collections from the agency
/// Usually one does not have to call this directly. /// Usually one does not have to call this directly.

View File

@ -670,6 +670,27 @@ static v8::Handle<v8::Value> JS_DoesDatabaseExistClusterInfo (v8::Arguments cons
return scope.Close(v8::Boolean::New(result)); return scope.Close(v8::Boolean::New(result));
} }
////////////////////////////////////////////////////////////////////////////////
/// @brief get the list of databases in the cluster
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_GetDatabases (v8::Arguments const& argv) {
v8::HandleScope scope;
if (argv.Length() != 0) {
TRI_V8_EXCEPTION_USAGE(scope, "doesDatabaseExist()");
}
vector<DatabaseID> res = ClusterInfo::instance()->getDatabases();
v8::Handle<v8::Array> a = v8::Array::New(res.size());
vector<DatabaseID>::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) /// @brief flush the caches (used for testing only)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1494,6 +1515,7 @@ void TRI_InitV8Cluster (v8::Handle<v8::Context> context) {
rt->SetInternalFieldCount(2); rt->SetInternalFieldCount(2);
TRI_AddMethodVocbase(rt, "doesDatabaseExist", JS_DoesDatabaseExistClusterInfo); TRI_AddMethodVocbase(rt, "doesDatabaseExist", JS_DoesDatabaseExistClusterInfo);
TRI_AddMethodVocbase(rt, "getDatabases", JS_GetDatabases);
TRI_AddMethodVocbase(rt, "flush", JS_FlushClusterInfo, true); TRI_AddMethodVocbase(rt, "flush", JS_FlushClusterInfo, true);
TRI_AddMethodVocbase(rt, "getCollectionInfo", JS_GetCollectionInfoClusterInfo); TRI_AddMethodVocbase(rt, "getCollectionInfo", JS_GetCollectionInfoClusterInfo);
TRI_AddMethodVocbase(rt, "getResponsibleServer", JS_GetResponsibleServerClusterInfo); TRI_AddMethodVocbase(rt, "getResponsibleServer", JS_GetResponsibleServerClusterInfo);