Search in sources :

Example 1 with DatabaseServerParameter

use of com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter in project cloudbreak by hortonworks.

the class ExternalDatabaseService method getDatabaseServerStackRequest.

private DatabaseServerV4StackRequest getDatabaseServerStackRequest(CloudPlatform cloudPlatform, DatabaseAvailabilityType externalDatabase) {
    DatabaseStackConfig databaseStackConfig = dbConfigs.get(cloudPlatform);
    if (databaseStackConfig == null) {
        throw new BadRequestException("Database config for cloud platform " + cloudPlatform + " not found");
    }
    DatabaseServerV4StackRequest request = new DatabaseServerV4StackRequest();
    request.setInstanceType(databaseStackConfig.getInstanceType());
    request.setDatabaseVendor(databaseStackConfig.getVendor());
    request.setStorageSize(databaseStackConfig.getVolumeSize());
    DatabaseServerParameter serverParameter = DatabaseServerParameter.builder().withHighlyAvailable(DatabaseAvailabilityType.HA == externalDatabase).build();
    parameterDecoratorMap.get(cloudPlatform).setParameters(request, serverParameter);
    return request;
}
Also used : DatabaseStackConfig(com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseStackConfig) DatabaseServerV4StackRequest(com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest) BadRequestException(javax.ws.rs.BadRequestException) DatabaseServerParameter(com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter)

Example 2 with DatabaseServerParameter

use of com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter in project cloudbreak by hortonworks.

the class ExternalDatabaseService method getDatabaseServerStackRequest.

private DatabaseServerV4StackRequest getDatabaseServerStackRequest(CloudPlatform cloudPlatform, DatabaseAvailabilityType externalDatabase, String databaseEngineVersion) {
    DatabaseStackConfig databaseStackConfig = dbConfigs.get(cloudPlatform);
    if (databaseStackConfig == null) {
        throw new BadRequestException("Database config for cloud platform " + cloudPlatform + " not found");
    }
    DatabaseServerV4StackRequest request = new DatabaseServerV4StackRequest();
    request.setInstanceType(databaseStackConfig.getInstanceType());
    request.setDatabaseVendor(databaseStackConfig.getVendor());
    request.setStorageSize(databaseStackConfig.getVolumeSize());
    DatabaseServerParameter serverParameter = DatabaseServerParameter.builder().withHighlyAvailable(DatabaseAvailabilityType.HA == externalDatabase).withEngineVersion(databaseEngineVersion).build();
    parameterDecoratorMap.get(cloudPlatform).setParameters(request, serverParameter);
    return request;
}
Also used : DatabaseStackConfig(com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseStackConfig) DatabaseServerV4StackRequest(com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest) BadRequestException(javax.ws.rs.BadRequestException) DatabaseServerParameter(com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter)

Example 3 with DatabaseServerParameter

use of com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter in project cloudbreak by hortonworks.

the class AwsDatabaseServerParameterDecoratorTest method setParameters.

