use of com.sequenceiq.cloudbreak.cloud.azure.context.AzureContext in project cloudbreak by hortonworks.
the class AzureVolumeResourceBuilder method delete.
@Override
@Retryable(value = RuntimeException.class, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000), maxAttempts = 5)
public CloudResource delete(AzureContext context, AuthenticatedContext auth, CloudResource resource) throws PreserveResourceException {
LOGGER.info("Delete the disks from the instances if they are not reattached. {}", resource);
VolumeSetAttributes volumeSetAttributes = getVolumeSetAttributes(resource);
List<CloudResourceStatus> cloudResourceStatuses = checkResources(ResourceType.AZURE_VOLUMESET, context, auth, List.of(resource));
boolean anyDeleted = cloudResourceStatuses.stream().map(CloudResourceStatus::getStatus).anyMatch(ResourceStatus.DELETED::equals);
preserveVolumeIfDoNotDeleteOnTermination(auth, resource, volumeSetAttributes, anyDeleted);
LOGGER.info("Resource {} will be deleted.", resource.getName());
AzureClient client = getAzureClient(auth);
List<CloudResourceStatus> removableDisks = cloudResourceStatuses.stream().filter(cloudResourceStatus -> ResourceStatus.CREATED.equals(cloudResourceStatus.getStatus()) || (ResourceStatus.ATTACHED.equals(cloudResourceStatus.getStatus()) && volumeSetAttributes.getDeleteOnTermination())).collect(toList());
deleteVolumes(client, removableDisks);
return null;
}
Aggregations