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());
}
Aggregations