From 9fcf72217d90c0fd383c06dfa5004d1f546f591c Mon Sep 17 00:00:00 2001 From: Clement Escoffier Date: Thu, 24 Feb 2022 13:29:48 +0100 Subject: [PATCH] remove-stork-config-helper --- .../stork/impl/config/StorkConfigHelper.java | 65 ------------------- .../consul/ConsulServiceDiscovery.java | 13 +++- 2 files changed, 10 insertions(+), 68 deletions(-) delete mode 100644 core/src/main/java/io/smallrye/stork/impl/config/StorkConfigHelper.java diff --git a/core/src/main/java/io/smallrye/stork/impl/config/StorkConfigHelper.java b/core/src/main/java/io/smallrye/stork/impl/config/StorkConfigHelper.java deleted file mode 100644 index 1a786ead..00000000 --- a/core/src/main/java/io/smallrye/stork/impl/config/StorkConfigHelper.java +++ /dev/null @@ -1,65 +0,0 @@ -package io.smallrye.stork.impl.config; - -import java.util.NoSuchElementException; -import java.util.Optional; - -import io.smallrye.stork.api.config.ServiceDiscoveryConfig; - -public class StorkConfigHelper { - - private StorkConfigHelper() { - // Avoid direct instantiation - } - - public static Optional get(ServiceDiscoveryConfig config, String name) { - return Optional.ofNullable(config.parameters().get(name)); - } - - public static String getOrDefault(ServiceDiscoveryConfig config, String name, String def) { - String val = config.parameters().get(name); - if (val == null) { - return def; - } - return val; - } - - public static int getIntegerOrDefault(String sn, ServiceDiscoveryConfig config, String name, int def) { - String v = config.parameters().get(name); - if (v == null) { - return def; - } - try { - return Integer.parseInt(v); - } catch (NumberFormatException e) { - throw new IllegalArgumentException("Unable to parse the property `" + name - + "` to int from the service discovery configuration for service '" + sn + "'", e); - } - } - - public static Integer getInteger(String sn, String propertyName, String value) { - try { - return Integer.parseInt(value); - } catch (NumberFormatException e) { - throw new IllegalArgumentException("Unable to parse the property `" + propertyName - + "` to int from the service discovery configuration for service '" + sn + "'", e); - } - } - - public static boolean getBooleanOrDefault(ServiceDiscoveryConfig config, String name, boolean def) { - String v = config.parameters().get(name); - if (v == null) { - return def; - } - return Boolean.parseBoolean(v); - - } - - public static String getOrDie(String sn, ServiceDiscoveryConfig config, String name) { - String val = config.parameters().get(name); - if (val == null) { - throw new NoSuchElementException( - "`" + name + "` must be set in the service discovery configuration for service '" + sn + "'"); - } - return val; - } -} diff --git a/service-discovery/consul/src/main/java/io/smallrye/stork/servicediscovery/consul/ConsulServiceDiscovery.java b/service-discovery/consul/src/main/java/io/smallrye/stork/servicediscovery/consul/ConsulServiceDiscovery.java index 52f1eeb4..c17adbe0 100644 --- a/service-discovery/consul/src/main/java/io/smallrye/stork/servicediscovery/consul/ConsulServiceDiscovery.java +++ b/service-discovery/consul/src/main/java/io/smallrye/stork/servicediscovery/consul/ConsulServiceDiscovery.java @@ -1,6 +1,5 @@ package io.smallrye.stork.servicediscovery.consul; -import static io.smallrye.stork.impl.config.StorkConfigHelper.getInteger; import static io.smallrye.stork.servicediscovery.consul.ConsulMetadataKey.META_CONSUL_SERVICE_ID; import static io.smallrye.stork.servicediscovery.consul.ConsulMetadataKey.META_CONSUL_SERVICE_NODE; import static io.smallrye.stork.servicediscovery.consul.ConsulMetadataKey.META_CONSUL_SERVICE_NODE_ADDRESS; @@ -41,11 +40,10 @@ public ConsulServiceDiscovery(String serviceName, ConsulServiceDiscoveryProvider // TODO: more validation ConsulClientOptions options = new ConsulClientOptions(); options.setHost(config.getConsulHost()); - options.setPort(getInteger(serviceName, "consul-port", config.getConsulPort())); + options.setPort(getPort(serviceName, config.getConsulPort())); passing = Boolean.parseBoolean(config.getUseHealthChecks()); this.application = config.getApplication() == null ? serviceName : config.getApplication(); client = ConsulClient.create(vertx, options); - } @Override @@ -102,4 +100,13 @@ private Metadata createConsulMetadata(ServiceEntry service) { } return consulMetadata; } + + private static Integer getPort(String name, String value) { + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Unable to parse the property `consul-port` to an integer from the " + + "service discovery configuration for service '" + name + "'", e); + } + } }