use of com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.DELETED in project cloudbreak by hortonworks.
the class AwsVolumeResourceBuilder method checkResources.
@Override
protected List<CloudResourceStatus> checkResources(ResourceType type, AwsContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
AmazonEc2Client client = getAmazonEC2Client(auth);
Pair<List<String>, List<CloudResource>> volumes = volumeResourceCollector.getVolumeIdsByVolumeResources(resources, resourceType(), volumeSetAttributes());
DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest(volumes.getFirst());
LOGGER.debug("Going to describe volume(s) with id(s): [{}]", String.join(",", describeVolumesRequest.getVolumeIds()));
AtomicReference<ResourceStatus> volumeSetStatus = new AtomicReference<>();
try {
DescribeVolumesResult result = client.describeVolumes(describeVolumesRequest);
volumeSetStatus.set(getResourceStatus(result));
} catch (AmazonEC2Exception e) {
if (!"InvalidVolume.NotFound".equals(e.getErrorCode())) {
throw e;
}
LOGGER.info("The volume doesn't need to be deleted as it does not exist on the provider side. Reason: {}", e.getMessage());
volumeSetStatus.set(DELETED);
}
LOGGER.debug("[{}] volume set status is {}", String.join(",", volumes.getFirst()), volumeSetStatus);
return volumes.getSecond().stream().map(resource -> new CloudResourceStatus(resource, volumeSetStatus.get())).collect(Collectors.toList());
}
use of com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.DELETED in project cloudbreak by hortonworks.
the class MockResourceConnector method downscale.
@Override
public List<CloudResourceStatus> downscale(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources, List<CloudInstance> vms, Object resourcesToRemove) {
mockUrlFactory.get(authenticatedContext, "/spi/terminate_instances").post(Entity.entity(vms, MediaType.APPLICATION_JSON_TYPE), String.class);
List<String> instanceIdsToDownscale = new ArrayList<>();
for (CloudInstance vm : vms) {
instanceIdsToDownscale.add(vm.getInstanceId());
}
List<CloudResource> resourcesToDownscale = resources.stream().filter(resource -> instanceIdsToDownscale.contains(resource.getInstanceId())).collect(Collectors.toList());
resourcesToDownscale.forEach(r -> resourceNotifier.notifyDeletion(r, authenticatedContext.getCloudContext()));
return resourcesToDownscale.stream().map(r -> new CloudResourceStatus(r, DELETED)).collect(Collectors.toList());
}
use of com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.DELETED 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