Search in sources :

Example 61 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class AzureResourceConnector method downscale.

@Override
public List<CloudResourceStatus> downscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, List<CloudInstance> vms, Map<String, Map<String, Object>> resourcesToRemove) {
    AzureClient client = ac.getParameter(AzureClient.class);
    String stackName = azureUtils.getStackName(ac.getCloudContext());
    String resourceGroupName = azureUtils.getResourceGroupName(ac.getCloudContext());
    String diskContainer = azureStorage.getDiskContainerName(ac.getCloudContext());
    for (CloudInstance instance : vms) {
        String instanceId = instance.getInstanceId();
        Map<String, Object> instanceResources = resourcesToRemove.get(instanceId);
        try {
            deallocateVirtualMachine(client, stackName, instanceId);
            deleteVirtualMachine(client, stackName, instanceId);
            if (instanceResources != null) {
                deleteNetworkInterfaces(client, stackName, (Iterable<String>) instanceResources.get(NETWORK_INTERFACES_NAMES));
                deletePublicIps(client, stackName, (Iterable<String>) instanceResources.get(PUBLIC_ADDRESS_NAME));
                deleteDisk((Iterable<String>) instanceResources.get(STORAGE_PROFILE_DISK_NAMES), client, resourceGroupName, (String) instanceResources.get(ATTACHED_DISK_STORAGE_NAME), diskContainer);
                deleteManagedDisks((Iterable<String>) instanceResources.get(MANAGED_DISK_IDS), client);
                if (azureStorage.getArmAttachedStorageOption(stack.getParameters()) == ArmAttachedStorageOption.PER_VM) {
                    azureStorage.deleteStorage(client, (String) instanceResources.get(ATTACHED_DISK_STORAGE_NAME), resourceGroupName);
                }
            }
        } catch (CloudConnectorException e) {
            throw e;
        } catch (RuntimeException e) {
            throw new CloudConnectorException(String.format("Failed to cleanup resources after downscale: %s", stackName), e);
        }
    }
    return check(ac, resources);
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 62 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class AzureResourceConnector method launch.

@Override
public List<CloudResourceStatus> launch(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier notifier, AdjustmentType adjustmentType, Long threshold) {
    AzureCredentialView azureCredentialView = new AzureCredentialView(ac.getCloudCredential());
    String stackName = azureUtils.getStackName(ac.getCloudContext());
    String resourceGroupName = azureUtils.getResourceGroupName(ac.getCloudContext());
    AzureClient client = ac.getParameter(AzureClient.class);
    AzureStackView azureStackView = getAzureStack(azureCredentialView, ac.getCloudContext(), stack, getNumberOfAvailableIPsInSubnets(client, stack.getNetwork()));
    String customImageId = azureStorage.getCustomImageId(client, ac, stack);
    String template = azureTemplateBuilder.build(stackName, customImageId, azureCredentialView, azureStackView, ac.getCloudContext(), stack);
    String parameters = azureTemplateBuilder.buildParameters(ac.getCloudCredential(), stack.getNetwork(), stack.getImage());
    Boolean encrytionNeeded = azureStorage.isEncrytionNeeded(stack.getParameters());
    try {
        String region = ac.getCloudContext().getLocation().getRegion().value();
        if (AzureUtils.hasUnmanagedDisk(stack)) {
            Map<String, AzureDiskType> storageAccounts = azureStackView.getStorageAccounts();
            for (Entry<String, AzureDiskType> entry : storageAccounts.entrySet()) {
                azureStorage.createStorage(client, entry.getKey(), entry.getValue(), resourceGroupName, region, encrytionNeeded, stack.getTags());
            }
        }
        if (!client.templateDeploymentExists(resourceGroupName, stackName)) {
            Deployment templateDeployment = client.createTemplateDeployment(resourceGroupName, stackName, template, parameters);
            LOGGER.info("created template deployment for launch: {}", templateDeployment.exportTemplate().template());
            if (!azureUtils.isExistingNetwork(stack.getNetwork())) {
                client.collectAndSaveNetworkAndSubnet(resourceGroupName, stackName, notifier, ac.getCloudContext());
            }
        }
    } catch (CloudException e) {
        LOGGER.error("Provisioning error, cloud exception happened: ", e);
        if (e.body() != null && e.body().details() != null) {
            String details = e.body().details().stream().map(CloudError::message).collect(Collectors.joining(", "));
            throw new CloudConnectorException(String.format("Stack provisioning failed, status code %s, error message: %s, details: %s", e.body().code(), e.body().message(), details));
        } else {
            throw new CloudConnectorException(String.format("Stack provisioning failed: '%s', please go to Azure Portal for detailed message", e));
        }
    } catch (Exception e) {
        LOGGER.error("Provisioning error:", e);
        throw new CloudConnectorException(String.format("Error in provisioning stack %s: %s", stackName, e.getMessage()));
    }
    CloudResource cloudResource = new Builder().type(ResourceType.ARM_TEMPLATE).name(stackName).build();
    List<CloudResourceStatus> resources = check(ac, Collections.singletonList(cloudResource));
    LOGGER.debug("Launched resources: {}", resources);
    return resources;
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) Deployment(com.microsoft.azure.management.resources.Deployment) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) CloudError(com.microsoft.azure.CloudError) CloudException(com.microsoft.azure.CloudException) ActionWentFailException(com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) 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)

