Search in sources :

Example 16 with DatabaseServer

use of com.sequenceiq.redbeams.domain.stack.DatabaseServer in project cloudbreak by hortonworks.

the class AllocateDatabaseServerV4RequestToDBStackConverter method buildDatabaseServer.

private DatabaseServer buildDatabaseServer(DatabaseServerV4StackRequest source, CloudPlatform cloudPlatform, Crn ownerCrn, SecurityAccessResponse securityAccessResponse) {
    DatabaseServer server = new DatabaseServer();
    server.setAccountId(ownerCrn.getAccountId());
    server.setName(generateDatabaseServerName());
    server.setInstanceType(source.getInstanceType());
    DatabaseVendor databaseVendor = DatabaseVendor.fromValue(source.getDatabaseVendor());
    server.setDatabaseVendor(databaseVendor);
    server.setConnectionDriver(source.getConnectionDriver());
    server.setStorageSize(source.getStorageSize());
    server.setRootUserName(source.getRootUserName() != null ? source.getRootUserName() : userGeneratorService.generateUserName());
    server.setRootPassword(source.getRootUserPassword() != null ? source.getRootUserPassword() : passwordGeneratorService.generatePassword(Optional.of(cloudPlatform)));
    server.setPort(source.getPort());
    server.setSecurityGroup(buildExistingSecurityGroup(source.getSecurityGroup(), securityAccessResponse));
    Map<String, Object> parameters = providerParameterCalculator.get(source).asMap();
    if (parameters != null) {
        try {
            setDbVersion(parameters, cloudPlatform);
            server.setAttributes(new Json(parameters));
        } catch (IllegalArgumentException e) {
            throw new BadRequestException("Invalid database server parameters", e);
        }
    }
    return server;
}
Also used : DatabaseVendor(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DatabaseVendor) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Json(com.sequenceiq.cloudbreak.common.json.Json)

Aggregations

DatabaseServer (com.sequenceiq.redbeams.domain.stack.DatabaseServer)16 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)11 Test (org.junit.jupiter.api.Test)11 Json (com.sequenceiq.cloudbreak.common.json.Json)8 Network (com.sequenceiq.redbeams.domain.stack.Network)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)6 SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)3 DatabaseVendor (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DatabaseVendor)1 TemplatingNotSupportedException (com.sequenceiq.cloudbreak.cloud.exception.TemplatingNotSupportedException)1 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)1 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)1 SecurityGroup (com.sequenceiq.redbeams.domain.stack.SecurityGroup)1 RedbeamsException (com.sequenceiq.redbeams.exception.RedbeamsException)1 HashSet (java.util.HashSet)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1