in aws-batch-schedulingpolicy/src/main/java/software/amazon/batch/schedulingpolicy/TagUtils.java [26:55]
static void handleTagging(
final ResourceModel model,
final Map<String, String> desiredResourceTags,
final Map<String, String> previousResourceTags,
final AmazonWebServicesClientProxy proxy,
final BatchClient client,
final Logger logger) {
final Map<String, String> tagsToRemove = getTagsToDelete(desiredResourceTags, previousResourceTags);
final Map<String, String> tagsToAdd = getTagsToCreate(desiredResourceTags, previousResourceTags);
final List<String> tagKeysToRemove = new ArrayList<>(tagsToRemove.keySet());
// Deletes tags only if tagsToRemove is not empty.
if (!tagKeysToRemove.isEmpty()) {
logger.log(String.format("Tags to remove for %s are %s", model.getArn(), tagKeysToRemove));
UntagResourceResponse untagResourceResponse = proxy.injectCredentialsAndInvokeV2(
Translator.toUntagResourceRequest(model, tagKeysToRemove),
client::untagResource);
logger.log(String.format("Untag API result for %s is %s", model.getArn(), untagResourceResponse));
}
// Adds tags only if tagsToAdd is not empty.
if (!tagsToAdd.isEmpty()) {
logger.log(String.format("Tags to add for %s are %s", model.getArn(), tagsToAdd));
TagResourceResponse tagResourceResponse = proxy.injectCredentialsAndInvokeV2(
Translator.toTagResourceRequest(model, tagsToAdd),
client::tagResource);
logger.log(String.format("Tag API result for %s is %s", model.getArn(), tagResourceResponse));
}
}