static boolean shouldInitialize() { // GRZE:WARNING:HACKHACKHACK do not duplicate pls thanks. for (final Host h : Hosts.listActiveDatabases()) { final String url = String.format( "jdbc:%s", ServiceUris.remote(Database.class, h.getBindAddress(), "eucalyptus_config")); try { final Connection conn = DriverManager.getConnection(url, Databases.getUserName(), Databases.getPassword()); try { final PreparedStatement statement = conn.prepareStatement( "select config_component_hostname from config_component_base where config_component_partition='eucalyptus';"); final ResultSet result = statement.executeQuery(); while (result.next()) { final Object columnValue = result.getObject(1); if (Internets.testLocal(columnValue.toString())) { return true; } } } finally { conn.close(); } } catch (final Exception ex) { LOG.error(ex, ex); } } return false; }
private static void resetDatabaseWeights(final String contextName) { for (final Host host : Hosts.listActiveDatabases()) try { lookupDatabase(contextName, host.getDisplayName()) .setweight( Hosts.isCoordinator(host) ? DATABASE_WEIGHT_PRIMARY : DATABASE_WEIGHT_SECONDARY); } catch (NoSuchElementException e) { // Weight will be set on activation } catch (Exception e) { LOG.error( "Error resetting weight for host " + host.getDisplayName() + " context " + contextName, e); } }
/** List all known databases. */ static Set<String> listDatabases() { final Set<String> dbNames = Sets.newHashSet(); final Predicate<String> dbNamePredicate = Predicates.or(Strings.startsWith("eucalyptus_"), Predicates.equalTo("database_events")); for (final Host h : Hosts.listActiveDatabases()) { Iterables.addAll( dbNames, Iterables.filter( Databases.getBootstrapper().listDatabases(h.getBindAddress()), dbNamePredicate)); } return dbNames; }