Skip to content

Commit

Permalink
add tagging parameter for createGlobalCluster
Browse files Browse the repository at this point in the history
  • Loading branch information
akwan224 committed Jan 17, 2025
1 parent 97cc3cf commit c66b08e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ protected ProgressEvent<ResourceModel, CallbackContext> removeFromGlobalCluster(

protected ProgressEvent<ResourceModel, CallbackContext> createGlobalClusterWithSourceDBCluster(final AmazonWebServicesClientProxy proxy,
final ProxyClient<RdsClient> proxyClient,
final ProgressEvent<ResourceModel, CallbackContext> progress) {
final ProgressEvent<ResourceModel, CallbackContext> progress,
final Tagging.TagSet tagSet) {

if(progress.getCallbackContext().isGlobalClusterCreated()) return progress;
//check if sourceDbCluster is not null and is in format of Identifier
Expand All @@ -199,7 +200,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> createGlobalClusterWithS
.done((describeDbClusterRequest, describeDbClusterResponse, proxyClient2, resourceModel, callbackContext) -> {
final String arn = describeDbClusterResponse.dbClusters().get(0).dbClusterArn();
try {
proxyClient2.injectCredentialsAndInvokeV2(Translator.createGlobalClusterRequest(resourceModel, arn, Tagging.TagSet.emptySet()), proxyClient2.client()::createGlobalCluster);
proxyClient2.injectCredentialsAndInvokeV2(Translator.createGlobalClusterRequest(resourceModel, arn, tagSet), proxyClient2.client()::createGlobalCluster);
callbackContext.setGlobalClusterCreated(true);
} catch (GlobalClusterAlreadyExistsException e) {
throw new CfnAlreadyExistsException(e);
Expand All @@ -210,7 +211,8 @@ protected ProgressEvent<ResourceModel, CallbackContext> createGlobalClusterWithS

protected ProgressEvent<ResourceModel, CallbackContext> createGlobalCluster(final AmazonWebServicesClientProxy proxy,
final ProxyClient<RdsClient> proxyClient,
final ProgressEvent<ResourceModel, CallbackContext> progress) {
final ProgressEvent<ResourceModel, CallbackContext> progress,
final Tagging.TagSet tagSet) {

return proxy.initiate("rds::create-global-cluster", proxyClient, progress.getResourceModel(), progress.getCallbackContext())
// request to create global cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@

public class Translator {

<<<<<<< HEAD
static CreateGlobalClusterRequest createGlobalClusterRequest(final ResourceModel model) {
return createGlobalClusterRequest(model, null, Tagging.TagSet.emptySet());
=======
static CreateGlobalClusterRequest createGlobalClusterRequest(final ResourceModel model, final Tagging.TagSet tagSet) {
return createGlobalClusterRequest(model, null, tagSet);
>>>>>>> d618efc (add tagging parameter for createGlobalCluster)
}

static CreateGlobalClusterRequest createGlobalClusterRequest(final ResourceModel model, String dbClusterArn, final Tagging.TagSet tagSet) {
Expand Down Expand Up @@ -86,4 +91,16 @@ static DescribeDbClustersRequest describeDbClustersRequest(final ResourceModel m
.dbClusterIdentifier(model.getSourceDBClusterIdentifier())
.build();
}

static Set<software.amazon.awssdk.services.rds.model.Tag> translateTagsToSdk(
final Collection<Tag> tags
) {
return Optional.ofNullable(tags).orElse(Collections.emptySet())
.stream()
.map(tag -> software.amazon.awssdk.services.rds.model.Tag.builder()
.key(tag.getKey())
.value(tag.getValue())
.build())
.collect(Collectors.toSet());
}
}

0 comments on commit c66b08e

Please sign in to comment.