Search in sources :

Example 56 with CloudConnectorException

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

the class AzureClient method deleteBlobInStorageContainer.

public void deleteBlobInStorageContainer(String resourceGroup, String storageName, String containerName, String blobName) {
    LOGGER.debug("delete blob: RG={}, storageName={}, containerName={}, blobName={}", resourceGroup, storageName, containerName, blobName);
    CloudBlobContainer container = getBlobContainer(resourceGroup, storageName, containerName);
    try {
        CloudBlockBlob blob = container.getBlockBlobReference(blobName);
        boolean wasDeleted = blob.deleteIfExists();
        LOGGER.info("blob was deleted: " + wasDeleted);
    } catch (URISyntaxException e) {
        throw new CloudConnectorException("can't delete blob in storage container, URI is not valid", e);
    } catch (StorageException e) {
        throw new CloudConnectorException("can't delete blob in storage container, storage service error occurred", e);
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) URISyntaxException(java.net.URISyntaxException) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException)

Example 57 with CloudConnectorException

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

the class AzureClient method setPublicPermissionOnContainer.

public void setPublicPermissionOnContainer(String resourceGroup, String storageName, String containerName) {
    LOGGER.debug("set public permission on container: RG={}, storageName={}, containerName={}", resourceGroup, storageName, containerName);
    CloudBlobContainer container = getBlobContainer(resourceGroup, storageName, containerName);
    BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
    containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
    try {
        container.uploadPermissions(containerPermissions);
    } catch (StorageException e) {
        throw new CloudConnectorException("can't set public permission on container, storage service error occurred", e);
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobContainerPermissions(com.microsoft.azure.storage.blob.BlobContainerPermissions) StorageException(com.microsoft.azure.storage.StorageException)

Example 58 with CloudConnectorException

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

the class AzureClient method copyImageBlobInStorageContainer.

public void copyImageBlobInStorageContainer(String resourceGroup, String storageName, String containerName, String sourceBlob) {
    LOGGER.debug("copy image in storage container: RG={}, storageName={}, containerName={}, sourceBlob={}", resourceGroup, storageName, containerName, sourceBlob);
    CloudBlobContainer container = getBlobContainer(resourceGroup, storageName, containerName);
    try {
        CloudPageBlob cloudPageBlob = container.getPageBlobReference(sourceBlob.substring(sourceBlob.lastIndexOf('/') + 1));
        String copyId = cloudPageBlob.startCopy(new URI(sourceBlob));
        LOGGER.info("image copy started, copy id: {}", copyId);
    } catch (URISyntaxException e) {
        throw new CloudConnectorException("can't copy image blob, URI is not valid", e);
    } catch (StorageException e) {
        throw new CloudConnectorException("can't copy image blob, storage service error occurred", e);
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) StorageException(com.microsoft.azure.storage.StorageException) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob)

Example 59 with CloudConnectorException

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

the class AzureClient method getCopyStatus.

public CopyState getCopyStatus(String resourceGroup, String storageName, String containerName, String sourceBlob) {
    LOGGER.debug("get image copy status: RG={}, storageName={}, containerName={}, sourceBlob={}", resourceGroup, storageName, containerName, sourceBlob);
    CloudBlobContainer container = getBlobContainer(resourceGroup, storageName, containerName);
    try {
        CloudPageBlob cloudPageBlob = container.getPageBlobReference(sourceBlob.substring(sourceBlob.lastIndexOf('/') + 1));
        container.downloadAttributes();
        cloudPageBlob.downloadAttributes();
        return cloudPageBlob.getCopyState();
    } catch (URISyntaxException e) {
        throw new CloudConnectorException("can't get copy status, URI is not valid", e);
    } catch (StorageException e) {
        throw new CloudConnectorException("can't get copy status, storage service error occurred", e);
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob)

Example 60 with CloudConnectorException

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

the class AzureResourceConnector method terminate.

@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) {
    AzureClient client = authenticatedContext.getParameter(AzureClient.class);
    for (CloudResource resource : resources) {
        try {
            try {
                retryService.testWith2SecDelayMax5Times(() -> {
                    if (!client.resourceGroupExists(resource.getName())) {
                        throw new ActionWentFailException("Resource group not exists");
                    }
                    return true;
                });
                client.deleteResourceGroup(resource.getName());
            } catch (ActionWentFailException ignored) {
                LOGGER.info(String.format("Resource group not found with name: %s", resource.getName()));
            }
            if (azureStorage.isPersistentStorage(azureStorage.getPersistentStorageName(stack))) {
                CloudContext cloudCtx = authenticatedContext.getCloudContext();
                AzureCredentialView azureCredentialView = new AzureCredentialView(authenticatedContext.getCloudCredential());
                String imageStorageName = azureStorage.getImageStorageName(azureCredentialView, cloudCtx, stack);
                String imageResourceGroupName = azureStorage.getImageResourceGroupName(cloudCtx, stack);
                String diskContainer = azureStorage.getDiskContainerName(cloudCtx);
                deleteContainer(client, imageResourceGroupName, imageStorageName, diskContainer);
            }
        } catch (CloudException e) {
            if (e.response().code() != AzureConstants.NOT_FOUND) {
                throw new CloudConnectorException(String.format("Could not delete resource group: %s", resource.getName()), e);
            } else {
                return check(authenticatedContext, Collections.emptyList());
            }
        }
    }
    return check(authenticatedContext, resources);
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudException(com.microsoft.azure.CloudException) ActionWentFailException(com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException)

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