return result;
}
public static void persistStorageClusterSettingsIfNecessary(HashMap<String, String> serverProperties,
String password) throws Exception {
DatabaseType db = null;
Connection connection = null;
PreparedStatement updateClusterSetting = null;
try {
String dbUrl = serverProperties.get(ServerProperties.PROP_DATABASE_CONNECTION_URL);
String userName = serverProperties.get(ServerProperties.PROP_DATABASE_USERNAME);
connection = getDatabaseConnection(dbUrl, userName, password);
db = DatabaseTypeFactory.getDatabaseType(connection);
if (!(db instanceof PostgresqlDatabaseType || db instanceof OracleDatabaseType)) {
throw new IllegalArgumentException("Unknown database type, can't continue: " + db);
}
connection = getDatabaseConnection(dbUrl, userName, password);
connection.setAutoCommit(false);
updateClusterSetting = connection.prepareStatement("" //
+ "UPDATE rhq_system_config " //
+ " SET property_value = ?, default_property_value = ? " //
+ " WHERE property_key = ? " //
+ " AND ( property_value IS NULL OR property_value = '' OR property_value = 'UNSET' ) ");
updateClusterSetting.setString(1, serverProperties.get(ServerProperties.PROP_STORAGE_USERNAME));
updateClusterSetting.setString(2, serverProperties.get(ServerProperties.PROP_STORAGE_USERNAME));
updateClusterSetting.setString(3, "STORAGE_USERNAME");
updateClusterSetting.executeUpdate();
updateClusterSetting.setString(1, serverProperties.get(ServerProperties.PROP_STORAGE_PASSWORD));
updateClusterSetting.setString(2, serverProperties.get(ServerProperties.PROP_STORAGE_PASSWORD));
updateClusterSetting.setString(3, "STORAGE_PASSWORD");
updateClusterSetting.executeUpdate();
updateClusterSetting.setString(1, serverProperties.get(ServerProperties.PROP_STORAGE_CQL_PORT));
updateClusterSetting.setString(2, serverProperties.get(ServerProperties.PROP_STORAGE_CQL_PORT));
updateClusterSetting.setString(3, "STORAGE_CQL_PORT");
updateClusterSetting.executeUpdate();
updateClusterSetting.setString(1, serverProperties.get(ServerProperties.PROP_STORAGE_GOSSIP_PORT));
updateClusterSetting.setString(2, serverProperties.get(ServerProperties.PROP_STORAGE_GOSSIP_PORT));
updateClusterSetting.setString(3, "STORAGE_GOSSIP_PORT");
updateClusterSetting.executeUpdate();
connection.commit();
} catch (SQLException e) {
LOG.error("Failed to initialize storage cluster settings. Transaction will be rolled back.", e);
connection.rollback();
throw e;
} finally {
if (db != null) {
db.closeStatement(updateClusterSetting);
db.closeConnection(connection);
}
}
}