@Test public void testCreateDatabaseConfig() { config.setId(1L); config.setAccountId("myaccount"); Crn crn = TestData.getTestCrn("databaseServer", "myserver"); config.setResourceCrn(crn); config.setWorkspaceId(0L); config.setName("myserver"); config.setDescription("mine not yours"); config.setHost("myserver.db.example.com"); config.setPort(5432); config.setDatabaseVendor(DatabaseVendor.POSTGRES); config.setConnectionDriver("org.postgresql.Driver"); config.setConnectionUserName("root"); config.setConnectionPassword("cloudera"); long now = System.currentTimeMillis(); config.setCreationDate(now); config.setResourceStatus(ResourceStatus.SERVICE_MANAGED); config.setDeletionTimestamp(2L); config.setArchived(true); config.setEnvironmentId("myenvironment"); DatabaseConfig db = config.createDatabaseConfig("mydb", "hive", Optional.empty(), ResourceStatus.USER_MANAGED, "dbuser", "dbpass"); assertEquals(config.getDatabaseVendor(), db.getDatabaseVendor()); assertEquals("mydb", db.getName()); assertEquals(config.getDescription(), db.getDescription()); String connectionUrl = new DatabaseCommon().getJdbcConnectionUrl(config.getDatabaseVendor().jdbcUrlDriverId(), config.getHost(), config.getPort(), Optional.of("mydb")); assertEquals(connectionUrl, db.getConnectionURL()); assertEquals(config.getConnectionDriver(), db.getConnectionDriver()); assertEquals("dbuser", db.getConnectionUserName().getRaw()); assertEquals("dbpass", db.getConnectionPassword().getRaw()); assertEquals(ResourceStatus.USER_MANAGED, db.getStatus()); assertEquals("hive", db.getType()); assertEquals(config.getEnvironmentId(), db.getEnvironmentId()); assertEquals(config, db.getServer()); }
public DatabaseConfig createDatabaseConfig(String databaseName, String type, Optional<String> databaseDescription, ResourceStatus status, String userName, String password) { if (host == null) { throw new IllegalStateException("Database server config has no host"); } if (port == null) { throw new IllegalStateException("Database server config has no port"); } DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setDatabaseVendor(databaseVendor); databaseConfig.setName(databaseName); databaseConfig.setDescription(databaseDescription.orElse(description)); databaseConfig.setConnectionURL(new DatabaseCommon().getJdbcConnectionUrl(databaseVendor.jdbcUrlDriverId(), host, port, Optional.of(databaseName))); databaseConfig.setConnectionDriver(connectionDriver); databaseConfig.setConnectionUserName(userName); databaseConfig.setConnectionPassword(password); databaseConfig.setStatus(status); databaseConfig.setType(type); databaseConfig.setEnvironmentId(environmentId); databaseConfig.setServer(this); return databaseConfig; }
DatabaseServerConfig implements ArchivableResource, AccountIdAwareResource { public DatabaseConfig createDatabaseConfig(String databaseName, String type, Optional<String> databaseDescription, ResourceStatus status, String userName, String password) { if (host == null) { throw new IllegalStateException("Database server config has no host"); } if (port == null) { throw new IllegalStateException("Database server config has no port"); } DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setDatabaseVendor(databaseVendor); databaseConfig.setName(databaseName); databaseConfig.setDescription(databaseDescription.orElse(description)); databaseConfig.setConnectionURL(new DatabaseCommon().getJdbcConnectionUrl(databaseVendor.jdbcUrlDriverId(), host, port, Optional.of(databaseName))); databaseConfig.setConnectionDriver(connectionDriver); databaseConfig.setConnectionUserName(userName); databaseConfig.setConnectionPassword(password); databaseConfig.setStatus(status); databaseConfig.setType(type); databaseConfig.setEnvironmentId(environmentId); databaseConfig.setServer(this); return databaseConfig; } }
DatabaseServerConfig implements ArchivableResource, AccountIdAwareResource { public DatabaseConfig createDatabaseConfig(String databaseName, String type, Optional<String> databaseDescription, ResourceStatus status, String userName, String password) { if (host == null) { throw new IllegalStateException("Database server config has no host"); } if (port == null) { throw new IllegalStateException("Database server config has no port"); } DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setDatabaseVendor(databaseVendor); databaseConfig.setName(databaseName); databaseConfig.setDescription(databaseDescription.orElse(description)); databaseConfig.setConnectionURL(new DatabaseCommon().getJdbcConnectionUrl(databaseVendor.jdbcUrlDriverId(), host, port, Optional.of(databaseName))); databaseConfig.setConnectionDriver(connectionDriver); databaseConfig.setConnectionUserName(userName); databaseConfig.setConnectionPassword(password); databaseConfig.setStatus(status); databaseConfig.setType(type); databaseConfig.setEnvironmentId(environmentId); databaseConfig.setServer(this); return databaseConfig; }  }
DatabaseServerConfig implements ArchivableResource, AccountIdAwareResource { public DatabaseConfig createDatabaseConfig(String databaseName, String type, Optional<String> databaseDescription, ResourceStatus status, String userName, String password) { if (host == null) { throw new IllegalStateException("Database server config has no host"); } if (port == null) { throw new IllegalStateException("Database server config has no port"); } DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setDatabaseVendor(databaseVendor); databaseConfig.setName(databaseName); databaseConfig.setDescription(databaseDescription.orElse(description)); databaseConfig.setConnectionURL(new DatabaseCommon().getJdbcConnectionUrl(databaseVendor.jdbcUrlDriverId(), host, port, Optional.of(databaseName))); databaseConfig.setConnectionDriver(connectionDriver); databaseConfig.setConnectionUserName(userName); databaseConfig.setConnectionPassword(password); databaseConfig.setStatus(status); databaseConfig.setType(type); databaseConfig.setEnvironmentId(environmentId); databaseConfig.setServer(this); return databaseConfig; }  Long getId(); void setId(Long id); @Override String getAccountId(); void setAccountId(String accountId); Crn getResourceCrn(); void setResourceCrn(Crn resourceCrn); Long getWorkspaceId(); void setWorkspaceId(Long workspaceId); String getName(); void setName(String name); String getDescription(); void setDescription(String description); String getHost(); void setHost(String host); Integer getPort(); void setPort(Integer port); DatabaseVendor getDatabaseVendor(); void setDatabaseVendor(DatabaseVendor databaseVendor); String getConnectionDriver(); void setConnectionDriver(String connectionDriver); String getConnectionUserName(); String getConnectionUserNameSecret(); void setConnectionUserName(String connectionUserName); String getConnectionPassword(); String getConnectionPasswordSecret(); void setConnectionPassword(String connectionPassword); Long getCreationDate(); void setCreationDate(Long creationDate); ResourceStatus getResourceStatus(); void setResourceStatus(ResourceStatus resourceStatus); Long getDeletionTimestamp(); @Override void setDeletionTimestamp(Long timestampMillisecs); boolean isArchived(); @Override void setArchived(boolean archived); @Override void unsetRelationsToEntitiesToBeDeleted(); String getEnvironmentId(); void setEnvironmentId(String environmentId); Set<DatabaseConfig> getDatabases(); @VisibleForTesting void setDatabases(Set<DatabaseConfig> databases); Optional<DBStack> getDbStack(); void setDbStack(DBStack dbStack); String getClusterCrn(); void setClusterCrn(String clusterCrn); DatabaseConfig createDatabaseConfig(String databaseName, String type, Optional<String> databaseDescription, ResourceStatus status,
        String userName, String password); }
