in aws-ssmincidents-replicationset/src/main/java/software/amazon/ssmincidents/replicationset/BaseHandlerStd.java [101:171]
protected abstract ProgressEvent<ResourceModel, CallbackContext> handleRequest(
AmazonWebServicesClientProxy proxy,
ResourceHandlerRequest<ResourceModel> request,
CallbackContext callbackContext,
ProxyClient<SsmIncidentsClient> proxyClient,
Logger logger
);
protected Function<ProgressEvent<ResourceModel, CallbackContext>, ProgressEvent<ResourceModel, CallbackContext>> waitForReplicationSetToBecomeActive(
ProxyClient<SsmIncidentsClient> proxyClient,
boolean notFoundIsOkay,
boolean beforeMainCall,
Logger logger,
String timeoutMessage
) {
return progress -> {
CallbackContext context = progress.getCallbackContext();
ResourceModel model = progress.getResourceModel();
// skip if await should be completed before main API call
// and the main API call has already be done
if (beforeMainCall & context.mainAPICalled()) {
logger.log("waitForReplicationSetToBecomeActive: beforeMainCall requested, but main call was made already. Skipping.");
return progress;
}
if (context.getAwaitRetryAttemptsRemaining() == null) {
logger.log("waitForReplicationSetToBecomeActive: setting attempts to " + INITIAL_AWAIT_COUNT);
context.setAwaitRetryAttemptsRemaining(INITIAL_AWAIT_COUNT);
}
try {
GetReplicationSetRequest awsRequest = Translator.translateToReadRequest(progress.getResourceModel());
GetReplicationSetResponse awsResponse = proxyClient.injectCredentialsAndInvokeV2(
awsRequest,
proxyClient.client()::getReplicationSet
);
ReplicationSetStatus status = awsResponse.replicationSet().status();
logger.log("waitForReplicationSetToBecomeActive: replicationSet status = " + status.name());
if (status == ReplicationSetStatus.ACTIVE) {
logger.log("waitForReplicationSetToBecomeActive: removing remaining attempts");
context.setAwaitRetryAttemptsRemaining(null);
return ProgressEvent.defaultInProgressHandler(context, 0, model);
}
if (status == ReplicationSetStatus.FAILED) {
logger.log("waitForReplicationSetToBecomeActive: replication set failed");
return ProgressEvent.defaultFailureHandler(
new RuntimeException("Replication Set creation failed"),
HandlerErrorCode.NotStabilized
);
}
context.setAwaitRetryAttemptsRemaining(context.getAwaitRetryAttemptsRemaining() - 1);
logger.log("waitForReplicationSetToBecomeActive: decremented remaining attempt count to " +
context.getAwaitRetryAttemptsRemaining());
if (context.getAwaitRetryAttemptsRemaining() <= 0) {
logger.log("waitForReplicationSetToBecomeActive: timed out waiting for replication set to become active");
return ProgressEvent.defaultFailureHandler(
new RuntimeException(timeoutMessage),
HandlerErrorCode.NotStabilized
);
}
logger.log("waitForReplicationSetToBecomeActive: Returning delay in seconds = " + RETRY_DELAY_SECONDS);
return ProgressEvent.defaultInProgressHandler(context, RETRY_DELAY_SECONDS, model);
} catch (ResourceNotFoundException e) {
if (notFoundIsOkay) {
logger.log("waitForReplicationSetToBecomeActive: replication set not found and it's okay, continuing.");
return ProgressEvent.defaultInProgressHandler(progress.getCallbackContext(), 0, progress.getResourceModel());
}
return ProgressEvent.defaultFailureHandler(e, HandlerErrorCode.NotFound);
} catch (Exception exception) {
return ProgressEvent.defaultFailureHandler(exception, HandlerErrorCode.GeneralServiceException);
}
};
}