From 32a4bb57a566dc08fe0212d22b6978c8c7aa18b8 Mon Sep 17 00:00:00 2001 From: Thomas Segismont Date: Tue, 12 May 2015 12:12:02 +0200 Subject: [PATCH 1/3] HWKMETRICS-84 Update ptrans to use tenant as a request header --- clients/ptranslator/ptrans.conf | 3 ++- .../src/assembly/dist/assets/ptrans.conf | 3 ++- .../metrics/clients/ptrans/Configuration.java | 12 ++++++++++- .../clients/ptrans/ConfigurationKey.java | 2 ++ .../ptrans/backend/RestForwardingHandler.java | 17 +++++++++------ .../backend/RestForwardingHandlerITest.java | 8 ++++--- .../ptrans/fullstack/CollectdITest.java | 21 ++++++++++++------- .../src/test/resources/ptrans.conf | 3 ++- 8 files changed, 48 insertions(+), 21 deletions(-) diff --git a/clients/ptranslator/ptrans.conf b/clients/ptranslator/ptrans.conf index 0f9f60ed6..6dd3380fe 100644 --- a/clients/ptranslator/ptrans.conf +++ b/clients/ptranslator/ptrans.conf @@ -41,7 +41,8 @@ statsd.port=8125 collectd.port=25826 # REST endpoint -rest.url=http://localhost:8080/hawkular/metrics/gauges/data?tenantId=test +rest.url=http://localhost:8080/hawkular/metrics/gauges/data +tenant=default # Close connection to rest-server after this many requests rest.close-after=200 diff --git a/clients/ptranslator/src/assembly/dist/assets/ptrans.conf b/clients/ptranslator/src/assembly/dist/assets/ptrans.conf index 0f9f60ed6..6dd3380fe 100644 --- a/clients/ptranslator/src/assembly/dist/assets/ptrans.conf +++ b/clients/ptranslator/src/assembly/dist/assets/ptrans.conf @@ -41,7 +41,8 @@ statsd.port=8125 collectd.port=25826 # REST endpoint -rest.url=http://localhost:8080/hawkular/metrics/gauges/data?tenantId=test +rest.url=http://localhost:8080/hawkular/metrics/gauges/data +tenant=default # Close connection to rest-server after this many requests rest.close-after=200 diff --git a/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/Configuration.java b/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/Configuration.java index b73d23922..ee9a1d30d 100644 --- a/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/Configuration.java +++ b/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/Configuration.java @@ -28,6 +28,7 @@ import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.SPOOL_SIZE; import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.STATSD_PORT; import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.TCP_PORT; +import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.TENANT; import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.UDP_PORT; import java.net.URI; @@ -59,6 +60,7 @@ public class Configuration { private final int minimumBatchSize; private final int maximumBatchDelay; private final URI restUrl; + private final String tenant; private final int restCloseAfterRequests; private final int spoolSize; private final Set validationMessages; @@ -75,6 +77,7 @@ private Configuration( int minimumBatchSize, int maximumBatchDelay, URI restUrl, + String tenant, int restCloseAfterRequests, int spoolSize, Set validationMessages @@ -90,6 +93,7 @@ private Configuration( this.minimumBatchSize = minimumBatchSize; this.maximumBatchDelay = maximumBatchDelay; this.restUrl = restUrl; + this.tenant = tenant; this.restCloseAfterRequests = restCloseAfterRequests; this.spoolSize = spoolSize; this.validationMessages = Collections.unmodifiableSet(validationMessages); @@ -108,7 +112,8 @@ public static Configuration from(Properties properties) { int minimumBatchSize = getIntProperty(properties, BATCH_SIZE, 50); int maximumBatchDelay = getIntProperty(properties, BATCH_DELAY, 1); URI restUrl = URI.create(properties.getProperty(REST_URL.getExternalForm(), - "http://localhost:8080/hawkular/metrics/")); + "http://localhost:8080/hawkular/metrics/gauges/data")); + String tenant = properties.getProperty(TENANT.getExternalForm(), "default"); int restCloseAfterRequests = getIntProperty(properties, REST_CLOSE_AFTER_REQUESTS, 200); int spoolSize = getIntProperty(properties, SPOOL_SIZE, 10000); return new Configuration( @@ -123,6 +128,7 @@ public static Configuration from(Properties properties) { minimumBatchSize, maximumBatchDelay, restUrl, + tenant, restCloseAfterRequests, spoolSize, validationMessages @@ -221,6 +227,10 @@ public URI getRestUrl() { return restUrl; } + public String getTenant() { + return tenant; + } + public int getRestCloseAfterRequests() { return restCloseAfterRequests; } diff --git a/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/ConfigurationKey.java b/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/ConfigurationKey.java index 6d834abbd..fee98431d 100644 --- a/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/ConfigurationKey.java +++ b/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/ConfigurationKey.java @@ -46,6 +46,8 @@ public enum ConfigurationKey { BATCH_DELAY("batch.delay"), /** REST endpoint **/ REST_URL("rest.url"), + /** Tenant **/ + TENANT("tenant"), /** Close connection to rest-server after this many requests **/ REST_CLOSE_AFTER_REQUESTS("rest.close-after"), /** Maximum number of metrics to spool if the server is not reachable **/ diff --git a/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandler.java b/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandler.java index 4d205207a..c211ba4a0 100644 --- a/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandler.java +++ b/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandler.java @@ -16,6 +16,7 @@ */ package org.hawkular.metrics.clients.ptrans.backend; +import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE; import static io.netty.handler.codec.http.HttpMethod.POST; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import io.netty.bootstrap.Bootstrap; @@ -66,10 +67,12 @@ public class RestForwardingHandler extends ChannelInboundHandlerAdapter { private static final Logger LOG = LoggerFactory.getLogger(RestForwardingHandler.class); + private static final String TENANT_HEADER_NAME = "tenantId"; + private final String restHost; private final int restPort; - private final String restPrefix; - private final String restParams; + private final String restUri; + private final String tenant; private final int restCloseAfterRequests; BoundMetricFifo fifo; @@ -91,8 +94,9 @@ public RestForwardingHandler(Configuration configuration) { URI restUrl = configuration.getRestUrl(); restHost = restUrl.getHost(); restPort = restUrl.getPort(); - restPrefix = restUrl.getPath(); - restParams = restUrl.getQuery(); + restUri = restUrl.getPath(); + + tenant = configuration.getTenant(); restCloseAfterRequests = configuration.getRestCloseAfterRequests(); @@ -157,10 +161,11 @@ private void sendToChannel(final Channel ch) { String payload = Batcher.metricListToJson(metricsToSend); ByteBuf content = Unpooled.copiedBuffer(payload, CharsetUtil.UTF_8); - FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, POST, restPrefix + "?" + restParams, content); + FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, POST, restUri, content); + HttpHeaders.setHeader(request, CONTENT_TYPE, "application/json;charset=utf-8"); HttpHeaders.setContentLength(request, content.readableBytes()); HttpHeaders.setKeepAlive(request, true); - HttpHeaders.setHeader(request, HttpHeaders.Names.CONTENT_TYPE, "application/json;charset=utf-8"); + HttpHeaders.setHeader(request, TENANT_HEADER_NAME, tenant); // We need to send the list of metrics we are sending down the pipeline, so the status watcher // can later clean them out of the fifo ch.attr(listKey).set(metricsToSend); diff --git a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandlerITest.java b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandlerITest.java index 3f798d49a..d5cdbcb65 100644 --- a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandlerITest.java +++ b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandlerITest.java @@ -73,13 +73,14 @@ public void setUp() throws Exception { when(eventLoop.parent()).thenReturn(eventLoopGroup); Properties properties = new Properties(); - String addGuageDataUrl = "http://" + BASE_URI + "/gauges/data?tenantId=" + TENANT; - properties.setProperty(ConfigurationKey.REST_URL.getExternalForm(), addGuageDataUrl); + String addGaugeDataUrl = "http://" + BASE_URI + "/gauges/data"; + properties.setProperty(ConfigurationKey.REST_URL.getExternalForm(), addGaugeDataUrl); + properties.setProperty(ConfigurationKey.TENANT.getExternalForm(), TENANT); Configuration configuration = Configuration.from(properties); restForwardingHandler = new RestForwardingHandler(configuration); - findGaugeDataUrl = "http://" + BASE_URI + "/gauges/" + METRIC_NAME + "/data?tenantId=" + TENANT; + findGaugeDataUrl = "http://" + BASE_URI + "/gauges/" + METRIC_NAME + "/data"; } @Test @@ -101,6 +102,7 @@ public void shouldForwardMetrics() throws Exception { private JsonNode findGaugeDataOnServer() throws IOException { HttpURLConnection urlConnection = (HttpURLConnection) new URL(findGaugeDataUrl).openConnection(); + urlConnection.setRequestProperty("tenantId", TENANT); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { diff --git a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java index 08d8b7e19..4592660c4 100644 --- a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java +++ b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java @@ -21,10 +21,12 @@ import static java.util.stream.Collectors.counting; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; + import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.BATCH_DELAY; import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.BATCH_SIZE; import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.REST_URL; import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.SERVICES; +import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.TENANT; import static org.hawkular.metrics.clients.ptrans.util.ProcessUtil.kill; import static org.hawkular.metrics.clients.ptrans.util.TenantUtil.getRandomTenantId; import static org.junit.Assert.assertEquals; @@ -49,8 +51,6 @@ import java.util.Properties; import java.util.stream.Stream; -import jnr.constants.platform.Signal; - import org.hawkular.metrics.clients.ptrans.ExecutableITestBase; import org.hawkular.metrics.clients.ptrans.PrintOutputOnFailureWatcher; import org.hawkular.metrics.clients.ptrans.Service; @@ -66,6 +66,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.io.Resources; +import jnr.constants.platform.Signal; + /** * @author Thomas Segismont */ @@ -77,7 +79,7 @@ public class CollectdITest extends ExecutableITestBase { ); private String tenant; - private String findGuageMetricsUrl; + private String findGaugeMetricsUrl; private File collectdConfFile; private File collectdOut; private File collectdErr; @@ -94,7 +96,7 @@ public class CollectdITest extends ExecutableITestBase { @Before public void setUp() throws Exception { tenant = getRandomTenantId(); - findGuageMetricsUrl = "http://" + BASE_URI + "/metrics?type=gauge&tenantId=" + tenant; + findGaugeMetricsUrl = "http://" + BASE_URI + "/metrics?type=gauge"; assumeCollectdIsPresent(); configureCollectd(); assertCollectdConfIsValid(); @@ -144,8 +146,9 @@ public void configurePTrans() throws Exception { properties.setProperty(SERVICES.getExternalForm(), Service.COLLECTD.getExternalForm()); properties.setProperty(BATCH_DELAY.getExternalForm(), String.valueOf(1)); properties.setProperty(BATCH_SIZE.getExternalForm(), String.valueOf(1)); - String restUrl = "http://" + BASE_URI + "/gauges/data?tenantId=" + tenant; + String restUrl = "http://" + BASE_URI + "/gauges/data"; properties.setProperty(REST_URL.getExternalForm(), restUrl); + properties.setProperty(TENANT.getExternalForm(), tenant); try (OutputStream out = new FileOutputStream(ptransConfFile)) { properties.store(out, ""); } @@ -242,12 +245,13 @@ private Point collectdLogToPoint(String line) { private List getServerData() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); - HttpURLConnection urlConnection = (HttpURLConnection) new URL(findGuageMetricsUrl).openConnection(); + HttpURLConnection urlConnection = (HttpURLConnection) new URL(findGaugeMetricsUrl).openConnection(); + urlConnection.setRequestProperty("tenantId", tenant); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { String msg = "Could not get metrics list from server: %s, %d"; - fail(String.format(Locale.ROOT, msg, findGuageMetricsUrl, responseCode)); + fail(String.format(Locale.ROOT, msg, findGaugeMetricsUrl, responseCode)); } List metricNames; try (InputStream inputStream = urlConnection.getInputStream()) { @@ -264,6 +268,7 @@ private List getServerData() throws Exception { String type = split[split.length - 1]; urlConnection = (HttpURLConnection) new URL(findGaugeDataUrl(metricName)).openConnection(); + urlConnection.setRequestProperty("tenantId", tenant); urlConnection.connect(); responseCode = urlConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { @@ -284,7 +289,7 @@ private List getServerData() throws Exception { } private String findGaugeDataUrl(String metricName) { - return "http://" + BASE_URI + "/gauges/" + metricName + "/data?tenantId=" + tenant; + return "http://" + BASE_URI + "/gauges/" + metricName + "/data"; } @After diff --git a/clients/ptranslator/src/test/resources/ptrans.conf b/clients/ptranslator/src/test/resources/ptrans.conf index 0f9f60ed6..6dd3380fe 100644 --- a/clients/ptranslator/src/test/resources/ptrans.conf +++ b/clients/ptranslator/src/test/resources/ptrans.conf @@ -41,7 +41,8 @@ statsd.port=8125 collectd.port=25826 # REST endpoint -rest.url=http://localhost:8080/hawkular/metrics/gauges/data?tenantId=test +rest.url=http://localhost:8080/hawkular/metrics/gauges/data +tenant=default # Close connection to rest-server after this many requests rest.close-after=200 From 08ec1cf2b692e3859b29421e959f3ac861d60ee3 Mon Sep 17 00:00:00 2001 From: Thomas Segismont Date: Tue, 12 May 2015 14:14:03 +0200 Subject: [PATCH 2/3] Make it easier to distinguish a ptrans config parameter from another string constant --- .../ptrans/fullstack/CollectdITest.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java index 4592660c4..23d8aa301 100644 --- a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java +++ b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java @@ -22,11 +22,6 @@ import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; -import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.BATCH_DELAY; -import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.BATCH_SIZE; -import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.REST_URL; -import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.SERVICES; -import static org.hawkular.metrics.clients.ptrans.ConfigurationKey.TENANT; import static org.hawkular.metrics.clients.ptrans.util.ProcessUtil.kill; import static org.hawkular.metrics.clients.ptrans.util.TenantUtil.getRandomTenantId; import static org.junit.Assert.assertEquals; @@ -51,6 +46,7 @@ import java.util.Properties; import java.util.stream.Stream; +import org.hawkular.metrics.clients.ptrans.ConfigurationKey; import org.hawkular.metrics.clients.ptrans.ExecutableITestBase; import org.hawkular.metrics.clients.ptrans.PrintOutputOnFailureWatcher; import org.hawkular.metrics.clients.ptrans.Service; @@ -77,6 +73,7 @@ public class CollectdITest extends ExecutableITestBase { "hawkular-metrics.base-uri", "127.0.0.1:8080/hawkular/metrics" ); + private static final String HAWKULAR_TENANT_HEADER = "tenantId"; private String tenant; private String findGaugeMetricsUrl; @@ -143,12 +140,12 @@ public void configurePTrans() throws Exception { try (InputStream in = new FileInputStream(ptransConfFile)) { properties.load(in); } - properties.setProperty(SERVICES.getExternalForm(), Service.COLLECTD.getExternalForm()); - properties.setProperty(BATCH_DELAY.getExternalForm(), String.valueOf(1)); - properties.setProperty(BATCH_SIZE.getExternalForm(), String.valueOf(1)); + properties.setProperty(ConfigurationKey.SERVICES.getExternalForm(), Service.COLLECTD.getExternalForm()); + properties.setProperty(ConfigurationKey.BATCH_DELAY.getExternalForm(), String.valueOf(1)); + properties.setProperty(ConfigurationKey.BATCH_SIZE.getExternalForm(), String.valueOf(1)); String restUrl = "http://" + BASE_URI + "/gauges/data"; - properties.setProperty(REST_URL.getExternalForm(), restUrl); - properties.setProperty(TENANT.getExternalForm(), tenant); + properties.setProperty(ConfigurationKey.REST_URL.getExternalForm(), restUrl); + properties.setProperty(ConfigurationKey.TENANT.getExternalForm(), tenant); try (OutputStream out = new FileOutputStream(ptransConfFile)) { properties.store(out, ""); } @@ -246,7 +243,7 @@ private List getServerData() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); HttpURLConnection urlConnection = (HttpURLConnection) new URL(findGaugeMetricsUrl).openConnection(); - urlConnection.setRequestProperty("tenantId", tenant); + urlConnection.setRequestProperty(HAWKULAR_TENANT_HEADER, tenant); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { @@ -268,7 +265,7 @@ private List getServerData() throws Exception { String type = split[split.length - 1]; urlConnection = (HttpURLConnection) new URL(findGaugeDataUrl(metricName)).openConnection(); - urlConnection.setRequestProperty("tenantId", tenant); + urlConnection.setRequestProperty(HAWKULAR_TENANT_HEADER, tenant); urlConnection.connect(); responseCode = urlConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { From 56e4c3c3e2c8b77c5a364202c12b18e103631dda Mon Sep 17 00:00:00 2001 From: Thomas Segismont Date: Tue, 12 May 2015 14:19:12 +0200 Subject: [PATCH 3/3] Use #toString instead of #getExternalForm in ConfigurationKey --- .../metrics/clients/ptrans/Configuration.java | 14 +++++++------- .../metrics/clients/ptrans/ConfigurationKey.java | 3 ++- .../metrics/clients/ptrans/ConfigurationITest.java | 6 +++--- .../metrics/clients/ptrans/OpenedPortsITest.java | 2 +- .../metrics/clients/ptrans/PTransTest.java | 2 +- .../ptrans/backend/RestForwardingHandlerITest.java | 4 ++-- .../clients/ptrans/fullstack/CollectdITest.java | 10 +++++----- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/Configuration.java b/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/Configuration.java index ee9a1d30d..ff04d4230 100644 --- a/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/Configuration.java +++ b/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/Configuration.java @@ -105,15 +105,15 @@ public static Configuration from(Properties properties) { int udpPort = getIntProperty(properties, UDP_PORT, 5140); int tcpPort = getIntProperty(properties, TCP_PORT, 5140); int gangliaPort = getIntProperty(properties, GANGLIA_PORT, 8649); - String gangliaGroup = properties.getProperty(GANGLIA_GROUP.getExternalForm(), "239.2.11.71"); - String multicastIfOverride = properties.getProperty(GANGLIA_MULTICAST_INTERFACE.getExternalForm()); + String gangliaGroup = properties.getProperty(GANGLIA_GROUP.toString(), "239.2.11.71"); + String multicastIfOverride = properties.getProperty(GANGLIA_MULTICAST_INTERFACE.toString()); int statsDport = getIntProperty(properties, STATSD_PORT, 8125); int collectdPort = getIntProperty(properties, COLLECTD_PORT, 25826); int minimumBatchSize = getIntProperty(properties, BATCH_SIZE, 50); int maximumBatchDelay = getIntProperty(properties, BATCH_DELAY, 1); - URI restUrl = URI.create(properties.getProperty(REST_URL.getExternalForm(), + URI restUrl = URI.create(properties.getProperty(REST_URL.toString(), "http://localhost:8080/hawkular/metrics/gauges/data")); - String tenant = properties.getProperty(TENANT.getExternalForm(), "default"); + String tenant = properties.getProperty(TENANT.toString(), "default"); int restCloseAfterRequests = getIntProperty(properties, REST_CLOSE_AFTER_REQUESTS, 200); int spoolSize = getIntProperty(properties, SPOOL_SIZE, 10000); return new Configuration( @@ -136,9 +136,9 @@ public static Configuration from(Properties properties) { } private static Set getServices(Properties properties, Set validationMessages) { - String servicesProperty = properties.getProperty(SERVICES.getExternalForm()); + String servicesProperty = properties.getProperty(SERVICES.toString()); if (servicesProperty == null) { - validationMessages.add(String.format(Locale.ROOT, "Property %s not found", SERVICES.getExternalForm())); + validationMessages.add(String.format(Locale.ROOT, "Property %s not found", SERVICES.toString())); return Collections.emptySet(); } Set services = EnumSet.noneOf(Service.class); @@ -162,7 +162,7 @@ private static Set getServices(Properties properties, Set valid } private static int getIntProperty(Properties properties, ConfigurationKey key, int defaultValue) { - String property = properties.getProperty(key.getExternalForm()); + String property = properties.getProperty(key.toString()); if (property == null) { return defaultValue; } diff --git a/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/ConfigurationKey.java b/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/ConfigurationKey.java index fee98431d..4b4418ebf 100644 --- a/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/ConfigurationKey.java +++ b/clients/ptranslator/src/main/java/org/hawkular/metrics/clients/ptrans/ConfigurationKey.java @@ -62,7 +62,8 @@ public enum ConfigurationKey { /** * @return string representation of this configuration key */ - public String getExternalForm() { + @Override + public String toString() { return externalForm; } } diff --git a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/ConfigurationITest.java b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/ConfigurationITest.java index 5aa75787c..fa95618df 100644 --- a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/ConfigurationITest.java +++ b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/ConfigurationITest.java @@ -47,7 +47,7 @@ public void shouldExitWithErrorIfServicesPropertyIsMissing() throws Exception { try (InputStream in = new FileInputStream(ptransConfFile)) { properties.load(in); } - properties.remove(SERVICES.getExternalForm()); + properties.remove(SERVICES.toString()); try (OutputStream out = new FileOutputStream(ptransConfFile)) { properties.store(out, ""); } @@ -71,7 +71,7 @@ public void shouldExitWithErrorIfServicesListIsEmpty() throws Exception { try (InputStream in = new FileInputStream(ptransConfFile)) { properties.load(in); } - properties.setProperty(SERVICES.getExternalForm(), " , , ,,,, ,,,, ,"); + properties.setProperty(SERVICES.toString(), " , , ,,,, ,,,, ,"); try (OutputStream out = new FileOutputStream(ptransConfFile)) { properties.store(out, ""); } @@ -95,7 +95,7 @@ public void shouldExitWithErrorIfServicesListContainsUnknownService() throws Exc try (InputStream in = new FileInputStream(ptransConfFile)) { properties.load(in); } - properties.setProperty(SERVICES.getExternalForm(), "marseille, collectd"); + properties.setProperty(SERVICES.toString(), "marseille, collectd"); try (OutputStream out = new FileOutputStream(ptransConfFile)) { properties.store(out, ""); } diff --git a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/OpenedPortsITest.java b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/OpenedPortsITest.java index 8706aa775..a73e65fe7 100644 --- a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/OpenedPortsITest.java +++ b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/OpenedPortsITest.java @@ -48,7 +48,7 @@ public void shouldBindPortsForEnabledServicesOnly() throws Exception { try (InputStream in = new FileInputStream(ptransConfFile)) { properties.load(in); } - properties.setProperty(SERVICES.getExternalForm(), Service.COLLECTD.getExternalForm()); + properties.setProperty(SERVICES.toString(), Service.COLLECTD.getExternalForm()); try (OutputStream out = new FileOutputStream(ptransConfFile)) { properties.store(out, ""); } diff --git a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/PTransTest.java b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/PTransTest.java index c0e833a55..d9fb6ec88 100644 --- a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/PTransTest.java +++ b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/PTransTest.java @@ -51,7 +51,7 @@ public void constructorShouldThrowExceptionWhenProvidedConfigurationIsInvalid() @Test public void constructorShouldNotThrowExceptionWhenProvidedConfigurationIsValid() { Properties properties = new Properties(); - properties.setProperty(SERVICES.getExternalForm(), COLLECTD.getExternalForm()); + properties.setProperty(SERVICES.toString(), COLLECTD.getExternalForm()); new PTrans(Configuration.from(properties)); } diff --git a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandlerITest.java b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandlerITest.java index d5cdbcb65..74be1df48 100644 --- a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandlerITest.java +++ b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/backend/RestForwardingHandlerITest.java @@ -74,8 +74,8 @@ public void setUp() throws Exception { Properties properties = new Properties(); String addGaugeDataUrl = "http://" + BASE_URI + "/gauges/data"; - properties.setProperty(ConfigurationKey.REST_URL.getExternalForm(), addGaugeDataUrl); - properties.setProperty(ConfigurationKey.TENANT.getExternalForm(), TENANT); + properties.setProperty(ConfigurationKey.REST_URL.toString(), addGaugeDataUrl); + properties.setProperty(ConfigurationKey.TENANT.toString(), TENANT); Configuration configuration = Configuration.from(properties); restForwardingHandler = new RestForwardingHandler(configuration); diff --git a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java index 23d8aa301..fdfabda4b 100644 --- a/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java +++ b/clients/ptranslator/src/test/java/org/hawkular/metrics/clients/ptrans/fullstack/CollectdITest.java @@ -140,12 +140,12 @@ public void configurePTrans() throws Exception { try (InputStream in = new FileInputStream(ptransConfFile)) { properties.load(in); } - properties.setProperty(ConfigurationKey.SERVICES.getExternalForm(), Service.COLLECTD.getExternalForm()); - properties.setProperty(ConfigurationKey.BATCH_DELAY.getExternalForm(), String.valueOf(1)); - properties.setProperty(ConfigurationKey.BATCH_SIZE.getExternalForm(), String.valueOf(1)); + properties.setProperty(ConfigurationKey.SERVICES.toString(), Service.COLLECTD.getExternalForm()); + properties.setProperty(ConfigurationKey.BATCH_DELAY.toString(), String.valueOf(1)); + properties.setProperty(ConfigurationKey.BATCH_SIZE.toString(), String.valueOf(1)); String restUrl = "http://" + BASE_URI + "/gauges/data"; - properties.setProperty(ConfigurationKey.REST_URL.getExternalForm(), restUrl); - properties.setProperty(ConfigurationKey.TENANT.getExternalForm(), tenant); + properties.setProperty(ConfigurationKey.REST_URL.toString(), restUrl); + properties.setProperty(ConfigurationKey.TENANT.toString(), tenant); try (OutputStream out = new FileOutputStream(ptransConfFile)) { properties.store(out, ""); }