use of com.torodb.mongodb.commands.signatures.diagnostic.ListDatabasesCommand.ListDatabasesReply in project torodb by torodb.
the class ListDatabasesImplementation method apply.
@Override
public Status<ListDatabasesReply> apply(Request req, Command<? super Empty, ? super ListDatabasesReply> command, Empty arg, MongodTransaction context) {
List<String> databases = context.getTorodTransaction().getDatabases();
long totalSize = 0;
List<DatabaseEntry> databaseEntries = Lists.newArrayListWithCapacity(databases.size());
for (String databaseName : databases) {
long databaseSize = context.getTorodTransaction().getDatabaseSize(databaseName);
databaseEntries.add(new DatabaseEntry(databaseName, databaseSize, databaseSize == 0));
totalSize += databaseSize;
}
return Status.ok(new ListDatabasesReply(ImmutableList.copyOf(databaseEntries), totalSize));
}
use of com.torodb.mongodb.commands.signatures.diagnostic.ListDatabasesCommand.ListDatabasesReply in project torodb by torodb.
the class RecoveryService method cloneDatabases.
private void cloneDatabases(@Nonnull MongoClient remoteClient) throws CloningException, MongoException, UserException {
enableDataImportMode();
try {
Stream<String> dbNames;
try (MongoConnection remoteConnection = remoteClient.openConnection()) {
RemoteCommandResponse<ListDatabasesReply> remoteResponse = remoteConnection.execute(ListDatabasesCommand.INSTANCE, "admin", true, Empty.getInstance());
if (!remoteResponse.isOk()) {
throw remoteResponse.asMongoException();
}
dbNames = remoteResponse.getCommandReply().get().getDatabases().stream().map(db -> db.getName());
}
dbNames.filter(this::isReplicable).forEach(databaseName -> {
MyWritePermissionSupplier writePermissionSupplier = new MyWritePermissionSupplier(databaseName);
CloneOptions options = new CloneOptions(true, true, true, false, databaseName, Collections.<String>emptySet(), writePermissionSupplier, (colName) -> replFilters.getCollectionPredicate().test(databaseName, colName), (collection, indexName, unique, keys) -> replFilters.getIndexPredicate().test(databaseName, collection, indexName, unique, keys));
try {
cloner.cloneDatabase(databaseName, remoteClient, server, options);
} catch (MongoException ex) {
throw new CloningException(ex);
}
});
} finally {
disableDataImportMode();
}
}
Aggregations