Search in sources :

Example 6 with DatabaseServerV4StackRequest

use of com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest in project cloudbreak by hortonworks.

the class AllocateDatabaseServerV4RequestToDBStackConverterTest method setUp.

@BeforeEach
public void setUp() {
    ReflectionTestUtils.setField(underTest, FIELD_DB_SERVICE_SUPPORTED_PLATFORMS, Set.of("AWS", "AZURE"));
    ReflectionTestUtils.setField(underTest, FIELD_REDBEAMS_DB_MAJOR_VERSION, REDBEAMS_DB_MAJOR_VERSION);
    ReflectionTestUtils.setField(underTest, FIELD_SSL_ENABLED, true);
    allocateRequest = new AllocateDatabaseServerV4Request();
    networkRequest = new NetworkV4StackRequest();
    allocateRequest.setNetwork(networkRequest);
    databaseServerRequest = new DatabaseServerV4StackRequest();
    allocateRequest.setDatabaseServer(databaseServerRequest);
    securityGroupRequest = new SecurityGroupV4StackRequest();
    databaseServerRequest.setSecurityGroup(securityGroupRequest);
    when(crnUserDetailsService.loadUserByUsername(OWNER_CRN)).thenReturn(getCrnUser());
    when(uuidGeneratorService.randomUuid()).thenReturn("uuid");
    when(accountTagService.list()).thenReturn(new HashMap<>());
    when(uuidGeneratorService.uuidVariableParts(anyInt())).thenReturn("parts");
    when(entitlementService.internalTenant(anyString())).thenReturn(true);
    sslCertificateEntryV2 = new SslCertificateEntry(VERSION_2, CLOUD_PROVIDER_IDENTIFIER_V2, CERT_PEM_V2, x509Certificate);
    sslCertificateEntryV3 = new SslCertificateEntry(VERSION_3, CLOUD_PROVIDER_IDENTIFIER_V3, CERT_PEM_V3, x509Certificate);
    when(databaseServerSslCertificateConfig.getMaxVersionByCloudPlatformAndRegion(anyString(), eq(REGION))).thenReturn(MAX_VERSION);
    when(clock.getCurrentInstant()).thenReturn(NOW);
    when(crnService.createCrn(any(DBStack.class))).thenReturn(CrnTestUtil.getDatabaseServerCrnBuilder().setAccountId("accountid").setResource("1").build());
}
Also used : NetworkV4StackRequest(com.sequenceiq.redbeams.api.endpoint.v4.stacks.NetworkV4StackRequest) DatabaseServerV4StackRequest(com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) SslCertificateEntry(com.sequenceiq.redbeams.configuration.SslCertificateEntry) AllocateDatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request) SecurityGroupV4StackRequest(com.sequenceiq.redbeams.api.endpoint.v4.stacks.SecurityGroupV4StackRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with DatabaseServerV4StackRequest

use of com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest 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 8 with DatabaseServerV4StackRequest

use of com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest in project cloudbreak by hortonworks.

the class GcpDatabaseServerParameterSetter method setParameters.

@Override
public void setParameters(DatabaseServerV4StackRequest request, SdxDatabaseAvailabilityType availabilityType, String databaseEngineVersion) {
    GcpDatabaseServerV4Parameters parameters = new GcpDatabaseServerV4Parameters();
    if (SdxDatabaseAvailabilityType.HA.equals(availabilityType)) {
        parameters.setBackupRetentionDays(backupRetentionPeriodNonHa);
    } else if (SdxDatabaseAvailabilityType.NON_HA.equals(availabilityType)) {
        parameters.setBackupRetentionDays(backupRetentionPeriodNonHa);
    } else {
        throw new IllegalArgumentException(availabilityType + " database availability type is not supported on Azure.");
    }
    if (StringUtils.isNotEmpty(databaseEngineVersion)) {
        parameters.setEngineVersion(databaseEngineVersion);
    }
    request.setGcp(parameters);
}
Also used : GcpDatabaseServerV4Parameters(com.sequenceiq.redbeams.api.endpoint.v4.stacks.gcp.GcpDatabaseServerV4Parameters)

Example 9 with DatabaseServerV4StackRequest

use of com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest in project cloudbreak by hortonworks.

the class AwsDatabaseServerParameterSetter method setParameters.

@Override
public void setParameters(DatabaseServerV4StackRequest request, SdxDatabaseAvailabilityType availabilityType, String databaseEngineVersion) {
    AwsDatabaseServerV4Parameters parameters = new AwsDatabaseServerV4Parameters();
    if (SdxDatabaseAvailabilityType.HA.equals(availabilityType)) {
        parameters.setBackupRetentionPeriod(backupRetentionPeriodHa);
        parameters.setMultiAZ("true");
    } else if (SdxDatabaseAvailabilityType.NON_HA.equals(availabilityType)) {
        parameters.setBackupRetentionPeriod(backupRetentionPeriodNonHa);
        parameters.setMultiAZ("false");
    } else {
        throw new IllegalArgumentException(availabilityType + " database availability type is not supported on AWS.");
    }
    if (StringUtils.isNotEmpty(databaseEngineVersion)) {
        parameters.setEngineVersion(databaseEngineVersion);
    }
    request.setAws(parameters);
}
Also used : AwsDatabaseServerV4Parameters(com.sequenceiq.redbeams.api.endpoint.v4.stacks.aws.AwsDatabaseServerV4Parameters)

Example 10 with DatabaseServerV4StackRequest

use of com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest in project cloudbreak by hortonworks.

the class DatabaseServiceTest method shouldSetDbConfigBasedOnClusterShape.

@ParameterizedTest(name = "{0}")
@MethodSource("sslEnforcementDataProvider")
public void shouldSetDbConfigBasedOnClusterShape(String testCaseName, boolean supportedPlatform, String runtime, Boolean entitled, boolean sslEnforcementAppliedExpected) {
    SdxCluster cluster = new SdxCluster();
    cluster.setClusterName("NAME");
    cluster.setClusterShape(SdxClusterShape.LIGHT_DUTY);
    cluster.setCrn(CLUSTER_CRN);
    cluster.setRuntime(runtime);
    DetailedEnvironmentResponse env = new DetailedEnvironmentResponse();
    env.setName("ENV");
    env.setCloudPlatform("aws");
    env.setCrn(ENV_CRN);
    DatabaseConfig databaseConfig = getDatabaseConfig();
    when(databaseServerV4Endpoint.createInternal(any(), any())).thenThrow(BadRequestException.class);
    DatabaseConfigKey dbConfigKey = new DatabaseConfigKey(CloudPlatform.AWS, SdxClusterShape.LIGHT_DUTY);
    when(dbConfigs.get(dbConfigKey)).thenReturn(databaseConfig);
    when(databaseParameterSetterMap.get(CloudPlatform.AWS)).thenReturn(getDatabaseParameterSetter());
    when(platformConfig.isExternalDatabaseSslEnforcementSupportedFor(CloudPlatform.AWS)).thenReturn(supportedPlatform);
    if (entitled != null) {
        when(entitlementService.databaseWireEncryptionEnabled(ACCOUNT_ID)).thenReturn(entitled);
    }
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    SdxStatusEntity status = new SdxStatusEntity();
    status.setStatus(DatalakeStatusEnum.REQUESTED);
    when(sdxStatusService.getActualStatusForSdx(any())).thenReturn(status);
    assertThatCode(() -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.create(cluster, env))).isInstanceOf(BadRequestException.class);
    verify(databaseServerV4Endpoint).createInternal(allocateDatabaseServerV4RequestCaptor.capture(), anyString());
    AllocateDatabaseServerV4Request dbRequest = allocateDatabaseServerV4RequestCaptor.getValue();
    assertThat(dbRequest).isNotNull();
    DatabaseServerV4StackRequest databaseServer = dbRequest.getDatabaseServer();
    assertThat(databaseServer).isNotNull();
    assertThat(databaseServer.getInstanceType()).isEqualTo("instanceType");
    assertThat(databaseServer.getDatabaseVendor()).isEqualTo("vendor");
    assertThat(databaseServer.getStorageSize()).isEqualTo(100L);
    assertThat(dbRequest.getClusterCrn()).isEqualTo(CLUSTER_CRN);
    assertThat(databaseServer.getAws()).isNotNull();
    SslConfigV4Request sslConfig = dbRequest.getSslConfig();
    if (sslEnforcementAppliedExpected) {
        assertThat(sslConfig).isNotNull();
        assertThat(sslConfig.getSslMode()).isEqualTo(SslMode.ENABLED);
    } else {
        assertThat(sslConfig).isNull();
    }
    verifyNoInteractions(sdxClusterRepository);
    verifyNoInteractions(notificationService);
}
Also used : DatabaseServerV4StackRequest(com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest) SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity) AllocateDatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SslConfigV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.SslConfigV4Request) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

