From cb6a5b4e85f871dc2a4c73fa7743d33be61382e4 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 14 Apr 2016 23:15:41 -0700 Subject: [PATCH 01/23] Simplify xcontentstring usages This is the xplugins side of elastic/elasticsearchelastic/elasticsearch#17774. Original commit: elastic/x-pack-elasticsearch@5c05609840690cd5e9761c47ad757869c72cd5b0 --- .../agent/resolver/shards/ShardsResolver.java | 2 +- .../marvel/action/MonitoringBulkTests.java | 6 +-- .../MonitoringIndexNameResolverTestCase.java | 6 +-- .../resolver/cluster/ClusterInfoTests.java | 40 +++++++++---------- .../resolver/cluster/ClusterStateTests.java | 40 +++++++++---------- .../resolver/indices/IndexRecoveryTests.java | 12 +++--- 6 files changed, 53 insertions(+), 53 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsResolver.java index ca4288b9617..c5064d7eb71 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsResolver.java @@ -60,7 +60,7 @@ public class ShardsResolver extends MonitoringIndexNameResolver.Timestamped source = searchHit.sourceAsMap(); - assertNotNull(source.get(MonitoringBulkResolver.Fields.CLUSTER_UUID.underscore().toString())); - assertNotNull(source.get(MonitoringBulkResolver.Fields.TIMESTAMP.underscore().toString())); - assertNotNull(source.get(MonitoringBulkResolver.Fields.SOURCE_NODE.underscore().toString())); + assertNotNull(source.get(MonitoringBulkResolver.Fields.CLUSTER_UUID.value())); + assertNotNull(source.get(MonitoringBulkResolver.Fields.TIMESTAMP.value())); + assertNotNull(source.get(MonitoringBulkResolver.Fields.SOURCE_NODE.value())); } } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java index 3c2fdb0e9a1..bc4177cf787 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java @@ -148,9 +148,9 @@ public abstract class MonitoringIndexNameResolverTestCase source = response.getSource(); - assertThat(source.get(MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString()), notNullValue()); - assertThat(source.get(MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString()), notNullValue()); - assertThat(source.get(MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString()), notNullValue()); - assertThat(source.get(ClusterInfoResolver.Fields.CLUSTER_NAME.underscore().toString()), equalTo(cluster().getClusterName())); - assertThat(source.get(ClusterInfoResolver.Fields.VERSION.underscore().toString()), equalTo(Version.CURRENT.toString())); + assertThat(source.get(MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value()), notNullValue()); + assertThat(source.get(MonitoringIndexNameResolver.Fields.TIMESTAMP.value()), notNullValue()); + assertThat(source.get(MonitoringIndexNameResolver.Fields.SOURCE_NODE.value()), notNullValue()); + assertThat(source.get(ClusterInfoResolver.Fields.CLUSTER_NAME.value()), equalTo(cluster().getClusterName())); + assertThat(source.get(ClusterInfoResolver.Fields.VERSION.value()), equalTo(Version.CURRENT.toString())); logger.debug("--> checking that the document contains license information"); - Object licenseObj = source.get(ClusterInfoResolver.Fields.LICENSE.underscore().toString()); + Object licenseObj = source.get(ClusterInfoResolver.Fields.LICENSE.value()); assertThat(licenseObj, instanceOf(Map.class)); Map license = (Map) licenseObj; assertThat(license, instanceOf(Map.class)); - String uid = (String) license.get(ClusterInfoResolver.Fields.UID.underscore().toString()); + String uid = (String) license.get(ClusterInfoResolver.Fields.UID.value()); assertThat(uid, not(isEmptyOrNullString())); - String type = (String) license.get(ClusterInfoResolver.Fields.TYPE.underscore().toString()); + String type = (String) license.get(ClusterInfoResolver.Fields.TYPE.value()); assertThat(type, not(isEmptyOrNullString())); - String status = (String) license.get(License.XFields.STATUS.underscore().toString()); + String status = (String) license.get(License.XFields.STATUS.value()); assertThat(status, not(isEmptyOrNullString())); - Long expiryDate = (Long) license.get(License.XFields.EXPIRY_DATE_IN_MILLIS.underscore().toString()); + Long expiryDate = (Long) license.get(License.XFields.EXPIRY_DATE_IN_MILLIS.value()); assertThat(expiryDate, greaterThan(0L)); // We basically recompute the hash here - String hkey = (String) license.get(ClusterInfoResolver.Fields.HKEY.underscore().toString()); + String hkey = (String) license.get(ClusterInfoResolver.Fields.HKEY.value()); String recalculated = ClusterInfoResolver.hash(status, uid, type, String.valueOf(expiryDate), clusterUUID); assertThat(hkey, equalTo(recalculated)); - assertThat((String) license.get(License.XFields.ISSUER.underscore().toString()), not(isEmptyOrNullString())); - assertThat((String) license.get(License.XFields.ISSUED_TO.underscore().toString()), not(isEmptyOrNullString())); - assertThat((Long) license.get(License.XFields.ISSUE_DATE_IN_MILLIS.underscore().toString()), greaterThan(0L)); - assertThat((Integer) license.get(License.XFields.MAX_NODES.underscore().toString()), greaterThan(0)); + assertThat((String) license.get(License.XFields.ISSUER.value()), not(isEmptyOrNullString())); + assertThat((String) license.get(License.XFields.ISSUED_TO.value()), not(isEmptyOrNullString())); + assertThat((Long) license.get(License.XFields.ISSUE_DATE_IN_MILLIS.value()), greaterThan(0L)); + assertThat((Integer) license.get(License.XFields.MAX_NODES.value()), greaterThan(0)); - Object clusterStats = source.get(ClusterInfoResolver.Fields.CLUSTER_STATS.underscore().toString()); + Object clusterStats = source.get(ClusterInfoResolver.Fields.CLUSTER_STATS.value()); assertNotNull(clusterStats); assertThat(clusterStats, instanceOf(Map.class)); assertThat(((Map) clusterStats).size(), greaterThan(0)); @@ -128,10 +128,10 @@ public class ClusterInfoTests extends MarvelIntegTestCase { .setTypes(ClusterInfoResolver.TYPE) .setQuery( QueryBuilders.boolQuery() - .should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.ACTIVE.label())) - .should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.INVALID.label())) - .should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.EXPIRED.label())) - .should(QueryBuilders.matchQuery(ClusterInfoResolver.Fields.CLUSTER_NAME.underscore().toString(), + .should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.ACTIVE.label())) + .should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.INVALID.label())) + .should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.EXPIRED.label())) + .should(QueryBuilders.matchQuery(ClusterInfoResolver.Fields.CLUSTER_NAME.value(), cluster().getClusterName())) .minimumNumberShouldMatch(1) ).get(), 0L); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java index f71e20ddc73..e58e13fd81c 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java @@ -122,13 +122,13 @@ public class ClusterStateTests extends MarvelIntegTestCase { logger.debug("--> checking that every document contains the expected fields"); String[] filters = { - MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(), - MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(), - SOURCE_NODE.underscore().toString(), - ClusterStateNodeResolver.Fields.STATE_UUID.underscore().toString(), - ClusterStateNodeResolver.Fields.NODE.underscore().toString(), - ClusterStateNodeResolver.Fields.NODE.underscore().toString() + "." - + ClusterStateNodeResolver.Fields.ID.underscore().toString(), + MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(), + MonitoringIndexNameResolver.Fields.TIMESTAMP.value(), + SOURCE_NODE.value(), + ClusterStateNodeResolver.Fields.STATE_UUID.value(), + ClusterStateNodeResolver.Fields.NODE.value(), + ClusterStateNodeResolver.Fields.NODE.value() + "." + + ClusterStateNodeResolver.Fields.ID.value(), }; for (SearchHit searchHit : response.getHits().getHits()) { @@ -143,7 +143,7 @@ public class ClusterStateTests extends MarvelIntegTestCase { assertThat(client().prepareSearch().setSize(0) .setIndices(timestampedIndex) .setTypes(ClusterStateNodeResolver.TYPE) - .setQuery(QueryBuilders.matchQuery(SOURCE_NODE.underscore().toString() + ".attributes.custom", randomInt)) + .setQuery(QueryBuilders.matchQuery(SOURCE_NODE.value() + ".attributes.custom", randomInt)) .get().getHits().getTotalHits(), greaterThan(0L)); logger.debug("--> cluster state nodes successfully collected"); @@ -167,18 +167,18 @@ public class ClusterStateTests extends MarvelIntegTestCase { logger.debug("--> checking that every document contains the expected fields"); String[] filters = { - MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(), - MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(), - MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString(), - DiscoveryNodeResolver.Fields.NODE.underscore().toString(), - DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "." - + DiscoveryNodeResolver.Fields.ID.underscore().toString(), - DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "." - + DiscoveryNodeResolver.Fields.NAME.underscore().toString(), - DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "." - + DiscoveryNodeResolver.Fields.ATTRIBUTES.underscore().toString(), - DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "." - + DiscoveryNodeResolver.Fields.TRANSPORT_ADDRESS.underscore().toString(), + MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(), + MonitoringIndexNameResolver.Fields.TIMESTAMP.value(), + MonitoringIndexNameResolver.Fields.SOURCE_NODE.value(), + DiscoveryNodeResolver.Fields.NODE.value(), + DiscoveryNodeResolver.Fields.NODE.value() + "." + + DiscoveryNodeResolver.Fields.ID.value(), + DiscoveryNodeResolver.Fields.NODE.value() + "." + + DiscoveryNodeResolver.Fields.NAME.value(), + DiscoveryNodeResolver.Fields.NODE.value() + "." + + DiscoveryNodeResolver.Fields.ATTRIBUTES.value(), + DiscoveryNodeResolver.Fields.NODE.value() + "." + + DiscoveryNodeResolver.Fields.TRANSPORT_ADDRESS.value(), }; for (SearchHit searchHit : response.getHits().getHits()) { diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java index 41f155d85da..1f15944cf66 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java @@ -80,12 +80,12 @@ public class IndexRecoveryTests extends MarvelIntegTestCase { logger.debug("--> checking that every document contains the expected fields"); String[] filters = { - MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(), - MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(), - MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString(), - IndexRecoveryResolver.Fields.INDEX_RECOVERY.underscore().toString(), - IndexRecoveryResolver.Fields.INDEX_RECOVERY.underscore().toString() + "." - + IndexRecoveryResolver.Fields.SHARDS.underscore().toString(), + MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(), + MonitoringIndexNameResolver.Fields.TIMESTAMP.value(), + MonitoringIndexNameResolver.Fields.SOURCE_NODE.value(), + IndexRecoveryResolver.Fields.INDEX_RECOVERY.value(), + IndexRecoveryResolver.Fields.INDEX_RECOVERY.value() + "." + + IndexRecoveryResolver.Fields.SHARDS.value(), }; for (SearchHit searchHit : response.getHits().getHits()) { From 7275d48bbd394a54c834052bd9a4967b082cb690 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 18 Apr 2016 14:37:17 -0700 Subject: [PATCH 02/23] Remove XContentBuilderString This is the xplugins side of elastic/elasticsearchelastic/elasticsearch#17833 Original commit: elastic/x-pack-elasticsearch@24001927757136be53ddf029544c8e3b1392d80e --- .../elasticsearch/license/core/License.java | 73 +++++++------------ .../graph/action/GraphExploreResponse.java | 13 ++-- .../marvel/agent/exporter/MonitoringDoc.java | 13 ++-- .../resolver/MonitoringIndexNameResolver.java | 7 +- .../resolver/cluster/ClusterInfoResolver.java | 15 ++-- .../cluster/ClusterStateNodeResolver.java | 7 +- .../cluster/ClusterStateResolver.java | 5 +- .../cluster/ClusterStatsResolver.java | 3 +- .../cluster/DiscoveryNodeResolver.java | 11 ++- .../indices/IndexRecoveryResolver.java | 7 +- .../resolver/indices/IndexStatsResolver.java | 9 +-- .../indices/IndicesStatsResolver.java | 3 +- .../resolver/node/NodeStatsResolver.java | 13 ++-- .../agent/resolver/shards/ShardsResolver.java | 7 +- .../rest/action/RestMonitoringBulkAction.java | 7 +- .../marvel/action/MonitoringBulkTests.java | 6 +- .../MonitoringIndexNameResolverTestCase.java | 6 +- .../resolver/cluster/ClusterInfoTests.java | 40 +++++----- .../resolver/cluster/ClusterStateTests.java | 40 +++++----- .../resolver/indices/IndexRecoveryTests.java | 12 +-- .../shield/audit/index/IndexAuditTrail.java | 39 +++++----- .../actions/hipchat/service/SentMessages.java | 17 ++--- .../actions/slack/service/SentMessages.java | 17 ++--- 23 files changed, 168 insertions(+), 202 deletions(-) diff --git a/elasticsearch/license/base/src/main/java/org/elasticsearch/license/core/License.java b/elasticsearch/license/base/src/main/java/org/elasticsearch/license/core/License.java index a736463e5ba..4f503f68073 100644 --- a/elasticsearch/license/base/src/main/java/org/elasticsearch/license/core/License.java +++ b/elasticsearch/license/base/src/main/java/org/elasticsearch/license/core/License.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; @@ -315,23 +314,23 @@ public class License implements ToXContent { version = this.version; } if (restViewMode) { - builder.field(XFields.STATUS, status().label()); + builder.field(Fields.STATUS, status().label()); } - builder.field(XFields.UID, uid); - builder.field(XFields.TYPE, type); + builder.field(Fields.UID, uid); + builder.field(Fields.TYPE, type); if (version == VERSION_START) { - builder.field(XFields.SUBSCRIPTION_TYPE, subscriptionType); + builder.field(Fields.SUBSCRIPTION_TYPE, subscriptionType); } - builder.dateValueField(XFields.ISSUE_DATE_IN_MILLIS, XFields.ISSUE_DATE, issueDate); + builder.dateValueField(Fields.ISSUE_DATE_IN_MILLIS, Fields.ISSUE_DATE, issueDate); if (version == VERSION_START) { - builder.field(XFields.FEATURE, feature); + builder.field(Fields.FEATURE, feature); } - builder.dateValueField(XFields.EXPIRY_DATE_IN_MILLIS, XFields.EXPIRY_DATE, expiryDate); - builder.field(XFields.MAX_NODES, maxNodes); - builder.field(XFields.ISSUED_TO, issuedTo); - builder.field(XFields.ISSUER, issuer); + builder.dateValueField(Fields.EXPIRY_DATE_IN_MILLIS, Fields.EXPIRY_DATE, expiryDate); + builder.field(Fields.MAX_NODES, maxNodes); + builder.field(Fields.ISSUED_TO, issuedTo); + builder.field(Fields.ISSUER, issuer); if (!licenseSpecMode && !restViewMode && signature != null) { - builder.field(XFields.SIGNATURE, signature); + builder.field(Fields.SIGNATURE, signature); } if (restViewMode) { builder.humanReadable(previouslyHumanReadable); @@ -504,43 +503,27 @@ public class License implements ToXContent { return result; } - final static class Fields { - static final String STATUS = "status"; - static final String UID = "uid"; - static final String TYPE = "type"; - static final String SUBSCRIPTION_TYPE = "subscription_type"; - static final String ISSUE_DATE_IN_MILLIS = "issue_date_in_millis"; - static final String ISSUE_DATE = "issue_date"; - static final String FEATURE = "feature"; - static final String EXPIRY_DATE_IN_MILLIS = "expiry_date_in_millis"; - static final String EXPIRY_DATE = "expiry_date"; - static final String MAX_NODES = "max_nodes"; - static final String ISSUED_TO = "issued_to"; - static final String ISSUER = "issuer"; - static final String VERSION = "version"; - static final String SIGNATURE = "signature"; + public final static class Fields { + public static final String STATUS = "status"; + public static final String UID = "uid"; + public static final String TYPE = "type"; + public static final String SUBSCRIPTION_TYPE = "subscription_type"; + public static final String ISSUE_DATE_IN_MILLIS = "issue_date_in_millis"; + public static final String ISSUE_DATE = "issue_date"; + public static final String FEATURE = "feature"; + public static final String EXPIRY_DATE_IN_MILLIS = "expiry_date_in_millis"; + public static final String EXPIRY_DATE = "expiry_date"; + public static final String MAX_NODES = "max_nodes"; + public static final String ISSUED_TO = "issued_to"; + public static final String ISSUER = "issuer"; + public static final String VERSION = "version"; + public static final String SIGNATURE = "signature"; - static final String LICENSES = "licenses"; - static final String LICENSE = "license"; + public static final String LICENSES = "licenses"; + public static final String LICENSE = "license"; } - public interface XFields { - XContentBuilderString STATUS = new XContentBuilderString(Fields.STATUS); - XContentBuilderString UID = new XContentBuilderString(Fields.UID); - XContentBuilderString TYPE = new XContentBuilderString(Fields.TYPE); - XContentBuilderString SUBSCRIPTION_TYPE = new XContentBuilderString(Fields.SUBSCRIPTION_TYPE); - XContentBuilderString ISSUE_DATE_IN_MILLIS = new XContentBuilderString(Fields.ISSUE_DATE_IN_MILLIS); - XContentBuilderString ISSUE_DATE = new XContentBuilderString(Fields.ISSUE_DATE); - XContentBuilderString FEATURE = new XContentBuilderString(Fields.FEATURE); - XContentBuilderString EXPIRY_DATE_IN_MILLIS = new XContentBuilderString(Fields.EXPIRY_DATE_IN_MILLIS); - XContentBuilderString EXPIRY_DATE = new XContentBuilderString(Fields.EXPIRY_DATE); - XContentBuilderString MAX_NODES = new XContentBuilderString(Fields.MAX_NODES); - XContentBuilderString ISSUED_TO = new XContentBuilderString(Fields.ISSUED_TO); - XContentBuilderString ISSUER = new XContentBuilderString(Fields.ISSUER); - XContentBuilderString SIGNATURE = new XContentBuilderString(Fields.SIGNATURE); - } - private static long parseDate(XContentParser parser, String description, boolean endOfTheDay) throws IOException { if (parser.currentToken() == XContentParser.Token.VALUE_NUMBER) { return parser.longValue(); diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreResponse.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreResponse.java index 298b8a8a5cb..24dfe28a119 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreResponse.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreResponse.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.graph.action.Connection.ConnectionId; import org.elasticsearch.graph.action.Vertex.VertexId; @@ -149,12 +148,12 @@ public class GraphExploreResponse extends ActionResponse implements ToXContent { } static final class Fields { - static final XContentBuilderString TOOK = new XContentBuilderString("took"); - static final XContentBuilderString TIMED_OUT = new XContentBuilderString("timed_out"); - static final XContentBuilderString INDICES = new XContentBuilderString("_indices"); - static final XContentBuilderString FAILURES = new XContentBuilderString("failures"); - static final XContentBuilderString VERTICES = new XContentBuilderString("vertices"); - static final XContentBuilderString CONNECTIONS = new XContentBuilderString("connections"); + static final String TOOK = "took"; + static final String TIMED_OUT = "timed_out"; + static final String INDICES = "_indices"; + static final String FAILURES = "failures"; + static final String VERTICES = "vertices"; + static final String CONNECTIONS = "connections"; } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java index e1be3f48510..5bf0295c3ca 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.util.Collections; @@ -229,12 +228,12 @@ public class MonitoringDoc implements Writeable { } static final class Fields { - static final XContentBuilderString UUID = new XContentBuilderString("uuid"); - static final XContentBuilderString HOST = new XContentBuilderString("host"); - static final XContentBuilderString TRANSPORT_ADDRESS = new XContentBuilderString("transport_address"); - static final XContentBuilderString IP = new XContentBuilderString("ip"); - static final XContentBuilderString NAME = new XContentBuilderString("name"); - static final XContentBuilderString ATTRIBUTES = new XContentBuilderString("attributes"); + static final String UUID = "uuid"; + static final String HOST = "host"; + static final String TRANSPORT_ADDRESS = "transport_address"; + static final String IP = "ip"; + static final String NAME = "name"; + static final String ATTRIBUTES = "attributes"; } } } \ No newline at end of file diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolver.java index 698d22db650..add17936baa 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolver.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils; @@ -128,9 +127,9 @@ public abstract class MonitoringIndexNameResolver { protected abstract void buildXContent(T document, XContentBuilder builder, ToXContent.Params params) throws IOException; public static final class Fields { - public static final XContentBuilderString CLUSTER_UUID = new XContentBuilderString("cluster_uuid"); - public static final XContentBuilderString TIMESTAMP = new XContentBuilderString("timestamp"); - public static final XContentBuilderString SOURCE_NODE = new XContentBuilderString("source_node"); + public static final String CLUSTER_UUID = "cluster_uuid"; + public static final String TIMESTAMP = "timestamp"; + public static final String SOURCE_NODE = "source_node"; } /** diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolver.java index 1e85d67c2c7..407d3eb2659 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolver.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.hash.MessageDigests; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.license.core.License; import org.elasticsearch.marvel.agent.collector.cluster.ClusterInfoMonitoringDoc; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver; @@ -72,14 +71,14 @@ public class ClusterInfoResolver extends MonitoringIndexNameResolver.Data source = searchHit.sourceAsMap(); - assertNotNull(source.get(MonitoringBulkResolver.Fields.CLUSTER_UUID.value())); - assertNotNull(source.get(MonitoringBulkResolver.Fields.TIMESTAMP.value())); - assertNotNull(source.get(MonitoringBulkResolver.Fields.SOURCE_NODE.value())); + assertNotNull(source.get(MonitoringBulkResolver.Fields.CLUSTER_UUID)); + assertNotNull(source.get(MonitoringBulkResolver.Fields.TIMESTAMP)); + assertNotNull(source.get(MonitoringBulkResolver.Fields.SOURCE_NODE)); } } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java index bc4177cf787..4b540ced892 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java @@ -148,9 +148,9 @@ public abstract class MonitoringIndexNameResolverTestCase source = response.getSource(); - assertThat(source.get(MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value()), notNullValue()); - assertThat(source.get(MonitoringIndexNameResolver.Fields.TIMESTAMP.value()), notNullValue()); - assertThat(source.get(MonitoringIndexNameResolver.Fields.SOURCE_NODE.value()), notNullValue()); - assertThat(source.get(ClusterInfoResolver.Fields.CLUSTER_NAME.value()), equalTo(cluster().getClusterName())); - assertThat(source.get(ClusterInfoResolver.Fields.VERSION.value()), equalTo(Version.CURRENT.toString())); + assertThat(source.get(MonitoringIndexNameResolver.Fields.CLUSTER_UUID), notNullValue()); + assertThat(source.get(MonitoringIndexNameResolver.Fields.TIMESTAMP), notNullValue()); + assertThat(source.get(MonitoringIndexNameResolver.Fields.SOURCE_NODE), notNullValue()); + assertThat(source.get(ClusterInfoResolver.Fields.CLUSTER_NAME), equalTo(cluster().getClusterName())); + assertThat(source.get(ClusterInfoResolver.Fields.VERSION), equalTo(Version.CURRENT.toString())); logger.debug("--> checking that the document contains license information"); - Object licenseObj = source.get(ClusterInfoResolver.Fields.LICENSE.value()); + Object licenseObj = source.get(ClusterInfoResolver.Fields.LICENSE); assertThat(licenseObj, instanceOf(Map.class)); Map license = (Map) licenseObj; assertThat(license, instanceOf(Map.class)); - String uid = (String) license.get(ClusterInfoResolver.Fields.UID.value()); + String uid = (String) license.get(ClusterInfoResolver.Fields.UID); assertThat(uid, not(isEmptyOrNullString())); - String type = (String) license.get(ClusterInfoResolver.Fields.TYPE.value()); + String type = (String) license.get(ClusterInfoResolver.Fields.TYPE); assertThat(type, not(isEmptyOrNullString())); - String status = (String) license.get(License.XFields.STATUS.value()); + String status = (String) license.get(License.Fields.STATUS); assertThat(status, not(isEmptyOrNullString())); - Long expiryDate = (Long) license.get(License.XFields.EXPIRY_DATE_IN_MILLIS.value()); + Long expiryDate = (Long) license.get(License.Fields.EXPIRY_DATE_IN_MILLIS); assertThat(expiryDate, greaterThan(0L)); // We basically recompute the hash here - String hkey = (String) license.get(ClusterInfoResolver.Fields.HKEY.value()); + String hkey = (String) license.get(ClusterInfoResolver.Fields.HKEY); String recalculated = ClusterInfoResolver.hash(status, uid, type, String.valueOf(expiryDate), clusterUUID); assertThat(hkey, equalTo(recalculated)); - assertThat((String) license.get(License.XFields.ISSUER.value()), not(isEmptyOrNullString())); - assertThat((String) license.get(License.XFields.ISSUED_TO.value()), not(isEmptyOrNullString())); - assertThat((Long) license.get(License.XFields.ISSUE_DATE_IN_MILLIS.value()), greaterThan(0L)); - assertThat((Integer) license.get(License.XFields.MAX_NODES.value()), greaterThan(0)); + assertThat((String) license.get(License.Fields.ISSUER), not(isEmptyOrNullString())); + assertThat((String) license.get(License.Fields.ISSUED_TO), not(isEmptyOrNullString())); + assertThat((Long) license.get(License.Fields.ISSUE_DATE_IN_MILLIS), greaterThan(0L)); + assertThat((Integer) license.get(License.Fields.MAX_NODES), greaterThan(0)); - Object clusterStats = source.get(ClusterInfoResolver.Fields.CLUSTER_STATS.value()); + Object clusterStats = source.get(ClusterInfoResolver.Fields.CLUSTER_STATS); assertNotNull(clusterStats); assertThat(clusterStats, instanceOf(Map.class)); assertThat(((Map) clusterStats).size(), greaterThan(0)); @@ -128,10 +128,10 @@ public class ClusterInfoTests extends MarvelIntegTestCase { .setTypes(ClusterInfoResolver.TYPE) .setQuery( QueryBuilders.boolQuery() - .should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.ACTIVE.label())) - .should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.INVALID.label())) - .should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.EXPIRED.label())) - .should(QueryBuilders.matchQuery(ClusterInfoResolver.Fields.CLUSTER_NAME.value(), + .should(QueryBuilders.matchQuery(License.Fields.STATUS, License.Status.ACTIVE.label())) + .should(QueryBuilders.matchQuery(License.Fields.STATUS, License.Status.INVALID.label())) + .should(QueryBuilders.matchQuery(License.Fields.STATUS, License.Status.EXPIRED.label())) + .should(QueryBuilders.matchQuery(ClusterInfoResolver.Fields.CLUSTER_NAME, cluster().getClusterName())) .minimumNumberShouldMatch(1) ).get(), 0L); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java index e58e13fd81c..41cdd6b314c 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java @@ -122,13 +122,13 @@ public class ClusterStateTests extends MarvelIntegTestCase { logger.debug("--> checking that every document contains the expected fields"); String[] filters = { - MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(), - MonitoringIndexNameResolver.Fields.TIMESTAMP.value(), - SOURCE_NODE.value(), - ClusterStateNodeResolver.Fields.STATE_UUID.value(), - ClusterStateNodeResolver.Fields.NODE.value(), - ClusterStateNodeResolver.Fields.NODE.value() + "." - + ClusterStateNodeResolver.Fields.ID.value(), + MonitoringIndexNameResolver.Fields.CLUSTER_UUID, + MonitoringIndexNameResolver.Fields.TIMESTAMP, + SOURCE_NODE, + ClusterStateNodeResolver.Fields.STATE_UUID, + ClusterStateNodeResolver.Fields.NODE, + ClusterStateNodeResolver.Fields.NODE + "." + + ClusterStateNodeResolver.Fields.ID, }; for (SearchHit searchHit : response.getHits().getHits()) { @@ -143,7 +143,7 @@ public class ClusterStateTests extends MarvelIntegTestCase { assertThat(client().prepareSearch().setSize(0) .setIndices(timestampedIndex) .setTypes(ClusterStateNodeResolver.TYPE) - .setQuery(QueryBuilders.matchQuery(SOURCE_NODE.value() + ".attributes.custom", randomInt)) + .setQuery(QueryBuilders.matchQuery(SOURCE_NODE + ".attributes.custom", randomInt)) .get().getHits().getTotalHits(), greaterThan(0L)); logger.debug("--> cluster state nodes successfully collected"); @@ -167,18 +167,18 @@ public class ClusterStateTests extends MarvelIntegTestCase { logger.debug("--> checking that every document contains the expected fields"); String[] filters = { - MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(), - MonitoringIndexNameResolver.Fields.TIMESTAMP.value(), - MonitoringIndexNameResolver.Fields.SOURCE_NODE.value(), - DiscoveryNodeResolver.Fields.NODE.value(), - DiscoveryNodeResolver.Fields.NODE.value() + "." - + DiscoveryNodeResolver.Fields.ID.value(), - DiscoveryNodeResolver.Fields.NODE.value() + "." - + DiscoveryNodeResolver.Fields.NAME.value(), - DiscoveryNodeResolver.Fields.NODE.value() + "." - + DiscoveryNodeResolver.Fields.ATTRIBUTES.value(), - DiscoveryNodeResolver.Fields.NODE.value() + "." - + DiscoveryNodeResolver.Fields.TRANSPORT_ADDRESS.value(), + MonitoringIndexNameResolver.Fields.CLUSTER_UUID, + MonitoringIndexNameResolver.Fields.TIMESTAMP, + MonitoringIndexNameResolver.Fields.SOURCE_NODE, + DiscoveryNodeResolver.Fields.NODE, + DiscoveryNodeResolver.Fields.NODE + "." + + DiscoveryNodeResolver.Fields.ID, + DiscoveryNodeResolver.Fields.NODE + "." + + DiscoveryNodeResolver.Fields.NAME, + DiscoveryNodeResolver.Fields.NODE + "." + + DiscoveryNodeResolver.Fields.ATTRIBUTES, + DiscoveryNodeResolver.Fields.NODE + "." + + DiscoveryNodeResolver.Fields.TRANSPORT_ADDRESS, }; for (SearchHit searchHit : response.getHits().getHits()) { diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java index 1f15944cf66..b270f6c7acd 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java @@ -80,12 +80,12 @@ public class IndexRecoveryTests extends MarvelIntegTestCase { logger.debug("--> checking that every document contains the expected fields"); String[] filters = { - MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(), - MonitoringIndexNameResolver.Fields.TIMESTAMP.value(), - MonitoringIndexNameResolver.Fields.SOURCE_NODE.value(), - IndexRecoveryResolver.Fields.INDEX_RECOVERY.value(), - IndexRecoveryResolver.Fields.INDEX_RECOVERY.value() + "." - + IndexRecoveryResolver.Fields.SHARDS.value(), + MonitoringIndexNameResolver.Fields.CLUSTER_UUID, + MonitoringIndexNameResolver.Fields.TIMESTAMP, + MonitoringIndexNameResolver.Fields.SOURCE_NODE, + IndexRecoveryResolver.Fields.INDEX_RECOVERY, + IndexRecoveryResolver.Fields.INDEX_RECOVERY + "." + + IndexRecoveryResolver.Fields.SHARDS, }; for (SearchHit searchHit : response.getHits().getHits()) { diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/audit/index/IndexAuditTrail.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/audit/index/IndexAuditTrail.java index b71456d7dbe..d5445dd5cc7 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/audit/index/IndexAuditTrail.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/audit/index/IndexAuditTrail.java @@ -41,7 +41,6 @@ import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.node.Node; @@ -937,25 +936,25 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl } interface Field { - XContentBuilderString TIMESTAMP = new XContentBuilderString("@timestamp"); - XContentBuilderString NODE_NAME = new XContentBuilderString("node_name"); - XContentBuilderString NODE_HOST_NAME = new XContentBuilderString("node_host_name"); - XContentBuilderString NODE_HOST_ADDRESS = new XContentBuilderString("node_host_address"); - XContentBuilderString LAYER = new XContentBuilderString("layer"); - XContentBuilderString TYPE = new XContentBuilderString("event_type"); - XContentBuilderString ORIGIN_ADDRESS = new XContentBuilderString("origin_address"); - XContentBuilderString ORIGIN_TYPE = new XContentBuilderString("origin_type"); - XContentBuilderString PRINCIPAL = new XContentBuilderString("principal"); - XContentBuilderString RUN_AS_PRINCIPAL = new XContentBuilderString("run_as_principal"); - XContentBuilderString RUN_BY_PRINCIPAL = new XContentBuilderString("run_by_principal"); - XContentBuilderString ACTION = new XContentBuilderString("action"); - XContentBuilderString INDICES = new XContentBuilderString("indices"); - XContentBuilderString REQUEST = new XContentBuilderString("request"); - XContentBuilderString REQUEST_BODY = new XContentBuilderString("request_body"); - XContentBuilderString URI = new XContentBuilderString("uri"); - XContentBuilderString REALM = new XContentBuilderString("realm"); - XContentBuilderString TRANSPORT_PROFILE = new XContentBuilderString("transport_profile"); - XContentBuilderString RULE = new XContentBuilderString("rule"); + String TIMESTAMP = new String("@timestamp"); + String NODE_NAME = new String("node_name"); + String NODE_HOST_NAME = new String("node_host_name"); + String NODE_HOST_ADDRESS = new String("node_host_address"); + String LAYER = new String("layer"); + String TYPE = new String("event_type"); + String ORIGIN_ADDRESS = new String("origin_address"); + String ORIGIN_TYPE = new String("origin_type"); + String PRINCIPAL = new String("principal"); + String RUN_AS_PRINCIPAL = new String("run_as_principal"); + String RUN_BY_PRINCIPAL = new String("run_by_principal"); + String ACTION = new String("action"); + String INDICES = new String("indices"); + String REQUEST = new String("request"); + String REQUEST_BODY = new String("request_body"); + String URI = new String("uri"); + String REALM = new String("realm"); + String TRANSPORT_PROFILE = new String("transport_profile"); + String RULE = new String("rule"); } public enum State { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/SentMessages.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/SentMessages.java index a21b2c45eba..fd9b0443032 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/SentMessages.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/SentMessages.java @@ -8,7 +8,6 @@ package org.elasticsearch.watcher.actions.hipchat.service; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.watcher.support.http.HttpRequest; import org.elasticsearch.watcher.support.http.HttpResponse; @@ -65,7 +64,7 @@ public class SentMessages implements ToXContent, Iterable Date: Mon, 18 Apr 2016 14:54:14 -0700 Subject: [PATCH 03/23] Replace more occurences of new String(CONSTANT) with CONSTANT Original commit: elastic/x-pack-elasticsearch@339de6350ff5358649f6ab6464063ffa762c9c28 --- .../marvel/agent/resolver/cluster/ClusterStateResolver.java | 2 +- .../marvel/agent/resolver/cluster/ClusterStatsResolver.java | 2 +- .../marvel/agent/resolver/cluster/DiscoveryNodeResolver.java | 2 +- .../marvel/agent/resolver/indices/IndexRecoveryResolver.java | 2 +- .../marvel/agent/resolver/indices/IndexStatsResolver.java | 2 +- .../marvel/agent/resolver/indices/IndicesStatsResolver.java | 2 +- .../marvel/agent/resolver/node/NodeStatsResolver.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateResolver.java index 54a5a1650e3..54cff93720f 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateResolver.java @@ -57,7 +57,7 @@ public class ClusterStateResolver extends MonitoringIndexNameResolver.Timestampe } static final class Fields { - static final String CLUSTER_STATE = new String(TYPE); + static final String CLUSTER_STATE = TYPE; static final String STATUS = "status"; } } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolver.java index d995f7901b7..de81f68b22b 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolver.java @@ -63,6 +63,6 @@ public class ClusterStatsResolver extends MonitoringIndexNameResolver.Timestampe } static final class Fields { - static final String CLUSTER_STATS = new String(TYPE); + static final String CLUSTER_STATS = TYPE; } } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/DiscoveryNodeResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/DiscoveryNodeResolver.java index 2ba482ae41f..4a5df234572 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/DiscoveryNodeResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/DiscoveryNodeResolver.java @@ -54,7 +54,7 @@ public class DiscoveryNodeResolver extends MonitoringIndexNameResolver.Data Date: Tue, 19 Apr 2016 08:41:47 +0200 Subject: [PATCH 04/23] Use underscore notation for field names Relates elastic/elasticsearchelastic/elasticsearch#17800 Original commit: elastic/x-pack-elasticsearch@1f6022116cbb325d20359b36e866b8bc905c98d3 --- .../watcher/actions/pagerduty/PagerDutyActionTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionTests.java index 51cd7a4c04c..0010c90303b 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionTests.java @@ -158,7 +158,7 @@ public class PagerDutyActionTests extends ESTestCase { TextTemplate eventType = null; if (randomBoolean()) { eventType = TextTemplate.inline(randomFrom("trigger", "resolve", "acknowledge")).build(); - builder.field("eventType", eventType); + builder.field("event_type", eventType); } Boolean attachPayload = randomBoolean() ? null : randomBoolean(); From 0c7dff4fa72f86d94437e1b78797183e5e481666 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 19 Apr 2016 11:23:04 +0200 Subject: [PATCH 05/23] security: Deal with upstream percolator changes. From now on, if field level security and percolator is used then the percolator field needs to be included in the allowed fields. Original commit: elastic/x-pack-elasticsearch@7d39b5caf68f19f655bc5f6058acad62f3baf652 --- .../ShieldIndexSearcherWrapper.java | 10 +--------- .../DocumentLevelSecurityTests.java | 18 +++++++++--------- .../integration/FieldLevelSecurityTests.java | 12 ++++++------ 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java index 83229f46b44..0fcae47b741 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java @@ -33,6 +33,7 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.cache.bitset.BitsetFilterCache; import org.elasticsearch.index.engine.EngineException; import org.elasticsearch.index.mapper.DocumentMapper; +import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.internal.ParentFieldMapper; import org.elasticsearch.index.percolator.PercolatorFieldMapper; @@ -135,7 +136,6 @@ public class ShieldIndexSearcherWrapper extends IndexSearcherWrapper { allowedFields.addAll(mapperService.simpleMatchToIndexNames(field)); } resolveParentChildJoinFields(allowedFields); - resolvePercolatorFields(allowedFields); reader = FieldSubsetReader.wrap(reader, allowedFields); } @@ -240,14 +240,6 @@ public class ShieldIndexSearcherWrapper extends IndexSearcherWrapper { } } - private void resolvePercolatorFields(Set allowedFields) { - if (mapperService.hasMapping(PercolatorFieldMapper.TYPE_NAME)) { - allowedFields.add(PercolatorFieldMapper.EXTRACTED_TERMS_FULL_FIELD_NAME); - allowedFields.add(PercolatorFieldMapper.UNKNOWN_QUERY_FULL_FIELD_NAME); - allowedFields.add(PercolatorFieldMapper.EXTRACTED_TERMS_FULL_FIELD_NAME); - } - } - static void intersectScorerAndRoleBits(Scorer scorer, SparseFixedBitSet roleBits, LeafCollector collector, Bits acceptDocs) throws IOException { // ConjunctionDISI uses the DocIdSetIterator#cost() to order the iterators, so if roleBits has the lowest cardinality it should diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java index 1b02791285e..1f2e9c2efcf 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java @@ -607,9 +607,9 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { public void testPercolateApi() { assertAcked(client().admin().indices().prepareCreate("test") - .addMapping(".percolator", "field1", "type=text", "field2", "type=text", "field3", "type=text") + .addMapping("query", "query", "type=percolator", "field1", "type=text", "field2", "type=text", "field3", "type=text") ); - client().prepareIndex("test", ".percolator", "1") + client().prepareIndex("test", "query", "1") .setSource("{\"query\" : { \"match_all\" : {} }, \"field1\" : \"value1\"}") .setRefresh(true) .get(); @@ -618,7 +618,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { PercolateResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .preparePercolate() - .setDocumentType("type") + .setDocumentType("query") .setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc("{}")) .get(); assertThat(response.getCount(), equalTo(1L)); @@ -627,7 +627,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .preparePercolate() - .setDocumentType("type") + .setDocumentType("query") .setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc("{}")) .get(); assertThat(response.getCount(), equalTo(0L)); @@ -635,7 +635,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) .preparePercolate() - .setDocumentType("type") + .setDocumentType("query") .setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc("{}")) .get(); assertThat(response.getCount(), equalTo(1L)); @@ -645,7 +645,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { // match: response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .preparePercolate() - .setDocumentType("type") + .setDocumentType("query") .setPercolateQuery(termQuery("field1", "value1")) .setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc("{}")) .get(); @@ -656,7 +656,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { // is no match: response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .preparePercolate() - .setDocumentType("type") + .setDocumentType("query") .setPercolateQuery(termQuery("field1", "value1")) .setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc("{}")) .get(); @@ -664,7 +664,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) .preparePercolate() - .setDocumentType("type") + .setDocumentType("query") .setPercolateQuery(termQuery("field1", "value1")) .setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc("{}")) .get(); @@ -678,7 +678,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { // Ensure that the query loading that happens at startup has permissions to load the percolator queries: response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .preparePercolate() - .setDocumentType("type") + .setDocumentType("query") .setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc("{}")) .get(); assertThat(response.getCount(), equalTo(1L)); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java index 1585d33b9e4..40081fdf81f 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java @@ -97,7 +97,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { " indices:\n" + " - names: '*'\n" + " privileges: [ ALL ]\n" + - " fields: [ field2 ]\n" + + " fields: [ field2, query* ]\n" + "role4:\n" + " cluster: [ all ]\n" + " indices:\n" + @@ -1122,9 +1122,9 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { public void testPercolateApi() { assertAcked(client().admin().indices().prepareCreate("test") - .addMapping(".percolator", "field1", "type=text", "field2", "type=text") + .addMapping("query", "query", "type=percolator", "field1", "type=text", "field2", "type=text") ); - client().prepareIndex("test", ".percolator", "1") + client().prepareIndex("test", "query", "1") .setSource("{\"query\" : { \"match_all\" : {} }, \"field1\" : \"value1\"}") .setRefresh(true) .get(); @@ -1133,7 +1133,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { PercolateResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .preparePercolate() - .setDocumentType("type") + .setDocumentType("query") .setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc("{}")) .get(); assertThat(response.getCount(), equalTo(1L)); @@ -1143,7 +1143,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { // no match: response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .preparePercolate() - .setDocumentType("type") + .setDocumentType("query") .setPercolateQuery(termQuery("field1", "value1")) .setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc("{}")) .get(); @@ -1156,7 +1156,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { // Ensure that the query loading that happens at startup has permissions to load the percolator queries: response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .preparePercolate() - .setDocumentType("type") + .setDocumentType("query") .setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc("{}")) .get(); assertThat(response.getCount(), equalTo(1L)); From 98feb695ffb9e1144c5be73a1fd755ef176a3048 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 19 Apr 2016 13:56:50 +0200 Subject: [PATCH 06/23] Tests: Fixing failing history transform tests after mapping changes Original commit: elastic/x-pack-elasticsearch@b1b13c52b0486216b3a72da0560c69cb76f3949c --- .../HistoryTemplateTransformMappingsIT.java | 47 +++++-------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/HistoryTemplateTransformMappingsIT.java b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/HistoryTemplateTransformMappingsIT.java index 52ab0b7bff4..7bd46be6616 100644 --- a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/HistoryTemplateTransformMappingsIT.java +++ b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/HistoryTemplateTransformMappingsIT.java @@ -5,21 +5,17 @@ */ package org.elasticsearch.messy.tests; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; -import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse; +import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetaData; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.groovy.GroovyPlugin; import org.elasticsearch.watcher.execution.ExecutionState; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse; -import java.io.IOException; import java.util.List; import java.util.Map; -import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue; import static org.elasticsearch.watcher.actions.ActionBuilders.loggingAction; import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder; import static org.elasticsearch.watcher.condition.ConditionBuilders.alwaysCondition; @@ -27,13 +23,9 @@ import static org.elasticsearch.watcher.input.InputBuilders.simpleInput; import static org.elasticsearch.watcher.transform.TransformBuilders.scriptTransform; import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule; import static org.elasticsearch.watcher.trigger.schedule.Schedules.interval; +import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -/** - * This test makes sure that the http host and path fields in the watch_record action result are - * not analyzed so they can be used in aggregations - */ public class HistoryTemplateTransformMappingsIT extends AbstractWatcherIntegrationTestCase { @Override @@ -91,29 +83,16 @@ public class HistoryTemplateTransformMappingsIT extends AbstractWatcherIntegrati refresh(); - assertBusy(new Runnable() { - @Override - public void run() { - GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings().get(); - assertThat(mappingsResponse, notNullValue()); - assertThat(mappingsResponse.getMappings().isEmpty(), is(false)); - for (ObjectObjectCursor> metadatas : mappingsResponse.getMappings()) { - if (!metadatas.key.startsWith(".watcher-history")) { - continue; - } - MappingMetaData metadata = metadatas.value.get("watch_record"); - assertThat(metadata, notNullValue()); - try { - Map source = metadata.getSourceAsMap(); - logger.info("checking index [{}] with metadata:\n[{}]", metadatas.key, metadata.source().toString()); - assertThat(extractValue("properties.result.properties.transform.properties.payload.enabled", source), - is((Object) false)); - String path = "properties.result.properties.actions.properties.transform.properties.payload.enabled"; - assertThat(extractValue(path, source), is((Object) false)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + assertBusy(() -> { + GetFieldMappingsResponse getFieldMappingsResponse = client().admin().indices() + .prepareGetFieldMappings(".watcher-history*").setFields("result.actions.transform.payload") + .setTypes("watch_record").includeDefaults(true).get(); + + for (Map> map : getFieldMappingsResponse.mappings().values()) { + Map watchRecord = map.get("watch_record"); + assertThat(watchRecord, hasKey("result.actions.transform.payload")); + FieldMappingMetaData fieldMappingMetaData = watchRecord.get("result.actions.transform.payload"); + assertThat(fieldMappingMetaData.isNull(), is(true)); } }); } From e24d09b54e6fec90d86f62b657266a8776b7d091 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 19 Apr 2016 14:11:38 +0200 Subject: [PATCH 07/23] test: allow percolate api to fail when the percolator field can't be found Original commit: elastic/x-pack-elasticsearch@3343c9dc3a7d5ab09bbcdae5ce761c8141f0be0c --- .../integration/IndexPrivilegeTests.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/IndexPrivilegeTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/IndexPrivilegeTests.java index 8dd3ccbf4e5..eb669f0e5d2 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/IndexPrivilegeTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/IndexPrivilegeTests.java @@ -18,6 +18,7 @@ import java.util.Locale; import java.util.Map; import static java.util.Collections.singletonMap; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; //test is just too slow, please fix it to not be sleep-based @@ -312,11 +313,11 @@ public class IndexPrivilegeTests extends AbstractPrivilegeTestCase { switch (action) { case "all" : if (userIsAllowed) { - assertUserIsAllowed(user, "manage", index); assertUserIsAllowed(user, "crud", index); + assertUserIsAllowed(user, "manage", index); } else { - assertUserIsDenied(user, "manage", index); assertUserIsDenied(user, "crud", index); + assertUserIsDenied(user, "manage", index); } break; @@ -404,7 +405,11 @@ public class IndexPrivilegeTests extends AbstractPrivilegeTestCase { assertAccessIsAllowed("admin", "GET", "/" + index + "/foo/1"); assertAccessIsAllowed(user, "GET", "/" + index + "/foo/1/_explain", "{ \"query\" : { \"match_all\" : {} } }"); assertAccessIsAllowed(user, "GET", "/" + index + "/foo/1/_termvector"); - assertAccessIsAllowed(user, "GET", "/" + index + "/foo/_percolate", "{ \"doc\" : { \"foo\" : \"bar\" } }"); + try { + assertAccessIsAllowed(user, "GET", "/" + index + "/foo/_percolate", "{ \"doc\" : { \"foo\" : \"bar\" } }"); + } catch (Throwable e) { + assertThat(e.getMessage(), containsString("field [query] does not exist")); + } assertAccessIsAllowed(user, "GET", "/" + index + "/_suggest", "{ \"sgs\" : { \"text\" : \"foo\", \"term\" : { \"field\" : \"body\" } } }"); assertAccessIsAllowed(user, "GET", @@ -417,7 +422,11 @@ public class IndexPrivilegeTests extends AbstractPrivilegeTestCase { multiPercolate.append("{\"doc\" : {\"message\" : \"some text\"}}\n"); multiPercolate.append("{\"percolate\" : {\"index\" : \"" + index + "\", \"type\" : \"foo\", \"id\" : \"1\"}}\n"); multiPercolate.append("{}\n"); - assertAccessIsAllowed(user, "GET", "/" + index + "/foo/_mpercolate", multiPercolate.toString()); + try { + assertAccessIsAllowed(user, "GET", "/" + index + "/foo/_mpercolate", multiPercolate.toString()); + } catch (Throwable e) { + assertThat(e.getMessage(), containsString("field [query] does not exist")); + } assertUserIsAllowed(user, "search", index); } else { From 962729bd3b341a080b6a892edf22544028e03fa6 Mon Sep 17 00:00:00 2001 From: PhaedrusTheGreek Date: Mon, 18 Apr 2016 15:18:39 -0400 Subject: [PATCH 08/23] Changed LDAP searches to NOATTRS in order to avoid returning unecessary data in searches where only getDn() is done on results Original commit: elastic/x-pack-elasticsearch@5ce64235a195c63ff668856095340a96960057ba --- .../authc/activedirectory/ActiveDirectoryGroupsResolver.java | 2 +- .../authc/activedirectory/ActiveDirectorySessionFactory.java | 2 +- .../shield/authc/ldap/LdapUserSearchSessionFactory.java | 2 +- .../elasticsearch/shield/authc/ldap/SearchGroupsResolver.java | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectoryGroupsResolver.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectoryGroupsResolver.java index 5216905597c..5f71e1fcbb0 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectoryGroupsResolver.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectoryGroupsResolver.java @@ -45,7 +45,7 @@ public class ActiveDirectoryGroupsResolver implements GroupsResolver { Filter groupSearchFilter = buildGroupQuery(connection, userDn, timeout, logger); logger.debug("group SID to DN search filter: [{}]", groupSearchFilter); - SearchRequest searchRequest = new SearchRequest(baseDn, scope.scope(), groupSearchFilter, Strings.EMPTY_ARRAY); + SearchRequest searchRequest = new SearchRequest(baseDn, scope.scope(), groupSearchFilter, SearchRequest.NO_ATTRIBUTES); searchRequest.setTimeLimitSeconds(Math.toIntExact(timeout.seconds())); SearchResult results; try { diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectorySessionFactory.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectorySessionFactory.java index 37f6f1e685e..3648bd9d3cb 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectorySessionFactory.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectorySessionFactory.java @@ -89,7 +89,7 @@ public class ActiveDirectorySessionFactory extends SessionFactory { try { connection.bind(userPrincipal, new String(password.internalChars())); SearchRequest searchRequest = new SearchRequest(userSearchDN, userSearchScope.scope(), - createFilter(userSearchFilter, userName), Strings.EMPTY_ARRAY); + createFilter(userSearchFilter, userName), SearchRequest.NO_ATTRIBUTES); searchRequest.setTimeLimitSeconds(Math.toIntExact(timeout.seconds())); SearchResult results = search(connection, searchRequest, logger); int numResults = results.getEntryCount(); diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/ldap/LdapUserSearchSessionFactory.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/ldap/LdapUserSearchSessionFactory.java index 89848da5a6f..0acb7b10088 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/ldap/LdapUserSearchSessionFactory.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/ldap/LdapUserSearchSessionFactory.java @@ -152,7 +152,7 @@ public class LdapUserSearchSessionFactory extends SessionFactory { private String findUserDN(String user) throws Exception { SearchRequest request = new SearchRequest(userSearchBaseDn, scope.scope(), createEqualityFilter(userAttribute, encodeValue(user)) - , Strings.EMPTY_ARRAY); + , SearchRequest.NO_ATTRIBUTES); request.setTimeLimitSeconds(Math.toIntExact(timeout.seconds())); LDAPConnectionPool connectionPool = connectionPool(); SearchResultEntry entry = searchForEntry(connectionPool, request, logger); diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/ldap/SearchGroupsResolver.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/ldap/SearchGroupsResolver.java index 904dc0205eb..776237e1bbc 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/ldap/SearchGroupsResolver.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/ldap/SearchGroupsResolver.java @@ -58,7 +58,8 @@ class SearchGroupsResolver implements GroupsResolver { String userId = userAttribute != null ? readUserAttribute(connection, userDn, timeout, logger) : userDn; try { - SearchRequest searchRequest = new SearchRequest(baseDn, scope.scope(), createFilter(filter, userId), Strings.EMPTY_ARRAY); + SearchRequest searchRequest = new SearchRequest(baseDn, scope.scope(), createFilter(filter, userId), + SearchRequest.NO_ATTRIBUTES); searchRequest.setTimeLimitSeconds(Math.toIntExact(timeout.seconds())); SearchResult results = search(connection, searchRequest, logger); for (SearchResultEntry entry : results.getSearchEntries()) { From 28bb39955c0aa3589f2f702dced89ce56589ab42 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 19 Apr 2016 11:06:39 -0400 Subject: [PATCH 09/23] Replace (read|write)Query with (read|write)NamedWriteable (read|write)Query is going away. Original commit: elastic/x-pack-elasticsearch@5ac3ded68e01ef9a1ec1846b19b914b357fc5829 --- .../org/elasticsearch/graph/action/Hop.java | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/Hop.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/Hop.java index 68dcfe03482..598d0cfc792 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/Hop.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/Hop.java @@ -21,22 +21,22 @@ import java.util.List; * A Hop represents one of potentially many stages in a graph exploration. * Each Hop identifies one or more fields in which it will attempt to find * terms that are significantly connected to the previous Hop. Each field is identified - * using a {@link VertexRequest} - * + * using a {@link VertexRequest} + * *

An example series of Hops on webserver logs would be: *

    - *
  1. an initial Hop to find + *
  2. an initial Hop to find * the top ten IPAddresses trying to access urls containing the word "admin"
  3. *
  4. a secondary Hop to see which other URLs those IPAddresses were trying to access
  5. - *
- * + * + * *

* Optionally, each hop can contain a "guiding query" that further limits the set of documents considered. - * In our weblog example above we might choose to constrain the second hop to only look at log records that + * In our weblog example above we might choose to constrain the second hop to only look at log records that * had a reponse code of 404. *

*

- * If absent, the list of {@link VertexRequest}s is inherited from the prior Hop's list to avoid repeating + * If absent, the list of {@link VertexRequest}s is inherited from the prior Hop's list to avoid repeating * the fields that will be examined at each stage. *

* @@ -64,12 +64,7 @@ public class Hop { } void writeTo(StreamOutput out) throws IOException { - if (guidingQuery == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeQuery(guidingQuery); - } + out.writeOptionalNamedWriteable(guidingQuery); if (vertices == null) { out.writeVInt(0); } else { @@ -81,9 +76,7 @@ public class Hop { } void readFrom(StreamInput in) throws IOException { - if (in.readBoolean()) { - guidingQuery = in.readQuery(); - } + guidingQuery = in.readOptionalNamedWriteable(QueryBuilder.class); int size = in.readVInt(); if (size > 0) { vertices = new ArrayList<>(); @@ -103,9 +96,9 @@ public class Hop { } /** - * Add a field in which this {@link Hop} will look for terms that are highly linked to - * previous hops and optionally the guiding query. - * + * Add a field in which this {@link Hop} will look for terms that are highly linked to + * previous hops and optionally the guiding query. + * * @param fieldName a field in the chosen index */ public VertexRequest addVertexRequest(String fieldName) { @@ -120,8 +113,8 @@ public class Hop { /** * An optional parameter that focuses the exploration on documents that - * match the given query. - * + * match the given query. + * * @param queryBuilder any query */ public void guidingQuery(QueryBuilder queryBuilder) { @@ -146,4 +139,4 @@ public class Hop { VertexRequest getVertexRequest(int requestNumber) { return getEffectiveVertexRequests().get(requestNumber); } -} \ No newline at end of file +} From 659439841e1b93fd7b1d6083fa039b0f8c264819 Mon Sep 17 00:00:00 2001 From: jaymode Date: Tue, 19 Apr 2016 14:31:06 -0400 Subject: [PATCH 10/23] test: adapt to removal of setting Original commit: elastic/x-pack-elasticsearch@5f195001b93f90e20ad25e87462f6e3ddb11ca2a --- .../integration/DocumentLevelSecurityTests.java | 8 ++++---- .../integration/FieldLevelSecurityTests.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java index 1f2e9c2efcf..db7d5d3048e 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java @@ -156,7 +156,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { client().prepareIndex("test", "type1", "3").setSource("field3", "value3").get(); // test documents users can see - Boolean realtime = randomFrom(true, false, null); + boolean realtime = randomBoolean(); GetResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareGet("test", "type1", "1") @@ -220,7 +220,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { client().prepareIndex("test", "type1", "2").setSource("field2", "value2").get(); client().prepareIndex("test", "type1", "3").setSource("field3", "value3").get(); - Boolean realtime = randomFrom(true, false, null); + boolean realtime = randomBoolean(); MultiGetResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareMultiGet() @@ -300,7 +300,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { .setRefresh(true) .get(); - Boolean realtime = randomFrom(true, false, null); + boolean realtime = randomBoolean(); TermVectorsResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareTermVectors("test", "type1", "1") @@ -365,7 +365,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { .setRefresh(true) .get(); - Boolean realtime = randomFrom(true, false, null); + boolean realtime = randomBoolean(); MultiTermVectorsResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareMultiTermVectors() diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java index 40081fdf81f..0fab8e01be1 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java @@ -281,7 +281,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3") .get(); - Boolean realtime = randomFrom(true, false, null); + boolean realtime = randomBoolean(); // user1 is granted access to field1 only: GetResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) @@ -377,7 +377,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3").get(); - Boolean realtime = randomFrom(true, false, null); + boolean realtime = randomBoolean(); // user1 is granted access to field1 only: MultiGetResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) @@ -954,7 +954,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { .setRefresh(true) .get(); - Boolean realtime = randomFrom(true, false, null); + boolean realtime = randomBoolean(); TermVectorsResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareTermVectors("test", "type1", "1") @@ -1038,7 +1038,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { .setRefresh(true) .get(); - Boolean realtime = randomFrom(true, false, null); + boolean realtime = randomBoolean(); MultiTermVectorsResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareMultiTermVectors() From 5c9d96211ff9ae16883a05fd8171a0162b0508a9 Mon Sep 17 00:00:00 2001 From: uboness Date: Mon, 18 Apr 2016 12:36:07 +0200 Subject: [PATCH 11/23] Extended X-Pack Info API with Features Info - introduced the "Feature Set" notion - graph, security, monitoring, watcher, these are all feature sets - each feature set can be: - `available` - indicates whether this feature set is available under the current license - `enabled` - indicates whether this feature set is enabled (note that the feature set can be enabled, yet unavailable under the current license) - while at it, cleaned up the main modules of watcher, security, monitoring and graph. Original commit: elastic/x-pack-elasticsearch@5b3e19fe8ce82d22269ec0c270a8a955a8568f73 --- .../java/org/elasticsearch/graph/Graph.java | 43 ++--- .../elasticsearch/graph/GraphFeatureSet.java | 46 +++++ .../graph/{license => }/GraphLicensee.java | 5 +- .../org/elasticsearch/graph/GraphModule.java | 35 ++++ .../action/TransportGraphExploreAction.java | 4 +- .../graph/license/LicenseTests.java | 5 +- .../elasticsearch/graph/test/GraphTests.java | 4 +- .../AbstractLicensesIntegrationTestCase.java | 4 +- .../elasticsearch/marvel/MarvelModule.java | 20 --- .../marvel/{Marvel.java => Monitoring.java} | 30 ++-- .../marvel/MonitoringFeatureSet.java | 46 +++++ ...lLicensee.java => MonitoringLicensee.java} | 21 ++- .../marvel/MonitoringModule.java | 37 ++++ ...lSettings.java => MonitoringSettings.java} | 8 +- .../marvel/agent/AgentService.java | 8 +- .../agent/collector/AbstractCollector.java | 12 +- .../cluster/ClusterStateCollector.java | 10 +- .../cluster/ClusterStatsCollector.java | 10 +- .../indices/IndexRecoveryCollector.java | 16 +- .../indices/IndexStatsCollector.java | 14 +- .../indices/IndicesStatsCollector.java | 14 +- .../collector/node/NodeStatsCollector.java | 10 +- .../collector/shards/ShardsCollector.java | 13 +- .../marvel/agent/exporter/Exporter.java | 4 +- .../marvel/agent/exporter/Exporters.java | 6 +- .../marvel/cleaner/CleanerService.java | 21 +-- .../marvel/license/LicenseModule.java | 17 -- .../marvel/MarvelPluginClientTests.java | 9 +- .../marvel/MarvelPluginTests.java | 8 +- .../marvel/MarvelSettingsTests.java | 14 +- .../TransportMonitoringBulkActionTests.java | 6 +- .../collector/AbstractCollectorTestCase.java | 8 +- .../cluster/ClusterStateCollectorTests.java | 8 +- .../cluster/ClusterStatsCollectorTests.java | 8 +- .../indices/IndexRecoveryCollectorTests.java | 22 +-- .../indices/IndexStatsCollectorTests.java | 12 +- .../indices/IndicesStatsCollectorTests.java | 12 +- .../node/NodeStatsCollectorTests.java | 8 +- .../shards/ShardsCollectorTests.java | 10 +- .../AbstractExporterTemplateTestCase.java | 4 +- .../marvel/agent/exporter/ExportersTests.java | 8 +- .../exporter/http/HttpExporterTests.java | 14 +- .../exporter/local/LocalExporterTests.java | 4 +- .../resolver/cluster/ClusterInfoTests.java | 6 +- .../resolver/cluster/ClusterStateTests.java | 6 +- .../resolver/cluster/ClusterStatsTests.java | 6 +- .../resolver/indices/IndexRecoveryTests.java | 8 +- .../resolver/indices/IndexStatsTests.java | 6 +- .../resolver/indices/IndicesStatsTests.java | 7 +- .../resolver/node/MultiNodesStatsTests.java | 4 +- .../agent/resolver/node/NodeStatsTests.java | 6 +- .../agent/resolver/shards/ShardsTests.java | 9 +- .../agent/settings/MarvelSettingsTests.java | 86 ++++----- .../AbstractIndicesCleanerTestCase.java | 8 +- .../marvel/cleaner/CleanerServiceTests.java | 20 +-- .../license/LicenseIntegrationTests.java | 9 +- .../marvel/license/MarvelLicenseeTests.java | 21 +-- .../shield/MarvelInternalClientTests.java | 4 +- .../shield/MarvelSettingsFilterTests.java | 4 +- .../marvel/test/MarvelIntegTestCase.java | 4 +- .../org/elasticsearch/shield/Security.java | 73 ++++---- .../shield/SecurityFeatureSet.java | 46 +++++ ...seState.java => SecurityLicenseState.java} | 6 +- ...eldLicensee.java => SecurityLicensee.java} | 9 +- .../elasticsearch/shield/SecurityModule.java | 53 ++++++ .../shield/ShieldDisabledModule.java | 32 ---- .../elasticsearch/shield/ShieldModule.java | 30 ---- .../action/filter/ShieldActionFilter.java | 6 +- .../elasticsearch/shield/authc/Realms.java | 6 +- .../ShieldIndexSearcherWrapper.java | 9 +- .../shield/license/LicenseModule.java | 29 --- .../shield/rest/ShieldRestFilter.java | 6 +- .../ShieldServerTransportService.java | 10 +- .../shield/transport/filter/IPFilter.java | 6 +- .../ShieldLicenseStateTests.java | 18 +- .../{license => }/ShieldLicenseeTests.java | 16 +- .../shield/ShieldPluginTests.java | 4 +- .../filter/ShieldActionFilterTests.java | 6 +- .../InternalAuthenticationServiceTests.java | 4 +- .../shield/authc/RealmsTests.java | 6 +- ...dIndexSearcherWrapperIntegrationTests.java | 4 +- .../ShieldIndexSearcherWrapperUnitTests.java | 6 +- .../shield/rest/ShieldRestFilterTests.java | 6 +- .../transport/TransportFilterTests.java | 5 +- .../transport/filter/IPFilterTests.java | 6 +- .../IPFilterNettyUpstreamHandlerTests.java | 4 +- .../test/ShieldSettingsSource.java | 4 +- .../elasticsearch/xpack/XPackFeatureSet.java} | 17 +- .../org/elasticsearch/xpack/XPackPlugin.java | 30 ++-- .../action/TransportXPackInfoAction.java | 38 +++- .../xpack/action/XPackInfoRequest.java | 57 ++++++ .../xpack/action/XPackInfoRequestBuilder.java | 13 ++ .../xpack/action/XPackInfoResponse.java | 143 +++++++++++++-- .../{ => action}/RestXPackInfoAction.java | 36 +++- .../action/TransportXPackInfoActionTests.java | 71 +++++++- .../rest-api-spec/api/xpack.info.json | 11 +- .../rest-api-spec/test/xpack/15_basic.yaml | 105 ++++++++++- .../org/elasticsearch/watcher/Watcher.java | 39 ++-- .../watcher/WatcherFeatureSet.java | 46 +++++ .../{license => }/WatcherLicensee.java | 40 +++-- .../elasticsearch/watcher/WatcherModule.java | 18 +- .../watcher/actions/ActionRegistry.java | 2 +- .../watcher/actions/ActionWrapper.java | 2 +- .../actions/throttler/ActionThrottler.java | 2 +- .../watcher/license/LicenseModule.java | 20 --- .../actions/WatcherTransportAction.java | 2 +- .../actions/ack/TransportAckWatchAction.java | 2 +- .../TransportActivateWatchAction.java | 2 +- .../delete/TransportDeleteWatchAction.java | 2 +- .../execute/TransportExecuteWatchAction.java | 2 +- .../actions/get/TransportGetWatchAction.java | 2 +- .../actions/put/TransportPutWatchAction.java | 2 +- .../TransportWatcherServiceAction.java | 2 +- .../stats/TransportWatcherStatsAction.java | 2 +- .../watcher/WatcherPluginDisableTests.java | 4 +- .../throttler/WatchThrottlerTests.java | 2 +- .../watcher/license/LicenseTests.java | 1 + .../AbstractWatcherIntegrationTestCase.java | 166 ++++++++---------- .../HttpSecretsIntegrationTests.java | 1 + .../watcher/watch/WatchTests.java | 3 +- 120 files changed, 1341 insertions(+), 786 deletions(-) create mode 100644 elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/GraphFeatureSet.java rename elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/{license => }/GraphLicensee.java (95%) create mode 100644 elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/GraphModule.java delete mode 100644 elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MarvelModule.java rename elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/{Marvel.java => Monitoring.java} (83%) create mode 100644 elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringFeatureSet.java rename elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/{license/MarvelLicensee.java => MonitoringLicensee.java} (88%) create mode 100644 elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringModule.java rename elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/{MarvelSettings.java => MonitoringSettings.java} (96%) delete mode 100644 elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/license/LicenseModule.java create mode 100644 elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityFeatureSet.java rename elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/{license/ShieldLicenseState.java => SecurityLicenseState.java} (95%) rename elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/{license/ShieldLicensee.java => SecurityLicensee.java} (90%) create mode 100644 elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityModule.java delete mode 100644 elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldDisabledModule.java delete mode 100644 elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldModule.java delete mode 100644 elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/LicenseModule.java rename elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/{license => }/ShieldLicenseStateTests.java (86%) rename elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/{license => }/ShieldLicenseeTests.java (84%) rename elasticsearch/x-pack/{graph/src/main/java/org/elasticsearch/graph/license/GraphModule.java => src/main/java/org/elasticsearch/xpack/XPackFeatureSet.java} (50%) rename elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/rest/{ => action}/RestXPackInfoAction.java (61%) create mode 100644 elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherFeatureSet.java rename elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/{license => }/WatcherLicensee.java (87%) delete mode 100644 elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/license/LicenseModule.java diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/Graph.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/Graph.java index a44c990ab80..4b9a338fe4b 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/Graph.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/Graph.java @@ -5,10 +5,6 @@ */ package org.elasticsearch.graph; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - import org.elasticsearch.action.ActionModule; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; @@ -18,12 +14,13 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.graph.action.GraphExploreAction; import org.elasticsearch.graph.action.TransportGraphExploreAction; -import org.elasticsearch.graph.license.GraphLicensee; -import org.elasticsearch.graph.license.GraphModule; import org.elasticsearch.graph.rest.action.RestGraphAction; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.xpack.XPackPlugin; +import java.util.Collection; +import java.util.Collections; + public class Graph extends Plugin { public static final String NAME = "graph"; @@ -48,8 +45,20 @@ public class Graph extends Plugin { public static boolean enabled(Settings settings) { return XPackPlugin.featureEnabled(settings, NAME, true); - } - + } + + public Collection nodeModules() { + return Collections.singletonList(new GraphModule(enabled, transportClientMode)); + } + + @Override + public Collection> nodeServices() { + if (enabled == false|| transportClientMode) { + return Collections.emptyList(); + } + return Collections.singletonList(GraphLicensee.class); + } + public void onModule(ActionModule actionModule) { if (enabled) { actionModule.registerAction(GraphExploreAction.INSTANCE, TransportGraphExploreAction.class); @@ -65,23 +74,5 @@ public class Graph extends Plugin { public void onModule(SettingsModule module) { module.registerSetting(Setting.boolSetting(XPackPlugin.featureEnabledSetting(NAME), true, Setting.Property.NodeScope)); } - - public Collection nodeModules() { - if (enabled == false|| transportClientMode) { - return Collections.emptyList(); - } - return Arrays. asList(new GraphModule()); - } - - @Override - public Collection> nodeServices() { - if (enabled == false|| transportClientMode) { - return Collections.emptyList(); - } - return Arrays.>asList( - GraphLicensee.class - ); - } - } diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/GraphFeatureSet.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/GraphFeatureSet.java new file mode 100644 index 00000000000..ea0fdf18e7c --- /dev/null +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/GraphFeatureSet.java @@ -0,0 +1,46 @@ +/* + * 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.graph; + +import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.xpack.XPackFeatureSet; + +/** + * + */ +public class GraphFeatureSet implements XPackFeatureSet { + + private final boolean enabled; + private final GraphLicensee licensee; + + @Inject + public GraphFeatureSet(Settings settings, @Nullable GraphLicensee licensee) { + this.enabled = Graph.enabled(settings); + this.licensee = licensee; + } + + @Override + public String name() { + return Graph.NAME; + } + + @Override + public String description() { + return "Graph Data Exploration for the Elastic Stack"; + } + + @Override + public boolean available() { + return licensee != null && licensee.isAvailable(); + } + + @Override + public boolean enabled() { + return enabled; + } +} diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/license/GraphLicensee.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/GraphLicensee.java similarity index 95% rename from elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/license/GraphLicensee.java rename to elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/GraphLicensee.java index 9848e4679b0..4aaec502c59 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/license/GraphLicensee.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/GraphLicensee.java @@ -3,7 +3,7 @@ * 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.graph.license; +package org.elasticsearch.graph; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; @@ -13,7 +13,6 @@ import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent; import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.LicenseeRegistry; -import org.elasticsearch.graph.Graph; public class GraphLicensee extends AbstractLicenseeComponent { @@ -60,7 +59,7 @@ public class GraphLicensee extends AbstractLicenseeComponent { * * @return {@code true} as long as the license is valid. Otherwise {@code false}. */ - public boolean isGraphExploreEnabled() { + public boolean isAvailable() { // status is volatile Status localStatus = status; OperationMode operationMode = localStatus.getMode(); diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/GraphModule.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/GraphModule.java new file mode 100644 index 00000000000..eaf145e5e9c --- /dev/null +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/GraphModule.java @@ -0,0 +1,35 @@ +/* + * 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.graph; + +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.util.Providers; +import org.elasticsearch.xpack.XPackPlugin; + +/** + * + */ +public class GraphModule extends AbstractModule { + + private final boolean enabled; + private final boolean transportClientNode; + + public GraphModule(boolean enabled, boolean transportClientNode) { + this.enabled = enabled; + this.transportClientNode = transportClientNode; + } + + @Override + protected void configure() { + XPackPlugin.bindFeatureSet(binder(), GraphFeatureSet.class); + if (enabled && transportClientNode == false) { + bind(GraphLicensee.class).asEagerSingleton(); + } else { + bind(GraphLicensee.class).toProvider(Providers.of(null)); + } + } + +} diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/TransportGraphExploreAction.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/TransportGraphExploreAction.java index b6a1af125cf..74263e9b500 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/TransportGraphExploreAction.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/TransportGraphExploreAction.java @@ -24,7 +24,7 @@ import org.elasticsearch.common.util.CollectionUtils; import org.elasticsearch.graph.action.Connection.ConnectionId; import org.elasticsearch.graph.action.GraphExploreRequest.TermBoost; import org.elasticsearch.graph.action.Vertex.VertexId; -import org.elasticsearch.graph.license.GraphLicensee; +import org.elasticsearch.graph.GraphLicensee; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.license.plugin.core.LicenseUtils; @@ -85,7 +85,7 @@ public class TransportGraphExploreAction extends HandledTransportAction listener) { - if (licensee.isGraphExploreEnabled()) { + if (licensee.isAvailable()) { new AsyncGraphAction(request, listener).start(); } else { listener.onFailure(LicenseUtils.newComplianceException(GraphLicensee.ID)); diff --git a/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/graph/license/LicenseTests.java b/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/graph/license/LicenseTests.java index ebf339b7d88..fc1084c43b9 100644 --- a/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/graph/license/LicenseTests.java +++ b/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/graph/license/LicenseTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.graph.license; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.graph.GraphLicensee; import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase; @@ -95,10 +96,10 @@ public class LicenseTests extends AbstractLicenseeTestCase { } private void assertLicensePlatinumTrialBehaviour(GraphLicensee graphLicensee) { - assertThat("Expected graph exploration to be allowed", graphLicensee.isGraphExploreEnabled(), is(true)); + assertThat("Expected graph exploration to be allowed", graphLicensee.isAvailable(), is(true)); } private void assertLicenseBasicOrGoldOrNoneOrExpiredBehaviour(GraphLicensee graphLicensee) { - assertThat("Expected graph exploration not to be allowed", graphLicensee.isGraphExploreEnabled(), is(false)); + assertThat("Expected graph exploration not to be allowed", graphLicensee.isAvailable(), is(false)); } } diff --git a/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/graph/test/GraphTests.java b/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/graph/test/GraphTests.java index 1c633cdf61a..ae41b198e26 100644 --- a/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/graph/test/GraphTests.java +++ b/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/graph/test/GraphTests.java @@ -19,7 +19,7 @@ import org.elasticsearch.graph.action.Vertex; import org.elasticsearch.graph.action.VertexRequest; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.ScriptQueryBuilder; -import org.elasticsearch.marvel.Marvel; +import org.elasticsearch.marvel.Monitoring; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.AbstractSearchScript; import org.elasticsearch.script.ExecutableScript; @@ -126,7 +126,7 @@ public class GraphTests extends ESSingleNodeTestCase { // Disable Shield otherwise authentication failures happen creating indices. Builder newSettings = Settings.builder(); newSettings.put(XPackPlugin.featureEnabledSetting(Security.NAME), false); - newSettings.put(XPackPlugin.featureEnabledSetting(Marvel.NAME), false); + newSettings.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false); newSettings.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false); return newSettings.build(); } diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTestCase.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTestCase.java index e46027d642c..be32fbb528f 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTestCase.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTestCase.java @@ -24,7 +24,7 @@ import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.LicensesManagerService; import org.elasticsearch.license.plugin.core.LicensesMetaData; import org.elasticsearch.license.plugin.core.LicensesStatus; -import org.elasticsearch.marvel.Marvel; +import org.elasticsearch.marvel.Monitoring; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.shield.Security; import org.elasticsearch.test.ESIntegTestCase; @@ -49,7 +49,7 @@ public abstract class AbstractLicensesIntegrationTestCase extends ESIntegTestCas protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(XPackPlugin.featureEnabledSetting(Security.NAME), false) - .put(XPackPlugin.featureEnabledSetting(Marvel.NAME), false) + .put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) .put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false) .put(XPackPlugin.featureEnabledSetting(Graph.NAME), false) .build(); diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MarvelModule.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MarvelModule.java deleted file mode 100644 index c5125da6c2c..00000000000 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MarvelModule.java +++ /dev/null @@ -1,20 +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.marvel; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.marvel.agent.AgentService; -import org.elasticsearch.marvel.cleaner.CleanerService; - -public class MarvelModule extends AbstractModule { - - @Override - protected void configure() { - bind(MarvelSettings.class).asEagerSingleton(); - bind(AgentService.class).asEagerSingleton(); - bind(CleanerService.class).asEagerSingleton(); - } -} diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Marvel.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Monitoring.java similarity index 83% rename from elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Marvel.java rename to elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Monitoring.java index 6440795572d..c4725e523c9 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Marvel.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Monitoring.java @@ -18,16 +18,16 @@ import org.elasticsearch.marvel.agent.collector.CollectorModule; import org.elasticsearch.marvel.agent.exporter.ExporterModule; import org.elasticsearch.marvel.cleaner.CleanerService; import org.elasticsearch.marvel.client.MonitoringClientModule; -import org.elasticsearch.marvel.license.LicenseModule; -import org.elasticsearch.marvel.license.MarvelLicensee; import org.elasticsearch.marvel.rest.action.RestMonitoringBulkAction; import org.elasticsearch.marvel.support.init.proxy.MonitoringClientProxy; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.common.init.LazyInitializationModule; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.List; /** * This class activates/deactivates the monitoring modules depending if we're running a node client, transport client or tribe client: @@ -35,7 +35,7 @@ import java.util.Collections; * - transport clients: only action/transport actions are binded * - tribe clients: everything is disables by default but can be enabled per tribe cluster */ -public class Marvel { +public class Monitoring { public static final String NAME = "monitoring"; @@ -43,9 +43,9 @@ public class Marvel { private final boolean enabled; private final boolean transportClientMode; - public Marvel(Settings settings) { + public Monitoring(Settings settings) { this.settings = settings; - this.enabled = MarvelSettings.ENABLED.get(settings); + this.enabled = MonitoringSettings.ENABLED.get(settings); this.transportClientMode = XPackPlugin.transportClientMode(settings); } @@ -58,29 +58,27 @@ public class Marvel { } public Collection nodeModules() { - if (enabled == false || transportClientMode) { - return Collections.emptyList(); + List modules = new ArrayList<>(); + modules.add(new MonitoringModule(enabled, transportClientMode)); + if (enabled && transportClientMode == false) { + modules.add(new CollectorModule()); + modules.add(new ExporterModule(settings)); + modules.add(new MonitoringClientModule()); } - - return Arrays.asList( - new MarvelModule(), - new LicenseModule(), - new CollectorModule(), - new ExporterModule(settings), - new MonitoringClientModule()); + return modules; } public Collection> nodeServices() { if (enabled == false || transportClientMode) { return Collections.emptyList(); } - return Arrays.>asList(MarvelLicensee.class, + return Arrays.>asList(MonitoringLicensee.class, AgentService.class, CleanerService.class); } public void onModule(SettingsModule module) { - MarvelSettings.register(module); + MonitoringSettings.register(module); } public void onModule(ActionModule module) { diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringFeatureSet.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringFeatureSet.java new file mode 100644 index 00000000000..c8b6dd29005 --- /dev/null +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringFeatureSet.java @@ -0,0 +1,46 @@ +/* + * 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.marvel; + +import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.xpack.XPackFeatureSet; + +/** + * + */ +public class MonitoringFeatureSet implements XPackFeatureSet { + + private final boolean enabled; + private final MonitoringLicensee licensee; + + @Inject + public MonitoringFeatureSet(Settings settings, @Nullable MonitoringLicensee licensee) { + this.enabled = MonitoringSettings.ENABLED.get(settings); + this.licensee = licensee; + } + + @Override + public String name() { + return Monitoring.NAME; + } + + @Override + public String description() { + return "Monitoring for the Elastic Stack"; + } + + @Override + public boolean available() { + return licensee != null && licensee.available(); + } + + @Override + public boolean enabled() { + return enabled; + } +} diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/license/MarvelLicensee.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringLicensee.java similarity index 88% rename from elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/license/MarvelLicensee.java rename to elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringLicensee.java index aa70d45106b..e73a8f40321 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/license/MarvelLicensee.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringLicensee.java @@ -3,7 +3,7 @@ * 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.marvel.license; +package org.elasticsearch.marvel; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; @@ -15,8 +15,6 @@ import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent; import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.LicenseeRegistry; -import org.elasticsearch.marvel.Marvel; -import org.elasticsearch.marvel.MarvelSettings; /** * {@code MarvelLicensee} determines whether certain features of Monitoring are enabled or disabled. @@ -27,11 +25,11 @@ import org.elasticsearch.marvel.MarvelSettings; *
  • Cleaning up (deleting) older indices.
  • * */ -public class MarvelLicensee extends AbstractLicenseeComponent implements Licensee { +public class MonitoringLicensee extends AbstractLicenseeComponent implements Licensee { @Inject - public MarvelLicensee(Settings settings, LicenseeRegistry clientService) { - super(settings, Marvel.NAME, clientService); + public MonitoringLicensee(Settings settings, LicenseeRegistry clientService) { + super(settings, Monitoring.NAME, clientService); } /** @@ -67,7 +65,7 @@ public class MarvelLicensee extends AbstractLicenseeComponent im newLicense.type(), newLicense.type(), newLicense.type()), LoggerMessageFormat.format( "Automatic index cleanup is locked to {} days for clusters with [{}] license.", - MarvelSettings.HISTORY_DURATION.getDefault(Settings.EMPTY).days(), newLicense.type()) + MonitoringSettings.HISTORY_DURATION.getDefault(Settings.EMPTY).days(), newLicense.type()) }; } } @@ -76,6 +74,15 @@ public class MarvelLicensee extends AbstractLicenseeComponent im return Strings.EMPTY_ARRAY; } + /** + * Monitoring is always available regardless of the license type (operation mode) + * + * @return true + */ + public boolean available() { + return true; + } + /** * Determine if the index cleaning service is enabled. *

    diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringModule.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringModule.java new file mode 100644 index 00000000000..6bf0f453c99 --- /dev/null +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringModule.java @@ -0,0 +1,37 @@ +/* + * 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.marvel; + +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.util.Providers; +import org.elasticsearch.marvel.agent.AgentService; +import org.elasticsearch.marvel.cleaner.CleanerService; +import org.elasticsearch.xpack.XPackPlugin; + +public class MonitoringModule extends AbstractModule { + + private final boolean enabled; + private final boolean transportClientMode; + + public MonitoringModule(boolean enabled, boolean transportClientMode) { + this.enabled = enabled; + this.transportClientMode = transportClientMode; + } + + @Override + protected void configure() { + XPackPlugin.bindFeatureSet(binder(), MonitoringFeatureSet.class); + + if (enabled && transportClientMode == false) { + bind(MonitoringLicensee.class).asEagerSingleton(); + bind(MonitoringSettings.class).asEagerSingleton(); + bind(AgentService.class).asEagerSingleton(); + bind(CleanerService.class).asEagerSingleton(); + } else { + bind(MonitoringLicensee.class).toProvider(Providers.of(null)); + } + } +} diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MarvelSettings.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringSettings.java similarity index 96% rename from elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MarvelSettings.java rename to elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringSettings.java index 6d6a74212b7..3ee8afcce21 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MarvelSettings.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/MonitoringSettings.java @@ -25,7 +25,7 @@ import static org.elasticsearch.common.settings.Setting.groupSetting; import static org.elasticsearch.common.settings.Setting.listSetting; import static org.elasticsearch.common.settings.Setting.timeSetting; -public class MarvelSettings extends AbstractComponent { +public class MonitoringSettings extends AbstractComponent { public static final String LEGACY_DATA_INDEX_NAME = ".marvel-es-data"; @@ -40,7 +40,7 @@ public class MarvelSettings extends AbstractComponent { * Determines whether monitoring is enabled/disabled */ public static final Setting ENABLED = - new Setting<>(XPackPlugin.featureEnabledSetting(Marvel.NAME), + new Setting<>(XPackPlugin.featureEnabledSetting(Monitoring.NAME), // By default, marvel is disabled on tribe nodes (s) -> String.valueOf(!XPackPlugin.isTribeNode(s) && !XPackPlugin.isTribeClientNode(s)), @@ -153,7 +153,7 @@ public class MarvelSettings extends AbstractComponent { private volatile String[] indices; @Inject - public MarvelSettings(Settings settings, ClusterSettings clusterSettings) { + public MonitoringSettings(Settings settings, ClusterSettings clusterSettings) { super(settings); setIndexStatsTimeout(INDEX_STATS_TIMEOUT.get(settings)); @@ -233,7 +233,7 @@ public class MarvelSettings extends AbstractComponent { * @return The key prefixed by the product prefixes. */ static String key(String key) { - return XPackPlugin.featureSettingPrefix(Marvel.NAME) + "." + key; + return XPackPlugin.featureSettingPrefix(Monitoring.NAME) + "." + key; } } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/AgentService.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/AgentService.java index b7dfbc57193..697c9b0f52a 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/AgentService.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/AgentService.java @@ -16,7 +16,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.CollectionUtils; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.ReleasableLock; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.Collector; import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector; import org.elasticsearch.marvel.agent.exporter.ExportException; @@ -54,12 +54,12 @@ public class AgentService extends AbstractLifecycleComponent { @Inject public AgentService(Settings settings, ClusterSettings clusterSettings, Set collectors, Exporters exporters) { super(settings); - this.samplingIntervalMillis = MarvelSettings.INTERVAL.get(settings).millis(); - this.settingsCollectors = MarvelSettings.COLLECTORS.get(settings).toArray(new String[0]); + this.samplingIntervalMillis = MonitoringSettings.INTERVAL.get(settings).millis(); + this.settingsCollectors = MonitoringSettings.COLLECTORS.get(settings).toArray(new String[0]); this.collectors = Collections.unmodifiableSet(filterCollectors(collectors, settingsCollectors)); this.exporters = exporters; - clusterSettings.addSettingsUpdateConsumer(MarvelSettings.INTERVAL, this::setInterval); + clusterSettings.addSettingsUpdateConsumer(MonitoringSettings.INTERVAL, this::setInterval); } private void setInterval(TimeValue interval) { diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/AbstractCollector.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/AbstractCollector.java index 4fb939fcb27..bbed7bf34c5 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/AbstractCollector.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/AbstractCollector.java @@ -12,10 +12,10 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringLicensee; import java.util.Collection; @@ -24,16 +24,16 @@ public abstract class AbstractCollector extends AbstractLifecycleComponent private final String name; protected final ClusterService clusterService; - protected final MarvelSettings marvelSettings; - protected final MarvelLicensee licensee; + protected final MonitoringSettings monitoringSettings; + protected final MonitoringLicensee licensee; @Inject public AbstractCollector(Settings settings, String name, ClusterService clusterService, - MarvelSettings marvelSettings, MarvelLicensee licensee) { + MonitoringSettings monitoringSettings, MonitoringLicensee licensee) { super(settings); this.name = name; this.clusterService = clusterService; - this.marvelSettings = marvelSettings; + this.monitoringSettings = monitoringSettings; this.licensee = licensee; } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStateCollector.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStateCollector.java index d24162e9673..cd444432395 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStateCollector.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStateCollector.java @@ -13,10 +13,10 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.AbstractCollector; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringLicensee; import org.elasticsearch.shield.InternalClient; import java.util.ArrayList; @@ -38,8 +38,8 @@ public class ClusterStateCollector extends AbstractCollector results = new ArrayList<>(1); try { RecoveryResponse recoveryResponse = client.admin().indices().prepareRecoveries() - .setIndices(marvelSettings.indices()) + .setIndices(monitoringSettings.indices()) .setIndicesOptions(IndicesOptions.lenientExpandOpen()) - .setActiveOnly(marvelSettings.recoveryActiveOnly()) - .get(marvelSettings.recoveryTimeout()); + .setActiveOnly(monitoringSettings.recoveryActiveOnly()) + .get(monitoringSettings.recoveryTimeout()); if (recoveryResponse.hasRecoveries()) { IndexRecoveryMonitoringDoc indexRecoveryDoc = new IndexRecoveryMonitoringDoc(monitoringId(), monitoringVersion()); @@ -69,7 +69,7 @@ public class IndexRecoveryCollector extends AbstractCollector @Inject public IndexStatsCollector(Settings settings, ClusterService clusterService, - MarvelSettings marvelSettings, MarvelLicensee marvelLicensee, InternalClient client) { - super(settings, NAME, clusterService, marvelSettings, marvelLicensee); + MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client) { + super(settings, NAME, clusterService, monitoringSettings, licensee); this.client = client; } @@ -57,7 +57,7 @@ public class IndexStatsCollector extends AbstractCollector List results = new ArrayList<>(); try { IndicesStatsResponse indicesStats = client.admin().indices().prepareStats() - .setIndices(marvelSettings.indices()) + .setIndices(monitoringSettings.indices()) .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .clear() .setDocs(true) @@ -68,7 +68,7 @@ public class IndexStatsCollector extends AbstractCollector .setSegments(true) .setStore(true) .setRefresh(true) - .get(marvelSettings.indexStatsTimeout()); + .get(monitoringSettings.indexStatsTimeout()); long timestamp = System.currentTimeMillis(); String clusterUUID = clusterUUID(); @@ -83,7 +83,7 @@ public class IndexStatsCollector extends AbstractCollector results.add(indexStatsDoc); } } catch (IndexNotFoundException e) { - if (Security.enabled(settings) && IndexNameExpressionResolver.isAllIndices(Arrays.asList(marvelSettings.indices()))) { + if (Security.enabled(settings) && IndexNameExpressionResolver.isAllIndices(Arrays.asList(monitoringSettings.indices()))) { logger.debug("collector [{}] - unable to collect data for missing index [{}]", name(), e.getIndex()); } else { throw e; diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndicesStatsCollector.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndicesStatsCollector.java index 8c56780f640..170e230ff0a 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndicesStatsCollector.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndicesStatsCollector.java @@ -13,10 +13,10 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexNotFoundException; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.AbstractCollector; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringLicensee; import org.elasticsearch.shield.InternalClient; import org.elasticsearch.shield.Security; @@ -37,8 +37,8 @@ public class IndicesStatsCollector extends AbstractCollector doCollect() throws Exception { try { IndicesStatsResponse indicesStats = client.admin().indices().prepareStats() - .setIndices(marvelSettings.indices()) + .setIndices(monitoringSettings.indices()) .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .clear() .setDocs(true) .setIndexing(true) .setSearch(true) .setStore(true) - .get(marvelSettings.indicesStatsTimeout()); + .get(monitoringSettings.indicesStatsTimeout()); IndicesStatsMonitoringDoc indicesStatsDoc = new IndicesStatsMonitoringDoc(monitoringId(), monitoringVersion()); indicesStatsDoc.setClusterUUID(clusterUUID()); @@ -68,7 +68,7 @@ public class IndicesStatsCollector extends AbstractCollector { private final DiskThresholdDecider diskThresholdDecider; @Inject - public NodeStatsCollector(Settings settings, ClusterService clusterService, MarvelSettings marvelSettings, - MarvelLicensee marvelLicensee, InternalClient client, + public NodeStatsCollector(Settings settings, ClusterService clusterService, MonitoringSettings monitoringSettings, + MonitoringLicensee licensee, InternalClient client, NodeEnvironment nodeEnvironment, DiskThresholdDecider diskThresholdDecider) { - super(settings, NAME, clusterService, marvelSettings, marvelLicensee); + super(settings, NAME, clusterService, monitoringSettings, licensee); this.client = client; this.nodeEnvironment = nodeEnvironment; this.diskThresholdDecider = diskThresholdDecider; diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/shards/ShardsCollector.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/shards/ShardsCollector.java index 5c6fef95b3c..919408139dd 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/shards/ShardsCollector.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/shards/ShardsCollector.java @@ -13,10 +13,10 @@ import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.AbstractCollector; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringLicensee; import java.util.ArrayList; import java.util.Arrays; @@ -36,8 +36,8 @@ public class ShardsCollector extends AbstractCollector { @Inject public ShardsCollector(Settings settings, ClusterService clusterService, - MarvelSettings marvelSettings, MarvelLicensee marvelLicensee) { - super(settings, NAME, clusterService, marvelSettings, marvelLicensee); + MonitoringSettings monitoringSettings, MonitoringLicensee licensee) { + super(settings, NAME, clusterService, monitoringSettings, licensee); } @Override @@ -82,7 +82,8 @@ public class ShardsCollector extends AbstractCollector { } private boolean match(String indexName) { - String[] indices = marvelSettings.indices(); - return IndexNameExpressionResolver.isAllIndices(Arrays.asList(marvelSettings.indices())) || Regex.simpleMatch(indices, indexName); + String[] indices = monitoringSettings.indices(); + return IndexNameExpressionResolver + .isAllIndices(Arrays.asList(monitoringSettings.indices())) || Regex.simpleMatch(indices, indexName); } } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporter.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporter.java index 581a253daee..6bf3b09564f 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporter.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporter.java @@ -10,7 +10,7 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import java.util.concurrent.atomic.AtomicBoolean; @@ -65,7 +65,7 @@ public abstract class Exporter implements AutoCloseable { protected abstract void doClose(); protected String settingFQN(String setting) { - return MarvelSettings.EXPORTERS_SETTINGS.getKey() + config.name + "." + setting; + return MonitoringSettings.EXPORTERS_SETTINGS.getKey() + config.name + "." + setting; } public static class Config { diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporters.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporters.java index 2910664b8ef..4c98b6194c2 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporters.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporters.java @@ -13,7 +13,7 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.exporter.local.LocalExporter; import org.elasticsearch.node.Node; @@ -48,7 +48,7 @@ public class Exporters extends AbstractLifecycleComponent implements this.factories = factories; this.clusterService = clusterService; this.exporters = new AtomicReference<>(emptyMap()); - clusterSettings.addSettingsUpdateConsumer(MarvelSettings.EXPORTERS_SETTINGS, this::setExportersSetting); + clusterSettings.addSettingsUpdateConsumer(MonitoringSettings.EXPORTERS_SETTINGS, this::setExportersSetting); } private void setExportersSetting(Settings exportersSetting) { @@ -63,7 +63,7 @@ public class Exporters extends AbstractLifecycleComponent implements @Override protected void doStart() { - exporters.set(initExporters(MarvelSettings.EXPORTERS_SETTINGS.get(settings))); + exporters.set(initExporters(MonitoringSettings.EXPORTERS_SETTINGS.get(settings))); } @Override diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/cleaner/CleanerService.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/cleaner/CleanerService.java index 1eb6aaba2d7..a0a0c8f813b 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/cleaner/CleanerService.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/cleaner/CleanerService.java @@ -13,8 +13,8 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.AbstractLifecycleRunnable; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.util.concurrent.FutureUtils; -import org.elasticsearch.marvel.MarvelSettings; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringSettings; +import org.elasticsearch.marvel.MonitoringLicensee; import org.elasticsearch.threadpool.ThreadPool; import org.joda.time.DateTime; import org.joda.time.chrono.ISOChronology; @@ -28,7 +28,7 @@ import java.util.concurrent.ScheduledFuture; */ public class CleanerService extends AbstractLifecycleComponent { - private final MarvelLicensee licensee; + private final MonitoringLicensee licensee; private final ThreadPool threadPool; private final ExecutionScheduler executionScheduler; private final List listeners = new CopyOnWriteArrayList<>(); @@ -36,21 +36,21 @@ public class CleanerService extends AbstractLifecycleComponent { private volatile TimeValue globalRetention; - CleanerService(Settings settings, ClusterSettings clusterSettings, MarvelLicensee licensee, ThreadPool threadPool, + CleanerService(Settings settings, ClusterSettings clusterSettings, MonitoringLicensee licensee, ThreadPool threadPool, ExecutionScheduler executionScheduler) { super(settings); this.licensee = licensee; this.threadPool = threadPool; this.executionScheduler = executionScheduler; - this.globalRetention = MarvelSettings.HISTORY_DURATION.get(settings); + this.globalRetention = MonitoringSettings.HISTORY_DURATION.get(settings); this.runnable = new IndicesCleaner(); // the validation is performed by the setting's object itself - clusterSettings.addSettingsUpdateConsumer(MarvelSettings.HISTORY_DURATION, this::setGlobalRetention); + clusterSettings.addSettingsUpdateConsumer(MonitoringSettings.HISTORY_DURATION, this::setGlobalRetention); } @Inject - public CleanerService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, MarvelLicensee licensee) { + public CleanerService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, MonitoringLicensee licensee) { this(settings, clusterSettings, licensee,threadPool, new DefaultExecutionScheduler()); } @@ -85,7 +85,7 @@ public class CleanerService extends AbstractLifecycleComponent { * This will ignore the global retention if the license does not allow retention updates. * * @return Never {@code null} - * @see MarvelLicensee#allowUpdateRetention() + * @see MonitoringLicensee#allowUpdateRetention() */ public TimeValue getRetention() { // we only care about their value if they are allowed to set it @@ -93,7 +93,7 @@ public class CleanerService extends AbstractLifecycleComponent { return globalRetention; } else { - return MarvelSettings.HISTORY_DURATION.getDefault(Settings.EMPTY); + return MonitoringSettings.HISTORY_DURATION.getDefault(Settings.EMPTY); } } @@ -108,7 +108,8 @@ public class CleanerService extends AbstractLifecycleComponent { public void setGlobalRetention(TimeValue globalRetention) { // notify the user that their setting will be ignored until they get the right license if (licensee.allowUpdateRetention() == false) { - logger.warn("[{}] setting will be ignored until an appropriate license is applied", MarvelSettings.HISTORY_DURATION.getKey()); + logger.warn("[{}] setting will be ignored until an appropriate license is applied", + MonitoringSettings.HISTORY_DURATION.getKey()); } this.globalRetention = globalRetention; diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/license/LicenseModule.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/license/LicenseModule.java deleted file mode 100644 index 40cba26b5d4..00000000000 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/license/LicenseModule.java +++ /dev/null @@ -1,17 +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.marvel.license; - -import org.elasticsearch.common.inject.AbstractModule; - -public class LicenseModule extends AbstractModule { - - @Override - protected void configure() { - bind(MarvelLicensee.class).asEagerSingleton(); - } - -} \ No newline at end of file diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginClientTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginClientTests.java index 6eb4d8bbb0f..cc1dc71e881 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginClientTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginClientTests.java @@ -16,16 +16,15 @@ import java.util.Collection; import static org.hamcrest.Matchers.is; public class MarvelPluginClientTests extends ESTestCase { + public void testModulesWithClientSettings() { Settings settings = Settings.builder() .put(Client.CLIENT_TYPE_SETTING_S.getKey(), TransportClient.CLIENT_TYPE) .build(); - Marvel plugin = new Marvel(settings); + Monitoring plugin = new Monitoring(settings); assertThat(plugin.isEnabled(), is(true)); assertThat(plugin.isTransportClient(), is(true)); - Collection modules = plugin.nodeModules(); - assertThat(modules.size(), is(0)); } public void testModulesWithNodeSettings() { @@ -33,10 +32,8 @@ public class MarvelPluginClientTests extends ESTestCase { Settings settings = Settings.builder() .put(Client.CLIENT_TYPE_SETTING_S.getKey(), "node") .build(); - Marvel plugin = new Marvel(settings); + Monitoring plugin = new Monitoring(settings); assertThat(plugin.isEnabled(), is(true)); assertThat(plugin.isTransportClient(), is(false)); - Collection modules = plugin.nodeModules(); - assertThat(modules.size(), is(5)); } } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginTests.java index a0fb6d3a4b2..63b4753e673 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginTests.java @@ -35,13 +35,13 @@ public class MarvelPluginTests extends MarvelIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .build(); } public void testMarvelEnabled() { internalCluster().startNode(Settings.builder() - .put(XPackPlugin.featureEnabledSetting(Marvel.NAME), true) + .put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), true) .build()); assertPluginIsLoaded(); assertServiceIsBound(AgentService.class); @@ -49,7 +49,7 @@ public class MarvelPluginTests extends MarvelIntegTestCase { public void testMarvelDisabled() { internalCluster().startNode(Settings.builder() - .put(XPackPlugin.featureEnabledSetting(Marvel.NAME), false) + .put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) .build()); assertPluginIsLoaded(); assertServiceIsNotBound(AgentService.class); @@ -57,7 +57,7 @@ public class MarvelPluginTests extends MarvelIntegTestCase { public void testMarvelEnabledOnTribeNode() { internalCluster().startNode(Settings.builder() - .put(XPackPlugin.featureEnabledSetting(Marvel.NAME), true) + .put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), true) .put("tribe.name", "t1") .build()); assertPluginIsLoaded(); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelSettingsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelSettingsTests.java index 82f1a9d2abd..d6240ea4c71 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelSettingsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelSettingsTests.java @@ -13,7 +13,7 @@ import org.junit.Rule; import org.junit.rules.ExpectedException; /** - * Tests {@link MarvelSettings} + * Tests {@link MonitoringSettings} */ public class MarvelSettingsTests extends ESTestCase { @Rule @@ -23,24 +23,24 @@ public class MarvelSettingsTests extends ESTestCase { TimeValue sevenDays = TimeValue.timeValueHours(7 * 24); // 7 days - assertEquals(sevenDays, MarvelSettings.HISTORY_DURATION.get(Settings.EMPTY)); + assertEquals(sevenDays, MonitoringSettings.HISTORY_DURATION.get(Settings.EMPTY)); // Note: this verifies the semantics because this is taken for granted that it never returns null! - assertEquals(sevenDays, MarvelSettings.HISTORY_DURATION.get(buildSettings(MarvelSettings.HISTORY_DURATION.getKey(), null))); + assertEquals(sevenDays, MonitoringSettings.HISTORY_DURATION.get(buildSettings(MonitoringSettings.HISTORY_DURATION.getKey(), null))); } public void testHistoryDurationMinimum24Hours() { // hit the minimum - assertEquals(MarvelSettings.HISTORY_DURATION_MINIMUM, - MarvelSettings.HISTORY_DURATION.get(buildSettings(MarvelSettings.HISTORY_DURATION.getKey(), "24h"))); + assertEquals(MonitoringSettings.HISTORY_DURATION_MINIMUM, + MonitoringSettings.HISTORY_DURATION.get(buildSettings(MonitoringSettings.HISTORY_DURATION.getKey(), "24h"))); } public void testHistoryDurationMinimum24HoursBlocksLower() { expectedException.expect(IllegalArgumentException.class); // 1 ms early! - String oneSecondEarly = (MarvelSettings.HISTORY_DURATION_MINIMUM.millis() - 1) + "ms"; + String oneSecondEarly = (MonitoringSettings.HISTORY_DURATION_MINIMUM.millis() - 1) + "ms"; - MarvelSettings.HISTORY_DURATION.get(buildSettings(MarvelSettings.HISTORY_DURATION.getKey(), oneSecondEarly)); + MonitoringSettings.HISTORY_DURATION.get(buildSettings(MonitoringSettings.HISTORY_DURATION.getKey(), oneSecondEarly)); } private Settings buildSettings(String key, String value) { diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/TransportMonitoringBulkActionTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/TransportMonitoringBulkActionTests.java index d5cb049176a..4dc0f3d7d11 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/TransportMonitoringBulkActionTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/TransportMonitoringBulkActionTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.discovery.DiscoverySettings; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.exporter.ExportException; import org.elasticsearch.marvel.agent.exporter.Exporters; @@ -257,7 +257,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase { public CapturingExporters() { super(Settings.EMPTY, Collections.emptyMap(), clusterService, - new ClusterSettings(Settings.EMPTY, Collections.singleton(MarvelSettings.EXPORTERS_SETTINGS))); + new ClusterSettings(Settings.EMPTY, Collections.singleton(MonitoringSettings.EXPORTERS_SETTINGS))); } @Override @@ -279,7 +279,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase { public ConsumingExporters(Consumer> consumer) { super(Settings.EMPTY, Collections.emptyMap(), clusterService, - new ClusterSettings(Settings.EMPTY, Collections.singleton(MarvelSettings.EXPORTERS_SETTINGS))); + new ClusterSettings(Settings.EMPTY, Collections.singleton(MonitoringSettings.EXPORTERS_SETTINGS))); this.consumer = consumer; } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/AbstractCollectorTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/AbstractCollectorTestCase.java index 0c0cc7f61f5..c9d20457c6b 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/AbstractCollectorTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/AbstractCollectorTestCase.java @@ -23,7 +23,7 @@ import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.LicenseeRegistry; import org.elasticsearch.license.plugin.core.LicensesManagerService; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.shield.InternalClient; @@ -54,7 +54,7 @@ public abstract class AbstractCollectorTestCase extends MarvelIntegTestCase { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) .put(NetworkModule.HTTP_ENABLED.getKey(), false) - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .build(); } @@ -126,7 +126,7 @@ public abstract class AbstractCollectorTestCase extends MarvelIntegTestCase { } protected static void endGracefulPeriod() { - long expiryDate = System.currentTimeMillis() - MarvelSettings.MAX_LICENSE_GRACE_PERIOD.millis() - timeValueMinutes(10).millis(); + long expiryDate = System.currentTimeMillis() - MonitoringSettings.MAX_LICENSE_GRACE_PERIOD.millis() - timeValueMinutes(10).millis(); long issueDate = expiryDate - randomDaysInMillis(); final License license = createTestingLicense(issueDate, expiryDate); @@ -139,7 +139,7 @@ public abstract class AbstractCollectorTestCase extends MarvelIntegTestCase { } protected static void disableLicense() { - long expiryDate = System.currentTimeMillis() - MarvelSettings.MAX_LICENSE_GRACE_PERIOD.millis() - randomDaysInMillis(); + long expiryDate = System.currentTimeMillis() - MonitoringSettings.MAX_LICENSE_GRACE_PERIOD.millis() - randomDaysInMillis(); long issueDate = expiryDate - randomDaysInMillis(); final License license = createTestingLicense(issueDate, expiryDate); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStateCollectorTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStateCollectorTests.java index b330155d6cb..c1075c51af0 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStateCollectorTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStateCollectorTests.java @@ -10,11 +10,11 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringLicensee; import java.util.ArrayList; import java.util.Collection; @@ -153,8 +153,8 @@ public class ClusterStateCollectorTests extends AbstractCollectorTestCase { assertNotNull(nodeId); return new ClusterStateCollector(internalCluster().getInstance(Settings.class, nodeId), internalCluster().getInstance(ClusterService.class, nodeId), - internalCluster().getInstance(MarvelSettings.class, nodeId), - internalCluster().getInstance(MarvelLicensee.class, nodeId), + internalCluster().getInstance(MonitoringSettings.class, nodeId), + internalCluster().getInstance(MonitoringLicensee.class, nodeId), securedClient(nodeId)); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStatsCollectorTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStatsCollectorTests.java index fb2ec67f9d9..8d6c4120677 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStatsCollectorTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStatsCollectorTests.java @@ -11,12 +11,12 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.plugin.core.LicensesManagerService; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.collector.AbstractCollector; import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringLicensee; import java.util.Collection; @@ -131,8 +131,8 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase { assertNotNull(nodeId); return new ClusterStatsCollector(internalCluster().getInstance(Settings.class, nodeId), internalCluster().getInstance(ClusterService.class, nodeId), - internalCluster().getInstance(MarvelSettings.class, nodeId), - internalCluster().getInstance(MarvelLicensee.class, nodeId), + internalCluster().getInstance(MonitoringSettings.class, nodeId), + internalCluster().getInstance(MonitoringLicensee.class, nodeId), securedClient(nodeId), internalCluster().getInstance(LicensesManagerService.class, nodeId), internalCluster().getInstance(ClusterName.class, nodeId)); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollectorTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollectorTests.java index 759ba460cae..20c07c55cb0 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollectorTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollectorTests.java @@ -13,11 +13,11 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.recovery.RecoveryState; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringLicensee; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import java.util.Collection; @@ -47,8 +47,8 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY.getKey(), activeOnly) - .put(MarvelSettings.INDICES.getKey(), indexName) + .put(MonitoringSettings.INDEX_RECOVERY_ACTIVE_ONLY.getKey(), activeOnly) + .put(MonitoringSettings.INDICES.getKey(), indexName) .build(); } @@ -85,8 +85,8 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase { waitForNoBlocksOnNode(node2); waitForRelocation(); - for (MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) { - assertThat(marvelSettings.recoveryActiveOnly(), equalTo(activeOnly)); + for (MonitoringSettings monitoringSettings : internalCluster().getInstances(MonitoringSettings.class)) { + assertThat(monitoringSettings.recoveryActiveOnly(), equalTo(activeOnly)); } logger.info("--> collect index recovery data"); @@ -168,7 +168,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase { } public void testEmptyCluster() throws Exception { - final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), + final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), Strings.EMPTY_ARRAY)); waitForNoBlocksOnNode(node); @@ -180,7 +180,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase { } public void testEmptyClusterAllIndices() throws Exception { - final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL)); + final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), MetaData.ALL)); waitForNoBlocksOnNode(node); try { @@ -191,7 +191,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase { } public void testEmptyClusterMissingIndex() throws Exception { - final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), "unknown")); + final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), "unknown")); waitForNoBlocksOnNode(node); try { @@ -207,8 +207,8 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase { } return new IndexRecoveryCollector(internalCluster().getInstance(Settings.class, nodeId), internalCluster().getInstance(ClusterService.class, nodeId), - internalCluster().getInstance(MarvelSettings.class, nodeId), - internalCluster().getInstance(MarvelLicensee.class, nodeId), + internalCluster().getInstance(MonitoringSettings.class, nodeId), + internalCluster().getInstance(MonitoringLicensee.class, nodeId), securedClient(nodeId)); } } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollectorTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollectorTests.java index 16203ddf14d..b66bfee4e50 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollectorTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollectorTests.java @@ -11,11 +11,11 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexNotFoundException; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringLicensee; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import java.util.Collection; @@ -52,7 +52,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase { } public void testEmptyClusterAllIndices() throws Exception { - final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL)); + final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), MetaData.ALL)); waitForNoBlocksOnNode(node); try { @@ -63,7 +63,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase { } public void testEmptyClusterMissingIndex() throws Exception { - final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), "unknown")); + final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), "unknown")); waitForNoBlocksOnNode(node); try { @@ -240,8 +240,8 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase { assertNotNull(nodeId); return new IndexStatsCollector(internalCluster().getInstance(Settings.class, nodeId), internalCluster().getInstance(ClusterService.class, nodeId), - internalCluster().getInstance(MarvelSettings.class, nodeId), - internalCluster().getInstance(MarvelLicensee.class, nodeId), + internalCluster().getInstance(MonitoringSettings.class, nodeId), + internalCluster().getInstance(MonitoringLicensee.class, nodeId), securedClient(nodeId)); } } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndicesStatsCollectorTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndicesStatsCollectorTests.java index ce6094ef1e3..84ee2b73585 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndicesStatsCollectorTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndicesStatsCollectorTests.java @@ -13,11 +13,11 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexNotFoundException; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringLicensee; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import java.util.Collection; @@ -52,7 +52,7 @@ public class IndicesStatsCollectorTests extends AbstractCollectorTestCase { } public void testEmptyClusterAllIndices() throws Exception { - final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL)); + final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), MetaData.ALL)); waitForNoBlocksOnNode(node); try { @@ -63,7 +63,7 @@ public class IndicesStatsCollectorTests extends AbstractCollectorTestCase { } public void testEmptyClusterMissingIndex() throws Exception { - final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), "unknown")); + final String node = internalCluster().startNode(Settings.builder().put(MonitoringSettings.INDICES.getKey(), "unknown")); waitForNoBlocksOnNode(node); try { @@ -215,8 +215,8 @@ public class IndicesStatsCollectorTests extends AbstractCollectorTestCase { } return new IndicesStatsCollector(internalCluster().getInstance(Settings.class, nodeId), internalCluster().getInstance(ClusterService.class, nodeId), - internalCluster().getInstance(MarvelSettings.class, nodeId), - internalCluster().getInstance(MarvelLicensee.class, nodeId), + internalCluster().getInstance(MonitoringSettings.class, nodeId), + internalCluster().getInstance(MonitoringLicensee.class, nodeId), securedClient(nodeId)); } } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollectorTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollectorTests.java index 089fe6adcd2..c30c83602a8 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollectorTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollectorTests.java @@ -11,11 +11,11 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.NodeEnvironment; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringLicensee; import org.elasticsearch.shield.InternalClient; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; @@ -96,8 +96,8 @@ public class NodeStatsCollectorTests extends AbstractCollectorTestCase { private NodeStatsCollector newNodeStatsCollector(final String nodeId) { return new NodeStatsCollector(internalCluster().getInstance(Settings.class, nodeId), internalCluster().getInstance(ClusterService.class, nodeId), - internalCluster().getInstance(MarvelSettings.class, nodeId), - internalCluster().getInstance(MarvelLicensee.class, nodeId), + internalCluster().getInstance(MonitoringSettings.class, nodeId), + internalCluster().getInstance(MonitoringLicensee.class, nodeId), internalCluster().getInstance(InternalClient.class, nodeId), internalCluster().getInstance(NodeEnvironment.class, nodeId), internalCluster().getInstance(DiskThresholdDecider.class, nodeId)); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/shards/ShardsCollectorTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/shards/ShardsCollectorTests.java index 8f2553296a0..f873790ea7c 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/shards/ShardsCollectorTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/shards/ShardsCollectorTests.java @@ -10,11 +10,11 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringLicensee; import java.util.Collection; @@ -39,7 +39,7 @@ public class ShardsCollectorTests extends AbstractCollectorTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INDICES.getKey(), "test-shards*") + .put(MonitoringSettings.INDICES.getKey(), "test-shards*") .build(); } @@ -207,7 +207,7 @@ public class ShardsCollectorTests extends AbstractCollectorTestCase { assertNotNull(nodeId); return new ShardsCollector(internalCluster().getInstance(Settings.class, nodeId), internalCluster().getInstance(ClusterService.class, nodeId), - internalCluster().getInstance(MarvelSettings.class, nodeId), - internalCluster().getInstance(MarvelLicensee.class, nodeId)); + internalCluster().getInstance(MonitoringSettings.class, nodeId), + internalCluster().getInstance(MonitoringLicensee.class, nodeId)); } } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/AbstractExporterTemplateTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/AbstractExporterTemplateTestCase.java index f079f405b13..c2d35393b02 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/AbstractExporterTemplateTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/AbstractExporterTemplateTestCase.java @@ -8,7 +8,7 @@ package org.elasticsearch.marvel.agent.exporter; import org.elasticsearch.Version; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.collector.Collector; import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector; @@ -31,7 +31,7 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa protected Settings nodeSettings(int nodeOrdinal) { Settings.Builder settings = Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1"); + .put(MonitoringSettings.INTERVAL.getKey(), "-1"); for (Map.Entry setting : exporterSettings().getAsMap().entrySet()) { settings.put("xpack.monitoring.agent.exporters._exporter." + setting.getKey(), setting.getValue()); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java index aa894898e3c..7ed76f5c9f8 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java @@ -15,7 +15,7 @@ import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.common.util.concurrent.AbstractRunnable; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.exporter.local.LocalExporter; import org.elasticsearch.marvel.cleaner.CleanerService; @@ -71,8 +71,8 @@ public class ExportersTests extends ESTestCase { // we always need to have the local exporter as it serves as the default one factories.put(LocalExporter.TYPE, new LocalExporter.Factory(MonitoringClientProxy.of(client), clusterService, mock(CleanerService.class))); - clusterSettings = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList(MarvelSettings.COLLECTORS, - MarvelSettings.INTERVAL, MarvelSettings.EXPORTERS_SETTINGS))); + clusterSettings = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList(MonitoringSettings.COLLECTORS, + MonitoringSettings.INTERVAL, MonitoringSettings.EXPORTERS_SETTINGS))); exporters = new Exporters(Settings.EMPTY, factories, clusterService, clusterSettings); } @@ -179,7 +179,7 @@ public class ExportersTests extends ESTestCase { .put("xpack.monitoring.agent.exporters._name0.type", "_type") .put("xpack.monitoring.agent.exporters._name1.type", "_type") .build(); - clusterSettings = new ClusterSettings(nodeSettings, new HashSet<>(Arrays.asList(MarvelSettings.EXPORTERS_SETTINGS))); + clusterSettings = new ClusterSettings(nodeSettings, new HashSet<>(Arrays.asList(MonitoringSettings.EXPORTERS_SETTINGS))); exporters = new Exporters(nodeSettings, factories, clusterService, clusterSettings) { @Override diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTests.java index 922ae058a20..60338a77393 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTests.java @@ -24,7 +24,7 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.common.xcontent.XContentHelper; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.collector.cluster.ClusterStateMonitoringDoc; import org.elasticsearch.marvel.agent.collector.indices.IndexRecoveryMonitoringDoc; @@ -94,7 +94,7 @@ public class HttpExporterTests extends MarvelIntegTestCase { enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}"); Settings.Builder builder = Settings.builder() - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .put("xpack.monitoring.agent.exporters._http.type", "http") .put("xpack.monitoring.agent.exporters._http.host", webServer.getHostName() + ":" + webServer.getPort()) .put("xpack.monitoring.agent.exporters._http.connection.keep_alive", false) @@ -132,7 +132,7 @@ public class HttpExporterTests extends MarvelIntegTestCase { public void testDynamicHostChange() { // disable exporting to be able to use non valid hosts Settings.Builder builder = Settings.builder() - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .put("xpack.monitoring.agent.exporters._http.type", "http") .put("xpack.monitoring.agent.exporters._http.host", "test0"); @@ -156,7 +156,7 @@ public class HttpExporterTests extends MarvelIntegTestCase { public void testHostChangeReChecksTemplate() throws Exception { Settings.Builder builder = Settings.builder() - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .put("xpack.monitoring.agent.exporters._http.type", "http") .put("xpack.monitoring.agent.exporters._http.host", webServer.getHostName() + ":" + webServer.getPort()) .put("xpack.monitoring.agent.exporters._http.connection.keep_alive", false) @@ -273,7 +273,7 @@ public class HttpExporterTests extends MarvelIntegTestCase { public void testUnsupportedClusterVersion() throws Exception { Settings.Builder builder = Settings.builder() - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .put("xpack.monitoring.agent.exporters._http.type", "http") .put("xpack.monitoring.agent.exporters._http.host", webServer.getHostName() + ":" + webServer.getPort()) .put("xpack.monitoring.agent.exporters._http.connection.keep_alive", false); @@ -301,7 +301,7 @@ public class HttpExporterTests extends MarvelIntegTestCase { public void testDynamicIndexFormatChange() throws Exception { Settings.Builder builder = Settings.builder() - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .put("xpack.monitoring.agent.exporters._http.type", "http") .put("xpack.monitoring.agent.exporters._http.host", webServer.getHostName() + ":" + webServer.getPort()) .put("xpack.monitoring.agent.exporters._http.connection.keep_alive", false) @@ -401,7 +401,7 @@ public class HttpExporterTests extends MarvelIntegTestCase { final String host = webServer.getHostName() + ":" + webServer.getPort(); Settings.Builder builder = Settings.builder() - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .put("xpack.monitoring.agent.exporters._http.type", "http") .put("xpack.monitoring.agent.exporters._http.host", host) .put("xpack.monitoring.agent.exporters._http.connection.keep_alive", false); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporterTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporterTests.java index a5af0be8bc4..59080b27735 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporterTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporterTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.DummyTransportAddress; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.collector.cluster.ClusterStateMonitoringDoc; import org.elasticsearch.marvel.agent.collector.indices.IndexRecoveryMonitoringDoc; @@ -53,7 +53,7 @@ public class LocalExporterTests extends MarvelIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .build(); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoTests.java index e8cc28a9f31..fabb79d69f6 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoTests.java @@ -11,7 +11,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.license.core.License; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector; import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver; @@ -39,8 +39,8 @@ public class ClusterInfoTests extends MarvelIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1") - .put(MarvelSettings.COLLECTORS.getKey(), ClusterStatsCollector.NAME) + .put(MonitoringSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.COLLECTORS.getKey(), ClusterStatsCollector.NAME) .build(); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java index 41cdd6b314c..e1d1ffd7415 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java @@ -10,7 +10,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.cluster.ClusterStateCollector; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver; import org.elasticsearch.marvel.test.MarvelIntegTestCase; @@ -43,8 +43,8 @@ public class ClusterStateTests extends MarvelIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1") - .put(MarvelSettings.COLLECTORS.getKey(), ClusterStateCollector.NAME) + .put(MonitoringSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.COLLECTORS.getKey(), ClusterStateCollector.NAME) .put("xpack.monitoring.agent.exporters.default_local.type", "local") .put("node.attr.custom", randomInt) .build(); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsTests.java index ef4915895c7..d787ff3cea6 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsTests.java @@ -8,7 +8,7 @@ package org.elasticsearch.marvel.agent.resolver.cluster; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodes; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.search.SearchHit; @@ -30,8 +30,8 @@ public class ClusterStatsTests extends MarvelIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1") - .put(MarvelSettings.COLLECTORS.getKey(), ClusterStatsCollector.NAME) + .put(MonitoringSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.COLLECTORS.getKey(), ClusterStatsCollector.NAME) .put("xpack.monitoring.agent.exporters.default_local.type", "local") .build(); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java index b270f6c7acd..561563f4445 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexRecoveryTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.indices.IndexRecoveryCollector; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver; import org.elasticsearch.marvel.test.MarvelIntegTestCase; @@ -35,9 +35,9 @@ public class IndexRecoveryTests extends MarvelIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1") - .put(MarvelSettings.INDICES.getKey(), INDEX_PREFIX + "*") - .put(MarvelSettings.COLLECTORS.getKey(), IndexRecoveryCollector.NAME) + .put(MonitoringSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INDICES.getKey(), INDEX_PREFIX + "*") + .put(MonitoringSettings.COLLECTORS.getKey(), IndexRecoveryCollector.NAME) .put("xpack.monitoring.agent.exporters.default_local.type", "local") .build(); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsTests.java index 9c2eb30aad4..d1af88aadaf 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsTests.java @@ -8,7 +8,7 @@ package org.elasticsearch.marvel.agent.resolver.indices; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.indices.IndexStatsCollector; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.search.SearchHit; @@ -28,8 +28,8 @@ public class IndexStatsTests extends MarvelIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1") - .put(MarvelSettings.COLLECTORS.getKey(), IndexStatsCollector.NAME) + .put(MonitoringSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.COLLECTORS.getKey(), IndexStatsCollector.NAME) .put("xpack.monitoring.agent.exporters.default_local.type", "local") .build(); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndicesStatsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndicesStatsTests.java index cfaddb309f6..25ae10e8e2f 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndicesStatsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/indices/IndicesStatsTests.java @@ -8,9 +8,8 @@ package org.elasticsearch.marvel.agent.resolver.indices; import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.indices.IndicesStatsCollector; -import org.elasticsearch.marvel.agent.resolver.indices.IndicesStatsResolver; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.search.SearchHit; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; @@ -29,8 +28,8 @@ public class IndicesStatsTests extends MarvelIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1") - .put(MarvelSettings.COLLECTORS.getKey(), IndicesStatsCollector.NAME) + .put(MonitoringSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.COLLECTORS.getKey(), IndicesStatsCollector.NAME) .put("xpack.monitoring.agent.exporters.default_local.type", "local") .build(); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/MultiNodesStatsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/MultiNodesStatsTests.java index 06a13a72446..3c6a862d84a 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/MultiNodesStatsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/MultiNodesStatsTests.java @@ -8,7 +8,7 @@ package org.elasticsearch.marvel.agent.resolver.node; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexNotFoundException; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.node.Node; import org.elasticsearch.search.aggregations.Aggregation; @@ -34,7 +34,7 @@ public class MultiNodesStatsTests extends MarvelIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .put("xpack.monitoring.agent.exporters.default_local.type", "local") .build(); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsTests.java index a54223eba0f..863e81fc0e6 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsTests.java @@ -8,7 +8,7 @@ package org.elasticsearch.marvel.agent.resolver.node; import org.apache.lucene.util.Constants; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.node.NodeStatsCollector; import org.elasticsearch.marvel.agent.exporter.local.LocalExporter; import org.elasticsearch.marvel.test.MarvelIntegTestCase; @@ -31,8 +31,8 @@ public class NodeStatsTests extends MarvelIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1") - .put(MarvelSettings.COLLECTORS.getKey(), NodeStatsCollector.NAME) + .put(MonitoringSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.COLLECTORS.getKey(), NodeStatsCollector.NAME) .put("xpack.monitoring.agent.exporters.default_local.type", LocalExporter.TYPE) .build(); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsTests.java index d8e50b9bed0..970e714fd49 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsTests.java @@ -11,9 +11,8 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.collector.shards.ShardsCollector; -import org.elasticsearch.marvel.agent.resolver.shards.ShardsResolver; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.aggregations.Aggregation; @@ -43,9 +42,9 @@ public class ShardsTests extends MarvelIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1") - .put(MarvelSettings.COLLECTORS.getKey(), ShardsCollector.NAME) - .put(MarvelSettings.INDICES.getKey(), INDEX_PREFIX + "*") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.COLLECTORS.getKey(), ShardsCollector.NAME) + .put(MonitoringSettings.INDICES.getKey(), INDEX_PREFIX + "*") .put("xpack.monitoring.agent.exporters.default_local.type", "local") .build(); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingsTests.java index a22f238e7d7..bea8fe25868 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingsTests.java @@ -10,7 +10,7 @@ import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.agent.AgentService; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.test.ESIntegTestCase; @@ -46,28 +46,28 @@ public class MarvelSettingsTests extends MarvelIntegTestCase { private Settings marvelSettings() { return Settings.builder() - .put(MarvelSettings.INTERVAL.getKey(), interval) - .put(MarvelSettings.INDEX_STATS_TIMEOUT.getKey(), indexStatsTimeout) - .put(MarvelSettings.INDICES_STATS_TIMEOUT.getKey(), indicesStatsTimeout) - .putArray(MarvelSettings.INDICES.getKey(), indices) - .put(MarvelSettings.CLUSTER_STATE_TIMEOUT.getKey(), clusterStateTimeout) - .put(MarvelSettings.CLUSTER_STATS_TIMEOUT.getKey(), clusterStatsTimeout) - .put(MarvelSettings.INDEX_RECOVERY_TIMEOUT.getKey(), recoveryTimeout) - .put(MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY.getKey(), recoveryActiveOnly) - .putArray(MarvelSettings.COLLECTORS.getKey(), collectors) + .put(MonitoringSettings.INTERVAL.getKey(), interval) + .put(MonitoringSettings.INDEX_STATS_TIMEOUT.getKey(), indexStatsTimeout) + .put(MonitoringSettings.INDICES_STATS_TIMEOUT.getKey(), indicesStatsTimeout) + .putArray(MonitoringSettings.INDICES.getKey(), indices) + .put(MonitoringSettings.CLUSTER_STATE_TIMEOUT.getKey(), clusterStateTimeout) + .put(MonitoringSettings.CLUSTER_STATS_TIMEOUT.getKey(), clusterStatsTimeout) + .put(MonitoringSettings.INDEX_RECOVERY_TIMEOUT.getKey(), recoveryTimeout) + .put(MonitoringSettings.INDEX_RECOVERY_ACTIVE_ONLY.getKey(), recoveryActiveOnly) + .putArray(MonitoringSettings.COLLECTORS.getKey(), collectors) .build(); } public void testMarvelSettings() throws Exception { logger.info("--> testing monitoring settings service initialization"); - for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) { - assertThat(marvelSettings.indexStatsTimeout().millis(), equalTo(indexStatsTimeout.millis())); - assertThat(marvelSettings.indicesStatsTimeout().millis(), equalTo(indicesStatsTimeout.millis())); - assertArrayEquals(marvelSettings.indices(), indices); - assertThat(marvelSettings.clusterStateTimeout().millis(), equalTo(clusterStateTimeout.millis())); - assertThat(marvelSettings.clusterStatsTimeout().millis(), equalTo(clusterStatsTimeout.millis())); - assertThat(marvelSettings.recoveryTimeout().millis(), equalTo(recoveryTimeout.millis())); - assertThat(marvelSettings.recoveryActiveOnly(), equalTo(recoveryActiveOnly)); + for (final MonitoringSettings monitoringSettings : internalCluster().getInstances(MonitoringSettings.class)) { + assertThat(monitoringSettings.indexStatsTimeout().millis(), equalTo(indexStatsTimeout.millis())); + assertThat(monitoringSettings.indicesStatsTimeout().millis(), equalTo(indicesStatsTimeout.millis())); + assertArrayEquals(monitoringSettings.indices(), indices); + assertThat(monitoringSettings.clusterStateTimeout().millis(), equalTo(clusterStateTimeout.millis())); + assertThat(monitoringSettings.clusterStatsTimeout().millis(), equalTo(clusterStatsTimeout.millis())); + assertThat(monitoringSettings.recoveryTimeout().millis(), equalTo(recoveryTimeout.millis())); + assertThat(monitoringSettings.recoveryActiveOnly(), equalTo(recoveryActiveOnly)); } for (final AgentService service : internalCluster().getInstances(AgentService.class)) { @@ -79,15 +79,15 @@ public class MarvelSettingsTests extends MarvelIntegTestCase { logger.info("--> testing monitoring dynamic settings update"); Settings.Builder transientSettings = Settings.builder(); final Setting[] marvelSettings = new Setting[] { - MarvelSettings.INDICES, - MarvelSettings.INTERVAL, - MarvelSettings.INDEX_RECOVERY_TIMEOUT, - MarvelSettings.INDEX_STATS_TIMEOUT, - MarvelSettings.INDICES_STATS_TIMEOUT, - MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY, - MarvelSettings.COLLECTORS, - MarvelSettings.CLUSTER_STATE_TIMEOUT, - MarvelSettings.CLUSTER_STATS_TIMEOUT }; + MonitoringSettings.INDICES, + MonitoringSettings.INTERVAL, + MonitoringSettings.INDEX_RECOVERY_TIMEOUT, + MonitoringSettings.INDEX_STATS_TIMEOUT, + MonitoringSettings.INDICES_STATS_TIMEOUT, + MonitoringSettings.INDEX_RECOVERY_ACTIVE_ONLY, + MonitoringSettings.COLLECTORS, + MonitoringSettings.CLUSTER_STATE_TIMEOUT, + MonitoringSettings.CLUSTER_STATS_TIMEOUT }; for (Setting setting : marvelSettings) { if (setting.isDynamic()) { Object updated = null; @@ -115,26 +115,26 @@ public class MarvelSettingsTests extends MarvelIntegTestCase { if (setting.isDynamic() == false) { continue; } - if (setting == MarvelSettings.INTERVAL) { + if (setting == MonitoringSettings.INTERVAL) { for (final AgentService service : internalCluster().getInstances(AgentService.class)) { assertEquals(service.getSamplingInterval(), setting.get(updatedSettings)); } } else { - for (final MarvelSettings marvelSettings1 : internalCluster().getInstances(MarvelSettings.class)) { - if (setting == MarvelSettings.INDEX_STATS_TIMEOUT) { - assertEquals(marvelSettings1.indexStatsTimeout(), setting.get(updatedSettings)); - } else if (setting == MarvelSettings.INDICES_STATS_TIMEOUT) { - assertEquals(marvelSettings1.indicesStatsTimeout(), setting.get(updatedSettings)); - } else if (setting == MarvelSettings.CLUSTER_STATS_TIMEOUT) { - assertEquals(marvelSettings1.clusterStatsTimeout(), setting.get(updatedSettings)); - } else if (setting == MarvelSettings.CLUSTER_STATE_TIMEOUT) { - assertEquals(marvelSettings1.clusterStateTimeout(), setting.get(updatedSettings)); - } else if (setting == MarvelSettings.INDEX_RECOVERY_TIMEOUT) { - assertEquals(marvelSettings1.recoveryTimeout(), setting.get(updatedSettings)); - } else if (setting == MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY) { - assertEquals(Boolean.valueOf(marvelSettings1.recoveryActiveOnly()), setting.get(updatedSettings)); - } else if (setting == MarvelSettings.INDICES) { - assertEquals(Arrays.asList(marvelSettings1.indices()), setting.get(updatedSettings)); + for (final MonitoringSettings monitoringSettings1 : internalCluster().getInstances(MonitoringSettings.class)) { + if (setting == MonitoringSettings.INDEX_STATS_TIMEOUT) { + assertEquals(monitoringSettings1.indexStatsTimeout(), setting.get(updatedSettings)); + } else if (setting == MonitoringSettings.INDICES_STATS_TIMEOUT) { + assertEquals(monitoringSettings1.indicesStatsTimeout(), setting.get(updatedSettings)); + } else if (setting == MonitoringSettings.CLUSTER_STATS_TIMEOUT) { + assertEquals(monitoringSettings1.clusterStatsTimeout(), setting.get(updatedSettings)); + } else if (setting == MonitoringSettings.CLUSTER_STATE_TIMEOUT) { + assertEquals(monitoringSettings1.clusterStateTimeout(), setting.get(updatedSettings)); + } else if (setting == MonitoringSettings.INDEX_RECOVERY_TIMEOUT) { + assertEquals(monitoringSettings1.recoveryTimeout(), setting.get(updatedSettings)); + } else if (setting == MonitoringSettings.INDEX_RECOVERY_ACTIVE_ONLY) { + assertEquals(Boolean.valueOf(monitoringSettings1.recoveryActiveOnly()), setting.get(updatedSettings)); + } else if (setting == MonitoringSettings.INDICES) { + assertEquals(Arrays.asList(monitoringSettings1.indices()), setting.get(updatedSettings)); } else { fail("unable to check value for unknown dynamic setting [" + setting + "]"); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/AbstractIndicesCleanerTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/AbstractIndicesCleanerTestCase.java index 1d56ea411bb..39060b09797 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/AbstractIndicesCleanerTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/AbstractIndicesCleanerTestCase.java @@ -7,7 +7,7 @@ package org.elasticsearch.marvel.cleaner; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.exporter.Exporter; import org.elasticsearch.marvel.agent.exporter.Exporters; @@ -31,7 +31,7 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase protected Settings nodeSettings(int nodeOrdinal) { Settings.Builder settings = Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MarvelSettings.INTERVAL.getKey(), "-1"); + .put(MonitoringSettings.INTERVAL.getKey(), "-1"); return settings.build(); } @@ -68,7 +68,7 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase public void testIgnoreDataIndicesInOtherVersions() throws Exception { internalCluster().startNode(); - createIndex(MarvelSettings.LEGACY_DATA_INDEX_NAME, now().minusYears(1)); + createIndex(MonitoringSettings.LEGACY_DATA_INDEX_NAME, now().minusYears(1)); createDataIndex(0, now().minusDays(10)); createDataIndex(Integer.MAX_VALUE, now().minusDays(20)); assertIndicesCount(3); @@ -143,7 +143,7 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase public void testRetentionAsGlobalSetting() throws Exception { final int max = 10; final int retention = randomIntBetween(1, max); - internalCluster().startNode(Settings.builder().put(MarvelSettings.HISTORY_DURATION.getKey(), + internalCluster().startNode(Settings.builder().put(MonitoringSettings.HISTORY_DURATION.getKey(), String.format(Locale.ROOT, "%dd", retention))); final DateTime now = now(); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/CleanerServiceTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/CleanerServiceTests.java index 8476a92e69b..97b3e7da384 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/CleanerServiceTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/CleanerServiceTests.java @@ -8,8 +8,8 @@ package org.elasticsearch.marvel.cleaner; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.marvel.MarvelSettings; -import org.elasticsearch.marvel.license.MarvelLicensee; +import org.elasticsearch.marvel.MonitoringSettings; +import org.elasticsearch.marvel.MonitoringLicensee; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.joda.time.DateTime; @@ -33,13 +33,13 @@ public class CleanerServiceTests extends ESTestCase { @Rule public ExpectedException expectedException = ExpectedException.none(); - private final MarvelLicensee licensee = mock(MarvelLicensee.class); + private final MonitoringLicensee licensee = mock(MonitoringLicensee.class); private ClusterSettings clusterSettings; private ThreadPool threadPool; @Before public void start() { - clusterSettings = new ClusterSettings(Settings.EMPTY, Collections.singleton(MarvelSettings.HISTORY_DURATION)); + clusterSettings = new ClusterSettings(Settings.EMPTY, Collections.singleton(MonitoringSettings.HISTORY_DURATION)); threadPool = new ThreadPool("CleanerServiceTests"); } @@ -53,14 +53,14 @@ public class CleanerServiceTests extends ESTestCase { expectedException.expect(IllegalArgumentException.class); TimeValue expected = TimeValue.timeValueHours(1); - Settings settings = Settings.builder().put(MarvelSettings.HISTORY_DURATION.getKey(), expected.getStringRep()).build(); + Settings settings = Settings.builder().put(MonitoringSettings.HISTORY_DURATION.getKey(), expected.getStringRep()).build(); new CleanerService(settings, clusterSettings, threadPool, licensee); } public void testGetRetentionWithSettingWithUpdatesAllowed() { TimeValue expected = TimeValue.timeValueHours(25); - Settings settings = Settings.builder().put(MarvelSettings.HISTORY_DURATION.getKey(), expected.getStringRep()).build(); + Settings settings = Settings.builder().put(MonitoringSettings.HISTORY_DURATION.getKey(), expected.getStringRep()).build(); when(licensee.allowUpdateRetention()).thenReturn(true); @@ -72,7 +72,7 @@ public class CleanerServiceTests extends ESTestCase { public void testGetRetentionDefaultValueWithNoSettings() { when(licensee.allowUpdateRetention()).thenReturn(true); - assertEquals(MarvelSettings.HISTORY_DURATION.get(Settings.EMPTY), + assertEquals(MonitoringSettings.HISTORY_DURATION.get(Settings.EMPTY), new CleanerService(Settings.EMPTY, clusterSettings, threadPool, licensee).getRetention()); verify(licensee).allowUpdateRetention(); @@ -80,11 +80,11 @@ public class CleanerServiceTests extends ESTestCase { public void testGetRetentionDefaultValueWithSettingsButUpdatesNotAllowed() { TimeValue notExpected = TimeValue.timeValueHours(25); - Settings settings = Settings.builder().put(MarvelSettings.HISTORY_DURATION.getKey(), notExpected.getStringRep()).build(); + Settings settings = Settings.builder().put(MonitoringSettings.HISTORY_DURATION.getKey(), notExpected.getStringRep()).build(); when(licensee.allowUpdateRetention()).thenReturn(false); - assertEquals(MarvelSettings.HISTORY_DURATION.get(Settings.EMPTY), + assertEquals(MonitoringSettings.HISTORY_DURATION.get(Settings.EMPTY), new CleanerService(settings, clusterSettings, threadPool, licensee).getRetention()); verify(licensee).allowUpdateRetention(); @@ -150,7 +150,7 @@ public class CleanerServiceTests extends ESTestCase { CountDownLatch latch = new CountDownLatch(nbExecutions); logger.debug("--> creates a cleaner service that cleans every second"); - MarvelLicensee licensee = mock(MarvelLicensee.class); + MonitoringLicensee licensee = mock(MonitoringLicensee.class); when(licensee.cleaningEnabled()).thenReturn(true); CleanerService service = new CleanerService(Settings.EMPTY, clusterSettings, licensee, threadPool, new TestExecutionScheduler(1_000)); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/LicenseIntegrationTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/LicenseIntegrationTests.java index 85669fe130c..c574e3f4912 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/LicenseIntegrationTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/LicenseIntegrationTests.java @@ -19,6 +19,7 @@ import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.LicenseeRegistry; import org.elasticsearch.license.plugin.core.LicensesManagerService; +import org.elasticsearch.marvel.MonitoringLicensee; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; @@ -62,10 +63,10 @@ public class LicenseIntegrationTests extends MarvelIntegTestCase { assertThat(getLicensee().collectionEnabled(), is(true)); } - private MarvelLicensee getLicensee() { - MarvelLicensee marvelLicensee = internalCluster().getInstance(MarvelLicensee.class); - assertNotNull(marvelLicensee); - return marvelLicensee; + private MonitoringLicensee getLicensee() { + MonitoringLicensee licensee = internalCluster().getInstance(MonitoringLicensee.class); + assertNotNull(licensee); + return licensee; } public static void disableLicensing() { diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java index 7e1eb108c72..dd5e017daf2 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase; import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.Licensee.Status; import org.elasticsearch.license.plugin.core.LicenseeRegistry; +import org.elasticsearch.marvel.MonitoringLicensee; import java.util.function.Predicate; @@ -21,13 +22,13 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; /** - * Tests {@link MarvelLicensee}. + * Tests {@link MonitoringLicensee}. *

    * If you change the behavior of these tests, then it means that licensing changes for Monitoring! */ public class MarvelLicenseeTests extends AbstractLicenseeTestCase { private final LicenseeRegistry registry = mock(LicenseeRegistry.class); - private final MarvelLicensee licensee = new MarvelLicensee(Settings.EMPTY, registry); + private final MonitoringLicensee licensee = new MonitoringLicensee(Settings.EMPTY, registry); public void testAcknowledgementMessagesToAnyFromFreeIsNoOp() { assertEmptyAck(OperationMode.BASIC, randomMode(), licensee); @@ -48,27 +49,27 @@ public class MarvelLicenseeTests extends AbstractLicenseeTestCase { } public void testCollectionEnabledIsTrueForActiveState() { - assertEnabled(randomEnabledOrGracePeriodState(), MarvelLicensee::collectionEnabled, true); + assertEnabled(randomEnabledOrGracePeriodState(), MonitoringLicensee::collectionEnabled, true); } public void testCollectionEnabledIsFalseForInactiveState() { - assertEnabled(LicenseState.DISABLED, MarvelLicensee::collectionEnabled, false); + assertEnabled(LicenseState.DISABLED, MonitoringLicensee::collectionEnabled, false); } public void testCleaningEnabledIsTrueForActiveState() { - assertEnabled(randomEnabledOrGracePeriodState(), MarvelLicensee::cleaningEnabled, true); + assertEnabled(randomEnabledOrGracePeriodState(), MonitoringLicensee::cleaningEnabled, true); } public void testCleaningEnabledIsFalseForInactiveState() { - assertEnabled(LicenseState.DISABLED, MarvelLicensee::cleaningEnabled, false); + assertEnabled(LicenseState.DISABLED, MonitoringLicensee::cleaningEnabled, false); } public void testAllowUpdateRetentionIsTrueForNotBasic() { - assertEnabled(randomModeExcept(OperationMode.BASIC), MarvelLicensee::allowUpdateRetention, true); + assertEnabled(randomModeExcept(OperationMode.BASIC), MonitoringLicensee::allowUpdateRetention, true); } public void testAllowUpdateRetentionIsFalseForBasic() { - assertEnabled(OperationMode.BASIC, MarvelLicensee::allowUpdateRetention, false); + assertEnabled(OperationMode.BASIC, MonitoringLicensee::allowUpdateRetention, false); } /** @@ -78,7 +79,7 @@ public class MarvelLicenseeTests extends AbstractLicenseeTestCase { * @param predicate The method to invoke (expected to be an instance method). * @param expected The expected outcome given the {@code state} and {@code predicate}. */ - private void assertEnabled(LicenseState state, Predicate predicate, boolean expected) { + private void assertEnabled(LicenseState state, Predicate predicate, boolean expected) { Status status = mock(Status.class); when(status.getLicenseState()).thenReturn(state); @@ -97,7 +98,7 @@ public class MarvelLicenseeTests extends AbstractLicenseeTestCase { * @param predicate The method to invoke (expected to be an instance method). * @param expected The expected outcome given the {@code mode} and {@code predicate}. */ - private void assertEnabled(OperationMode mode, Predicate predicate, boolean expected) { + private void assertEnabled(OperationMode mode, Predicate predicate, boolean expected) { Status status = mock(Status.class); when(status.getMode()).thenReturn(mode); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/shield/MarvelInternalClientTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/shield/MarvelInternalClientTests.java index 8a21703608e..4a51d2d28c0 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/shield/MarvelInternalClientTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/shield/MarvelInternalClientTests.java @@ -10,7 +10,7 @@ import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexNotFoundException; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.shield.InternalClient; @@ -27,7 +27,7 @@ public class MarvelInternalClientTests extends MarvelIntegTestCase { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) .put(NetworkModule.HTTP_ENABLED.getKey(), false) - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .build(); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/shield/MarvelSettingsFilterTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/shield/MarvelSettingsFilterTests.java index cf7c6459fcf..f847966061a 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/shield/MarvelSettingsFilterTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/shield/MarvelSettingsFilterTests.java @@ -11,7 +11,7 @@ import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.http.HttpServerTransport; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.test.rest.client.http.HttpRequestBuilder; @@ -41,7 +41,7 @@ public class MarvelSettingsFilterTests extends MarvelIntegTestCase { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) .put(NetworkModule.HTTP_ENABLED.getKey(), true) - .put(MarvelSettings.INTERVAL.getKey(), "-1") + .put(MonitoringSettings.INTERVAL.getKey(), "-1") .put("xpack.monitoring.agent.exporters._http.type", "http") .put("xpack.monitoring.agent.exporters._http.enabled", false) .put("xpack.monitoring.agent.exporters._http.auth.username", "_user") diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java index b09d1c269f4..c007990500e 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java @@ -17,7 +17,7 @@ import org.elasticsearch.common.util.concurrent.CountDown; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.IndexNotFoundException; -import org.elasticsearch.marvel.MarvelSettings; +import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.AgentService; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; @@ -435,7 +435,7 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase { protected void updateMarvelInterval(long value, TimeUnit timeUnit) { assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings( - Settings.builder().put(MarvelSettings.INTERVAL.getKey(), value, timeUnit))); + Settings.builder().put(MonitoringSettings.INTERVAL.getKey(), value, timeUnit))); } protected class MockDataIndexNameResolver extends MonitoringIndexNameResolver.Data { diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/Security.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/Security.java index 641e779b672..285bc330ca3 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/Security.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/Security.java @@ -21,28 +21,28 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.IndexModule; -import org.elasticsearch.shield.action.filter.ShieldActionFilter; import org.elasticsearch.shield.action.ShieldActionModule; +import org.elasticsearch.shield.action.filter.ShieldActionFilter; import org.elasticsearch.shield.action.realm.ClearRealmCacheAction; import org.elasticsearch.shield.action.realm.TransportClearRealmCacheAction; -import org.elasticsearch.shield.action.role.PutRoleAction; import org.elasticsearch.shield.action.role.ClearRolesCacheAction; import org.elasticsearch.shield.action.role.DeleteRoleAction; import org.elasticsearch.shield.action.role.GetRolesAction; -import org.elasticsearch.shield.action.role.TransportPutRoleAction; +import org.elasticsearch.shield.action.role.PutRoleAction; import org.elasticsearch.shield.action.role.TransportClearRolesCacheAction; import org.elasticsearch.shield.action.role.TransportDeleteRoleAction; import org.elasticsearch.shield.action.role.TransportGetRolesAction; +import org.elasticsearch.shield.action.role.TransportPutRoleAction; import org.elasticsearch.shield.action.user.AuthenticateAction; import org.elasticsearch.shield.action.user.ChangePasswordAction; -import org.elasticsearch.shield.action.user.PutUserAction; import org.elasticsearch.shield.action.user.DeleteUserAction; import org.elasticsearch.shield.action.user.GetUsersAction; +import org.elasticsearch.shield.action.user.PutUserAction; import org.elasticsearch.shield.action.user.TransportAuthenticateAction; import org.elasticsearch.shield.action.user.TransportChangePasswordAction; -import org.elasticsearch.shield.action.user.TransportPutUserAction; import org.elasticsearch.shield.action.user.TransportDeleteUserAction; import org.elasticsearch.shield.action.user.TransportGetUsersAction; +import org.elasticsearch.shield.action.user.TransportPutUserAction; import org.elasticsearch.shield.audit.AuditTrailModule; import org.elasticsearch.shield.audit.index.IndexAuditTrail; import org.elasticsearch.shield.audit.index.IndexNameResolver; @@ -62,20 +62,17 @@ import org.elasticsearch.shield.authz.store.FileRolesStore; import org.elasticsearch.shield.authz.store.NativeRolesStore; import org.elasticsearch.shield.crypto.CryptoModule; import org.elasticsearch.shield.crypto.InternalCryptoService; -import org.elasticsearch.shield.license.LicenseModule; -import org.elasticsearch.shield.license.ShieldLicenseState; -import org.elasticsearch.shield.license.ShieldLicensee; import org.elasticsearch.shield.rest.ShieldRestModule; import org.elasticsearch.shield.rest.action.RestAuthenticateAction; import org.elasticsearch.shield.rest.action.realm.RestClearRealmCacheAction; -import org.elasticsearch.shield.rest.action.role.RestPutRoleAction; import org.elasticsearch.shield.rest.action.role.RestClearRolesCacheAction; import org.elasticsearch.shield.rest.action.role.RestDeleteRoleAction; import org.elasticsearch.shield.rest.action.role.RestGetRolesAction; +import org.elasticsearch.shield.rest.action.role.RestPutRoleAction; import org.elasticsearch.shield.rest.action.user.RestChangePasswordAction; -import org.elasticsearch.shield.rest.action.user.RestPutUserAction; import org.elasticsearch.shield.rest.action.user.RestDeleteUserAction; import org.elasticsearch.shield.rest.action.user.RestGetUsersAction; +import org.elasticsearch.shield.rest.action.user.RestPutUserAction; import org.elasticsearch.shield.ssl.SSLModule; import org.elasticsearch.shield.ssl.SSLSettings; import org.elasticsearch.shield.support.OptionalStringSetting; @@ -114,7 +111,7 @@ public class Security { private final Settings settings; private final boolean enabled; private final boolean transportClientMode; - private ShieldLicenseState shieldLicenseState; + private SecurityLicenseState securityLicenseState; public Security(Settings settings) { this.settings = settings; @@ -126,32 +123,36 @@ public class Security { } public Collection nodeModules() { - - if (enabled == false) { - return Collections.singletonList(new ShieldDisabledModule(settings)); - } - - if (transportClientMode == true) { - return Arrays.asList( - new ShieldTransportModule(settings), - new SSLModule(settings)); - } + List modules = new ArrayList<>(); // we can't load that at construction time since the license plugin might not have been loaded at that point // which might not be the case during Plugin class instantiation. Once nodeModules are pulled // everything should have been loaded - shieldLicenseState = new ShieldLicenseState(); - return Arrays.asList( - new ShieldModule(settings), - new LicenseModule(settings, shieldLicenseState), - new CryptoModule(settings), - new AuthenticationModule(settings), - new AuthorizationModule(settings), - new AuditTrailModule(settings), - new ShieldRestModule(settings), - new ShieldActionModule(settings), - new ShieldTransportModule(settings), - new SSLModule(settings)); + if (enabled && transportClientMode == false) { + securityLicenseState = new SecurityLicenseState(); + } + + modules.add(new SecurityModule(settings, securityLicenseState)); + + if (enabled == false) { + return modules; + } + + if (transportClientMode == true) { + modules.add(new ShieldTransportModule(settings)); + modules.add(new SSLModule(settings)); + return modules; + } + + modules.add(new CryptoModule(settings)); + modules.add(new AuthenticationModule(settings)); + modules.add(new AuthorizationModule(settings)); + modules.add(new AuditTrailModule(settings)); + modules.add(new ShieldRestModule(settings)); + modules.add(new ShieldActionModule(settings)); + modules.add(new ShieldTransportModule(settings)); + modules.add(new SSLModule(settings)); + return modules; } public Collection> nodeServices() { @@ -164,7 +165,7 @@ public class Security { if (AuditTrailModule.fileAuditLoggingEnabled(settings) == true) { list.add(LoggingAuditTrail.class); } - list.add(ShieldLicensee.class); + list.add(SecurityLicensee.class); list.add(InternalCryptoService.class); list.add(FileRolesStore.class); list.add(Realms.class); @@ -249,12 +250,12 @@ public class Security { return; } - assert shieldLicenseState != null; + assert securityLicenseState != null; if (flsDlsEnabled(settings)) { module.setSearcherWrapper((indexService) -> new ShieldIndexSearcherWrapper(indexService.getIndexSettings(), indexService.newQueryShardContext(), indexService.mapperService(), indexService.cache().bitsetFilterCache(), indexService.getIndexServices().getThreadPool().getThreadContext(), - shieldLicenseState)); + securityLicenseState)); } if (transportClientMode == false) { /* We need to forcefully overwrite the query cache implementation to use Shield's opt out query cache implementation. diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityFeatureSet.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityFeatureSet.java new file mode 100644 index 00000000000..2d0410d41ef --- /dev/null +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityFeatureSet.java @@ -0,0 +1,46 @@ +/* + * 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.shield; + +import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.xpack.XPackFeatureSet; + +/** + * + */ +public class SecurityFeatureSet implements XPackFeatureSet { + + private final boolean enabled; + private final SecurityLicenseState licenseState; + + @Inject + public SecurityFeatureSet(Settings settings, @Nullable SecurityLicenseState licenseState) { + this.enabled = Security.enabled(settings); + this.licenseState = licenseState; + } + + @Override + public String name() { + return Security.NAME; + } + + @Override + public String description() { + return "Security for the Elastic Stack"; + } + + @Override + public boolean available() { + return licenseState != null && licenseState.securityEnabled(); + } + + @Override + public boolean enabled() { + return enabled; + } +} diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicenseState.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityLicenseState.java similarity index 95% rename from elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicenseState.java rename to elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityLicenseState.java index 078ed00af1f..8426e555057 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicenseState.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityLicenseState.java @@ -3,7 +3,7 @@ * 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.shield.license; +package org.elasticsearch.shield; import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.plugin.core.LicenseState; @@ -11,10 +11,10 @@ import org.elasticsearch.license.plugin.core.Licensee.Status; /** - * This class serves to decouple shield code that needs to check the license state from the {@link ShieldLicensee} as the + * This class serves to decouple shield code that needs to check the license state from the {@link SecurityLicensee} as the * tight coupling causes issues with guice injection and circular dependencies */ -public class ShieldLicenseState { +public class SecurityLicenseState { // we initialize the licensee status to enabled with trial operation mode to ensure no // legitimate requests are blocked before initial license plugin notification diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicensee.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityLicensee.java similarity index 90% rename from elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicensee.java rename to elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityLicensee.java index 185794a978b..49db1413600 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicensee.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityLicensee.java @@ -3,7 +3,7 @@ * 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.shield.license; +package org.elasticsearch.shield; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.Strings; @@ -13,18 +13,17 @@ import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent; import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.LicenseeRegistry; -import org.elasticsearch.shield.Security; /** * */ -public class ShieldLicensee extends AbstractLicenseeComponent implements Licensee { +public class SecurityLicensee extends AbstractLicenseeComponent implements Licensee { private final boolean isTribeNode; - private final ShieldLicenseState shieldLicenseState; + private final SecurityLicenseState shieldLicenseState; @Inject - public ShieldLicensee(Settings settings, LicenseeRegistry clientService, ShieldLicenseState shieldLicenseState) { + public SecurityLicensee(Settings settings, LicenseeRegistry clientService, SecurityLicenseState shieldLicenseState) { super(settings, Security.NAME, clientService); this.shieldLicenseState = shieldLicenseState; this.isTribeNode = settings.getGroups("tribe", true).isEmpty() == false; diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityModule.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityModule.java new file mode 100644 index 00000000000..5cc3881532f --- /dev/null +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/SecurityModule.java @@ -0,0 +1,53 @@ +/* + * 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.shield; + +import org.elasticsearch.common.inject.util.Providers; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.shield.support.AbstractShieldModule; +import org.elasticsearch.xpack.XPackPlugin; + +/** + * + */ +public class SecurityModule extends AbstractShieldModule { + + private final SecurityLicenseState securityLicenseState; + + public SecurityModule(Settings settings, SecurityLicenseState securityLicenseState) { + super(settings); + this.securityLicenseState = securityLicenseState; + } + + @Override + protected void configure(boolean clientMode) { + if (clientMode) { + return; + } + + if (securityLicenseState != null) { + bind(SecurityLicenseState.class).toInstance(securityLicenseState); + } else { + bind(SecurityLicenseState.class).toProvider(Providers.of(null)); + } + + XPackPlugin.bindFeatureSet(binder(), SecurityFeatureSet.class); + + if (shieldEnabled) { + bind(SecurityContext.Secure.class).asEagerSingleton(); + bind(SecurityContext.class).to(SecurityContext.Secure.class); + bind(ShieldLifecycleService.class).asEagerSingleton(); + bind(InternalClient.Secure.class).asEagerSingleton(); + bind(InternalClient.class).to(InternalClient.Secure.class); + + } else { + bind(SecurityContext.class).toInstance(SecurityContext.Insecure.INSTANCE); + bind(InternalClient.Insecure.class).asEagerSingleton(); + bind(InternalClient.class).to(InternalClient.Insecure.class); + } + } + +} diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldDisabledModule.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldDisabledModule.java deleted file mode 100644 index a52a695d7d7..00000000000 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldDisabledModule.java +++ /dev/null @@ -1,32 +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.shield; - -import org.elasticsearch.common.inject.util.Providers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.shield.license.ShieldLicenseState; -import org.elasticsearch.shield.support.AbstractShieldModule; - -public class ShieldDisabledModule extends AbstractShieldModule { - - public ShieldDisabledModule(Settings settings) { - super(settings); - } - - @Override - protected void configure(boolean clientMode) { - assert !shieldEnabled : "shield disabled module should only get loaded with shield disabled"; - if (!clientMode) { - // required by the shield info rest action (when shield is disabled) - bind(ShieldLicenseState.class).toProvider(Providers.of(null)); - - bind(SecurityContext.class).toInstance(SecurityContext.Insecure.INSTANCE); - - bind(InternalClient.Insecure.class).asEagerSingleton(); - bind(InternalClient.class).to(InternalClient.Insecure.class); - } - } -} diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldModule.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldModule.java deleted file mode 100644 index d82cf10cffc..00000000000 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldModule.java +++ /dev/null @@ -1,30 +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.shield; - -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.shield.support.AbstractShieldModule; - -/** - * - */ -public class ShieldModule extends AbstractShieldModule { - - public ShieldModule(Settings settings) { - super(settings); - } - - @Override - protected void configure(boolean clientMode) { - if (!clientMode) { - bind(SecurityContext.Secure.class).asEagerSingleton(); - bind(SecurityContext.class).to(SecurityContext.Secure.class); - bind(ShieldLifecycleService.class).asEagerSingleton(); - bind(InternalClient.Secure.class).asEagerSingleton(); - bind(InternalClient.class).to(InternalClient.Secure.class); - } - } -} diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/filter/ShieldActionFilter.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/filter/ShieldActionFilter.java index 426fcc7240e..5d7c10bddc9 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/filter/ShieldActionFilter.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/filter/ShieldActionFilter.java @@ -31,7 +31,7 @@ import org.elasticsearch.shield.authz.AuthorizationService; import org.elasticsearch.shield.authz.AuthorizationUtils; import org.elasticsearch.shield.authz.privilege.HealthAndStatsPrivilege; import org.elasticsearch.shield.crypto.CryptoService; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; @@ -56,12 +56,12 @@ public class ShieldActionFilter extends AbstractComponent implements ActionFilte private final AuditTrail auditTrail; private final ShieldActionMapper actionMapper; private final Set requestInterceptors; - private final ShieldLicenseState licenseState; + private final SecurityLicenseState licenseState; private final ThreadContext threadContext; @Inject public ShieldActionFilter(Settings settings, AuthenticationService authcService, AuthorizationService authzService, - CryptoService cryptoService, AuditTrail auditTrail, ShieldLicenseState licenseState, + CryptoService cryptoService, AuditTrail auditTrail, SecurityLicenseState licenseState, ShieldActionMapper actionMapper, Set requestInterceptors, ThreadPool threadPool) { super(settings); this.authcService = authcService; diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/Realms.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/Realms.java index 0bc68a60247..90ed0446392 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/Realms.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/Realms.java @@ -16,7 +16,7 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.shield.authc.esnative.ReservedRealm; import org.elasticsearch.shield.authc.esnative.NativeRealm; import org.elasticsearch.shield.authc.file.FileRealm; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import java.util.ArrayList; import java.util.Collections; @@ -37,7 +37,7 @@ public class Realms extends AbstractLifecycleComponent implements Iterab private final Environment env; private final Map factories; - private final ShieldLicenseState shieldLicenseState; + private final SecurityLicenseState shieldLicenseState; private final ReservedRealm reservedRealm; protected List realms = Collections.emptyList(); @@ -45,7 +45,7 @@ public class Realms extends AbstractLifecycleComponent implements Iterab protected List internalRealmsOnly = Collections.emptyList(); @Inject - public Realms(Settings settings, Environment env, Map factories, ShieldLicenseState shieldLicenseState, + public Realms(Settings settings, Environment env, Map factories, SecurityLicenseState shieldLicenseState, ReservedRealm reservedRealm) { super(settings); this.env = env; diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java index 0fcae47b741..f4ca7e9e24a 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java @@ -6,7 +6,6 @@ package org.elasticsearch.shield.authz.accesscontrol; import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BulkScorer; @@ -33,10 +32,8 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.cache.bitset.BitsetFilterCache; import org.elasticsearch.index.engine.EngineException; import org.elasticsearch.index.mapper.DocumentMapper; -import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.internal.ParentFieldMapper; -import org.elasticsearch.index.percolator.PercolatorFieldMapper; import org.elasticsearch.index.query.ParsedQuery; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.shard.IndexSearcherWrapper; @@ -44,7 +41,7 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardUtils; import org.elasticsearch.shield.authz.InternalAuthorizationService; import org.elasticsearch.shield.authz.accesscontrol.DocumentSubsetReader.DocumentSubsetDirectoryReader; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.shield.support.Exceptions; import java.io.IOException; @@ -73,13 +70,13 @@ public class ShieldIndexSearcherWrapper extends IndexSearcherWrapper { private final Set allowedMetaFields; private final QueryShardContext queryShardContext; private final BitsetFilterCache bitsetFilterCache; - private final ShieldLicenseState shieldLicenseState; + private final SecurityLicenseState shieldLicenseState; private final ThreadContext threadContext; private final ESLogger logger; public ShieldIndexSearcherWrapper(IndexSettings indexSettings, QueryShardContext queryShardContext, MapperService mapperService, BitsetFilterCache bitsetFilterCache, - ThreadContext threadContext, ShieldLicenseState shieldLicenseState) { + ThreadContext threadContext, SecurityLicenseState shieldLicenseState) { this.logger = Loggers.getLogger(getClass(), indexSettings.getSettings()); this.mapperService = mapperService; this.queryShardContext = queryShardContext; diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/LicenseModule.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/LicenseModule.java deleted file mode 100644 index f15708b3254..00000000000 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/LicenseModule.java +++ /dev/null @@ -1,29 +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.shield.license; - -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.shield.support.AbstractShieldModule; - -/** - * - */ -public class LicenseModule extends AbstractShieldModule.Node { - - private final ShieldLicenseState shieldLicenseState; - - public LicenseModule(Settings settings, ShieldLicenseState shieldLicenseState) { - super(settings); - this.shieldLicenseState = shieldLicenseState; - } - - @Override - protected void configureNode() { - bind(ShieldLicensee.class).asEagerSingleton(); - bind(ShieldLicenseState.class).toInstance(shieldLicenseState); - } - -} diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/ShieldRestFilter.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/ShieldRestFilter.java index cb470ffa4d3..f938566c224 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/ShieldRestFilter.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/ShieldRestFilter.java @@ -18,7 +18,7 @@ import org.elasticsearch.rest.RestFilterChain; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.shield.authc.AuthenticationService; import org.elasticsearch.shield.authc.pki.PkiRealm; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.shield.transport.netty.ShieldNettyHttpServerTransport; import org.elasticsearch.threadpool.ThreadPool; import org.jboss.netty.handler.ssl.SslHandler; @@ -34,13 +34,13 @@ public class ShieldRestFilter extends RestFilter { private final AuthenticationService service; private final ESLogger logger; - private final ShieldLicenseState licenseState; + private final SecurityLicenseState licenseState; private final ThreadContext threadContext; private final boolean extractClientCertificate; @Inject public ShieldRestFilter(AuthenticationService service, RestController controller, Settings settings, - ThreadPool threadPool, ShieldLicenseState licenseState) { + ThreadPool threadPool, SecurityLicenseState licenseState) { this.service = service; this.licenseState = licenseState; this.threadContext = threadPool.getThreadContext(); diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldServerTransportService.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldServerTransportService.java index ee79f6628d0..ed0ac6070c5 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldServerTransportService.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldServerTransportService.java @@ -14,7 +14,7 @@ import org.elasticsearch.shield.authc.AuthenticationService; import org.elasticsearch.shield.authz.AuthorizationService; import org.elasticsearch.shield.authz.AuthorizationUtils; import org.elasticsearch.shield.authz.accesscontrol.RequestContext; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.shield.transport.netty.ShieldNettyTransport; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; @@ -49,7 +49,7 @@ public class ShieldServerTransportService extends TransportService { protected final AuthorizationService authzService; protected final ShieldActionMapper actionMapper; protected final ClientTransportFilter clientFilter; - protected final ShieldLicenseState licenseState; + protected final SecurityLicenseState licenseState; protected final Map profileFilters; @@ -59,7 +59,7 @@ public class ShieldServerTransportService extends TransportService { AuthorizationService authzService, ShieldActionMapper actionMapper, ClientTransportFilter clientTransportFilter, - ShieldLicenseState licenseState) { + SecurityLicenseState licenseState) { super(settings, transport, threadPool); this.authcService = authcService; this.authzService = authzService; @@ -158,11 +158,11 @@ public class ShieldServerTransportService extends TransportService { protected final String action; protected final TransportRequestHandler handler; private final Map profileFilters; - private final ShieldLicenseState licenseState; + private final SecurityLicenseState licenseState; private final ThreadContext threadContext; public ProfileSecuredRequestHandler(String action, TransportRequestHandler handler, - Map profileFilters, ShieldLicenseState licenseState, + Map profileFilters, SecurityLicenseState licenseState, ThreadContext threadContext) { this.action = action; this.handler = handler; diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/filter/IPFilter.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/filter/IPFilter.java index 7a4100c6bd6..3fe73e781c9 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/filter/IPFilter.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/filter/IPFilter.java @@ -18,7 +18,7 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.transport.BoundTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.shield.audit.AuditTrail; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.transport.TransportSettings; import java.net.InetAddress; @@ -89,7 +89,7 @@ public class IPFilter { }; private final AuditTrail auditTrail; - private final ShieldLicenseState licenseState; + private final SecurityLicenseState licenseState; private final boolean alwaysAllowBoundAddresses; private final ESLogger logger; @@ -107,7 +107,7 @@ public class IPFilter { @Inject public IPFilter(final Settings settings, AuditTrail auditTrail, ClusterSettings clusterSettings, - ShieldLicenseState licenseState) { + SecurityLicenseState licenseState) { this.logger = Loggers.getLogger(getClass(), settings); this.auditTrail = auditTrail; this.licenseState = licenseState; diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseStateTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldLicenseStateTests.java similarity index 86% rename from elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseStateTests.java rename to elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldLicenseStateTests.java index 5c806a972aa..cbef7881fa8 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseStateTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldLicenseStateTests.java @@ -3,7 +3,7 @@ * 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.shield.license; +package org.elasticsearch.shield; import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.core.LicenseState; @@ -13,12 +13,12 @@ import org.elasticsearch.test.ESTestCase; import static org.hamcrest.Matchers.is; /** - * Unit tests for the {@link ShieldLicenseState} + * Unit tests for the {@link SecurityLicenseState} */ public class ShieldLicenseStateTests extends ESTestCase { public void testDefaults() { - ShieldLicenseState licenseState = new ShieldLicenseState(); + SecurityLicenseState licenseState = new SecurityLicenseState(); assertThat(licenseState.securityEnabled(), is(true)); assertThat(licenseState.statsAndHealthEnabled(), is(true)); assertThat(licenseState.documentAndFieldLevelSecurityEnabled(), is(true)); @@ -26,7 +26,7 @@ public class ShieldLicenseStateTests extends ESTestCase { } public void testBasic() { - ShieldLicenseState licenseState = new ShieldLicenseState(); + SecurityLicenseState licenseState = new SecurityLicenseState(); licenseState.updateStatus(new Licensee.Status(License.OperationMode.BASIC, randomBoolean() ? LicenseState.ENABLED : LicenseState.GRACE_PERIOD)); @@ -37,7 +37,7 @@ public class ShieldLicenseStateTests extends ESTestCase { } public void testBasicExpired() { - ShieldLicenseState licenseState = new ShieldLicenseState(); + SecurityLicenseState licenseState = new SecurityLicenseState(); licenseState.updateStatus(new Licensee.Status(License.OperationMode.BASIC, LicenseState.DISABLED)); assertThat(licenseState.securityEnabled(), is(false)); @@ -47,7 +47,7 @@ public class ShieldLicenseStateTests extends ESTestCase { } public void testGold() { - ShieldLicenseState licenseState = new ShieldLicenseState(); + SecurityLicenseState licenseState = new SecurityLicenseState(); licenseState.updateStatus(new Licensee.Status(License.OperationMode.GOLD, randomBoolean() ? LicenseState.ENABLED : LicenseState.GRACE_PERIOD)); @@ -58,7 +58,7 @@ public class ShieldLicenseStateTests extends ESTestCase { } public void testGoldExpired() { - ShieldLicenseState licenseState = new ShieldLicenseState(); + SecurityLicenseState licenseState = new SecurityLicenseState(); licenseState.updateStatus(new Licensee.Status(License.OperationMode.GOLD, LicenseState.DISABLED)); assertThat(licenseState.securityEnabled(), is(true)); @@ -68,7 +68,7 @@ public class ShieldLicenseStateTests extends ESTestCase { } public void testPlatinum() { - ShieldLicenseState licenseState = new ShieldLicenseState(); + SecurityLicenseState licenseState = new SecurityLicenseState(); licenseState.updateStatus(new Licensee.Status(License.OperationMode.PLATINUM, randomBoolean() ? LicenseState.ENABLED : LicenseState.GRACE_PERIOD)); @@ -79,7 +79,7 @@ public class ShieldLicenseStateTests extends ESTestCase { } public void testPlatinumExpired() { - ShieldLicenseState licenseState = new ShieldLicenseState(); + SecurityLicenseState licenseState = new SecurityLicenseState(); licenseState.updateStatus(new Licensee.Status(License.OperationMode.PLATINUM, LicenseState.DISABLED)); assertThat(licenseState.securityEnabled(), is(true)); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseeTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldLicenseeTests.java similarity index 84% rename from elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseeTests.java rename to elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldLicenseeTests.java index 2ff192f37ec..6e4cfdf845e 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseeTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldLicenseeTests.java @@ -3,7 +3,7 @@ * 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.shield.license; +package org.elasticsearch.shield; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.core.License.OperationMode; @@ -17,16 +17,16 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; /** - * Tests {@link ShieldLicensee}. + * Tests {@link SecurityLicensee}. *

    * If you change the behavior of these tests, then it means that licensing changes for Security! */ public class ShieldLicenseeTests extends AbstractLicenseeTestCase { - private final ShieldLicenseState shieldState = mock(ShieldLicenseState.class); + private final SecurityLicenseState shieldState = mock(SecurityLicenseState.class); private final LicenseeRegistry registry = mock(LicenseeRegistry.class); public void testStartsWithoutTribeNode() { - ShieldLicensee licensee = new ShieldLicensee(Settings.EMPTY, registry, shieldState); + SecurityLicensee licensee = new SecurityLicensee(Settings.EMPTY, registry, shieldState); // starting the Licensee start trigger it being registered licensee.start(); @@ -37,7 +37,7 @@ public class ShieldLicenseeTests extends AbstractLicenseeTestCase { public void testDoesNotStartWithTribeNode() { Settings settings = Settings.builder().put("tribe.fake.cluster.name", "notchecked").build(); - ShieldLicensee licensee = new ShieldLicensee(settings, registry, shieldState); + SecurityLicensee licensee = new SecurityLicensee(settings, registry, shieldState); // starting the Licensee as a tribe node should not trigger it being registered licensee.start(); @@ -48,7 +48,7 @@ public class ShieldLicenseeTests extends AbstractLicenseeTestCase { public void testOnChangeModifiesShieldLicenseState() { Status status = mock(Status.class); - ShieldLicensee licensee = new ShieldLicensee(Settings.EMPTY, registry, shieldState); + SecurityLicensee licensee = new SecurityLicensee(Settings.EMPTY, registry, shieldState); licensee.onChange(status); @@ -83,7 +83,7 @@ public class ShieldLicenseeTests extends AbstractLicenseeTestCase { assertThat(messages.length, equalTo(2)); } - private ShieldLicensee buildLicensee() { - return new ShieldLicensee(Settings.EMPTY, registry, shieldState); + private SecurityLicensee buildLicensee() { + return new SecurityLicensee(Settings.EMPTY, registry, shieldState); } } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldPluginTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldPluginTests.java index 9fd7c5febe2..2f543a4b280 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldPluginTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldPluginTests.java @@ -26,6 +26,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; public class ShieldPluginTests extends ShieldIntegTestCase { + @Override public Settings nodeSettings(int nodeOrdinal) { return Settings.builder() @@ -53,9 +54,6 @@ public class ShieldPluginTests extends ShieldIntegTestCase { new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))) .execute(); assertThat(response.getStatusCode(), is(OK.getStatus())); - assertThat(response.getBody(), allOf(containsString("status"), containsString("hash"), - containsString("timestamp"), containsString("uid"), - containsString("type"), containsString("status"))); } } } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/action/filter/ShieldActionFilterTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/action/filter/ShieldActionFilterTests.java index 24e7c4feb34..38010bf5a0c 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/action/filter/ShieldActionFilterTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/action/filter/ShieldActionFilterTests.java @@ -19,7 +19,7 @@ import org.elasticsearch.shield.audit.AuditTrail; import org.elasticsearch.shield.authc.AuthenticationService; import org.elasticsearch.shield.authz.AuthorizationService; import org.elasticsearch.shield.crypto.CryptoService; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.tasks.Task; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -47,7 +47,7 @@ public class ShieldActionFilterTests extends ESTestCase { private AuthorizationService authzService; private CryptoService cryptoService; private AuditTrail auditTrail; - private ShieldLicenseState shieldLicenseState; + private SecurityLicenseState shieldLicenseState; private ShieldActionFilter filter; @Before @@ -56,7 +56,7 @@ public class ShieldActionFilterTests extends ESTestCase { authzService = mock(AuthorizationService.class); cryptoService = mock(CryptoService.class); auditTrail = mock(AuditTrail.class); - shieldLicenseState = mock(ShieldLicenseState.class); + shieldLicenseState = mock(SecurityLicenseState.class); when(shieldLicenseState.securityEnabled()).thenReturn(true); when(shieldLicenseState.statsAndHealthEnabled()).thenReturn(true); ThreadPool threadPool = mock(ThreadPool.class); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/InternalAuthenticationServiceTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/InternalAuthenticationServiceTests.java index 5301e33bb0f..ea9ebb28d89 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/InternalAuthenticationServiceTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/InternalAuthenticationServiceTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.shield.authc.esnative.ReservedRealm; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.authc.support.UsernamePasswordToken; import org.elasticsearch.shield.crypto.CryptoService; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.threadpool.ThreadPool; @@ -87,7 +87,7 @@ public class InternalAuthenticationServiceTests extends ESTestCase { secondRealm = mock(Realm.class); when(secondRealm.type()).thenReturn("second"); Settings settings = Settings.builder().put("path.home", createTempDir()).build(); - ShieldLicenseState shieldLicenseState = mock(ShieldLicenseState.class); + SecurityLicenseState shieldLicenseState = mock(SecurityLicenseState.class); when(shieldLicenseState.customRealmsEnabled()).thenReturn(true); realms = new Realms(Settings.EMPTY, new Environment(settings), Collections.emptyMap(), shieldLicenseState, mock(ReservedRealm.class)) { diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/RealmsTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/RealmsTests.java index c9e5f0ea54a..f5afd3fdd10 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/RealmsTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/RealmsTests.java @@ -13,7 +13,7 @@ import org.elasticsearch.shield.authc.esnative.ReservedRealm; import org.elasticsearch.shield.authc.esnative.NativeRealm; import org.elasticsearch.shield.authc.file.FileRealm; import org.elasticsearch.shield.authc.ldap.LdapRealm; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.test.ESTestCase; import org.junit.Before; @@ -37,7 +37,7 @@ import static org.mockito.Mockito.when; */ public class RealmsTests extends ESTestCase { private Map factories; - private ShieldLicenseState shieldLicenseState; + private SecurityLicenseState shieldLicenseState; private ReservedRealm reservedRealm; @Before @@ -49,7 +49,7 @@ public class RealmsTests extends ESTestCase { DummyRealm.Factory factory = new DummyRealm.Factory("type_" + i, rarely()); factories.put("type_" + i, factory); } - shieldLicenseState = mock(ShieldLicenseState.class); + shieldLicenseState = mock(SecurityLicenseState.class); reservedRealm = mock(ReservedRealm.class); when(shieldLicenseState.customRealmsEnabled()).thenReturn(true); } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperIntegrationTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperIntegrationTests.java index 839b0f8e7b1..6418399f3e0 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperIntegrationTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperIntegrationTests.java @@ -31,7 +31,7 @@ import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.query.ParsedQuery; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.IndexSettingsModule; @@ -71,7 +71,7 @@ public class ShieldIndexSearcherWrapperIntegrationTests extends ESTestCase { } }); - ShieldLicenseState licenseState = mock(ShieldLicenseState.class); + SecurityLicenseState licenseState = mock(SecurityLicenseState.class); when(licenseState.documentAndFieldLevelSecurityEnabled()).thenReturn(true); ShieldIndexSearcherWrapper wrapper = new ShieldIndexSearcherWrapper(indexSettings, queryShardContext, mapperService, bitsetFilterCache, threadContext, licenseState) { diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperUnitTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperUnitTests.java index a5d7a61fe57..15a9de93d97 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperUnitTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperUnitTests.java @@ -52,7 +52,7 @@ import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.indices.IndicesModule; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.shield.authz.accesscontrol.DocumentSubsetReader.DocumentSubsetDirectoryReader; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.IndexSettingsModule; import org.junit.After; @@ -82,7 +82,7 @@ public class ShieldIndexSearcherWrapperUnitTests extends ESTestCase { private MapperService mapperService; private ShieldIndexSearcherWrapper shieldIndexSearcherWrapper; private ElasticsearchDirectoryReader esIn; - private ShieldLicenseState licenseState; + private SecurityLicenseState licenseState; private IndexSettings indexSettings; @Before @@ -96,7 +96,7 @@ public class ShieldIndexSearcherWrapperUnitTests extends ESTestCase { new IndicesModule().getMapperRegistry(), () -> null); ShardId shardId = new ShardId(index, 0); - licenseState = mock(ShieldLicenseState.class); + licenseState = mock(SecurityLicenseState.class); when(licenseState.documentAndFieldLevelSecurityEnabled()).thenReturn(true); threadContext = new ThreadContext(Settings.EMPTY); IndexShard indexShard = mock(IndexShard.class); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/rest/ShieldRestFilterTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/rest/ShieldRestFilterTests.java index b65026fa7b5..122ed9381d3 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/rest/ShieldRestFilterTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/rest/ShieldRestFilterTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.rest.RestFilterChain; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.shield.user.User; import org.elasticsearch.shield.authc.AuthenticationService; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.junit.Before; @@ -34,7 +34,7 @@ public class ShieldRestFilterTests extends ESTestCase { private RestChannel channel; private RestFilterChain chain; private ShieldRestFilter filter; - private ShieldLicenseState licenseState; + private SecurityLicenseState licenseState; @Before public void init() throws Exception { @@ -42,7 +42,7 @@ public class ShieldRestFilterTests extends ESTestCase { RestController restController = mock(RestController.class); channel = mock(RestChannel.class); chain = mock(RestFilterChain.class); - licenseState = mock(ShieldLicenseState.class); + licenseState = mock(SecurityLicenseState.class); when(licenseState.securityEnabled()).thenReturn(true); ThreadPool threadPool = mock(ThreadPool.class); when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY)); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java index 67f46b299c8..91e3c8adeff 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java @@ -10,7 +10,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.network.NetworkModule; @@ -19,7 +18,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.shield.action.ShieldActionMapper; import org.elasticsearch.shield.authc.AuthenticationService; import org.elasticsearch.shield.authz.AuthorizationService; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.threadpool.ThreadPool; @@ -311,7 +310,7 @@ public class TransportFilterTests extends ESIntegTestCase { AuthenticationService authcService, AuthorizationService authzService, ShieldActionMapper actionMapper, ClientTransportFilter clientTransportFilter) { super(settings, transport, threadPool, authcService, authzService, actionMapper, clientTransportFilter, - mock(ShieldLicenseState.class)); + mock(SecurityLicenseState.class)); when(licenseState.securityEnabled()).thenReturn(true); } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/filter/IPFilterTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/filter/IPFilterTests.java index b532c7de159..3ae9464b125 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/filter/IPFilterTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/filter/IPFilterTests.java @@ -15,7 +15,7 @@ import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.shield.audit.AuditTrail; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.junit.annotations.Network; import org.elasticsearch.transport.Transport; @@ -44,7 +44,7 @@ import static org.mockito.Mockito.when; */ public class IPFilterTests extends ESTestCase { private IPFilter ipFilter; - private ShieldLicenseState licenseState; + private SecurityLicenseState licenseState; private AuditTrail auditTrail; private Transport transport; private HttpServerTransport httpTransport; @@ -52,7 +52,7 @@ public class IPFilterTests extends ESTestCase { @Before public void init() { - licenseState = mock(ShieldLicenseState.class); + licenseState = mock(SecurityLicenseState.class); when(licenseState.securityEnabled()).thenReturn(true); auditTrail = mock(AuditTrail.class); clusterSettings = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList( diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/netty/IPFilterNettyUpstreamHandlerTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/netty/IPFilterNettyUpstreamHandlerTests.java index 8bdf4a4df20..79738bf4fcc 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/netty/IPFilterNettyUpstreamHandlerTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/netty/IPFilterNettyUpstreamHandlerTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.shield.audit.AuditTrail; -import org.elasticsearch.shield.license.ShieldLicenseState; +import org.elasticsearch.shield.SecurityLicenseState; import org.elasticsearch.shield.transport.filter.IPFilter; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.transport.Transport; @@ -68,7 +68,7 @@ public class IPFilterNettyUpstreamHandlerTests extends ESTestCase { IPFilter.TRANSPORT_FILTER_ALLOW_SETTING, IPFilter.TRANSPORT_FILTER_DENY_SETTING, TransportSettings.TRANSPORT_PROFILES_SETTING))); - ShieldLicenseState licenseState = mock(ShieldLicenseState.class); + SecurityLicenseState licenseState = mock(SecurityLicenseState.class); when(licenseState.securityEnabled()).thenReturn(true); IPFilter ipFilter = new IPFilter(settings, AuditTrail.NOOP, clusterSettings, licenseState); ipFilter.setBoundTransportAddress(transport.boundAddress(), transport.profileBoundAddresses()); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldSettingsSource.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldSettingsSource.java index 77158f37463..2f3fbaea06c 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldSettingsSource.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldSettingsSource.java @@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; -import org.elasticsearch.marvel.Marvel; +import org.elasticsearch.marvel.Monitoring; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.shield.authc.file.FileRealm; import org.elasticsearch.shield.authc.esnative.NativeRealm; @@ -123,7 +123,7 @@ public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZ //TODO: for now isolate shield tests from watcher & monitoring (randomize this later) .put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false) - .put(XPackPlugin.featureEnabledSetting(Marvel.NAME), false) + .put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) .put(AuditTrailModule.ENABLED_SETTING.getKey(), randomBoolean()) .put(LoggingAuditTrail.HOST_ADDRESS_SETTING.getKey(), randomBoolean()) .put(LoggingAuditTrail.HOST_NAME_SETTING.getKey(), randomBoolean()) diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/license/GraphModule.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackFeatureSet.java similarity index 50% rename from elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/license/GraphModule.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackFeatureSet.java index 0416ef9a7ce..af26f5ef8d2 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/license/GraphModule.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackFeatureSet.java @@ -3,18 +3,19 @@ * 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.graph.license; - -import org.elasticsearch.common.inject.AbstractModule; +package org.elasticsearch.xpack; /** * */ -public class GraphModule extends AbstractModule { +public interface XPackFeatureSet { - @Override - protected void configure() { - bind(GraphLicensee.class).asEagerSingleton(); - } + String name(); + + String description(); + + boolean available(); + + boolean enabled(); } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 266cf949009..98a9fc04d04 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -10,7 +10,9 @@ import org.elasticsearch.action.ActionModule; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.component.LifecycleComponent; +import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; @@ -19,11 +21,11 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.graph.Graph; import org.elasticsearch.index.IndexModule; import org.elasticsearch.license.plugin.Licensing; -import org.elasticsearch.marvel.Marvel; +import org.elasticsearch.marvel.Monitoring; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptModule; -import org.elasticsearch.shield.authc.AuthenticationModule; import org.elasticsearch.shield.Security; +import org.elasticsearch.shield.authc.AuthenticationModule; import org.elasticsearch.watcher.Watcher; import org.elasticsearch.xpack.action.TransportXPackInfoAction; import org.elasticsearch.xpack.action.XPackInfoAction; @@ -31,7 +33,7 @@ import org.elasticsearch.xpack.common.init.LazyInitializationModule; import org.elasticsearch.xpack.common.init.LazyInitializationService; import org.elasticsearch.xpack.extensions.XPackExtension; import org.elasticsearch.xpack.extensions.XPackExtensionsService; -import org.elasticsearch.xpack.rest.RestXPackInfoAction; +import org.elasticsearch.xpack.rest.action.RestXPackInfoAction; import java.nio.file.Path; import java.security.AccessController; @@ -83,7 +85,7 @@ public class XPackPlugin extends Plugin { protected Licensing licensing; protected Security security; - protected Marvel marvel; + protected Monitoring monitoring; protected Watcher watcher; protected Graph graph; @@ -92,7 +94,7 @@ public class XPackPlugin extends Plugin { transportClientMode = transportClientMode(settings); this.licensing = new Licensing(settings); this.security = new Security(settings); - this.marvel = new Marvel(settings); + this.monitoring = new Monitoring(settings); this.watcher = new Watcher(settings); this.graph = new Graph(settings); // Check if the node is a transport client. @@ -125,7 +127,7 @@ public class XPackPlugin extends Plugin { modules.addAll(licensing.nodeModules()); modules.addAll(security.nodeModules()); modules.addAll(watcher.nodeModules()); - modules.addAll(marvel.nodeModules()); + modules.addAll(monitoring.nodeModules()); modules.addAll(graph.nodeModules()); return modules; } @@ -140,7 +142,7 @@ public class XPackPlugin extends Plugin { services.addAll(licensing.nodeServices()); services.addAll(security.nodeServices()); services.addAll(watcher.nodeServices()); - services.addAll(marvel.nodeServices()); + services.addAll(monitoring.nodeServices()); services.addAll(graph.nodeServices()); return services; } @@ -164,7 +166,7 @@ public class XPackPlugin extends Plugin { module.registerSetting(Setting.simpleString("index.xpack.version", Setting.Property.IndexScope)); security.onModule(module); - marvel.onModule(module); + monitoring.onModule(module); watcher.onModule(module); graph.onModule(module); licensing.onModule(module); @@ -175,7 +177,7 @@ public class XPackPlugin extends Plugin { module.registerRestHandler(RestXPackInfoAction.class); } licensing.onModule(module); - marvel.onModule(module); + monitoring.onModule(module); security.onModule(module); watcher.onModule(module); graph.onModule(module); @@ -186,7 +188,7 @@ public class XPackPlugin extends Plugin { module.registerAction(XPackInfoAction.INSTANCE, TransportXPackInfoAction.class); } licensing.onModule(module); - marvel.onModule(module); + monitoring.onModule(module); security.onModule(module); watcher.onModule(module); graph.onModule(module); @@ -204,10 +206,16 @@ public class XPackPlugin extends Plugin { } public void onModule(LazyInitializationModule module) { - marvel.onModule(module); + monitoring.onModule(module); watcher.onModule(module); } + public static void bindFeatureSet(Binder binder, Class featureSet) { + binder.bind(featureSet).asEagerSingleton(); + Multibinder featureSetBinder = Multibinder.newSetBinder(binder, XPackFeatureSet.class); + featureSetBinder.addBinding().to(featureSet); + } + public static boolean transportClientMode(Settings settings) { return TransportClient.CLIENT_TYPE.equals(settings.get(Client.CLIENT_TYPE_SETTING_S.getKey())); } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/TransportXPackInfoAction.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/TransportXPackInfoAction.java index a80e49759c1..2473618c571 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/TransportXPackInfoAction.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/TransportXPackInfoAction.java @@ -16,29 +16,55 @@ import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.XPackBuild; +import org.elasticsearch.xpack.XPackFeatureSet; +import org.elasticsearch.xpack.action.XPackInfoResponse.FeatureSetsInfo.FeatureSet; import org.elasticsearch.xpack.action.XPackInfoResponse.LicenseInfo; +import java.util.Set; +import java.util.stream.Collectors; + /** */ public class TransportXPackInfoAction extends HandledTransportAction { private final LicensesService licensesService; + private final Set featureSets; @Inject public TransportXPackInfoAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, - LicensesService licensesService) { + LicensesService licensesService, Set featureSets) { super(settings, XPackInfoAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, XPackInfoRequest::new); this.licensesService = licensesService; + this.featureSets = featureSets; } @Override protected void doExecute(XPackInfoRequest request, ActionListener listener) { - XPackInfoResponse.BuildInfo buildInfo = new XPackInfoResponse.BuildInfo(XPackBuild.CURRENT); - License license = licensesService.getLicense(); - LicenseInfo licenseInfo = license != null ? new LicenseInfo(license) : null; - XPackInfoResponse response = new XPackInfoResponse(buildInfo, licenseInfo); - listener.onResponse(response); + + + XPackInfoResponse.BuildInfo buildInfo = null; + if (request.getCategories().contains(XPackInfoRequest.Category.BUILD)) { + buildInfo = new XPackInfoResponse.BuildInfo(XPackBuild.CURRENT); + } + + LicenseInfo licenseInfo = null; + if (request.getCategories().contains(XPackInfoRequest.Category.LICENSE)) { + License license = licensesService.getLicense(); + if (license != null) { + licenseInfo = new LicenseInfo(license); + } + } + + XPackInfoResponse.FeatureSetsInfo featureSetsInfo = null; + if (request.getCategories().contains(XPackInfoRequest.Category.FEATURES)) { + Set featureSets = this.featureSets.stream().map(fs -> + new FeatureSet(fs.name(), request.isVerbose() ? fs.description() : null, fs.available(), fs.enabled())) + .collect(Collectors.toSet()); + featureSetsInfo = new XPackInfoResponse.FeatureSetsInfo(featureSets); + } + + listener.onResponse(new XPackInfoResponse(buildInfo, licenseInfo, featureSetsInfo)); } } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequest.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequest.java index e3364c6a140..a01fc96b249 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequest.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequest.java @@ -7,16 +7,73 @@ package org.elasticsearch.xpack.action; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; +import java.util.EnumSet; +import java.util.Locale; /** * */ public class XPackInfoRequest extends ActionRequest { + public enum Category { + BUILD, LICENSE, FEATURES; + + public static EnumSet toSet(String... categories) { + EnumSet set = EnumSet.noneOf(Category.class); + for (String category : categories) { + set.add(Category.valueOf(category.toUpperCase(Locale.ROOT))); + } + return set; + } + } + + private boolean verbose; + private EnumSet categories = EnumSet.noneOf(Category.class); + public XPackInfoRequest() {} + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + public boolean isVerbose() { + return verbose; + } + + public void setCategories(EnumSet categories) { + this.categories = categories; + } + + public EnumSet getCategories() { + return categories; + } + @Override public ActionRequestValidationException validate() { return null; } + + @Override + public void readFrom(StreamInput in) throws IOException { + this.verbose = in.readBoolean(); + EnumSet categories = EnumSet.noneOf(Category.class); + int size = in.readVInt(); + for (int i = 0; i < size; i++) { + categories.add(Category.valueOf(in.readString())); + } + this.categories = categories; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeBoolean(verbose); + out.writeVInt(categories.size()); + for (Category category : categories) { + out.writeString(category.name()); + } + } } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequestBuilder.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequestBuilder.java index b5e3bc9c8e0..c440c44fa1b 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequestBuilder.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequestBuilder.java @@ -8,6 +8,8 @@ package org.elasticsearch.xpack.action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; +import java.util.EnumSet; + /** */ public class XPackInfoRequestBuilder extends ActionRequestBuilder { @@ -20,4 +22,15 @@ public class XPackInfoRequestBuilder extends ActionRequestBuilder categories) { + request.setCategories(categories); + return this; + } + } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoResponse.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoResponse.java index 478b41a20ea..6ee7351b3a3 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoResponse.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoResponse.java @@ -9,26 +9,37 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.core.License; import org.elasticsearch.xpack.XPackBuild; +import org.elasticsearch.xpack.XPackFeatureSet; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; /** */ public class XPackInfoResponse extends ActionResponse { - private BuildInfo buildInfo; + private @Nullable BuildInfo buildInfo; private @Nullable LicenseInfo licenseInfo; + private @Nullable FeatureSetsInfo featureSetsInfo; public XPackInfoResponse() {} - public XPackInfoResponse(BuildInfo buildInfo, @Nullable LicenseInfo licenseInfo) { + public XPackInfoResponse(@Nullable BuildInfo buildInfo, @Nullable LicenseInfo licenseInfo, @Nullable FeatureSetsInfo featureSetsInfo) { this.buildInfo = buildInfo; this.licenseInfo = licenseInfo; + this.featureSetsInfo = featureSetsInfo; } /** @@ -46,25 +57,29 @@ public class XPackInfoResponse extends ActionResponse { return licenseInfo; } + /** + * @return The current status of the feature sets in X-Pack. Feature sets describe the features available/enabled in X-Pack. + */ + public FeatureSetsInfo getFeatureSetsInfo() { + return featureSetsInfo; + } + @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - buildInfo.writeTo(out); - if (licenseInfo != null) { - out.writeBoolean(true); - licenseInfo.writeTo(out); - } else { - out.writeBoolean(false); - } + out.writeOptionalWriteable(buildInfo); + out.writeOptionalWriteable(licenseInfo); + out.writeOptionalWriteable(featureSetsInfo); } @Override public void readFrom(StreamInput in) throws IOException { - this.buildInfo = new BuildInfo(in); - this.licenseInfo = in.readBoolean() ? new LicenseInfo(in) : null; + this.buildInfo = in.readOptionalWriteable(BuildInfo::new); + this.licenseInfo = in.readOptionalWriteable(LicenseInfo::new); + this.featureSetsInfo = in.readOptionalWriteable(FeatureSetsInfo::new); } - public static class LicenseInfo implements ToXContent { + public static class LicenseInfo implements ToXContent, Writeable { private final String uid; private final String type; @@ -121,7 +136,7 @@ public class XPackInfoResponse extends ActionResponse { } } - public static class BuildInfo implements ToXContent { + public static class BuildInfo implements ToXContent, Writeable { private final String hash; private final String timestamp; @@ -160,4 +175,106 @@ public class XPackInfoResponse extends ActionResponse { output.writeString(timestamp); } } + + public static class FeatureSetsInfo implements ToXContent, Writeable { + + private final Map featureSets; + + public FeatureSetsInfo(StreamInput in) throws IOException { + int size = in.readVInt(); + Map featureSets = new HashMap<>(size); + for (int i = 0; i < size; i++) { + FeatureSet featureSet = new FeatureSet(in); + featureSets.put(featureSet.name, featureSet); + } + this.featureSets = Collections.unmodifiableMap(featureSets); + } + + public FeatureSetsInfo(Set featureSets) { + Map map = new HashMap<>(featureSets.size()); + for (FeatureSet featureSet : featureSets) { + map.put(featureSet.name, featureSet); + } + this.featureSets = Collections.unmodifiableMap(map); + } + + public Map getFeatureSets() { + return featureSets; + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + List names = new ArrayList<>(this.featureSets.keySet()).stream().sorted().collect(Collectors.toList()); + for (String name : names) { + builder.field(name, featureSets.get(name), params); + } + return builder.endObject(); + } + + public void writeTo(StreamOutput out) throws IOException { + out.writeVInt(featureSets.size()); + for (FeatureSet featureSet : featureSets.values()) { + featureSet.writeTo(out); + } + } + + public static class FeatureSet implements XPackFeatureSet, ToXContent, Writeable { + + private final String name; + private final @Nullable String description; + private final boolean available; + private final boolean enabled; + + public FeatureSet(StreamInput in) throws IOException { + this(in.readString(), in.readOptionalString(), in.readBoolean(), in.readBoolean()); + } + + public FeatureSet(String name, @Nullable String description, boolean available, boolean enabled) { + this.name = name; + this.description = description; + this.available = available; + this.enabled = enabled; + } + + @Override + public String name() { + return name; + } + + @Override + @Nullable + public String description() { + return description; + } + + @Override + public boolean available() { + return available; + } + + @Override + public boolean enabled() { + return enabled; + } + + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + if (description != null) { + builder.field("description", description); + } + builder.field("available", available); + builder.field("enabled", enabled); + return builder.endObject(); + } + + public void writeTo(StreamOutput out) throws IOException { + out.writeString(name); + out.writeOptionalString(description); + out.writeBoolean(available); + out.writeBoolean(enabled); + } + } + + } } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/rest/RestXPackInfoAction.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackInfoAction.java similarity index 61% rename from elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/rest/RestXPackInfoAction.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackInfoAction.java index 6d7a4a4809a..5b1119c8ac4 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/rest/RestXPackInfoAction.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackInfoAction.java @@ -3,9 +3,10 @@ * 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.rest; +package org.elasticsearch.xpack.rest.action; import org.elasticsearch.client.Client; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -16,7 +17,11 @@ import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.support.RestBuilderListener; import org.elasticsearch.xpack.XPackClient; +import org.elasticsearch.xpack.action.XPackInfoRequest; import org.elasticsearch.xpack.action.XPackInfoResponse; +import org.elasticsearch.xpack.rest.XPackRestHandler; + +import java.util.EnumSet; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; @@ -33,7 +38,13 @@ public class RestXPackInfoAction extends XPackRestHandler { @Override protected void handleRequest(RestRequest request, RestChannel restChannel, XPackClient client) throws Exception { - client.prepareInfo().execute(new RestBuilderListener(restChannel) { + + // we piggyback verbosity on "human" output + boolean verbose = request.paramAsBoolean("human", false); + + EnumSet categories = XPackInfoRequest.Category + .toSet(request.paramAsStringArray("categories", Strings.EMPTY_ARRAY)); + client.prepareInfo().setVerbose(verbose).setCategories(categories).execute(new RestBuilderListener(restChannel) { @Override public RestResponse buildResponse(XPackInfoResponse infoResponse, XContentBuilder builder) throws Exception { @@ -44,13 +55,28 @@ public class RestXPackInfoAction extends XPackRestHandler { } builder.startObject(); - builder.field("build", infoResponse.getBuildInfo(), request); + + if (infoResponse.getBuildInfo() != null) { + builder.field("build", infoResponse.getBuildInfo(), request); + } + if (infoResponse.getLicenseInfo() != null) { builder.field("license", infoResponse.getLicenseInfo(), request); - } else { + } else if (categories.contains(XPackInfoRequest.Category.LICENSE)) { + // if the user requested the license info, and there is no license, we should send + // back an explicit null value (indicating there is no license). This is different + // than not adding the license info at all builder.nullField("license"); } - builder.field("tagline", "You know, for X"); + + if (infoResponse.getFeatureSetsInfo() != null) { + builder.field("features", infoResponse.getFeatureSetsInfo(), request); + } + + if (verbose) { + builder.field("tagline", "You know, for X"); + } + builder.endObject(); return new BytesRestResponse(OK, builder); } diff --git a/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/action/TransportXPackInfoActionTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/action/TransportXPackInfoActionTests.java index ac4a1bfe4cd..39582f72159 100644 --- a/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/action/TransportXPackInfoActionTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/action/TransportXPackInfoActionTests.java @@ -15,13 +15,21 @@ import org.elasticsearch.shield.user.AnonymousUser; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.XPackFeatureSet; +import org.elasticsearch.xpack.action.XPackInfoResponse.FeatureSetsInfo.FeatureSet; import org.junit.After; import org.junit.Before; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.is; import static org.hamcrest.core.IsNull.notNullValue; import static org.hamcrest.core.IsNull.nullValue; @@ -50,8 +58,20 @@ public class TransportXPackInfoActionTests extends ESTestCase { LicensesService licensesService = mock(LicensesService.class); + final Set featureSets = new HashSet<>(); + int featureSetCount = randomIntBetween(0, 5); + for (int i = 0; i < featureSetCount; i++) { + XPackFeatureSet fs = mock(XPackFeatureSet.class); + when(fs.name()).thenReturn(randomAsciiOfLength(5)); + when(fs.description()).thenReturn(randomAsciiOfLength(10)); + when(fs.available()).thenReturn(randomBoolean()); + when(fs.enabled()).thenReturn(randomBoolean()); + featureSets.add(fs); + } + TransportXPackInfoAction action = new TransportXPackInfoAction(Settings.EMPTY, mock(ThreadPool.class), - mock(TransportService.class), mock(ActionFilters.class), mock(IndexNameExpressionResolver.class), licensesService); + mock(TransportService.class), mock(ActionFilters.class), mock(IndexNameExpressionResolver.class), + licensesService, featureSets); License license = mock(License.class); long expiryDate = randomLong(); @@ -65,6 +85,14 @@ public class TransportXPackInfoActionTests extends ESTestCase { when(licensesService.getLicense()).thenReturn(license); XPackInfoRequest request = new XPackInfoRequest(); + request.setVerbose(randomBoolean()); + + EnumSet categories = EnumSet.noneOf(XPackInfoRequest.Category.class); + int maxCategoryCount = randomIntBetween(0, XPackInfoRequest.Category.values().length); + for (int i = 0; i < maxCategoryCount; i++) { + categories.add(randomFrom(XPackInfoRequest.Category.values())); + } + request.setCategories(categories); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference response = new AtomicReference<>(); @@ -90,12 +118,41 @@ public class TransportXPackInfoActionTests extends ESTestCase { assertThat(error.get(), nullValue()); assertThat(response.get(), notNullValue()); - assertThat(response.get().getBuildInfo(), notNullValue()); - assertThat(response.get().getLicenseInfo(), notNullValue()); - assertThat(response.get().getLicenseInfo().getExpiryDate(), is(expiryDate)); - assertThat(response.get().getLicenseInfo().getStatus(), is(status)); - assertThat(response.get().getLicenseInfo().getType(), is(type)); - assertThat(response.get().getLicenseInfo().getUid(), is(uid)); + if (request.getCategories().contains(XPackInfoRequest.Category.BUILD)) { + assertThat(response.get().getBuildInfo(), notNullValue()); + } else { + assertThat(response.get().getBuildInfo(), nullValue()); + } + + if (request.getCategories().contains(XPackInfoRequest.Category.LICENSE)) { + assertThat(response.get().getLicenseInfo(), notNullValue()); + assertThat(response.get().getLicenseInfo().getExpiryDate(), is(expiryDate)); + assertThat(response.get().getLicenseInfo().getStatus(), is(status)); + assertThat(response.get().getLicenseInfo().getType(), is(type)); + assertThat(response.get().getLicenseInfo().getUid(), is(uid)); + } else { + assertThat(response.get().getLicenseInfo(), nullValue()); + } + + if (request.getCategories().contains(XPackInfoRequest.Category.FEATURES)) { + assertThat(response.get().getFeatureSetsInfo(), notNullValue()); + Map features = response.get().getFeatureSetsInfo().getFeatureSets(); + assertThat(features.size(), is(featureSets.size())); + for (XPackFeatureSet fs : featureSets) { + assertThat(features, hasKey(fs.name())); + assertThat(features.get(fs.name()).name(), equalTo(fs.name())); + if (!request.isVerbose()) { + assertThat(features.get(fs.name()).description(), is(nullValue())); + } else { + assertThat(features.get(fs.name()).description(), is(fs.description())); + } + assertThat(features.get(fs.name()).available(), equalTo(fs.available())); + assertThat(features.get(fs.name()).enabled(), equalTo(fs.enabled())); + } + } else { + assertThat(response.get().getFeatureSetsInfo(), nullValue()); + } + } } diff --git a/elasticsearch/x-pack/src/test/resources/rest-api-spec/api/xpack.info.json b/elasticsearch/x-pack/src/test/resources/rest-api-spec/api/xpack.info.json index 36dea81cded..206cbf40a0a 100644 --- a/elasticsearch/x-pack/src/test/resources/rest-api-spec/api/xpack.info.json +++ b/elasticsearch/x-pack/src/test/resources/rest-api-spec/api/xpack.info.json @@ -6,7 +6,16 @@ "path": "/_xpack", "paths": [ "/_xpack" ], "parts": {}, - "params": {} + "params": { + "human" : { + "type" : "boolean", + "description" : "Presents additional info for humans (feature descriptions and X-Pack tagline)" + }, + "categories": { + "type": "list", + "description" : "Comma-separated list of info categories. Can be any of: build, license, features" + } + } }, "body": null } diff --git a/elasticsearch/x-pack/src/test/resources/rest-api-spec/test/xpack/15_basic.yaml b/elasticsearch/x-pack/src/test/resources/rest-api-spec/test/xpack/15_basic.yaml index 8e62c2ee28c..6d5e3413c1a 100644 --- a/elasticsearch/x-pack/src/test/resources/rest-api-spec/test/xpack/15_basic.yaml +++ b/elasticsearch/x-pack/src/test/resources/rest-api-spec/test/xpack/15_basic.yaml @@ -1,9 +1,10 @@ # Integration tests xpack info API # "X-Pack Info": + - do: cluster.health: - wait_for_status: yellow + wait_for_status: yellow - do: license.delete: {} @@ -11,12 +12,23 @@ # we don't have a license now - do: - xpack.info: {} - - is_true: build.hash - - is_true: build.timestamp + xpack.info: + categories: "license,features" - is_false: license + - is_true: features + - is_true: features.watcher + - is_true: features.watcher.enabled +# - is_false: features.watcher.available TODO fix once licensing is fixed + - is_true: features.security + - is_true: features.security.enabled +# - is_false: features.security.available TODO fix once licensing is fixed + - is_true: features.graph + - is_true: features.graph.enabled +# - is_false: features.graph.available TODO fix once licensing is fixed + - is_true: features.monitoring + - is_true: features.monitoring.enabled +# - is_false: features.monitoring.available TODO fix once licensing is fixed - # lets put an active license - do: license.post: body: > @@ -37,13 +49,31 @@ - match: { license_status: "valid" } - do: - license.get: {} + license.get: {} - match: { license.uid: "893361dc-9749-4997-93cb-802e3dofh7aa" } - match: { license.type: "internal" } - match: { license.status: "active" } - do: xpack.info: {} + - is_false: tagline + - is_false: build + - is_false: features + - is_false: license + + - do: + xpack.info: + categories: "build" + - is_true: build + - is_true: build.hash + - is_true: build.timestamp + - is_false: tagline + - is_false: features + - is_false: license + + - do: + xpack.info: + categories: "build,license" - is_true: build.hash - is_true: build.timestamp - is_true: license @@ -52,3 +82,66 @@ - match: { license.mode: "platinum" } - match: { license.status: "active" } - match: { license.expiry_date_in_millis: 1914278399999 } + - is_false: tagline + - is_false: features + + - do: + xpack.info: + categories: "build,license,features" + - is_true: build.hash + - is_true: build.timestamp + - is_true: license + - match: { license.uid: "893361dc-9749-4997-93cb-802e3dofh7aa" } + - match: { license.type: "internal" } + - match: { license.mode: "platinum" } + - match: { license.status: "active" } + - match: { license.expiry_date_in_millis: 1914278399999 } + - is_true: features + - is_true: features.watcher + - is_true: features.watcher.enabled + - is_true: features.watcher.available + - is_false: features.watcher.description + - is_true: features.security + - is_true: features.security.enabled + - is_true: features.security.available + - is_false: features.security.description + - is_true: features.graph + - is_true: features.graph.enabled + - is_true: features.graph.available + - is_false: features.graph.description + - is_true: features.monitoring + - is_true: features.monitoring.enabled + - is_true: features.monitoring.available + - is_false: features.monitoring.description + - is_false: tagline + + - do: + xpack.info: + categories: "build,license,features" + human: "true" + - is_true: build.hash + - is_true: build.timestamp + - is_true: license + - match: { license.uid: "893361dc-9749-4997-93cb-802e3dofh7aa" } + - match: { license.type: "internal" } + - match: { license.mode: "platinum" } + - match: { license.status: "active" } + - match: { license.expiry_date_in_millis: 1914278399999 } + - is_true: features + - is_true: features.watcher + - is_true: features.watcher.enabled + - is_true: features.watcher.available + - is_true: features.watcher.description + - is_true: features.security + - is_true: features.security.enabled + - is_true: features.security.available + - is_true: features.security.description + - is_true: features.graph + - is_true: features.graph.enabled + - is_true: features.graph.available + - is_true: features.graph.description + - is_true: features.monitoring + - is_true: features.monitoring.enabled + - is_true: features.monitoring.available + - is_true: features.monitoring.description + - is_true: tagline diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java index 2a7c4abae67..0e08369d642 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java @@ -38,8 +38,6 @@ import org.elasticsearch.watcher.history.HistoryModule; import org.elasticsearch.watcher.history.HistoryStore; import org.elasticsearch.watcher.input.InputModule; import org.elasticsearch.watcher.input.chain.ChainInputFactory; -import org.elasticsearch.watcher.license.LicenseModule; -import org.elasticsearch.watcher.license.WatcherLicensee; import org.elasticsearch.watcher.rest.action.RestAckWatchAction; import org.elasticsearch.watcher.rest.action.RestActivateWatchAction; import org.elasticsearch.watcher.rest.action.RestDeleteWatchAction; @@ -119,26 +117,25 @@ public class Watcher { } public Collection nodeModules() { - if (enabled == false|| transportClient) { - return Collections.emptyList(); + List modules = new ArrayList<>(); + modules.add(new WatcherModule(enabled, transportClient)); + if (enabled && transportClient == false) { + modules.add(new WatchModule()); + modules.add(new TextTemplateModule()); + modules.add(new HttpClientModule()); + modules.add(new ClockModule()); + modules.add(new WatcherClientModule()); + modules.add(new TransformModule()); + modules.add(new TriggerModule(settings)); + modules.add(new ScheduleModule()); + modules.add(new ConditionModule()); + modules.add(new InputModule()); + modules.add(new WatcherActionModule()); + modules.add(new HistoryModule()); + modules.add(new ExecutionModule()); + modules.add(new SecretModule(settings)); } - return Arrays.asList( - new WatcherModule(settings), - new LicenseModule(), - new WatchModule(), - new TextTemplateModule(), - new HttpClientModule(), - new ClockModule(), - new WatcherClientModule(), - new TransformModule(), - new TriggerModule(settings), - new ScheduleModule(), - new ConditionModule(), - new InputModule(), - new WatcherActionModule(), - new HistoryModule(), - new ExecutionModule(), - new SecretModule(settings)); + return modules; } public Collection> nodeServices() { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherFeatureSet.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherFeatureSet.java new file mode 100644 index 00000000000..ba8814182f0 --- /dev/null +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherFeatureSet.java @@ -0,0 +1,46 @@ +/* + * 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.watcher; + +import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.xpack.XPackFeatureSet; + +/** + * + */ +public class WatcherFeatureSet implements XPackFeatureSet { + + private final boolean enabled; + private final WatcherLicensee licensee; + + @Inject + public WatcherFeatureSet(Settings settings, @Nullable WatcherLicensee licensee) { + this.enabled = Watcher.enabled(settings); + this.licensee = licensee; + } + + @Override + public String name() { + return Watcher.NAME; + } + + @Override + public String description() { + return "Alerting, Notification and Automation for the Elastic Stack"; + } + + @Override + public boolean available() { + return licensee != null && licensee.available(); + } + + @Override + public boolean enabled() { + return enabled; + } +} diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/license/WatcherLicensee.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherLicensee.java similarity index 87% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/license/WatcherLicensee.java rename to elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherLicensee.java index e3cb1f885d6..d4796d30b36 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/license/WatcherLicensee.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherLicensee.java @@ -3,7 +3,7 @@ * 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.watcher.license; +package org.elasticsearch.watcher; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; @@ -13,7 +13,6 @@ import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent; import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.LicenseeRegistry; -import org.elasticsearch.watcher.Watcher; public class WatcherLicensee extends AbstractLicenseeComponent { @@ -51,22 +50,10 @@ public class WatcherLicensee extends AbstractLicenseeComponent return Strings.EMPTY_ARRAY; } - public boolean isExecutingActionsAllowed() { - return isPutWatchAllowed(); - } - - public boolean isGetWatchAllowed() { - return isPutWatchAllowed(); - } - - public boolean isPutWatchAllowed() { - return isWatcherTransportActionAllowed(); - } - /** - * Determine if Watcher should be enabled. + * Determine if Watcher is available based on the current license. *

    - * Watcher is only disabled when the license has expired or if the mode is not: + * Watcher is available if the license is active (hasn't expired) and of one of the following types: *

      *
    • {@link OperationMode#PLATINUM}
    • *
    • {@link OperationMode#GOLD}
    • @@ -75,11 +62,30 @@ public class WatcherLicensee extends AbstractLicenseeComponent * * @return {@code true} as long as the license is valid. Otherwise {@code false}. */ - public boolean isWatcherTransportActionAllowed() { + public boolean available() { // status is volatile, so a local variable is used for a consistent view Status localStatus = status; return localStatus.getLicenseState() != LicenseState.DISABLED && (localStatus.getMode() == OperationMode.TRIAL || localStatus.getMode() == OperationMode.GOLD || localStatus.getMode() == OperationMode.PLATINUM); } + + public boolean isExecutingActionsAllowed() { + return isWatcherTransportActionAllowed(); + } + + public boolean isGetWatchAllowed() { + return isWatcherTransportActionAllowed(); + } + + public boolean isPutWatchAllowed() { + return isWatcherTransportActionAllowed(); + } + + + public boolean isWatcherTransportActionAllowed() { + return available(); + } + + } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java index 46cbad6864f..61aa80b6cac 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java @@ -9,11 +9,13 @@ package org.elasticsearch.watcher; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.multibindings.Multibinder; +import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry; import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.TemplateConfig; import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation; +import org.elasticsearch.xpack.XPackPlugin; import java.io.IOException; import java.io.InputStream; @@ -42,14 +44,24 @@ public class WatcherModule extends AbstractModule { new TemplateConfig(WATCHES_TEMPLATE_NAME, WATCHES_TEMPLATE_SETTING) }; - protected final Settings settings; + private final boolean enabled; + private final boolean transportClientMode; - public WatcherModule(Settings settings) { - this.settings = settings; + public WatcherModule(boolean enabled, boolean transportClientMode) { + this.enabled = enabled; + this.transportClientMode = transportClientMode; } @Override protected void configure() { + XPackPlugin.bindFeatureSet(binder(), WatcherFeatureSet.class); + + if (enabled == false || transportClientMode) { + bind(WatcherLicensee.class).toProvider(Providers.of(null)); + return; + } + + bind(WatcherLicensee.class).asEagerSingleton(); bind(WatcherLifeCycleService.class).asEagerSingleton(); bind(WatcherSettingsValidation.class).asEagerSingleton(); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionRegistry.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionRegistry.java index 942305515d5..9065e7a7b1a 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionRegistry.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionRegistry.java @@ -8,7 +8,7 @@ package org.elasticsearch.watcher.actions; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.support.clock.Clock; import org.elasticsearch.watcher.support.validation.Validation; import org.elasticsearch.watcher.transform.TransformRegistry; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionWrapper.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionWrapper.java index 957477bd4db..6d9b3779223 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionWrapper.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionWrapper.java @@ -17,7 +17,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.actions.throttler.ActionThrottler; import org.elasticsearch.watcher.actions.throttler.Throttler; import org.elasticsearch.watcher.execution.WatchExecutionContext; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.support.WatcherDateTimeUtils; import org.elasticsearch.watcher.support.clock.Clock; import org.elasticsearch.watcher.transform.ExecutableTransform; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/throttler/ActionThrottler.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/throttler/ActionThrottler.java index 32243fa7dca..22130006863 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/throttler/ActionThrottler.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/throttler/ActionThrottler.java @@ -8,7 +8,7 @@ package org.elasticsearch.watcher.actions.throttler; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.watcher.execution.WatchExecutionContext; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.support.clock.Clock; /** diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/license/LicenseModule.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/license/LicenseModule.java deleted file mode 100644 index 8f72298707d..00000000000 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/license/LicenseModule.java +++ /dev/null @@ -1,20 +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.watcher.license; - -import org.elasticsearch.common.inject.AbstractModule; - -/** - * - */ -public class LicenseModule extends AbstractModule { - - @Override - protected void configure() { - bind(WatcherLicensee.class).asEagerSingleton(); - } - -} diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java index e7a9fc8dd3e..2f2b0c578b9 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java @@ -17,7 +17,7 @@ import org.elasticsearch.license.plugin.core.LicenseUtils; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import java.util.function.Supplier; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java index dd81b2ca563..6db822e4754 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java @@ -18,7 +18,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.watcher.WatcherService; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.transport.actions.WatcherTransportAction; import org.elasticsearch.watcher.watch.WatchStatus; import org.elasticsearch.watcher.watch.WatchStore; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/activate/TransportActivateWatchAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/activate/TransportActivateWatchAction.java index 854053b9c77..3fdc7854bf7 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/activate/TransportActivateWatchAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/activate/TransportActivateWatchAction.java @@ -18,7 +18,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.watcher.WatcherService; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.transport.actions.WatcherTransportAction; import org.elasticsearch.watcher.watch.WatchStatus; import org.elasticsearch.watcher.watch.WatchStore; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/delete/TransportDeleteWatchAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/delete/TransportDeleteWatchAction.java index 40084fbb79f..be98e3e08db 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/delete/TransportDeleteWatchAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/delete/TransportDeleteWatchAction.java @@ -19,7 +19,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.watcher.WatcherService; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.transport.actions.WatcherTransportAction; import org.elasticsearch.watcher.watch.WatchStore; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/execute/TransportExecuteWatchAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/execute/TransportExecuteWatchAction.java index f69bbb71421..238a7d88d69 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/execute/TransportExecuteWatchAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/execute/TransportExecuteWatchAction.java @@ -26,7 +26,7 @@ import org.elasticsearch.watcher.execution.ExecutionService; import org.elasticsearch.watcher.execution.ManualExecutionContext; import org.elasticsearch.watcher.history.WatchRecord; import org.elasticsearch.watcher.input.simple.SimpleInput; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.support.clock.Clock; import org.elasticsearch.watcher.support.xcontent.WatcherParams; import org.elasticsearch.watcher.transport.actions.WatcherTransportAction; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/get/TransportGetWatchAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/get/TransportGetWatchAction.java index 83686c5d1b8..3a85d1c8072 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/get/TransportGetWatchAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/get/TransportGetWatchAction.java @@ -22,7 +22,7 @@ import org.elasticsearch.license.plugin.core.LicenseUtils; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.watcher.WatcherService; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.support.xcontent.WatcherParams; import org.elasticsearch.watcher.transport.actions.WatcherTransportAction; import org.elasticsearch.watcher.watch.Watch; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/put/TransportPutWatchAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/put/TransportPutWatchAction.java index e5ffe4274ee..4ac9597b32c 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/put/TransportPutWatchAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/put/TransportPutWatchAction.java @@ -20,7 +20,7 @@ import org.elasticsearch.license.plugin.core.LicenseUtils; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.watcher.WatcherService; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.transport.actions.WatcherTransportAction; import org.elasticsearch.watcher.watch.WatchStore; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/service/TransportWatcherServiceAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/service/TransportWatcherServiceAction.java index 166e0e87e80..de92311e0d2 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/service/TransportWatcherServiceAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/service/TransportWatcherServiceAction.java @@ -18,7 +18,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.watcher.WatcherLifeCycleService; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.transport.actions.WatcherTransportAction; /** diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/stats/TransportWatcherStatsAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/stats/TransportWatcherStatsAction.java index fc6ac8b9ad6..5fb77a0f59d 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/stats/TransportWatcherStatsAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/stats/TransportWatcherStatsAction.java @@ -21,7 +21,7 @@ import org.elasticsearch.watcher.WatcherBuild; import org.elasticsearch.watcher.WatcherLifeCycleService; import org.elasticsearch.watcher.WatcherService; import org.elasticsearch.watcher.execution.ExecutionService; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.transport.actions.WatcherTransportAction; /** diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java index 98d06faa40b..468afd30644 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java @@ -13,7 +13,7 @@ import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.http.HttpServerTransport; -import org.elasticsearch.marvel.Marvel; +import org.elasticsearch.marvel.Monitoring; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.shield.Security; import org.elasticsearch.test.ESIntegTestCase; @@ -45,7 +45,7 @@ public class WatcherPluginDisableTests extends ESIntegTestCase { // disable shield because of query cache check and authentication/authorization .put(XPackPlugin.featureEnabledSetting(Security.NAME), false) - .put(XPackPlugin.featureEnabledSetting(Marvel.NAME), false) + .put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) .put(NetworkModule.HTTP_ENABLED.getKey(), true) .build(); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/throttler/WatchThrottlerTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/throttler/WatchThrottlerTests.java index 596630e2f28..d958bab3a92 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/throttler/WatchThrottlerTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/throttler/WatchThrottlerTests.java @@ -7,7 +7,7 @@ package org.elasticsearch.watcher.actions.throttler; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.execution.WatchExecutionContext; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java index def1a44e72b..0be401bbbef 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.watcher.license; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase; +import org.elasticsearch.watcher.WatcherLicensee; import static org.elasticsearch.license.core.License.OperationMode.BASIC; import static org.elasticsearch.license.core.License.OperationMode.GOLD; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java index b4c7379d5ce..9dd18ae6566 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -22,7 +22,7 @@ import org.elasticsearch.common.util.Callback; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.marvel.Marvel; +import org.elasticsearch.marvel.Monitoring; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockMustacheScriptEngine; import org.elasticsearch.search.SearchHit; @@ -51,7 +51,7 @@ import org.elasticsearch.watcher.client.WatcherClient; import org.elasticsearch.watcher.execution.ExecutionService; import org.elasticsearch.watcher.execution.ExecutionState; import org.elasticsearch.watcher.history.HistoryStore; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry; import org.elasticsearch.watcher.support.clock.ClockMock; import org.elasticsearch.watcher.support.http.HttpClient; @@ -130,7 +130,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) //TODO: for now lets isolate watcher tests from monitoring (randomize this later) - .put(XPackPlugin.featureEnabledSetting(Marvel.NAME), false) + .put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) // we do this by default in core, but for watcher this isn't needed and only adds noise. .put("index.store.mock.check_index_on_close", false) .put("xpack.watcher.execution.scroll.size", randomIntBetween(1, 100)) @@ -394,32 +394,29 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase final boolean assertConditionMet) throws Exception { final AtomicReference lastResponse = new AtomicReference<>(); try { - assertBusy(new Runnable() { - @Override - public void run() { - ClusterState state = client().admin().cluster().prepareState().get().getState(); - String[] watchHistoryIndices = indexNameExpressionResolver().concreteIndexNames(state, - IndicesOptions.lenientExpandOpen(), HistoryStore.INDEX_PREFIX + "*"); - assertThat(watchHistoryIndices, not(emptyArray())); - for (String index : watchHistoryIndices) { - IndexRoutingTable routingTable = state.getRoutingTable().index(index); - assertThat(routingTable, notNullValue()); - assertThat(routingTable.allPrimaryShardsActive(), is(true)); - } + assertBusy(() -> { + ClusterState state = client().admin().cluster().prepareState().get().getState(); + String[] watchHistoryIndices = indexNameExpressionResolver().concreteIndexNames(state, + IndicesOptions.lenientExpandOpen(), HistoryStore.INDEX_PREFIX + "*"); + assertThat(watchHistoryIndices, not(emptyArray())); + for (String index : watchHistoryIndices) { + IndexRoutingTable routingTable = state.getRoutingTable().index(index); + assertThat(routingTable, notNullValue()); + assertThat(routingTable.allPrimaryShardsActive(), is(true)); + } - refresh(); - SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") - .setIndicesOptions(IndicesOptions.lenientExpandOpen()) - .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", - ExecutionState.EXECUTED.id()))) - .get(); - lastResponse.set(searchResponse); - assertThat("could not find executed watch record", searchResponse.getHits().getTotalHits(), - greaterThanOrEqualTo(minimumExpectedWatchActionsWithActionPerformed)); - if (assertConditionMet) { - assertThat((Integer) XContentMapValues.extractValue("result.input.payload.hits.total", - searchResponse.getHits().getAt(0).sourceAsMap()), greaterThanOrEqualTo(1)); - } + refresh(); + SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") + .setIndicesOptions(IndicesOptions.lenientExpandOpen()) + .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", + ExecutionState.EXECUTED.id()))) + .get(); + lastResponse.set(searchResponse); + assertThat("could not find executed watch record", searchResponse.getHits().getTotalHits(), + greaterThanOrEqualTo(minimumExpectedWatchActionsWithActionPerformed)); + if (assertConditionMet) { + assertThat((Integer) XContentMapValues.extractValue("result.input.payload.hits.total", + searchResponse.getHits().getAt(0).sourceAsMap()), greaterThanOrEqualTo(1)); } }); } catch (AssertionError error) { @@ -462,29 +459,26 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase final long expectedWatchActionsWithNoActionNeeded) throws Exception { final AtomicReference lastResponse = new AtomicReference<>(); try { - assertBusy(new Runnable() { - @Override - public void run() { - // The watch_history index gets created in the background when the first watch is triggered - // so we to check first is this index is created and shards are started - ClusterState state = client().admin().cluster().prepareState().get().getState(); - String[] watchHistoryIndices = indexNameExpressionResolver().concreteIndexNames(state, - IndicesOptions.lenientExpandOpen(), HistoryStore.INDEX_PREFIX + "*"); - assertThat(watchHistoryIndices, not(emptyArray())); - for (String index : watchHistoryIndices) { - IndexRoutingTable routingTable = state.getRoutingTable().index(index); - assertThat(routingTable, notNullValue()); - assertThat(routingTable.allPrimaryShardsActive(), is(true)); - } - refresh(); - SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") - .setIndicesOptions(IndicesOptions.lenientExpandOpen()) - .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", - ExecutionState.EXECUTION_NOT_NEEDED.id()))) - .get(); - lastResponse.set(searchResponse); - assertThat(searchResponse.getHits().getTotalHits(), greaterThanOrEqualTo(expectedWatchActionsWithNoActionNeeded)); + assertBusy(() -> { + // The watch_history index gets created in the background when the first watch is triggered + // so we to check first is this index is created and shards are started + ClusterState state = client().admin().cluster().prepareState().get().getState(); + String[] watchHistoryIndices = indexNameExpressionResolver().concreteIndexNames(state, + IndicesOptions.lenientExpandOpen(), HistoryStore.INDEX_PREFIX + "*"); + assertThat(watchHistoryIndices, not(emptyArray())); + for (String index : watchHistoryIndices) { + IndexRoutingTable routingTable = state.getRoutingTable().index(index); + assertThat(routingTable, notNullValue()); + assertThat(routingTable.allPrimaryShardsActive(), is(true)); } + refresh(); + SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") + .setIndicesOptions(IndicesOptions.lenientExpandOpen()) + .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", + ExecutionState.EXECUTION_NOT_NEEDED.id()))) + .get(); + lastResponse.set(searchResponse); + assertThat(searchResponse.getHits().getTotalHits(), greaterThanOrEqualTo(expectedWatchActionsWithNoActionNeeded)); }); } catch (AssertionError error) { SearchResponse searchResponse = lastResponse.get(); @@ -499,27 +493,24 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase protected void assertWatchWithMinimumActionsCount(final String watchName, final ExecutionState recordState, final long recordCount) throws Exception { - assertBusy(new Runnable() { - @Override - public void run() { - ClusterState state = client().admin().cluster().prepareState().get().getState(); - String[] watchHistoryIndices = indexNameExpressionResolver().concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), - HistoryStore.INDEX_PREFIX + "*"); - assertThat(watchHistoryIndices, not(emptyArray())); - for (String index : watchHistoryIndices) { - IndexRoutingTable routingTable = state.getRoutingTable().index(index); - assertThat(routingTable, notNullValue()); - assertThat(routingTable.allPrimaryShardsActive(), is(true)); - } - - refresh(); - SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") - .setIndicesOptions(IndicesOptions.lenientExpandOpen()) - .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", recordState.id()))) - .get(); - assertThat("could not find executed watch record", searchResponse.getHits().getTotalHits(), - greaterThanOrEqualTo(recordCount)); + assertBusy(() -> { + ClusterState state = client().admin().cluster().prepareState().get().getState(); + String[] watchHistoryIndices = indexNameExpressionResolver().concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), + HistoryStore.INDEX_PREFIX + "*"); + assertThat(watchHistoryIndices, not(emptyArray())); + for (String index : watchHistoryIndices) { + IndexRoutingTable routingTable = state.getRoutingTable().index(index); + assertThat(routingTable, notNullValue()); + assertThat(routingTable.allPrimaryShardsActive(), is(true)); } + + refresh(); + SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") + .setIndicesOptions(IndicesOptions.lenientExpandOpen()) + .setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", recordState.id()))) + .get(); + assertThat("could not find executed watch record", searchResponse.getHits().getTotalHits(), + greaterThanOrEqualTo(recordCount)); }); } @@ -528,14 +519,11 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase } protected void ensureWatcherStarted(final boolean useClient) throws Exception { - assertBusy(new Runnable() { - @Override - public void run() { - if (useClient) { - assertThat(watcherClient().prepareWatcherStats().get().getWatcherState(), is(WatcherState.STARTED)); - } else { - assertThat(getInstanceFromMaster(WatcherService.class).state(), is(WatcherState.STARTED)); - } + assertBusy(() -> { + if (useClient) { + assertThat(watcherClient().prepareWatcherStats().get().getWatcherState(), is(WatcherState.STARTED)); + } else { + assertThat(getInstanceFromMaster(WatcherService.class).state(), is(WatcherState.STARTED)); } }); @@ -549,12 +537,9 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase } protected void ensureLicenseEnabled() throws Exception { - assertBusy(new Runnable() { - @Override - public void run() { - for (WatcherLicensee service : internalCluster().getInstances(WatcherLicensee.class)) { - assertThat(service.isWatcherTransportActionAllowed(), is(true)); - } + assertBusy(() -> { + for (WatcherLicensee service : internalCluster().getInstances(WatcherLicensee.class)) { + assertThat(service.isWatcherTransportActionAllowed(), is(true)); } }); } @@ -564,14 +549,11 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase } protected void ensureWatcherStopped(final boolean useClient) throws Exception { - assertBusy(new Runnable() { - @Override - public void run() { - if (useClient) { - assertThat(watcherClient().prepareWatcherStats().get().getWatcherState(), is(WatcherState.STOPPED)); - } else { - assertThat(getInstanceFromMaster(WatcherService.class).state(), is(WatcherState.STOPPED)); - } + assertBusy(() -> { + if (useClient) { + assertThat(watcherClient().prepareWatcherStats().get().getWatcherState(), is(WatcherState.STOPPED)); + } else { + assertThat(getInstanceFromMaster(WatcherService.class).state(), is(WatcherState.STOPPED)); } }); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/HttpSecretsIntegrationTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/HttpSecretsIntegrationTests.java index 71a077dbb2d..14f073e0fb4 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/HttpSecretsIntegrationTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/HttpSecretsIntegrationTests.java @@ -53,6 +53,7 @@ import static org.joda.time.DateTimeZone.UTC; * */ public class HttpSecretsIntegrationTests extends AbstractWatcherIntegrationTestCase { + static final String USERNAME = "_user"; static final String PASSWORD = "_passwd"; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java index 8735bbb3630..a059b29de4e 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java @@ -15,7 +15,6 @@ import java.util.Map; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; @@ -75,7 +74,7 @@ import org.elasticsearch.watcher.input.search.SearchInputFactory; import org.elasticsearch.watcher.input.simple.ExecutableSimpleInput; import org.elasticsearch.watcher.input.simple.SimpleInput; import org.elasticsearch.watcher.input.simple.SimpleInputFactory; -import org.elasticsearch.watcher.license.WatcherLicensee; +import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.support.Script; import org.elasticsearch.watcher.support.WatcherUtils; import org.elasticsearch.watcher.support.clock.Clock; From de6d3e1a72b77730beb92ca7e54fd545ca663f9f Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 21 Apr 2016 07:58:51 -0400 Subject: [PATCH 12/23] Remove readFrom from xpack Writeable#readFrom has become a method you just implement because the interface requires it but the prefered way to actually do the reading is a ctor that takes a StreamReader. readFrom just delegates to the ctor. This removes readFrom entirely because it is not needed anymore and is going away in core. Relates to https://github.com/elastic/elasticsearch/issues/17085 Original commit: elastic/x-pack-elasticsearch@dd74db5dedff19d302cbbae100c4611afb659f93 --- .../marvel/action/MonitoringBulkDoc.java | 26 ++++--- .../marvel/agent/exporter/MonitoringDoc.java | 71 +++++++++---------- 2 files changed, 46 insertions(+), 51 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkDoc.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkDoc.java index 96fcce29ab2..25bc836d555 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkDoc.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkDoc.java @@ -24,6 +24,9 @@ public class MonitoringBulkDoc extends MonitoringDoc { super(monitoringId, monitoringVersion); } + /** + * Read from a stream. + */ public MonitoringBulkDoc(StreamInput in) throws IOException { super(in); index = in.readOptionalString(); @@ -32,6 +35,15 @@ public class MonitoringBulkDoc extends MonitoringDoc { source = in.readBytesReference(); } + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalString(index); + out.writeOptionalString(type); + out.writeOptionalString(id); + out.writeBytesReference(source); + } + public String getIndex() { return index; } @@ -63,18 +75,4 @@ public class MonitoringBulkDoc extends MonitoringDoc { public void setSource(BytesReference source) { this.source = source; } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeOptionalString(index); - out.writeOptionalString(type); - out.writeOptionalString(id); - out.writeBytesReference(source); - } - - @Override - public MonitoringBulkDoc readFrom(StreamInput in) throws IOException { - return new MonitoringBulkDoc(in); - } } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java index 5bf0295c3ca..6b04b66cc0f 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java @@ -34,6 +34,9 @@ public class MonitoringDoc implements Writeable { this.monitoringVersion = monitoringVersion; } + /** + * Read from a stream. + */ public MonitoringDoc(StreamInput in) throws IOException { this(in.readOptionalString(), in.readOptionalString()); clusterUUID = in.readOptionalString(); @@ -41,6 +44,15 @@ public class MonitoringDoc implements Writeable { sourceNode = in.readOptionalWriteable(Node::new); } + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeOptionalString(getMonitoringId()); + out.writeOptionalString(getMonitoringVersion()); + out.writeOptionalString(getClusterUUID()); + out.writeVLong(getTimestamp()); + out.writeOptionalWriteable(getSourceNode()); + } + public String getClusterUUID() { return clusterUUID; } @@ -86,20 +98,6 @@ public class MonitoringDoc implements Writeable { "]"; } - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeOptionalString(getMonitoringId()); - out.writeOptionalString(getMonitoringVersion()); - out.writeOptionalString(getClusterUUID()); - out.writeVLong(getTimestamp()); - out.writeOptionalWriteable(getSourceNode()); - } - - @Override - public MonitoringDoc readFrom(StreamInput in) throws IOException { - return new MonitoringDoc(in); - } - public static class Node implements Writeable, ToXContent { private String uuid; @@ -123,6 +121,9 @@ public class MonitoringDoc implements Writeable { } } + /** + * Read from a stream. + */ public Node(StreamInput in) throws IOException { uuid = in.readOptionalString(); host = in.readOptionalString(); @@ -136,6 +137,25 @@ public class MonitoringDoc implements Writeable { } } + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeOptionalString(uuid); + out.writeOptionalString(host); + out.writeOptionalString(transportAddress); + out.writeOptionalString(ip); + out.writeOptionalString(name); + if (attributes != null) { + out.writeVInt(attributes.size()); + for (Map.Entry entry : attributes.entrySet()) { + out.writeString(entry.getKey()); + out.writeString(entry.getValue()); + } + } else { + out.writeVInt(0); + } + } + + public String getUUID() { return uuid; } @@ -177,29 +197,6 @@ public class MonitoringDoc implements Writeable { return builder.endObject(); } - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeOptionalString(uuid); - out.writeOptionalString(host); - out.writeOptionalString(transportAddress); - out.writeOptionalString(ip); - out.writeOptionalString(name); - if (attributes != null) { - out.writeVInt(attributes.size()); - for (Map.Entry entry : attributes.entrySet()) { - out.writeString(entry.getKey()); - out.writeString(entry.getValue()); - } - } else { - out.writeVInt(0); - } - } - - @Override - public Node readFrom(StreamInput in) throws IOException { - return new Node(in); - } - @Override public boolean equals(Object o) { if (this == o) return true; From 8c8e33889c90383343144b7c29042d2b8dd63400 Mon Sep 17 00:00:00 2001 From: jaymode Date: Thu, 21 Apr 2016 07:52:00 -0400 Subject: [PATCH 13/23] build: remove test dependencies from published pom file See elastic/elasticsearch#2063 Original commit: elastic/x-pack-elasticsearch@3653368363e861b3474b1343f695f0e479ad9f8e --- elasticsearch/x-pack/build.gradle | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/elasticsearch/x-pack/build.gradle b/elasticsearch/x-pack/build.gradle index 970169a404c..e64aac614c9 100644 --- a/elasticsearch/x-pack/build.gradle +++ b/elasticsearch/x-pack/build.gradle @@ -187,13 +187,17 @@ modifyPom { MavenPom pom -> // find the 'base' dependency and replace it with the correct name because the project name is // always used even when the pom of the other project is correct - for (Node depNode : depsNodes.get(0).children()) { + Iterator childNodeIter = depsNodes.get(0).children().iterator() + while (childNodeIter.hasNext()) { + Node depNode = childNodeIter.next() String groupId = depNode.get('groupId').get(0).text() Node artifactIdNode = depNode.get('artifactId').get(0) String artifactId = artifactIdNode.text() + String scope = depNode.get("scope").get(0).text() if (groupId.equals('org.elasticsearch') && artifactId.equals('base')) { artifactIdNode.replaceNode(new Node(null, 'artifactId', 'license-core')) - return + } else if ('test'.equals(scope)) { + childNodeIter.remove() } } } From c4dc28e7f74e8fd712875894ab3d0630fac70967 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 21 Apr 2016 09:41:21 -0400 Subject: [PATCH 14/23] Remove the last readFrom from xpack This the last Writeable#readFrom in xpack! Original commit: elastic/x-pack-elasticsearch@5412160bdda2a37dbd6695e1cfea1d3ca095adaf --- .../marvel/action/MonitoringBulkResponse.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkResponse.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkResponse.java index e7544a99434..d57a878f74e 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkResponse.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkResponse.java @@ -87,6 +87,11 @@ public class MonitoringBulkResponse extends ActionResponse { this(in.readThrowable()); } + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeThrowable(getCause()); + } + /** * The failure message. */ @@ -108,16 +113,6 @@ public class MonitoringBulkResponse extends ActionResponse { return cause; } - @Override - public Error readFrom(StreamInput in) throws IOException { - return new Error(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeThrowable(getCause()); - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); From 629c585fba834fc11903bfa71010bff3039769a7 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 21 Apr 2016 13:00:39 -0400 Subject: [PATCH 15/23] Handle core removing from Writeable Original commit: elastic/x-pack-elasticsearch@34632c8a67a2118882b871188ef999515afe42e7 --- .../elasticsearch/marvel/action/MonitoringBulkResponse.java | 2 +- .../elasticsearch/marvel/agent/exporter/MonitoringDoc.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkResponse.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkResponse.java index d57a878f74e..341e41408fc 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkResponse.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/action/MonitoringBulkResponse.java @@ -73,7 +73,7 @@ public class MonitoringBulkResponse extends ActionResponse { out.writeOptionalWriteable(error); } - public static class Error implements Writeable, ToXContent { + public static class Error implements Writeable, ToXContent { private final Throwable cause; private final RestStatus status; diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java index 6b04b66cc0f..9929fffa248 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MonitoringDoc.java @@ -20,7 +20,7 @@ import java.util.Map; /** * Base class for all monitoring documents. */ -public class MonitoringDoc implements Writeable { +public class MonitoringDoc implements Writeable { private final String monitoringId; private final String monitoringVersion; @@ -98,7 +98,7 @@ public class MonitoringDoc implements Writeable { "]"; } - public static class Node implements Writeable, ToXContent { + public static class Node implements Writeable, ToXContent { private String uuid; private String host; From a84347f711b2749078cf7db734d9f0fb57690a32 Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Thu, 21 Apr 2016 15:48:41 -0400 Subject: [PATCH 16/23] Monitoring: Ignore NodesStatsResposne if no stats are returned This avoids exceptional cases where node stats are not returned due to some concurrent modification. Original commit: elastic/x-pack-elasticsearch@6f6b8ec3938a824aaf0364bcea1503c3169d768f --- .../agent/collector/node/NodeStatsCollector.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java index b915e2da853..72e6cf6ff83 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java @@ -71,7 +71,17 @@ public class NodeStatsCollector extends AbstractCollector { request.process(true); request.threadPool(true); request.fs(true); - NodeStats nodeStats = client.admin().cluster().nodesStats(request).actionGet().getAt(0); + + NodeStats[] nodesStatsResponses = client.admin().cluster().nodesStats(request).actionGet().getNodes(); + + // In unusual scenarios, node stats can be empty (e.g., closing an index in the middle of the request) + // Note: NodesStatsResponse does not currently override failures, so we cannot log the actual reason + if (nodesStatsResponses.length == 0) { + logger.debug("_local NodesStatsResponse is empty"); + return null; + } + + NodeStats nodeStats = nodesStatsResponses[0]; // Here we are calling directly the DiskThresholdDecider to retrieve the high watermark value // It would be nicer to use a settings API like documented in #6732 From df3bbd42b99c1b2559e50ef3cac7360b8808ccc2 Mon Sep 17 00:00:00 2001 From: uboness Date: Thu, 21 Apr 2016 09:50:44 -0700 Subject: [PATCH 17/23] Changed the default output of X-Pack Info API - by default the response includes all info - build, license, features + human descriptions. - you can still control the output using `categories` and `human` parameters - Added docs to this API Original commit: elastic/x-pack-elasticsearch@85115495ec6560552240cf519c4caaad46ae70ec --- .../xpack/action/XPackInfoRequest.java | 9 +- .../rest/action/RestXPackInfoAction.java | 5 +- .../rest-api-spec/test/xpack/15_basic.yaml | 110 ++++++++++-------- 3 files changed, 71 insertions(+), 53 deletions(-) diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequest.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequest.java index a01fc96b249..64f0b512cb6 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequest.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/action/XPackInfoRequest.java @@ -25,7 +25,14 @@ public class XPackInfoRequest extends ActionRequest { public static EnumSet toSet(String... categories) { EnumSet set = EnumSet.noneOf(Category.class); for (String category : categories) { - set.add(Category.valueOf(category.toUpperCase(Locale.ROOT))); + switch (category) { + case "_all": + return EnumSet.allOf(Category.class); + case "_none": + return EnumSet.noneOf(Category.class); + default: + set.add(Category.valueOf(category.toUpperCase(Locale.ROOT))); + } } return set; } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackInfoAction.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackInfoAction.java index 5b1119c8ac4..fe24da5acfa 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackInfoAction.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackInfoAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.rest.action; import org.elasticsearch.client.Client; -import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -40,10 +39,10 @@ public class RestXPackInfoAction extends XPackRestHandler { protected void handleRequest(RestRequest request, RestChannel restChannel, XPackClient client) throws Exception { // we piggyback verbosity on "human" output - boolean verbose = request.paramAsBoolean("human", false); + boolean verbose = request.paramAsBoolean("human", true); EnumSet categories = XPackInfoRequest.Category - .toSet(request.paramAsStringArray("categories", Strings.EMPTY_ARRAY)); + .toSet(request.paramAsStringArray("categories", new String[] { "_all" })); client.prepareInfo().setVerbose(verbose).setCategories(categories).execute(new RestBuilderListener(restChannel) { @Override public RestResponse buildResponse(XPackInfoResponse infoResponse, XContentBuilder builder) throws Exception { diff --git a/elasticsearch/x-pack/src/test/resources/rest-api-spec/test/xpack/15_basic.yaml b/elasticsearch/x-pack/src/test/resources/rest-api-spec/test/xpack/15_basic.yaml index 6d5e3413c1a..713ff499e49 100644 --- a/elasticsearch/x-pack/src/test/resources/rest-api-spec/test/xpack/15_basic.yaml +++ b/elasticsearch/x-pack/src/test/resources/rest-api-spec/test/xpack/15_basic.yaml @@ -56,24 +56,6 @@ - do: xpack.info: {} - - is_false: tagline - - is_false: build - - is_false: features - - is_false: license - - - do: - xpack.info: - categories: "build" - - is_true: build - - is_true: build.hash - - is_true: build.timestamp - - is_false: tagline - - is_false: features - - is_false: license - - - do: - xpack.info: - categories: "build,license" - is_true: build.hash - is_true: build.timestamp - is_true: license @@ -82,12 +64,71 @@ - match: { license.mode: "platinum" } - match: { license.status: "active" } - match: { license.expiry_date_in_millis: 1914278399999 } - - is_false: tagline + - is_true: features + - is_true: features.watcher + - is_true: features.watcher.enabled + - is_true: features.watcher.available + - is_true: features.watcher.description + - is_true: features.security + - is_true: features.security.enabled + - is_true: features.security.available + - is_true: features.security.description + - is_true: features.graph + - is_true: features.graph.enabled + - is_true: features.graph.available + - is_true: features.graph.description + - is_true: features.monitoring + - is_true: features.monitoring.enabled + - is_true: features.monitoring.available + - is_true: features.monitoring.description + - is_true: tagline + + - do: + xpack.info: + categories: "_none" + - is_false: build + - is_false: features + - is_false: license + - match: { tagline: "You know, for X" } + + - do: + xpack.info: + categories: "_none" + human: false + - is_false: build + - is_false: features + - is_false: license + - is_false: tagline + + - do: + xpack.info: + categories: "build" + - is_true: build + - is_true: build.hash + - is_true: build.timestamp + - is_true: tagline - is_false: features + - is_false: license + + - do: + xpack.info: + categories: "build,license" + - is_true: build.hash + - is_true: build.timestamp + - is_true: tagline + - is_false: features + - is_true: license + - match: { license.uid: "893361dc-9749-4997-93cb-802e3dofh7aa" } + - match: { license.type: "internal" } + - match: { license.mode: "platinum" } + - match: { license.status: "active" } + - match: { license.expiry_date_in_millis: 1914278399999 } + - do: xpack.info: categories: "build,license,features" + human: false - is_true: build.hash - is_true: build.timestamp - is_true: license @@ -115,33 +156,4 @@ - is_false: features.monitoring.description - is_false: tagline - - do: - xpack.info: - categories: "build,license,features" - human: "true" - - is_true: build.hash - - is_true: build.timestamp - - is_true: license - - match: { license.uid: "893361dc-9749-4997-93cb-802e3dofh7aa" } - - match: { license.type: "internal" } - - match: { license.mode: "platinum" } - - match: { license.status: "active" } - - match: { license.expiry_date_in_millis: 1914278399999 } - - is_true: features - - is_true: features.watcher - - is_true: features.watcher.enabled - - is_true: features.watcher.available - - is_true: features.watcher.description - - is_true: features.security - - is_true: features.security.enabled - - is_true: features.security.available - - is_true: features.security.description - - is_true: features.graph - - is_true: features.graph.enabled - - is_true: features.graph.available - - is_true: features.graph.description - - is_true: features.monitoring - - is_true: features.monitoring.enabled - - is_true: features.monitoring.available - - is_true: features.monitoring.description - - is_true: tagline + From 12ff8853f05d37f04c93e6ba3c931c08b6d08df0 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Fri, 22 Apr 2016 09:26:40 +0200 Subject: [PATCH 18/23] Monitoring/Watcher: Load version of templates in a static way (elastic/elasticsearch#2040) The old implementation was to use properties at build-time. This however did not work, as the tests could not be run in the IDE. This has been removed of monitoring for some time already, but needs to be removed from watcher as well. This commit uses static variables and refactors the code a bit. First, there is a generic TemplateUtils class, to be used in monitoring and watcher. Also the watcher code has been changed to copy the needed variables into the template registry class instead of keeping it in the WatcherModule. This commit also includes some refactoring to remove the version parameter in marvel, was static anyway Closes elastic/elasticsearch#1372 Original commit: elastic/x-pack-elasticsearch@fbfc22ea09dbc4e1aa5162ab75b13ba444b39eea --- .../agent/exporter/MarvelTemplateUtils.java | 62 +---------- .../resolver/MonitoringIndexNameResolver.java | 28 ++--- .../agent/resolver/ResolversRegistry.java | 34 +++--- .../resolver/bulk/MonitoringBulkResolver.java | 4 +- .../resolver/cluster/ClusterInfoResolver.java | 4 - .../cluster/ClusterStateNodeResolver.java | 4 +- .../cluster/ClusterStateResolver.java | 4 +- .../cluster/ClusterStatsResolver.java | 4 +- .../cluster/DiscoveryNodeResolver.java | 4 - .../indices/IndexRecoveryResolver.java | 4 +- .../resolver/indices/IndexStatsResolver.java | 4 +- .../indices/IndicesStatsResolver.java | 4 +- .../resolver/node/NodeStatsResolver.java | 4 +- .../agent/resolver/shards/ShardsResolver.java | 4 +- .../AbstractExporterTemplateTestCase.java | 79 +++----------- .../exporter/MarvelTemplateUtilsTests.java | 77 +------------ .../http/HttpExporterTemplateTests.java | 4 +- .../local/LocalExporterTemplateTests.java | 4 +- .../agent/resolver/DataResolverTests.java | 12 +- .../MonitoringIndexNameResolverTestCase.java | 6 +- .../resolver/TimestampedResolverTests.java | 14 +-- .../resolver/cluster/ClusterStateTests.java | 4 +- .../AbstractIndicesCleanerTestCase.java | 46 +++++--- .../marvel/test/MarvelIntegTestCase.java | 16 +-- .../xpack/template/TemplateUtils.java | 79 ++++++++++++++ .../xpack/template/TemplateUtilsTests.java | 103 ++++++++++++++++++ .../org/elasticsearch/watcher/Watcher.java | 3 +- .../elasticsearch/watcher/WatcherModule.java | 48 -------- .../watcher/history/HistoryStore.java | 3 +- .../support/WatcherIndexTemplateRegistry.java | 79 +++++++------- .../history/HistoryStoreSettingsTests.java | 13 ++- .../watcher/history/HistoryStoreTests.java | 3 +- .../WatcherIndexTemplateRegistryTests.java | 6 +- .../AbstractWatcherIntegrationTestCase.java | 11 +- 34 files changed, 365 insertions(+), 413 deletions(-) create mode 100644 elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/template/TemplateUtils.java create mode 100644 elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/template/TemplateUtilsTests.java diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtils.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtils.java index 5c3163b2da8..65ef16e108e 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtils.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtils.java @@ -5,16 +5,8 @@ */ package org.elasticsearch.marvel.agent.exporter; -import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.compress.NotXContentException; -import org.elasticsearch.common.io.Streams; -import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.xpack.template.TemplateUtils; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; import java.util.Locale; import java.util.regex.Pattern; @@ -29,56 +21,8 @@ public final class MarvelTemplateUtils { private MarvelTemplateUtils() { } - /** - * Loads a built-in template and returns its source. - */ - public static String loadTemplate(String id, Integer version) { + public static String loadTemplate(String id) { String resource = String.format(Locale.ROOT, TEMPLATE_FILE, id); - try { - BytesReference source = load(resource); - validate(source); - - return filter(source, version); - } catch (Exception e) { - throw new IllegalArgumentException("Unable to load monitoring template [" + resource + "]", e); - } - } - - /** - * Loads a resource from the classpath and returns it as a {@link BytesReference} - */ - static BytesReference load(String name) throws IOException { - try (InputStream is = MarvelTemplateUtils.class.getResourceAsStream(name)) { - try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { - Streams.copy(is, out); - return new BytesArray(out.toByteArray()); - } - } - } - - /** - * Parses and validates that the source is not empty. - */ - static void validate(BytesReference source) { - if (source == null) { - throw new ElasticsearchParseException("Monitoring template must not be null"); - } - - try { - XContentHelper.convertToMap(source, false).v2(); - } catch (NotXContentException e) { - throw new ElasticsearchParseException("Monitoring template must not be empty"); - } catch (Exception e) { - throw new ElasticsearchParseException("Invalid monitoring template", e); - } - } - - /** - * Filters the source: replaces any template version property with the version number - */ - static String filter(BytesReference source, Integer version) { - return Pattern.compile(TEMPLATE_VERSION_PROPERTY) - .matcher(source.toUtf8()) - .replaceAll(String.valueOf(version)); + return TemplateUtils.loadTemplate(resource, String.valueOf(TEMPLATE_VERSION), TEMPLATE_VERSION_PROPERTY); } } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolver.java index add17936baa..6b89eec592b 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolver.java @@ -35,12 +35,6 @@ public abstract class MonitoringIndexNameResolver { public static final String PREFIX = ".monitoring"; public static final String DELIMITER = "-"; - private final int version; - - protected MonitoringIndexNameResolver(int version) { - this.version = version; - } - /** * Returns the name of the index in which the monitoring document must be indexed. * @@ -111,10 +105,6 @@ public abstract class MonitoringIndexNameResolver { */ public abstract String template(); - int getVersion() { - return version; - } - /** * @return the filters used when rendering the document. * If null or empty, no filtering is applied. @@ -142,9 +132,8 @@ public abstract class MonitoringIndexNameResolver { private final String index; - public Data(int version) { - super(version); - this.index = String.join(DELIMITER, PREFIX, DATA, String.valueOf(version)); + public Data() { + this.index = String.join(DELIMITER, PREFIX, DATA, String.valueOf(MarvelTemplateUtils.TEMPLATE_VERSION)); } @Override @@ -159,12 +148,12 @@ public abstract class MonitoringIndexNameResolver { @Override public String templateName() { - return String.format(Locale.ROOT, "%s-%s-%d", PREFIX, DATA, getVersion()); + return String.format(Locale.ROOT, "%s-%s-%d", PREFIX, DATA, MarvelTemplateUtils.TEMPLATE_VERSION); } @Override public String template() { - return MarvelTemplateUtils.loadTemplate(DATA, getVersion()); + return MarvelTemplateUtils.loadTemplate(DATA); } } @@ -181,10 +170,9 @@ public abstract class MonitoringIndexNameResolver { private final DateTimeFormatter formatter; private final String index; - public Timestamped(MonitoredSystem system, int version, Settings settings) { - super(version); + public Timestamped(MonitoredSystem system, Settings settings) { this.system = system; - this.index = String.join(DELIMITER, PREFIX, system.getSystem(), String.valueOf(getVersion())); + this.index = String.join(DELIMITER, PREFIX, system.getSystem(), String.valueOf(MarvelTemplateUtils.TEMPLATE_VERSION)); String format = INDEX_NAME_TIME_FORMAT_SETTING.get(settings); try { this.formatter = DateTimeFormat.forPattern(format).withZoneUTC(); @@ -211,12 +199,12 @@ public abstract class MonitoringIndexNameResolver { @Override public String templateName() { - return String.format(Locale.ROOT, "%s-%s-%d", PREFIX, getId(), getVersion()); + return String.format(Locale.ROOT, "%s-%s-%d", PREFIX, getId(), MarvelTemplateUtils.TEMPLATE_VERSION); } @Override public String template() { - return MarvelTemplateUtils.loadTemplate(getId(), getVersion()); + return MarvelTemplateUtils.loadTemplate(getId()); } String getId() { diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/ResolversRegistry.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/ResolversRegistry.java index 6f14a53c77a..86d5d9c3913 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/ResolversRegistry.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/ResolversRegistry.java @@ -19,7 +19,6 @@ import org.elasticsearch.marvel.agent.collector.indices.IndexStatsMonitoringDoc; import org.elasticsearch.marvel.agent.collector.indices.IndicesStatsMonitoringDoc; import org.elasticsearch.marvel.agent.collector.node.NodeStatsMonitoringDoc; import org.elasticsearch.marvel.agent.collector.shards.ShardMonitoringDoc; -import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; import org.elasticsearch.marvel.agent.resolver.bulk.MonitoringBulkResolver; import org.elasticsearch.marvel.agent.resolver.cluster.ClusterInfoResolver; @@ -43,40 +42,37 @@ import static org.elasticsearch.marvel.MonitoredSystem.ES; public class ResolversRegistry implements Iterable { - private static final int ES_TEMPLATE_VERSION = MarvelTemplateUtils.TEMPLATE_VERSION; - private static final int KIBANA_TEMPLATE_VERSION = MarvelTemplateUtils.TEMPLATE_VERSION; - private final List registrations = new ArrayList<>(); public ResolversRegistry(Settings settings) { // register built-in defaults resolvers - registerBuiltIn(ES, ES_TEMPLATE_VERSION, settings); + registerBuiltIn(ES, settings); // register resolvers for monitored systems - registerMonitoredSystem(MonitoredSystem.KIBANA, KIBANA_TEMPLATE_VERSION, settings); + registerMonitoredSystem(MonitoredSystem.KIBANA, settings); } /** * Registers resolvers for elasticsearch documents collected by the monitoring plugin */ - private void registerBuiltIn(MonitoredSystem id, int version, Settings settings) { - registrations.add(resolveByClass(ClusterInfoMonitoringDoc.class, new ClusterInfoResolver(version))); - registrations.add(resolveByClass(ClusterStateNodeMonitoringDoc.class, new ClusterStateNodeResolver(id, version, settings))); - registrations.add(resolveByClass(ClusterStateMonitoringDoc.class, new ClusterStateResolver(id, version, settings))); - registrations.add(resolveByClass(ClusterStatsMonitoringDoc.class, new ClusterStatsResolver(id, version, settings))); - registrations.add(resolveByClass(DiscoveryNodeMonitoringDoc.class, new DiscoveryNodeResolver(version))); - registrations.add(resolveByClass(IndexRecoveryMonitoringDoc.class, new IndexRecoveryResolver(id, version, settings))); - registrations.add(resolveByClass(IndexStatsMonitoringDoc.class, new IndexStatsResolver(id, version, settings))); - registrations.add(resolveByClass(IndicesStatsMonitoringDoc.class, new IndicesStatsResolver(id, version, settings))); - registrations.add(resolveByClass(NodeStatsMonitoringDoc.class, new NodeStatsResolver(id, version, settings))); - registrations.add(resolveByClass(ShardMonitoringDoc.class, new ShardsResolver(id, version, settings))); + private void registerBuiltIn(MonitoredSystem id, Settings settings) { + registrations.add(resolveByClass(ClusterInfoMonitoringDoc.class, new ClusterInfoResolver())); + registrations.add(resolveByClass(ClusterStateNodeMonitoringDoc.class, new ClusterStateNodeResolver(id, settings))); + registrations.add(resolveByClass(ClusterStateMonitoringDoc.class, new ClusterStateResolver(id, settings))); + registrations.add(resolveByClass(ClusterStatsMonitoringDoc.class, new ClusterStatsResolver(id, settings))); + registrations.add(resolveByClass(DiscoveryNodeMonitoringDoc.class, new DiscoveryNodeResolver())); + registrations.add(resolveByClass(IndexRecoveryMonitoringDoc.class, new IndexRecoveryResolver(id, settings))); + registrations.add(resolveByClass(IndexStatsMonitoringDoc.class, new IndexStatsResolver(id, settings))); + registrations.add(resolveByClass(IndicesStatsMonitoringDoc.class, new IndicesStatsResolver(id, settings))); + registrations.add(resolveByClass(NodeStatsMonitoringDoc.class, new NodeStatsResolver(id, settings))); + registrations.add(resolveByClass(ShardMonitoringDoc.class, new ShardsResolver(id, settings))); } /** * Registers resolvers for monitored systems */ - private void registerMonitoredSystem(MonitoredSystem id, int version, Settings settings) { - final MonitoringBulkResolver resolver = new MonitoringBulkResolver(id, version, settings); + private void registerMonitoredSystem(MonitoredSystem id, Settings settings) { + final MonitoringBulkResolver resolver = new MonitoringBulkResolver(id, settings); registrations.add(resolveByClassSystemVersion(MonitoringBulkDoc.class, id, Version.CURRENT, resolver)); } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/bulk/MonitoringBulkResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/bulk/MonitoringBulkResolver.java index e92b3e34452..e4fa402075d 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/bulk/MonitoringBulkResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/bulk/MonitoringBulkResolver.java @@ -17,8 +17,8 @@ import java.io.IOException; public class MonitoringBulkResolver extends MonitoringIndexNameResolver.Timestamped { - public MonitoringBulkResolver(MonitoredSystem id, int version, Settings settings) { - super(id, version, settings); + public MonitoringBulkResolver(MonitoredSystem id, Settings settings) { + super(id, settings); } @Override diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolver.java index 407d3eb2659..cab0a37cb88 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolver.java @@ -22,10 +22,6 @@ public class ClusterInfoResolver extends MonitoringIndexNameResolver.Data existing templates are old"); - assertTemplateExist(dataTemplateName(version)); - assertTemplateExist(indexTemplateName(version)); + assertTemplateExist(dataTemplateName()); + assertTemplateExist(indexTemplateName()); logger.debug("--> existing templates are old: new templates should be created"); for (String template : monitoringTemplates().keySet()) { @@ -95,8 +92,8 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa public void testCreateWhenExistingTemplateAreUpToDate() throws Exception { internalCluster().startNode(); - putTemplate(indexTemplateName(currentVersion), currentVersion); - putTemplate(dataTemplateName(currentVersion), currentVersion); + putTemplate(indexTemplateName()); + putTemplate(dataTemplateName()); doExporting(); @@ -106,8 +103,8 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa } logger.debug("--> existing templates has the same version: they should not be changed"); - assertTemplateNotUpdated(indexTemplateName(currentVersion)); - assertTemplateNotUpdated(dataTemplateName(currentVersion)); + assertTemplateNotUpdated(indexTemplateName()); + assertTemplateNotUpdated(dataTemplateName()); doExporting(); @@ -116,47 +113,6 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa awaitIndexExists(currentTimestampedIndexName()); } - public void testRandomTemplates() throws Exception { - internalCluster().startNode(); - - int previousIndexTemplateVersion = rarely() ? currentVersion : randomIntBetween(0, currentVersion - 1); - boolean previousIndexTemplateExist = randomBoolean(); - if (previousIndexTemplateExist) { - logger.debug("--> creating index template in version [{}]", previousIndexTemplateVersion); - putTemplate(indexTemplateName(previousIndexTemplateVersion), previousIndexTemplateVersion); - } - - int previousDataTemplateVersion = rarely() ? currentVersion : randomIntBetween(0, currentVersion - 1); - boolean previousDataTemplateExist = randomBoolean(); - if (previousDataTemplateExist) { - logger.debug("--> creating data template in version [{}]", previousDataTemplateVersion); - putTemplate(dataTemplateName(previousDataTemplateVersion), previousDataTemplateVersion); - } - - doExporting(); - - logger.debug("--> templates should exist in current version"); - for (String template : monitoringTemplates().keySet()) { - assertTemplateExist(template); - } - - if (previousIndexTemplateExist) { - logger.debug("--> index template should exist in version [{}]", previousIndexTemplateVersion); - assertTemplateExist(indexTemplateName(previousIndexTemplateVersion)); - } - - if (previousDataTemplateExist) { - logger.debug("--> data template should exist in version [{}]", previousDataTemplateVersion); - assertTemplateExist(dataTemplateName(previousDataTemplateVersion)); - } - - doExporting(); - - logger.debug("--> indices should exist in current version"); - awaitIndexExists(currentDataIndexName()); - awaitIndexExists(currentTimestampedIndexName()); - } - protected void doExporting() throws Exception { Collector collector = internalCluster().getInstance(ClusterStatsCollector.class); assertNotNull(collector); @@ -169,18 +125,18 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa exporters.export(collector.collect()); } - private String dataTemplateName(Integer version) { - MockDataIndexNameResolver resolver = new MockDataIndexNameResolver(version); + private String dataTemplateName() { + MockDataIndexNameResolver resolver = new MockDataIndexNameResolver(); return resolver.templateName(); } - private String indexTemplateName(Integer version) { - MockTimestampedIndexNameResolver resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES, version, exporterSettings()); + private String indexTemplateName() { + MockTimestampedIndexNameResolver resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES, exporterSettings()); return resolver.templateName(); } private String currentDataIndexName() { - MockDataIndexNameResolver resolver = new MockDataIndexNameResolver(currentVersion); + MockDataIndexNameResolver resolver = new MockDataIndexNameResolver(); return resolver.index(null); } @@ -188,13 +144,12 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa MonitoringDoc doc = new MonitoringDoc(MonitoredSystem.ES.getSystem(), Version.CURRENT.toString()); doc.setTimestamp(System.currentTimeMillis()); - MockTimestampedIndexNameResolver resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES, currentVersion, - exporterSettings()); + MockTimestampedIndexNameResolver resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES, exporterSettings()); return resolver.index(doc); } /** Generates a basic template **/ - protected static BytesReference generateTemplateSource(String name, Integer version) throws IOException { + protected static BytesReference generateTemplateSource(String name) throws IOException { return jsonBuilder().startObject() .field("template", name) .startObject("settings") diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtilsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtilsTests.java index 8138d8520e5..c70566898b8 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtilsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtilsTests.java @@ -5,100 +5,31 @@ */ package org.elasticsearch.marvel.agent.exporter; -import org.apache.lucene.util.Constants; -import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.test.ESTestCase; -import org.hamcrest.Matcher; -import org.junit.Rule; -import org.junit.rules.ExpectedException; import java.io.IOException; +import static org.elasticsearch.xpack.template.TemplateUtilsTests.assertTemplate; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.notNullValue; public class MarvelTemplateUtilsTests extends ESTestCase { - private static final String TEST_TEMPLATE = "/monitoring-test.json"; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - public void testLoadTemplate() throws IOException { - final int version = randomIntBetween(0, 10_000); - String source = MarvelTemplateUtils.loadTemplate("test", version); + String source = MarvelTemplateUtils.loadTemplate("test"); assertThat(source, notNullValue()); assertThat(source.length(), greaterThan(0)); assertTemplate(source, equalTo("{\n" + - " \"template\": \".monitoring-data-" + version + "\",\n" + + " \"template\": \".monitoring-data-" + MarvelTemplateUtils.TEMPLATE_VERSION + "\",\n" + " \"mappings\": {\n" + " \"type_1\": {\n" + " \"_meta\": {\n" + - " \"template.version\": \"" + version + "\"\n" + + " \"template.version\": \"" + MarvelTemplateUtils.TEMPLATE_VERSION + "\"\n" + " }\n" + " }\n" + " }\n" + "}")); } - - public void testLoad() throws IOException { - BytesReference source = MarvelTemplateUtils.load(TEST_TEMPLATE); - assertThat(source, notNullValue()); - assertThat(source.length(), greaterThan(0)); - } - - public void testValidateNullSource() { - expectedException.expect(ElasticsearchParseException.class); - expectedException.expectMessage("Monitoring template must not be null"); - MarvelTemplateUtils.validate(null); - } - - public void testValidateEmptySource() { - expectedException.expect(ElasticsearchParseException.class); - expectedException.expectMessage("Monitoring template must not be empty"); - MarvelTemplateUtils.validate(new BytesArray("")); - } - - public void testValidateInvalidSource() { - expectedException.expect(ElasticsearchParseException.class); - expectedException.expectMessage("Invalid monitoring template"); - MarvelTemplateUtils.validate(new BytesArray("{\"foo\": \"bar")); - } - - public void testValidate() { - try { - MarvelTemplateUtils.validate(MarvelTemplateUtils.load(TEST_TEMPLATE)); - } catch (Exception e) { - fail("failed to validate test template: " + e.getMessage()); - } - } - - public void testFilter() { - assertTemplate(MarvelTemplateUtils.filter(new BytesArray("${monitoring.template.version}"), 0), equalTo("0")); - assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"test-${monitoring.template.version}\"}"), 1), - equalTo("{\"template\": \"test-1\"}")); - assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"${monitoring.template.version}-test\"}"), 2), - equalTo("{\"template\": \"2-test\"}")); - assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"test-${monitoring.template.version}-test\"}"), 3), - equalTo("{\"template\": \"test-3-test\"}")); - - final int version = randomIntBetween(0, 100); - assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"foo-${monitoring.template.version}\": " + - "\"bar-${monitoring.template.version}\"}"), version), - equalTo("{\"foo-" + version + "\": \"bar-" + version + "\"}")); - } - - public static void assertTemplate(String actual, Matcher matcher) { - if (Constants.WINDOWS) { - // translate Windows line endings (\r\n) to standard ones (\n) - actual = Strings.replace(actual, System.lineSeparator(), "\n"); - } - assertThat(actual, matcher); - } - } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTemplateTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTemplateTests.java index bb0d6afea5e..2ce259b6665 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTemplateTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTemplateTests.java @@ -74,8 +74,8 @@ public class HttpExporterTemplateTests extends AbstractExporterTemplateTestCase } @Override - protected void putTemplate(String name, int version) throws Exception { - dispatcher.templates.put(name, generateTemplateSource(name, version)); + protected void putTemplate(String name) throws Exception { + dispatcher.templates.put(name, generateTemplateSource(name)); } @Override diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporterTemplateTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporterTemplateTests.java index 035254747c6..8ec319f2c8d 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporterTemplateTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporterTemplateTests.java @@ -26,9 +26,9 @@ public class LocalExporterTemplateTests extends AbstractExporterTemplateTestCase } @Override - protected void putTemplate(String name, int version) throws Exception { + protected void putTemplate(String name) throws Exception { waitNoPendingTasksOnAll(); - assertAcked(client().admin().indices().preparePutTemplate(name).setSource(generateTemplateSource(name, version)).get()); + assertAcked(client().admin().indices().preparePutTemplate(name).setSource(generateTemplateSource(name)).get()); } @Override diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/DataResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/DataResolverTests.java index a526dfd20a4..471234ed3eb 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/DataResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/DataResolverTests.java @@ -10,6 +10,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; import java.io.IOException; @@ -20,11 +21,9 @@ import static org.hamcrest.Matchers.equalTo; public class DataResolverTests extends MonitoringIndexNameResolverTestCase { - private int randomVersion = randomIntBetween(0, 100); - @Override protected MonitoringIndexNameResolver newResolver() { - return newDataResolver(randomVersion); + return newDataResolver(); } @Override @@ -52,12 +51,11 @@ public class DataResolverTests extends MonitoringIndexNameResolverTestCase { } public void testDataResolver() { - assertThat(newDataResolver(randomVersion).index(newMarvelDoc()), equalTo(".monitoring-data-" + randomVersion)); - assertThat(newDataResolver(42).index(newMarvelDoc()), equalTo(".monitoring-data-42")); + assertThat(newDataResolver().index(newMarvelDoc()), equalTo(".monitoring-data-" + MarvelTemplateUtils.TEMPLATE_VERSION)); } - private MonitoringIndexNameResolver.Data newDataResolver(int randomVersion) { - return new MonitoringIndexNameResolver.Data(randomVersion) { + private MonitoringIndexNameResolver.Data newDataResolver() { + return new MonitoringIndexNameResolver.Data() { @Override public String type(MonitoringDoc document) { return null; diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java index 4b540ced892..8443e960297 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/MonitoringIndexNameResolverTestCase.java @@ -11,6 +11,7 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.marvel.MonitoredSystem; +import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; import org.elasticsearch.test.ESTestCase; @@ -128,18 +129,17 @@ public abstract class MonitoringIndexNameResolverTestCase newResolver() { - return newTimestampedResolver(randomId, randomVersion, Settings.EMPTY); + return newTimestampedResolver(randomId, Settings.EMPTY); } @Override @@ -72,19 +72,17 @@ public class TimestampedResolverTests extends MonitoringIndexNameResolverTestCas .build(); } - MonitoringIndexNameResolver.Timestamped resolver = newTimestampedResolver(randomId, randomVersion, settings); + MonitoringIndexNameResolver.Timestamped resolver = newTimestampedResolver(randomId, settings); assertThat(resolver, notNullValue()); assertThat(resolver.getId(), equalTo(randomId.getSystem())); - assertThat(resolver.getVersion(), equalTo(randomVersion)); assertThat(resolver.index(doc), - equalTo(PREFIX + DELIMITER + resolver.getId() + DELIMITER + String.valueOf(resolver.getVersion()) + equalTo(PREFIX + DELIMITER + resolver.getId() + DELIMITER + String.valueOf(MarvelTemplateUtils.TEMPLATE_VERSION) + DELIMITER + DateTimeFormat.forPattern(format).withZoneUTC().print(1437580442979L))); } } - private MonitoringIndexNameResolver.Timestamped newTimestampedResolver(MonitoredSystem id, int version, - Settings settings) { - return new MonitoringIndexNameResolver.Timestamped(id, version, settings) { + private MonitoringIndexNameResolver.Timestamped newTimestampedResolver(MonitoredSystem id, Settings settings) { + return new MonitoringIndexNameResolver.Timestamped(id, settings) { @Override public String type(MonitoringDoc document) { return null; diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java index e1d1ffd7415..9b172ec25e7 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStateTests.java @@ -107,7 +107,7 @@ public class ClusterStateTests extends MarvelIntegTestCase { public void testClusterStateNodes() throws Exception { final long nbNodes = internalCluster().size(); - MonitoringIndexNameResolver.Timestamped timestampedResolver = new MockTimestampedIndexNameResolver(ES, TEMPLATE_VERSION); + MonitoringIndexNameResolver.Timestamped timestampedResolver = new MockTimestampedIndexNameResolver(ES); assertNotNull(timestampedResolver); String timestampedIndex = timestampedResolver.indexPattern(); @@ -152,7 +152,7 @@ public class ClusterStateTests extends MarvelIntegTestCase { public void testDiscoveryNodes() throws Exception { final long nbNodes = internalCluster().size(); - MonitoringIndexNameResolver.Data dataResolver = new MockDataIndexNameResolver(TEMPLATE_VERSION); + MonitoringIndexNameResolver.Data dataResolver = new MockDataIndexNameResolver(); assertNotNull(dataResolver); String dataIndex = dataResolver.indexPattern(); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/AbstractIndicesCleanerTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/AbstractIndicesCleanerTestCase.java index 39060b09797..90846a2fc53 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/AbstractIndicesCleanerTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/AbstractIndicesCleanerTestCase.java @@ -19,6 +19,8 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.VersionUtils; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; import java.util.Locale; @@ -46,7 +48,7 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase public void testDeleteIndex() throws Exception { internalCluster().startNode(); - createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now().minusDays(10)); + createTimestampedIndex(now().minusDays(10)); assertIndicesCount(1); CleanerService.Listener listener = getListener(); @@ -57,7 +59,7 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase public void testIgnoreCurrentDataIndex() throws Exception { internalCluster().startNode(); - createDataIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now().minusDays(10)); + createDataIndex(now().minusDays(10)); assertIndicesCount(1); CleanerService.Listener listener = getListener(); @@ -69,8 +71,11 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase internalCluster().startNode(); createIndex(MonitoringSettings.LEGACY_DATA_INDEX_NAME, now().minusYears(1)); - createDataIndex(0, now().minusDays(10)); - createDataIndex(Integer.MAX_VALUE, now().minusDays(20)); + createDataIndex(now().minusDays(10)); + String olderIndex = String.join(MonitoringIndexNameResolver.DELIMITER, MonitoringIndexNameResolver.PREFIX, + MonitoringIndexNameResolver.Data.DATA, "1"); + createIndex(olderIndex, now().minusDays(20)); + assertIndicesCount(3); CleanerService.Listener listener = getListener(); @@ -81,8 +86,8 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase public void testIgnoreCurrentTimestampedIndex() throws Exception { internalCluster().startNode(); - createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now().minusDays(10)); - createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now()); + createTimestampedIndex(now().minusDays(10)); + createTimestampedIndex(now()); assertIndicesCount(2); CleanerService.Listener listener = getListener(); @@ -93,8 +98,13 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase public void testIgnoreTimestampedIndicesInOtherVersions() throws Exception { internalCluster().startNode(); - createTimestampedIndex(0, now().minusDays(10)); - createTimestampedIndex(Integer.MAX_VALUE, now().minusDays(10)); + createTimestampedIndex(now().minusDays(10)); + // create an older index based on an older template + DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY.MM.dd").withZoneUTC(); + String index = String.join(MonitoringIndexNameResolver.DELIMITER, MonitoringIndexNameResolver.PREFIX, + MonitoredSystem.ES.getSystem(), "1"); + String timestampedIndex = String.join("-", index, formatter.print(now().minusDays(10))); + createIndex(timestampedIndex, now().minusDays(10)); assertIndicesCount(2); CleanerService.Listener listener = getListener(); @@ -108,11 +118,11 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase CleanerService.Listener listener = getListener(); final DateTime now = now(); - createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusYears(1)); - createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusMonths(6)); - createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusMonths(1)); - createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusDays(10)); - createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusDays(1)); + createTimestampedIndex(now.minusYears(1)); + createTimestampedIndex(now.minusMonths(6)); + createTimestampedIndex(now.minusMonths(1)); + createTimestampedIndex(now.minusDays(10)); + createTimestampedIndex(now.minusDays(1)); assertIndicesCount(5); // Clean indices that have expired two years ago @@ -148,7 +158,7 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase final DateTime now = now(); for (int i = 0; i < max; i++) { - createTimestampedIndex(MarvelTemplateUtils.TEMPLATE_VERSION, now.minusDays(i)); + createTimestampedIndex(now.minusDays(i)); } assertIndicesCount(max); @@ -175,18 +185,18 @@ public abstract class AbstractIndicesCleanerTestCase extends MarvelIntegTestCase /** * Creates a monitoring data index in a given version. */ - protected void createDataIndex(int version, DateTime creationDate) { - createIndex(new MockDataIndexNameResolver(version).index(randomMonitoringDoc()), creationDate); + protected void createDataIndex(DateTime creationDate) { + createIndex(new MockDataIndexNameResolver().index(randomMonitoringDoc()), creationDate); } /** * Creates a monitoring timestamped index in a given version. */ - protected void createTimestampedIndex(int version, DateTime creationDate) { + protected void createTimestampedIndex(DateTime creationDate) { MonitoringDoc monitoringDoc = randomMonitoringDoc(); monitoringDoc.setTimestamp(creationDate.getMillis()); - MonitoringIndexNameResolver.Timestamped resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES, version); + MonitoringIndexNameResolver.Timestamped resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES); createIndex(resolver.index(monitoringDoc), creationDate); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java index c007990500e..f0d86963560 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java @@ -25,8 +25,8 @@ import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver; import org.elasticsearch.marvel.agent.resolver.ResolversRegistry; import org.elasticsearch.marvel.client.MonitoringClient; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.shield.authc.file.FileRealm; import org.elasticsearch.shield.Security; +import org.elasticsearch.shield.authc.file.FileRealm; import org.elasticsearch.shield.authc.support.Hasher; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.authz.store.FileRolesStore; @@ -438,11 +438,7 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase { Settings.builder().put(MonitoringSettings.INTERVAL.getKey(), value, timeUnit))); } - protected class MockDataIndexNameResolver extends MonitoringIndexNameResolver.Data { - - public MockDataIndexNameResolver(int version) { - super(version); - } + public class MockDataIndexNameResolver extends MonitoringIndexNameResolver.Data { @Override public String type(MonitoringDoc document) { @@ -462,12 +458,12 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase { protected class MockTimestampedIndexNameResolver extends MonitoringIndexNameResolver.Timestamped { - public MockTimestampedIndexNameResolver(MonitoredSystem id, int version, Settings settings) { - super(id, version, settings); + public MockTimestampedIndexNameResolver(MonitoredSystem id, Settings settings) { + super(id, settings); } - public MockTimestampedIndexNameResolver(MonitoredSystem id, int version) { - this(id, version, Settings.EMPTY); + public MockTimestampedIndexNameResolver(MonitoredSystem id) { + this(id, Settings.EMPTY); } @Override diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/template/TemplateUtils.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/template/TemplateUtils.java new file mode 100644 index 00000000000..c4ca9a71899 --- /dev/null +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/template/TemplateUtils.java @@ -0,0 +1,79 @@ +/* + * 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.template; + +import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.compress.NotXContentException; +import org.elasticsearch.common.io.Streams; +import org.elasticsearch.common.xcontent.XContentHelper; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.regex.Pattern; + +/** + * Handling versioned templates for time-based indices in x-pack + */ +public class TemplateUtils { + + private TemplateUtils() {} + + /** + * Loads a built-in template and returns its source. + */ + public static String loadTemplate(String resource, String version, String versionProperty) { + try { + BytesReference source = load(resource); + validate(source); + + return filter(source, version, versionProperty); + } catch (Exception e) { + throw new IllegalArgumentException("Unable to load template [" + resource + "]", e); + } + } + + /** + * Loads a resource from the classpath and returns it as a {@link BytesReference} + */ + public static BytesReference load(String name) throws IOException { + try (InputStream is = TemplateUtils.class.getResourceAsStream(name)) { + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { + Streams.copy(is, out); + return new BytesArray(out.toByteArray()); + } + } + } + + /** + * Parses and validates that the source is not empty. + */ + public static void validate(BytesReference source) { + if (source == null) { + throw new ElasticsearchParseException("Template must not be null"); + } + + try { + XContentHelper.convertToMap(source, false).v2(); + } catch (NotXContentException e) { + throw new ElasticsearchParseException("Template must not be empty"); + } catch (Exception e) { + throw new ElasticsearchParseException("Invalid template", e); + } + } + + /** + * Filters the source: replaces any template version property with the version number + */ + public static String filter(BytesReference source, String version, String versionProperty) { + return Pattern.compile(versionProperty) + .matcher(source.toUtf8()) + .replaceAll(version); + } + +} diff --git a/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/template/TemplateUtilsTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/template/TemplateUtilsTests.java new file mode 100644 index 00000000000..ab656373e25 --- /dev/null +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/template/TemplateUtilsTests.java @@ -0,0 +1,103 @@ +/* + * 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.template; + +import org.apache.lucene.util.Constants; +import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.test.ESTestCase; +import org.hamcrest.Matcher; + +import java.io.IOException; +import java.util.Locale; +import java.util.regex.Pattern; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.core.Is.is; + +public class TemplateUtilsTests extends ESTestCase { + + private static final String TEST_TEMPLATE = "/monitoring-%s.json"; + + public void testLoadTemplate() throws IOException { + final int version = randomIntBetween(0, 10_000); + String resource = String.format(Locale.ROOT, TEST_TEMPLATE, "test"); + String source = TemplateUtils.loadTemplate(resource, String.valueOf(version), Pattern.quote("${monitoring.template.version}")); + + assertThat(source, notNullValue()); + assertThat(source.length(), greaterThan(0)); + assertTemplate(source, equalTo("{\n" + + " \"template\": \".monitoring-data-" + version + "\",\n" + + " \"mappings\": {\n" + + " \"type_1\": {\n" + + " \"_meta\": {\n" + + " \"template.version\": \"" + version + "\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}")); + } + + public void testLoad() throws IOException { + String resource = String.format(Locale.ROOT, TEST_TEMPLATE, "test"); + BytesReference source = TemplateUtils.load(resource); + assertThat(source, notNullValue()); + assertThat(source.length(), greaterThan(0)); + } + + public void testValidateNullSource() { + ElasticsearchParseException exception = expectThrows(ElasticsearchParseException.class, () -> TemplateUtils.validate(null)); + assertThat(exception.getMessage(), is("Template must not be null")); + } + + public void testValidateEmptySource() { + ElasticsearchParseException exception = expectThrows(ElasticsearchParseException.class, + () -> TemplateUtils.validate(new BytesArray(""))); + assertThat(exception.getMessage(), is("Template must not be empty")); + } + + public void testValidateInvalidSource() { + ElasticsearchParseException exception = expectThrows(ElasticsearchParseException.class, + () -> TemplateUtils.validate(new BytesArray("{\"foo\": \"bar"))); + assertThat(exception.getMessage(), is("Invalid template")); + } + + public void testValidate() throws IOException { + String resource = String.format(Locale.ROOT, TEST_TEMPLATE, "test"); + TemplateUtils.validate(TemplateUtils.load(resource)); + } + + public void testFilter() { + assertTemplate(TemplateUtils.filter(new BytesArray("${monitoring.template.version}"), "0", + Pattern.quote("${monitoring.template.version}")), equalTo("0")); + assertTemplate(TemplateUtils.filter(new BytesArray("{\"template\": \"test-${monitoring.template.version}\"}"), "1", + Pattern.quote("${monitoring.template.version}")), equalTo("{\"template\": \"test-1\"}")); + assertTemplate(TemplateUtils.filter(new BytesArray("{\"template\": \"${monitoring.template.version}-test\"}"), "2", + Pattern.quote("${monitoring.template.version}")), equalTo("{\"template\": \"2-test\"}")); + assertTemplate(TemplateUtils.filter(new BytesArray("{\"template\": \"test-${monitoring.template.version}-test\"}"), "3", + Pattern.quote("${monitoring.template.version}")), equalTo("{\"template\": \"test-3-test\"}")); + + final int version = randomIntBetween(0, 100); + assertTemplate(TemplateUtils.filter(new BytesArray("{\"foo-${monitoring.template.version}\": " + + "\"bar-${monitoring.template.version}\"}"), String.valueOf(version), + Pattern.quote("${monitoring.template.version}")), + equalTo("{\"foo-" + version + "\": \"bar-" + version + "\"}")); + } + + public static void assertTemplate(String actual, Matcher matcher) { + if (Constants.WINDOWS) { + // translate Windows line endings (\r\n) to standard ones (\n) + actual = Strings.replace(actual, System.lineSeparator(), "\n"); + } + assertThat(actual, matcher); + } + + +} diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java index 0e08369d642..cc539d63b38 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java @@ -47,6 +47,7 @@ import org.elasticsearch.watcher.rest.action.RestHijackOperationAction; import org.elasticsearch.watcher.rest.action.RestPutWatchAction; import org.elasticsearch.watcher.rest.action.RestWatchServiceAction; import org.elasticsearch.watcher.rest.action.RestWatcherStatsAction; +import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry; import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.TemplateConfig; import org.elasticsearch.watcher.support.clock.ClockModule; import org.elasticsearch.watcher.support.http.HttpClient; @@ -168,7 +169,7 @@ public class Watcher { } public void onModule(SettingsModule module) { - for (TemplateConfig templateConfig : WatcherModule.TEMPLATE_CONFIGS) { + for (TemplateConfig templateConfig : WatcherIndexTemplateRegistry.TEMPLATE_CONFIGS) { module.registerSetting(templateConfig.getSetting()); } module.registerSetting(InternalSlackService.SLACK_ACCOUNT_SETTING); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java index 61aa80b6cac..2367d082912 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java @@ -6,44 +6,18 @@ package org.elasticsearch.watcher; -import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry; -import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.TemplateConfig; import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation; import org.elasticsearch.xpack.XPackPlugin; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - public class WatcherModule extends AbstractModule { - static final String PROPERTIES_FILE = "/watcher.properties"; - static final String VERSION_FIELD = "xpack.watcher.template.version"; - - public static final String HISTORY_TEMPLATE_NAME = "watch_history_" + getHistoryIndexTemplateVersion(); - public static final String TRIGGERED_TEMPLATE_NAME = "triggered_watches"; - public static final String WATCHES_TEMPLATE_NAME = "watches"; - public static final Setting HISTORY_TEMPLATE_SETTING = Setting.groupSetting("xpack.watcher.history.index.", - Setting.Property.Dynamic, Setting.Property.NodeScope); - public static final Setting TRIGGERED_TEMPLATE_SETTING = Setting.groupSetting("xpack.watcher.triggered_watches.index.", - Setting.Property.Dynamic, Setting.Property.NodeScope); - public static final Setting WATCHES_TEMPLATE_SETTING = Setting.groupSetting("xpack.watcher.watches.index.", - Setting.Property.Dynamic, Setting.Property.NodeScope); - - - public final static TemplateConfig[] TEMPLATE_CONFIGS = new TemplateConfig[]{ - new TemplateConfig(TRIGGERED_TEMPLATE_NAME, TRIGGERED_TEMPLATE_SETTING), - new TemplateConfig(HISTORY_TEMPLATE_NAME, "watch_history", HISTORY_TEMPLATE_SETTING), - new TemplateConfig(WATCHES_TEMPLATE_NAME, WATCHES_TEMPLATE_SETTING) - }; - private final boolean enabled; private final boolean transportClientMode; @@ -64,28 +38,6 @@ public class WatcherModule extends AbstractModule { bind(WatcherLicensee.class).asEagerSingleton(); bind(WatcherLifeCycleService.class).asEagerSingleton(); bind(WatcherSettingsValidation.class).asEagerSingleton(); - bind(WatcherIndexTemplateRegistry.class).asEagerSingleton(); - Multibinder multibinder - = Multibinder.newSetBinder(binder(), TemplateConfig.class); - for (TemplateConfig templateConfig : TEMPLATE_CONFIGS) { - multibinder.addBinding().toInstance(templateConfig); - } - } - - public static Integer getHistoryIndexTemplateVersion() { - try (InputStream is = WatcherModule.class.getResourceAsStream(PROPERTIES_FILE)) { - Properties properties = new Properties(); - properties.load(is); - String version = properties.getProperty(VERSION_FIELD); - if (Strings.hasLength(version)) { - return Integer.parseInt(version); - } - return null; - } catch (NumberFormatException e) { - throw new IllegalArgumentException("failed to parse watcher template version"); - } catch (IOException e) { - throw new IllegalArgumentException("failed to load watcher template version"); - } } } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java index d067c2c7c4c..12f4785812b 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.engine.VersionConflictEngineException; import org.elasticsearch.watcher.WatcherModule; import org.elasticsearch.watcher.execution.ExecutionState; +import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry; import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; @@ -31,7 +32,7 @@ import static org.elasticsearch.watcher.support.Exceptions.ioException; */ public class HistoryStore extends AbstractComponent { - public static final String INDEX_PREFIX = ".watcher-history-" + WatcherModule.getHistoryIndexTemplateVersion() + "-"; + public static final String INDEX_PREFIX = ".watcher-history-" + WatcherIndexTemplateRegistry.INDEX_TEMPLATE_VERSION + "-"; public static final String DOC_TYPE = "watch_record"; static final DateTimeFormatter indexTimeFormat = DateTimeFormat.forPattern("YYYY.MM.dd"); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistry.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistry.java index 14949ba0cb9..6a88ca174dc 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistry.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistry.java @@ -5,54 +5,69 @@ */ package org.elasticsearch.watcher.support; +import com.google.common.base.Charsets; import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest; import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse; import org.elasticsearch.cluster.ClusterChangedEvent; -import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateListener; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.io.Streams; -import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; -import org.elasticsearch.watcher.watch.WatchStore; +import org.elasticsearch.xpack.template.TemplateUtils; -import java.io.InputStream; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.concurrent.Executor; +import java.util.regex.Pattern; import static java.util.Collections.unmodifiableMap; -import static java.util.Collections.unmodifiableSet; /** */ public class WatcherIndexTemplateRegistry extends AbstractComponent implements ClusterStateListener { + private static final String FORBIDDEN_INDEX_SETTING = "index.mapper.dynamic"; + public static final String INDEX_TEMPLATE_VERSION = "1"; + + public static final String HISTORY_TEMPLATE_NAME = "watch_history_" + INDEX_TEMPLATE_VERSION; + public static final String TRIGGERED_TEMPLATE_NAME = "triggered_watches"; + public static final String WATCHES_TEMPLATE_NAME = "watches"; + + public static final Setting HISTORY_TEMPLATE_SETTING = Setting.groupSetting("xpack.watcher.history.index.", + Setting.Property.Dynamic, Setting.Property.NodeScope); + public static final Setting TRIGGERED_TEMPLATE_SETTING = Setting.groupSetting("xpack.watcher.triggered_watches.index.", + Setting.Property.Dynamic, Setting.Property.NodeScope); + public static final Setting WATCHES_TEMPLATE_SETTING = Setting.groupSetting("xpack.watcher.watches.index.", + Setting.Property.Dynamic, Setting.Property.NodeScope); + public static final TemplateConfig[] TEMPLATE_CONFIGS = new TemplateConfig[]{ + new TemplateConfig(TRIGGERED_TEMPLATE_NAME, TRIGGERED_TEMPLATE_SETTING), + new TemplateConfig(HISTORY_TEMPLATE_NAME, "watch_history", HISTORY_TEMPLATE_SETTING), + new TemplateConfig(WATCHES_TEMPLATE_NAME, WATCHES_TEMPLATE_SETTING) + }; private final WatcherClientProxy client; private final ThreadPool threadPool; private final ClusterService clusterService; - private final Set indexTemplates; + private final TemplateConfig[] indexTemplates; private volatile Map customIndexSettings; @Inject public WatcherIndexTemplateRegistry(Settings settings, ClusterSettings clusterSettings, ClusterService clusterService, - ThreadPool threadPool, WatcherClientProxy client, Set configs) { + ThreadPool threadPool, WatcherClientProxy client) { super(settings); this.client = client; this.threadPool = threadPool; this.clusterService = clusterService; - this.indexTemplates = unmodifiableSet(new HashSet<>(configs)); + this.indexTemplates = TEMPLATE_CONFIGS; clusterService.add(this); Map customIndexSettings = new HashMap<>(); @@ -150,33 +165,23 @@ public class WatcherIndexTemplateRegistry extends AbstractComponent implements C } else { executor = threadPool.generic(); } - executor.execute(new Runnable() { - @Override - public void run() { - try (InputStream is = WatchStore.class.getResourceAsStream("/" + config.getFileName()+ ".json")) { - if (is == null) { - logger.error("Resource [/{}.json] not found in classpath", config.getFileName()); - return; - } - final byte[] template; - try (BytesStreamOutput out = new BytesStreamOutput()) { - Streams.copy(is, out); - template = out.bytes().toBytes(); - } + executor.execute(() -> { + final byte[] template = TemplateUtils.loadTemplate("/" + config.getFileName()+ ".json", INDEX_TEMPLATE_VERSION, + Pattern.quote("${xpack.watcher.template.version}")).getBytes(Charsets.UTF_8); - PutIndexTemplateRequest request = new PutIndexTemplateRequest(config.getTemplateName()).source(template); - Settings customSettings = customIndexSettings.get(config.getSetting().getKey()); - if (customSettings != null && customSettings.names().size() > 0) { - Settings updatedSettings = Settings.builder() - .put(request.settings()) - .put(customSettings) - .build(); - request.settings(updatedSettings); - } - PutIndexTemplateResponse response = client.putTemplate(request); - } catch (Exception e) { - logger.error("failed to load [{}.json]", e, config.getTemplateName()); - } + PutIndexTemplateRequest request = new PutIndexTemplateRequest(config.getTemplateName()).source(template); + request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); + Settings customSettings = customIndexSettings.get(config.getSetting().getKey()); + if (customSettings != null && customSettings.names().size() > 0) { + Settings updatedSettings = Settings.builder() + .put(request.settings()) + .put(customSettings) + .build(); + request.settings(updatedSettings); + } + PutIndexTemplateResponse response = client.putTemplate(request); + if (response.isAcknowledged() == false) { + logger.error("Error adding watcher template [{}], request was not acknowledged", config.getTemplateName()); } }); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreSettingsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreSettingsTests.java index 2b2d03d67c4..6cb1031b619 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreSettingsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreSettingsTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResp import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.junit.annotations.TestLogging; -import org.elasticsearch.watcher.WatcherModule; +import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST; @@ -23,8 +23,10 @@ import static org.hamcrest.core.Is.is; @TestLogging("cluster:DEBUG,action.admin.cluster.settings:DEBUG,watcher:DEBUG") @ESIntegTestCase.ClusterScope(scope = TEST, numClientNodes = 0, transportClientRatio = 0, randomDynamicTemplates = false, numDataNodes = 1) public class HistoryStoreSettingsTests extends AbstractWatcherIntegrationTestCase { + public void testChangeSettings() throws Exception { - GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(WatcherModule.HISTORY_TEMPLATE_NAME).get(); + GetIndexTemplatesResponse response = client().admin().indices() + .prepareGetTemplates(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get(); assertThat(response.getIndexTemplates().get(0).getSettings().get("index.number_of_shards"), equalTo("1")); // this isn't defined in the template, so we rely on ES's default, which is zero assertThat(response.getIndexTemplates().get(0).getSettings().get("index.number_of_replicas"), nullValue()); @@ -44,7 +46,7 @@ public class HistoryStoreSettingsTests extends AbstractWatcherIntegrationTestCas @Override public void run() { GetIndexTemplatesResponse response = client().admin().indices() - .prepareGetTemplates(WatcherModule.HISTORY_TEMPLATE_NAME).get(); + .prepareGetTemplates(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get(); assertThat(response.getIndexTemplates().get(0).getSettings().get("index.number_of_shards"), equalTo("2")); assertThat(response.getIndexTemplates().get(0).getSettings().get("index.number_of_replicas"), equalTo("2")); assertThat(response.getIndexTemplates().get(0).getSettings().get("index.refresh_interval"), equalTo("5m")); @@ -53,7 +55,8 @@ public class HistoryStoreSettingsTests extends AbstractWatcherIntegrationTestCas } public void testChangeSettingsIgnoringForbiddenSetting() throws Exception { - GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(WatcherModule.HISTORY_TEMPLATE_NAME).get(); + GetIndexTemplatesResponse response = client().admin().indices() + .prepareGetTemplates(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get(); assertThat(response.getIndexTemplates().get(0).getSettings().get("index.number_of_shards"), equalTo("1")); assertThat(response.getIndexTemplates().get(0).getSettings().getAsBoolean("index.mapper.dynamic", null), is(false)); @@ -70,7 +73,7 @@ public class HistoryStoreSettingsTests extends AbstractWatcherIntegrationTestCas @Override public void run() { GetIndexTemplatesResponse response = client().admin().indices() - .prepareGetTemplates(WatcherModule.HISTORY_TEMPLATE_NAME).get(); + .prepareGetTemplates(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get(); assertThat(response.getIndexTemplates().get(0).getSettings().get("index.number_of_shards"), equalTo("2")); assertThat(response.getIndexTemplates().get(0).getSettings().getAsBoolean("index.mapper.dynamic", null), is(false)); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java index 4fe7bbcdfe6..2522e341f59 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java @@ -13,6 +13,7 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.WatcherModule; import org.elasticsearch.watcher.execution.ExecutionState; import org.elasticsearch.watcher.execution.Wid; +import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry; import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent; import org.joda.time.DateTime; @@ -70,7 +71,7 @@ public class HistoryStoreTests extends ESTestCase { } public void testIndexNameGeneration() { - Integer indexTemplateVersion = WatcherModule.getHistoryIndexTemplateVersion(); + String indexTemplateVersion = WatcherIndexTemplateRegistry.INDEX_TEMPLATE_VERSION; assertThat(HistoryStore.getHistoryIndexNameForTime(new DateTime(0, UTC)), equalTo(".watcher-history-"+ indexTemplateVersion +"-1970.01.01")); assertThat(HistoryStore.getHistoryIndexNameForTime(new DateTime(100000000000L, UTC)), diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistryTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistryTests.java index 4adfd5d4631..bdae08dc757 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistryTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherIndexTemplateRegistryTests.java @@ -47,7 +47,7 @@ public class WatcherIndexTemplateRegistryTests extends AbstractWatcherIntegratio @Override public void run() { GetIndexTemplatesResponse response = client().admin().indices() - .prepareGetTemplates(WatcherModule.HISTORY_TEMPLATE_NAME).get(); + .prepareGetTemplates(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get(); assertThat(response.getIndexTemplates().size(), equalTo(1)); // setting from the file on the classpath: assertThat(response.getIndexTemplates().get(0).getSettings().getAsBoolean("index.mapper.dynamic", null), is(false)); @@ -57,13 +57,13 @@ public class WatcherIndexTemplateRegistryTests extends AbstractWatcherIntegratio }); // Now delete the index template and verify the index template gets added back: - assertAcked(client().admin().indices().prepareDeleteTemplate(WatcherModule.HISTORY_TEMPLATE_NAME).get()); + assertAcked(client().admin().indices().prepareDeleteTemplate(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get()); assertBusy(new Runnable() { @Override public void run() { GetIndexTemplatesResponse response = client().admin().indices() - .prepareGetTemplates(WatcherModule.HISTORY_TEMPLATE_NAME).get(); + .prepareGetTemplates(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get(); assertThat(response.getIndexTemplates().size(), equalTo(1)); // setting from the file on the classpath: assertThat(response.getIndexTemplates().get(0).getSettings().getAsBoolean("index.mapper.dynamic", null), is(false)); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java index 9dd18ae6566..c57ac04e35d 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -27,8 +27,8 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockMustacheScriptEngine; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.shield.authc.file.FileRealm; import org.elasticsearch.shield.Security; +import org.elasticsearch.shield.authc.file.FileRealm; import org.elasticsearch.shield.authc.support.Hasher; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.authz.store.FileRolesStore; @@ -40,7 +40,6 @@ import org.elasticsearch.test.store.MockFSIndexStore; import org.elasticsearch.test.transport.AssertingLocalTransport; import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.watcher.WatcherLifeCycleService; -import org.elasticsearch.watcher.WatcherModule; import org.elasticsearch.watcher.WatcherService; import org.elasticsearch.watcher.WatcherState; import org.elasticsearch.watcher.actions.email.service.Authentication; @@ -91,9 +90,9 @@ import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; -import static org.elasticsearch.watcher.WatcherModule.HISTORY_TEMPLATE_NAME; -import static org.elasticsearch.watcher.WatcherModule.TRIGGERED_TEMPLATE_NAME; -import static org.elasticsearch.watcher.WatcherModule.WATCHES_TEMPLATE_NAME; +import static org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME; +import static org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.TRIGGERED_TEMPLATE_NAME; +import static org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.WATCHES_TEMPLATE_NAME; import static org.hamcrest.Matchers.emptyArray; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -143,7 +142,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase @Override protected Set excludeTemplates() { Set excludes = new HashSet<>(); - for (WatcherIndexTemplateRegistry.TemplateConfig templateConfig : WatcherModule.TEMPLATE_CONFIGS) { + for (WatcherIndexTemplateRegistry.TemplateConfig templateConfig : WatcherIndexTemplateRegistry.TEMPLATE_CONFIGS) { excludes.add(templateConfig.getTemplateName()); } return excludes; From 276d5fbbcabb0da3fc8d64bcdd2f1b666f211347 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Fri, 22 Apr 2016 09:45:46 +0200 Subject: [PATCH 19/23] Watcher: Updated dependencies (elastic/elasticsearch#2064) Updated okhttp and moved the jsr305 dependency into testing. This required a minor change in tests using SSL, as otherwise the security manager barfs, when the okhttp webserver tries to load sun internal SSL based classes. Original commit: elastic/x-pack-elasticsearch@77131589e081bf7136a0f411661ac7b37cfc19d7 --- elasticsearch/x-pack/build.gradle | 9 +++++---- .../actions/webhook/WebhookHttpsIntegrationTests.java | 1 + .../watcher/support/http/HttpClientTests.java | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/elasticsearch/x-pack/build.gradle b/elasticsearch/x-pack/build.gradle index e64aac614c9..7dc0fb61399 100644 --- a/elasticsearch/x-pack/build.gradle +++ b/elasticsearch/x-pack/build.gradle @@ -11,7 +11,7 @@ esplugin { } ext.versions = [ - okhttp: '2.3.0' + okhttp: '2.7.5' ] // TODO: fix this! https://github.com/elastic/x-plugins/issues/1066 @@ -32,9 +32,10 @@ dependencies { // watcher deps compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:r239' compile 'com.google.guava:guava:16.0.1' // needed by watcher for the html sanitizer and shield tests for jimfs - compile 'com.google.code.findbugs:jsr305:3.0.1' // TODO: remove this compile 'com.sun.mail:javax.mail:1.5.3' testCompile 'org.subethamail:subethasmtp:3.1.7' + // needed for subethasmtp, has @GuardedBy annotation + testCompile 'com.google.code.findbugs:jsr305:3.0.1' // common test deps testCompile 'org.elasticsearch:securemock:1.2' @@ -45,7 +46,7 @@ dependencies { testCompile "com.squareup.okhttp:mockwebserver:${versions.okhttp}" testCompile "com.squareup.okhttp:okhttp:${versions.okhttp}" testCompile "com.squareup.okhttp:okhttp-ws:${versions.okhttp}" - testCompile 'com.squareup.okio:okio:1.3.0' + testCompile 'com.squareup.okio:okio:1.6.0' testCompile 'org.bouncycastle:bcprov-jdk15on:1.50' } @@ -201,4 +202,4 @@ modifyPom { MavenPom pom -> } } } -} \ No newline at end of file +} diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/webhook/WebhookHttpsIntegrationTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/webhook/WebhookHttpsIntegrationTests.java index 04612e4c741..d8501d0efe9 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/webhook/WebhookHttpsIntegrationTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/webhook/WebhookHttpsIntegrationTests.java @@ -60,6 +60,7 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest for (webPort = 9200; webPort < 9300; webPort++) { try { webServer = new MockWebServer(); + webServer.setProtocolNegotiationEnabled(false); QueueDispatcher dispatcher = new QueueDispatcher(); dispatcher.setFailFast(true); webServer.setDispatcher(dispatcher); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/http/HttpClientTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/http/HttpClientTests.java index 0afaf192257..83bcb26e299 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/http/HttpClientTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/http/HttpClientTests.java @@ -398,6 +398,7 @@ public class HttpClientTests extends ESTestCase { private MockWebServer startWebServer() throws IOException { try { MockWebServer mockWebServer = new MockWebServer(); + mockWebServer.setProtocolNegotiationEnabled(false); mockWebServer.start(); return mockWebServer; } catch (BindException be) { From b9515357fa158b7b82938207f58240e5336eb1ec Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 21 Apr 2016 15:16:28 +0200 Subject: [PATCH 20/23] Migrated from indexed scripts to store scripts Original commit: elastic/x-pack-elasticsearch@a0218f1c9e25c16dcefd286786a5e2ffee9f9de4 --- .../messy/tests/MessyTestUtils.java | 9 ++++++++- .../messy/tests/ScriptConditionTests.java | 4 ++-- .../elasticsearch/messy/tests/TransformIT.java | 6 +++++- .../messy/tests/SearchInputIT.java | 16 ++++++++++------ .../messy/tests/SearchTransformIT.java | 17 +++++++++++------ .../messy/tests/ShieldCachePermissionIT.java | 9 +++++---- .../smoketest/WatcherTemplateTests.java | 7 ++++++- .../org/elasticsearch/transport/actions | 6 +++--- .../elasticsearch/watcher/support/Script.java | 6 +++--- .../support/init/proxy/ScriptServiceProxy.java | 17 +++++++---------- .../watcher/support/text/TextTemplate.java | 8 ++++---- .../condition/script/ScriptConditionTests.java | 4 ++-- .../watcher/support/WatcherUtilsTests.java | 2 +- .../watcher/support/text/TextTemplateTests.java | 6 +++--- .../AbstractWatcherIntegrationTestCase.java | 3 ++- .../watcher/test/WatcherTestUtils.java | 9 ++++++++- .../test/integration/BasicWatcherTests.java | 7 +++---- .../transform/TransformIntegrationTests.java | 6 +++++- .../transform/script/ScriptTransformTests.java | 6 +++--- 19 files changed, 91 insertions(+), 57 deletions(-) diff --git a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java index 653d4b794d9..7f1510ec1a5 100644 --- a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java +++ b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java @@ -6,6 +6,9 @@ package org.elasticsearch.messy.tests; import org.apache.lucene.util.LuceneTestCase; +import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; @@ -19,6 +22,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; import org.junit.Ignore; +import org.mockito.Mockito; import java.util.Arrays; import java.util.HashSet; @@ -43,8 +47,11 @@ public final class MessyTestUtils { ); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Arrays.asList(ScriptServiceProxy.INSTANCE)); + ClusterService clusterService = Mockito.mock(ClusterService.class); + Mockito.when(clusterService.state()).thenReturn(ClusterState.builder(new ClusterName("_name")).build()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); return ScriptServiceProxy.of(new ScriptService(settings, new Environment(settings), engineServiceSet, - new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings)); + new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings), + clusterService); } } diff --git a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionTests.java b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionTests.java index b0db5da4114..556b1dc52a4 100644 --- a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionTests.java +++ b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionTests.java @@ -124,7 +124,7 @@ public class ScriptConditionTests extends ESTestCase { ScriptType scriptType = randomFrom(ScriptType.values()); String script; switch (scriptType) { - case INDEXED: + case STORED: case FILE: script = "nonExisting_script"; break; @@ -212,7 +212,7 @@ public class ScriptConditionTests extends ESTestCase { case FILE: builder.field("file", script); break; - case INDEXED: + case STORED: builder.field("id", script); break; default: diff --git a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/TransformIT.java b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/TransformIT.java index 6fc32aecf91..e48017531ec 100644 --- a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/TransformIT.java +++ b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/TransformIT.java @@ -7,6 +7,7 @@ package org.elasticsearch.messy.tests; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; @@ -77,7 +78,10 @@ public class TransformIT extends AbstractWatcherIntegrationTestCase { script = Script.inline("return [key3 : ctx.payload.key1 + ctx.payload.key2]").lang("groovy").build(); } else if (randomBoolean()) { logger.info("testing script transform with an indexed script"); - client().preparePutIndexedScript("groovy", "_id", "{\"script\" : \"return [key3 : ctx.payload.key1 + ctx.payload.key2]\"}") + client().admin().cluster().preparePutStoredScript() + .setId("_id") + .setScriptLang("groovy") + .setSource(new BytesArray("{\"script\" : \"return [key3 : ctx.payload.key1 + ctx.payload.key2]\"}")) .get(); script = Script.indexed("_id").lang("groovy").build(); } else { diff --git a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchInputIT.java b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchInputIT.java index bf916cffa67..d941ac4f802 100644 --- a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchInputIT.java +++ b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchInputIT.java @@ -5,9 +5,10 @@ */ package org.elasticsearch.messy.tests; -import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptRequest; +import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -192,14 +193,17 @@ public class SearchInputIT extends ESIntegTestCase { public void testSearchIndexedTemplate() throws Exception { WatchExecutionContext ctx = createContext(); - PutIndexedScriptRequest indexedScriptRequest = client().preparePutIndexedScript("mustache","test-template", - TEMPLATE_QUERY).request(); - assertThat(client().putIndexedScript(indexedScriptRequest).actionGet().isCreated(), is(true)); + PutStoredScriptRequest indexedScriptRequest = client().admin().cluster().preparePutStoredScript() + .setId("test-template") + .setScriptLang("mustache") + .setSource(new BytesArray(TEMPLATE_QUERY)) + .request(); + assertThat(client().admin().cluster().putStoredScript(indexedScriptRequest).actionGet().isAcknowledged(), is(true)); Map params = new HashMap<>(); params.put("seconds_param", "30s"); - Template template = new Template("test-template", ScriptType.INDEXED, null, null, params); + Template template = new Template("test-template", ScriptType.STORED, null, null, params); jsonBuilder().value(TextTemplate.indexed("test-template").params(params).build()).bytes(); SearchRequest request = client().prepareSearch().setSearchType(ExecutableSearchInput.DEFAULT_SEARCH_TYPE) @@ -209,7 +213,7 @@ public class SearchInputIT extends ESIntegTestCase { Template resultTemplate = executedResult.executedRequest().template(); assertThat(resultTemplate, notNullValue()); assertThat(resultTemplate.getScript(), equalTo("test-template")); - assertThat(resultTemplate.getType(), equalTo(ScriptType.INDEXED)); + assertThat(resultTemplate.getType(), equalTo(ScriptType.STORED)); } public void testSearchOnDiskTemplate() throws Exception { diff --git a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchTransformIT.java b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchTransformIT.java index 1519bea48ab..ee5f7e57920 100644 --- a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchTransformIT.java +++ b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchTransformIT.java @@ -5,12 +5,13 @@ */ package org.elasticsearch.messy.tests; -import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptRequest; +import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.client.Requests; import org.elasticsearch.common.Base64; +import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; @@ -388,8 +389,12 @@ public class SearchTransformIT extends ESIntegTestCase { "{\"from\":\"{{ctx.trigger.scheduled_time}}||-{{seconds_param}}\",\"to\":\"{{ctx.trigger.scheduled_time}}\"," + "\"include_lower\":true,\"include_upper\":true}}}]}}}"; - PutIndexedScriptRequest indexedScriptRequest = client().preparePutIndexedScript("mustache", "test-script", templateQuery).request(); - assertThat(client().putIndexedScript(indexedScriptRequest).actionGet().isCreated(), is(true)); + PutStoredScriptRequest indexedScriptRequest = client().admin().cluster().preparePutStoredScript() + .setId("mustache") + .setScriptLang("test-script") + .setSource(new BytesArray(templateQuery)) + .request(); + assertThat(client().admin().cluster().putStoredScript(indexedScriptRequest).actionGet().isAcknowledged(), is(true)); Map params = new HashMap<>(); params.put("seconds_param", "30s"); @@ -397,7 +402,7 @@ public class SearchTransformIT extends ESIntegTestCase { BytesReference templateSource = jsonBuilder() .value(TextTemplate.indexed("test-script").params(params).build()) .bytes(); - Template template = new Template("test-script", ScriptType.INDEXED, null, null, null); + Template template = new Template("test-script", ScriptType.STORED, null, null, null); SearchRequest request = client() .prepareSearch() @@ -411,7 +416,7 @@ public class SearchTransformIT extends ESIntegTestCase { Template resultTemplate = result.executedRequest().template(); assertThat(resultTemplate, notNullValue()); assertThat(resultTemplate.getScript(), equalTo("test-script")); - assertThat(resultTemplate.getType(), equalTo(ScriptType.INDEXED)); + assertThat(resultTemplate.getType(), equalTo(ScriptType.STORED)); } public void testSearchOnDiskTemplate() throws Exception { @@ -466,7 +471,7 @@ public class SearchTransformIT extends ESIntegTestCase { new ExecutableAlwaysCondition(logger), null, null, - new ExecutableActions(new ArrayList()), + new ExecutableActions(new ArrayList<>()), null, new WatchStatus( new DateTime(40000, UTC), emptyMap())), new DateTime(60000, UTC), diff --git a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/ShieldCachePermissionIT.java b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/ShieldCachePermissionIT.java index ba3471e61c5..2266c798528 100644 --- a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/ShieldCachePermissionIT.java +++ b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/ShieldCachePermissionIT.java @@ -9,6 +9,7 @@ import org.elasticsearch.Version; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.indices.TermsLookup; import org.elasticsearch.plugins.Plugin; @@ -72,7 +73,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase { public void loadData() { index("data", "a", "1", "{ \"name\": \"John\", \"token\": \"token1\" }"); index("tokens", "tokens", "1", "{ \"group\": \"1\", \"tokens\": [\"token1\", \"token2\"] }"); - client().preparePutIndexedScript().setOpType(IndexRequest.OpType.CREATE).setSource("{\n" + + client().admin().cluster().preparePutStoredScript().setSource(new BytesArray("{\n" + "\"template\": {\n" + " \"query\": {\n" + " \"exists\": {\n" + @@ -80,7 +81,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase { " }\n" + " }\n" + " }\n" + - "}") + "}")) .setScriptLang("mustache") .setId("testTemplate") .execute().actionGet(); @@ -110,7 +111,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase { public void testThatScriptServiceDoesntLeakData() { SearchResponse response = client().prepareSearch("data").setTypes("a") - .setTemplate(new Template("testTemplate", ScriptService.ScriptType.INDEXED, MustacheScriptEngineService.NAME, null, + .setTemplate(new Template("testTemplate", ScriptService.ScriptType.STORED, MustacheScriptEngineService.NAME, null, Collections.singletonMap("name", "token"))) .execute().actionGet(); assertThat(response.isTimedOut(), is(false)); @@ -121,7 +122,7 @@ public class ShieldCachePermissionIT extends ShieldIntegTestCase { response = client().filterWithHeader(Collections.singletonMap("Authorization", basicAuthHeaderValue(READ_ONE_IDX_USER, new SecuredString("changeme".toCharArray())))) .prepareSearch("data").setTypes("a") - .setTemplate(new Template("testTemplate", ScriptService.ScriptType.INDEXED, MustacheScriptEngineService.NAME, null, + .setTemplate(new Template("testTemplate", ScriptService.ScriptType.STORED, MustacheScriptEngineService.NAME, null, Collections.singletonMap("name", "token"))) .execute().actionGet(); fail("search phase exception should have been thrown! response was:\n" + response.toString()); diff --git a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java index 4098ae21366..75b6b155756 100644 --- a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java +++ b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java @@ -6,6 +6,9 @@ package org.elasticsearch.smoketest; import com.fasterxml.jackson.core.io.JsonStringEncoder; +import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentType; @@ -59,7 +62,9 @@ public class WatcherTemplateTests extends ESTestCase { ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, registry); ScriptService scriptService = new ScriptService(setting, environment, engines, resourceWatcherService, scriptEngineRegistry, registry, scriptSettings); - engine = new DefaultTextTemplateEngine(Settings.EMPTY, ScriptServiceProxy.of(scriptService)); + ClusterService clusterService = Mockito.mock(ClusterService.class); + Mockito.when(clusterService.state()).thenReturn(ClusterState.builder(new ClusterName("_name")).build()); + engine = new DefaultTextTemplateEngine(Settings.EMPTY, ScriptServiceProxy.of(scriptService, clusterService)); } public void testEscaping() throws Exception { diff --git a/elasticsearch/x-pack/shield/src/test/resources/org/elasticsearch/transport/actions b/elasticsearch/x-pack/shield/src/test/resources/org/elasticsearch/transport/actions index 376da2fd067..d2d08bf1977 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/org/elasticsearch/transport/actions +++ b/elasticsearch/x-pack/shield/src/test/resources/org/elasticsearch/transport/actions @@ -62,7 +62,7 @@ indices:data/read/mpercolate indices:data/read/msearch indices:data/read/mtv indices:data/read/percolate -indices:data/read/script/get +cluster:admin/script/get indices:data/read/scroll indices:data/read/scroll/clear indices:data/read/search @@ -70,8 +70,8 @@ indices:data/read/tv indices:data/write/bulk indices:data/write/delete indices:data/write/index -indices:data/write/script/delete -indices:data/write/script/put +cluster:admin/script/delete +cluster:admin/script/put indices:data/write/update cluster:monitor/xpack/info cluster:monitor/xpack/license/get diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/Script.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/Script.java index c54facdb863..811ace3c28b 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/Script.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/Script.java @@ -94,7 +94,7 @@ public class Script implements ToXContent { builder.field(Field.FILE.getPreferredName(), script); break; default: - assert type == ScriptType.INDEXED : "script type [" + type + "] is not supported"; + assert type == ScriptType.STORED : "script type [" + type + "] is not supported"; builder.field(Field.ID.getPreferredName(), script); } if (lang != null) { @@ -141,7 +141,7 @@ public class Script implements ToXContent { token); } } else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.ID)) { - type = ScriptType.INDEXED; + type = ScriptType.STORED; if (token == XContentParser.Token.VALUE_STRING) { script = parser.text(); } else { @@ -240,7 +240,7 @@ public class Script implements ToXContent { public static class Indexed extends Builder { public Indexed(String id) { - super(id, ScriptType.INDEXED); + super(id, ScriptType.STORED); } @Override diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/ScriptServiceProxy.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/ScriptServiceProxy.java index 5da4d7c87e3..3df32ca2524 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/ScriptServiceProxy.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/ScriptServiceProxy.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.watcher.support.init.proxy; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; @@ -27,14 +28,16 @@ public class ScriptServiceProxy implements LazyInitializable { private ScriptService service; private SecurityContext securityContext; + private ClusterService clusterService; /** * Creates a proxy to the given script service (can be used for testing) */ - public static ScriptServiceProxy of(ScriptService service) { + public static ScriptServiceProxy of(ScriptService service, ClusterService clusterService) { ScriptServiceProxy proxy = new ScriptServiceProxy(); proxy.service = service; proxy.securityContext = SecurityContext.Insecure.INSTANCE; + proxy.clusterService = clusterService; return proxy; } @@ -42,16 +45,16 @@ public class ScriptServiceProxy implements LazyInitializable { public void init(Injector injector) { this.service = injector.getInstance(ScriptService.class); this.securityContext = injector.getInstance(SecurityContext.class); + this.clusterService = injector.getInstance(ClusterService.class); } public CompiledScript compile(Script script) { - return securityContext.executeAs(XPackUser.INSTANCE, () -> - compile(new org.elasticsearch.script.Script(script.script(), script.type(), script.lang(), script.params()), emptyMap())); + return compile(new org.elasticsearch.script.Script(script.script(), script.type(), script.lang(), script.params()), emptyMap()); } public CompiledScript compile(org.elasticsearch.script.Script script, Map compileParams) { return securityContext.executeAs(XPackUser.INSTANCE, () -> - service.compile(script, WatcherScriptContext.CTX, compileParams)); + service.compile(script, WatcherScriptContext.CTX, compileParams, clusterService.state())); } public ExecutableScript executable(CompiledScript compiledScript, Map vars) { @@ -59,12 +62,6 @@ public class ScriptServiceProxy implements LazyInitializable { service.executable(compiledScript, vars)); } - - public ExecutableScript executable(org.elasticsearch.script.Script script) { - return securityContext.executeAs(XPackUser.INSTANCE, () -> - service.executable(script, WatcherScriptContext.CTX, emptyMap())); - } - public static final ScriptContext.Plugin INSTANCE = new ScriptContext.Plugin("xpack", "watch"); private static class WatcherScriptContext implements ScriptContext { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/TextTemplate.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/TextTemplate.java index 37f4d3aaec2..d8159f67283 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/TextTemplate.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/TextTemplate.java @@ -99,8 +99,8 @@ public class TextTemplate implements ToXContent { case FILE: builder.field(Field.FILE.getPreferredName(), template); break; - default: // INDEXED - assert type == ScriptType.INDEXED : "template type [" + type + "] is not supported"; + default: // STORED + assert type == ScriptType.STORED : "template type [" + type + "] is not supported"; builder.field(Field.ID.getPreferredName(), template); } if (this.params != null) { @@ -145,7 +145,7 @@ public class TextTemplate implements ToXContent { currentFieldName, token); } } else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.ID)) { - type = ScriptType.INDEXED; + type = ScriptType.STORED; if (token == XContentParser.Token.VALUE_STRING) { template = parser.text(); } else { @@ -242,7 +242,7 @@ public class TextTemplate implements ToXContent { public static class Indexed extends Builder { public Indexed(String id) { - super(id, ScriptType.INDEXED); + super(id, ScriptType.STORED); } @Override diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionTests.java index daec5020dc3..2c325fb2024 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionTests.java @@ -124,7 +124,7 @@ public class ScriptConditionTests extends ESTestCase { ScriptType scriptType = randomFrom(ScriptType.values()); String script; switch (scriptType) { - case INDEXED: + case STORED: case FILE: script = "nonExisting_script"; break; @@ -212,7 +212,7 @@ public class ScriptConditionTests extends ESTestCase { case FILE: builder.field("file", script); break; - case INDEXED: + case STORED: builder.field("id", script); break; default: diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherUtilsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherUtilsTests.java index 0425e3403a5..131f08c59b6 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherUtilsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/WatcherUtilsTests.java @@ -125,7 +125,7 @@ public class WatcherUtilsTests extends ESTestCase { Template template = randomFrom( new Template(text, ScriptType.INLINE, null, null, params), new Template(text, ScriptType.FILE, null, null, params), - new Template(text, ScriptType.INDEXED, null, null, params) + new Template(text, ScriptType.STORED, null, null, params) ); expectedRequest.template(template); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java index 2731fcd8501..2185815f4cc 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java @@ -114,7 +114,7 @@ public class TextTemplateTests extends ESTestCase { case FILE: builder.field("file", template.getTemplate()); break; - case INDEXED: + case STORED: builder.field("id", template.getTemplate()); } builder.field("params", template.getParams()); @@ -173,7 +173,7 @@ public class TextTemplateTests extends ESTestCase { public void testParserInvalidMissingText() throws Exception { XContentBuilder builder = jsonBuilder().startObject() - .field("type", ScriptType.INDEXED) + .field("type", ScriptType.STORED) .startObject("params").endObject() .endObject(); BytesReference bytes = builder.bytes(); @@ -195,7 +195,7 @@ public class TextTemplateTests extends ESTestCase { switch (type) { case INLINE: return TextTemplate.inline(text); case FILE: return TextTemplate.file(text); - case INDEXED: return TextTemplate.indexed(text); + case STORED: return TextTemplate.indexed(text); default: throw illegalArgument("unsupported script type [{}]", type); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java index c57ac04e35d..03931ff18c5 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -668,7 +668,8 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase "test:\n" + // a user for the test infra. " cluster: [ 'cluster:monitor/nodes/info', 'cluster:monitor/state', 'cluster:monitor/health', 'cluster:monitor/stats'," + " 'cluster:admin/settings/update', 'cluster:admin/repository/delete', 'cluster:monitor/nodes/liveness'," + - " 'indices:admin/template/get', 'indices:admin/template/put', 'indices:admin/template/delete' ]\n" + + " 'indices:admin/template/get', 'indices:admin/template/put', 'indices:admin/template/delete'," + + " 'cluster:admin/script/put' ]\n" + " indices:\n" + " - names: '*'\n" + " privileges: [ all ]\n" + diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java index 7bd9ffef2af..4d9758c9e57 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java @@ -8,6 +8,9 @@ package org.elasticsearch.watcher.test; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -67,6 +70,7 @@ import org.elasticsearch.watcher.watch.Watch; import org.elasticsearch.watcher.watch.WatchStatus; import org.hamcrest.Matcher; import org.joda.time.DateTime; +import org.mockito.Mockito; import javax.mail.internet.AddressException; import java.io.IOException; @@ -248,8 +252,11 @@ public final class WatcherTestUtils { ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.emptyList()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); + ClusterService clusterService = Mockito.mock(ClusterService.class); + Mockito.when(clusterService.state()).thenReturn(ClusterState.builder(new ClusterName("_name")).build()); return ScriptServiceProxy.of(new ScriptService(settings, new Environment(settings), Collections.emptySet(), - new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings)); + new ResourceWatcherService(settings, tp), scriptEngineRegistry, scriptContextRegistry, scriptSettings), + clusterService); } public static SearchType getRandomSupportedSearchType() { diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/BasicWatcherTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/BasicWatcherTests.java index d97157a1da2..c6616b66132 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/BasicWatcherTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/BasicWatcherTests.java @@ -257,14 +257,13 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase { public void testConditionSearchWithIndexedTemplate() throws Exception { SearchSourceBuilder searchSourceBuilder = searchSource().query(matchQuery("level", "a")); - client().preparePutIndexedScript() + client().admin().cluster().preparePutStoredScript() .setScriptLang("mustache") .setId("my-template") - .setSource(jsonBuilder().startObject().field("template").value(searchSourceBuilder).endObject()) + .setSource(jsonBuilder().startObject().field("template").value(searchSourceBuilder).endObject().bytes()) .get(); - refresh(); - Template template = new Template("my-template", ScriptType.INDEXED, null, null, null); + Template template = new Template("my-template", ScriptType.STORED, null, null, null); SearchRequest searchRequest = newInputSearchRequest("events"); // TODO (2.0 upgrade): move back to BytesReference instead of coverting to a string searchRequest.template(template); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/TransformIntegrationTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/TransformIntegrationTests.java index f6d0a439cf8..de3344394e1 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/TransformIntegrationTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/TransformIntegrationTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.watcher.transform; import org.apache.lucene.util.LuceneTestCase.AwaitsFix; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; @@ -68,7 +69,10 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas script = Script.inline("return [key3 : ctx.payload.key1 + ctx.payload.key2]").lang("groovy").build(); } else if (randomBoolean()) { logger.info("testing script transform with an indexed script"); - client().preparePutIndexedScript("groovy", "_id", "{\"script\" : \"return [key3 : ctx.payload.key1 + ctx.payload.key2]\"}") + client().admin().cluster().preparePutStoredScript() + .setId("id") + .setScriptLang("groovy") + .setSource(new BytesArray("{\"script\" : \"return [key3 : ctx.payload.key1 + ctx.payload.key2]\"}")) .get(); script = Script.indexed("_id").lang("groovy").build(); } else { diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/script/ScriptTransformTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/script/ScriptTransformTests.java index 63585cc9c31..71b0dbc4801 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/script/ScriptTransformTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/script/ScriptTransformTests.java @@ -174,7 +174,7 @@ public class ScriptTransformTests extends ESTestCase { ScriptType scriptType = randomFrom(ScriptType.values()); String script; switch (scriptType) { - case INDEXED: + case STORED: case FILE: script = "nonExisting_script"; break; @@ -227,7 +227,7 @@ public class ScriptTransformTests extends ESTestCase { switch (type) { case INLINE: return Script.inline(script); case FILE: return Script.file(script); - case INDEXED: return Script.indexed(script); + case STORED: return Script.indexed(script); default: throw illegalArgument("unsupported script type [{}]", type); } @@ -237,7 +237,7 @@ public class ScriptTransformTests extends ESTestCase { switch (type) { case INLINE: return "inline"; case FILE: return "file"; - case INDEXED: return "id"; + case STORED: return "id"; default: throw illegalArgument("unsupported script type [{}]", type); } From 4650592150d55f09a2a1f3a69096c03a2189a85e Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 22 Apr 2016 14:02:07 +0200 Subject: [PATCH 21/23] Remove LazyInitializable from ScriptServiceProxy Closes elastic/elasticsearch#2062 Original commit: elastic/x-pack-elasticsearch@4eaf323158920bafa4a2a50f464ab7e99f1ab615 --- .../messy/tests/GroovyScriptConditionIT.java | 2 +- .../messy/tests/MessyTestUtils.java | 2 +- .../messy/tests/ScriptConditionSearchIT.java | 2 +- .../messy/tests/ScriptConditionTests.java | 3 +- .../smoketest/WatcherTemplateTests.java | 2 +- .../org/elasticsearch/watcher/Watcher.java | 3 +- .../script/ExecutableScriptCondition.java | 2 +- .../script/ScriptConditionFactory.java | 2 +- .../{init/proxy => }/ScriptServiceProxy.java | 45 ++++++++----------- .../text/DefaultTextTemplateEngine.java | 2 +- .../script/ExecutableScriptTransform.java | 2 +- .../script/ScriptTransformFactory.java | 2 +- .../watcher/watch/WatchModule.java | 2 + .../script/ScriptConditionSearchTests.java | 2 +- .../script/ScriptConditionTests.java | 3 +- .../support/text/TextTemplateTests.java | 5 +-- .../AbstractWatcherIntegrationTestCase.java | 2 +- .../watcher/test/WatcherTestUtils.java | 2 +- .../script/ScriptTransformTests.java | 2 +- .../watcher/watch/WatchTests.java | 2 +- 20 files changed, 39 insertions(+), 50 deletions(-) rename elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/{init/proxy => }/ScriptServiceProxy.java (61%) diff --git a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/GroovyScriptConditionIT.java b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/GroovyScriptConditionIT.java index 2f9facc1b49..404ae21382c 100644 --- a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/GroovyScriptConditionIT.java +++ b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/GroovyScriptConditionIT.java @@ -16,7 +16,7 @@ import org.elasticsearch.watcher.condition.script.ExecutableScriptCondition; import org.elasticsearch.watcher.condition.script.ScriptCondition; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Script; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.watcher.watch.Payload; import org.junit.AfterClass; diff --git a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java index 7f1510ec1a5..80d629674b8 100644 --- a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java +++ b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/MessyTestUtils.java @@ -20,7 +20,7 @@ import org.elasticsearch.script.ScriptSettings; import org.elasticsearch.script.groovy.GroovyScriptEngineService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.ResourceWatcherService; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.junit.Ignore; import org.mockito.Mockito; diff --git a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionSearchIT.java b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionSearchIT.java index 27ba49d2a0f..456a5ee62fb 100644 --- a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionSearchIT.java +++ b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionSearchIT.java @@ -23,7 +23,7 @@ import org.elasticsearch.watcher.condition.script.ExecutableScriptCondition; import org.elasticsearch.watcher.condition.script.ScriptCondition; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Script; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.watcher.watch.Payload; import org.junit.After; diff --git a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionTests.java b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionTests.java index 556b1dc52a4..0bbbafcfdc7 100644 --- a/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionTests.java +++ b/elasticsearch/qa/messy-test-watcher-with-groovy/src/test/java/org/elasticsearch/messy/tests/ScriptConditionTests.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.script.ScriptException; -import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.test.ESTestCase; @@ -25,7 +24,7 @@ import org.elasticsearch.watcher.condition.script.ScriptCondition; import org.elasticsearch.watcher.condition.script.ScriptConditionFactory; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Script; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.watch.Payload; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java index 75b6b155756..e6b418e7dc2 100644 --- a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java +++ b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateTests.java @@ -21,7 +21,7 @@ import org.elasticsearch.script.ScriptSettings; import org.elasticsearch.script.mustache.MustacheScriptEngineService; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.ResourceWatcherService; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.support.text.DefaultTextTemplateEngine; import org.elasticsearch.watcher.support.text.TextTemplate; import org.elasticsearch.watcher.support.text.TextTemplateEngine; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java index cc539d63b38..64fdd6cbed4 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java @@ -52,7 +52,7 @@ import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.TemplateCo import org.elasticsearch.watcher.support.clock.ClockModule; import org.elasticsearch.watcher.support.http.HttpClient; import org.elasticsearch.watcher.support.http.HttpClientModule; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.support.secret.SecretModule; import org.elasticsearch.watcher.support.secret.SecretService; @@ -240,7 +240,6 @@ public class Watcher { public void onModule(LazyInitializationModule module) { if (enabled) { module.registerLazyInitializable(WatcherClientProxy.class); - module.registerLazyInitializable(ScriptServiceProxy.class); module.registerLazyInitializable(ChainTransformFactory.class); module.registerLazyInitializable(ChainInputFactory.class); } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/condition/script/ExecutableScriptCondition.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/condition/script/ExecutableScriptCondition.java index e233e123fd8..5bac6a2ba9e 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/condition/script/ExecutableScriptCondition.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/condition/script/ExecutableScriptCondition.java @@ -11,7 +11,7 @@ import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.watcher.condition.ExecutableCondition; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Variables; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import java.util.Map; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/condition/script/ScriptConditionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/condition/script/ScriptConditionFactory.java index bd65fec884d..6173ada4a8c 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/condition/script/ScriptConditionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/condition/script/ScriptConditionFactory.java @@ -10,7 +10,7 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.condition.ConditionFactory; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/ScriptServiceProxy.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/ScriptServiceProxy.java similarity index 61% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/ScriptServiceProxy.java rename to elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/ScriptServiceProxy.java index 3df32ca2524..b9b0ae27976 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/ScriptServiceProxy.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/ScriptServiceProxy.java @@ -3,49 +3,35 @@ * 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.watcher.support.init.proxy; +package org.elasticsearch.watcher.support; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.inject.Injector; +import org.elasticsearch.common.inject.Inject; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; import org.elasticsearch.shield.SecurityContext; import org.elasticsearch.shield.user.XPackUser; -import org.elasticsearch.watcher.support.Script; -import org.elasticsearch.xpack.common.init.LazyInitializable; import java.util.Map; import static java.util.Collections.emptyMap; /** - *A lazily initialized proxy to the elasticsearch {@link ScriptService}. Inject this proxy whenever the script - * service needs to be injected to avoid circular dependencies issues. + * Wraps {@link ScriptService} but ensure that all scripts are run or compiled as {@link XPackUser}. */ -public class ScriptServiceProxy implements LazyInitializable { +public class ScriptServiceProxy { - private ScriptService service; - private SecurityContext securityContext; - private ClusterService clusterService; + private final ScriptService service; + private final SecurityContext securityContext; + private final ClusterService clusterService; - /** - * Creates a proxy to the given script service (can be used for testing) - */ - public static ScriptServiceProxy of(ScriptService service, ClusterService clusterService) { - ScriptServiceProxy proxy = new ScriptServiceProxy(); - proxy.service = service; - proxy.securityContext = SecurityContext.Insecure.INSTANCE; - proxy.clusterService = clusterService; - return proxy; - } - - @Override - public void init(Injector injector) { - this.service = injector.getInstance(ScriptService.class); - this.securityContext = injector.getInstance(SecurityContext.class); - this.clusterService = injector.getInstance(ClusterService.class); + @Inject + public ScriptServiceProxy(ScriptService service, SecurityContext securityContext, ClusterService clusterService) { + this.service = service; + this.securityContext = securityContext; + this.clusterService = clusterService; } public CompiledScript compile(Script script) { @@ -73,4 +59,11 @@ public class ScriptServiceProxy implements LazyInitializable { return INSTANCE.getKey(); } } + + /** + * Factory helper method for testing. + */ + public static ScriptServiceProxy of(ScriptService service, ClusterService clusterService) { + return new ScriptServiceProxy(service, SecurityContext.Insecure.INSTANCE, clusterService); + } } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/DefaultTextTemplateEngine.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/DefaultTextTemplateEngine.java index c079e5da222..680c6b72053 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/DefaultTextTemplateEngine.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/text/DefaultTextTemplateEngine.java @@ -13,7 +13,7 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Template; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import java.util.Collections; import java.util.HashMap; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/script/ExecutableScriptTransform.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/script/ExecutableScriptTransform.java index 3adf6f95e0a..aa8b0fbe6ee 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/script/ExecutableScriptTransform.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/script/ExecutableScriptTransform.java @@ -10,7 +10,7 @@ import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Script; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.transform.ExecutableTransform; import org.elasticsearch.watcher.watch.Payload; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/script/ScriptTransformFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/script/ScriptTransformFactory.java index 27b0d3c2cdd..18d330f5e62 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/script/ScriptTransformFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/script/ScriptTransformFactory.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.transform.TransformFactory; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchModule.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchModule.java index 0f4bdf70a2a..888e7156279 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchModule.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchModule.java @@ -7,6 +7,7 @@ package org.elasticsearch.watcher.watch; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.watcher.WatcherService; +import org.elasticsearch.watcher.support.ScriptServiceProxy; /** * @@ -19,5 +20,6 @@ public class WatchModule extends AbstractModule { bind(WatchLockService.class).asEagerSingleton(); bind(WatcherService.class).asEagerSingleton(); bind(WatchStore.class).asEagerSingleton(); + bind(ScriptServiceProxy.class).asEagerSingleton(); } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionSearchTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionSearchTests.java index 416a8c7d6f6..c7b31c95c5f 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionSearchTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionSearchTests.java @@ -20,7 +20,7 @@ import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Script; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.watcher.test.WatcherTestUtils; import org.elasticsearch.watcher.watch.Payload; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionTests.java index 2c325fb2024..eb7aaaab607 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/condition/script/ScriptConditionTests.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.script.ScriptException; -import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.test.ESTestCase; @@ -23,7 +22,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.condition.Condition; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Script; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.watch.Payload; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java index 2185815f4cc..d9fcdb65f68 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/support/text/TextTemplateTests.java @@ -17,10 +17,7 @@ import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.script.Template; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; -import org.elasticsearch.watcher.support.text.DefaultTextTemplateEngine; -import org.elasticsearch.watcher.support.text.TextTemplate; -import org.elasticsearch.watcher.support.text.TextTemplateEngine; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.junit.Before; import java.util.Collections; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java index 03931ff18c5..68a949bcb51 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -54,7 +54,7 @@ import org.elasticsearch.watcher.WatcherLicensee; import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry; import org.elasticsearch.watcher.support.clock.ClockMock; import org.elasticsearch.watcher.support.http.HttpClient; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.support.xcontent.XContentSource; import org.elasticsearch.watcher.trigger.ScheduleTriggerEngineMock; import org.elasticsearch.watcher.trigger.TriggerService; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java index 4d9758c9e57..a268c1a981c 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java @@ -54,7 +54,7 @@ import org.elasticsearch.watcher.support.http.HttpClient; import org.elasticsearch.watcher.support.http.HttpMethod; import org.elasticsearch.watcher.support.http.HttpRequestTemplate; import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.support.secret.Secret; import org.elasticsearch.watcher.support.text.TextTemplate; import org.elasticsearch.watcher.support.text.TextTemplateEngine; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/script/ScriptTransformTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/script/ScriptTransformTests.java index 71b0dbc4801..e801635ba04 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/script/ScriptTransformTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/transform/script/ScriptTransformTests.java @@ -19,7 +19,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Script; import org.elasticsearch.watcher.support.Variables; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.transform.Transform; import org.elasticsearch.watcher.watch.Payload; import org.junit.After; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java index a059b29de4e..dd26eca7ff7 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java @@ -85,7 +85,7 @@ import org.elasticsearch.watcher.support.http.HttpMethod; import org.elasticsearch.watcher.support.http.HttpRequestTemplate; import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry; import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.ScriptServiceProxy; import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.support.secret.SecretService; import org.elasticsearch.watcher.support.text.TextTemplate; From 358fa38cf6180c4fe9b9432ba95bbb19c95fbef2 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 22 Apr 2016 15:12:35 +0200 Subject: [PATCH 22/23] test: fix id, script_lang mix up Original commit: elastic/x-pack-elasticsearch@7c4a3152baf7492882f6cde7442a7bcae316411e --- .../org/elasticsearch/messy/tests/SearchTransformIT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchTransformIT.java b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchTransformIT.java index ee5f7e57920..5d66aa009dc 100644 --- a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchTransformIT.java +++ b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SearchTransformIT.java @@ -390,8 +390,8 @@ public class SearchTransformIT extends ESIntegTestCase { "\"include_lower\":true,\"include_upper\":true}}}]}}}"; PutStoredScriptRequest indexedScriptRequest = client().admin().cluster().preparePutStoredScript() - .setId("mustache") - .setScriptLang("test-script") + .setId("test-script") + .setScriptLang("mustache") .setSource(new BytesArray(templateQuery)) .request(); assertThat(client().admin().cluster().putStoredScript(indexedScriptRequest).actionGet().isAcknowledged(), is(true)); @@ -408,7 +408,7 @@ public class SearchTransformIT extends ESIntegTestCase { .prepareSearch() .setSearchType(ExecutableSearchTransform.DEFAULT_SEARCH_TYPE) .setIndices("test-search-index") -.setTemplate(template) + .setTemplate(template) .request(); SearchTransform.Result result = executeSearchTransform(request, ctx); From b47d161b9efdf4b95930e6d45b2ed6f38fa3d937 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Fri, 22 Apr 2016 15:57:34 +0200 Subject: [PATCH 23/23] X-Pack: Porting watcher notifications to xpack notifications (elastic/elasticsearch#2056) This mainly moves packages over to the x-pack directory and renames the settings from `xpack.watcher.actions.` to `xpack.notification.` Moved services include pagerduty, hipchat, slack and email. Closes elastic/elasticsearch#1998 Original commit: elastic/x-pack-elasticsearch@40c16fe123c75eabcd74f89575d1728b49265896 --- .../messy/tests/HipChatServiceIT.java | 22 +++---- .../messy/tests/PagerDutyServiceIT.java | 12 ++-- .../messy/tests/SlackServiceIT.java | 12 ++-- .../xpack/notification/email}/Account.java | 2 +- .../xpack/notification/email}/Accounts.java | 2 +- .../xpack/notification/email}/Attachment.java | 4 +- .../notification/email}/Authentication.java | 2 +- .../notification}/email/DataAttachment.java | 5 +- .../xpack/notification/email}/Email.java | 2 +- .../notification/email}/EmailService.java | 2 +- .../notification/email}/EmailTemplate.java | 2 +- .../notification/email}/HtmlSanitizer.java | 8 +-- .../xpack/notification/email}/Inline.java | 4 +- .../email}/InternalEmailService.java | 4 +- .../xpack/notification/email}/Profile.java | 2 +- .../email}/attachment/DataAttachment.java | 14 ++-- .../attachment/DataAttachmentParser.java | 9 +-- .../attachment/EmailAttachmentParser.java | 4 +- .../email}/attachment/EmailAttachments.java | 2 +- .../attachment/EmailAttachmentsParser.java | 2 +- .../HttpEmailAttachementParser.java | 4 +- .../attachment/HttpRequestAttachment.java | 2 +- .../email}/support/BodyPartSource.java | 2 +- .../notification/hipchat}/HipChatAccount.java | 2 +- .../hipchat}/HipChatAccounts.java | 4 +- .../notification/hipchat}/HipChatMessage.java | 2 +- .../notification/hipchat}/HipChatServer.java | 2 +- .../notification/hipchat}/HipChatService.java | 2 +- .../hipchat}/IntegrationAccount.java | 6 +- .../hipchat}/InternalHipChatService.java | 4 +- .../notification/hipchat}/SentMessages.java | 2 +- .../notification/hipchat}/UserAccount.java | 6 +- .../notification/hipchat}/V1Account.java | 6 +- .../pagerduty}/IncidentEvent.java | 2 +- .../pagerduty}/IncidentEventContext.java | 2 +- .../pagerduty}/IncidentEventDefaults.java | 2 +- .../pagerduty}/InternalPagerDutyService.java | 4 +- .../pagerduty}/PagerDutyAccount.java | 2 +- .../pagerduty}/PagerDutyAccounts.java | 2 +- .../pagerduty}/PagerDutyService.java | 2 +- .../notification/pagerduty}/SentEvent.java | 2 +- .../slack}/InternalSlackService.java | 4 +- .../notification/slack}/SentMessages.java | 4 +- .../notification/slack}/SlackAccount.java | 8 +-- .../notification/slack}/SlackAccounts.java | 2 +- .../notification/slack}/SlackService.java | 2 +- .../slack}/message/Attachment.java | 5 +- .../slack}/message/DynamicAttachments.java | 5 +- .../notification/slack}/message/Field.java | 6 +- .../slack}/message/MessageElement.java | 2 +- .../slack}/message/SlackMessage.java | 2 +- .../slack}/message/SlackMessageDefaults.java | 2 +- .../notification/email}/AccountTests.java | 4 +- .../notification/email}/AccountsTests.java | 2 +- .../email/DataAttachmentTests.java | 3 +- .../email/EmailSecretsIntegrationTests.java | 11 ++-- .../email}/EmailTemplateTests.java | 2 +- .../xpack/notification/email}/EmailTests.java | 2 +- .../email}/HtmlSanitizerTests.java | 8 +-- .../email}/InternalEmailServiceTests.java | 2 +- .../email}/ManualPublicSmtpServersTester.java | 64 +++++++++---------- .../attachment/DataAttachmentParserTests.java | 2 +- .../EmailAttachmentParsersTests.java | 6 +- .../HttpEmailAttachementParserTests.java | 2 +- .../email}/support/EmailServer.java | 2 +- .../hipchat}/HipChatAccountsTests.java | 2 +- .../hipchat}/HipChatMessageTests.java | 2 +- .../hipchat}/IntegrationAccountTests.java | 2 +- .../hipchat}/InternalHipChatServiceTests.java | 54 ++++++++-------- .../hipchat}/UserAccountTests.java | 2 +- .../notification/hipchat}/V1AccountTests.java | 2 +- .../IncidentEventDefaultsTests.java | 2 +- .../pagerduty}/PagerDutyAccountsTests.java | 4 +- .../slack}/SlackAccountsTests.java | 4 +- .../org/elasticsearch/watcher/Watcher.java | 31 +++++---- .../watcher/actions/ActionBuilders.java | 6 +- .../watcher/actions/WatcherActionModule.java | 26 ++++---- .../watcher/actions/email/EmailAction.java | 13 ++-- .../actions/email/EmailActionFactory.java | 6 +- .../actions/email/ExecutableEmailAction.java | 11 ++-- .../hipchat/ExecutableHipChatAction.java | 8 +-- .../actions/hipchat/HipChatAction.java | 4 +- .../actions/hipchat/HipChatActionFactory.java | 4 +- .../pagerduty/ExecutablePagerDutyAction.java | 8 +-- .../actions/pagerduty/PagerDutyAction.java | 4 +- .../pagerduty/PagerDutyActionFactory.java | 4 +- .../actions/slack/ExecutableSlackAction.java | 8 +-- .../watcher/actions/slack/SlackAction.java | 4 +- .../actions/slack/SlackActionFactory.java | 4 +- .../org/elasticsearch/watcher/WatcherF.java | 18 +++--- .../actions/email/EmailActionTests.java | 38 +++++------ .../actions/email/EmailAttachmentTests.java | 31 ++++----- .../hipchat/HipChatActionFactoryTests.java | 6 +- .../actions/hipchat/HipChatActionTests.java | 8 +-- .../actions/logging/LoggingActionTests.java | 2 +- .../PagerDutyActionFactoryTests.java | 4 +- .../pagerduty/PagerDutyActionTests.java | 12 ++-- .../slack/SlackActionFactoryTests.java | 6 +- .../actions/slack/SlackActionTests.java | 12 ++-- .../throttler/ActionThrottleTests.java | 2 +- .../actions/webhook/WebhookActionTests.java | 8 +-- .../HistoryTemplateEmailMappingsTests.java | 14 ++-- .../AbstractWatcherIntegrationTestCase.java | 10 +-- .../watcher/test/WatcherTestUtils.java | 10 +-- .../WatcherSettingsFilterTests.java | 13 ++-- .../watcher/watch/WatchTests.java | 14 ++-- .../message/SlackMessageDefaultsTests.java | 2 +- .../slack}/message/SlackMessageTests.java | 2 +- 108 files changed, 376 insertions(+), 381 deletions(-) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/Account.java (99%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/Accounts.java (97%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/Attachment.java (97%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/Authentication.java (95%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions => src/main/java/org/elasticsearch/xpack/notification}/email/DataAttachment.java (96%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/Email.java (99%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/EmailService.java (94%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/EmailTemplate.java (99%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/HtmlSanitizer.java (94%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/Inline.java (97%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/InternalEmailService.java (94%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/Profile.java (99%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/attachment/DataAttachment.java (74%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/attachment/DataAttachmentParser.java (85%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/attachment/EmailAttachmentParser.java (93%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/attachment/EmailAttachments.java (96%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/attachment/EmailAttachmentsParser.java (97%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/attachment/HttpEmailAttachementParser.java (97%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/attachment/HttpRequestAttachment.java (97%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/email/service => src/main/java/org/elasticsearch/xpack/notification/email}/support/BodyPartSource.java (94%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service => src/main/java/org/elasticsearch/xpack/notification/hipchat}/HipChatAccount.java (98%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service => src/main/java/org/elasticsearch/xpack/notification/hipchat}/HipChatAccounts.java (95%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service => src/main/java/org/elasticsearch/xpack/notification/hipchat}/HipChatMessage.java (99%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service => src/main/java/org/elasticsearch/xpack/notification/hipchat}/HipChatServer.java (96%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service => src/main/java/org/elasticsearch/xpack/notification/hipchat}/HipChatService.java (92%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service => src/main/java/org/elasticsearch/xpack/notification/hipchat}/IntegrationAccount.java (96%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service => src/main/java/org/elasticsearch/xpack/notification/hipchat}/InternalHipChatService.java (90%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service => src/main/java/org/elasticsearch/xpack/notification/hipchat}/SentMessages.java (98%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service => src/main/java/org/elasticsearch/xpack/notification/hipchat}/UserAccount.java (97%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service => src/main/java/org/elasticsearch/xpack/notification/hipchat}/V1Account.java (96%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service => src/main/java/org/elasticsearch/xpack/notification/pagerduty}/IncidentEvent.java (99%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service => src/main/java/org/elasticsearch/xpack/notification/pagerduty}/IncidentEventContext.java (99%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service => src/main/java/org/elasticsearch/xpack/notification/pagerduty}/IncidentEventDefaults.java (98%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service => src/main/java/org/elasticsearch/xpack/notification/pagerduty}/InternalPagerDutyService.java (90%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service => src/main/java/org/elasticsearch/xpack/notification/pagerduty}/PagerDutyAccount.java (97%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service => src/main/java/org/elasticsearch/xpack/notification/pagerduty}/PagerDutyAccounts.java (97%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service => src/main/java/org/elasticsearch/xpack/notification/pagerduty}/PagerDutyService.java (89%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service => src/main/java/org/elasticsearch/xpack/notification/pagerduty}/SentEvent.java (99%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service => src/main/java/org/elasticsearch/xpack/notification/slack}/InternalSlackService.java (90%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service => src/main/java/org/elasticsearch/xpack/notification/slack}/SentMessages.java (97%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service => src/main/java/org/elasticsearch/xpack/notification/slack}/SlackAccount.java (94%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service => src/main/java/org/elasticsearch/xpack/notification/slack}/SlackAccounts.java (97%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service => src/main/java/org/elasticsearch/xpack/notification/slack}/SlackService.java (92%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service => src/main/java/org/elasticsearch/xpack/notification/slack}/message/Attachment.java (99%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service => src/main/java/org/elasticsearch/xpack/notification/slack}/message/DynamicAttachments.java (95%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service => src/main/java/org/elasticsearch/xpack/notification/slack}/message/Field.java (96%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service => src/main/java/org/elasticsearch/xpack/notification/slack}/message/MessageElement.java (89%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service => src/main/java/org/elasticsearch/xpack/notification/slack}/message/SlackMessage.java (99%) rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service => src/main/java/org/elasticsearch/xpack/notification/slack}/message/SlackMessageDefaults.java (99%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/email/service => src/test/java/org/elasticsearch/xpack/notification/email}/AccountTests.java (99%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/email/service => src/test/java/org/elasticsearch/xpack/notification/email}/AccountsTests.java (98%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions => src/test/java/org/elasticsearch/xpack/notification}/email/DataAttachmentTests.java (93%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions => src/test/java/org/elasticsearch/xpack/notification}/email/EmailSecretsIntegrationTests.java (93%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/email/service => src/test/java/org/elasticsearch/xpack/notification/email}/EmailTemplateTests.java (98%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/email/service => src/test/java/org/elasticsearch/xpack/notification/email}/EmailTests.java (98%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/email/service => src/test/java/org/elasticsearch/xpack/notification/email}/HtmlSanitizerTests.java (95%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/email/service => src/test/java/org/elasticsearch/xpack/notification/email}/InternalEmailServiceTests.java (97%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/email/service => src/test/java/org/elasticsearch/xpack/notification/email}/ManualPublicSmtpServersTester.java (50%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/email/service => src/test/java/org/elasticsearch/xpack/notification/email}/attachment/DataAttachmentParserTests.java (96%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/email/service => src/test/java/org/elasticsearch/xpack/notification/email}/attachment/EmailAttachmentParsersTests.java (97%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/email/service => src/test/java/org/elasticsearch/xpack/notification/email}/attachment/HttpEmailAttachementParserTests.java (98%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/email/service => src/test/java/org/elasticsearch/xpack/notification/email}/support/EmailServer.java (98%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service => src/test/java/org/elasticsearch/xpack/notification/hipchat}/HipChatAccountsTests.java (99%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service => src/test/java/org/elasticsearch/xpack/notification/hipchat}/HipChatMessageTests.java (99%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service => src/test/java/org/elasticsearch/xpack/notification/hipchat}/IntegrationAccountTests.java (99%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service => src/test/java/org/elasticsearch/xpack/notification/hipchat}/InternalHipChatServiceTests.java (81%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service => src/test/java/org/elasticsearch/xpack/notification/hipchat}/UserAccountTests.java (99%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service => src/test/java/org/elasticsearch/xpack/notification/hipchat}/V1AccountTests.java (99%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/service => src/test/java/org/elasticsearch/xpack/notification/pagerduty}/IncidentEventDefaultsTests.java (98%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/service => src/test/java/org/elasticsearch/xpack/notification/pagerduty}/PagerDutyAccountsTests.java (97%) rename elasticsearch/x-pack/{watcher/src/test/java/org/elasticsearch/watcher/actions/slack/service => src/test/java/org/elasticsearch/xpack/notification/slack}/SlackAccountsTests.java (97%) rename elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/{watcher/actions/slack/service => xpack/notification/slack}/message/SlackMessageDefaultsTests.java (98%) rename elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/{watcher/actions/slack/service => xpack/notification/slack}/message/SlackMessageTests.java (99%) diff --git a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/HipChatServiceIT.java b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/HipChatServiceIT.java index cfd68f10af1..e7d9e2ecd46 100644 --- a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/HipChatServiceIT.java +++ b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/HipChatServiceIT.java @@ -13,10 +13,10 @@ import org.elasticsearch.script.mustache.MustachePlugin; import org.elasticsearch.test.junit.annotations.Network; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.watcher.actions.hipchat.HipChatAction; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatAccount; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatService; -import org.elasticsearch.watcher.actions.hipchat.service.SentMessages; +import org.elasticsearch.xpack.notification.hipchat.HipChatAccount; +import org.elasticsearch.xpack.notification.hipchat.HipChatMessage; +import org.elasticsearch.xpack.notification.hipchat.HipChatService; +import org.elasticsearch.xpack.notification.hipchat.SentMessages; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse; @@ -72,18 +72,18 @@ public class HipChatServiceIT extends AbstractWatcherIntegrationTestCase { .put(super.nodeSettings(nodeOrdinal)) // this is for the `test-watcher-integration` group level integration in HipChat - .put("xpack.watcher.actions.hipchat.service.account.integration_account.profile", "integration") - .put("xpack.watcher.actions.hipchat.service.account.integration_account.auth_token", + .put("xpack.notification.hipchat.service.account.integration_account.profile", "integration") + .put("xpack.notification.hipchat.service.account.integration_account.auth_token", "huuS9v7ccuOy3ZBWWWr1vt8Lqu3sQnLUE81nrLZU") - .put("xpack.watcher.actions.hipchat.service.account.integration_account.room", "test-watcher") + .put("xpack.notification.hipchat.service.account.integration_account.room", "test-watcher") // this is for the Watcher Test account in HipChat - .put("xpack.watcher.actions.hipchat.service.account.user_account.profile", "user") - .put("xpack.watcher.actions.hipchat.service.account.user_account.auth_token", "FYVx16oDH78ZW9r13wtXbcszyoyA7oX5tiMWg9X0") + .put("xpack.notification.hipchat.service.account.user_account.profile", "user") + .put("xpack.notification.hipchat.service.account.user_account.auth_token", "FYVx16oDH78ZW9r13wtXbcszyoyA7oX5tiMWg9X0") // this is for the `test-watcher-v1` notification token - .put("xpack.watcher.actions.hipchat.service.account.v1_account.profile", "v1") - .put("xpack.watcher.actions.hipchat.service.account.v1_account.auth_token", "a734baf62df618b96dda55b323fc30") + .put("xpack.notification.hipchat.service.account.v1_account.profile", "v1") + .put("xpack.notification.hipchat.service.account.v1_account.auth_token", "a734baf62df618b96dda55b323fc30") .build(); } diff --git a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/PagerDutyServiceIT.java b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/PagerDutyServiceIT.java index c4bc95f5b6f..c06cada5c70 100644 --- a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/PagerDutyServiceIT.java +++ b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/PagerDutyServiceIT.java @@ -12,11 +12,11 @@ import org.elasticsearch.script.MockMustacheScriptEngine; import org.elasticsearch.script.mustache.MustachePlugin; import org.elasticsearch.test.junit.annotations.Network; import org.elasticsearch.watcher.actions.pagerduty.PagerDutyAction; -import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEvent; -import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEventContext; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyAccount; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyService; -import org.elasticsearch.watcher.actions.pagerduty.service.SentEvent; +import org.elasticsearch.xpack.notification.pagerduty.IncidentEvent; +import org.elasticsearch.xpack.notification.pagerduty.IncidentEventContext; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; +import org.elasticsearch.xpack.notification.pagerduty.SentEvent; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse; import org.elasticsearch.watcher.watch.Payload; @@ -72,7 +72,7 @@ public class PagerDutyServiceIT extends AbstractWatcherIntegrationTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put("xpack.watcher.actions.pagerduty.service.account.test_account.service_api_key", "fc082467005d4072a914e0bb041882d0") + .put("xpack.notification.pagerduty.service.account.test_account.service_api_key", "fc082467005d4072a914e0bb041882d0") .build(); } diff --git a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SlackServiceIT.java b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SlackServiceIT.java index cd70a4434e9..1b673eb93ec 100644 --- a/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SlackServiceIT.java +++ b/elasticsearch/qa/messy-test-xpack-with-mustache/src/test/java/org/elasticsearch/messy/tests/SlackServiceIT.java @@ -12,11 +12,11 @@ import org.elasticsearch.script.MockMustacheScriptEngine; import org.elasticsearch.script.mustache.MustachePlugin; import org.elasticsearch.test.junit.annotations.Network; import org.elasticsearch.watcher.actions.slack.SlackAction; -import org.elasticsearch.watcher.actions.slack.service.SentMessages; -import org.elasticsearch.watcher.actions.slack.service.SlackAccount; -import org.elasticsearch.watcher.actions.slack.service.SlackService; -import org.elasticsearch.watcher.actions.slack.service.message.Attachment; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessage; +import org.elasticsearch.xpack.notification.slack.SentMessages; +import org.elasticsearch.xpack.notification.slack.SlackAccount; +import org.elasticsearch.xpack.notification.slack.SlackService; +import org.elasticsearch.xpack.notification.slack.message.Attachment; +import org.elasticsearch.xpack.notification.slack.message.SlackMessage; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse; @@ -71,7 +71,7 @@ public class SlackServiceIT extends AbstractWatcherIntegrationTestCase { .put(super.nodeSettings(nodeOrdinal)) // this is for the `test-watcher-integration` group level integration in HipChat - .put("xpack.watcher.actions.slack.service.account.test_account.url", + .put("xpack.notification.slack.service.account.test_account.url", "https://hooks.slack.com/services/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") .build(); } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Account.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Account.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Account.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Account.java index 5f5689219a8..8a0ff47b39a 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Account.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Account.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.SpecialPermission; import org.elasticsearch.common.logging.ESLogger; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Accounts.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Accounts.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Accounts.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Accounts.java index cde3a1923fc..bbab963e6e4 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Accounts.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Accounts.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Attachment.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Attachment.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Attachment.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Attachment.java index 428736cddda..f05a995f995 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Attachment.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Attachment.java @@ -3,14 +3,14 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.watcher.actions.email.service.support.BodyPartSource; +import org.elasticsearch.xpack.notification.email.support.BodyPartSource; import javax.activation.DataHandler; import javax.activation.DataSource; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Authentication.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Authentication.java similarity index 95% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Authentication.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Authentication.java index f2f3f9d397c..72835c675bb 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Authentication.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Authentication.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.watcher.support.secret.Secret; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/DataAttachment.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/DataAttachment.java similarity index 96% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/DataAttachment.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/DataAttachment.java index a5480eb4ee7..e90339f8083 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/DataAttachment.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/DataAttachment.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.watcher.actions.email.service.Attachment; import org.elasticsearch.watcher.watch.Payload; import java.io.IOException; @@ -60,7 +59,7 @@ public enum DataAttachment implements ToXContent { } }; - static DataAttachment DEFAULT = YAML; + public static DataAttachment DEFAULT = YAML; public abstract String contentType(); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Email.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Email.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Email.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Email.java index 737bbfa938f..2be6fc3c071 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Email.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Email.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/EmailService.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/EmailService.java similarity index 94% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/EmailService.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/EmailService.java index d8276347df6..3131cc5a8f7 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/EmailService.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/EmailService.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.common.component.LifecycleComponent; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/EmailTemplate.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/EmailTemplate.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/EmailTemplate.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/EmailTemplate.java index 5316f346f32..75c3befd0e7 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/EmailTemplate.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/EmailTemplate.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseFieldMatcher; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/HtmlSanitizer.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/HtmlSanitizer.java similarity index 94% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/HtmlSanitizer.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/HtmlSanitizer.java index c81eaa77cdc..100b2c92301 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/HtmlSanitizer.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/HtmlSanitizer.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.common.Strings; import org.elasticsearch.common.SuppressForbidden; @@ -44,9 +44,9 @@ public class HtmlSanitizer { @Inject public HtmlSanitizer(Settings settings) { - enabled = settings.getAsBoolean("xpack.watcher.actions.email.html.sanitization.enabled", true); - String[] allow = settings.getAsArray("xpack.watcher.actions.email.html.sanitization.allow", DEFAULT_ALLOWED); - String[] disallow = settings.getAsArray("xpack.watcher.actions.email.html.sanitization.disallow", Strings.EMPTY_ARRAY); + enabled = settings.getAsBoolean("xpack.notification.email.html.sanitization.enabled", true); + String[] allow = settings.getAsArray("xpack.notification.email.html.sanitization.allow", DEFAULT_ALLOWED); + String[] disallow = settings.getAsArray("xpack.notification.email.html.sanitization.disallow", Strings.EMPTY_ARRAY); policy = createCommonPolicy(allow, disallow); } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Inline.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Inline.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Inline.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Inline.java index aafdef5c774..d8043da494a 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Inline.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Inline.java @@ -3,14 +3,14 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Provider; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.watcher.actions.email.service.support.BodyPartSource; +import org.elasticsearch.xpack.notification.email.support.BodyPartSource; import javax.activation.DataHandler; import javax.activation.DataSource; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/InternalEmailService.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/InternalEmailService.java similarity index 94% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/InternalEmailService.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/InternalEmailService.java index 2d303c33087..75eefd140ff 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/InternalEmailService.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/InternalEmailService.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.component.AbstractLifecycleComponent; @@ -23,7 +23,7 @@ public class InternalEmailService extends AbstractLifecycleComponent EMAIL_ACCOUNT_SETTING = - Setting.groupSetting("xpack.watcher.actions.email.service.", Setting.Property.Dynamic, Setting.Property.NodeScope); + Setting.groupSetting("xpack.notification.email.service.", Setting.Property.Dynamic, Setting.Property.NodeScope); private volatile Accounts accounts; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Profile.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Profile.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Profile.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Profile.java index a8dacf96a32..b39ee8cb1a7 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/Profile.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Profile.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachment.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachment.java similarity index 74% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachment.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachment.java index 258723f3415..8678daae382 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachment.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachment.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service.attachment; +package org.elasticsearch.xpack.notification.email.attachment; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -13,21 +13,21 @@ import java.util.Objects; public class DataAttachment implements EmailAttachmentParser.EmailAttachment { private final String id; - private final org.elasticsearch.watcher.actions.email.DataAttachment dataAttachment; + private final org.elasticsearch.xpack.notification.email.DataAttachment dataAttachment; - public DataAttachment(String id, org.elasticsearch.watcher.actions.email.DataAttachment dataAttachment) { + public DataAttachment(String id, org.elasticsearch.xpack.notification.email.DataAttachment dataAttachment) { this.id = id; this.dataAttachment = dataAttachment; } - public org.elasticsearch.watcher.actions.email.DataAttachment getDataAttachment() { + public org.elasticsearch.xpack.notification.email.DataAttachment getDataAttachment() { return dataAttachment; } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(id).startObject(DataAttachmentParser.TYPE); - if (dataAttachment == org.elasticsearch.watcher.actions.email.DataAttachment.YAML) { + if (dataAttachment == org.elasticsearch.xpack.notification.email.DataAttachment.YAML) { builder.field("format", "yaml"); } else { builder.field("format", "json"); @@ -66,13 +66,13 @@ public class DataAttachment implements EmailAttachmentParser.EmailAttachment { public static class Builder { private String id; - private org.elasticsearch.watcher.actions.email.DataAttachment dataAttachment; + private org.elasticsearch.xpack.notification.email.DataAttachment dataAttachment; private Builder(String id) { this.id = id; } - public Builder dataAttachment(org.elasticsearch.watcher.actions.email.DataAttachment dataAttachment) { + public Builder dataAttachment(org.elasticsearch.xpack.notification.email.DataAttachment dataAttachment) { this.dataAttachment = dataAttachment; return this; } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachmentParser.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachmentParser.java similarity index 85% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachmentParser.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachmentParser.java index f6a75208504..b7866e1d411 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachmentParser.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachmentParser.java @@ -3,22 +3,22 @@ * 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.watcher.actions.email.service.attachment; +package org.elasticsearch.xpack.notification.email.attachment; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.watcher.actions.email.service.Attachment; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Variables; import org.elasticsearch.watcher.watch.Payload; +import org.elasticsearch.xpack.notification.email.Attachment; import java.io.IOException; import java.util.Map; -import static org.elasticsearch.watcher.actions.email.DataAttachment.resolve; +import static org.elasticsearch.xpack.notification.email.DataAttachment.resolve; public class DataAttachmentParser implements EmailAttachmentParser { @@ -35,7 +35,8 @@ public class DataAttachmentParser implements EmailAttachmentParser HIPCHAT_ACCOUNT_SETTING = - Setting.groupSetting("xpack.watcher.actions.hipchat.service.", Setting.Property.Dynamic, Setting.Property.NodeScope); + Setting.groupSetting("xpack.notification.hipchat.service.", Setting.Property.Dynamic, Setting.Property.NodeScope); @Inject public InternalHipChatService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/SentMessages.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/SentMessages.java similarity index 98% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/SentMessages.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/SentMessages.java index fd9b0443032..c01df2cadfc 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/SentMessages.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/SentMessages.java @@ -3,7 +3,7 @@ * 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.watcher.actions.hipchat.service; +package org.elasticsearch.xpack.notification.hipchat; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.xcontent.ToXContent; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/UserAccount.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/UserAccount.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/UserAccount.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/UserAccount.java index d18d163a172..acd32cca279 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/UserAccount.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/UserAccount.java @@ -3,7 +3,7 @@ * 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.watcher.actions.hipchat.service; +package org.elasticsearch.xpack.notification.hipchat; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ExceptionsHelper; @@ -15,8 +15,8 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.watcher.actions.hipchat.HipChatAction; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage.Color; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage.Format; +import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Color; +import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Format; import org.elasticsearch.watcher.support.http.HttpClient; import org.elasticsearch.watcher.support.http.HttpMethod; import org.elasticsearch.watcher.support.http.HttpRequest; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/V1Account.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/V1Account.java similarity index 96% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/V1Account.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/V1Account.java index 60f9509f974..9c33cd0592e 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/service/V1Account.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/V1Account.java @@ -3,7 +3,7 @@ * 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.watcher.actions.hipchat.service; +package org.elasticsearch.xpack.notification.hipchat; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ExceptionsHelper; @@ -11,8 +11,8 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.watcher.actions.hipchat.HipChatAction; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage.Color; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage.Format; +import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Color; +import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Format; import org.elasticsearch.watcher.support.http.HttpClient; import org.elasticsearch.watcher.support.http.HttpMethod; import org.elasticsearch.watcher.support.http.HttpRequest; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEvent.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEvent.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEvent.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEvent.java index 236ab301c78..222072739ed 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEvent.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEvent.java @@ -3,7 +3,7 @@ * 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.watcher.actions.pagerduty.service; +package org.elasticsearch.xpack.notification.pagerduty; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Nullable; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEventContext.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEventContext.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEventContext.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEventContext.java index 4d957525be2..4977e5e5405 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEventContext.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEventContext.java @@ -3,7 +3,7 @@ * 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.watcher.actions.pagerduty.service; +package org.elasticsearch.xpack.notification.pagerduty; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Nullable; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEventDefaults.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEventDefaults.java similarity index 98% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEventDefaults.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEventDefaults.java index b82e33d5fef..d104716141a 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEventDefaults.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEventDefaults.java @@ -3,7 +3,7 @@ * 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.watcher.actions.pagerduty.service; +package org.elasticsearch.xpack.notification.pagerduty; import org.elasticsearch.common.settings.Settings; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/InternalPagerDutyService.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/InternalPagerDutyService.java similarity index 90% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/InternalPagerDutyService.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/InternalPagerDutyService.java index 3b00cf1a49c..090fc987220 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/InternalPagerDutyService.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/InternalPagerDutyService.java @@ -3,7 +3,7 @@ * 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.watcher.actions.pagerduty.service; +package org.elasticsearch.xpack.notification.pagerduty; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; @@ -18,7 +18,7 @@ import org.elasticsearch.watcher.support.http.HttpClient; public class InternalPagerDutyService extends AbstractLifecycleComponent implements PagerDutyService { public static final Setting PAGERDUTY_ACCOUNT_SETTING = - Setting.groupSetting("xpack.watcher.actions.pagerduty.service.", Setting.Property.Dynamic, Setting.Property.NodeScope); + Setting.groupSetting("xpack.notification.pagerduty.service.", Setting.Property.Dynamic, Setting.Property.NodeScope); private final HttpClient httpClient; private volatile PagerDutyAccounts accounts; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyAccount.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccount.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyAccount.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccount.java index 205fb736e3c..50612911990 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyAccount.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccount.java @@ -3,7 +3,7 @@ * 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.watcher.actions.pagerduty.service; +package org.elasticsearch.xpack.notification.pagerduty; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyAccounts.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccounts.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyAccounts.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccounts.java index 53eafeef9a4..d1617355c39 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyAccounts.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccounts.java @@ -3,7 +3,7 @@ * 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.watcher.actions.pagerduty.service; +package org.elasticsearch.xpack.notification.pagerduty; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyService.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyService.java similarity index 89% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyService.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyService.java index 5e04e3291cc..8135fa149af 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyService.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyService.java @@ -3,7 +3,7 @@ * 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.watcher.actions.pagerduty.service; +package org.elasticsearch.xpack.notification.pagerduty; import org.elasticsearch.common.component.LifecycleComponent; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/SentEvent.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/SentEvent.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/SentEvent.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/SentEvent.java index 0e4e8fe9868..b8dd2857c50 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/service/SentEvent.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/SentEvent.java @@ -3,7 +3,7 @@ * 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.watcher.actions.pagerduty.service; +package org.elasticsearch.xpack.notification.pagerduty; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Nullable; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/InternalSlackService.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/InternalSlackService.java similarity index 90% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/InternalSlackService.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/InternalSlackService.java index 636a5f43c65..bee52adda74 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/InternalSlackService.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/InternalSlackService.java @@ -3,7 +3,7 @@ * 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.watcher.actions.slack.service; +package org.elasticsearch.xpack.notification.slack; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; @@ -19,7 +19,7 @@ public class InternalSlackService extends AbstractLifecycleComponent SLACK_ACCOUNT_SETTING = - Setting.groupSetting("xpack.watcher.actions.slack.service.", Setting.Property.Dynamic, Setting.Property.NodeScope); + Setting.groupSetting("xpack.notification.slack.service.", Setting.Property.Dynamic, Setting.Property.NodeScope); private volatile SlackAccounts accounts; @Inject diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SentMessages.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SentMessages.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SentMessages.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SentMessages.java index 154ac268508..2efa2030ee9 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SentMessages.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SentMessages.java @@ -3,14 +3,14 @@ * 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.watcher.actions.slack.service; +package org.elasticsearch.xpack.notification.slack; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessage; import org.elasticsearch.watcher.support.http.HttpRequest; import org.elasticsearch.watcher.support.http.HttpResponse; +import org.elasticsearch.xpack.notification.slack.message.SlackMessage; import java.io.IOException; import java.util.Collections; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SlackAccount.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackAccount.java similarity index 94% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SlackAccount.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackAccount.java index 89facc9f579..af6de3b1524 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SlackAccount.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackAccount.java @@ -3,7 +3,7 @@ * 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.watcher.actions.slack.service; +package org.elasticsearch.xpack.notification.slack; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.logging.ESLogger; @@ -11,13 +11,13 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.watcher.actions.slack.service.message.Attachment; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessage; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessageDefaults; import org.elasticsearch.watcher.support.http.HttpClient; import org.elasticsearch.watcher.support.http.HttpRequest; import org.elasticsearch.watcher.support.http.HttpResponse; import org.elasticsearch.watcher.support.http.Scheme; +import org.elasticsearch.xpack.notification.slack.message.Attachment; +import org.elasticsearch.xpack.notification.slack.message.SlackMessage; +import org.elasticsearch.xpack.notification.slack.message.SlackMessageDefaults; import java.io.IOException; import java.net.URI; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SlackAccounts.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackAccounts.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SlackAccounts.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackAccounts.java index 0db9e27a059..36d4cd29fd0 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SlackAccounts.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackAccounts.java @@ -3,7 +3,7 @@ * 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.watcher.actions.slack.service; +package org.elasticsearch.xpack.notification.slack; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SlackService.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackService.java similarity index 92% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SlackService.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackService.java index 908fa3f808e..65983272af7 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/SlackService.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackService.java @@ -3,7 +3,7 @@ * 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.watcher.actions.slack.service; +package org.elasticsearch.xpack.notification.slack; import org.elasticsearch.common.component.LifecycleComponent; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/Attachment.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/Attachment.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/Attachment.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/Attachment.java index 1819aade405..599ffadf160 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/Attachment.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/Attachment.java @@ -3,7 +3,7 @@ * 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.watcher.actions.slack.service.message; +package org.elasticsearch.xpack.notification.slack.message; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; @@ -11,7 +11,6 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessageDefaults.AttachmentDefaults; import org.elasticsearch.watcher.support.text.TextTemplate; import org.elasticsearch.watcher.support.text.TextTemplateEngine; @@ -180,7 +179,7 @@ public class Attachment implements MessageElement { this.thumbUrl = thumbUrl; } - public Attachment render(TextTemplateEngine engine, Map model, AttachmentDefaults defaults) { + public Attachment render(TextTemplateEngine engine, Map model, SlackMessageDefaults.AttachmentDefaults defaults) { String fallback = this.fallback != null ? engine.render(this.fallback, model) : defaults.fallback; String color = this.color != null ? engine.render(this.color, model) : defaults.color; String pretext = this.pretext != null ? engine.render(this.pretext, model) : defaults.pretext; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/DynamicAttachments.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/DynamicAttachments.java similarity index 95% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/DynamicAttachments.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/DynamicAttachments.java index 5bd98260b2d..7928be571e0 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/DynamicAttachments.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/DynamicAttachments.java @@ -3,14 +3,13 @@ * 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.watcher.actions.slack.service.message; +package org.elasticsearch.xpack.notification.slack.message; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessageDefaults.AttachmentDefaults; import org.elasticsearch.watcher.support.text.TextTemplateEngine; import org.elasticsearch.watcher.support.xcontent.ObjectPath; @@ -32,7 +31,7 @@ public class DynamicAttachments implements MessageElement { this.attachment = attachment; } - public List render(TextTemplateEngine engine, Map model, AttachmentDefaults defaults) { + public List render(TextTemplateEngine engine, Map model, SlackMessageDefaults.AttachmentDefaults defaults) { Object value = ObjectPath.eval(listPath, model); if (!(value instanceof Iterable)) { throw new IllegalArgumentException("dynamic attachment could not be resolved. expected context [" + listPath + "] to be a " + diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/Field.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/Field.java similarity index 96% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/Field.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/Field.java index a0f8fdcf473..298acfc7d08 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/Field.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/Field.java @@ -3,7 +3,7 @@ * 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.watcher.actions.slack.service.message; +package org.elasticsearch.xpack.notification.slack.message; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; @@ -11,7 +11,6 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessageDefaults.AttachmentDefaults.FieldDefaults; import org.elasticsearch.watcher.support.text.TextTemplate; import org.elasticsearch.watcher.support.text.TextTemplateEngine; @@ -74,7 +73,8 @@ class Field implements MessageElement { this.isShort = isShort; } - public Field render(TextTemplateEngine engine, Map model, FieldDefaults defaults) { + public Field render(TextTemplateEngine engine, Map model, + SlackMessageDefaults.AttachmentDefaults.FieldDefaults defaults) { String title = this.title != null ? engine.render(this.title, model) : defaults.title; String value = this.value != null ? engine.render(this.value, model) : defaults.value; Boolean isShort = this.isShort != null ? this.isShort : defaults.isShort; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/MessageElement.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/MessageElement.java similarity index 89% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/MessageElement.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/MessageElement.java index 9396a8cb3e4..bf58e9b0e36 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/MessageElement.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/MessageElement.java @@ -3,7 +3,7 @@ * 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.watcher.actions.slack.service.message; +package org.elasticsearch.xpack.notification.slack.message; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.ToXContent; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessage.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/SlackMessage.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessage.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/SlackMessage.java index f718f37138e..19c81210f3c 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessage.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/SlackMessage.java @@ -3,7 +3,7 @@ * 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.watcher.actions.slack.service.message; +package org.elasticsearch.xpack.notification.slack.message; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessageDefaults.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageDefaults.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessageDefaults.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageDefaults.java index 7a2ae1055cc..6a78019d623 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessageDefaults.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageDefaults.java @@ -3,7 +3,7 @@ * 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.watcher.actions.slack.service.message; +package org.elasticsearch.xpack.notification.slack.message; import org.elasticsearch.common.settings.Settings; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/AccountTests.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/AccountTests.java index aa8be553f33..30bd05cdc4f 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/AccountTests.java @@ -3,13 +3,13 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.actions.email.service.support.EmailServer; +import org.elasticsearch.xpack.notification.email.support.EmailServer; import org.elasticsearch.watcher.support.secret.Secret; import org.elasticsearch.watcher.support.secret.SecretService; import org.junit.After; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountsTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/AccountsTests.java similarity index 98% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountsTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/AccountsTests.java index 7f857404f86..5be57c0ae5a 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountsTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/AccountsTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/DataAttachmentTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/DataAttachmentTests.java similarity index 93% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/DataAttachmentTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/DataAttachmentTests.java index 746c8389add..a55c0e25c5f 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/DataAttachmentTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/DataAttachmentTests.java @@ -3,11 +3,10 @@ * 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.watcher.actions.email; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.common.io.Streams; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.actions.email.service.Attachment; import java.io.InputStream; import java.io.InputStreamReader; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/EmailSecretsIntegrationTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/EmailSecretsIntegrationTests.java similarity index 93% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/EmailSecretsIntegrationTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/EmailSecretsIntegrationTests.java index 0b9d47c83b8..9c6306916e2 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/EmailSecretsIntegrationTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/EmailSecretsIntegrationTests.java @@ -3,13 +3,11 @@ * 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.watcher.actions.email; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.support.XContentMapValues; -import org.elasticsearch.watcher.actions.email.service.EmailTemplate; -import org.elasticsearch.watcher.actions.email.service.support.EmailServer; import org.elasticsearch.watcher.client.WatcherClient; import org.elasticsearch.watcher.execution.ActionExecutionMode; import org.elasticsearch.watcher.support.secret.SecretService; @@ -20,6 +18,7 @@ import org.elasticsearch.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.watcher.trigger.TriggerEvent; import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent; import org.elasticsearch.watcher.watch.WatchStore; +import org.elasticsearch.xpack.notification.email.support.EmailServer; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.junit.After; @@ -67,9 +66,9 @@ public class EmailSecretsIntegrationTests extends AbstractWatcherIntegrationTest } return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put("xpack.watcher.actions.email.service.account.test.smtp.auth", true) - .put("xpack.watcher.actions.email.service.account.test.smtp.port", server.port()) - .put("xpack.watcher.actions.email.service.account.test.smtp.host", "localhost") + .put("xpack.notification.email.service.account.test.smtp.auth", true) + .put("xpack.notification.email.service.account.test.smtp.port", server.port()) + .put("xpack.notification.email.service.account.test.smtp.host", "localhost") .put("xpack.watcher.shield.encrypt_sensitive_data", encryptSensitiveData) .build(); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTemplateTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/EmailTemplateTests.java similarity index 98% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTemplateTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/EmailTemplateTests.java index 20c0e488b64..ff8ac258434 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTemplateTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/EmailTemplateTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/EmailTests.java similarity index 98% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/EmailTests.java index 2a7c14644b6..f5ce6fb7dab 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/EmailTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/HtmlSanitizerTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/HtmlSanitizerTests.java similarity index 95% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/HtmlSanitizerTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/HtmlSanitizerTests.java index 0aa7a287424..ac5d1c561c3 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/HtmlSanitizerTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/HtmlSanitizerTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; @@ -123,7 +123,7 @@ public class HtmlSanitizerTests extends ESTestCase { public void testCustomDisabled() { String html = "This is a bad image"; HtmlSanitizer sanitizer = new HtmlSanitizer(Settings.builder() - .put("xpack.watcher.actions.email.html.sanitization.enabled", false) + .put("xpack.notification.email.html.sanitization.enabled", false) .build()); String sanitizedHtml = sanitizer.sanitize(html); assertThat(sanitizedHtml, equalTo(html)); @@ -132,7 +132,7 @@ public class HtmlSanitizerTests extends ESTestCase { public void testCustomAllImageAllowed() { String html = "This is a bad image"; HtmlSanitizer sanitizer = new HtmlSanitizer(Settings.builder() - .put("xpack.watcher.actions.email.html.sanitization.allow", "img:all") + .put("xpack.notification.email.html.sanitization.allow", "img:all") .build()); String sanitizedHtml = sanitizer.sanitize(html); assertThat(sanitizedHtml, equalTo(html)); @@ -141,7 +141,7 @@ public class HtmlSanitizerTests extends ESTestCase { public void testCustomTablesDisallowed() { String html = "
      cell1cell2
      "; HtmlSanitizer sanitizer = new HtmlSanitizer(Settings.builder() - .put("xpack.watcher.actions.email.html.sanitization.disallow", "_tables") + .put("xpack.notification.email.html.sanitization.disallow", "_tables") .build()); String sanitizedHtml = sanitizer.sanitize(html); assertThat(sanitizedHtml, equalTo("cell1cell2")); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/InternalEmailServiceTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/InternalEmailServiceTests.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/InternalEmailServiceTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/InternalEmailServiceTests.java index 8fedd733cf9..c5836897853 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/InternalEmailServiceTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/InternalEmailServiceTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.ClusterSettings; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/ManualPublicSmtpServersTester.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/ManualPublicSmtpServersTester.java similarity index 50% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/ManualPublicSmtpServersTester.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/ManualPublicSmtpServersTester.java index e11407bca6e..59e134242c6 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/ManualPublicSmtpServersTester.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/ManualPublicSmtpServersTester.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service; +package org.elasticsearch.xpack.notification.email; import org.apache.lucene.util.LuceneTestCase.AwaitsFix; import org.elasticsearch.cli.Terminal; @@ -26,13 +26,13 @@ public class ManualPublicSmtpServersTester { public static void main(String[] args) throws Exception { test(Profile.GMAIL, Settings.builder() - .put("xpack.watcher.actions.email.service.account.gmail.smtp.auth", true) - .put("xpack.watcher.actions.email.service.account.gmail.smtp.starttls.enable", true) - .put("xpack.watcher.actions.email.service.account.gmail.smtp.host", "smtp.gmail.com") - .put("xpack.watcher.actions.email.service.account.gmail.smtp.port", 587) - .put("xpack.watcher.actions.email.service.account.gmail.smtp.user", terminal.readText("username: ")) - .put("xpack.watcher.actions.email.service.account.gmail.smtp.password", new String(terminal.readSecret("password: "))) - .put("xpack.watcher.actions.email.service.account.gmail.email_defaults.to", terminal.readText("to: ")) + .put("xpack.notification.email.service.account.gmail.smtp.auth", true) + .put("xpack.notification.email.service.account.gmail.smtp.starttls.enable", true) + .put("xpack.notification.email.service.account.gmail.smtp.host", "smtp.gmail.com") + .put("xpack.notification.email.service.account.gmail.smtp.port", 587) + .put("xpack.notification.email.service.account.gmail.smtp.user", terminal.readText("username: ")) + .put("xpack.notification.email.service.account.gmail.smtp.password", new String(terminal.readSecret("password: "))) + .put("xpack.notification.email.service.account.gmail.email_defaults.to", terminal.readText("to: ")) ); } } @@ -41,13 +41,13 @@ public class ManualPublicSmtpServersTester { public static void main(String[] args) throws Exception { test(Profile.STANDARD, Settings.builder() - .put("xpack.watcher.actions.email.service.account.outlook.smtp.auth", true) - .put("xpack.watcher.actions.email.service.account.outlook.smtp.starttls.enable", true) - .put("xpack.watcher.actions.email.service.account.outlook.smtp.host", "smtp-mail.outlook.com") - .put("xpack.watcher.actions.email.service.account.outlook.smtp.port", 587) - .put("xpack.watcher.actions.email.service.account.outlook.smtp.user", "elastic.user@outlook.com") - .put("xpack.watcher.actions.email.service.account.outlook.smtp.password", "fantastic42") - .put("xpack.watcher.actions.email.service.account.outlook.email_defaults.to", "elastic.user@outlook.com") + .put("xpack.notification.email.service.account.outlook.smtp.auth", true) + .put("xpack.notification.email.service.account.outlook.smtp.starttls.enable", true) + .put("xpack.notification.email.service.account.outlook.smtp.host", "smtp-mail.outlook.com") + .put("xpack.notification.email.service.account.outlook.smtp.port", 587) + .put("xpack.notification.email.service.account.outlook.smtp.user", "elastic.user@outlook.com") + .put("xpack.notification.email.service.account.outlook.smtp.password", "fantastic42") + .put("xpack.notification.email.service.account.outlook.email_defaults.to", "elastic.user@outlook.com") .put() ); } @@ -57,15 +57,15 @@ public class ManualPublicSmtpServersTester { public static void main(String[] args) throws Exception { test(Profile.STANDARD, Settings.builder() - .put("xpack.watcher.actions.email.service.account.yahoo.smtp.starttls.enable", true) - .put("xpack.watcher.actions.email.service.account.yahoo.smtp.auth", true) - .put("xpack.watcher.actions.email.service.account.yahoo.smtp.host", "smtp.mail.yahoo.com") - .put("xpack.watcher.actions.email.service.account.yahoo.smtp.port", 587) - .put("xpack.watcher.actions.email.service.account.yahoo.smtp.user", "elastic.user@yahoo.com") - .put("xpack.watcher.actions.email.service.account.yahoo.smtp.password", "fantastic42") + .put("xpack.notification.email.service.account.yahoo.smtp.starttls.enable", true) + .put("xpack.notification.email.service.account.yahoo.smtp.auth", true) + .put("xpack.notification.email.service.account.yahoo.smtp.host", "smtp.mail.yahoo.com") + .put("xpack.notification.email.service.account.yahoo.smtp.port", 587) + .put("xpack.notification.email.service.account.yahoo.smtp.user", "elastic.user@yahoo.com") + .put("xpack.notification.email.service.account.yahoo.smtp.password", "fantastic42") // note: from must be set to the same authenticated user account - .put("xpack.watcher.actions.email.service.account.yahoo.email_defaults.from", "elastic.user@yahoo.com") - .put("xpack.watcher.actions.email.service.account.yahoo.email_defaults.to", "elastic.user@yahoo.com") + .put("xpack.notification.email.service.account.yahoo.email_defaults.from", "elastic.user@yahoo.com") + .put("xpack.notification.email.service.account.yahoo.email_defaults.to", "elastic.user@yahoo.com") ); } } @@ -75,15 +75,15 @@ public class ManualPublicSmtpServersTester { public static void main(String[] args) throws Exception { test(Profile.STANDARD, Settings.builder() - .put("xpack.watcher.actions.email.service.account.ses.smtp.auth", true) - .put("xpack.watcher.actions.email.service.account.ses.smtp.starttls.enable", true) - .put("xpack.watcher.actions.email.service.account.ses.smtp.starttls.required", true) - .put("xpack.watcher.actions.email.service.account.ses.smtp.host", "email-smtp.us-east-1.amazonaws.com") - .put("xpack.watcher.actions.email.service.account.ses.smtp.port", 587) - .put("xpack.watcher.actions.email.service.account.ses.smtp.user", terminal.readText("user: ")) - .put("xpack.watcher.actions.email.service.account.ses.email_defaults.from", "dummy.user@elasticsearch.com") - .put("xpack.watcher.actions.email.service.account.ses.email_defaults.to", terminal.readText("to: ")) - .put("xpack.watcher.actions.email.service.account.ses.smtp.password", + .put("xpack.notification.email.service.account.ses.smtp.auth", true) + .put("xpack.notification.email.service.account.ses.smtp.starttls.enable", true) + .put("xpack.notification.email.service.account.ses.smtp.starttls.required", true) + .put("xpack.notification.email.service.account.ses.smtp.host", "email-smtp.us-east-1.amazonaws.com") + .put("xpack.notification.email.service.account.ses.smtp.port", 587) + .put("xpack.notification.email.service.account.ses.smtp.user", terminal.readText("user: ")) + .put("xpack.notification.email.service.account.ses.email_defaults.from", "dummy.user@elasticsearch.com") + .put("xpack.notification.email.service.account.ses.email_defaults.to", terminal.readText("to: ")) + .put("xpack.notification.email.service.account.ses.smtp.password", new String(terminal.readSecret("password: "))) ); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachmentParserTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachmentParserTests.java similarity index 96% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachmentParserTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachmentParserTests.java index 7cf3ecd5e80..bc7d2ce1780 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachmentParserTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachmentParserTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service.attachment; +package org.elasticsearch.xpack.notification.email.attachment; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentParsersTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentParsersTests.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentParsersTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentParsersTests.java index f9d572f438f..2d751fefa77 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentParsersTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentParsersTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service.attachment; +package org.elasticsearch.xpack.notification.email.attachment; import com.google.common.base.Charsets; import org.elasticsearch.ElasticsearchParseException; @@ -13,11 +13,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.actions.email.service.Attachment; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.http.HttpRequestTemplate; import org.elasticsearch.watcher.support.http.Scheme; import org.elasticsearch.watcher.watch.Payload; +import org.elasticsearch.xpack.notification.email.Attachment; import java.io.IOException; import java.util.ArrayList; @@ -90,7 +90,7 @@ public class EmailAttachmentParsersTests extends ESTestCase { public void testThatToXContentSerializationWorks() throws Exception { List attachments = new ArrayList<>(); - attachments.add(new DataAttachment("my-name.json", org.elasticsearch.watcher.actions.email.DataAttachment.JSON)); + attachments.add(new DataAttachment("my-name.json", org.elasticsearch.xpack.notification.email.DataAttachment.JSON)); HttpRequestTemplate requestTemplate = HttpRequestTemplate.builder("localhost", 80).scheme(Scheme.HTTP).path("/").build(); HttpRequestAttachment httpRequestAttachment = new HttpRequestAttachment("other-id", requestTemplate, null); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/HttpEmailAttachementParserTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/attachment/HttpEmailAttachementParserTests.java similarity index 98% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/HttpEmailAttachementParserTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/attachment/HttpEmailAttachementParserTests.java index 1d41d3e3060..96db0438cd9 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/HttpEmailAttachementParserTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/attachment/HttpEmailAttachementParserTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service.attachment; +package org.elasticsearch.xpack.notification.email.attachment; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/support/EmailServer.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/support/EmailServer.java similarity index 98% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/support/EmailServer.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/support/EmailServer.java index f8379a6ec31..6179d98cb12 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/support/EmailServer.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/email/support/EmailServer.java @@ -3,7 +3,7 @@ * 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.watcher.actions.email.service.support; +package org.elasticsearch.xpack.notification.email.support; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.logging.ESLogger; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/HipChatAccountsTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/HipChatAccountsTests.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/HipChatAccountsTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/HipChatAccountsTests.java index 544ada45fb3..529a9172d45 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/HipChatAccountsTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/HipChatAccountsTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.hipchat.service; +package org.elasticsearch.xpack.notification.hipchat; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/HipChatMessageTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/HipChatMessageTests.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/HipChatMessageTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/HipChatMessageTests.java index 43c0eb451f2..816d1d4bb30 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/HipChatMessageTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/HipChatMessageTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.hipchat.service; +package org.elasticsearch.xpack.notification.hipchat; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.ToXContent; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/IntegrationAccountTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/IntegrationAccountTests.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/IntegrationAccountTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/IntegrationAccountTests.java index 360c15c00bb..9d722187ca7 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/IntegrationAccountTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/IntegrationAccountTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.hipchat.service; +package org.elasticsearch.xpack.notification.hipchat; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/InternalHipChatServiceTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/InternalHipChatServiceTests.java similarity index 81% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/InternalHipChatServiceTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/InternalHipChatServiceTests.java index 0ee030090b6..79d9b932628 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/InternalHipChatServiceTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/InternalHipChatServiceTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.hipchat.service; +package org.elasticsearch.xpack.notification.hipchat; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; @@ -22,8 +22,6 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * @@ -46,13 +44,13 @@ public class InternalHipChatServiceTests extends ESTestCase { HipChatMessage.Format defaultFormat = randomBoolean() ? null : randomFrom(HipChatMessage.Format.values()); Boolean defaultNotify = randomBoolean() ? null : (Boolean) randomBoolean(); Settings.Builder settingsBuilder = Settings.builder() - .put("xpack.watcher.actions.hipchat.service.account." + accountName + ".profile", HipChatAccount.Profile.V1.value()) - .put("xpack.watcher.actions.hipchat.service.account." + accountName + ".auth_token", "_token"); + .put("xpack.notification.hipchat.service.account." + accountName + ".profile", HipChatAccount.Profile.V1.value()) + .put("xpack.notification.hipchat.service.account." + accountName + ".auth_token", "_token"); if (host != null) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + accountName + ".host", host); + settingsBuilder.put("xpack.notification.hipchat.service.account." + accountName + ".host", host); } if (port > 0) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + accountName + ".port", port); + settingsBuilder.put("xpack.notification.hipchat.service.account." + accountName + ".port", port); } buildMessageDefaults(accountName, settingsBuilder, defaultRoom, null, defaultFrom, defaultColor, defaultFormat, defaultNotify); InternalHipChatService service = new InternalHipChatService(settingsBuilder.build(), httpClient, @@ -93,15 +91,15 @@ public class InternalHipChatServiceTests extends ESTestCase { HipChatMessage.Format defaultFormat = randomBoolean() ? null : randomFrom(HipChatMessage.Format.values()); Boolean defaultNotify = randomBoolean() ? null : (Boolean) randomBoolean(); Settings.Builder settingsBuilder = Settings.builder() - .put("xpack.watcher.actions.hipchat.service.account." + accountName + ".profile", + .put("xpack.notification.hipchat.service.account." + accountName + ".profile", HipChatAccount.Profile.INTEGRATION.value()) - .put("xpack.watcher.actions.hipchat.service.account." + accountName + ".auth_token", "_token") - .put("xpack.watcher.actions.hipchat.service.account." + accountName + ".room", room); + .put("xpack.notification.hipchat.service.account." + accountName + ".auth_token", "_token") + .put("xpack.notification.hipchat.service.account." + accountName + ".room", room); if (host != null) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + accountName + ".host", host); + settingsBuilder.put("xpack.notification.hipchat.service.account." + accountName + ".host", host); } if (port > 0) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + accountName + ".port", port); + settingsBuilder.put("xpack.notification.hipchat.service.account." + accountName + ".port", port); } buildMessageDefaults(accountName, settingsBuilder, null, null, defaultFrom, defaultColor, defaultFormat, defaultNotify); InternalHipChatService service = new InternalHipChatService(settingsBuilder.build(), httpClient, @@ -130,9 +128,9 @@ public class InternalHipChatServiceTests extends ESTestCase { public void testSingleAccountIntegrationNoRoomSetting() throws Exception { String accountName = randomAsciiOfLength(10); Settings.Builder settingsBuilder = Settings.builder() - .put("xpack.watcher.actions.hipchat.service.account." + accountName + ".profile", + .put("xpack.notification.hipchat.service.account." + accountName + ".profile", HipChatAccount.Profile.INTEGRATION.value()) - .put("xpack.watcher.actions.hipchat.service.account." + accountName + ".auth_token", "_token"); + .put("xpack.notification.hipchat.service.account." + accountName + ".auth_token", "_token"); try (InternalHipChatService service = new InternalHipChatService(settingsBuilder.build(), httpClient, new ClusterSettings(settingsBuilder.build(), Collections.singleton(InternalHipChatService.HIPCHAT_ACCOUNT_SETTING)))) { service.start(); @@ -152,13 +150,13 @@ public class InternalHipChatServiceTests extends ESTestCase { HipChatMessage.Format defaultFormat = randomBoolean() ? null : randomFrom(HipChatMessage.Format.values()); Boolean defaultNotify = randomBoolean() ? null : (Boolean) randomBoolean(); Settings.Builder settingsBuilder = Settings.builder() - .put("xpack.watcher.actions.hipchat.service.account." + accountName + ".profile", HipChatAccount.Profile.USER.value()) - .put("xpack.watcher.actions.hipchat.service.account." + accountName + ".auth_token", "_token"); + .put("xpack.notification.hipchat.service.account." + accountName + ".profile", HipChatAccount.Profile.USER.value()) + .put("xpack.notification.hipchat.service.account." + accountName + ".auth_token", "_token"); if (host != null) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + accountName + ".host", host); + settingsBuilder.put("xpack.notification.hipchat.service.account." + accountName + ".host", host); } if (port > 0) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + accountName + ".port", port); + settingsBuilder.put("xpack.notification.hipchat.service.account." + accountName + ".port", port); } buildMessageDefaults(accountName, settingsBuilder, defaultRoom, defaultUser, null, defaultColor, defaultFormat, defaultNotify); InternalHipChatService service = new InternalHipChatService(settingsBuilder.build(), httpClient, @@ -199,17 +197,17 @@ public class InternalHipChatServiceTests extends ESTestCase { Boolean defaultNotify = randomBoolean() ? null : (Boolean) randomBoolean(); Settings.Builder settingsBuilder = Settings.builder(); String defaultAccount = "_a" + randomIntBetween(0, 4); - settingsBuilder.put("xpack.watcher.actions.hipchat.service.default_account", defaultAccount); + settingsBuilder.put("xpack.notification.hipchat.service.default_account", defaultAccount); boolean customGlobalServer = randomBoolean(); if (customGlobalServer) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.host", "_host_global"); - settingsBuilder.put("xpack.watcher.actions.hipchat.service.port", 299); + settingsBuilder.put("xpack.notification.hipchat.service.host", "_host_global"); + settingsBuilder.put("xpack.notification.hipchat.service.port", 299); } for (int i = 0; i < 5; i++) { String name = "_a" + i; - String prefix = "xpack.watcher.actions.hipchat.service.account." + name; + String prefix = "xpack.notification.hipchat.service.account." + name; HipChatAccount.Profile profile = randomFrom(HipChatAccount.Profile.values()); settingsBuilder.put(prefix + ".profile", profile); settingsBuilder.put(prefix + ".auth_token", "_token" + i); @@ -258,22 +256,22 @@ public class InternalHipChatServiceTests extends ESTestCase { private void buildMessageDefaults(String account, Settings.Builder settingsBuilder, String room, String user, String from, HipChatMessage.Color color, HipChatMessage.Format format, Boolean notify) { if (room != null) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + account + ".message_defaults.room", room); + settingsBuilder.put("xpack.notification.hipchat.service.account." + account + ".message_defaults.room", room); } if (user != null) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + account + ".message_defaults.user", user); + settingsBuilder.put("xpack.notification.hipchat.service.account." + account + ".message_defaults.user", user); } if (from != null) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + account + ".message_defaults.from", from); + settingsBuilder.put("xpack.notification.hipchat.service.account." + account + ".message_defaults.from", from); } if (color != null) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + account + ".message_defaults.color", color.value()); + settingsBuilder.put("xpack.notification.hipchat.service.account." + account + ".message_defaults.color", color.value()); } if (format != null) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + account + ".message_defaults.format", format); + settingsBuilder.put("xpack.notification.hipchat.service.account." + account + ".message_defaults.format", format); } if (notify != null) { - settingsBuilder.put("xpack.watcher.actions.hipchat.service.account." + account + ".message_defaults.notify", notify); + settingsBuilder.put("xpack.notification.hipchat.service.account." + account + ".message_defaults.notify", notify); } } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/UserAccountTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/UserAccountTests.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/UserAccountTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/UserAccountTests.java index dd2c01ef294..e046cc6b829 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/UserAccountTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/UserAccountTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.hipchat.service; +package org.elasticsearch.xpack.notification.hipchat; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/V1AccountTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/V1AccountTests.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/V1AccountTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/V1AccountTests.java index 1359170f609..913247857d1 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/service/V1AccountTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/hipchat/V1AccountTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.hipchat.service; +package org.elasticsearch.xpack.notification.hipchat; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEventDefaultsTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEventDefaultsTests.java similarity index 98% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEventDefaultsTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEventDefaultsTests.java index 4ff934fc1c1..c8e5b425285 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/service/IncidentEventDefaultsTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/pagerduty/IncidentEventDefaultsTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.pagerduty.service; +package org.elasticsearch.xpack.notification.pagerduty; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyAccountsTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccountsTests.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyAccountsTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccountsTests.java index f12ff0b62ce..15406eb798a 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/service/PagerDutyAccountsTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccountsTests.java @@ -3,13 +3,13 @@ * 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.watcher.actions.pagerduty.service; +package org.elasticsearch.xpack.notification.pagerduty; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessageDefaultsTests; import org.elasticsearch.watcher.support.http.HttpClient; +import org.elasticsearch.xpack.notification.slack.message.SlackMessageDefaultsTests; import org.junit.Before; import java.util.Map; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/service/SlackAccountsTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/slack/SlackAccountsTests.java similarity index 97% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/service/SlackAccountsTests.java rename to elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/slack/SlackAccountsTests.java index ac9816b56f1..61ddceb2efd 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/service/SlackAccountsTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/notification/slack/SlackAccountsTests.java @@ -3,13 +3,13 @@ * 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.watcher.actions.slack.service; +package org.elasticsearch.xpack.notification.slack; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessageDefaultsTests; import org.elasticsearch.watcher.support.http.HttpClient; +import org.elasticsearch.xpack.notification.slack.message.SlackMessageDefaultsTests; import org.junit.Before; import java.util.Map; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java index 64fdd6cbed4..996c98b5aec 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/Watcher.java @@ -22,15 +22,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.watcher.actions.WatcherActionModule; -import org.elasticsearch.watcher.actions.email.service.EmailService; -import org.elasticsearch.watcher.actions.email.service.InternalEmailService; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatService; -import org.elasticsearch.watcher.actions.hipchat.service.InternalHipChatService; -import org.elasticsearch.watcher.actions.pagerduty.service.InternalPagerDutyService; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyAccount; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyService; -import org.elasticsearch.watcher.actions.slack.service.InternalSlackService; -import org.elasticsearch.watcher.actions.slack.service.SlackService; import org.elasticsearch.watcher.client.WatcherClientModule; import org.elasticsearch.watcher.condition.ConditionModule; import org.elasticsearch.watcher.execution.ExecutionModule; @@ -81,6 +72,15 @@ import org.elasticsearch.watcher.trigger.schedule.ScheduleModule; import org.elasticsearch.watcher.watch.WatchModule; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.common.init.LazyInitializationModule; +import org.elasticsearch.xpack.notification.email.EmailService; +import org.elasticsearch.xpack.notification.email.InternalEmailService; +import org.elasticsearch.xpack.notification.hipchat.HipChatService; +import org.elasticsearch.xpack.notification.hipchat.InternalHipChatService; +import org.elasticsearch.xpack.notification.pagerduty.InternalPagerDutyService; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; +import org.elasticsearch.xpack.notification.slack.InternalSlackService; +import org.elasticsearch.xpack.notification.slack.SlackService; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -201,13 +201,12 @@ public class Watcher { module.registerSetting(Setting.simpleString("xpack.watcher.start_immediately", Setting.Property.NodeScope)); module.registerSetting(Setting.simpleString("xpack.watcher.http.default_connection_timeout", Setting.Property.NodeScope)); - module.registerSettingsFilter("xpack.watcher.actions.email.service.account.*.smtp.password"); - module.registerSettingsFilter("xpack.watcher.actions.slack.service.account.*.url"); - module.registerSettingsFilter("xpack.watcher.actions.pagerduty.service.account.*.url"); - module.registerSettingsFilter("xpack.watcher.actions.pagerduty.service." + PagerDutyAccount.SERVICE_KEY_SETTING); - module.registerSettingsFilter("xpack.watcher.actions.pagerduty.service.account.*." + - PagerDutyAccount.SERVICE_KEY_SETTING); - module.registerSettingsFilter("xpack.watcher.actions.hipchat.service.account.*.auth_token"); + module.registerSettingsFilter("xpack.notification.email.service.account.*.smtp.password"); + module.registerSettingsFilter("xpack.notification.slack.service.account.*.url"); + module.registerSettingsFilter("xpack.notification.pagerduty.service.account.*.url"); + module.registerSettingsFilter("xpack.notification.pagerduty.service." + PagerDutyAccount.SERVICE_KEY_SETTING); + module.registerSettingsFilter("xpack.notification.pagerduty.service.account.*." + PagerDutyAccount.SERVICE_KEY_SETTING); + module.registerSettingsFilter("xpack.notification.hipchat.service.account.*.auth_token"); } public void onModule(NetworkModule module) { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionBuilders.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionBuilders.java index 247138c8396..d6f5eb2de6d 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionBuilders.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionBuilders.java @@ -6,14 +6,14 @@ package org.elasticsearch.watcher.actions; import org.elasticsearch.watcher.actions.email.EmailAction; -import org.elasticsearch.watcher.actions.email.service.EmailTemplate; import org.elasticsearch.watcher.actions.hipchat.HipChatAction; import org.elasticsearch.watcher.actions.index.IndexAction; import org.elasticsearch.watcher.actions.logging.LoggingAction; import org.elasticsearch.watcher.actions.pagerduty.PagerDutyAction; -import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEvent; +import org.elasticsearch.xpack.notification.email.EmailTemplate; +import org.elasticsearch.xpack.notification.pagerduty.IncidentEvent; import org.elasticsearch.watcher.actions.slack.SlackAction; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessage; +import org.elasticsearch.xpack.notification.slack.message.SlackMessage; import org.elasticsearch.watcher.actions.webhook.WebhookAction; import org.elasticsearch.watcher.support.http.HttpRequestTemplate; import org.elasticsearch.watcher.support.text.TextTemplate; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/WatcherActionModule.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/WatcherActionModule.java index 63ae9a31c72..2f634627899 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/WatcherActionModule.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/WatcherActionModule.java @@ -9,29 +9,29 @@ import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.multibindings.MapBinder; import org.elasticsearch.watcher.actions.email.EmailAction; import org.elasticsearch.watcher.actions.email.EmailActionFactory; -import org.elasticsearch.watcher.actions.email.service.EmailService; -import org.elasticsearch.watcher.actions.email.service.HtmlSanitizer; -import org.elasticsearch.watcher.actions.email.service.InternalEmailService; -import org.elasticsearch.watcher.actions.email.service.attachment.DataAttachmentParser; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachmentParser; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachmentsParser; -import org.elasticsearch.watcher.actions.email.service.attachment.HttpEmailAttachementParser; import org.elasticsearch.watcher.actions.hipchat.HipChatAction; import org.elasticsearch.watcher.actions.hipchat.HipChatActionFactory; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatService; -import org.elasticsearch.watcher.actions.hipchat.service.InternalHipChatService; +import org.elasticsearch.xpack.notification.email.EmailService; +import org.elasticsearch.xpack.notification.email.HtmlSanitizer; +import org.elasticsearch.xpack.notification.email.InternalEmailService; +import org.elasticsearch.xpack.notification.email.attachment.DataAttachmentParser; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentParser; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentsParser; +import org.elasticsearch.xpack.notification.email.attachment.HttpEmailAttachementParser; +import org.elasticsearch.xpack.notification.hipchat.HipChatService; +import org.elasticsearch.xpack.notification.hipchat.InternalHipChatService; import org.elasticsearch.watcher.actions.index.IndexAction; import org.elasticsearch.watcher.actions.index.IndexActionFactory; import org.elasticsearch.watcher.actions.logging.LoggingAction; import org.elasticsearch.watcher.actions.logging.LoggingActionFactory; import org.elasticsearch.watcher.actions.pagerduty.PagerDutyAction; import org.elasticsearch.watcher.actions.pagerduty.PagerDutyActionFactory; -import org.elasticsearch.watcher.actions.pagerduty.service.InternalPagerDutyService; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyService; +import org.elasticsearch.xpack.notification.pagerduty.InternalPagerDutyService; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; import org.elasticsearch.watcher.actions.slack.SlackAction; import org.elasticsearch.watcher.actions.slack.SlackActionFactory; -import org.elasticsearch.watcher.actions.slack.service.InternalSlackService; -import org.elasticsearch.watcher.actions.slack.service.SlackService; +import org.elasticsearch.xpack.notification.slack.InternalSlackService; +import org.elasticsearch.xpack.notification.slack.SlackService; import org.elasticsearch.watcher.actions.webhook.WebhookAction; import org.elasticsearch.watcher.actions.webhook.WebhookActionFactory; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/EmailAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/EmailAction.java index 255e48cd565..f34f7f2d6c3 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/EmailAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/EmailAction.java @@ -12,15 +12,16 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.actions.Action; -import org.elasticsearch.watcher.actions.email.service.Authentication; -import org.elasticsearch.watcher.actions.email.service.Email; -import org.elasticsearch.watcher.actions.email.service.EmailTemplate; -import org.elasticsearch.watcher.actions.email.service.Profile; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachments; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachmentsParser; import org.elasticsearch.watcher.support.secret.Secret; import org.elasticsearch.watcher.support.xcontent.WatcherParams; import org.elasticsearch.watcher.support.xcontent.WatcherXContentParser; +import org.elasticsearch.xpack.notification.email.Authentication; +import org.elasticsearch.xpack.notification.email.DataAttachment; +import org.elasticsearch.xpack.notification.email.Email; +import org.elasticsearch.xpack.notification.email.EmailTemplate; +import org.elasticsearch.xpack.notification.email.Profile; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachments; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentsParser; import java.io.IOException; import java.util.Locale; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/EmailActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/EmailActionFactory.java index a16bafa34e0..8832d833ea8 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/EmailActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/EmailActionFactory.java @@ -10,10 +10,10 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.actions.ActionFactory; -import org.elasticsearch.watcher.actions.email.service.EmailService; -import org.elasticsearch.watcher.actions.email.service.HtmlSanitizer; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachmentsParser; import org.elasticsearch.watcher.support.text.TextTemplateEngine; +import org.elasticsearch.xpack.notification.email.EmailService; +import org.elasticsearch.xpack.notification.email.HtmlSanitizer; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentsParser; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/ExecutableEmailAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/ExecutableEmailAction.java index dc3aeb141b3..0b7a1dc1351 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/ExecutableEmailAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/ExecutableEmailAction.java @@ -9,15 +9,16 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.watcher.actions.Action; import org.elasticsearch.watcher.actions.ExecutableAction; -import org.elasticsearch.watcher.actions.email.service.Attachment; -import org.elasticsearch.watcher.actions.email.service.Email; -import org.elasticsearch.watcher.actions.email.service.EmailService; -import org.elasticsearch.watcher.actions.email.service.HtmlSanitizer; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachmentParser; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Variables; import org.elasticsearch.watcher.support.text.TextTemplateEngine; import org.elasticsearch.watcher.watch.Payload; +import org.elasticsearch.xpack.notification.email.Attachment; +import org.elasticsearch.xpack.notification.email.DataAttachment; +import org.elasticsearch.xpack.notification.email.Email; +import org.elasticsearch.xpack.notification.email.EmailService; +import org.elasticsearch.xpack.notification.email.HtmlSanitizer; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentParser; import java.util.HashMap; import java.util.Map; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/ExecutableHipChatAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/ExecutableHipChatAction.java index bf9ce4a4e9b..bebb7ac4152 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/ExecutableHipChatAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/ExecutableHipChatAction.java @@ -8,10 +8,10 @@ package org.elasticsearch.watcher.actions.hipchat; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.watcher.actions.Action; import org.elasticsearch.watcher.actions.ExecutableAction; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatAccount; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatService; -import org.elasticsearch.watcher.actions.hipchat.service.SentMessages; +import org.elasticsearch.xpack.notification.hipchat.HipChatAccount; +import org.elasticsearch.xpack.notification.hipchat.HipChatMessage; +import org.elasticsearch.xpack.notification.hipchat.HipChatService; +import org.elasticsearch.xpack.notification.hipchat.SentMessages; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Variables; import org.elasticsearch.watcher.support.text.TextTemplateEngine; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/HipChatAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/HipChatAction.java index a3d45e9bbe6..c4516b36b77 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/HipChatAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/HipChatAction.java @@ -13,8 +13,8 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.actions.Action; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage; -import org.elasticsearch.watcher.actions.hipchat.service.SentMessages; +import org.elasticsearch.xpack.notification.hipchat.HipChatMessage; +import org.elasticsearch.xpack.notification.hipchat.SentMessages; import org.elasticsearch.watcher.support.text.TextTemplate; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionFactory.java index e21e770bc35..6cd74ee9766 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionFactory.java @@ -11,8 +11,8 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.actions.ActionFactory; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatAccount; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatService; +import org.elasticsearch.xpack.notification.hipchat.HipChatAccount; +import org.elasticsearch.xpack.notification.hipchat.HipChatService; import org.elasticsearch.watcher.support.text.TextTemplateEngine; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/ExecutablePagerDutyAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/ExecutablePagerDutyAction.java index 101f2d1fb79..b8230dbbf0b 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/ExecutablePagerDutyAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/ExecutablePagerDutyAction.java @@ -8,10 +8,10 @@ package org.elasticsearch.watcher.actions.pagerduty; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.watcher.actions.Action; import org.elasticsearch.watcher.actions.ExecutableAction; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyAccount; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyService; -import org.elasticsearch.watcher.actions.pagerduty.service.SentEvent; -import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEvent; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; +import org.elasticsearch.xpack.notification.pagerduty.SentEvent; +import org.elasticsearch.xpack.notification.pagerduty.IncidentEvent; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Variables; import org.elasticsearch.watcher.support.text.TextTemplateEngine; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyAction.java index 2d6f85b286e..d2d86d1da16 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyAction.java @@ -10,8 +10,8 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.actions.Action; -import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEvent; -import org.elasticsearch.watcher.actions.pagerduty.service.SentEvent; +import org.elasticsearch.xpack.notification.pagerduty.IncidentEvent; +import org.elasticsearch.xpack.notification.pagerduty.SentEvent; import java.io.IOException; import java.util.Objects; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionFactory.java index 9e5bd0fc2a4..009c880214d 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionFactory.java @@ -12,8 +12,8 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.actions.ActionFactory; import org.elasticsearch.watcher.actions.hipchat.ExecutableHipChatAction; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyAccount; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyService; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; import org.elasticsearch.watcher.support.text.TextTemplateEngine; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/ExecutableSlackAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/ExecutableSlackAction.java index befc61f4e61..213dd4c4f51 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/ExecutableSlackAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/ExecutableSlackAction.java @@ -8,10 +8,10 @@ package org.elasticsearch.watcher.actions.slack; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.watcher.actions.Action; import org.elasticsearch.watcher.actions.ExecutableAction; -import org.elasticsearch.watcher.actions.slack.service.SentMessages; -import org.elasticsearch.watcher.actions.slack.service.SlackAccount; -import org.elasticsearch.watcher.actions.slack.service.SlackService; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessage; +import org.elasticsearch.xpack.notification.slack.SentMessages; +import org.elasticsearch.xpack.notification.slack.SlackAccount; +import org.elasticsearch.xpack.notification.slack.SlackService; +import org.elasticsearch.xpack.notification.slack.message.SlackMessage; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.Variables; import org.elasticsearch.watcher.support.text.TextTemplateEngine; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/SlackAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/SlackAction.java index 6cde8f091f8..f63778bead5 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/SlackAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/SlackAction.java @@ -13,8 +13,8 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.actions.Action; -import org.elasticsearch.watcher.actions.slack.service.SentMessages; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessage; +import org.elasticsearch.xpack.notification.slack.SentMessages; +import org.elasticsearch.xpack.notification.slack.message.SlackMessage; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/SlackActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/SlackActionFactory.java index 31a22e058cc..da1ea0c4309 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/SlackActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/slack/SlackActionFactory.java @@ -12,8 +12,8 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.actions.ActionFactory; import org.elasticsearch.watcher.actions.hipchat.ExecutableHipChatAction; -import org.elasticsearch.watcher.actions.slack.service.SlackAccount; -import org.elasticsearch.watcher.actions.slack.service.SlackService; +import org.elasticsearch.xpack.notification.slack.SlackAccount; +import org.elasticsearch.xpack.notification.slack.SlackService; import org.elasticsearch.watcher.support.text.TextTemplateEngine; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherF.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherF.java index fb3e5c5af75..3f026f145b3 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherF.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/WatcherF.java @@ -38,23 +38,23 @@ public class WatcherF { settings.put("cluster.name", WatcherF.class.getSimpleName()); // this is for the `test-watcher-integration` group level integration in HipChat - settings.put("xpack.watcher.actions.hipchat.service.account.integration.profile", "integration"); - settings.put("xpack.watcher.actions.hipchat.service.account.integration.auth_token", "huuS9v7ccuOy3ZBWWWr1vt8Lqu3sQnLUE81nrLZU"); - settings.put("xpack.watcher.actions.hipchat.service.account.integration.room", "test-watcher"); + settings.put("xpack.notification.hipchat.service.account.integration.profile", "integration"); + settings.put("xpack.notification.hipchat.service.account.integration.auth_token", "huuS9v7ccuOy3ZBWWWr1vt8Lqu3sQnLUE81nrLZU"); + settings.put("xpack.notification.hipchat.service.account.integration.room", "test-watcher"); // this is for the Watcher Test account in HipChat - settings.put("xpack.watcher.actions.hipchat.service.account.user.profile", "user"); - settings.put("xpack.watcher.actions.hipchat.service.account.user.auth_token", "FYVx16oDH78ZW9r13wtXbcszyoyA7oX5tiMWg9X0"); + settings.put("xpack.notification.hipchat.service.account.user.profile", "user"); + settings.put("xpack.notification.hipchat.service.account.user.auth_token", "FYVx16oDH78ZW9r13wtXbcszyoyA7oX5tiMWg9X0"); // this is for the `test-watcher-v1` notification token (hipchat) - settings.put("xpack.watcher.actions.hipchat.service.account.v1.profile", "v1"); - settings.put("xpack.watcher.actions.hipchat.service.account.v1.auth_token", "a734baf62df618b96dda55b323fc30"); + settings.put("xpack.notification.hipchat.service.account.v1.profile", "v1"); + settings.put("xpack.notification.hipchat.service.account.v1.auth_token", "a734baf62df618b96dda55b323fc30"); // this is for our test slack incoming webhook (under elasticsearch team) - System.setProperty("es.xpack.watcher.actions.slack.service.account.a1.url", + System.setProperty("es.xpack.notification.slack.service.account.a1.url", "https://hooks.slack.com/services/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"); - System.setProperty("es.xpack.watcher.actions.pagerduty.service.account.service1.service_api_key", + System.setProperty("es.xpack.notification.pagerduty.service.account.service1.service_api_key", "fc082467005d4072a914e0bb041882d0"); final CountDownLatch latch = new CountDownLatch(1); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionTests.java index 5a922b07666..4ec0c5f134b 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionTests.java @@ -17,19 +17,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.actions.Action; -import org.elasticsearch.watcher.actions.email.service.Attachment; -import org.elasticsearch.watcher.actions.email.service.Authentication; -import org.elasticsearch.watcher.actions.email.service.Email; -import org.elasticsearch.watcher.actions.email.service.EmailService; -import org.elasticsearch.watcher.actions.email.service.EmailTemplate; -import org.elasticsearch.watcher.actions.email.service.HtmlSanitizer; -import org.elasticsearch.watcher.actions.email.service.Profile; -import org.elasticsearch.watcher.actions.email.service.attachment.DataAttachmentParser; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachmentParser; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachments; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachmentsParser; -import org.elasticsearch.watcher.actions.email.service.attachment.HttpEmailAttachementParser; -import org.elasticsearch.watcher.actions.email.service.attachment.HttpRequestAttachment; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.execution.Wid; import org.elasticsearch.watcher.support.http.HttpClient; @@ -46,6 +33,20 @@ import org.elasticsearch.watcher.support.xcontent.WatcherParams; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.watcher.test.MockTextTemplateEngine; import org.elasticsearch.watcher.watch.Payload; +import org.elasticsearch.xpack.notification.email.Attachment; +import org.elasticsearch.xpack.notification.email.Authentication; +import org.elasticsearch.xpack.notification.email.DataAttachment; +import org.elasticsearch.xpack.notification.email.Email; +import org.elasticsearch.xpack.notification.email.EmailService; +import org.elasticsearch.xpack.notification.email.EmailTemplate; +import org.elasticsearch.xpack.notification.email.HtmlSanitizer; +import org.elasticsearch.xpack.notification.email.Profile; +import org.elasticsearch.xpack.notification.email.attachment.DataAttachmentParser; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentParser; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachments; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentsParser; +import org.elasticsearch.xpack.notification.email.attachment.HttpEmailAttachementParser; +import org.elasticsearch.xpack.notification.email.attachment.HttpRequestAttachment; import org.jboss.netty.handler.codec.http.HttpHeaders; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -55,7 +56,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -100,13 +100,13 @@ public class EmailActionTests extends ESTestCase { final String account = "account1"; EmailService service = new AbstractWatcherIntegrationTestCase.NoopEmailService() { @Override - public EmailSent send(Email email, Authentication auth, Profile profile) { - return new EmailSent(account, email); + public EmailService.EmailSent send(Email email, Authentication auth, Profile profile) { + return new EmailService.EmailSent(account, email); } @Override - public EmailSent send(Email email, Authentication auth, Profile profile, String accountName) { - return new EmailSent(account, email); + public EmailService.EmailSent send(Email email, Authentication auth, Profile profile, String accountName) { + return new EmailService.EmailSent(account, email); } }; TextTemplateEngine engine = mock(TextTemplateEngine.class); @@ -610,7 +610,7 @@ public class EmailActionTests extends ESTestCase { HttpRequestTemplate template = HttpRequestTemplate.builder("localhost", 1234).build(); attachments.add(new HttpRequestAttachment(randomAsciiOfLength(10), template, randomFrom("my/custom-type", null))); } else if ("data".equals(attachmentType)) { - attachments.add(new org.elasticsearch.watcher.actions.email.service.attachment.DataAttachment(randomAsciiOfLength(10), + attachments.add(new org.elasticsearch.xpack.notification.email.attachment.DataAttachment(randomAsciiOfLength(10), randomFrom(DataAttachment.JSON, DataAttachment.YAML))); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/EmailAttachmentTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/EmailAttachmentTests.java index 4dd67ba2cb9..93c3c96a47d 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/EmailAttachmentTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/EmailAttachmentTests.java @@ -14,12 +14,12 @@ import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.watcher.actions.email.service.EmailTemplate; -import org.elasticsearch.watcher.actions.email.service.attachment.DataAttachment; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachmentParser; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachments; -import org.elasticsearch.watcher.actions.email.service.attachment.HttpRequestAttachment; -import org.elasticsearch.watcher.actions.email.service.support.EmailServer; +import org.elasticsearch.xpack.notification.email.DataAttachment; +import org.elasticsearch.xpack.notification.email.EmailTemplate; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentParser; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachments; +import org.elasticsearch.xpack.notification.email.attachment.HttpRequestAttachment; +import org.elasticsearch.xpack.notification.email.support.EmailServer; import org.elasticsearch.watcher.client.WatchSourceBuilder; import org.elasticsearch.watcher.client.WatcherClient; import org.elasticsearch.watcher.condition.compare.CompareCondition; @@ -46,8 +46,8 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.watcher.actions.ActionBuilders.emailAction; -import static org.elasticsearch.watcher.actions.email.DataAttachment.JSON; -import static org.elasticsearch.watcher.actions.email.DataAttachment.YAML; +import static org.elasticsearch.xpack.notification.email.DataAttachment.JSON; +import static org.elasticsearch.xpack.notification.email.DataAttachment.YAML; import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder; import static org.elasticsearch.watcher.condition.ConditionBuilders.compareCondition; import static org.elasticsearch.watcher.input.InputBuilders.searchInput; @@ -93,11 +93,11 @@ public class EmailAttachmentTests extends AbstractWatcherIntegrationTestCase { } return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put("xpack.watcher.actions.email.service.account.test.smtp.auth", true) - .put("xpack.watcher.actions.email.service.account.test.smtp.user", USERNAME) - .put("xpack.watcher.actions.email.service.account.test.smtp.password", PASSWORD) - .put("xpack.watcher.actions.email.service.account.test.smtp.port", server.port()) - .put("xpack.watcher.actions.email.service.account.test.smtp.host", "localhost") + .put("xpack.notification.email.service.account.test.smtp.auth", true) + .put("xpack.notification.email.service.account.test.smtp.user", USERNAME) + .put("xpack.notification.email.service.account.test.smtp.password", PASSWORD) + .put("xpack.notification.email.service.account.test.smtp.port", server.port()) + .put("xpack.notification.email.service.account.test.smtp.host", "localhost") .build(); } @@ -142,7 +142,7 @@ public class EmailAttachmentTests extends AbstractWatcherIntegrationTestCase { } public void testThatEmailAttachmentsAreSent() throws Exception { - org.elasticsearch.watcher.actions.email.DataAttachment dataFormat = randomFrom(JSON, YAML); + DataAttachment dataFormat = randomFrom(JSON, YAML); final CountDownLatch latch = new CountDownLatch(1); server.addListener(new EmailServer.Listener() { @Override @@ -168,7 +168,8 @@ public class EmailAttachmentTests extends AbstractWatcherIntegrationTestCase { List attachments = new ArrayList<>(); - DataAttachment dataAttachment = DataAttachment.builder("my-id").dataAttachment(dataFormat).build(); + org.elasticsearch.xpack.notification.email.attachment.DataAttachment dataAttachment = + org.elasticsearch.xpack.notification.email.attachment.DataAttachment.builder("my-id").dataAttachment(dataFormat).build(); attachments.add(dataAttachment); HttpRequestTemplate requestTemplate = HttpRequestTemplate.builder("localhost", webServer.getPort()) diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionFactoryTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionFactoryTests.java index 23a414def5f..07050ce213d 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionFactoryTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionFactoryTests.java @@ -13,9 +13,9 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatAccount; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatService; +import org.elasticsearch.xpack.notification.hipchat.HipChatAccount; +import org.elasticsearch.xpack.notification.hipchat.HipChatMessage; +import org.elasticsearch.xpack.notification.hipchat.HipChatService; import org.elasticsearch.watcher.support.text.TextTemplate; import org.elasticsearch.watcher.support.text.TextTemplateEngine; import org.junit.Before; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionTests.java index 8a70086f42a..b170ff56f38 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/hipchat/HipChatActionTests.java @@ -14,10 +14,10 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.actions.Action; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatAccount; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage; -import org.elasticsearch.watcher.actions.hipchat.service.HipChatService; -import org.elasticsearch.watcher.actions.hipchat.service.SentMessages; +import org.elasticsearch.xpack.notification.hipchat.HipChatAccount; +import org.elasticsearch.xpack.notification.hipchat.HipChatMessage; +import org.elasticsearch.xpack.notification.hipchat.HipChatService; +import org.elasticsearch.xpack.notification.hipchat.SentMessages; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.execution.Wid; import org.elasticsearch.watcher.support.http.HttpRequest; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/logging/LoggingActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/logging/LoggingActionTests.java index b89ae0c7b33..fc5cd194572 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/logging/LoggingActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/logging/LoggingActionTests.java @@ -14,12 +14,12 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.actions.Action; -import org.elasticsearch.watcher.actions.email.service.Attachment; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.text.TextTemplate; import org.elasticsearch.watcher.support.text.TextTemplateEngine; import org.elasticsearch.watcher.test.WatcherTestUtils; import org.elasticsearch.watcher.watch.Payload; +import org.elasticsearch.xpack.notification.email.Attachment; import org.joda.time.DateTime; import org.junit.Before; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java index 962e30d3f65..5d731e548ee 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java @@ -11,8 +11,8 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyAccount; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyService; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; import org.elasticsearch.watcher.support.text.TextTemplateEngine; import org.junit.Before; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionTests.java index 0010c90303b..7f55f5f6017 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/pagerduty/PagerDutyActionTests.java @@ -15,12 +15,12 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.actions.Action; -import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEvent; -import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEventContext; -import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEventDefaults; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyAccount; -import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyService; -import org.elasticsearch.watcher.actions.pagerduty.service.SentEvent; +import org.elasticsearch.xpack.notification.pagerduty.IncidentEvent; +import org.elasticsearch.xpack.notification.pagerduty.IncidentEventContext; +import org.elasticsearch.xpack.notification.pagerduty.IncidentEventDefaults; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; +import org.elasticsearch.xpack.notification.pagerduty.SentEvent; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.execution.Wid; import org.elasticsearch.watcher.support.http.HttpRequest; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/SlackActionFactoryTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/SlackActionFactoryTests.java index 5ef196e5947..42f759fa607 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/SlackActionFactoryTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/SlackActionFactoryTests.java @@ -11,14 +11,14 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.actions.slack.service.SlackAccount; -import org.elasticsearch.watcher.actions.slack.service.SlackService; +import org.elasticsearch.xpack.notification.slack.SlackAccount; +import org.elasticsearch.xpack.notification.slack.SlackService; import org.elasticsearch.watcher.support.text.TextTemplateEngine; import org.junit.Before; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.watcher.actions.ActionBuilders.slackAction; -import static org.elasticsearch.watcher.actions.slack.service.message.SlackMessageTests.createRandomTemplate; +import static org.elasticsearch.xpack.notification.slack.message.SlackMessageTests.createRandomTemplate; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/SlackActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/SlackActionTests.java index 3eb8b9af6fb..b314691e844 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/SlackActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/SlackActionTests.java @@ -14,12 +14,12 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.actions.Action; -import org.elasticsearch.watcher.actions.slack.service.SentMessages; -import org.elasticsearch.watcher.actions.slack.service.SlackAccount; -import org.elasticsearch.watcher.actions.slack.service.SlackService; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessage; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessageDefaults; -import org.elasticsearch.watcher.actions.slack.service.message.SlackMessageTests; +import org.elasticsearch.xpack.notification.slack.SentMessages; +import org.elasticsearch.xpack.notification.slack.SlackAccount; +import org.elasticsearch.xpack.notification.slack.SlackService; +import org.elasticsearch.xpack.notification.slack.message.SlackMessage; +import org.elasticsearch.xpack.notification.slack.message.SlackMessageDefaults; +import org.elasticsearch.xpack.notification.slack.message.SlackMessageTests; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.execution.Wid; import org.elasticsearch.watcher.support.http.HttpRequest; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/throttler/ActionThrottleTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/throttler/ActionThrottleTests.java index 65413e6ba06..446551de1ba 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/throttler/ActionThrottleTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/throttler/ActionThrottleTests.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.watcher.actions.Action; import org.elasticsearch.watcher.actions.ActionWrapper; import org.elasticsearch.watcher.actions.email.EmailAction; -import org.elasticsearch.watcher.actions.email.service.EmailTemplate; import org.elasticsearch.watcher.actions.index.IndexAction; import org.elasticsearch.watcher.actions.logging.LoggingAction; import org.elasticsearch.watcher.actions.webhook.WebhookAction; @@ -32,6 +31,7 @@ import org.elasticsearch.watcher.trigger.manual.ManualTriggerEvent; import org.elasticsearch.watcher.trigger.schedule.IntervalSchedule; import org.elasticsearch.watcher.trigger.schedule.ScheduleTrigger; import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent; +import org.elasticsearch.xpack.notification.email.EmailTemplate; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/webhook/WebhookActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/webhook/WebhookActionTests.java index 8a418cc6348..dee838b2d5c 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/webhook/WebhookActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/webhook/WebhookActionTests.java @@ -17,10 +17,6 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.actions.Action; import org.elasticsearch.watcher.actions.Action.Result.Status; -import org.elasticsearch.watcher.actions.email.service.Attachment; -import org.elasticsearch.watcher.actions.email.service.Authentication; -import org.elasticsearch.watcher.actions.email.service.Email; -import org.elasticsearch.watcher.actions.email.service.Profile; import org.elasticsearch.watcher.execution.TriggeredExecutionContext; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.http.HttpClient; @@ -41,6 +37,10 @@ import org.elasticsearch.watcher.test.WatcherTestUtils; import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent; import org.elasticsearch.watcher.watch.Payload; import org.elasticsearch.watcher.watch.Watch; +import org.elasticsearch.xpack.notification.email.Attachment; +import org.elasticsearch.xpack.notification.email.Authentication; +import org.elasticsearch.xpack.notification.email.Email; +import org.elasticsearch.xpack.notification.email.Profile; import org.hamcrest.Matchers; import org.joda.time.DateTime; import org.junit.Before; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateEmailMappingsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateEmailMappingsTests.java index 3d4ec7a2474..1723ebf5fcd 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateEmailMappingsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryTemplateEmailMappingsTests.java @@ -9,8 +9,8 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.bucket.terms.Terms; -import org.elasticsearch.watcher.actions.email.service.EmailTemplate; -import org.elasticsearch.watcher.actions.email.service.support.EmailServer; +import org.elasticsearch.xpack.notification.email.EmailTemplate; +import org.elasticsearch.xpack.notification.email.support.EmailServer; import org.elasticsearch.watcher.execution.ExecutionState; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse; @@ -62,11 +62,11 @@ public class HistoryTemplateEmailMappingsTests extends AbstractWatcherIntegratio .put(super.nodeSettings(nodeOrdinal)) // email - .put("xpack.watcher.actions.email.service.account.test.smtp.auth", true) - .put("xpack.watcher.actions.email.service.account.test.smtp.user", USERNAME) - .put("xpack.watcher.actions.email.service.account.test.smtp.password", PASSWORD) - .put("xpack.watcher.actions.email.service.account.test.smtp.port", server.port()) - .put("xpack.watcher.actions.email.service.account.test.smtp.host", "localhost") + .put("xpack.notification.email.service.account.test.smtp.auth", true) + .put("xpack.notification.email.service.account.test.smtp.user", USERNAME) + .put("xpack.notification.email.service.account.test.smtp.password", PASSWORD) + .put("xpack.notification.email.service.account.test.smtp.port", server.port()) + .put("xpack.notification.email.service.account.test.smtp.host", "localhost") .build(); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java index 68a949bcb51..a4e18eb1d4a 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -42,10 +42,6 @@ import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.watcher.WatcherLifeCycleService; import org.elasticsearch.watcher.WatcherService; import org.elasticsearch.watcher.WatcherState; -import org.elasticsearch.watcher.actions.email.service.Authentication; -import org.elasticsearch.watcher.actions.email.service.Email; -import org.elasticsearch.watcher.actions.email.service.EmailService; -import org.elasticsearch.watcher.actions.email.service.Profile; import org.elasticsearch.watcher.client.WatcherClient; import org.elasticsearch.watcher.execution.ExecutionService; import org.elasticsearch.watcher.execution.ExecutionState; @@ -63,6 +59,10 @@ import org.elasticsearch.watcher.watch.Watch; import org.elasticsearch.xpack.TimeWarpedXPackPlugin; import org.elasticsearch.xpack.XPackClient; import org.elasticsearch.xpack.XPackPlugin; +import org.elasticsearch.xpack.notification.email.Authentication; +import org.elasticsearch.xpack.notification.email.Email; +import org.elasticsearch.xpack.notification.email.EmailService; +import org.elasticsearch.xpack.notification.email.Profile; import org.hamcrest.Matcher; import org.jboss.netty.util.internal.SystemPropertyUtil; import org.junit.After; @@ -600,7 +600,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase } @Override - public EmailSent send(Email email, Authentication auth, Profile profile) { + public EmailService.EmailSent send(Email email, Authentication auth, Profile profile) { return new EmailSent(auth.user(), email); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java index a268c1a981c..bba5a58489c 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/WatcherTestUtils.java @@ -36,11 +36,6 @@ import org.elasticsearch.watcher.actions.ActionWrapper; import org.elasticsearch.watcher.actions.ExecutableActions; import org.elasticsearch.watcher.actions.email.EmailAction; import org.elasticsearch.watcher.actions.email.ExecutableEmailAction; -import org.elasticsearch.watcher.actions.email.service.Authentication; -import org.elasticsearch.watcher.actions.email.service.EmailService; -import org.elasticsearch.watcher.actions.email.service.EmailTemplate; -import org.elasticsearch.watcher.actions.email.service.HtmlSanitizer; -import org.elasticsearch.watcher.actions.email.service.Profile; import org.elasticsearch.watcher.actions.webhook.ExecutableWebhookAction; import org.elasticsearch.watcher.actions.webhook.WebhookAction; import org.elasticsearch.watcher.condition.always.ExecutableAlwaysCondition; @@ -68,6 +63,11 @@ import org.elasticsearch.watcher.trigger.schedule.ScheduleTrigger; import org.elasticsearch.watcher.watch.Payload; import org.elasticsearch.watcher.watch.Watch; import org.elasticsearch.watcher.watch.WatchStatus; +import org.elasticsearch.xpack.notification.email.Authentication; +import org.elasticsearch.xpack.notification.email.EmailService; +import org.elasticsearch.xpack.notification.email.EmailTemplate; +import org.elasticsearch.xpack.notification.email.HtmlSanitizer; +import org.elasticsearch.xpack.notification.email.Profile; import org.hamcrest.Matcher; import org.joda.time.DateTime; import org.mockito.Mockito; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/WatcherSettingsFilterTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/WatcherSettingsFilterTests.java index 8c1234ac70a..1d0e312a725 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/WatcherSettingsFilterTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/integration/WatcherSettingsFilterTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.http.HttpServerTransport; -import org.elasticsearch.node.Node; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.test.rest.client.http.HttpRequestBuilder; import org.elasticsearch.test.rest.client.http.HttpResponse; @@ -45,10 +44,10 @@ public class WatcherSettingsFilterTests extends AbstractWatcherIntegrationTestCa return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) .put(NetworkModule.HTTP_ENABLED.getKey(), true) - .put("xpack.watcher.actions.email.service.account._email.smtp.host", "host.domain") - .put("xpack.watcher.actions.email.service.account._email.smtp.port", 587) - .put("xpack.watcher.actions.email.service.account._email.smtp.user", "_user") - .put("xpack.watcher.actions.email.service.account._email.smtp.password", "_passwd") + .put("xpack.notification.email.service.account._email.smtp.host", "host.domain") + .put("xpack.notification.email.service.account._email.smtp.port", 587) + .put("xpack.notification.email.service.account._email.smtp.user", "_user") + .put("xpack.notification.email.service.account._email.smtp.password", "_passwd") .build(); } @@ -58,9 +57,9 @@ public class WatcherSettingsFilterTests extends AbstractWatcherIntegrationTestCa Map nodes = (Map) response.get("nodes"); for (Object node : nodes.values()) { Map settings = (Map) ((Map) node).get("settings"); - assertThat(XContentMapValues.extractValue("xpack.watcher.actions.email.service.account._email.smtp.user", settings), + assertThat(XContentMapValues.extractValue("xpack.notification.email.service.account._email.smtp.user", settings), is((Object) "_user")); - assertThat(XContentMapValues.extractValue("xpack.watcher.actions.email.service.account._email.smtp.password", settings), + assertThat(XContentMapValues.extractValue("xpack.notification.email.service.account._email.smtp.password", settings), nullValue()); } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java index dd26eca7ff7..bdfc7bacdb0 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchTests.java @@ -30,16 +30,10 @@ import org.elasticsearch.watcher.actions.ActionRegistry; import org.elasticsearch.watcher.actions.ActionStatus; import org.elasticsearch.watcher.actions.ActionWrapper; import org.elasticsearch.watcher.actions.ExecutableActions; -import org.elasticsearch.watcher.actions.email.DataAttachment; +import org.elasticsearch.xpack.notification.email.DataAttachment; import org.elasticsearch.watcher.actions.email.EmailAction; import org.elasticsearch.watcher.actions.email.EmailActionFactory; import org.elasticsearch.watcher.actions.email.ExecutableEmailAction; -import org.elasticsearch.watcher.actions.email.service.EmailService; -import org.elasticsearch.watcher.actions.email.service.EmailTemplate; -import org.elasticsearch.watcher.actions.email.service.HtmlSanitizer; -import org.elasticsearch.watcher.actions.email.service.Profile; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachments; -import org.elasticsearch.watcher.actions.email.service.attachment.EmailAttachmentsParser; import org.elasticsearch.watcher.actions.index.ExecutableIndexAction; import org.elasticsearch.watcher.actions.index.IndexAction; import org.elasticsearch.watcher.actions.index.IndexActionFactory; @@ -122,6 +116,12 @@ import org.elasticsearch.watcher.trigger.schedule.support.Month; import org.elasticsearch.watcher.trigger.schedule.support.MonthTimes; import org.elasticsearch.watcher.trigger.schedule.support.WeekTimes; import org.elasticsearch.watcher.trigger.schedule.support.YearTimes; +import org.elasticsearch.xpack.notification.email.EmailService; +import org.elasticsearch.xpack.notification.email.EmailTemplate; +import org.elasticsearch.xpack.notification.email.HtmlSanitizer; +import org.elasticsearch.xpack.notification.email.Profile; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachments; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentsParser; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.junit.Before; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessageDefaultsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageDefaultsTests.java similarity index 98% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessageDefaultsTests.java rename to elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageDefaultsTests.java index eb0ce5d184a..2bc18ef484d 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessageDefaultsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageDefaultsTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.slack.service.message; +package org.elasticsearch.xpack.notification.slack.message; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessageTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageTests.java similarity index 99% rename from elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessageTests.java rename to elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageTests.java index 678fcfa5d8e..20209b00db2 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/slack/service/message/SlackMessageTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageTests.java @@ -3,7 +3,7 @@ * 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.watcher.actions.slack.service.message; +package org.elasticsearch.xpack.notification.slack.message; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent;