use of com.sequenceiq.cloudbreak.cloud.azure.image.marketplace.AzureMarketplaceImage in project cloudbreak by hortonworks.
the class AzureTemplateDeploymentService method getTemplate.
private String getTemplate(CloudStack stack, AzureStackView azureStackView, AuthenticatedContext ac, CloudContext cloudContext, String stackName, AzureClient client, AzureInstanceTemplateOperation azureInstanceTemplateOperation) {
String template;
Image stackImage = stack.getImage();
if (azureImageFormatValidator.isMarketplaceImageFormat(stackImage)) {
AzureMarketplaceImage azureMarketplaceImage = azureMarketplaceImageProviderService.get(stack.getImage());
template = azureTemplateBuilder.build(stackName, null, createCredential(ac), azureStackView, cloudContext, stack, azureInstanceTemplateOperation, azureMarketplaceImage);
} else {
String customImageId = azureStorage.getCustomImage(client, ac, stack).getId();
template = azureTemplateBuilder.build(stackName, customImageId, createCredential(ac), azureStackView, cloudContext, stack, azureInstanceTemplateOperation, null);
}
return template;
}
use of com.sequenceiq.cloudbreak.cloud.azure.image.marketplace.AzureMarketplaceImage in project cloudbreak by hortonworks.
the class AzureImageFormatValidator method validate.
@Override
public void validate(AuthenticatedContext ac, CloudStack cloudStack) {
Image image = cloudStack.getImage();
String imageUri = image.getImageName();
if (isVhdImageFormat(image)) {
LOGGER.debug("Image {} seems to be a valid VHD image", imageUri);
} else if (isMarketplaceImageFormat(image)) {
LOGGER.debug("Checking presence of Azure Marketplace entitlement for Marketplace image {}", imageUri);
String accountId = ThreadBasedUserCrnProvider.getAccountId();
if (!entitlementService.azureMarketplaceImagesEnabled(accountId)) {
String errorMessage = String.format("Your image %s seems to be an Azure Marketplace image! " + "If you would like to use it please open Cloudera support ticket to enable this capability!", imageUri);
LOGGER.warn(errorMessage);
throw new CloudConnectorException(errorMessage);
}
LOGGER.debug("Checking if Terms and Conditions for your Azure Marketplace image {} are accepted", imageUri);
AzureClient azureClient = ac.getParameter(AzureClient.class);
AzureMarketplaceImage azureMarketplaceImage = azureMarketplaceImageProviderService.get(image);
if (!enableAzureImageTermsAutomaticSigner && !azureImageTermsSignerService.isSigned(azureClient.getCurrentSubscription().subscriptionId(), azureMarketplaceImage, azureClient)) {
String errorMessage = String.format("Your image %s seems to be an Azure Marketplace image, " + "however its Terms and Conditions are not accepted! Please accept them and retry upgrade. " + "On how to accept the Terms and Conditions of the image please refer to azure documentation " + "at https://docs.microsoft.com/en-us/cli/azure/vm/image/terms?view=azure-cli-latest.", imageUri);
LOGGER.warn(errorMessage);
throw new CloudConnectorException(errorMessage);
}
} else {
String errorMessage = String.format("Your image name %s is invalid. Please check the desired format in the documentation!", imageUri);
LOGGER.warn(errorMessage);
throw new CloudConnectorException(errorMessage);
}
}
use of com.sequenceiq.cloudbreak.cloud.azure.image.marketplace.AzureMarketplaceImage in project cloudbreak by hortonworks.
the class AzureResourceConnector method launch.
@Override
public List<CloudResourceStatus> launch(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier notifier, AdjustmentTypeWithThreshold adjustmentTypeWithThreshold) {
AzureCredentialView azureCredentialView = new AzureCredentialView(ac.getCloudCredential());
CloudContext cloudContext = ac.getCloudContext();
String stackName = azureUtils.getStackName(cloudContext);
String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, stack);
AzureClient client = ac.getParameter(AzureClient.class);
AzureStackView azureStackView = azureStackViewProvider.getAzureStack(azureCredentialView, stack, client, ac);
String template;
Image stackImage = stack.getImage();
if (azureImageFormatValidator.isMarketplaceImageFormat(stackImage)) {
LOGGER.debug("Launching with Azure Marketplace image {}", stackImage);
AzureMarketplaceImage azureMarketplaceImage = azureMarketplaceImageProviderService.get(stackImage);
if (enableAzureImageTermsAutomaticSigner) {
azureImageTermsSignerService.sign(azureCredentialView.getSubscriptionId(), azureMarketplaceImage, client);
}
template = azureTemplateBuilder.build(stackName, null, azureCredentialView, azureStackView, cloudContext, stack, AzureInstanceTemplateOperation.PROVISION, azureMarketplaceImage);
} else {
LOGGER.debug("Launching with non-Azure Marketplace image {}", stackImage);
AzureImage image = azureStorage.getCustomImage(client, ac, stack);
if (!image.getAlreadyExists()) {
LOGGER.debug("Image {} has been created now, so we need to persist it", image.getName());
CloudResource imageCloudResource = azureCloudResourceService.buildCloudResource(image.getName(), image.getId(), ResourceType.AZURE_MANAGED_IMAGE);
azureCloudResourceService.saveCloudResources(notifier, ac.getCloudContext(), List.of(imageCloudResource));
}
String customImageId = image.getId();
template = azureTemplateBuilder.build(stackName, customImageId, azureCredentialView, azureStackView, cloudContext, stack, AzureInstanceTemplateOperation.PROVISION, null);
}
String parameters = azureTemplateBuilder.buildParameters(ac.getCloudCredential(), stack.getNetwork(), stackImage);
boolean resourcesPersisted = false;
try {
List<CloudResource> instances;
if (shouldCreateTemplateDeployment(stackName, resourceGroupName, client)) {
Deployment templateDeployment = client.createTemplateDeployment(resourceGroupName, stackName, template, parameters);
LOGGER.debug("Created template deployment for launch: {}", templateDeployment.exportTemplate().template());
instances = persistCloudResources(ac, stack, notifier, cloudContext, stackName, resourceGroupName, templateDeployment);
} else {
Deployment templateDeployment = client.getTemplateDeployment(resourceGroupName, stackName);
LOGGER.debug("Get template deployment for launch as it exists: {}", templateDeployment.exportTemplate().template());
instances = persistCloudResources(ac, stack, notifier, cloudContext, stackName, resourceGroupName, templateDeployment);
}
resourcesPersisted = true;
String networkName = azureUtils.getCustomNetworkId(stack.getNetwork());
List<String> subnetNameList = azureUtils.getCustomSubnetIds(stack.getNetwork());
List<CloudResource> networkResources = azureCloudResourceService.collectAndSaveNetworkAndSubnet(resourceGroupName, stackName, notifier, cloudContext, subnetNameList, networkName, client);
azureComputeResourceService.buildComputeResourcesForLaunch(ac, stack, adjustmentTypeWithThreshold, instances, networkResources);
} catch (CloudException e) {
throw azureUtils.convertToCloudConnectorException(e, "Stack provisioning");
} catch (Exception e) {
LOGGER.warn("Provisioning error:", e);
throw new CloudConnectorException(String.format("Error in provisioning stack %s: %s", stackName, e.getMessage()));
} finally {
if (!resourcesPersisted) {
Deployment templateDeployment = client.getTemplateDeployment(resourceGroupName, stackName);
if (templateDeployment != null && templateDeployment.exportTemplate() != null) {
LOGGER.debug("Get template deployment to persist created resources: {}", templateDeployment.exportTemplate().template());
persistCloudResources(ac, stack, notifier, cloudContext, stackName, resourceGroupName, templateDeployment);
}
}
}
CloudResource cloudResource = new Builder().type(ResourceType.ARM_TEMPLATE).name(resourceGroupName).build();
List<CloudResourceStatus> resources = check(ac, Collections.singletonList(cloudResource));
LOGGER.debug("Launched resources: {}", resources);
return resources;
}
Aggregations