use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DatabaseServerConfigToDatabaseServerV4ResponseConverterTest method testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeCloudProviderOwned.
@ParameterizedTest(name = "{0}")
@MethodSource("testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeCloudProviderOwnedDataProvider")
void testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeCloudProviderOwned(String testCaseName, Integer certActiveVersionInput, String certActiveCloudProviderIdentifierInput, int certActiveVersionExpected, String certActiveCloudProviderIdentifierExpected) {
DatabaseServerConfig server = new DatabaseServerConfig();
server.setResourceCrn(TestData.getTestCrn(RESOURCE_TYPE_DATABASE_SERVER, RESOURCE_ID));
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
DBStack dbStack = new DBStack();
dbStack.setCloudPlatform(CLOUD_PLATFORM);
dbStack.setRegion(REGION);
SslConfig sslConfig = new SslConfig();
sslConfig.setSslCertificateType(SslCertificateType.CLOUD_PROVIDER_OWNED);
sslConfig.setSslCertificates(CERTS);
sslConfig.setSslCertificateActiveVersion(certActiveVersionInput);
sslConfig.setSslCertificateActiveCloudProviderIdentifier(certActiveCloudProviderIdentifierInput);
dbStack.setSslConfig(sslConfig);
server.setDbStack(dbStack);
when(databaseServerSslCertificateConfig.getMaxVersionByCloudPlatformAndRegion(CLOUD_PLATFORM, REGION)).thenReturn(CERT_MAX_VERSION);
when(databaseServerSslCertificateConfig.getLegacyMaxVersionByCloudPlatformAndRegion(CLOUD_PLATFORM, REGION)).thenReturn(CERT_LEGACY_MAX_VERSION);
when(databaseServerSslCertificateConfig.getLegacyCloudProviderIdentifierByCloudPlatformAndRegion(CLOUD_PLATFORM, REGION)).thenReturn(CERT_LEGACY_CLOUD_PROVIDER_IDENTIFIER);
DatabaseServerV4Response response = converter.convert(server);
assertThat(response).isNotNull();
SslConfigV4Response sslConfigV4Response = response.getSslConfig();
assertThat(sslConfigV4Response).isNotNull();
assertThat(sslConfigV4Response.getSslMode()).isEqualTo(SslMode.ENABLED);
assertThat(sslConfigV4Response.getSslCertificateType()).isEqualTo(SslCertificateType.CLOUD_PROVIDER_OWNED);
assertThat(sslConfigV4Response.getSslCertificates()).isSameAs(CERTS);
assertThat(sslConfigV4Response.getSslCertificateHighestAvailableVersion()).isEqualTo(CERT_MAX_VERSION);
assertThat(sslConfigV4Response.getSslCertificateActiveVersion()).isEqualTo(certActiveVersionExpected);
assertThat(sslConfigV4Response.getSslCertificateActiveCloudProviderIdentifier()).isEqualTo(certActiveCloudProviderIdentifierExpected);
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DatabaseServerConfigTest method testGettersAndSetters.
@Test
public void testGettersAndSetters() {
config.setId(1L);
assertEquals(1L, config.getId().longValue());
config.setAccountId("myaccount");
assertEquals("myaccount", config.getAccountId());
Crn crn = TestData.getTestCrn("databaseServer", "myserver");
config.setResourceCrn(crn);
assertEquals(crn, config.getResourceCrn());
config.setWorkspaceId(0L);
assertEquals(0L, config.getWorkspaceId().longValue());
config.setName("myserver");
assertEquals("myserver", config.getName());
config.setDescription("mine not yours");
assertEquals("mine not yours", config.getDescription());
config.setHost("myserver.db.example.com");
assertEquals("myserver.db.example.com", config.getHost());
config.setPort(5432);
assertEquals(5432, config.getPort().intValue());
config.setDatabaseVendor(DatabaseVendor.POSTGRES);
assertEquals(DatabaseVendor.POSTGRES, config.getDatabaseVendor());
config.setConnectionDriver("org.postgresql.Driver");
assertEquals("org.postgresql.Driver", config.getConnectionDriver());
config.setConnectionUserName("root");
assertEquals("root", config.getConnectionUserName());
config.setConnectionPassword("cloudera");
assertEquals("cloudera", config.getConnectionPassword());
long now = System.currentTimeMillis();
config.setCreationDate(now);
assertEquals(now, config.getCreationDate().longValue());
config.setResourceStatus(ResourceStatus.SERVICE_MANAGED);
assertEquals(ResourceStatus.SERVICE_MANAGED, config.getResourceStatus());
config.setDeletionTimestamp(2L);
assertEquals(2L, config.getDeletionTimestamp().longValue());
config.setArchived(true);
assertTrue(config.isArchived());
config.setEnvironmentId("myenvironment");
assertEquals("myenvironment", config.getEnvironmentId());
config.setDbStack(new DBStack());
assertTrue(config.getDbStack().isPresent());
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DatabaseServerV4ControllerTest method testCreate.
@Test
public void testCreate() {
when(dbStackConverter.convert(allocateRequest, USER_CRN)).thenReturn(dbStack);
DBStack savedDBStack = new DBStack();
when(creationService.launchDatabaseServer(dbStack, CLUSTER_CRN)).thenReturn(savedDBStack);
when(dbStackToDatabaseServerStatusV4ResponseConverter.convert(savedDBStack)).thenReturn(allocateResponse);
DatabaseServerStatusV4Response response = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.create(allocateRequest));
assertEquals(allocateResponse, response);
verify(creationService).launchDatabaseServer(dbStack, CLUSTER_CRN);
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DatabaseServerV4ControllerTest method setUp.
@Before
public void setUp() {
initMocks(this);
server = new DatabaseServerConfig();
server.setId(1L);
server.setName(SERVER_NAME);
server.setEnvironmentId(ENVIRONMENT_CRN);
server.setResourceCrn(CRN);
server2 = new DatabaseServerConfig();
server2.setId(2L);
server2.setName("myotherserver");
server2.setEnvironmentId(ENVIRONMENT_CRN);
request = new DatabaseServerV4Request();
request.setName(SERVER_NAME);
serverResponse = new DatabaseServerV4Response();
serverResponse.setId(1L);
serverResponse.setName(SERVER_NAME);
serverResponse2 = new DatabaseServerV4Response();
serverResponse2.setId(2L);
serverResponse2.setName("myotherserver");
allocateRequest = new AllocateDatabaseServerV4Request();
allocateRequest.setClusterCrn(CLUSTER_CRN);
allocateResponse = new DatabaseServerStatusV4Response();
dbStack = new DBStack();
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DBStackStatusSyncJob method executeTracedJob.
@Override
protected void executeTracedJob(JobExecutionContext context) throws JobExecutionException {
Long dbStackId = Long.valueOf(getLocalId());
DBStack dbStack = dbStackService.getById(dbStackId);
if (flowLogService.isOtherFlowRunning(dbStackId)) {
LOGGER.debug("DBStackStatusCheckerJob cannot run, because flow is running for stack: {}", dbStackId);
} else {
try {
measure(() -> {
ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> {
dbStackStatusSyncService.sync(dbStack);
});
}, LOGGER, ":::Auto sync::: DB stack sync in {}ms");
} catch (Exception e) {
LOGGER.info(":::Auto sync::: Error occurred during DB sync: {}", e.getMessage(), e);
}
}
}
Aggregations