Search in sources :

Example 1 with AzureMarketplaceImage

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;
}
Also used : AzureMarketplaceImage(com.sequenceiq.cloudbreak.cloud.azure.image.marketplace.AzureMarketplaceImage) AzureMarketplaceImage(com.sequenceiq.cloudbreak.cloud.azure.image.marketplace.AzureMarketplaceImage) Image(com.sequenceiq.cloudbreak.cloud.model.Image)

Example 2 with AzureMarketplaceImage

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);
    }
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AzureMarketplaceImage(com.sequenceiq.cloudbreak.cloud.azure.image.marketplace.AzureMarketplaceImage) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AzureMarketplaceImage(com.sequenceiq.cloudbreak.cloud.azure.image.marketplace.AzureMarketplaceImage) Image(com.sequenceiq.cloudbreak.cloud.model.Image)

Example 3 with AzureMarketplaceImage

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;
}
Also used : AzureMarketplaceImage(com.sequenceiq.cloudbreak.cloud.azure.image.marketplace.AzureMarketplaceImage) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) Deployment(com.microsoft.azure.management.resources.Deployment) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) CloudException(com.microsoft.azure.CloudException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) AzureMarketplaceImage(com.sequenceiq.cloudbreak.cloud.azure.image.marketplace.AzureMarketplaceImage) ActionFailedException(com.sequenceiq.cloudbreak.service.Retry.ActionFailedException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) QuotaExceededException(com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException) CloudException(com.microsoft.azure.CloudException) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Aggregations

AzureMarketplaceImage (com.sequenceiq.cloudbreak.cloud.azure.image.marketplace.AzureMarketplaceImage)3 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 CloudException (com.microsoft.azure.CloudException)1 Deployment (com.microsoft.azure.management.resources.Deployment)1 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)1 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 QuotaExceededException (com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)1 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1 ActionFailedException (com.sequenceiq.cloudbreak.service.Retry.ActionFailedException)1