protected ProgressEvent handleRequest()

in aws-codeartifact-domain/src/main/java/software/amazon/codeartifact/domain/DeleteHandler.java [18:60]


    protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
        final AmazonWebServicesClientProxy proxy,
        final ResourceHandlerRequest<ResourceModel> request,
        final CallbackContext callbackContext,
        final ProxyClient<CodeartifactClient> proxyClient,
        final Logger logger) {

        this.logger = logger;
        ResourceModel model = request.getDesiredResourceState();
        // STEP 1.0 [initialize a proxy context]
        return proxy.initiate("AWS-CodeArtifact-Domain::Delete", proxyClient, model, callbackContext)
            // STEP 1.1 [construct a body of a request]
            .translateToServiceRequest(Translator::translateToDeleteRequest)
            // STEP 1.2 [make an api call]
            .makeServiceCall((awsRequest, client) -> {

                // if domain does not exist, deleteDomain does not throw an exception, so we must do this
                // to be under the ResourceHandler Contract
                if (!doesDomainExist(model, proxyClient)) {
                    throw new CfnNotFoundException(model.getDomainName(), ResourceModel.TYPE_NAME);
                }

                AwsResponse awsResponse = null;
                try {
                    awsResponse = client.injectCredentialsAndInvokeV2(awsRequest, proxyClient.client()::deleteDomain);
                } catch (final ConflictException e) {
                    // We are not wrapping in CfnResourceConflictException because this case is a result of domain
                    // deletion failing because there are repositories in the account. CfnResourceConflictException
                    // retries until it logs an internal service exception, so we rather just fast fail in this case.
                    throw new CfnInvalidRequestException(e);
                } catch (final AwsServiceException e) {
                    String domainName = model.getDomainName();
                    Translator.throwCfnException(e, Constants.DELETE_DOMAIN, domainName);
                }

                logger.log(String.format("%s successfully deleted.", ResourceModel.TYPE_NAME));
                return awsResponse;
            })
            // STEP 2.3 [Stabilize to check if the resource got deleted]
            .stabilize((deleteDomainRequest, deleteDomainResponse, proxyInvocation, resourceModel, context) -> !doesDomainExist(model, proxyClient))
            // according to the ResourceHandler contract we must not return the model in the response
            .done((awsRequest, response, client, resourceModel, context) -> ProgressEvent.success(null, context));
    }