private static Set<String> listDatabases( final String clusterName, final boolean active, final Optional<Integer> weight) { final Set<String> databases = Sets.newLinkedHashSet(); try { final DatabaseClusterMBean cluster = lookup(clusterName, 0); final Iterable<String> databaseIds = active ? cluster.getactiveDatabases() : cluster.getinactiveDatabases(); for (final String databaseId : databaseIds) try { final DriverDatabaseMBean database = lookupDatabase(clusterName, databaseId); if (!weight.isPresent() || database.getweight() == weight.get()) { databases.add(databaseId); } } catch (NoSuchElementException e) { // ignore database } } catch (NoSuchElementException e) { // no databases } catch (Exception e) { LOG.error(e, e); } return databases; }
private static void prepareConnections(final Host host, final String contextName) throws NoSuchElementException { final String dbUrl = "jdbc:" + ServiceUris.remote(Database.class, host.getBindAddress(), contextName); final String hostName = host.getDisplayName(); final DriverDatabaseMBean database = Databases.lookupDatabase(contextName, hostName); database.setuser(getUserName()); database.setpassword(getPassword()); database.setweight( Hosts.isCoordinator(host) ? DATABASE_WEIGHT_PRIMARY : DATABASE_WEIGHT_SECONDARY); database.setlocal(host.isLocalHost()); database.setlocation(dbUrl); }