protected ProgressEvent handleRequest()

in aws-mwaa-environment/src/main/java/software/amazon/mwaa/environment/UpdateHandler.java [43:103]


    protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
            final Proxies proxies,
            final ResourceHandlerRequest<ResourceModel> request,
            final CallbackContext callbackContext) {

        final ResourceModel model = request.getDesiredResourceState();
        if (callbackContext.isStabilizing()) {
            log("callback context indicates Stabilizing mode");
            final Optional<EnvironmentStatus> status = getEnvironmentStatus(
                    proxies.getMwaaClientProxy(),
                    model.getName());

            final Optional<UpdateError> lastUpdateError = getLastUpdateError(
                    proxies.getMwaaClientProxy(),
                    model.getName());
            String errorMessage = lastUpdateError.map(UpdateError::errorMessage).orElse("");

            if (!status.isPresent()) {
                log("Environment not found, failing update");
                return ProgressEvent.failed(
                        model,
                        null,
                        HandlerErrorCode.NotStabilized,
                        "Update failed, resource no longer exists");
            }

            if (status.get() == EnvironmentStatus.AVAILABLE) {
                log("status is AVAILABLE, returning success");
                return ProgressEvent.progress(model, callbackContext).then(
                        progress -> getEnvironmentDetails("Update::PostUpdateRead", proxies, progress));
            }

            if (status.get() == EnvironmentStatus.UPDATE_FAILED) {
                log("status is UPDATE_FAILED, returning failure");
                return ProgressEvent.failed(
                        model,
                        null,
                        HandlerErrorCode.NotStabilized,
                        String.format("Update failed. %s", errorMessage));
            }
            if (status.get() == EnvironmentStatus.UNAVAILABLE) {
                log("status is UNAVAILABLE, returning failure");
                return ProgressEvent.failed(
                        model,
                        null,
                        HandlerErrorCode.NotStabilized,
                        String.format("Update failed, Environment unavailable. %s", errorMessage));
            }

            log("status is %s, requesting a callback in %s", status, CALLBACK_DELAY);
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                    .resourceModel(model)
                    .callbackContext(callbackContext)
                    .callbackDelaySeconds((int) CALLBACK_DELAY.getSeconds())
                    .status(OperationStatus.IN_PROGRESS)
                    .build();
        }

        return ProgressEvent.progress(model, callbackContext)
                .then(progress -> startUpdateTask(proxies, progress, callbackContext));
    }