private ProgressEvent updateProxyAndUpdateProgress()

in aws-rds-dbproxytargetgroup/src/main/java/software/amazon/rds/dbproxytargetgroup/UpdateHandler.java [56:132]


    private ProgressEvent<ResourceModel, CallbackContext> updateProxyAndUpdateProgress(ResourceModel newModel,
                                                                                       ResourceModel oldModel,
                                                                                       CallbackContext callbackContext) {
        // This Lambda will continually be re-invoked with the current state of the proxy, finally succeeding when state stabilizes.
        if (callbackContext.getStabilizationRetriesRemaining() == 0) {
            throw new RuntimeException(TIMED_OUT_MESSAGE);
        }

        // Update target-group settings
        if (callbackContext.getTargetGroupStatus() == null) {
            try {
                return ProgressEvent.<ResourceModel, CallbackContext>builder()
                        .resourceModel(newModel)
                        .status(OperationStatus.IN_PROGRESS)
                        .callbackContext(CallbackContext.builder()
                                .targetGroupStatus(modifyProxyTargetGroup(oldModel, newModel))
                                .stabilizationRetriesRemaining(Constants.NUMBER_OF_STATE_POLL_RETRIES)
                                .build())
                        .build();
            } catch (DBProxyTargetGroupNotFoundException e) {
                return ProgressEvent.defaultFailureHandler(e, HandlerErrorCode.NotFound);
            }
        }

        // Update registered databases
        if  (!callbackContext.isTargetsDeregistered()) {
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                           .resourceModel(newModel)
                           .status(OperationStatus.IN_PROGRESS)
                           .callbackContext(CallbackContext.builder()
                                                           .targetGroupStatus(callbackContext.getTargetGroupStatus())
                                                           .targetsDeregistered(deregisterOldTargets(oldModel, newModel))
                                                           .stabilizationRetriesRemaining(Constants.NUMBER_OF_STATE_POLL_RETRIES)
                                                           .build())
                           .build();
        }

        if (callbackContext.getTargets() == null) {
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                           .resourceModel(newModel)
                           .status(OperationStatus.IN_PROGRESS)
                           .callbackContext(CallbackContext.builder()
                                                           .targetGroupStatus(callbackContext.getTargetGroupStatus())
                                                           .targetsDeregistered(callbackContext.isTargetsDeregistered())
                                                           .targets(registerNewTargets(oldModel, newModel))
                                                           .stabilizationRetriesRemaining(Constants.NUMBER_OF_STATE_POLL_RETRIES)
                                                           .build())
                           .build();
        }

        if (!callbackContext.isAllTargetsHealthy()) {
            boolean allTargetsHealthy = checkTargetHealth(newModel);

            try {
                Thread.sleep(Constants.POLL_RETRY_DELAY_IN_MS);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                           .resourceModel(newModel)
                           .status(OperationStatus.IN_PROGRESS)
                           .callbackContext(CallbackContext.builder()
                               .targetGroupStatus(callbackContext.getTargetGroupStatus())
                               .targetsDeregistered(callbackContext.isTargetsDeregistered())
                               .targets(callbackContext.getTargets())
                               .stabilizationRetriesRemaining(callbackContext.getStabilizationRetriesRemaining() - 1)
                               .allTargetsHealthy(allTargetsHealthy)
                               .build())
                           .build();
        }

        return ProgressEvent.<ResourceModel, CallbackContext>builder()
                       .resourceModel(newModel)
                       .status(OperationStatus.SUCCESS)
                       .build();
    }