private ProgressEvent createProxyAndUpdateProgress()

in aws-rds-dbproxy/src/main/java/software/amazon/rds/dbproxy/CreateHandler.java [49:112]


    private ProgressEvent<ResourceModel, CallbackContext> createProxyAndUpdateProgress(ResourceModel model,
                                                                                       CallbackContext callbackContext) {
        // This Lambda will continually be re-invoked with the current state of the proxy, finally succeeding when state stabilizes.
        final DBProxy proxyStateSoFar = callbackContext.getProxy();

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

        if (proxyStateSoFar == null) {
            try {
                return ProgressEvent.<ResourceModel, CallbackContext>builder()
                        .resourceModel(model)
                        .status(OperationStatus.IN_PROGRESS)
                        .callbackContext(CallbackContext.builder()
                                .proxy(createProxy(model))
                                .stabilizationRetriesRemaining(Constants.NUMBER_OF_STATE_POLL_RETRIES)
                                .build())
                        .build();
            } catch (DBProxyAlreadyExistsException e) {
                return ProgressEvent.defaultFailureHandler(e, HandlerErrorCode.AlreadyExists);
            }
        } else if (proxyStateSoFar.getStatus().equals(Constants.AVAILABLE_PROXY_STATE)) {
            model.setDBProxyArn(proxyStateSoFar.getDBProxyArn());
            model.setEndpoint(proxyStateSoFar.getEndpoint());
            model.setVpcId(proxyStateSoFar.getVpcId());
            model.setDebugLogging(proxyStateSoFar.getDebugLogging());
            model.setIdleClientTimeout(proxyStateSoFar.getIdleClientTimeout());
            model.setRequireTLS(proxyStateSoFar.getRequireTLS());

            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                           .resourceModel(model)
                           .status(OperationStatus.SUCCESS)
                           .build();
        } else if (Constants.TERMINAL_FAILURE_STATES.contains(proxyStateSoFar.getStatus())) {
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                           .status(OperationStatus.FAILED)
                           .errorCode(HandlerErrorCode.NotFound)
                           .build();
        } else {
            model.setDBProxyArn(proxyStateSoFar.getDBProxyArn());
            model.setEndpoint(proxyStateSoFar.getEndpoint());
            model.setVpcId(proxyStateSoFar.getVpcId());
            model.setDebugLogging(proxyStateSoFar.getDebugLogging());
            model.setIdleClientTimeout(proxyStateSoFar.getIdleClientTimeout());
            model.setRequireTLS(proxyStateSoFar.getRequireTLS());

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

            DBProxy proxy = updatedProxyProgress(proxyStateSoFar.getDBProxyName());
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                           .resourceModel(model)
                           .status(OperationStatus.IN_PROGRESS)
                           .callbackContext(CallbackContext.builder()
                                                           .proxy(proxy)
                                                           .stabilizationRetriesRemaining(callbackContext.getStabilizationRetriesRemaining() - 1)
                                                           .build())
                           .build();
        }
    }