From 23882f2d097fc9891dba0c9fb0445cc564437782 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Tue, 30 Apr 2024 08:11:17 +0200 Subject: [PATCH] Fail when there are 2+ Trino announcements --- .../src/main/java/io/trino/server/Server.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/server/Server.java b/core/trino-main/src/main/java/io/trino/server/Server.java index 68ff9d8040f8..58deacb9b453 100644 --- a/core/trino-main/src/main/java/io/trino/server/Server.java +++ b/core/trino-main/src/main/java/io/trino/server/Server.java @@ -77,6 +77,7 @@ import java.util.Optional; import java.util.Set; +import static com.google.common.collect.MoreCollectors.toOptional; import static io.airlift.discovery.client.ServiceAnnouncement.ServiceAnnouncementBuilder; import static io.airlift.discovery.client.ServiceAnnouncement.serviceAnnouncement; import static io.trino.server.TrinoSystemRequirements.verifyJvmRequirements; @@ -268,12 +269,10 @@ private static void updateConnectorIds(Announcer announcer, CatalogManager catal private static ServiceAnnouncement getTrinoAnnouncement(Set announcements) { - for (ServiceAnnouncement announcement : announcements) { - if (announcement.getType().equals("trino")) { - return announcement; - } - } - throw new IllegalArgumentException("Trino announcement not found: " + announcements); + return announcements.stream() + .filter(announcement -> announcement.getType().equals("trino")) + .collect(toOptional()) + .orElseThrow(() -> new IllegalArgumentException("Trino announcement not found: " + announcements)); } private static void logLocation(Logger log, String name, Path path)