in aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/BaseHandlerStd.java [277:344]
protected ProgressEvent<ResourceModel, CallbackContext> tagResource(
final AmazonWebServicesClientProxy proxy,
final ProxyClient<RdsClient> proxyClient,
final ProgressEvent<ResourceModel, CallbackContext> progress,
final Collection<Tag> previousTags,
final Collection<Tag> desiredTags
) {
final Set<Tag> tagsToAdd = new HashSet<>(desiredTags);
final Set<Tag> tagsToRemove = new HashSet<>(previousTags);
tagsToAdd.removeAll(previousTags);
tagsToRemove.removeAll(desiredTags);
if (tagsToAdd.isEmpty() && tagsToRemove.isEmpty()) {
return progress;
}
try {
final DBCluster dbCluster = fetchDBCluster(proxyClient, progress.getResourceModel());
final String arn = dbCluster.dbClusterArn();
proxyClient.injectCredentialsAndInvokeV2(
removeTagsFromResourceRequest(arn, tagsToRemove),
proxyClient.client()::removeTagsFromResource
);
proxyClient.injectCredentialsAndInvokeV2(
addTagsToResourceRequest(arn, tagsToAdd),
proxyClient.client()::addTagsToResource
);
} catch (Exception exception) {
return Commons.handleException(progress, exception, DEFAULT_DB_CLUSTER_ERROR_RULE_SET);
}
return progress;
/*
return proxy.initiate("rds::tag-dbcluster", proxyClient, progress.getResourceModel(), progress.getCallbackContext())
.translateToServiceRequest(Translator::describeDbClustersRequest)
.makeServiceCall((describeRequest, rdsClientProxyClient) -> rdsClientProxyClient.injectCredentialsAndInvokeV2(
describeRequest,
rdsClientProxyClient.client()::describeDBClusters
))
.handleError((describeRequest, exception, client, model, context) -> Commons.handleException(
ProgressEvent.progress(model, context),
exception,
DEFAULT_DB_CLUSTER_ERROR_RULE_SET
))
.done((describeRequest, describeResponse, rdsClientProxyClient, resourceModel, context) -> {
final DBCluster dbCluster = describeResponse.dbClusters().stream().findFirst().get();
final String arn = dbCluster.dbClusterArn();
final Set<Tag> currentTags = Optional.ofNullable(resourceModel.getTags()).orElse(Collections.emptySet());
final Set<Tag> existingTags = Translator.translateTagsFromSdk(dbCluster.tagList());
final Set<Tag> tagsToRemove = Sets.difference(existingTags, currentTags);
final Set<Tag> tagsToAdd = Sets.difference(currentTags, existingTags);
rdsClientProxyClient.injectCredentialsAndInvokeV2(
removeTagsFromResourceRequest(arn, tagsToRemove),
rdsClientProxyClient.client()::removeTagsFromResource
);
rdsClientProxyClient.injectCredentialsAndInvokeV2(
addTagsToResourceRequest(arn, tagsToAdd),
rdsClientProxyClient.client()::addTagsToResource
);
return ProgressEvent.progress(resourceModel, context);
});
*/
}