in aws-codeartifact-repository/src/main/java/software/amazon/codeartifact/repository/CreateHandler.java [60:96]
private ProgressEvent<ResourceModel, CallbackContext> createRepository(
AmazonWebServicesClientProxy proxy,
ResourceHandlerRequest<ResourceModel> request,
ProgressEvent<ResourceModel, CallbackContext> progress,
ProxyClient<CodeartifactClient> proxyClient
) {
CallbackContext callbackContext = progress.getCallbackContext();
if (callbackContext.isCreated()) {
// This happens when handler gets called again during callback delay or the handler is retrying for
// a Retriable exception after repository was created already. This will prevent 409s on retry.
// https://code.amazon.com/packages/AWSCloudFormationRPDKJavaPlugin/blobs/mainline/--/src/main/java/software/amazon/cloudformation/proxy/HandlerErrorCode.java
return ProgressEvent.progress(progress.getResourceModel(), callbackContext);
}
return proxy.initiate("AWS-CodeArtifact-Repository::Create", proxyClient, progress.getResourceModel(), callbackContext)
.translateToServiceRequest((model) -> Translator.translateToCreateRequest(model, request.getDesiredResourceTags()))
.makeServiceCall((awsRequest, client) -> {
AwsResponse awsResponse = null;
try {
awsResponse = client.injectCredentialsAndInvokeV2(awsRequest, client.client()::createRepository);
} catch (final AwsServiceException e) {
String repositoryName = progress.getResourceModel().getRepositoryName();
Translator.throwCfnException(e, Constants.CREATE_REPOSITORY, repositoryName);
}
logger.log(String.format("%s successfully created.", ResourceModel.TYPE_NAME));
callbackContext.setCreated(true);
return awsResponse;
})
.stabilize((awsRequest, awsResponse, client, model, context) -> isStabilized(model, client))
// This Callback delay will return IN_PROGRESS and wait a certain amount of seconds and then retry
// the whole CreateHandler chain. We are doing this to wait for eventual consistencies.
// Since we are setting the isCreated flag in the callback context
// the handler will not try to re-create the repository but will skip createRepository and continue down
// the chain.
.progress(CALLBACK_DELAY_SECONDS);
}