@ParameterizedTest
@ValueSource(booleans = { false, true })
void setParameters(boolean needsHA) {
    DatabaseServerParameter serverParameter = DatabaseServerParameter.builder().withHighlyAvailable(needsHA).build();
    DatabaseServerV4StackRequest request = new DatabaseServerV4StackRequest();
    underTest.setParameters(request, serverParameter);
    assertThat(request.getAws().getMultiAZ()).isEqualTo(Boolean.toString(needsHA));
}
Also used : DatabaseServerV4StackRequest(com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest) DatabaseServerParameter(com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with DatabaseServerParameter

use of com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter in project cloudbreak by hortonworks.

the class ExternalDatabaseServiceTest method provisionDatabaseWhenStackIsNullOnCluster.

@Test
void provisionDatabaseWhenStackIsNullOnCluster() throws JsonProcessingException {
    DatabaseServerStatusV4Response createResponse = new DatabaseServerStatusV4Response();
    createResponse.setResourceCrn(RDBMS_CRN);
    Cluster cluster = spy(new Cluster());
    cluster.setStack(null);
    when(redbeamsClient.create(any())).thenReturn(createResponse);
    when(databaseObtainerService.obtainAttemptResult(eq(cluster), eq(DatabaseOperation.CREATION), eq(RDBMS_CRN), eq(true))).thenReturn(AttemptResults.finishWith(new DatabaseServerV4Response()));
    underTest.provisionDatabase(cluster, DatabaseAvailabilityType.NON_HA, environmentResponse);
    verify(redbeamsClient, never()).getByClusterCrn(nullable(String.class), nullable(String.class));
    ArgumentCaptor<DatabaseServerParameter> serverParameterCaptor = ArgumentCaptor.forClass(DatabaseServerParameter.class);
    verify(redbeamsClient).create(any(AllocateDatabaseServerV4Request.class));
    verify(cluster).setDatabaseServerCrn(RDBMS_CRN);
    verify(dbServerParameterDecorator).setParameters(any(), serverParameterCaptor.capture());
    verify(clusterRepository).save(cluster);
    DatabaseServerParameter paramValue = serverParameterCaptor.getValue();
    assertThat(paramValue.isHighlyAvailable()).isFalse();
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) AllocateDatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request) DatabaseServerStatusV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerStatusV4Response) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DatabaseServerParameter(com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with DatabaseServerParameter

use of com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter in project cloudbreak by hortonworks.

the class ExternalDatabaseServiceTest method provisionDatabase.

@ParameterizedTest
@EnumSource(DatabaseAvailabilityType.class)
void provisionDatabase(DatabaseAvailabilityType availabilty) throws JsonProcessingException {
    Assumptions.assumeTrue(!availabilty.isEmbedded());
    DatabaseServerStatusV4Response createResponse = new DatabaseServerStatusV4Response();
    createResponse.setResourceCrn(RDBMS_CRN);
    Cluster cluster = spy(new Cluster());
    Stack stack = new Stack();
    stack.setResourceCrn(CLUSTER_CRN);
    cluster.setStack(stack);
    when(redbeamsClient.getByClusterCrn(nullable(String.class), nullable(String.class))).thenReturn(null);
    when(redbeamsClient.create(any())).thenReturn(createResponse);
    when(databaseObtainerService.obtainAttemptResult(eq(cluster), eq(DatabaseOperation.CREATION), eq(RDBMS_CRN), eq(true))).thenReturn(AttemptResults.finishWith(new DatabaseServerV4Response()));
    underTest.provisionDatabase(cluster, availabilty, environmentResponse);
    ArgumentCaptor<DatabaseServerParameter> serverParameterCaptor = ArgumentCaptor.forClass(DatabaseServerParameter.class);
    verify(redbeamsClient).getByClusterCrn(ENV_CRN, CLUSTER_CRN);
    verify(redbeamsClient).create(any(AllocateDatabaseServerV4Request.class));
    verify(cluster).setDatabaseServerCrn(RDBMS_CRN);
    verify(dbServerParameterDecorator).setParameters(any(), serverParameterCaptor.capture());
    verify(clusterRepository).save(cluster);
    DatabaseServerParameter paramValue = serverParameterCaptor.getValue();
    assertThat(paramValue.isHighlyAvailable()).isEqualTo(availabilty == DatabaseAvailabilityType.HA);
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) AllocateDatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request) DatabaseServerStatusV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerStatusV4Response) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseServerParameter(com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DatabaseServerParameter (com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter)5 DatabaseServerV4StackRequest (com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)2 DatabaseStackConfig (com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseStackConfig)2 AllocateDatabaseServerV4Request (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request)2 DatabaseServerStatusV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerStatusV4Response)2 DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)2 BadRequestException (javax.ws.rs.BadRequestException)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 Test (org.junit.jupiter.api.Test)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1