From a890cfb81ef06a605e2b7da7550cfbe21fd85728 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Tue, 10 Jan 2017 13:32:11 +0100 Subject: [PATCH 1/5] Keep NodeConnectionsService in sync with current nodes in the cluster state Companion commit to elastic/elasticsearchelastic/elasticsearch#22509 Original commit: elastic/x-pack-elasticsearch@d46a46bf681f27812746928b3250c0f3a6358713 --- .../action/TransportMonitoringBulkActionTests.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java index 9faaf342cc0..5e5665963ac 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringBulkActionTests.java @@ -9,9 +9,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.LocalClusterUpdateTask; import org.elasticsearch.cluster.NodeConnectionsService; import org.elasticsearch.cluster.block.ClusterBlocks; @@ -44,7 +42,6 @@ import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -101,12 +98,12 @@ public class TransportMonitoringBulkActionTests extends ESTestCase { Version.CURRENT)); clusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) { @Override - public void connectToNodes(List addedNodes) { + public void connectToNodes(Iterable discoveryNodes) { // skip } @Override - public void disconnectFromNodes(List removedNodes) { + public void disconnectFromNodesExcept(Iterable nodesToKeep) { // skip } }); From 56e3e107d4b0f7b8ef898a492769bfcb66c795c6 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 10 Jan 2017 17:26:54 +0100 Subject: [PATCH 2/5] Tests: Fix watcher test using DNS resolution (elastic/elasticsearch#4576) Turns out that this test became flaky on dev machines with specific DNS setup. This test uses an index action to provoke an error, thus there is no dependency on anything network specific. The reason it was uncovered now, was due to the change to the Apache HTTP client which is doing DNS lookups. This DNS lookup happened inadvertantly because of a bug in the test, which had a URI like http://http://127.0.0.1.... However having web request was not needed at all, so it was replaced. Closes elastic/elasticsearch#4561 Original commit: elastic/x-pack-elasticsearch@158516b5e502b6e60c8ad0773059f48ddf9ddcf4 --- .../throttler/ActionThrottleTests.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java index 950b7b59692..4213195a009 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.watcher.actions.throttler; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.xpack.common.http.HttpMethod; import org.elasticsearch.xpack.common.http.HttpRequestTemplate; import org.elasticsearch.xpack.common.text.TextTemplate; @@ -40,8 +41,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction; import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction; -import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.webhookAction; import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder; import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule; import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval; @@ -287,8 +288,21 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase { }, 20, TimeUnit.SECONDS); } - @AwaitsFix(bugUrl = "https://github.com/elastic/x-pack/issues/4561") public void testFailingActionDoesGetThrottled() throws Exception { + // create a mapping with a wrong @timestamp field, so that the index action of the watch below will fail + String mapping = XContentFactory.jsonBuilder() + .startObject() + .startObject("bar") + .startObject("properties") + .startObject("@timestamp") + .field("type", "integer") + .endObject() + .endObject() + .endObject() + .endObject().string(); + + client().admin().indices().prepareCreate("foo").addMapping("bar", mapping).get(); + TimeValue throttlePeriod = new TimeValue(60, TimeUnit.MINUTES); watcherClient().preparePutWatch("_id").setSource(watchBuilder() @@ -296,8 +310,7 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase { new IntervalSchedule.Interval(60, IntervalSchedule.Interval.Unit.MINUTES)))) .defaultThrottlePeriod(throttlePeriod) .addAction("logging", loggingAction("test out")) - // no DNS resolution here please - .addAction("failing_hook", webhookAction(HttpRequestTemplate.builder("http://127.0.0.1/foobar", 80)))) + .addAction("failing_hook", indexAction("foo", "bar").setExecutionTimeField("@timestamp"))) .get(); refresh(Watch.INDEX); From 02ef01897815fb38fe251b3e42ab44e991f5b5f0 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Wed, 11 Jan 2017 13:32:03 +0100 Subject: [PATCH 3/5] [TEST] Ensure that there is at least one enabled test in elasticsearch-transport-client Original commit: elastic/x-pack-elasticsearch@092d35dc1cb57e607fc5d71320d28312dc29dc41 --- .../xpack/client/PreBuiltXPackTransportClientTests.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/elasticsearch-transport-client/src/test/java/org/elasticsearch/xpack/client/PreBuiltXPackTransportClientTests.java b/elasticsearch-transport-client/src/test/java/org/elasticsearch/xpack/client/PreBuiltXPackTransportClientTests.java index cbff866c37c..97cf65e83d5 100644 --- a/elasticsearch-transport-client/src/test/java/org/elasticsearch/xpack/client/PreBuiltXPackTransportClientTests.java +++ b/elasticsearch-transport-client/src/test/java/org/elasticsearch/xpack/client/PreBuiltXPackTransportClientTests.java @@ -30,4 +30,8 @@ public class PreBuiltXPackTransportClientTests extends RandomizedTest { } } + // dummy test so that the tests pass on JDK9 as the only test in this module is disabled on JDK9 + public void testDummy() { + + } } From 44d745bd921d866b291848bb27d682f11b129432 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Wed, 11 Jan 2017 14:18:46 +0100 Subject: [PATCH 4/5] [TEST] Missed @Test annotation Original commit: elastic/x-pack-elasticsearch@57798e6763db46835e1c2b6a9a1a657092cf654e --- .../xpack/client/PreBuiltXPackTransportClientTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/elasticsearch-transport-client/src/test/java/org/elasticsearch/xpack/client/PreBuiltXPackTransportClientTests.java b/elasticsearch-transport-client/src/test/java/org/elasticsearch/xpack/client/PreBuiltXPackTransportClientTests.java index 97cf65e83d5..903d1509eeb 100644 --- a/elasticsearch-transport-client/src/test/java/org/elasticsearch/xpack/client/PreBuiltXPackTransportClientTests.java +++ b/elasticsearch-transport-client/src/test/java/org/elasticsearch/xpack/client/PreBuiltXPackTransportClientTests.java @@ -31,6 +31,7 @@ public class PreBuiltXPackTransportClientTests extends RandomizedTest { } // dummy test so that the tests pass on JDK9 as the only test in this module is disabled on JDK9 + @Test public void testDummy() { } From 818c4e9791aaf66762971b0065f1723bf97271ca Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 10 Jan 2017 16:49:11 -0500 Subject: [PATCH 5/5] Handle core removing SearchRequestParsers Original commit: elastic/x-pack-elasticsearch@e2f0ef773bb73c9e404a13086fb8cc47832902ec --- .../java/org/elasticsearch/xpack/XPackPlugin.java | 6 ++---- .../org/elasticsearch/xpack/watcher/Watcher.java | 10 ++++------ .../watcher/input/search/SearchInputFactory.java | 13 ++++++------- .../search/WatcherSearchTemplateService.java | 6 +----- .../transform/search/SearchTransformFactory.java | 13 ++++++------- .../watcher/test/integration/SearchInputTests.java | 5 +---- .../test/integration/SearchTransformTests.java | 5 +---- .../xpack/watcher/watch/WatchTests.java | 11 +++-------- 8 files changed, 24 insertions(+), 45 deletions(-) diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 8ebb0158c50..dca131d78bc 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -40,7 +40,6 @@ import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.Transport; @@ -96,7 +95,6 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.time.Clock; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -221,7 +219,7 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I @Override public Collection createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, ResourceWatcherService resourceWatcherService, ScriptService scriptService, - SearchRequestParsers searchRequestParsers, NamedXContentRegistry xContentRegistry) { + NamedXContentRegistry xContentRegistry) { List components = new ArrayList<>(); components.add(sslService); @@ -255,7 +253,7 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I httpTemplateParser, scriptService, httpAuthRegistry); components.addAll(notificationComponents); - components.addAll(watcher.createComponents(getClock(), scriptService, internalClient, searchRequestParsers, licenseState, + components.addAll(watcher.createComponents(getClock(), scriptService, internalClient, licenseState, httpClient, httpTemplateParser, threadPool, clusterService, security.getCryptoService(), xContentRegistry, components)); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 3723578f481..c6975b5ca02 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -32,7 +32,6 @@ import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.FixedExecutorBuilder; import org.elasticsearch.threadpool.ThreadPool; @@ -219,7 +218,7 @@ public class Watcher implements ActionPlugin, ScriptPlugin { } public Collection createComponents(Clock clock, ScriptService scriptService, InternalClient internalClient, - SearchRequestParsers searchRequestParsers, XPackLicenseState licenseState, + XPackLicenseState licenseState, HttpClient httpClient, HttpRequestTemplate.Parser httpTemplateParser, ThreadPool threadPool, ClusterService clusterService, CryptoService cryptoService, NamedXContentRegistry xContentRegistry, Collection components) { @@ -237,8 +236,7 @@ public class Watcher implements ActionPlugin, ScriptPlugin { final ConditionRegistry conditionRegistry = new ConditionRegistry(Collections.unmodifiableMap(parsers), clock); final Map transformFactories = new HashMap<>(); transformFactories.put(ScriptTransform.TYPE, new ScriptTransformFactory(settings, scriptService)); - transformFactories.put(SearchTransform.TYPE, new SearchTransformFactory(settings, internalClient, searchRequestParsers, - xContentRegistry, scriptService)); + transformFactories.put(SearchTransform.TYPE, new SearchTransformFactory(settings, internalClient, xContentRegistry, scriptService)); final TransformRegistry transformRegistry = new TransformRegistry(settings, Collections.unmodifiableMap(transformFactories)); final Map actionFactoryMap = new HashMap<>(); @@ -261,7 +259,7 @@ public class Watcher implements ActionPlugin, ScriptPlugin { final Map inputFactories = new HashMap<>(); inputFactories.put(SearchInput.TYPE, - new SearchInputFactory(settings, internalClient, searchRequestParsers, xContentRegistry, scriptService)); + new SearchInputFactory(settings, internalClient, xContentRegistry, scriptService)); inputFactories.put(SimpleInput.TYPE, new SimpleInputFactory(settings)); inputFactories.put(HttpInput.TYPE, new HttpInputFactory(settings, httpClient, templateEngine, httpTemplateParser)); inputFactories.put(NoneInput.TYPE, new NoneInputFactory(settings)); @@ -294,7 +292,7 @@ public class Watcher implements ActionPlugin, ScriptPlugin { final TriggeredWatchStore triggeredWatchStore = new TriggeredWatchStore(settings, watcherClientProxy, triggeredWatchParser); final WatcherSearchTemplateService watcherSearchTemplateService = - new WatcherSearchTemplateService(settings, scriptService, searchRequestParsers, xContentRegistry); + new WatcherSearchTemplateService(settings, scriptService, xContentRegistry); final WatchExecutor watchExecutor = getWatchExecutor(threadPool); final Watch.Parser watchParser = new Watch.Parser(settings, triggerService, registry, inputRegistry, cryptoService, clock); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/SearchInputFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/SearchInputFactory.java index a2941e6a9a8..4a11bd9b027 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/SearchInputFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/SearchInputFactory.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.xpack.security.InternalClient; import org.elasticsearch.xpack.watcher.input.InputFactory; import org.elasticsearch.xpack.watcher.input.simple.ExecutableSimpleInput; @@ -25,17 +24,17 @@ public class SearchInputFactory extends InputFactory parsers = new HashMap<>(); switch (inputType) { case SearchInput.TYPE: - SearchRequestParsers searchParsers = new SearchRequestParsers(); - parsers.put(SearchInput.TYPE, new SearchInputFactory(settings, client, searchParsers, xContentRegistry(), scriptService)); + parsers.put(SearchInput.TYPE, new SearchInputFactory(settings, client, xContentRegistry(), scriptService)); return new InputRegistry(Settings.EMPTY, parsers); default: parsers.put(SimpleInput.TYPE, new SimpleInputFactory(settings)); @@ -457,10 +453,9 @@ public class WatchTests extends ESTestCase { } private TransformRegistry transformRegistry() { - SearchRequestParsers searchParsers = new SearchRequestParsers(); Map factories = new HashMap<>(); factories.put(ScriptTransform.TYPE, new ScriptTransformFactory(settings, scriptService)); - factories.put(SearchTransform.TYPE, new SearchTransformFactory(settings, client, searchParsers, xContentRegistry(), scriptService)); + factories.put(SearchTransform.TYPE, new SearchTransformFactory(settings, client, xContentRegistry(), scriptService)); return new TransformRegistry(Settings.EMPTY, unmodifiableMap(factories)); }