Search in sources :

Example 1 with ResourceGroupUsage

use of com.sequenceiq.cloudbreak.cloud.azure.ResourceGroupUsage in project cloudbreak by hortonworks.

the class AzureDatabaseResourceService method buildDatabaseResourcesForLaunch.

public List<CloudResourceStatus> buildDatabaseResourcesForLaunch(AuthenticatedContext ac, DatabaseStack stack, PersistenceNotifier persistenceNotifier) {
    CloudContext cloudContext = ac.getCloudContext();
    AzureClient client = ac.getParameter(AzureClient.class);
    String stackName = azureUtils.getStackName(cloudContext);
    String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, stack);
    ResourceGroupUsage resourceGroupUsage = azureResourceGroupMetadataProvider.getResourceGroupUsage(stack);
    String template = azureDatabaseTemplateBuilder.build(cloudContext, stack);
    if (!client.resourceGroupExists(resourceGroupName)) {
        if (resourceGroupUsage != ResourceGroupUsage.MULTIPLE) {
            LOGGER.warn("Resource group with name {} does not exist", resourceGroupName);
            throw new CloudConnectorException(String.format("Resource group with name %s does not exist!", resourceGroupName));
        } else {
            LOGGER.debug("Resource group with name {} does not exist, creating it now..", resourceGroupName);
            String region = ac.getCloudContext().getLocation().getRegion().value();
            client.createResourceGroup(resourceGroupName, region, stack.getTags());
        }
    }
    createResourceGroupResource(persistenceNotifier, cloudContext, resourceGroupName);
    createTemplateResource(persistenceNotifier, cloudContext, stackName);
    Deployment deployment;
    try {
        String parametersMapAsString = new Json(Map.of()).getValue();
        client.createTemplateDeployment(resourceGroupName, stackName, template, parametersMapAsString);
    } catch (CloudException e) {
        throw azureUtils.convertToCloudConnectorException(e, "Database stack provisioning");
    } catch (Exception e) {
        throw new CloudConnectorException(String.format("Error in provisioning database stack %s: %s", stackName, e.getMessage()), e);
    } finally {
        deployment = client.getTemplateDeployment(resourceGroupName, stackName);
        if (deployment != null) {
            List<CloudResource> cloudResources = azureCloudResourceService.getDeploymentCloudResources(deployment);
            cloudResources.forEach(cloudResource -> persistenceNotifier.notifyAllocation(cloudResource, cloudContext));
        }
    }
    String fqdn = (String) ((Map) ((Map) deployment.outputs()).get(DATABASE_SERVER_FQDN)).get("value");
    List<CloudResource> databaseResources = createCloudResources(fqdn);
    databaseResources.forEach(dbr -> persistenceNotifier.notifyAllocation(dbr, cloudContext));
    return databaseResources.stream().map(resource -> new CloudResourceStatus(resource, ResourceStatus.CREATED)).collect(Collectors.toList());
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ARM_TEMPLATE(com.sequenceiq.common.api.type.ResourceType.ARM_TEMPLATE) AzureDatabaseTemplateProvider(com.sequenceiq.cloudbreak.cloud.azure.AzureDatabaseTemplateProvider) LoggerFactory(org.slf4j.LoggerFactory) ResourceGroupUsage(com.sequenceiq.cloudbreak.cloud.azure.ResourceGroupUsage) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AZURE_PRIVATE_ENDPOINT(com.sequenceiq.common.api.type.ResourceType.AZURE_PRIVATE_ENDPOINT) Lists(com.google.common.collect.Lists) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) AzureDatabaseTemplateBuilder(com.sequenceiq.cloudbreak.cloud.azure.AzureDatabaseTemplateBuilder) Service(org.springframework.stereotype.Service) Map(java.util.Map) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) AzureUtils(com.sequenceiq.cloudbreak.cloud.azure.AzureUtils) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) ResourceType(com.sequenceiq.common.api.type.ResourceType) AZURE_RESOURCE_GROUP(com.sequenceiq.common.api.type.ResourceType.AZURE_RESOURCE_GROUP) Deployment(com.microsoft.azure.management.resources.Deployment) Logger(org.slf4j.Logger) AzureResourceGroupMetadataProvider(com.sequenceiq.cloudbreak.cloud.azure.AzureResourceGroupMetadataProvider) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) Collectors(java.util.stream.Collectors) AzureCloudResourceService(com.sequenceiq.cloudbreak.cloud.azure.AzureCloudResourceService) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) Json(com.sequenceiq.cloudbreak.common.json.Json) AZURE_DATABASE(com.sequenceiq.common.api.type.ResourceType.AZURE_DATABASE) RDS_HOSTNAME(com.sequenceiq.common.api.type.ResourceType.RDS_HOSTNAME) List(java.util.List) AzureTransientDeploymentService(com.sequenceiq.cloudbreak.cloud.azure.template.AzureTransientDeploymentService) CloudException(com.microsoft.azure.CloudException) Optional(java.util.Optional) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Deployment(com.microsoft.azure.management.resources.Deployment) Json(com.sequenceiq.cloudbreak.common.json.Json) CloudException(com.microsoft.azure.CloudException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudException(com.microsoft.azure.CloudException) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) ResourceGroupUsage(com.sequenceiq.cloudbreak.cloud.azure.ResourceGroupUsage) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map)

Aggregations

Lists (com.google.common.collect.Lists)1 CloudException (com.microsoft.azure.CloudException)1 Deployment (com.microsoft.azure.management.resources.Deployment)1 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)1 AzureCloudResourceService (com.sequenceiq.cloudbreak.cloud.azure.AzureCloudResourceService)1 AzureDatabaseTemplateBuilder (com.sequenceiq.cloudbreak.cloud.azure.AzureDatabaseTemplateBuilder)1 AzureDatabaseTemplateProvider (com.sequenceiq.cloudbreak.cloud.azure.AzureDatabaseTemplateProvider)1 AzureResourceGroupMetadataProvider (com.sequenceiq.cloudbreak.cloud.azure.AzureResourceGroupMetadataProvider)1 AzureUtils (com.sequenceiq.cloudbreak.cloud.azure.AzureUtils)1 ResourceGroupUsage (com.sequenceiq.cloudbreak.cloud.azure.ResourceGroupUsage)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 AzureTransientDeploymentService (com.sequenceiq.cloudbreak.cloud.azure.template.AzureTransientDeploymentService)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)1 ExternalDatabaseStatus (com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)1 ResourceStatus (com.sequenceiq.cloudbreak.cloud.model.ResourceStatus)1