diff options
author | Valerij Fredriksen <valerijf@yahooinc.com> | 2023-01-09 15:17:28 +0100 |
---|---|---|
committer | Valerij Fredriksen <valerijf@yahooinc.com> | 2023-01-09 15:17:28 +0100 |
commit | d156ffb11de972c2fb0817d97151dbd185cccb6c (patch) | |
tree | 70b43fc1b3629f7a2d279ec5e2c0aa6ec7de1945 /controller-server | |
parent | baf54beef9119768f99d41d950373f742a42df62 (diff) |
Avoid duplicate reindexing notification
Diffstat (limited to 'controller-server')
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notification/NotificationsDb.java | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notification/NotificationsDb.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notification/NotificationsDb.java index cc84e012960..f8505775d26 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notification/NotificationsDb.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notification/NotificationsDb.java @@ -53,7 +53,7 @@ public class NotificationsDb { public List<Notification> listNotifications(NotificationSource source, boolean productionOnly) { return curatorDb.readNotifications(source.tenant()).stream() .filter(notification -> source.contains(notification.source()) && (!productionOnly || notification.source().isProduction())) - .collect(Collectors.toUnmodifiableList()); + .toList(); } public void setNotification(NotificationSource source, Type type, Level level, String message) { @@ -87,7 +87,7 @@ public class NotificationsDb { List<Notification> initial = curatorDb.readNotifications(source.tenant()); List<Notification> filtered = initial.stream() .filter(notification -> !source.equals(notification.source()) || type != notification.type()) - .collect(Collectors.toUnmodifiableList()); + .toList(); if (initial.size() > filtered.size()) curatorDb.writeNotifications(source.tenant(), filtered); } @@ -104,7 +104,7 @@ public class NotificationsDb { List<Notification> initial = curatorDb.readNotifications(source.tenant()); List<Notification> filtered = initial.stream() .filter(notification -> !source.contains(notification.source())) - .collect(Collectors.toUnmodifiableList()); + .toList(); if (initial.size() > filtered.size()) curatorDb.writeNotifications(source.tenant(), filtered); } @@ -121,13 +121,15 @@ public class NotificationsDb { public void setDeploymentMetricsNotifications(DeploymentId deploymentId, List<ClusterMetrics> clusterMetrics, ApplicationReindexing applicationReindexing) { Instant now = clock.instant(); List<Notification> changed = List.of(); - List<Notification> newNotifications = clusterMetrics.stream() - .flatMap(metric -> { + List<Notification> newNotifications = Stream.concat( + clusterMetrics.stream().map(metric -> { NotificationSource source = NotificationSource.from(deploymentId, ClusterSpec.Id.from(metric.getClusterId())); - Cluster cluster = applicationReindexing.clusters().getOrDefault(metric.getClusterId(), Cluster.EMPTY); - return Stream.of(createFeedBlockNotification(source, now, metric), - createReindexNotification(source, now, cluster)); - }) + return createFeedBlockNotification(source, now, metric); + }), + applicationReindexing.clusters().entrySet().stream().map(entry -> { + NotificationSource source = NotificationSource.from(deploymentId, ClusterSpec.Id.from(entry.getKey())); + return createReindexNotification(source, now, entry.getValue()); + })) .flatMap(Optional::stream) .toList(); |