in aws-codeguruprofiler-profilinggroup/src/main/java/software/amazon/codeguruprofiler/profilinggroup/UpdateHandler.java [142:166]
private void updateNotificationChannels(List<Channel> currentChannels, List<Channel> requestedConfiguration, String pgName, AmazonWebServicesClientProxy proxy) {
Map<String, Channel> currentChannelsMap = currentChannels.stream().collect(Collectors.toMap(Channel::uri, Function.identity()));
Map<String, Channel> requestedConfigurationMap = requestedConfiguration.stream().collect(Collectors.toMap(Channel::uri, Function.identity()));
for (Channel currentChannel : currentChannels) {
if (!requestedConfigurationMap.containsKey(currentChannel.uri())) {
// Can assert that channel.id() exists here, since this is from an existingChannel, which is fetched via the GetNotificationConfiguration, which has the id attached
NotificationChannelHelper.deleteNotificationChannel(pgName, currentChannel.id(), proxy, profilerClient);
} else {
// check if there is an updated id, and if so then re-add the channel with the new id, else use the existing channel
Channel requestedChannel = requestedConfigurationMap.get(currentChannel.uri());
if (requestedChannel.id() != null && !currentChannel.id().equals(requestedChannel.id())) {
NotificationChannelHelper.updateChannelId(pgName, currentChannel.id(), requestedChannel, proxy, profilerClient);
// Remove to avoid unnecessary iterations below
requestedConfiguration.remove(requestedChannel);
}
}
}
for (Channel channel : requestedConfiguration) {
if (!currentChannelsMap.containsKey(channel.uri())) {
NotificationChannelHelper.addChannelNotification(pgName, channel, proxy, profilerClient);
}
}
}