1 package org.onap.msb.apiroute.wrapper.consulextend;
3 import org.apache.http.HttpHost;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
7 import com.google.common.annotations.VisibleForTesting;
11 * Default Consul HTTP API host.
13 public static final String DEFAULT_HTTP_HOST = "localhost";
16 * Default Consul HTTP API port.
18 public static final int DEFAULT_HTTP_PORT = 8500;
20 private static final Logger LOGGER = LoggerFactory
21 .getLogger(Consul.class);
23 private final CatalogClient catalogClient;
24 private final HealthClient healthClient;
26 private Consul(CatalogClient catalogClient, HealthClient healthClient) {
27 this.catalogClient = catalogClient;
28 this.healthClient = healthClient;
32 * Get the Catalog HTTP client.
36 * @return The Catalog HTTP client.
38 public CatalogClient catalogClient() {
43 * Get the Health HTTP client.
47 * @return The Health HTTP client.
49 public HealthClient healthClient() {
54 * Creates a new {@link Builder} object.
56 * @return A new Consul builder.
58 public static Builder builder() {
63 * Used to create a default Consul client.
65 * @return A default {@link Consul} client.
68 public static Consul newClient() {
69 return builder().build();
72 public static class Builder {
74 private HttpHost targetHost;
77 targetHost = new HttpHost(DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT);
84 public Builder withHostAndPort(String hostname, int port) {
85 this.targetHost = new HttpHost(hostname, port);
89 public Consul build() {
90 LOGGER.info("********build consul:"+targetHost.toString()+"****************");
91 CatalogClient catalogClient = new CatalogClient(targetHost);
92 HealthClient healthClient = new HealthClient(targetHost);
93 return new Consul(catalogClient,healthClient);