in workgroup/src/main/java/software/amazon/athena/workgroup/UpdateHandler.java [55:99]
private UpdateWorkGroupResponse updateWorkgroup(final ResourceModel model) {
final UpdateWorkGroupRequest updateWorkGroupRequest = UpdateWorkGroupRequest.builder()
.workGroup(model.getName())
.description(model.getDescription())
.state(model.getState())
.configurationUpdates(model.getWorkGroupConfigurationUpdates() != null ?
translator.createSdkConfigurationUpdatesFromCfnConfigurationUpdates(model.getWorkGroupConfigurationUpdates()) : null)
.build();
final ResourceModel oldModel = request.getPreviousResourceState();
final Set<Tag> oldTags = (oldModel == null || oldModel.getTags() == null) ?
new HashSet<>() : new HashSet<>(translator.createSdkTagsFromCfnTags(oldModel.getTags()));
final Set<Tag> newTags = model.getTags() == null ?
new HashSet<>() : new HashSet<>(translator.createSdkTagsFromCfnTags(model.getTags()));
try {
// Handle modifications to WorkGroup tags
if (!oldTags.equals(newTags)) {
String workGroupARN = getWorkGroupArn(request, model.getName());
// {old tags} - {new tags} = {tags to remove}
Set<Tag> tagsToRemove = Sets.difference(oldTags, newTags);
if (!tagsToRemove.isEmpty()) {
UntagResourceRequest untagResourceRequest = UntagResourceRequest.builder()
.resourceARN(workGroupARN)
.tagKeys(tagsToRemove.stream().map(Tag::key).collect(Collectors.toList()))
.build();
clientProxy.injectCredentialsAndInvokeV2(untagResourceRequest, athenaClient::untagResource);
}
// {new tags} - {old tags} = {tags to add}
Set<Tag> tagsToAdd = Sets.difference(newTags, oldTags);
if (!tagsToAdd.isEmpty()) {
TagResourceRequest tagResourceRequest = TagResourceRequest.builder()
.resourceARN(workGroupARN)
.tags(tagsToAdd)
.build();
clientProxy.injectCredentialsAndInvokeV2(tagResourceRequest, athenaClient::tagResource);
}
}
// Handle modifications to WorkGroup configuration
return clientProxy.injectCredentialsAndInvokeV2(updateWorkGroupRequest, athenaClient::updateWorkGroup);
} catch (AthenaException e) {
throw translateAthenaException(e, model.getName());
}
}