private ProgressEvent updateProxyEndpointAndUpdateProgress()

in aws-rds-dbproxyendpoint/src/main/java/software/amazon/rds/dbproxyendpoint/UpdateHandler.java [64:146]


    private ProgressEvent<ResourceModel, CallbackContext> updateProxyEndpointAndUpdateProgress(ResourceModel newModel,
                                                                                       ResourceModel oldModel,
                                                                                       CallbackContext callbackContext) {
        // This Lambda will continually be re-invoked with the current state of the proxyEndpoint, finally succeeding when state stabilizes.
        final DBProxyEndpoint proxyEndpointStateSoFar = callbackContext.getProxyEndpoint();

        if (callbackContext.getStabilizationRetriesRemaining() == 0) {
            throw new RuntimeException(TIMED_OUT_MESSAGE);
        }

        // Update proxyEndpoint settings
        if (proxyEndpointStateSoFar == null) {
            try {
                return Optional.ofNullable(validateModels(oldModel, newModel))
                        .orElseGet(() -> ProgressEvent.<ResourceModel, CallbackContext>builder()
                        .resourceModel(newModel)
                        .status(OperationStatus.IN_PROGRESS)
                        .callbackContext(CallbackContext.builder()
                                .proxyEndpoint(updateProxyEndpointSettings(oldModel, newModel))
                                .stabilizationRetriesRemaining(Constants.NUMBER_OF_STATE_POLL_RETRIES)
                                .build())
                        .build());
            } catch (DBProxyEndpointNotFoundException e) {
                return ProgressEvent.defaultFailureHandler(e, HandlerErrorCode.NotFound);
            }
        }

        // Update tags
        if (!callbackContext.isTagsDeregistered()) {
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                    .resourceModel(newModel)
                    .status(OperationStatus.IN_PROGRESS)
                    .callbackContext(CallbackContext.builder()
                            .proxyEndpoint(proxyEndpointStateSoFar)
                            .tagsDeregistered(deregisterOldTags(oldModel, newModel, proxyEndpointStateSoFar))
                            .stabilizationRetriesRemaining(Constants.NUMBER_OF_STATE_POLL_RETRIES)
                            .build())
                    .build();
        }

        if (!callbackContext.isTagsRegistered()) {
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                    .resourceModel(newModel)
                    .status(OperationStatus.IN_PROGRESS)
                    .callbackContext(CallbackContext.builder()
                            .proxyEndpoint(proxyEndpointStateSoFar)
                            .tagsDeregistered(callbackContext.isTagsDeregistered())
                            .tagsRegistered(registerNewTags(oldModel, newModel, proxyEndpointStateSoFar))
                            .stabilizationRetriesRemaining(Constants.NUMBER_OF_STATE_POLL_RETRIES)
                            .build())
                    .build();
        }

        if (proxyEndpointStateSoFar.getStatus().equals(Constants.AVAILABLE_ENDPOINT_STATE)) {
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                    .resourceModel(newModel)
                    .status(OperationStatus.SUCCESS)
                    .build();
        } else if (Constants.TERMINAL_FAILURE_STATES.contains(proxyEndpointStateSoFar.getStatus())) {
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                    .status(OperationStatus.FAILED)
                    .errorCode(HandlerErrorCode.NotFound)
                    .build();
        } else {
            try {
                Thread.sleep(Constants.POLL_RETRY_DELAY_IN_MS);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            DBProxyEndpoint proxyEndpoint = updatedProxyEndpointProgress(proxyEndpointStateSoFar.getDBProxyEndpointName());
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                    .resourceModel(newModel)
                    .status(OperationStatus.IN_PROGRESS)
                    .callbackContext(CallbackContext.builder()
                            .tagsDeregistered(callbackContext.isTagsDeregistered())
                            .tagsRegistered(callbackContext.isTagsRegistered())
                            .proxyEndpoint(proxyEndpoint)
                            .stabilizationRetriesRemaining(callbackContext.getStabilizationRetriesRemaining() - 1)
                            .build())
                    .build();
        }
    }