protected ProgressEvent waitForStabilize()

in aws-memorydb-parametergroup/src/main/java/software/amazon/memorydb/parametergroup/UpdateHandler.java [114:155]


    protected ProgressEvent<ResourceModel, CallbackContext> waitForStabilize(final AmazonWebServicesClientProxy proxy,
                                                                             final ProxyClient<MemoryDbClient> proxyClient,
                                                                             final ProgressEvent<ResourceModel, CallbackContext> progress,
                                                                             final ResourceHandlerRequest<ResourceModel> request) {

        if (!isUpdateNeeded(request.getDesiredResourceState(), request.getPreviousResourceState())) {
            return progress; // if same params then skip stabilization
        }
        final CallbackContext cxt = progress.getCallbackContext();
        try {
            if (!cxt.isClusterStabilized()) { // if not stabilized then we keep describing clusters and memoizing the nextToken into the set

                final DescribeClustersResponse describeClustersResponse = proxyClient.injectCredentialsAndInvokeV2(Translator.translateToDescribeClustersRequest(cxt.getNextToken()), proxyClient.client()::describeClusters);

                List<Cluster> clusters = describeClustersResponse.clusters();
                if ((clusters == null) || (clusters != null && clusters.isEmpty())) {
                    cxt.setClusterStabilized(true);
                    return progress;
                }

                if (clusters.stream()
                        .filter(cluster -> cluster.parameterGroupName() != null // could be null when the cluster is in create-failed state
                                && cluster.parameterGroupStatus() != null // same as above
                                && cluster.parameterGroupName().equals(request.getDesiredResourceState().getParameterGroupName())) // all db clusters that use the param group
                        .allMatch(dbCluster -> STABILIZED_STATUS.equals(dbCluster.parameterGroupStatus()))) { // if all stabilized then move to the next page

                    if (describeClustersResponse.nextToken() != null) { // more pages left
                        cxt.setNextToken(describeClustersResponse.nextToken());
                        progress.setCallbackDelaySeconds(CALLBACK_DELAY); // if there are more to describe
                    } else { // nothing left to stabilized
                        cxt.setClusterStabilized(true);
                    }
                } else {
                    progress.setCallbackDelaySeconds(CALLBACK_DELAY); // if some still in transition status need some delay to describe
                }
            }
            progress.setCallbackContext(cxt);
            return progress;
        } catch (final Exception e) {
            throw new CfnGeneralServiceException(e);
        }
    }