Search in sources :

Example 41 with DBStack

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);
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 42 with DBStack

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());
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Test(org.junit.Test)

Example 43 with DBStack

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);
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) DatabaseServerStatusV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerStatusV4Response) Test(org.junit.Test)

Example 44 with DBStack

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();
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) AllocateDatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request) DatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.DatabaseServerV4Request) AllocateDatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request) DatabaseServerStatusV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerStatusV4Response) Before(org.junit.Before)

Example 45 with 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);
        }
    }
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) JobExecutionException(org.quartz.JobExecutionException)

Aggregations

DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)83 Test (org.junit.jupiter.api.Test)28 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 Test (org.junit.Test)13 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)7 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)7 DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)7 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)6 SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)6 Credential (com.sequenceiq.redbeams.dto.Credential)6 RedbeamsFailureEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent)6 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)5 CloudDatabaseServerSslCertificate (com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate)5 RedbeamsEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Location (com.sequenceiq.cloudbreak.cloud.model.Location)4