Example 63 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class AzureSetup method prerequisites.

@Override
public void prerequisites(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier persistenceNotifier) {
    String storageGroup = azureUtils.getResourceGroupName(ac.getCloudContext());
    CloudResource cloudResource = new Builder().type(ResourceType.ARM_TEMPLATE).name(storageGroup).build();
    String region = ac.getCloudContext().getLocation().getRegion().value();
    try {
        AzureClient client = ac.getParameter(AzureClient.class);
        persistenceNotifier.notifyAllocation(cloudResource, ac.getCloudContext());
        if (!client.resourceGroupExists(storageGroup)) {
            client.createResourceGroup(storageGroup, region, stack.getTags(), defaultCostTaggingService.prepareTemplateTagging());
        }
    } catch (Exception ex) {
        throw new CloudConnectorException(ex);
    }
    LOGGER.debug("setup has been executed");
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) URISyntaxException(java.net.URISyntaxException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) StorageException(com.microsoft.azure.storage.StorageException) UnknownHostException(java.net.UnknownHostException) InvalidKeyException(java.security.InvalidKeyException)

Example 64 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class AzureSetup method validateAdlsFileSystem.

private void validateAdlsFileSystem(CloudCredential credential, FileSystem fileSystem) {
    Map<String, Object> credentialAttributes = credential.getParameters();
    String clientSecret = String.valueOf(credentialAttributes.get(AdlsFileSystemConfiguration.CREDENTIAL_SECRET_KEY));
    String subscriptionId = String.valueOf(credentialAttributes.get(AdlsFileSystemConfiguration.SUBSCRIPTION_ID));
    String clientId = String.valueOf(credentialAttributes.get(AdlsFileSystemConfiguration.ACCESS_KEY));
    String tenantId = fileSystem.getStringParameter(AdlsFileSystemConfiguration.TENANT_ID);
    String accountName = fileSystem.getStringParameter(FileSystemConfiguration.ACCOUNT_NAME);
    ApplicationTokenCredentials creds = new ApplicationTokenCredentials(clientId, tenantId, clientSecret, AzureEnvironment.AZURE);
    DataLakeStoreAccountManagementClient adlsClient = new DataLakeStoreAccountManagementClientImpl(creds);
    adlsClient.withSubscriptionId(subscriptionId);
    List<DataLakeStoreAccount> dataLakeStoreAccounts = adlsClient.accounts().list();
    boolean validAccountname = false;
    for (DataLakeStoreAccount account : dataLakeStoreAccounts) {
        if (account.name().equalsIgnoreCase(accountName)) {
            validAccountname = true;
            break;
        }
    }
    if (!validAccountname) {
        throw new CloudConnectorException("The provided file system account name does not belong to a valid ADLS account");
    }
}
Also used : DataLakeStoreAccount(com.microsoft.azure.management.datalake.store.models.DataLakeStoreAccount) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) DataLakeStoreAccountManagementClient(com.microsoft.azure.management.datalake.store.DataLakeStoreAccountManagementClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) DataLakeStoreAccountManagementClientImpl(com.microsoft.azure.management.datalake.store.implementation.DataLakeStoreAccountManagementClientImpl)

Aggregations

CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)64 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)14 StorageException (com.microsoft.azure.storage.StorageException)11 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)9 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)9 AmazonServiceException (com.amazonaws.AmazonServiceException)8 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)8 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)8 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 URISyntaxException (java.net.URISyntaxException)7 ActionWentFailException (com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException)6 HashMap (java.util.HashMap)6 CloudException (com.microsoft.azure.CloudException)5 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)5 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)4 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)3 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)3 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)3 Group (com.sequenceiq.cloudbreak.cloud.model.Group)3