Search in sources :

Example 6 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class DBStackToDatabaseStackConverterTest method testConversionGcpWithGcpEncryptionResourcesPresent.

@Test
public void testConversionGcpWithGcpEncryptionResourcesPresent() {
    Network network = new Network();
    network.setAttributes(new Json(NETWORK_ATTRIBUTES));
    dbStack.setNetwork(network);
    dbStack.setCloudPlatform("GCP");
    dbStack.setParameters(new HashMap<>());
    DatabaseServer server = new DatabaseServer();
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    server.setAttributes(new Json(DATABASE_SERVER_ATTRIBUTES));
    dbStack.setDatabaseServer(server);
    dbStack.setTags(new Json(STACK_TAGS));
    dbStack.setTemplate("template");
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCloudPlatform("GCP");
    environmentResponse.setGcp(GcpEnvironmentParameters.builder().withResourceEncryptionParameters(GcpResourceEncryptionParameters.builder().withEncryptionKey("value").build()).build());
    when(environmentService.getByCrn(anyString())).thenReturn(environmentResponse);
    DatabaseStack convertedStack = underTest.convert(dbStack);
    Map<String, Object> parameters = convertedStack.getDatabaseServer().getParameters();
    assertThat(parameters.get("key").toString()).isEqualTo("value");
    assertThat(parameters.size()).isEqualTo(3);
}
Also used : Network(com.sequenceiq.redbeams.domain.stack.Network) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Json(com.sequenceiq.cloudbreak.common.json.Json) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 7 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class DBStackToDatabaseStackConverterTest method testConversionAwsWithAwsEncryptionResourcesPresent.

@Test
public void testConversionAwsWithAwsEncryptionResourcesPresent() {
    Network network = new Network();
    network.setAttributes(new Json(NETWORK_ATTRIBUTES));
    dbStack.setNetwork(network);
    dbStack.setCloudPlatform("AWS");
    dbStack.setParameters(new HashMap<>());
    DatabaseServer server = new DatabaseServer();
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    server.setAttributes(new Json(DATABASE_SERVER_ATTRIBUTES));
    dbStack.setDatabaseServer(server);
    dbStack.setTags(new Json(STACK_TAGS));
    dbStack.setTemplate("template");
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCloudPlatform("AWS");
    environmentResponse.setAws(AwsEnvironmentParameters.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParameters.builder().withEncryptionKeyArn("value").build()).build());
    when(environmentService.getByCrn(anyString())).thenReturn(environmentResponse);
    DatabaseStack convertedStack = underTest.convert(dbStack);
    Map<String, Object> parameters = convertedStack.getDatabaseServer().getParameters();
    assertThat(parameters.get("key").toString()).isEqualTo("value");
    assertThat(parameters.size()).isEqualTo(3);
}
Also used : Network(com.sequenceiq.redbeams.domain.stack.Network) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Json(com.sequenceiq.cloudbreak.common.json.Json) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 8 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class DBStackToDatabaseStackConverterTest method testConversionWithSslCertificateCloudProviderOwned.

@Test
void testConversionWithSslCertificateCloudProviderOwned() {
    DatabaseServer server = new DatabaseServer();
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    dbStack.setDatabaseServer(server);
    SslConfig sslConfig = new SslConfig();
    sslConfig.setSslCertificateType(SslCertificateType.CLOUD_PROVIDER_OWNED);
    dbStack.setSslConfig(sslConfig);
    DatabaseStack convertedStack = underTest.convert(dbStack);
    assertThat(convertedStack.getDatabaseServer().isUseSslEnforcement()).isTrue();
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Test(org.junit.jupiter.api.Test)

Example 9 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class AbstractRedbeamsTerminationAction method createFlowContext.

@Override
protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsTerminationState, RedbeamsTerminationEvent> stateContext, P payload) {
    Optional<DBStack> optionalDBStack = dbStackService.findById(payload.getResourceId());
    CloudContext cloudContext = null;
    CloudCredential cloudCredential = null;
    DatabaseStack databaseStack = null;
    DBStack dbStack = null;
    if (optionalDBStack.isPresent()) {
        dbStack = optionalDBStack.get();
        MDCBuilder.buildMdcContext(dbStack);
        Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone()));
        String userName = dbStack.getOwnerCrn().getUserId();
        String accountId = dbStack.getOwnerCrn().getAccountId();
        cloudContext = CloudContext.Builder.builder().withId(dbStack.getId()).withName(dbStack.getName()).withCrn(dbStack.getResourceCrn()).withPlatform(dbStack.getCloudPlatform()).withVariant(dbStack.getPlatformVariant()).withUserName(userName).withLocation(location).withAccountId(accountId).build();
        try {
            Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId());
            cloudCredential = credentialConverter.convert(credential);
        } catch (Exception ex) {
            LOGGER.warn("Could not detect credential for environment: {}", dbStack.getEnvironmentId());
        }
        databaseStack = databaseStackConverter.convert(dbStack);
    } else {
        LOGGER.warn("DBStack for {} id is not found in the database, it seems to be only possible if the redbeams process was killed during the execution" + " of the termination finished action", payload.getResourceId());
    }
    return new RedbeamsContext(flowParameters, cloudContext, cloudCredential, databaseStack, dbStack);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.redbeams.dto.Credential) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) RedbeamsContext(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsContext) RedbeamsException(com.sequenceiq.redbeams.exception.RedbeamsException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 10 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class AbstractRedbeamsStartAction method createFlowContext.

@Override
protected RedbeamsStartContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsStartState, RedbeamsStartEvent> stateContext, P payload) {
    DBStack dbStack = dbStackService.getById(payload.getResourceId());
    MDCBuilder.buildMdcContext(dbStack);
    Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone()));
    String userName = dbStack.getOwnerCrn().getUserId();
    String accountId = dbStack.getOwnerCrn().getAccountId();
    CloudContext cloudContext = CloudContext.Builder.builder().withId(dbStack.getId()).withName(dbStack.getName()).withCrn(dbStack.getResourceCrn()).withPlatform(dbStack.getCloudPlatform()).withVariant(dbStack.getPlatformVariant()).withLocation(location).withUserName(userName).withAccountId(accountId).build();
    Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId());
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    DatabaseStack databaseStack = databaseStackConverter.convert(dbStack);
    return new RedbeamsStartContext(flowParameters, cloudContext, cloudCredential, databaseStack);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.redbeams.dto.Credential) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) RedbeamsStartContext(com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)48 Test (org.junit.jupiter.api.Test)34 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)24 DatabaseServer (com.sequenceiq.cloudbreak.cloud.model.DatabaseServer)24 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)22 SQLAdmin (com.google.api.services.sqladmin.SQLAdmin)16 InstancesListResponse (com.google.api.services.sqladmin.model.InstancesListResponse)13 DatabaseInstance (com.google.api.services.sqladmin.model.DatabaseInstance)12 PersistenceNotifier (com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier)12 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)11 DatabaseServer (com.sequenceiq.redbeams.domain.stack.DatabaseServer)11 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)10 Network (com.sequenceiq.cloudbreak.cloud.model.Network)9 ExternalDatabaseStatus (com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)8 Location (com.sequenceiq.cloudbreak.cloud.model.Location)8 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)8 Json (com.sequenceiq.cloudbreak.common.json.Json)8 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)7 Network (com.sequenceiq.redbeams.domain.stack.Network)7