@Test public void getRdsConfigForAzure() { DatabaseServerV4Response resp = new DatabaseServerV4Response(); resp.setPort(1234); resp.setHost(DB_HOST_AZURE); resp.setDatabaseVendor("postgres"); when(redbeamsClientService.getByCrn(DB_SERVER_CRN)).thenReturn(resp); when(dbCommon.getJdbcConnectionUrl(any(), any(), anyInt(), any())).thenReturn(EXAMPLE_JDBC_URL_AZURE); when(dbUsernameConverterService.toConnectionUsername(anyString(), anyString())).thenReturn("cmuser@" + DB_HOST_SHORT_NAME); Stack testStack = TestUtil.stack(); InstanceMetaData metaData = testStack.getGatewayInstanceMetadata().iterator().next(); metaData.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY); testStack.getGatewayInstanceMetadata().add(metaData); Cluster testCluster = TestUtil.cluster(); testCluster.setDatabaseServerCrn(DB_SERVER_CRN); testStack.setCluster(testCluster); RDSConfig config = underTest.createNewRdsConfig(testStack, testCluster, "clouderamanager", DB_USER, DatabaseType.CLOUDERA_MANAGER); assertEquals("CLOUDERA_MANAGER_simplestack1", config.getName()); assertEquals(EXAMPLE_JDBC_URL_AZURE, config.getConnectionURL()); assertEquals("cmuser@" + DB_HOST_SHORT_NAME, config.getConnectionUserName()); }
public RDSConfig createNewRdsConfig(Stack stack, Cluster cluster, String dbName, String dbUser, DatabaseType type) { DatabaseServerV4Response resp = getDatabaseServer(cluster.getDatabaseServerCrn()); LOGGER.info("Using redbeams for remote database configuration: {}", resp.toString()); if (Objects.nonNull(resp.getStatus()) && !resp.getStatus().isAvailable()) { String message = String.format("Redbeams database server is not available (%s) with message: %s", resp.getStatus(), resp.getStatusReason()); LOGGER.warn(message); throw new CloudbreakServiceException(message); } RDSConfig rdsConfig = new RDSConfig(); rdsConfig.setConnectionURL(dbCommon.getJdbcConnectionUrl(resp.getDatabaseVendor(), resp.getHost(), resp.getPort(), Optional.of(dbName))); rdsConfig.setConnectionUserName(dbUsernameConverterService.toConnectionUsername(resp.getHost(), dbUser)); rdsConfig.setConnectionPassword(PasswordUtil.generatePassword()); rdsConfig.setConnectionDriver(resp.getConnectionDriver()); rdsConfig.setDatabaseEngine(DatabaseVendor.fromValue(resp.getDatabaseVendor())); rdsConfig.setStatus(ResourceStatus.DEFAULT); rdsConfig.setName(type.name() + '_' + stack.getName() + stack.getId()); rdsConfig.setType(type.name()); rdsConfig.setStatus(ResourceStatus.DEFAULT); rdsConfig.setCreationDate(new Date().getTime()); rdsConfig.setClusters(Collections.singleton(cluster)); LOGGER.info("Created RDS config {} for database type {} with connection URL {}, connection username {}", rdsConfig.getName(), type, rdsConfig.getConnectionURL(), rdsConfig.getConnectionUserName()); return rdsConfig; }
RedbeamsDbServerConfigurer { public RDSConfig createNewRdsConfig(Stack stack, Cluster cluster, String dbName, String dbUser, DatabaseType type) { DatabaseServerV4Response resp = getDatabaseServer(cluster.getDatabaseServerCrn()); LOGGER.info("Using redbeams for remote database configuration: {}", resp.toString()); if (Objects.nonNull(resp.getStatus()) && !resp.getStatus().isAvailable()) { String message = String.format("Redbeams database server is not available (%s) with message: %s", resp.getStatus(), resp.getStatusReason()); LOGGER.warn(message); throw new CloudbreakServiceException(message); } RDSConfig rdsConfig = new RDSConfig(); rdsConfig.setConnectionURL(dbCommon.getJdbcConnectionUrl(resp.getDatabaseVendor(), resp.getHost(), resp.getPort(), Optional.of(dbName))); rdsConfig.setConnectionUserName(dbUsernameConverterService.toConnectionUsername(resp.getHost(), dbUser)); rdsConfig.setConnectionPassword(PasswordUtil.generatePassword()); rdsConfig.setConnectionDriver(resp.getConnectionDriver()); rdsConfig.setDatabaseEngine(DatabaseVendor.fromValue(resp.getDatabaseVendor())); rdsConfig.setStatus(ResourceStatus.DEFAULT); rdsConfig.setName(type.name() + '_' + stack.getName() + stack.getId()); rdsConfig.setType(type.name()); rdsConfig.setStatus(ResourceStatus.DEFAULT); rdsConfig.setCreationDate(new Date().getTime()); rdsConfig.setClusters(Collections.singleton(cluster)); LOGGER.info("Created RDS config {} for database type {} with connection URL {}, connection username {}", rdsConfig.getName(), type, rdsConfig.getConnectionURL(), rdsConfig.getConnectionUserName()); return rdsConfig; } }
RedbeamsDbServerConfigurer { public RDSConfig createNewRdsConfig(Stack stack, Cluster cluster, String dbName, String dbUser, DatabaseType type) { DatabaseServerV4Response resp = getDatabaseServer(cluster.getDatabaseServerCrn()); LOGGER.info("Using redbeams for remote database configuration: {}", resp.toString()); if (Objects.nonNull(resp.getStatus()) && !resp.getStatus().isAvailable()) { String message = String.format("Redbeams database server is not available (%s) with message: %s", resp.getStatus(), resp.getStatusReason()); LOGGER.warn(message); throw new CloudbreakServiceException(message); } RDSConfig rdsConfig = new RDSConfig(); rdsConfig.setConnectionURL(dbCommon.getJdbcConnectionUrl(resp.getDatabaseVendor(), resp.getHost(), resp.getPort(), Optional.of(dbName))); rdsConfig.setConnectionUserName(dbUsernameConverterService.toConnectionUsername(resp.getHost(), dbUser)); rdsConfig.setConnectionPassword(PasswordUtil.generatePassword()); rdsConfig.setConnectionDriver(resp.getConnectionDriver()); rdsConfig.setDatabaseEngine(DatabaseVendor.fromValue(resp.getDatabaseVendor())); rdsConfig.setStatus(ResourceStatus.DEFAULT); rdsConfig.setName(type.name() + '_' + stack.getName() + stack.getId()); rdsConfig.setType(type.name()); rdsConfig.setStatus(ResourceStatus.DEFAULT); rdsConfig.setCreationDate(new Date().getTime()); rdsConfig.setClusters(Collections.singleton(cluster)); LOGGER.info("Created RDS config {} for database type {} with connection URL {}, connection username {}", rdsConfig.getName(), type, rdsConfig.getConnectionURL(), rdsConfig.getConnectionUserName()); return rdsConfig; }  }
RedbeamsDbServerConfigurer { public RDSConfig createNewRdsConfig(Stack stack, Cluster cluster, String dbName, String dbUser, DatabaseType type) { DatabaseServerV4Response resp = getDatabaseServer(cluster.getDatabaseServerCrn()); LOGGER.info("Using redbeams for remote database configuration: {}", resp.toString()); if (Objects.nonNull(resp.getStatus()) && !resp.getStatus().isAvailable()) { String message = String.format("Redbeams database server is not available (%s) with message: %s", resp.getStatus(), resp.getStatusReason()); LOGGER.warn(message); throw new CloudbreakServiceException(message); } RDSConfig rdsConfig = new RDSConfig(); rdsConfig.setConnectionURL(dbCommon.getJdbcConnectionUrl(resp.getDatabaseVendor(), resp.getHost(), resp.getPort(), Optional.of(dbName))); rdsConfig.setConnectionUserName(dbUsernameConverterService.toConnectionUsername(resp.getHost(), dbUser)); rdsConfig.setConnectionPassword(PasswordUtil.generatePassword()); rdsConfig.setConnectionDriver(resp.getConnectionDriver()); rdsConfig.setDatabaseEngine(DatabaseVendor.fromValue(resp.getDatabaseVendor())); rdsConfig.setStatus(ResourceStatus.DEFAULT); rdsConfig.setName(type.name() + '_' + stack.getName() + stack.getId()); rdsConfig.setType(type.name()); rdsConfig.setStatus(ResourceStatus.DEFAULT); rdsConfig.setCreationDate(new Date().getTime()); rdsConfig.setClusters(Collections.singleton(cluster)); LOGGER.info("Created RDS config {} for database type {} with connection URL {}, connection username {}", rdsConfig.getName(), type, rdsConfig.getConnectionURL(), rdsConfig.getConnectionUserName()); return rdsConfig; }  RDSConfig createNewRdsConfig(Stack stack, Cluster cluster, String dbName, String dbUser, DatabaseType type); boolean isRemoteDatabaseNeeded(Cluster cluster); DatabaseServerV4Response getDatabaseServer(String serverCrn); }
RedbeamsDbServerConfigurer { public RDSConfig createNewRdsConfig(Stack stack, Cluster cluster, String dbName, String dbUser, DatabaseType type) { DatabaseServerV4Response resp = getDatabaseServer(cluster.getDatabaseServerCrn()); LOGGER.info("Using redbeams for remote database configuration: {}", resp.toString()); if (Objects.nonNull(resp.getStatus()) && !resp.getStatus().isAvailable()) { String message = String.format("Redbeams database server is not available (%s) with message: %s", resp.getStatus(), resp.getStatusReason()); LOGGER.warn(message); throw new CloudbreakServiceException(message); } RDSConfig rdsConfig = new RDSConfig(); rdsConfig.setConnectionURL(dbCommon.getJdbcConnectionUrl(resp.getDatabaseVendor(), resp.getHost(), resp.getPort(), Optional.of(dbName))); rdsConfig.setConnectionUserName(dbUsernameConverterService.toConnectionUsername(resp.getHost(), dbUser)); rdsConfig.setConnectionPassword(PasswordUtil.generatePassword()); rdsConfig.setConnectionDriver(resp.getConnectionDriver()); rdsConfig.setDatabaseEngine(DatabaseVendor.fromValue(resp.getDatabaseVendor())); rdsConfig.setStatus(ResourceStatus.DEFAULT); rdsConfig.setName(type.name() + '_' + stack.getName() + stack.getId()); rdsConfig.setType(type.name()); rdsConfig.setStatus(ResourceStatus.DEFAULT); rdsConfig.setCreationDate(new Date().getTime()); rdsConfig.setClusters(Collections.singleton(cluster)); LOGGER.info("Created RDS config {} for database type {} with connection URL {}, connection username {}", rdsConfig.getName(), type, rdsConfig.getConnectionURL(), rdsConfig.getConnectionUserName()); return rdsConfig; }  RDSConfig createNewRdsConfig(Stack stack, Cluster cluster, String dbName, String dbUser, DatabaseType type); boolean isRemoteDatabaseNeeded(Cluster cluster); DatabaseServerV4Response getDatabaseServer(String serverCrn);  }