in aws-rds-dbproxyendpoint/src/main/java/software/amazon/rds/dbproxyendpoint/CreateHandler.java [57:114]
private ProgressEvent<ResourceModel, CallbackContext> createProxyEndpointAndUpdateProgress(ResourceModel model,
CallbackContext callbackContext) {
// This Lambda will continually be re-invoked with the current state of the proxyEndpoint, finally succeeding when state stabilizes.
final DBProxyEndpoint endpointStateSoFar = callbackContext.getProxyEndpoint();
if (callbackContext.getStabilizationRetriesRemaining() == 0) {
throw new RuntimeException(TIMED_OUT_MESSAGE);
}
// first time
if (endpointStateSoFar == null) {
try {
return Optional.ofNullable(validateModel(model))
.orElseGet(() -> ProgressEvent.<ResourceModel, CallbackContext>builder()
.resourceModel(model)
.status(OperationStatus.IN_PROGRESS)
.callbackContext(CallbackContext.builder()
.proxyEndpoint(createProxyEndpoint(model))
.stabilizationRetriesRemaining(Constants.NUMBER_OF_STATE_POLL_RETRIES)
.build())
.build());
} catch (DBProxyEndpointAlreadyExistsException e) {
return ProgressEvent.defaultFailureHandler(e, HandlerErrorCode.AlreadyExists);
}
} else if (endpointStateSoFar.getStatus().equals(Constants.AVAILABLE_ENDPOINT_STATE)) {
model.setDBProxyEndpointArn(endpointStateSoFar.getDBProxyEndpointArn());
model.setEndpoint(endpointStateSoFar.getEndpoint());
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.resourceModel(model)
.status(OperationStatus.SUCCESS)
.build();
} else if (Constants.TERMINAL_FAILURE_STATES.contains(endpointStateSoFar.getStatus())) {
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.status(OperationStatus.FAILED)
.errorCode(HandlerErrorCode.NotFound)
.build();
} else {
model.setDBProxyEndpointArn(endpointStateSoFar.getDBProxyEndpointArn());
model.setEndpoint(endpointStateSoFar.getEndpoint());
try {
Thread.sleep(Constants.POLL_RETRY_DELAY_IN_MS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
DBProxyEndpoint proxyEndpoint = updatedProxyEndpointProgress(endpointStateSoFar.getDBProxyEndpointName());
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.resourceModel(model)
.status(OperationStatus.IN_PROGRESS)
.callbackContext(CallbackContext.builder()
.proxyEndpoint(proxyEndpoint)
.stabilizationRetriesRemaining(callbackContext.getStabilizationRetriesRemaining() - 1)
.build())
.build();
}
}