DatabaseServerConfig implements ArchivableResource, AccountIdAwareResource { public DatabaseConfig createDatabaseConfig(String databaseName, String type, Optional<String> databaseDescription, ResourceStatus status, String userName, String password) { if (host == null) { throw new IllegalStateException("Database server config has no host"); } if (port == null) { throw new IllegalStateException("Database server config has no port"); } DatabaseConfig databaseConfig = new DatabaseConfig(); databaseConfig.setDatabaseVendor(databaseVendor); databaseConfig.setName(databaseName); databaseConfig.setDescription(databaseDescription.orElse(description)); databaseConfig.setConnectionURL(new DatabaseCommon().getJdbcConnectionUrl(databaseVendor.jdbcUrlDriverId(), host, port, Optional.of(databaseName))); databaseConfig.setConnectionDriver(connectionDriver); databaseConfig.setConnectionUserName(userName); databaseConfig.setConnectionPassword(password); databaseConfig.setStatus(status); databaseConfig.setType(type); databaseConfig.setEnvironmentId(environmentId); databaseConfig.setServer(this); return databaseConfig; }  Long getId(); void setId(Long id); @Override String getAccountId(); void setAccountId(String accountId); Crn getResourceCrn(); void setResourceCrn(Crn resourceCrn); Long getWorkspaceId(); void setWorkspaceId(Long workspaceId); String getName(); void setName(String name); String getDescription(); void setDescription(String description); String getHost(); void setHost(String host); Integer getPort(); void setPort(Integer port); DatabaseVendor getDatabaseVendor(); void setDatabaseVendor(DatabaseVendor databaseVendor); String getConnectionDriver(); void setConnectionDriver(String connectionDriver); String getConnectionUserName(); String getConnectionUserNameSecret(); void setConnectionUserName(String connectionUserName); String getConnectionPassword(); String getConnectionPasswordSecret(); void setConnectionPassword(String connectionPassword); Long getCreationDate(); void setCreationDate(Long creationDate); ResourceStatus getResourceStatus(); void setResourceStatus(ResourceStatus resourceStatus); Long getDeletionTimestamp(); @Override void setDeletionTimestamp(Long timestampMillisecs); boolean isArchived(); @Override void setArchived(boolean archived); @Override void unsetRelationsToEntitiesToBeDeleted(); String getEnvironmentId(); void setEnvironmentId(String environmentId); Set<DatabaseConfig> getDatabases(); @VisibleForTesting void setDatabases(Set<DatabaseConfig> databases); Optional<DBStack> getDbStack(); void setDbStack(DBStack dbStack); String getClusterCrn(); void setClusterCrn(String clusterCrn); DatabaseConfig createDatabaseConfig(String databaseName, String type, Optional<String> databaseDescription, ResourceStatus status,
        String userName, String password);  }