DatabaseServerV4StackRequest (com.sequenceiq.redbeams.api.endpoint.v4.stacks.DatabaseServerV4StackRequest)8 DatabaseServerParameter (com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter)3 BadRequestException (javax.ws.rs.BadRequestException)3 DatabaseStackConfig (com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseStackConfig)2 AllocateDatabaseServerV4Request (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request)2 NetworkV4StackRequest (com.sequenceiq.redbeams.api.endpoint.v4.stacks.NetworkV4StackRequest)2 AwsDatabaseServerV4Parameters (com.sequenceiq.redbeams.api.endpoint.v4.stacks.aws.AwsDatabaseServerV4Parameters)2 AzureDatabaseServerV4Parameters (com.sequenceiq.redbeams.api.endpoint.v4.stacks.azure.AzureDatabaseServerV4Parameters)2 GcpDatabaseServerV4Parameters (com.sequenceiq.redbeams.api.endpoint.v4.stacks.gcp.GcpDatabaseServerV4Parameters)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxStatusEntity (com.sequenceiq.datalake.entity.SdxStatusEntity)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 SslConfigV4Request (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.SslConfigV4Request)1 SecurityGroupV4StackRequest (com.sequenceiq.redbeams.api.endpoint.v4.stacks.SecurityGroupV4StackRequest)1 SslCertificateEntry (com.sequenceiq.redbeams.configuration.SslCertificateEntry)1 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)1 Test (org.junit.Test)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1