From a8ec59eb75c4113733cc615263ed8333d09be9a1 Mon Sep 17 00:00:00 2001 From: Viktor Lofgren Date: Wed, 28 Feb 2024 12:09:01 +0100 Subject: [PATCH] (conf) Add migration warning when ZOOKEEPER_HOSTS is not set. --- .../service/ServiceDiscoveryModule.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/code/common/service-discovery/java/nu/marginalia/service/ServiceDiscoveryModule.java b/code/common/service-discovery/java/nu/marginalia/service/ServiceDiscoveryModule.java index cc783c72..6daa084c 100644 --- a/code/common/service-discovery/java/nu/marginalia/service/ServiceDiscoveryModule.java +++ b/code/common/service-discovery/java/nu/marginalia/service/ServiceDiscoveryModule.java @@ -17,7 +17,7 @@ public class ServiceDiscoveryModule extends AbstractModule { private static final Logger logger = LoggerFactory.getLogger(ServiceDiscoveryModule.class); public void configure() { - var hosts = getZookeeperHosts().orElseThrow(() -> new IllegalStateException("Zookeeper hosts not set")); + var hosts = getZookeeperHosts(); logger.info("Using Zookeeper service registry at {}", hosts); CuratorFramework client = CuratorFrameworkFactory .newClient(hosts, new ExponentialBackoffRetry(100, 10, 1000)); @@ -26,11 +26,21 @@ public class ServiceDiscoveryModule extends AbstractModule { bind(ServiceRegistryIf.class).to(ZkServiceRegistry.class); } - private Optional getZookeeperHosts() { + private String getZookeeperHosts() { if (System.getProperty("zookeeper-hosts") != null) { - return Optional.of(System.getProperty("zookeeper-hosts")); + return System.getProperty("zookeeper-hosts"); } - return Optional.ofNullable(System.getenv("ZOOKEEPER_HOSTS")); + String env = System.getenv("ZOOKEEPER_HOSTS"); + if (null == env) { + System.err.println(""" + ZOOKEEPER_HOSTS not set. This probably means that you are running an old installation, + or that the environment is not set up correctly. + + See the 2024-03+ migration notes, https://docs.marginalia.nu/6_notes/6_1__migrate_2024_03_plus + + """); + } + return env; } }