From 74334b371393b0b35cc7180a9b19c97542787515 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 18 Oct 2016 13:19:13 +0200 Subject: [PATCH] Watcher: Remove watcherbuild info (elastic/elasticsearch#3792) Watcher does not require any unique build info anymore, as all is put into the MANIFEST.MF file during the build. Also the xpack-properties is unused now and can be deleted. Original commit: elastic/x-pack-elasticsearch@62f121c97947c22f459b25f5e9784f8888de51b4 --- .../xpack/watcher/WatcherBuild.java | 112 ------------------ .../stats/TransportWatcherStatsAction.java | 6 +- .../actions/stats/WatcherStatsResponse.java | 15 --- .../src/main/resources/xpack-build.properties | 3 - .../action/stats/WatcherStatsTests.java | 2 - 5 files changed, 1 insertion(+), 137 deletions(-) delete mode 100644 elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/WatcherBuild.java delete mode 100644 elasticsearch/src/main/resources/xpack-build.properties diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/WatcherBuild.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/WatcherBuild.java deleted file mode 100644 index cd7638700c7..00000000000 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/WatcherBuild.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.watcher; - -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.joda.time.DateTimeZone; -import org.joda.time.format.ISODateTimeFormat; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -public class WatcherBuild { - - public static final WatcherBuild CURRENT; - - static { - String versionName = "NA"; - String hash = "NA"; - String hashShort = "NA"; - String timestamp = "NA"; - - try (InputStream is = WatcherBuild.class.getResourceAsStream("/watcher-build.properties")) { - Properties props = new Properties(); - props.load(is); - hash = props.getProperty("hash", hash); - if (!hash.equals("NA")) { - hashShort = hash.substring(0, 7); - } - String gitTimestampRaw = props.getProperty("timestamp"); - if (gitTimestampRaw != null) { - timestamp = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).print(Long.parseLong(gitTimestampRaw)); - } - versionName = props.getProperty("version", "NA"); - } catch (Exception e) { - // just ignore... - } - - CURRENT = new WatcherBuild(versionName, hash, hashShort, timestamp); - } - - private final String versionName; - private final String hash; - private final String hashShort; - private final String timestamp; - - WatcherBuild(String versionName, String hash, String hashShort, String timestamp) { - this.versionName = versionName; - this.hash = hash; - this.hashShort = hashShort; - this.timestamp = timestamp; - } - - public String versionName() { - return versionName; - } - - public String hash() { - return hash; - } - - public String hashShort() { - return hashShort; - } - - public String timestamp() { - return timestamp; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - WatcherBuild that = (WatcherBuild) o; - - if (!hash.equals(that.hash)) return false; - if (!hashShort.equals(that.hashShort)) return false; - if (!timestamp.equals(that.timestamp)) return false; - if (!versionName.equals(that.versionName)) return false; - - return true; - } - - @Override - public int hashCode() { - int result = hash.hashCode(); - result = 31 * result + hashShort.hashCode(); - result = 31 * result + timestamp.hashCode(); - result = 31 * result + versionName.hashCode(); - return result; - } - - public static WatcherBuild readBuild(StreamInput in) throws IOException { - String versionName = in.readString(); - String hash = in.readString(); - String hashShort = in.readString(); - String timestamp = in.readString(); - return new WatcherBuild(versionName, hash, hashShort, timestamp); - } - - public static void writeBuild(WatcherBuild build, StreamOutput out) throws IOException { - out.writeString(build.versionName); - out.writeString(build.hash); - out.writeString(build.hashShort); - out.writeString(build.timestamp); - } -} diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/stats/TransportWatcherStatsAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/stats/TransportWatcherStatsAction.java index 2a52b30ad55..cf30e8e403e 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/stats/TransportWatcherStatsAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/stats/TransportWatcherStatsAction.java @@ -8,17 +8,16 @@ package org.elasticsearch.xpack.watcher.transport.actions.stats; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; -import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.watcher.WatcherBuild; import org.elasticsearch.xpack.watcher.WatcherLifeCycleService; import org.elasticsearch.xpack.watcher.WatcherService; import org.elasticsearch.xpack.watcher.execution.ExecutionService; @@ -65,7 +64,6 @@ public class TransportWatcherStatsAction extends WatcherTransportAction getSnapshots() { return snapshots; @@ -125,7 +112,6 @@ public class WatcherStatsResponse extends ActionResponse implements ToXContent { threadPoolQueueSize = in.readLong(); threadPoolMaxSize = in.readLong(); watcherState = WatcherState.fromId(in.readByte()); - build = WatcherBuild.readBuild(in); if (in.readBoolean()) { int size = in.readVInt(); @@ -151,7 +137,6 @@ public class WatcherStatsResponse extends ActionResponse implements ToXContent { out.writeLong(threadPoolQueueSize); out.writeLong(threadPoolMaxSize); out.writeByte(watcherState.getId()); - WatcherBuild.writeBuild(build, out); if (snapshots != null) { out.writeBoolean(true); diff --git a/elasticsearch/src/main/resources/xpack-build.properties b/elasticsearch/src/main/resources/xpack-build.properties deleted file mode 100644 index 563ecddcaf6..00000000000 --- a/elasticsearch/src/main/resources/xpack-build.properties +++ /dev/null @@ -1,3 +0,0 @@ -version=${project.version} -hash=${buildNumber} -timestamp=${timestamp} diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/WatcherStatsTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/WatcherStatsTests.java index 4327072342d..0e4ec2a2342 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/WatcherStatsTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/WatcherStatsTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.watcher.transport.action.stats; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.junit.annotations.TestLogging; -import org.elasticsearch.xpack.watcher.WatcherBuild; import org.elasticsearch.xpack.watcher.WatcherState; import org.elasticsearch.xpack.watcher.client.WatcherClient; import org.elasticsearch.xpack.watcher.condition.compare.CompareCondition; @@ -43,7 +42,6 @@ public class WatcherStatsTests extends AbstractWatcherIntegrationTestCase { assertThat(response.getThreadPoolQueueSize(), is(0L)); assertThat(response.getWatchesCount(), is(0L)); assertThat(response.getThreadPoolMaxSize(), is(timeWarped() ? 1L : 0L)); - assertThat(response.getBuild(), is(WatcherBuild.CURRENT)); } public void testWatchCountStats() throws Exception {