From 2a9ba9e934314f7604a05c7e22abd8ecfbadc27b Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 7 Mar 2016 04:13:30 -0500 Subject: [PATCH 01/11] lucene 6 api changes (tests only) Original commit: elastic/x-pack-elasticsearch@8120c29cd8493b11efc981692442780e025a6d1c --- .../DocumentSubsetReaderTests.java | 2 +- .../accesscontrol/FieldSubsetReaderTests.java | 46 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/DocumentSubsetReaderTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/DocumentSubsetReaderTests.java index 9a74ef861a8..34451dfbc89 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/DocumentSubsetReaderTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/DocumentSubsetReaderTests.java @@ -207,7 +207,7 @@ public class DocumentSubsetReaderTests extends ESTestCase { iw.addDocument(doc); // open reader - DirectoryReader ir = DocumentSubsetReader.wrap(DirectoryReader.open(iw, true), bitsetFilterCache, new MatchAllDocsQuery()); + DirectoryReader ir = DocumentSubsetReader.wrap(DirectoryReader.open(iw), bitsetFilterCache, new MatchAllDocsQuery()); assertEquals(2, ir.numDocs()); assertEquals(1, ir.leaves().size()); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/FieldSubsetReaderTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/FieldSubsetReaderTests.java index dfe3bafb9e4..df133f62b4e 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/FieldSubsetReaderTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/FieldSubsetReaderTests.java @@ -64,7 +64,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -96,7 +96,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field Document d2 = ir.document(0); @@ -123,7 +123,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field Document d2 = ir.document(0); @@ -150,7 +150,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field Document d2 = ir.document(0); @@ -177,7 +177,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field Document d2 = ir.document(0); @@ -204,7 +204,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field Document d2 = ir.document(0); @@ -231,7 +231,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field Document d2 = ir.document(0); @@ -260,7 +260,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field Fields vectors = ir.getTermVectors(0); @@ -290,7 +290,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -317,7 +317,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -349,7 +349,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -381,7 +381,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -413,7 +413,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -449,7 +449,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -484,7 +484,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -517,7 +517,7 @@ public class FieldSubsetReaderTests extends ESTestCase { Set fields = new HashSet<>(); fields.add("fieldA"); fields.add(SourceFieldMapper.NAME); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field Document d2 = ir.document(0); @@ -548,7 +548,7 @@ public class FieldSubsetReaderTests extends ESTestCase { Set fields = new HashSet<>(); fields.add("fieldA"); fields.add(FieldNamesFieldMapper.NAME); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -597,7 +597,7 @@ public class FieldSubsetReaderTests extends ESTestCase { fields.add("fieldA"); fields.add("fieldC"); fields.add(FieldNamesFieldMapper.NAME); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only two fields LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -645,7 +645,7 @@ public class FieldSubsetReaderTests extends ESTestCase { fields.add("fieldA"); fields.add("fieldC"); fields.add(FieldNamesFieldMapper.NAME); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -681,7 +681,7 @@ public class FieldSubsetReaderTests extends ESTestCase { Set fields = new HashSet<>(); fields.add("fieldA"); fields.add(FieldNamesFieldMapper.NAME); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see only one field LeafReader segmentReader = ir.leaves().get(0).reader(); @@ -710,7 +710,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("id"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); assertEquals(2, ir.numDocs()); assertEquals(1, ir.leaves().size()); @@ -745,7 +745,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldB"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // sees no fields assertNull(ir.getTermVectors(0)); @@ -765,7 +765,7 @@ public class FieldSubsetReaderTests extends ESTestCase { // open reader Set fields = Collections.singleton("fieldA"); - DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields); + DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields); // see no fields LeafReader segmentReader = ir.leaves().get(0).reader(); From 98e904deeff685ccc946181c329f823a39929ccb Mon Sep 17 00:00:00 2001 From: jaymode Date: Mon, 7 Mar 2016 09:34:53 -0500 Subject: [PATCH 02/11] fix compile due to core change in NodeInfo Original commit: elastic/x-pack-elasticsearch@3ff3fa63e6222e292b68db0bfcc492abdad74ae9 --- .../agent/resolver/cluster/ClusterStatsResolverTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java index 0971f8ce807..e35fb4a19d5 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java @@ -31,6 +31,7 @@ import org.elasticsearch.index.fielddata.FieldDataStats; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.indices.NodeIndicesStats; +import org.elasticsearch.ingest.core.IngestInfo; import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsMonitoringDoc; import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolverTestCase; @@ -112,7 +113,7 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa Settings.EMPTY, DummyOsInfo.INSTANCE, new ProcessInfo(randomInt(), randomBoolean()), JvmInfo.jvmInfo(), new ThreadPoolInfo(Collections.singletonList(new ThreadPool.Info("test_threadpool", ThreadPool.ThreadPoolType.FIXED, 5))), new TransportInfo(transportAddress, Collections.emptyMap()), new HttpInfo(transportAddress, randomLong()), - new PluginsAndModules()); + new PluginsAndModules(), new IngestInfo()); } From 101ff22546e26b74303216141e381c82707266f1 Mon Sep 17 00:00:00 2001 From: jaymode Date: Mon, 7 Mar 2016 10:53:07 -0500 Subject: [PATCH 03/11] fix compile after removal of versions < 2.0.0 Original commit: elastic/x-pack-elasticsearch@61e2814aacf611ae45f34f29d38f597ed2dcfd04 --- .../marvel/agent/exporter/http/HttpExporterTests.java | 7 ++++--- .../elasticsearch/marvel/support/VersionUtilsTests.java | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) 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 f55fdde6e2f..70a8e6edb57 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 @@ -292,7 +292,8 @@ public class HttpExporterTests extends MarvelIntegTestCase { logger.info("--> starting node"); // returning an unsupported cluster version - enqueueGetClusterVersionResponse(randomFrom(Version.V_0_18_0, Version.V_1_0_0, Version.V_1_4_0)); + enqueueGetClusterVersionResponse(randomFrom(Version.fromString("0.18.0"), Version.fromString("1.0.0"), + Version.fromString("1.4.0"))); String agentNode = internalCluster().startNode(builder); @@ -431,8 +432,8 @@ public class HttpExporterTests extends MarvelIntegTestCase { Version resolved = exporter.loadRemoteClusterVersion(host); assertTrue(resolved.equals(Version.CURRENT)); - final Version expected = randomFrom(Version.CURRENT, Version.V_0_18_0, Version.V_1_1_0, Version.V_1_2_4, - Version.V_1_4_5, Version.V_1_6_0); + final Version expected = randomFrom(Version.CURRENT, Version.V_2_0_0_beta1, Version.V_2_0_0_beta2, Version.V_2_0_0_rc1, + Version.V_2_0_0, Version.V_2_1_0, Version.V_2_2_0, Version.V_2_3_0); enqueueGetClusterVersionResponse(expected); resolved = exporter.loadRemoteClusterVersion(host); assertTrue(resolved.equals(expected)); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/support/VersionUtilsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/support/VersionUtilsTests.java index 6f0590efaca..722008a37b2 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/support/VersionUtilsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/support/VersionUtilsTests.java @@ -16,8 +16,9 @@ import static org.hamcrest.Matchers.equalTo; public class VersionUtilsTests extends ESTestCase { public void testParseVersion() { - List versions = randomSubsetOf(9, Version.V_0_18_0, Version.V_0_19_0, Version.V_1_0_1, Version.V_1_2_3, Version.V_1_3_2, - Version.V_1_4_5, Version.V_1_6_2, Version.V_1_7_2, Version.V_2_0_0); + List versions = randomSubsetOf(9, Version.V_2_0_0_beta1, Version.V_2_0_0_beta2, Version.V_2_0_0_rc1, Version.V_2_0_0, + Version.V_2_0_1, Version.V_2_0_2, Version.V_2_1_0, Version.V_2_1_1, Version.V_2_1_2, Version.V_2_2_0, Version.V_2_3_0, + Version.V_5_0_0); for (Version version : versions) { String output = createOutput(VersionUtils.VERSION_NUMBER_FIELD, version.toString()); assertThat(VersionUtils.parseVersion(output.getBytes(StandardCharsets.UTF_8)), equalTo(version)); From 2612edf4cbf412951f5629bb824ea47d95ca495b Mon Sep 17 00:00:00 2001 From: jaymode Date: Mon, 7 Mar 2016 12:15:06 -0500 Subject: [PATCH 04/11] test: blacklist the ingest default processors rest test This test assumes no modules are installed but the shield rest tests run with the modules installed. Original commit: elastic/x-pack-elasticsearch@2ba47fcd0f21756ff9415c9a551600a23caf01a1 --- elasticsearch/qa/shield-core-rest-tests/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/elasticsearch/qa/shield-core-rest-tests/build.gradle b/elasticsearch/qa/shield-core-rest-tests/build.gradle index 3e8c4bf42f1..ec109a9f19f 100644 --- a/elasticsearch/qa/shield-core-rest-tests/build.gradle +++ b/elasticsearch/qa/shield-core-rest-tests/build.gradle @@ -28,7 +28,8 @@ integTest { 'indices.shard_stores/10_basic/no indices test', 'cat.nodeattrs/10_basic/Test cat nodes attrs output', 'bulk/40_fields/Fields', - 'indices.get_alias/10_basic/Get alias against closed indices'].join(',') + 'indices.get_alias/10_basic/Get alias against closed indices', + 'ingest/10_crud/Check availability of default processors'].join(',') cluster { plugin 'x-pack', project(':x-plugins:elasticsearch:x-pack') From 03dcc5ea6785b83f2275634ea053720f5e790bb9 Mon Sep 17 00:00:00 2001 From: jaymode Date: Wed, 2 Mar 2016 13:30:02 -0500 Subject: [PATCH 05/11] shield: copy settings to tribe nodes The shield settings need to be copied down to the tribe nodes so that they are aware of the shield configuration. Otherwise there will be issues such as SSL not carrying over or authentication realms not being available. Closes elastic/elasticsearch#702 Original commit: elastic/x-pack-elasticsearch@7bd7674f3ec647300a65bd0856b359fbb45798fb --- .../java/org/elasticsearch/shield/Shield.java | 9 +++++++ .../shield/ShieldPluginSettingsTests.java | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/Shield.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/Shield.java index 2c6d3de6ef9..9cfa2f58159 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/Shield.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/Shield.java @@ -325,6 +325,7 @@ public class Shield { return; } + final Map settingsMap = settings.getAsMap(); for (Map.Entry tribeSettings : tribesSettings.entrySet()) { String tribePrefix = "tribe." + tribeSettings.getKey() + "."; @@ -352,6 +353,14 @@ public class Shield { //shield must be enabled on every tribe if it's enabled on the tribe node settingsBuilder.put(tribeEnabledSetting, true); } + + // we passed all the checks now we need to copy in all of the shield settings + for (Map.Entry entry : settingsMap.entrySet()) { + String key = entry.getKey(); + if (key.startsWith("shield.")) { + settingsBuilder.put(tribePrefix + key, entry.getValue()); + } + } } } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldPluginSettingsTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldPluginSettingsTests.java index bbdfeff048e..f9cb0e28196 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldPluginSettingsTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/ShieldPluginSettingsTests.java @@ -5,13 +5,16 @@ */ package org.elasticsearch.shield; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.XPackPlugin; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.Matchers.arrayContaining; public class ShieldPluginSettingsTests extends ESTestCase { @@ -106,4 +109,27 @@ public class ShieldPluginSettingsTests extends ESTestCase { assertThat(e.getMessage(), containsString(TRIBE_T1_SHIELD_ENABLED)); } } + + public void testShieldSettingsCopiedForTribeNodes() { + Settings settings = Settings.builder() + .put("tribe.t1.cluster.name", "non_existing") + .put("tribe.t2.cluster.name", "non_existing") + .put("shield.foo", "bar") + .put("shield.bar", "foo") + .putArray("shield.something.else.here", new String[] { "foo", "bar" }) + .build(); + + Shield shield = new Shield(settings); + Settings additionalSettings = shield.additionalSettings(); + + assertThat(additionalSettings.get("shield.foo"), nullValue()); + assertThat(additionalSettings.get("shield.bar"), nullValue()); + assertThat(additionalSettings.getAsArray("shield.something.else.here"), is(Strings.EMPTY_ARRAY)); + assertThat(additionalSettings.get("tribe.t1.shield.foo"), is("bar")); + assertThat(additionalSettings.get("tribe.t1.shield.bar"), is("foo")); + assertThat(additionalSettings.getAsArray("tribe.t1.shield.something.else.here"), arrayContaining("foo", "bar")); + assertThat(additionalSettings.get("tribe.t2.shield.foo"), is("bar")); + assertThat(additionalSettings.get("tribe.t2.shield.bar"), is("foo")); + assertThat(additionalSettings.getAsArray("tribe.t2.shield.something.else.here"), arrayContaining("foo", "bar")); + } } From 10644a2784d3a64cb3c5b65bd4d40e051e86c541 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Sun, 6 Mar 2016 21:57:18 +0100 Subject: [PATCH 06/11] Watcher: Fix correct setting of email attachment names Fix to ensure that the email attachment has a correctly set filename, which is also now explained in the documentation. In addition there is a check now for email attachments, that a filename can only be specified once, otherwise an exception is thrown. Closes elastic/elasticsearch#1503 Original commit: elastic/x-pack-elasticsearch@2a399058b3956e797eddef02ea2e42e8a2806c29 --- .../watcher/actions/email/DataAttachment.java | 4 +- .../service/attachment/DataAttachment.java | 1 - .../attachment/EmailAttachmentParser.java | 5 +++ .../service/attachment/EmailAttachments.java | 8 ++-- .../attachment/EmailAttachmentsParser.java | 14 ++++--- .../HttpEmailAttachementParser.java | 4 +- .../attachment/HttpRequestAttachment.java | 5 ++- .../actions/email/DataAttachmentTests.java | 4 +- .../actions/email/EmailActionTests.java | 8 ++-- .../attachment/DataAttachmentParserTests.java | 5 ++- .../EmailAttachmentParsersTests.java | 40 +++++++++++++++---- .../HttpEmailAttachementParserTests.java | 5 ++- 12 files changed, 70 insertions(+), 33 deletions(-) diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/DataAttachment.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/DataAttachment.java index 205c4d80d4f..a5480eb4ee7 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/DataAttachment.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/DataAttachment.java @@ -34,7 +34,7 @@ public enum DataAttachment implements ToXContent { @Override public Attachment create(String id, Map data) { - return new Attachment.XContent.Yaml(id, "data.yml", new Payload.Simple(data)); + return new Attachment.XContent.Yaml(id, id, new Payload.Simple(data)); } @Override @@ -51,7 +51,7 @@ public enum DataAttachment implements ToXContent { @Override public Attachment create(String id, Map data) { - return new Attachment.XContent.Json(id, "data.json", new Payload.Simple(data)); + return new Attachment.XContent.Json(id, id, new Payload.Simple(data)); } @Override diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachment.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachment.java index 618aa12a88e..258723f3415 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachment.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachment.java @@ -32,7 +32,6 @@ public class DataAttachment implements EmailAttachmentParser.EmailAttachment { } else { builder.field("format", "json"); } - return builder.endObject().endObject(); } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentParser.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentParser.java index ebde963ab9c..f8d864975d2 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentParser.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentParser.java @@ -25,6 +25,11 @@ public interface EmailAttachmentParser attachments; + private final Collection attachments; - public EmailAttachments(List attachments) { + public EmailAttachments(Collection attachments) { this.attachments = attachments; } - public List getAttachments() { + public Collection getAttachments() { return attachments; } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentsParser.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentsParser.java index 91834d239fe..fc795298072 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentsParser.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentsParser.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; import java.util.ArrayList; -import java.util.List; +import java.util.LinkedHashMap; import java.util.Map; public class EmailAttachmentsParser { @@ -25,7 +25,7 @@ public class EmailAttachmentsParser { } public EmailAttachments parse(XContentParser parser) throws IOException { - List attachments = new ArrayList<>(); + Map attachments = new LinkedHashMap<>(); String currentFieldName = null; XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -41,17 +41,21 @@ public class EmailAttachmentsParser { EmailAttachmentParser emailAttachmentParser = parsers.get(currentAttachmentType); if (emailAttachmentParser == null) { - throw new ElasticsearchParseException("Cannot parse attachment of type " + currentAttachmentType); + throw new ElasticsearchParseException("Cannot parse attachment of type [{}]", currentAttachmentType); } EmailAttachmentParser.EmailAttachment emailAttachment = emailAttachmentParser.parse(currentFieldName, parser); - attachments.add(emailAttachment); + if (attachments.containsKey(emailAttachment.id())) { + throw new ElasticsearchParseException("Attachment with id [{}] has already been created, must be renamed", + emailAttachment.id()); + } + attachments.put(emailAttachment.id(), emailAttachment); // one further to skip the end_object from the attachment parser.nextToken(); } } } - return new EmailAttachments(attachments); + return new EmailAttachments(new ArrayList<>(attachments.values())); } public Map getParsers() { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/HttpEmailAttachementParser.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/HttpEmailAttachementParser.java index 0c3fa669adf..0516015ec99 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/HttpEmailAttachementParser.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/email/service/attachment/HttpEmailAttachementParser.java @@ -94,7 +94,7 @@ public class HttpEmailAttachementParser implements EmailAttachmentParser data = singletonMap("key", "value"); Attachment attachment = DataAttachment.JSON.create("data", data); 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 984c443c2e3..ed4d9867233 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 @@ -481,7 +481,7 @@ public class EmailActionTests extends ESTestCase { } public void testThatDataAttachmentGetsAttachedWithId() throws Exception { - String attachmentId = "my_attachment"; + String attachmentId = randomAsciiOfLength(10) + ".yml"; XContentBuilder builder = jsonBuilder().startObject() .startObject("attachments") @@ -506,9 +506,9 @@ public class EmailActionTests extends ESTestCase { EmailAction.Result.Success successResult = (EmailAction.Result.Success) result; Map attachments = successResult.email().attachments(); - assertThat(attachments, hasKey("my_attachment")); - Attachment dataAttachment = attachments.get("my_attachment"); - assertThat(dataAttachment.name(), is("data.yml")); + assertThat(attachments, hasKey(attachmentId)); + Attachment dataAttachment = attachments.get(attachmentId); + assertThat(dataAttachment.name(), is(attachmentId)); assertThat(dataAttachment.type(), is("yaml")); assertThat(dataAttachment.contentType(), is("application/yaml")); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachmentParserTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachmentParserTests.java index 846a1d6b04e..7cf3ecd5e80 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachmentParserTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/DataAttachmentParserTests.java @@ -11,7 +11,9 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; @@ -36,7 +38,8 @@ public class DataAttachmentParserTests extends ESTestCase { assertThat(emailAttachments.getAttachments(), hasSize(1)); XContentBuilder toXcontentBuilder = jsonBuilder().startObject(); - emailAttachments.getAttachments().get(0).toXContent(toXcontentBuilder, ToXContent.EMPTY_PARAMS); + List attachments = new ArrayList<>(emailAttachments.getAttachments()); + attachments.get(0).toXContent(toXcontentBuilder, ToXContent.EMPTY_PARAMS); toXcontentBuilder.endObject(); assertThat(toXcontentBuilder.string(), is(builder.string())); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentParsersTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentParsersTests.java index 7566f161099..040346d5ccd 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentParsersTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/EmailAttachmentParsersTests.java @@ -61,15 +61,15 @@ public class EmailAttachmentParsersTests extends ESTestCase { EmailAttachments attachments = parser.parse(xContentParser); assertThat(attachments.getAttachments(), hasSize(2)); - EmailAttachmentParser.EmailAttachment emailAttachment = attachments.getAttachments().get(0); + List emailAttachments = new ArrayList<>(attachments.getAttachments()); + EmailAttachmentParser.EmailAttachment emailAttachment = emailAttachments.get(0); assertThat(emailAttachment, instanceOf(TestEmailAttachment.class)); Attachment attachment = parsers.get("test").toAttachment(ctx, new Payload.Simple(), emailAttachment); assertThat(attachment.name(), is("my-id")); assertThat(attachment.contentType(), is("personalContentType")); - assertThat(parsers.get("test").toAttachment(ctx, new Payload.Simple(), - attachments.getAttachments().get(1)).id(), is("my-other-id")); + assertThat(parsers.get("test").toAttachment(ctx, new Payload.Simple(), emailAttachments.get(1)).id(), is("my-other-id")); } public void testThatUnknownParserThrowsException() throws IOException { @@ -84,13 +84,13 @@ public class EmailAttachmentParsersTests extends ESTestCase { parser.parse(xContentParser); fail("Expected random parser of type [" + type + "] to throw an exception"); } catch (ElasticsearchParseException e) { - assertThat(e.getMessage(), containsString("Cannot parse attachment of type " + type)); + assertThat(e.getMessage(), containsString("Cannot parse attachment of type [" + type + "]")); } } public void testThatToXContentSerializationWorks() throws Exception { List attachments = new ArrayList<>(); - attachments.add(new DataAttachment("my-id", org.elasticsearch.watcher.actions.email.DataAttachment.JSON)); + attachments.add(new DataAttachment("my-name.json", org.elasticsearch.watcher.actions.email.DataAttachment.JSON)); HttpRequestTemplate requestTemplate = HttpRequestTemplate.builder("localhost", 80).scheme(Scheme.HTTP).path("/").build(); HttpRequestAttachment httpRequestAttachment = new HttpRequestAttachment("other-id", requestTemplate, null); @@ -100,13 +100,36 @@ public class EmailAttachmentParsersTests extends ESTestCase { XContentBuilder builder = jsonBuilder(); emailAttachments.toXContent(builder, ToXContent.EMPTY_PARAMS); logger.info("JSON is: " + builder.string()); - assertThat(builder.string(), containsString("my-id")); + assertThat(builder.string(), containsString("my-name.json")); assertThat(builder.string(), containsString("json")); assertThat(builder.string(), containsString("other-id")); assertThat(builder.string(), containsString("localhost")); assertThat(builder.string(), containsString("/")); } + public void testThatTwoAttachmentsWithTheSameIdThrowError() throws Exception { + Map parsers = new HashMap<>(); + parsers.put("test", new TestEmailAttachmentParser()); + EmailAttachmentsParser parser = new EmailAttachmentsParser(parsers); + + List attachments = new ArrayList<>(); + attachments.add(new TestEmailAttachment("my-name.json", "value")); + attachments.add(new TestEmailAttachment("my-name.json", "value")); + + EmailAttachments emailAttachments = new EmailAttachments(attachments); + XContentBuilder builder = jsonBuilder(); + emailAttachments.toXContent(builder, ToXContent.EMPTY_PARAMS); + logger.info("JSON is: " + builder.string()); + + XContentParser xContentParser = JsonXContent.jsonXContent.createParser(builder.bytes()); + try { + parser.parse(xContentParser); + fail("Expected parser to fail but did not happen"); + } catch (ElasticsearchParseException e) { + assertThat(e.getMessage(), is("Attachment with id [my-name.json] has already been created, must be renamed")); + } + } + public class TestEmailAttachmentParser implements EmailAttachmentParser { @Override @@ -138,7 +161,7 @@ public class EmailAttachmentParsersTests extends ESTestCase { @Override public Attachment toAttachment(WatchExecutionContext ctx, Payload payload, TestEmailAttachment attachment) { - return new Attachment.Bytes(attachment.getId(), attachment.getValue().getBytes(Charsets.UTF_8), "personalContentType"); + return new Attachment.Bytes(attachment.id(), attachment.getValue().getBytes(Charsets.UTF_8), "personalContentType"); } } @@ -165,7 +188,8 @@ public class EmailAttachmentParsersTests extends ESTestCase { return value; } - public String getId() { + @Override + public String id() { return id; } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/HttpEmailAttachementParserTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/HttpEmailAttachementParserTests.java index fd5ea57b9d1..1d41d3e3060 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/HttpEmailAttachementParserTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/email/service/attachment/HttpEmailAttachementParserTests.java @@ -21,7 +21,9 @@ import org.elasticsearch.watcher.support.secret.SecretService; import org.elasticsearch.watcher.test.MockTextTemplateEngine; import org.junit.Before; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import static java.nio.charset.StandardCharsets.UTF_8; @@ -83,7 +85,8 @@ public class HttpEmailAttachementParserTests extends ESTestCase { assertThat(emailAttachments.getAttachments(), hasSize(1)); XContentBuilder toXcontentBuilder = jsonBuilder().startObject(); - emailAttachments.getAttachments().get(0).toXContent(toXcontentBuilder, ToXContent.EMPTY_PARAMS); + List attachments = new ArrayList<>(emailAttachments.getAttachments()); + attachments.get(0).toXContent(toXcontentBuilder, ToXContent.EMPTY_PARAMS); toXcontentBuilder.endObject(); assertThat(toXcontentBuilder.string(), is(builder.string())); } From f4eb0e7c7cf75ac36b38410d6309c9cad2e95236 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 8 Mar 2016 12:04:28 +0100 Subject: [PATCH 07/11] Docs: Mention option to enable scripting for watcher-only Deep down buried there is an option to not only allow global script execution, but also allow a single scripting language for watcher only. It is time to document it as well. Renamed this option to `script.engine.groovy.inline.xpack_watch` to align with xpack renaming. Closes elastic/elasticsearch#1422 Original commit: elastic/x-pack-elasticsearch@845eb5a0c0ceae30fd5acd9a7886a316c807cfe0 --- .../watcher/support/init/proxy/ScriptServiceProxy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 07d745476fe..f7448f92680 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 @@ -65,7 +65,7 @@ public class ScriptServiceProxy implements InitializingService.Initializable { service.executable(script, WatcherScriptContext.CTX, emptyMap())); } - public static final ScriptContext.Plugin INSTANCE = new ScriptContext.Plugin("elasticsearch-watcher", "watch"); + public static final ScriptContext.Plugin INSTANCE = new ScriptContext.Plugin("xpack", "watch"); private static class WatcherScriptContext implements ScriptContext { From 146f91f7307f3f7d8f5d088850c00d5876166383 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Tue, 8 Mar 2016 13:34:13 +0100 Subject: [PATCH 08/11] Watcher: Rename ClientProxy to WatcherClientProxy Original commit: elastic/x-pack-elasticsearch@84c17d1bc046ddba39b687690a89178501e044b6 --- .../org/elasticsearch/messy/tests/SearchInputIT.java | 10 +++++----- .../elasticsearch/messy/tests/SearchTransformIT.java | 12 ++++++------ .../watcher/actions/index/ExecutableIndexAction.java | 6 +++--- .../watcher/actions/index/IndexActionFactory.java | 6 +++--- .../watcher/execution/TriggeredWatchStore.java | 6 +++--- .../elasticsearch/watcher/history/HistoryStore.java | 6 +++--- .../watcher/input/search/ExecutableSearchInput.java | 6 +++--- .../watcher/input/search/SearchInputFactory.java | 7 ++++--- .../support/WatcherIndexTemplateRegistry.java | 6 +++--- .../watcher/support/init/InitializingModule.java | 6 +++--- .../{ClientProxy.java => WatcherClientProxy.java} | 8 ++++---- .../transform/search/ExecutableSearchTransform.java | 7 ++++--- .../transform/search/SearchTransformFactory.java | 8 ++++---- .../org/elasticsearch/watcher/watch/WatchStore.java | 6 +++--- .../watcher/actions/index/IndexActionTests.java | 10 +++++----- .../watcher/actions/webhook/WebhookActionTests.java | 12 ++++-------- .../watcher/execution/TriggeredWatchStoreTests.java | 6 +++--- .../watcher/history/HistoryStoreTests.java | 6 +++--- .../elasticsearch/watcher/test/WatcherTestUtils.java | 6 +++--- .../elasticsearch/watcher/watch/WatchStoreTests.java | 6 +++--- .../org/elasticsearch/watcher/watch/WatchTests.java | 6 +++--- 21 files changed, 75 insertions(+), 77 deletions(-) rename elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/{ClientProxy.java => WatcherClientProxy.java} (95%) 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 5eccb24b38c..4129f3a1c31 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 @@ -34,7 +34,7 @@ import org.elasticsearch.watcher.input.search.SearchInput; 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.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.support.text.TextTemplate; import org.elasticsearch.watcher.trigger.schedule.IntervalSchedule; import org.elasticsearch.watcher.trigger.schedule.ScheduleTrigger; @@ -132,7 +132,7 @@ public class SearchInputIT extends ESIntegTestCase { .source(searchSourceBuilder); ExecutableSearchInput searchInput = new ExecutableSearchInput(new SearchInput(request, null, null, null), logger, - ClientProxy.of(client()), null); + WatcherClientProxy.of(client()), null); WatchExecutionContext ctx = new TriggeredExecutionContext( new Watch("test-watch", new ScheduleTrigger(new IntervalSchedule(new IntervalSchedule.Interval(1, IntervalSchedule.Interval.Unit.MINUTES))), @@ -244,7 +244,7 @@ public class SearchInputIT extends ESIntegTestCase { .source(searchSourceBuilder); ExecutableSearchInput searchInput = new ExecutableSearchInput(new SearchInput(request, null, null, null), logger, - ClientProxy.of(client()), null); + WatcherClientProxy.of(client()), null); WatchExecutionContext ctx = new TriggeredExecutionContext( new Watch("test-watch", new ScheduleTrigger(new IntervalSchedule(new IntervalSchedule.Interval(1, IntervalSchedule.Interval.Unit.MINUTES))), @@ -281,7 +281,7 @@ public class SearchInputIT extends ESIntegTestCase { parser.nextToken(); IndicesQueriesRegistry indicesQueryRegistry = internalCluster().getInstance(IndicesQueriesRegistry.class); - SearchInputFactory factory = new SearchInputFactory(Settings.EMPTY, ClientProxy.of(client()), indicesQueryRegistry, null); + SearchInputFactory factory = new SearchInputFactory(Settings.EMPTY, WatcherClientProxy.of(client()), indicesQueryRegistry, null); SearchInput searchInput = factory.parseInput("_id", parser); assertEquals(SearchInput.TYPE, searchInput.type()); @@ -311,7 +311,7 @@ public class SearchInputIT extends ESIntegTestCase { SearchInput si = siBuilder.build(); - ExecutableSearchInput searchInput = new ExecutableSearchInput(si, logger, ClientProxy.of(client()), null); + ExecutableSearchInput searchInput = new ExecutableSearchInput(si, logger, WatcherClientProxy.of(client()), null); return searchInput.execute(ctx, new Payload.Simple()); } 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 7a86d20879d..df2bfd00382 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 @@ -37,7 +37,7 @@ import org.elasticsearch.watcher.execution.TriggeredExecutionContext; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.input.simple.ExecutableSimpleInput; import org.elasticsearch.watcher.input.simple.SimpleInput; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.support.text.TextTemplate; import org.elasticsearch.watcher.transform.Transform; import org.elasticsearch.watcher.transform.TransformBuilders; @@ -154,7 +154,7 @@ public class SearchTransformIT extends ESIntegTestCase { SearchRequest request = Requests.searchRequest("idx").source(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery())); SearchTransform searchTransform = TransformBuilders.searchTransform(request).build(); - ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, ClientProxy.of(client()), null); + ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, WatcherClientProxy.of(client()), null); WatchExecutionContext ctx = mockExecutionContext("_name", EMPTY_PAYLOAD); @@ -188,7 +188,7 @@ public class SearchTransformIT extends ESIntegTestCase { new SearchSourceBuilder().query(QueryBuilders.wrapperQuery(jsonBuilder().startObject() .startObject("_unknown_query_").endObject().endObject().bytes()))); SearchTransform searchTransform = TransformBuilders.searchTransform(request).build(); - ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, ClientProxy.of(client()), null); + ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, WatcherClientProxy.of(client()), null); WatchExecutionContext ctx = mockExecutionContext("_name", EMPTY_PAYLOAD); @@ -252,7 +252,7 @@ public class SearchTransformIT extends ESIntegTestCase { .must(termQuery("value", "{{ctx.payload.value}}")))); SearchTransform searchTransform = TransformBuilders.searchTransform(request).build(); - ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, ClientProxy.of(client()), null); + ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, WatcherClientProxy.of(client()), null); ScheduleTriggerEvent event = new ScheduleTriggerEvent("_name", parseDate("2015-01-04T00:00:00", UTC), parseDate("2015-01-01T00:00:00", UTC)); @@ -318,7 +318,7 @@ public class SearchTransformIT extends ESIntegTestCase { parser.nextToken(); IndicesQueriesRegistry indicesQueryRegistry = internalCluster().getInstance(IndicesQueriesRegistry.class); - SearchTransformFactory transformFactory = new SearchTransformFactory(Settings.EMPTY, ClientProxy.of(client()), + SearchTransformFactory transformFactory = new SearchTransformFactory(Settings.EMPTY, WatcherClientProxy.of(client()), indicesQueryRegistry, null); ExecutableSearchTransform executable = transformFactory.parseExecutable("_id", parser); @@ -482,7 +482,7 @@ public class SearchTransformIT extends ESIntegTestCase { SearchTransform searchTransform = TransformBuilders.searchTransform(request).build(); ExecutableSearchTransform executableSearchTransform = new ExecutableSearchTransform(searchTransform, logger, - ClientProxy.of(client()), null); + WatcherClientProxy.of(client()), null); return executableSearchTransform.execute(ctx, Payload.Simple.EMPTY); } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/index/ExecutableIndexAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/index/ExecutableIndexAction.java index 144170c7f99..c81979989ad 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/index/ExecutableIndexAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/index/ExecutableIndexAction.java @@ -21,7 +21,7 @@ import org.elasticsearch.watcher.actions.ExecutableAction; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.ArrayObjectIterator; import org.elasticsearch.watcher.support.WatcherDateTimeUtils; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.support.xcontent.XContentSource; import org.elasticsearch.watcher.watch.Payload; @@ -34,10 +34,10 @@ import static org.elasticsearch.watcher.support.Exceptions.illegalState; public class ExecutableIndexAction extends ExecutableAction { - private final ClientProxy client; + private final WatcherClientProxy client; private final TimeValue timeout; - public ExecutableIndexAction(IndexAction action, ESLogger logger, ClientProxy client, @Nullable TimeValue defaultTimeout) { + public ExecutableIndexAction(IndexAction action, ESLogger logger, WatcherClientProxy client, @Nullable TimeValue defaultTimeout) { super(action, logger); this.client = client; this.timeout = action.timeout != null ? action.timeout : defaultTimeout; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/index/IndexActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/index/IndexActionFactory.java index c8c4129aaa4..23e09a6ee71 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/index/IndexActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/actions/index/IndexActionFactory.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.actions.ActionFactory; import org.elasticsearch.watcher.actions.email.ExecutableEmailAction; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import java.io.IOException; @@ -21,11 +21,11 @@ import java.io.IOException; */ public class IndexActionFactory extends ActionFactory { - private final ClientProxy client; + private final WatcherClientProxy client; private final TimeValue defaultTimeout; @Inject - public IndexActionFactory(Settings settings, ClientProxy client) { + public IndexActionFactory(Settings settings, WatcherClientProxy client) { super(Loggers.getLogger(ExecutableEmailAction.class, settings)); this.client = client; this.defaultTimeout = settings.getAsTime("watcher.actions.index.default_timeout", null); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/execution/TriggeredWatchStore.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/execution/TriggeredWatchStore.java index cca13bdc6e6..6a416c98e25 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/execution/TriggeredWatchStore.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/execution/TriggeredWatchStore.java @@ -26,7 +26,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.sort.SortBuilders; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import java.io.IOException; import java.util.ArrayList; @@ -47,7 +47,7 @@ public class TriggeredWatchStore extends AbstractComponent { public static final String DOC_TYPE = "triggered_watch"; private final int scrollSize; - private final ClientProxy client; + private final WatcherClientProxy client; private final TimeValue scrollTimeout; private final TriggeredWatch.Parser triggeredWatchParser; @@ -57,7 +57,7 @@ public class TriggeredWatchStore extends AbstractComponent { private final AtomicBoolean started = new AtomicBoolean(false); @Inject - public TriggeredWatchStore(Settings settings, ClientProxy client, TriggeredWatch.Parser triggeredWatchParser) { + public TriggeredWatchStore(Settings settings, WatcherClientProxy client, TriggeredWatch.Parser triggeredWatchParser) { super(settings); this.scrollSize = settings.getAsInt("watcher.execution.scroll.size", 100); this.client = client; 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 08c6b272860..d067c2c7c4c 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,7 +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.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; @@ -36,7 +36,7 @@ public class HistoryStore extends AbstractComponent { static final DateTimeFormatter indexTimeFormat = DateTimeFormat.forPattern("YYYY.MM.dd"); - private final ClientProxy client; + private final WatcherClientProxy client; private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); private final Lock putUpdateLock = readWriteLock.readLock(); @@ -44,7 +44,7 @@ public class HistoryStore extends AbstractComponent { private final AtomicBoolean started = new AtomicBoolean(false); @Inject - public HistoryStore(Settings settings, ClientProxy client) { + public HistoryStore(Settings settings, WatcherClientProxy client) { super(settings); this.client = client; } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/search/ExecutableSearchInput.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/search/ExecutableSearchInput.java index 9679aeef896..201dc0cf2cc 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/search/ExecutableSearchInput.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/search/ExecutableSearchInput.java @@ -20,7 +20,7 @@ import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.input.ExecutableInput; import org.elasticsearch.watcher.support.WatcherUtils; import org.elasticsearch.watcher.support.XContentFilterKeysUtils; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.watch.Payload; import java.util.Map; @@ -34,10 +34,10 @@ public class ExecutableSearchInput extends ExecutableInput { - private final ClientProxy client; + private final WatcherClientProxy client; private final TimeValue defaultTimeout; private IndicesQueriesRegistry queryRegistry; private AggregatorParsers aggParsers; @Inject - public SearchInputFactory(Settings settings, ClientProxy client, IndicesQueriesRegistry queryRegistry, AggregatorParsers aggParsers) { + public SearchInputFactory(Settings settings, WatcherClientProxy client, IndicesQueriesRegistry queryRegistry, + AggregatorParsers aggParsers) { super(Loggers.getLogger(ExecutableSimpleInput.class, settings)); this.client = client; this.queryRegistry = queryRegistry; 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 b8264d00a7c..3e93f0d5371 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 @@ -20,7 +20,7 @@ import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.watch.WatchStore; import java.io.InputStream; @@ -38,7 +38,7 @@ import static java.util.Collections.unmodifiableSet; public class WatcherIndexTemplateRegistry extends AbstractComponent implements ClusterStateListener { private static final String FORBIDDEN_INDEX_SETTING = "index.mapper.dynamic"; - private final ClientProxy client; + private final WatcherClientProxy client; private final ThreadPool threadPool; private final ClusterService clusterService; private final Set indexTemplates; @@ -47,7 +47,7 @@ public class WatcherIndexTemplateRegistry extends AbstractComponent implements C @Inject public WatcherIndexTemplateRegistry(Settings settings, ClusterSettings clusterSettings, ClusterService clusterService, - ThreadPool threadPool, ClientProxy client, Set configs) { + ThreadPool threadPool, WatcherClientProxy client, Set configs) { super(settings); this.client = client; this.threadPool = threadPool; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingModule.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingModule.java index 1b7dde099ec..5309b7ae3f8 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingModule.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingModule.java @@ -8,7 +8,7 @@ package org.elasticsearch.watcher.support.init; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.watcher.input.chain.ChainInputFactory; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; import org.elasticsearch.watcher.transform.chain.ChainTransformFactory; @@ -20,13 +20,13 @@ public class InitializingModule extends AbstractModule { @Override protected void configure() { - bind(ClientProxy.class).asEagerSingleton(); + bind(WatcherClientProxy.class).asEagerSingleton(); bind(ScriptServiceProxy.class).asEagerSingleton(); bind(ChainInputFactory.class).asEagerSingleton(); Multibinder mbinder = Multibinder.newSetBinder(binder(), InitializingService.Initializable.class); - mbinder.addBinding().to(ClientProxy.class); + mbinder.addBinding().to(WatcherClientProxy.class); mbinder.addBinding().to(ScriptServiceProxy.class); mbinder.addBinding().to(ChainTransformFactory.class); mbinder.addBinding().to(ChainInputFactory.class); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/ClientProxy.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/WatcherClientProxy.java similarity index 95% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/ClientProxy.java rename to elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/WatcherClientProxy.java index c22da70401f..10e4c362da9 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/ClientProxy.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/WatcherClientProxy.java @@ -37,7 +37,7 @@ import org.elasticsearch.watcher.support.init.InitializingService; * A lazily initialized proxy to an elasticsearch {@link Client}. Inject this proxy whenever a client * needs to injected to be avoid circular dependencies issues. */ -public class ClientProxy implements InitializingService.Initializable { +public class WatcherClientProxy implements InitializingService.Initializable { private final TimeValue defaultSearchTimeout; private final TimeValue defaultIndexTimeout; @@ -45,7 +45,7 @@ public class ClientProxy implements InitializingService.Initializable { private InternalClient client; @Inject - public ClientProxy(Settings settings) { + public WatcherClientProxy(Settings settings) { defaultSearchTimeout = settings.getAsTime("watcher.internal.ops.search.default_timeout", TimeValue.timeValueSeconds(30)); defaultIndexTimeout = settings.getAsTime("watcher.internal.ops.index.default_timeout", TimeValue.timeValueSeconds(60)); defaultBulkTimeout = settings.getAsTime("watcher.internal.ops.bulk.default_timeout", TimeValue.timeValueSeconds(120)); @@ -54,8 +54,8 @@ public class ClientProxy implements InitializingService.Initializable { /** * Creates a proxy to the given internal client (can be used for testing) */ - public static ClientProxy of(Client client) { - ClientProxy proxy = new ClientProxy(Settings.EMPTY); + public static WatcherClientProxy of(Client client) { + WatcherClientProxy proxy = new WatcherClientProxy(Settings.EMPTY); proxy.client = client instanceof InternalClient ? (InternalClient) client : new InternalClient.Insecure(client); return proxy; } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/search/ExecutableSearchTransform.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/search/ExecutableSearchTransform.java index 0ee96fdbda1..e4a82796709 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/search/ExecutableSearchTransform.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/search/ExecutableSearchTransform.java @@ -13,7 +13,7 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.WatcherUtils; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.transform.ExecutableTransform; import org.elasticsearch.watcher.watch.Payload; @@ -24,10 +24,11 @@ public class ExecutableSearchTransform extends ExecutableTransform { - protected final ClientProxy client; + protected final WatcherClientProxy client; private final TimeValue defaultTimeout; private IndicesQueriesRegistry queryRegistry; private AggregatorParsers aggParsers; @Inject - public SearchTransformFactory(Settings settings, ClientProxy client, IndicesQueriesRegistry queryRegistry, - AggregatorParsers aggParsers) { + public SearchTransformFactory(Settings settings, WatcherClientProxy client, IndicesQueriesRegistry queryRegistry, + AggregatorParsers aggParsers) { super(Loggers.getLogger(ExecutableSearchTransform.class, settings)); this.client = client; this.queryRegistry = queryRegistry; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchStore.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchStore.java index 49a18916a4f..d7cc1c14ba8 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchStore.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchStore.java @@ -31,7 +31,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.sort.SortBuilders; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import java.io.IOException; import java.util.Collection; @@ -49,7 +49,7 @@ public class WatchStore extends AbstractComponent { public static final String INDEX = ".watches"; public static final String DOC_TYPE = "watch"; - private final ClientProxy client; + private final WatcherClientProxy client; private final Watch.Parser watchParser; private final ConcurrentMap watches; @@ -59,7 +59,7 @@ public class WatchStore extends AbstractComponent { private final TimeValue scrollTimeout; @Inject - public WatchStore(Settings settings, ClientProxy client, Watch.Parser watchParser) { + public WatchStore(Settings settings, WatcherClientProxy client, Watch.Parser watchParser) { super(settings); this.client = client; this.watchParser = watchParser; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/index/IndexActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/index/IndexActionTests.java index 949d4f1e3fc..1e13e2e4af6 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/index/IndexActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/actions/index/IndexActionTests.java @@ -20,7 +20,7 @@ import org.elasticsearch.watcher.actions.Action; import org.elasticsearch.watcher.actions.Action.Result.Status; import org.elasticsearch.watcher.execution.WatchExecutionContext; import org.elasticsearch.watcher.support.WatcherDateTimeUtils; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.support.xcontent.XContentSource; import org.elasticsearch.watcher.test.WatcherTestUtils; import org.elasticsearch.watcher.watch.Payload; @@ -72,7 +72,7 @@ public class IndexActionTests extends ESIntegTestCase { } IndexAction action = new IndexAction("test-index", "test-type", timestampField, null, null); - ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, ClientProxy.of(client()), null); + ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, WatcherClientProxy.of(client()), null); DateTime executionTime = DateTime.now(UTC); Payload payload = randomBoolean() ? new Payload.Simple("foo", "bar") : new Payload.Simple("_doc", singletonMap("foo", "bar")); WatchExecutionContext ctx = WatcherTestUtils.mockExecutionContext("_id", executionTime, payload); @@ -132,7 +132,7 @@ public class IndexActionTests extends ESIntegTestCase { ); IndexAction action = new IndexAction("test-index", "test-type", timestampField, null, null); - ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, ClientProxy.of(client()), null); + ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, WatcherClientProxy.of(client()), null); DateTime executionTime = DateTime.now(UTC); WatchExecutionContext ctx = WatcherTestUtils.mockExecutionContext("_id", executionTime, new Payload.Simple("_doc", list)); @@ -196,7 +196,7 @@ public class IndexActionTests extends ESIntegTestCase { } builder.endObject(); - IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, ClientProxy.of(client())); + IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, WatcherClientProxy.of(client())); XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); parser.nextToken(); @@ -224,7 +224,7 @@ public class IndexActionTests extends ESIntegTestCase { } } builder.endObject(); - IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, ClientProxy.of(client())); + IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, WatcherClientProxy.of(client())); XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); parser.nextToken(); try { 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 431d52b59c7..8a418cc6348 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 @@ -15,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.env.Environment; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.actions.Action; import org.elasticsearch.watcher.actions.Action.Result.Status; import org.elasticsearch.watcher.actions.email.service.Attachment; @@ -32,12 +31,10 @@ import org.elasticsearch.watcher.support.http.HttpRequestTemplate; import org.elasticsearch.watcher.support.http.HttpResponse; import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry; import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.support.secret.SecretService; import org.elasticsearch.watcher.support.text.TextTemplate; import org.elasticsearch.watcher.support.text.TextTemplateEngine; -import org.elasticsearch.watcher.support.text.DefaultTextTemplateEngine; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.watcher.test.MockTextTemplateEngine; import org.elasticsearch.watcher.test.WatcherTestUtils; @@ -46,7 +43,6 @@ import org.elasticsearch.watcher.watch.Payload; import org.elasticsearch.watcher.watch.Watch; import org.hamcrest.Matchers; import org.joda.time.DateTime; -import org.junit.After; import org.junit.Before; import javax.mail.internet.AddressException; @@ -242,7 +238,7 @@ public class WebhookActionTests extends ESTestCase { ExecutableWebhookAction executable = new ExecutableWebhookAction(action, logger, httpClient, templateEngine); String watchId = "test_url_encode" + randomAsciiOfLength(10); - Watch watch = createWatch(watchId, mock(ClientProxy.class), "account1"); + Watch watch = createWatch(watchId, mock(WatcherClientProxy.class), "account1"); WatchExecutionContext ctx = new TriggeredExecutionContext(watch, new DateTime(UTC), new ScheduleTriggerEvent(watchId, new DateTime(UTC), new DateTime(UTC)), timeValueSeconds(5)); executable.execute("_id", ctx, new Payload.Simple()); @@ -268,14 +264,14 @@ public class WebhookActionTests extends ESTestCase { ExecutableWebhookAction executable = new ExecutableWebhookAction(action, logger, client, templateEngine); - Watch watch = createWatch(watchId, mock(ClientProxy.class), "account1"); + Watch watch = createWatch(watchId, mock(WatcherClientProxy.class), "account1"); WatchExecutionContext ctx = new TriggeredExecutionContext(watch, new DateTime(UTC), new ScheduleTriggerEvent(watchId, new DateTime(UTC), new DateTime(UTC)), timeValueSeconds(5)); Action.Result result = executable.execute("_id", ctx, new Payload.Simple()); assertThat(result, Matchers.instanceOf(WebhookAction.Result.Success.class)); } - private Watch createWatch(String watchId, ClientProxy client, final String account) throws AddressException, IOException { + private Watch createWatch(String watchId, WatcherClientProxy client, final String account) throws AddressException, IOException { return WatcherTestUtils.createTestWatch(watchId, client, ExecuteScenario.Success.client(), diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/execution/TriggeredWatchStoreTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/execution/TriggeredWatchStoreTests.java index 52808e16453..02dac16174a 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/execution/TriggeredWatchStoreTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/execution/TriggeredWatchStoreTests.java @@ -33,7 +33,7 @@ import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.InternalSearchHits; import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.hamcrest.core.IsNull; import org.junit.Before; @@ -53,13 +53,13 @@ import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; public class TriggeredWatchStoreTests extends ESTestCase { - private ClientProxy clientProxy; + private WatcherClientProxy clientProxy; private TriggeredWatch.Parser parser; private TriggeredWatchStore triggeredWatchStore; @Before public void init() { - clientProxy = mock(ClientProxy.class); + clientProxy = mock(WatcherClientProxy.class); parser = mock(TriggeredWatch.Parser.class); triggeredWatchStore = new TriggeredWatchStore(Settings.EMPTY, clientProxy, parser); triggeredWatchStore.start(); 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 d659a11c6ef..4fe7bbcdfe6 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,7 +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.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent; import org.joda.time.DateTime; import org.junit.Before; @@ -31,11 +31,11 @@ import static org.mockito.Mockito.when; */ public class HistoryStoreTests extends ESTestCase { private HistoryStore historyStore; - private ClientProxy clientProxy; + private WatcherClientProxy clientProxy; @Before public void init() { - clientProxy = mock(ClientProxy.class); + clientProxy = mock(WatcherClientProxy.class); historyStore = new HistoryStore(Settings.EMPTY, clientProxy); historyStore.start(); } 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 9109d23b851..4a465bdb895 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 @@ -50,7 +50,7 @@ import org.elasticsearch.watcher.support.WatcherUtils; 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.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; import org.elasticsearch.watcher.support.secret.Secret; import org.elasticsearch.watcher.support.text.TextTemplate; @@ -172,11 +172,11 @@ public final class WatcherTestUtils { public static Watch createTestWatch(String watchName, HttpClient httpClient, EmailService emailService, ESLogger logger) throws AddressException { - return createTestWatch(watchName, ClientProxy.of(ESIntegTestCase.client()), httpClient, emailService, logger); + return createTestWatch(watchName, WatcherClientProxy.of(ESIntegTestCase.client()), httpClient, emailService, logger); } - public static Watch createTestWatch(String watchName, ClientProxy client, HttpClient httpClient, EmailService emailService, + public static Watch createTestWatch(String watchName, WatcherClientProxy client, HttpClient httpClient, EmailService emailService, ESLogger logger) throws AddressException { SearchRequest conditionRequest = newInputSearchRequest("my-condition-index").source(searchSource().query(matchAllQuery())); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchStoreTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchStoreTests.java index 9db13a5b27d..faa42d79ed4 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchStoreTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/watch/WatchStoreTests.java @@ -32,7 +32,7 @@ import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.InternalSearchHits; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.watcher.support.init.proxy.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.junit.Before; import java.util.Collections; @@ -52,12 +52,12 @@ import static org.mockito.Mockito.when; */ public class WatchStoreTests extends ESTestCase { private WatchStore watchStore; - private ClientProxy clientProxy; + private WatcherClientProxy clientProxy; private Watch.Parser parser; @Before public void init() { - clientProxy = mock(ClientProxy.class); + clientProxy = mock(WatcherClientProxy.class); parser = mock(Watch.Parser.class); watchStore = new WatchStore(Settings.EMPTY, clientProxy, parser); } 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 c1b00c92df9..8dfa5749660 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 @@ -76,7 +76,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.ClientProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; import org.elasticsearch.watcher.support.secret.SecretService; import org.elasticsearch.watcher.support.text.TextTemplate; @@ -141,7 +141,7 @@ import static org.mockito.Mockito.mock; public class WatchTests extends ESTestCase { private ScriptServiceProxy scriptService; - private ClientProxy client; + private WatcherClientProxy client; private HttpClient httpClient; private EmailService emailService; private TextTemplateEngine templateEngine; @@ -155,7 +155,7 @@ public class WatchTests extends ESTestCase { @Before public void init() throws Exception { scriptService = mock(ScriptServiceProxy.class); - client = mock(ClientProxy.class); + client = mock(WatcherClientProxy.class); httpClient = mock(HttpClient.class); emailService = mock(EmailService.class); templateEngine = mock(TextTemplateEngine.class); From 0f905e9b00b0d81c51ac17bbfeadba7ae6db9fa3 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 25 Sep 2015 23:55:54 -0400 Subject: [PATCH 09/11] CLI: Don't let ubuntu try to install its crazy jayatana agent. See https://github.com/elastic/elasticsearch/pull/13813 This is the corresponding workaround for x-plugins commandline tools. Closes elastic/elasticsearch#719 Original commit: elastic/x-pack-elasticsearch@c607fd219735d012b59f24368d606909b1431046 --- elasticsearch/x-pack/shield/bin/xpack/esusers | 8 ++++++++ elasticsearch/x-pack/shield/bin/xpack/syskeygen | 8 ++++++++ elasticsearch/x-pack/watcher/bin/xpack/croneval | 10 +++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/elasticsearch/x-pack/shield/bin/xpack/esusers b/elasticsearch/x-pack/shield/bin/xpack/esusers index 50d7d522c34..732e9d0c8a8 100755 --- a/elasticsearch/x-pack/shield/bin/xpack/esusers +++ b/elasticsearch/x-pack/shield/bin/xpack/esusers @@ -125,6 +125,14 @@ export HOSTNAME=`hostname -s` # include shield jars in classpath ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/xpack/*" +# don't let JAVA_TOOL_OPTIONS slip in (e.g. crazy agents in ubuntu) +# works around https://bugs.launchpad.net/ubuntu/+source/jayatana/+bug/1441487 +if [ "x$JAVA_TOOL_OPTIONS" != "x" ]; then + echo "Warning: Ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS" + echo "Please pass JVM parameters via ES_JAVA_OPTS instead" + unset JAVA_TOOL_OPTIONS +fi + cd "$ES_HOME" > /dev/null "$JAVA" $ES_JAVA_OPTS -cp "$ES_CLASSPATH" -Des.path.home="$ES_HOME" $properties org.elasticsearch.shield.authc.esusers.tool.ESUsersTool "$@" status=$? diff --git a/elasticsearch/x-pack/shield/bin/xpack/syskeygen b/elasticsearch/x-pack/shield/bin/xpack/syskeygen index 6f29cb744b8..be326789b11 100755 --- a/elasticsearch/x-pack/shield/bin/xpack/syskeygen +++ b/elasticsearch/x-pack/shield/bin/xpack/syskeygen @@ -125,6 +125,14 @@ export HOSTNAME=`hostname -s` # include shield jars in classpath ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/xpack/*" +# don't let JAVA_TOOL_OPTIONS slip in (e.g. crazy agents in ubuntu) +# works around https://bugs.launchpad.net/ubuntu/+source/jayatana/+bug/1441487 +if [ "x$JAVA_TOOL_OPTIONS" != "x" ]; then + echo "Warning: Ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS" + echo "Please pass JVM parameters via ES_JAVA_OPTS instead" + unset JAVA_TOOL_OPTIONS +fi + cd "$ES_HOME" > /dev/null $JAVA $ES_JAVA_OPTS -cp "$ES_CLASSPATH" -Des.path.home="$ES_HOME" $properties org.elasticsearch.shield.crypto.tool.SystemKeyTool "$@" status=$? diff --git a/elasticsearch/x-pack/watcher/bin/xpack/croneval b/elasticsearch/x-pack/watcher/bin/xpack/croneval index 228f4233760..c2561b29245 100755 --- a/elasticsearch/x-pack/watcher/bin/xpack/croneval +++ b/elasticsearch/x-pack/watcher/bin/xpack/croneval @@ -116,8 +116,16 @@ export HOSTNAME=`hostname -s` # include watcher jars in classpath ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/xpack/*" +# don't let JAVA_TOOL_OPTIONS slip in (e.g. crazy agents in ubuntu) +# works around https://bugs.launchpad.net/ubuntu/+source/jayatana/+bug/1441487 +if [ "x$JAVA_TOOL_OPTIONS" != "x" ]; then + echo "Warning: Ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS" + echo "Please pass JVM parameters via ES_JAVA_OPTS instead" + unset JAVA_TOOL_OPTIONS +fi + cd "$ES_HOME" > /dev/null $JAVA $ES_JAVA_OPTS -cp "$ES_CLASSPATH" org.elasticsearch.watcher.trigger.schedule.tool.CronEvalTool "$@" $properties status=$? cd - > /dev/null -exit $status \ No newline at end of file +exit $status From 62ad9f4f0de8f24d74936047d5f304197ad4c15d Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Tue, 8 Mar 2016 15:02:46 +0100 Subject: [PATCH 10/11] Move lazy initialization classes from Watcher to XPack This commit moves the InitializingModule and InitializingService classes in the common XPack package so that it can be used by any plugin. It also renames the module and service from Initializing* to LazyInitializing* and add a ClientProxy class. Original commit: elastic/x-pack-elasticsearch@fbdf9d161450d96c8bd4472d55330d6a98692c76 --- .../org/elasticsearch/xpack/XPackPlugin.java | 11 +++++ .../xpack/common/init/LazyInitializable.java | 17 ++++++++ .../common/init/LazyInitializationModule.java | 39 +++++++++++++++++ .../init/LazyInitializationService.java} | 18 ++++---- .../xpack/common/init/proxy/ClientProxy.java | 42 +++++++++++++++++++ .../org/elasticsearch/watcher/Watcher.java | 20 +++++---- .../watcher/input/InputModule.java | 2 +- .../input/chain/ChainInputFactory.java | 4 +- .../support/init/InitializingModule.java | 35 ---------------- .../init/proxy/ScriptServiceProxy.java | 4 +- .../init/proxy/WatcherClientProxy.java | 21 +--------- .../watcher/transform/TransformModule.java | 2 +- .../chain/ChainTransformFactory.java | 4 +- 13 files changed, 139 insertions(+), 80 deletions(-) create mode 100644 elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializable.java create mode 100644 elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationModule.java rename elasticsearch/x-pack/{watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingService.java => src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationService.java} (66%) create mode 100644 elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/proxy/ClientProxy.java delete mode 100644 elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingModule.java 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 1b532eae312..2df5e099af3 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 @@ -22,6 +22,8 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.shield.Shield; import org.elasticsearch.watcher.Watcher; +import org.elasticsearch.xpack.common.init.LazyInitializationModule; +import org.elasticsearch.xpack.common.init.LazyInitializationService; import java.nio.file.Path; import java.security.AccessController; @@ -89,6 +91,7 @@ public class XPackPlugin extends Plugin { @Override public Collection nodeModules() { ArrayList modules = new ArrayList<>(); + modules.add(new LazyInitializationModule()); modules.addAll(licensing.nodeModules()); modules.addAll(shield.nodeModules()); modules.addAll(watcher.nodeModules()); @@ -99,6 +102,10 @@ public class XPackPlugin extends Plugin { @Override public Collection> nodeServices() { ArrayList> services = new ArrayList<>(); + // the initialization service must be first in the list + // as other services may depend on one of the initialized + // constructs + services.add(LazyInitializationService.class); services.addAll(licensing.nodeServices()); services.addAll(shield.nodeServices()); services.addAll(watcher.nodeServices()); @@ -145,6 +152,10 @@ public class XPackPlugin extends Plugin { shield.onIndexModule(module); } + public void onModule(LazyInitializationModule module) { + watcher.onModule(module); + } + public static boolean transportClientMode(Settings settings) { return !"node".equals(settings.get(Client.CLIENT_TYPE_SETTING_S.getKey())); } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializable.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializable.java new file mode 100644 index 00000000000..cc578d52213 --- /dev/null +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializable.java @@ -0,0 +1,17 @@ +/* + * 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.common.init; + +import org.elasticsearch.common.inject.Injector; + +public interface LazyInitializable { + + /** + * This method is called once all objects have been constructed and + * the @{link LazyInitializationService} has been started. + */ + void init(Injector injector); +} diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationModule.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationModule.java new file mode 100644 index 00000000000..7c7db7bcd0f --- /dev/null +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationModule.java @@ -0,0 +1,39 @@ +/* + * 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.common.init; + +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.multibindings.Multibinder; + +import java.util.HashSet; +import java.util.Set; + +/** + * A module to lazy initialize objects and avoid circular dependency injection issues. + * + * Objects that use the {@link org.elasticsearch.client.ElasticsearchClient} and that are also injected in transport actions provoke + * a circular dependency injection issues with Guice. Using proxies with lazy initialization is a way to solve this issue. + * + * The proxies are initialized by {@link LazyInitializationService}. + */ +public class LazyInitializationModule extends AbstractModule { + + private final Set> initializables = new HashSet<>(); + + @Override + protected void configure() { + Multibinder mbinder = Multibinder.newSetBinder(binder(), LazyInitializable.class); + for (Class initializable : initializables) { + bind(initializable).asEagerSingleton(); + mbinder.addBinding().to(initializable); + } + bind(LazyInitializationService.class).asEagerSingleton(); + } + + public void registerLazyInitializable(Class lazyTypeClass) { + initializables.add(lazyTypeClass); + } +} diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingService.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationService.java similarity index 66% rename from elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingService.java rename to elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationService.java index cab7be9cd7a..d525e2beb74 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingService.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationService.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.support.init; +package org.elasticsearch.xpack.common.init; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.component.AbstractLifecycleComponent; @@ -14,15 +14,15 @@ import org.elasticsearch.common.settings.Settings; import java.util.Set; /** - * A service to lazy initialize {@link InitializingService.Initializable} constructs. + * A service to lazy initialize {@link LazyInitializable} constructs. */ -public class InitializingService extends AbstractLifecycleComponent { +public class LazyInitializationService extends AbstractLifecycleComponent { private final Injector injector; - private final Set initializables; + private final Set initializables; @Inject - public InitializingService(Settings settings, Injector injector, Set initializables) { + public LazyInitializationService(Settings settings, Injector injector, Set initializables) { super(settings); this.injector = injector; this.initializables = initializables; @@ -30,7 +30,8 @@ public class InitializingService extends AbstractLifecycleComponent { @Override protected void doStart() throws ElasticsearchException { - for (Initializable initializable : initializables) { + for (LazyInitializable initializable : initializables) { + logger.trace("lazy initialization of [{}]", initializable); initializable.init(injector); } } @@ -42,9 +43,4 @@ public class InitializingService extends AbstractLifecycleComponent { @Override protected void doClose() throws ElasticsearchException { } - - public interface Initializable { - - void init(Injector injector); - } } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/proxy/ClientProxy.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/proxy/ClientProxy.java new file mode 100644 index 00000000000..8e990009182 --- /dev/null +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/proxy/ClientProxy.java @@ -0,0 +1,42 @@ +/* + * 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.common.init.proxy; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.bulk.BulkRequest; +import org.elasticsearch.action.bulk.BulkResponse; +import org.elasticsearch.client.AdminClient; +import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Injector; +import org.elasticsearch.shield.InternalClient; +import org.elasticsearch.transport.TransportMessage; +import org.elasticsearch.xpack.common.init.LazyInitializable; + +/** + * A lazily initialized proxy to an elasticsearch {@link Client}. Inject this proxy whenever a client + * needs to injected to be avoid circular dependencies issues. + */ +public class ClientProxy implements LazyInitializable { + + protected InternalClient client; + + @Override + public void init(Injector injector) { + this.client = injector.getInstance(InternalClient.class); + } + + public AdminClient admin() { + return client.admin(); + } + + public void bulk(BulkRequest request, ActionListener listener) { + client.bulk(preProcess(request), listener); + } + + protected M preProcess(M message) { + return message; + } +} 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 2538c7fc719..bf132a26002 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,6 +38,7 @@ import org.elasticsearch.watcher.execution.ExecutionModule; 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; @@ -54,14 +55,14 @@ 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.InitializingModule; -import org.elasticsearch.watcher.support.init.InitializingService; import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.watcher.support.secret.SecretModule; import org.elasticsearch.watcher.support.secret.SecretService; import org.elasticsearch.watcher.support.text.TextTemplateModule; import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation; import org.elasticsearch.watcher.transform.TransformModule; +import org.elasticsearch.watcher.transform.chain.ChainTransformFactory; import org.elasticsearch.watcher.transport.actions.ack.AckWatchAction; import org.elasticsearch.watcher.transport.actions.ack.TransportAckWatchAction; import org.elasticsearch.watcher.transport.actions.activate.ActivateWatchAction; @@ -82,6 +83,7 @@ import org.elasticsearch.watcher.trigger.TriggerModule; 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.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -133,7 +135,6 @@ public class Watcher { } return Arrays.asList( new WatcherModule(settings), - new InitializingModule(), new LicenseModule(), new WatchModule(), new TextTemplateModule(), @@ -156,10 +157,6 @@ public class Watcher { return Collections.emptyList(); } return Arrays.>asList( - // the initialization service must be first in the list - // as other services may depend on one of the initialized - // constructs - InitializingService.class, WatcherLicensee.class, EmailService.class, HipChatService.class, @@ -254,6 +251,15 @@ 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); + } + } + public static boolean enabled(Settings settings) { return XPackPlugin.featureEnabled(settings, NAME, true); } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/InputModule.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/InputModule.java index 03ed1e60461..587fdc5b042 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/InputModule.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/InputModule.java @@ -48,7 +48,7 @@ public class InputModule extends AbstractModule { bind(NoneInputFactory.class).asEagerSingleton(); parsersBinder.addBinding(NoneInput.TYPE).to(NoneInputFactory.class); - // no bind() needed, done in InitializingModule + // no bind() needed, done using the LazyInitializationModule parsersBinder.addBinding(ChainInput.TYPE).to(ChainInputFactory.class); for (Map.Entry> entry : parsers.entrySet()) { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/chain/ChainInputFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/chain/ChainInputFactory.java index 4d54a62e7e1..87ecc372e53 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/chain/ChainInputFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/chain/ChainInputFactory.java @@ -15,14 +15,14 @@ import org.elasticsearch.watcher.input.ExecutableInput; import org.elasticsearch.watcher.input.Input; import org.elasticsearch.watcher.input.InputFactory; import org.elasticsearch.watcher.input.InputRegistry; -import org.elasticsearch.watcher.support.init.InitializingService; +import org.elasticsearch.xpack.common.init.LazyInitializable; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class ChainInputFactory extends InputFactory - implements InitializingService.Initializable { + implements LazyInitializable { private InputRegistry inputRegistry; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingModule.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingModule.java deleted file mode 100644 index 5309b7ae3f8..00000000000 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/InitializingModule.java +++ /dev/null @@ -1,35 +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.support.init; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.multibindings.Multibinder; -import org.elasticsearch.watcher.input.chain.ChainInputFactory; -import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; -import org.elasticsearch.watcher.transform.chain.ChainTransformFactory; - -/** - * - */ -public class InitializingModule extends AbstractModule { - - @Override - protected void configure() { - - bind(WatcherClientProxy.class).asEagerSingleton(); - bind(ScriptServiceProxy.class).asEagerSingleton(); - bind(ChainInputFactory.class).asEagerSingleton(); - - Multibinder mbinder = Multibinder.newSetBinder(binder(), - InitializingService.Initializable.class); - mbinder.addBinding().to(WatcherClientProxy.class); - mbinder.addBinding().to(ScriptServiceProxy.class); - mbinder.addBinding().to(ChainTransformFactory.class); - mbinder.addBinding().to(ChainInputFactory.class); - bind(InitializingService.class).asEagerSingleton(); - } -} 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 f7448f92680..48e3a492f0a 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 @@ -13,7 +13,7 @@ import org.elasticsearch.script.ScriptService; import org.elasticsearch.shield.SecurityContext; import org.elasticsearch.shield.XPackUser; import org.elasticsearch.watcher.support.Script; -import org.elasticsearch.watcher.support.init.InitializingService; +import org.elasticsearch.xpack.common.init.LazyInitializable; import java.util.Map; @@ -23,7 +23,7 @@ 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. */ -public class ScriptServiceProxy implements InitializingService.Initializable { +public class ScriptServiceProxy implements LazyInitializable { private ScriptService service; private SecurityContext securityContext; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/WatcherClientProxy.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/WatcherClientProxy.java index 10e4c362da9..587da228604 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/WatcherClientProxy.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/support/init/proxy/WatcherClientProxy.java @@ -23,26 +23,22 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchScrollRequest; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateResponse; -import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.shield.InternalClient; -import org.elasticsearch.transport.TransportMessage; -import org.elasticsearch.watcher.support.init.InitializingService; +import org.elasticsearch.xpack.common.init.proxy.ClientProxy; /** * A lazily initialized proxy to an elasticsearch {@link Client}. Inject this proxy whenever a client * needs to injected to be avoid circular dependencies issues. */ -public class WatcherClientProxy implements InitializingService.Initializable { +public class WatcherClientProxy extends ClientProxy { private final TimeValue defaultSearchTimeout; private final TimeValue defaultIndexTimeout; private final TimeValue defaultBulkTimeout; - private InternalClient client; @Inject public WatcherClientProxy(Settings settings) { @@ -60,15 +56,6 @@ public class WatcherClientProxy implements InitializingService.Initializable { return proxy; } - @Override - public void init(Injector injector) { - this.client = injector.getInstance(InternalClient.class); - } - - public AdminClient admin() { - return client.admin(); - } - public IndexResponse index(IndexRequest request, TimeValue timeout) { if (timeout == null) { timeout = defaultIndexTimeout; @@ -125,8 +112,4 @@ public class WatcherClientProxy implements InitializingService.Initializable { preProcess(request); return client.admin().indices().putTemplate(request).actionGet(defaultIndexTimeout); } - - M preProcess(M message) { - return message; - } } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/TransformModule.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/TransformModule.java index 0f62dca754c..3efe73ccbc2 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/TransformModule.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/TransformModule.java @@ -38,7 +38,7 @@ public class TransformModule extends AbstractModule { bind(ScriptTransformFactory.class).asEagerSingleton(); mbinder.addBinding(ScriptTransform.TYPE).to(ScriptTransformFactory.class); - bind(ChainTransformFactory.class).asEagerSingleton(); + // no bind() needed, done using the LazyInitializationModule mbinder.addBinding(ChainTransform.TYPE).to(ChainTransformFactory.class); for (Map.Entry> entry : factories.entrySet()) { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransformFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransformFactory.java index a6eaa75e361..7dcfc20dbc5 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransformFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransformFactory.java @@ -9,11 +9,11 @@ import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.watcher.support.init.InitializingService; import org.elasticsearch.watcher.transform.ExecutableTransform; import org.elasticsearch.watcher.transform.Transform; import org.elasticsearch.watcher.transform.TransformFactory; import org.elasticsearch.watcher.transform.TransformRegistry; +import org.elasticsearch.xpack.common.init.LazyInitializable; import java.io.IOException; import java.util.ArrayList; @@ -22,7 +22,7 @@ import java.util.ArrayList; * */ public class ChainTransformFactory extends TransformFactory implements - InitializingService.Initializable { + LazyInitializable { private TransformRegistry registry; From e728a49853ea46254dac2e7e997f9ea7ae09910d Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 8 Mar 2016 17:27:04 +0100 Subject: [PATCH 11/11] Watcher: Fix home path for croneval CLI tool Drive-by fixes putting the $JAVA binary into quotes to support spaces, like we do in other scripts as well. Closes elastic/elasticsearch#1642 Original commit: elastic/x-pack-elasticsearch@f40fba32cc58457276d9a5d7f96e752ed281a37e --- elasticsearch/x-pack/shield/bin/xpack/syskeygen | 2 +- elasticsearch/x-pack/watcher/bin/xpack/croneval | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/elasticsearch/x-pack/shield/bin/xpack/syskeygen b/elasticsearch/x-pack/shield/bin/xpack/syskeygen index be326789b11..a79ef3808ec 100755 --- a/elasticsearch/x-pack/shield/bin/xpack/syskeygen +++ b/elasticsearch/x-pack/shield/bin/xpack/syskeygen @@ -134,7 +134,7 @@ if [ "x$JAVA_TOOL_OPTIONS" != "x" ]; then fi cd "$ES_HOME" > /dev/null -$JAVA $ES_JAVA_OPTS -cp "$ES_CLASSPATH" -Des.path.home="$ES_HOME" $properties org.elasticsearch.shield.crypto.tool.SystemKeyTool "$@" +"$JAVA" $ES_JAVA_OPTS -cp "$ES_CLASSPATH" -Des.path.home="$ES_HOME" $properties org.elasticsearch.shield.crypto.tool.SystemKeyTool "$@" status=$? cd - > /dev/null exit $status diff --git a/elasticsearch/x-pack/watcher/bin/xpack/croneval b/elasticsearch/x-pack/watcher/bin/xpack/croneval index c2561b29245..04abd90c385 100755 --- a/elasticsearch/x-pack/watcher/bin/xpack/croneval +++ b/elasticsearch/x-pack/watcher/bin/xpack/croneval @@ -125,7 +125,7 @@ if [ "x$JAVA_TOOL_OPTIONS" != "x" ]; then fi cd "$ES_HOME" > /dev/null -$JAVA $ES_JAVA_OPTS -cp "$ES_CLASSPATH" org.elasticsearch.watcher.trigger.schedule.tool.CronEvalTool "$@" $properties +"$JAVA" $ES_JAVA_OPTS -cp "$ES_CLASSPATH" -Des.path.home="$ES_HOME" org.elasticsearch.watcher.trigger.schedule.tool.CronEvalTool "$@" $properties status=$? cd - > /dev/null exit $status