use of com.sequenceiq.cloudbreak.cloud.template.compute.PreserveResourceException 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;
}
use of com.sequenceiq.cloudbreak.cloud.template.compute.PreserveResourceException in project cloudbreak by hortonworks.
the class AwsVolumeResourceBuilder method delete.
@Override
public CloudResource delete(AwsContext context, AuthenticatedContext auth, CloudResource resource) throws PreserveResourceException {
LOGGER.debug("Set delete on termination to true, on instances");
VolumeSetAttributes volumeSetAttributes = resource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class);
List<CloudResourceStatus> cloudResourceStatuses = checkResources(ResourceType.AWS_VOLUMESET, context, auth, List.of(resource));
boolean anyDeleted = cloudResourceStatuses.stream().map(CloudResourceStatus::getStatus).anyMatch(DELETED::equals);
if (!volumeSetAttributes.getDeleteOnTermination() && !anyDeleted) {
LOGGER.debug("Volumes will be preserved.");
resource.setStatus(CommonStatus.DETACHED);
volumeSetAttributes.setDeleteOnTermination(Boolean.TRUE);
resource.putParameter(CloudResource.ATTRIBUTES, volumeSetAttributes);
resourceNotifier.notifyUpdate(resource, auth.getCloudContext());
throw new PreserveResourceException("Resource will be preserved for later reattachment.");
}
AmazonEc2Client client = getAmazonEC2Client(auth);
deleteOrphanedVolumes(cloudResourceStatuses, client);
turnOnDeleteOnterminationOnAttachedVolumes(resource, cloudResourceStatuses, client);
return null;
}
Aggregations