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