in aws-lightsail-bucket/src/main/java/software/amazon/lightsail/bucket/helpers/handler/BucketHandler.java [175:205]
protected ProgressEvent<ResourceModel, CallbackContext> preDetachInstances(
final ProgressEvent<ResourceModel, CallbackContext> progress) {
val bucket = getBucket(resourceModelRequest, proxyClient, logger);
val instance = getInstance(resourceModelRequest, proxyClient, logger);
logger.log("Executing AWS-Lightsail-Bucket::Update::PreDetachInstances...");
return proxy
.initiate("AWS-Lightsail-Bucket::Update::PreDetachInstances", proxyClient, progress.getResourceModel(),
progress.getCallbackContext())
.translateToServiceRequest(Translator::translateToReadRequest).backoffDelay(BACKOFF_DELAY)
.makeServiceCall((awsRequest, client) -> {
// Just return empty Get Response. We are not making any service call here.
// We are making sure in the stabilize step that all instances that need to be detached are running.
return GetBucketsResponse.builder().build();
})
.stabilize((awsRequest, awsResponse, client, model, context) -> {
Set<String> desiredResources = resourceModelRequest.getDesiredResourceState().getResourcesReceivingAccess();
Set<String> currentResources = bucket.getCurrentResourceModelFromLightsail().getResourcesReceivingAccess();
Set<String> resourcesToRemove = bucket.setDifference(currentResources, desiredResources);
for (val resource: resourcesToRemove) {
if (!instance.isStabilized(resource)) {
return this.isStabilized(callbackContext, PRE_CHECK_DETACH);
}
}
return true;
})
.handleError((awsRequest, exception, client, model, context) -> handleError(exception, model,
callbackContext, ImmutableList.of(), logger, this.getClass().getSimpleName()))
.progress();
}