in aws-wafv2-webaclassociation/src/main/java/com/amazonaws/wafv2/webaclassociation/CreateHandler.java [28:84]
public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
final AmazonWebServicesClientProxy proxy,
final ResourceHandlerRequest<ResourceModel> request,
final CallbackContext callbackContext,
final Logger logger) {
final ResourceModel model = request.getDesiredResourceState();
final CallbackContext currentContext = callbackContext == null ?
CallbackContext.builder()
.stabilizationRetriesRemaining(CommonVariables.NUMBER_OF_STATE_POLL_RETRIES)
.build()
: callbackContext;
log(logger, model, "retries left: " + currentContext.getStabilizationRetriesRemaining());
if (currentContext.getStabilizationRetriesRemaining() <= 0) {
log(logger, model, "no more retries remaining");
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.status(OperationStatus.FAILED)
.errorCode(HandlerErrorCode.NotStabilized)
.build();
}
try {
associateWebACLExceptionWrapper(proxy, model).execute();
log(logger, model, "created successfully");
// propogate input values to make CFN happy, since these two make up the resource primary key.
final ResourceModel result = ResourceModel.builder()
.resourceArn(model.getResourceArn())
.webACLArn(model.getWebACLArn())
.build();
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.resourceModel(result)
.status(OperationStatus.SUCCESS)
.build();
} catch (WafUnavailableEntityException e) {
int retryLeft = currentContext.getStabilizationRetriesRemaining() - 1;
int delaySeconds = CommonVariables.CALLBACK_DELAY_SECONDS;
String message = String.format("WafUnavailableEntityException: %s Retryleft: %d NextDelay: %d",
e.getMessage(), retryLeft, delaySeconds);
log(logger, model, message);
// WebACL still being sequenced
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.resourceModel(model)
.status(OperationStatus.IN_PROGRESS)
.callbackContext(CallbackContext.builder()
.stabilizationRetriesRemaining(retryLeft)
.build())
.callbackDelaySeconds(delaySeconds)
.build();
} catch (RuntimeException e) {
log(logger, model, String.format("[%s]: %s", e.getClass().getSimpleName(), e.getMessage()));
// handle error code
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.status(OperationStatus.FAILED)
.errorCode(ExceptionTranslationWrapper.translateExceptionIntoErrorCode(e))
.message(e.getMessage())
.build();
}
}