Search in sources :

Example 6 with ResourceGroupUsage

use of com.sequenceiq.environment.api.v1.environment.model.request.azure.ResourceGroupUsage in project cloudbreak by hortonworks.

the class DBStackToDatabaseStackConverter method buildParameters.

private Map<String, Object> buildParameters(DBStack stack) {
    Json attributes = stack.getDatabaseServer().getAttributes();
    Map<String, Object> params = attributes == null ? Collections.emptyMap() : attributes.getMap();
    if (CloudPlatform.AZURE.name().equals(stack.getCloudPlatform())) {
        DetailedEnvironmentResponse environment = getDetailedEnvironmentResponse(stack);
        if (!stack.getParameters().containsKey(RESOURCE_GROUP_NAME_PARAMETER)) {
            Optional<AzureResourceGroup> resourceGroupOptional = getResourceGroupFromEnv(environment);
            if (resourceGroupOptional.isPresent() && !ResourceGroupUsage.MULTIPLE.equals(resourceGroupOptional.get().getResourceGroupUsage())) {
                AzureResourceGroup resourceGroup = resourceGroupOptional.get();
                String resourceGroupName = resourceGroup.getName();
                ResourceGroupUsage resourceGroupUsage = resourceGroup.getResourceGroupUsage();
                Map<String, Object> resourceGroupParameters = Map.of(RESOURCE_GROUP_NAME_PARAMETER, resourceGroupName, RESOURCE_GROUP_USAGE_PARAMETER, resourceGroupUsage.name());
                params = getMergedMap(params, resourceGroupParameters);
            }
        }
        if (azureEncryptionParametersPresent(environment)) {
            Map<String, Object> encryptionParameters = Map.of(ENCRYPTION_KEY_URL, getEncryptionKeyUrlFromEnv(environment), ENCRYPTION_KEY_RESOURCE_GROUP_NAME, getEncryptionKeyResourceGroupNameFromEnv(environment));
            params = getMergedMap(params, encryptionParameters);
        }
    } else if (CloudPlatform.GCP.name().equals(stack.getCloudPlatform())) {
        DetailedEnvironmentResponse environment = getDetailedEnvironmentResponse(stack);
        Optional<String> key = getGcpEncryptionKeyFromEnv(environment);
        if (key.isPresent()) {
            Map<String, Object> encryptionParameters = Map.of(VOLUME_ENCRYPTION_KEY_ID, key.get());
            params = getMergedMap(params, encryptionParameters);
        }
    } else if (CloudPlatform.AWS.name().equals(stack.getCloudPlatform())) {
        DetailedEnvironmentResponse environment = getDetailedEnvironmentResponse(stack);
        Optional<String> key = getEncryptionKeyArnFromEnv(environment);
        if (key.isPresent()) {
            Map<String, Object> awsEncryptionParameters = Map.of(VOLUME_ENCRYPTION_KEY_ID, key.get());
            params = getMergedMap(params, awsEncryptionParameters);
        }
    }
    return params;
}
Also used : ResourceGroupUsage(com.sequenceiq.environment.api.v1.environment.model.request.azure.ResourceGroupUsage) Optional(java.util.Optional) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Json(com.sequenceiq.cloudbreak.common.json.Json) AzureResourceGroup(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup) Map(java.util.Map)

Aggregations

ResourceGroupUsage (com.sequenceiq.environment.api.v1.environment.model.request.azure.ResourceGroupUsage)6 AzureResourceGroup (com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup)5 HashMap (java.util.HashMap)4 Json (com.sequenceiq.cloudbreak.common.json.Json)1 AzureEnvironmentParameters (com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureEnvironmentParameters)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 Map (java.util.Map)1 Optional (java.util.Optional)1