From a7d16a1dd18faca475a24dfc161e527cb371a946 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 29 Apr 2015 09:10:19 -0400 Subject: [PATCH 01/22] first strike against crazy CWD usages --- .../org/elasticsearch/env/Environment.java | 25 +++++-------------- .../indices/analysis/HunspellService.java | 6 ++--- .../elasticsearch/bootstrap/security.policy | 5 ++-- .../indices/analyze/HunspellServiceTests.java | 11 -------- .../test/InternalTestCluster.java | 24 ++++-------------- 5 files changed, 17 insertions(+), 54 deletions(-) diff --git a/src/main/java/org/elasticsearch/env/Environment.java b/src/main/java/org/elasticsearch/env/Environment.java index cab04792b5d..2c95e092bc9 100644 --- a/src/main/java/org/elasticsearch/env/Environment.java +++ b/src/main/java/org/elasticsearch/env/Environment.java @@ -175,26 +175,13 @@ public class Environment { } public URL resolveConfig(String path) throws FailedToResolveConfigException { - String origPath = path; - // first, try it as a path on the file system - Path f1 = PathUtils.get(path); - if (Files.exists(f1)) { + // first, try it as a path in the config directory + Path f = configFile.resolve(path); + if (Files.exists(f)) { try { - return f1.toUri().toURL(); + return f.toUri().toURL(); } catch (MalformedURLException e) { - throw new FailedToResolveConfigException("Failed to resolve path [" + f1 + "]", e); - } - } - if (path.startsWith("/")) { - path = path.substring(1); - } - // next, try it relative to the config location - Path f2 = configFile.resolve(path); - if (Files.exists(f2)) { - try { - return f2.toUri().toURL(); - } catch (MalformedURLException e) { - throw new FailedToResolveConfigException("Failed to resolve path [" + f1 + "]", e); + throw new FailedToResolveConfigException("Failed to resolve path [" + f + "]", e); } } // try and load it from the classpath directly @@ -209,6 +196,6 @@ public class Environment { return resource; } } - throw new FailedToResolveConfigException("Failed to resolve config path [" + origPath + "], tried file path [" + f1 + "], path file [" + f2 + "], and classpath"); + throw new FailedToResolveConfigException("Failed to resolve config path [" + path + "], tried config path [" + f + "] and classpath"); } } diff --git a/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java b/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java index ccb49a6fd2a..83b9a51b0c8 100644 --- a/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java +++ b/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java @@ -74,7 +74,7 @@ public class HunspellService extends AbstractComponent { public final static String HUNSPELL_LAZY_LOAD = "indices.analysis.hunspell.dictionary.lazy"; public final static String HUNSPELL_IGNORE_CASE = "indices.analysis.hunspell.dictionary.ignore_case"; - public final static String HUNSPELL_LOCATION = "indices.analysis.hunspell.dictionary.location"; + private final static String OLD_HUNSPELL_LOCATION = "indices.analysis.hunspell.dictionary.location"; private final LoadingCache dictionaries; private final Map knownDictionaries; @@ -116,9 +116,9 @@ public class HunspellService extends AbstractComponent { } private Path resolveHunspellDirectory(Settings settings, Environment env) { - String location = settings.get(HUNSPELL_LOCATION, null); + String location = settings.get(OLD_HUNSPELL_LOCATION, null); if (location != null) { - return PathUtils.get(location); + throw new IllegalArgumentException("please, put your hunspell dictionaries under config/hunspell !"); } return env.configFile().resolve("hunspell"); } diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index 44b89c47c58..771c95d44d0 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -31,8 +31,9 @@ grant { permission java.io.FilePermission "${java.io.tmpdir}${/}-", "read,write,delete"; // paths used for running tests - // project base directory - permission java.io.FilePermission "${project.basedir}${/}target${/}-", "read"; + // compiled classes + permission java.io.FilePermission "${project.basedir}${/}target${/}classes${/}-", "read"; + permission java.io.FilePermission "${project.basedir}${/}target${/}test-classes${/}-", "read"; // read permission for lib sigar permission java.io.FilePermission "${project.basedir}${/}lib/sigar{/}-", "read"; // mvn custom ./m2/repository for dependency jars diff --git a/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java b/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java index 304940e8141..742f5d1615e 100644 --- a/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java +++ b/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java @@ -79,17 +79,6 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest { assertIgnoreCase(true, dictionary); } - @Test - public void testCustomizeLocaleDirectory() throws Exception { - Settings settings = ImmutableSettings.settingsBuilder() - .put(HUNSPELL_LOCATION, getDataPath("/indices/analyze/conf_dir/hunspell")) - .build(); - - internalCluster().startNode(settings); - Dictionary dictionary = internalCluster().getInstance(HunspellService.class).getDictionary("en_US"); - assertThat(dictionary, notNullValue()); - } - @Test public void testDicWithNoAff() throws Exception { Settings settings = ImmutableSettings.settingsBuilder() diff --git a/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 660d228a43e..8eac41a29b2 100644 --- a/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -805,7 +805,7 @@ public final class InternalTestCluster extends TestCluster { /* no sniff client for now - doesn't work will all tests since it might throw NoNodeAvailableException if nodes are shut down. * we first need support of transportClientRatio as annotations or so */ - return transportClient = TransportClientFactory.noSniff(settingsSource.transportClient()).client(node, clusterName); + return transportClient = new TransportClientFactory(false, settingsSource.transportClient(), baseDir).client(node, clusterName); } void resetClient() throws IOException { @@ -859,29 +859,14 @@ public final class InternalTestCluster extends TestCluster { public static final String TRANSPORT_CLIENT_PREFIX = "transport_client_"; static class TransportClientFactory { - private static TransportClientFactory NO_SNIFF_CLIENT_FACTORY = new TransportClientFactory(false, ImmutableSettings.EMPTY); - private static TransportClientFactory SNIFF_CLIENT_FACTORY = new TransportClientFactory(true, ImmutableSettings.EMPTY); - private final boolean sniff; private final Settings settings; + private final Path baseDir; - public static TransportClientFactory noSniff(Settings settings) { - if (settings == null || settings.names().isEmpty()) { - return NO_SNIFF_CLIENT_FACTORY; - } - return new TransportClientFactory(false, settings); - } - - public static TransportClientFactory sniff(Settings settings) { - if (settings == null || settings.names().isEmpty()) { - return SNIFF_CLIENT_FACTORY; - } - return new TransportClientFactory(true, settings); - } - - TransportClientFactory(boolean sniff, Settings settings) { + TransportClientFactory(boolean sniff, Settings settings, Path baseDir) { this.sniff = sniff; this.settings = settings != null ? settings : ImmutableSettings.EMPTY; + this.baseDir = baseDir; } public Client client(Node node, String clusterName) { @@ -889,6 +874,7 @@ public final class InternalTestCluster extends TestCluster { Settings nodeSettings = node.settings(); Builder builder = settingsBuilder() .put("client.transport.nodes_sampler_interval", "1s") + .put("path.home", baseDir) .put("name", TRANSPORT_CLIENT_PREFIX + node.settings().get("name")) .put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) .put(ClusterName.SETTING, clusterName).put("client.transport.sniff", sniff) From c0587cb24424138b5bd8a841d9229ff9dbbc3efd Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 29 Apr 2015 09:44:37 -0400 Subject: [PATCH 02/22] fix CWD usage in analysis tests --- .../org/elasticsearch/env/Environment.java | 7 +---- .../ASCIIFoldingTokenFilterFactoryTests.java | 2 ++ .../index/analysis/AnalysisModuleTests.java | 5 +++- .../index/analysis/AnalysisTestsHelper.java | 8 ++++-- .../AnalyzerBackwardsCompatTests.java | 1 + .../index/analysis/CJKFilterFactoryTests.java | 8 +++--- .../HunspellTokenFilterFactoryTests.java | 2 ++ .../analysis/KeepFilterFactoryTests.java | 8 +++--- .../analysis/KeepTypesFilterFactoryTests.java | 1 + .../LimitTokenCountFilterFactoryTests.java | 26 ++++++++++++++----- .../ShingleTokenFilterFactoryTests.java | 8 +++--- .../StemmerTokenFilterFactoryTests.java | 2 ++ .../index/analysis/StopTokenFilterTests.java | 10 +++++-- .../WordDelimiterTokenFilterFactoryTests.java | 9 +++++++ .../CommonGramsTokenFilterFactoryTests.java | 24 ++++++++++++++--- .../synonyms/SynonymsAnalysisTest.java | 2 +- 16 files changed, 90 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/elasticsearch/env/Environment.java b/src/main/java/org/elasticsearch/env/Environment.java index 2c95e092bc9..46947c5667c 100644 --- a/src/main/java/org/elasticsearch/env/Environment.java +++ b/src/main/java/org/elasticsearch/env/Environment.java @@ -32,7 +32,6 @@ import java.nio.file.Path; import java.util.ArrayList; import static org.elasticsearch.common.Strings.cleanPath; -import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS; /** * The environment of where things exists. @@ -69,16 +68,12 @@ public class Environment { fileStores = allStores.toArray(new ESFileStore[allStores.size()]); } - public Environment() { - this(EMPTY_SETTINGS); - } - public Environment(Settings settings) { this.settings = settings; if (settings.get("path.home") != null) { homeFile = PathUtils.get(cleanPath(settings.get("path.home"))); } else { - homeFile = PathUtils.get(System.getProperty("user.dir")); + throw new IllegalStateException("path.home is not configured"); } if (settings.get("path.conf") != null) { diff --git a/src/test/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactoryTests.java index 04413f5d41e..70f12cdd401 100644 --- a/src/test/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactoryTests.java @@ -33,6 +33,7 @@ public class ASCIIFoldingTokenFilterFactoryTests extends ElasticsearchTokenStrea @Test public void testDefault() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_ascii_folding.type", "asciifolding") .build()); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_ascii_folding"); @@ -46,6 +47,7 @@ public class ASCIIFoldingTokenFilterFactoryTests extends ElasticsearchTokenStrea @Test public void testPreserveOriginal() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_ascii_folding.type", "asciifolding") .put("index.analysis.filter.my_ascii_folding.preserve_original", true) .build()); diff --git a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java index 81f06ad79d7..fb9024a460d 100644 --- a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java @@ -121,7 +121,10 @@ public class AnalysisModuleTests extends ElasticsearchTestCase { } private void assertTokenFilter(String name, Class clazz) throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(ImmutableSettings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build()); + Settings settings = ImmutableSettings.settingsBuilder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir().toString()).build(); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter(name); Tokenizer tokenizer = new WhitespaceTokenizer(); tokenizer.setReader(new StringReader("foo bar")); diff --git a/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java b/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java index 5a853c8f738..ea52f71e94a 100644 --- a/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java +++ b/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java @@ -34,11 +34,15 @@ import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.indices.analysis.IndicesAnalysisModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; +import java.nio.file.Path; + public class AnalysisTestsHelper { - public static AnalysisService createAnalysisServiceFromClassPath(String resource) { + public static AnalysisService createAnalysisServiceFromClassPath(Path baseDir, String resource) { Settings settings = ImmutableSettings.settingsBuilder() - .loadFromClasspath(resource).build(); + .loadFromClasspath(resource) + .put("path.home", baseDir.toString()) + .build(); return createAnalysisServiceFromSettings(settings); } diff --git a/src/test/java/org/elasticsearch/index/analysis/AnalyzerBackwardsCompatTests.java b/src/test/java/org/elasticsearch/index/analysis/AnalyzerBackwardsCompatTests.java index 880b9d80489..7254268eb40 100644 --- a/src/test/java/org/elasticsearch/index/analysis/AnalyzerBackwardsCompatTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/AnalyzerBackwardsCompatTests.java @@ -45,6 +45,7 @@ public class AnalyzerBackwardsCompatTests extends ElasticsearchTokenStreamTestCa builder.put(SETTING_VERSION_CREATED, version); } builder.put("index.analysis.analyzer.foo.type", type); + builder.put("path.home", createTempDir().toString()); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(builder.build()); NamedAnalyzer analyzer = analysisService.analyzer("foo"); if (version.onOrAfter(noStopwordVersion)) { diff --git a/src/test/java/org/elasticsearch/index/analysis/CJKFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/CJKFilterFactoryTests.java index b0bdda19be0..bfa4c5ed596 100644 --- a/src/test/java/org/elasticsearch/index/analysis/CJKFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/CJKFilterFactoryTests.java @@ -33,7 +33,7 @@ public class CJKFilterFactoryTests extends ElasticsearchTokenStreamTestCase { @Test public void testDefault() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("cjk_bigram"); String source = "多くの学生が試験に落ちた。"; String[] expected = new String[]{"多く", "くの", "の学", "学生", "生が", "が試", "試験", "験に", "に落", "落ち", "ちた" }; @@ -44,7 +44,7 @@ public class CJKFilterFactoryTests extends ElasticsearchTokenStreamTestCase { @Test public void testNoFlags() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("cjk_no_flags"); String source = "多くの学生が試験に落ちた。"; String[] expected = new String[]{"多く", "くの", "の学", "学生", "生が", "が試", "試験", "験に", "に落", "落ち", "ちた" }; @@ -55,7 +55,7 @@ public class CJKFilterFactoryTests extends ElasticsearchTokenStreamTestCase { @Test public void testHanOnly() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("cjk_han_only"); String source = "多くの学生が試験に落ちた。"; String[] expected = new String[]{"多", "く", "の", "学生", "が", "試験", "に", "落", "ち", "た" }; @@ -66,7 +66,7 @@ public class CJKFilterFactoryTests extends ElasticsearchTokenStreamTestCase { @Test public void testHanUnigramOnly() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("cjk_han_unigram_only"); String source = "多くの学生が試験に落ちた。"; String[] expected = new String[]{"多", "く", "の", "学", "学生", "生", "が", "試", "試験", "験", "に", "落", "ち", "た" }; diff --git a/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java index cb79991b90c..298910c9216 100644 --- a/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java @@ -33,6 +33,7 @@ public class HunspellTokenFilterFactoryTests extends ElasticsearchTestCase { @Test public void testDedup() throws IOException { Settings settings = settingsBuilder() + .put("path.home", createTempDir().toString()) .put("path.conf", getDataPath("/indices/analyze/conf_dir")) .put("index.analysis.filter.en_US.type", "hunspell") .put("index.analysis.filter.en_US.locale", "en_US") @@ -45,6 +46,7 @@ public class HunspellTokenFilterFactoryTests extends ElasticsearchTestCase { assertThat(hunspellTokenFilter.dedup(), is(true)); settings = settingsBuilder() + .put("path.home", createTempDir().toString()) .put("path.conf", getDataPath("/indices/analyze/conf_dir")) .put("index.analysis.filter.en_US.type", "hunspell") .put("index.analysis.filter.en_US.dedup", false) diff --git a/src/test/java/org/elasticsearch/index/analysis/KeepFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/KeepFilterFactoryTests.java index 78f2bd5077c..fb708a40c26 100644 --- a/src/test/java/org/elasticsearch/index/analysis/KeepFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/KeepFilterFactoryTests.java @@ -40,7 +40,7 @@ public class KeepFilterFactoryTests extends ElasticsearchTokenStreamTestCase { @Test public void testLoadWithoutSettings() { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("keep"); Assert.assertNull(tokenFilter); } @@ -48,6 +48,7 @@ public class KeepFilterFactoryTests extends ElasticsearchTokenStreamTestCase { @Test public void testLoadOverConfiguredSettings() { Settings settings = ImmutableSettings.settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.broken_keep_filter.type", "keep") .put("index.analysis.filter.broken_keep_filter.keep_words_path", "does/not/exists.txt") .put("index.analysis.filter.broken_keep_filter.keep_words", "[\"Hello\", \"worlD\"]") @@ -63,6 +64,7 @@ public class KeepFilterFactoryTests extends ElasticsearchTokenStreamTestCase { @Test public void testKeepWordsPathSettings() { Settings settings = ImmutableSettings.settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.non_broken_keep_filter.type", "keep") .put("index.analysis.filter.non_broken_keep_filter.keep_words_path", "does/not/exists.txt") .build(); @@ -89,7 +91,7 @@ public class KeepFilterFactoryTests extends ElasticsearchTokenStreamTestCase { @Test public void testCaseInsensitiveMapping() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_keep_filter"); assertThat(tokenFilter, instanceOf(KeepWordFilterFactory.class)); String source = "hello small world"; @@ -101,7 +103,7 @@ public class KeepFilterFactoryTests extends ElasticsearchTokenStreamTestCase { @Test public void testCaseSensitiveMapping() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_case_sensitive_keep_filter"); assertThat(tokenFilter, instanceOf(KeepWordFilterFactory.class)); String source = "Hello small world"; diff --git a/src/test/java/org/elasticsearch/index/analysis/KeepTypesFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/KeepTypesFilterFactoryTests.java index 95c942e19fd..c296c875987 100644 --- a/src/test/java/org/elasticsearch/index/analysis/KeepTypesFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/KeepTypesFilterFactoryTests.java @@ -36,6 +36,7 @@ public class KeepTypesFilterFactoryTests extends ElasticsearchTokenStreamTestCas @Test public void testKeepTypes() throws IOException { Settings settings = ImmutableSettings.settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.keep_numbers.type", "keep_types") .putArray("index.analysis.filter.keep_numbers.types", new String[] {"", ""}) .build(); diff --git a/src/test/java/org/elasticsearch/index/analysis/LimitTokenCountFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/LimitTokenCountFilterFactoryTests.java index 5473c635980..0428e66263d 100644 --- a/src/test/java/org/elasticsearch/index/analysis/LimitTokenCountFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/LimitTokenCountFilterFactoryTests.java @@ -33,7 +33,10 @@ public class LimitTokenCountFilterFactoryTests extends ElasticsearchTokenStreamT @Test public void testDefault() throws IOException { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.limit_default.type", "limit").build(); + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.limit_default.type", "limit") + .put("path.home", createTempDir().toString()) + .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); { TokenFilterFactory tokenFilter = analysisService.tokenFilter("limit_default"); @@ -56,8 +59,11 @@ public class LimitTokenCountFilterFactoryTests extends ElasticsearchTokenStreamT @Test public void testSettings() throws IOException { { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.limit_1.type", "limit") - .put("index.analysis.filter.limit_1.max_token_count", 3).put("index.analysis.filter.limit_1.consume_all_tokens", true) + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.limit_1.type", "limit") + .put("index.analysis.filter.limit_1.max_token_count", 3) + .put("index.analysis.filter.limit_1.consume_all_tokens", true) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("limit_1"); @@ -68,8 +74,11 @@ public class LimitTokenCountFilterFactoryTests extends ElasticsearchTokenStreamT assertTokenStreamContents(tokenFilter.create(tokenizer), expected); } { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.limit_1.type", "limit") - .put("index.analysis.filter.limit_1.max_token_count", 3).put("index.analysis.filter.limit_1.consume_all_tokens", false) + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.limit_1.type", "limit") + .put("index.analysis.filter.limit_1.max_token_count", 3) + .put("index.analysis.filter.limit_1.consume_all_tokens", false) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("limit_1"); @@ -81,8 +90,11 @@ public class LimitTokenCountFilterFactoryTests extends ElasticsearchTokenStreamT } { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.limit_1.type", "limit") - .put("index.analysis.filter.limit_1.max_token_count", 17).put("index.analysis.filter.limit_1.consume_all_tokens", true) + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.limit_1.type", "limit") + .put("index.analysis.filter.limit_1.max_token_count", 17) + .put("index.analysis.filter.limit_1.consume_all_tokens", true) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("limit_1"); diff --git a/src/test/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactoryTests.java index a6c193df2ec..866aad321f8 100644 --- a/src/test/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactoryTests.java @@ -40,7 +40,7 @@ public class ShingleTokenFilterFactoryTests extends ElasticsearchTokenStreamTest @Test public void testDefault() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("shingle"); String source = "the quick brown fox"; String[] expected = new String[]{"the", "the quick", "quick", "quick brown", "brown", "brown fox", "fox"}; @@ -51,7 +51,7 @@ public class ShingleTokenFilterFactoryTests extends ElasticsearchTokenStreamTest @Test public void testInverseMapping() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("shingle_inverse"); assertThat(tokenFilter, instanceOf(ShingleTokenFilterFactory.class)); String source = "the quick brown fox"; @@ -63,7 +63,7 @@ public class ShingleTokenFilterFactoryTests extends ElasticsearchTokenStreamTest @Test public void testInverseMappingNoShingles() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("shingle_inverse"); assertThat(tokenFilter, instanceOf(ShingleTokenFilterFactory.class)); String source = "the quick"; @@ -75,7 +75,7 @@ public class ShingleTokenFilterFactoryTests extends ElasticsearchTokenStreamTest @Test public void testFillerToken() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("shingle_filler"); String source = "simon the sorcerer"; String[] expected = new String[]{"simon FILLER", "simon FILLER sorcerer", "FILLER sorcerer"}; diff --git a/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java index ab335129df5..727b71f3b2f 100644 --- a/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java @@ -54,6 +54,7 @@ public class StemmerTokenFilterFactoryTests extends ElasticsearchTokenStreamTest .put("index.analysis.analyzer.my_english.tokenizer","whitespace") .put("index.analysis.analyzer.my_english.filter","my_english") .put(SETTING_VERSION_CREATED,v) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -87,6 +88,7 @@ public class StemmerTokenFilterFactoryTests extends ElasticsearchTokenStreamTest .put("index.analysis.analyzer.my_porter2.tokenizer","whitespace") .put("index.analysis.analyzer.my_porter2.filter","my_porter2") .put(SETTING_VERSION_CREATED,v) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); diff --git a/src/test/java/org/elasticsearch/index/analysis/StopTokenFilterTests.java b/src/test/java/org/elasticsearch/index/analysis/StopTokenFilterTests.java index 929d4f335d8..fa1dbf71362 100644 --- a/src/test/java/org/elasticsearch/index/analysis/StopTokenFilterTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/StopTokenFilterTests.java @@ -49,6 +49,7 @@ public class StopTokenFilterTests extends ElasticsearchTokenStreamTestCase { if (random().nextBoolean()) { builder.put("index.analysis.filter.my_stop.version", "5.0"); } + builder.put("path.home", createTempDir().toString()); Settings settings = builder.build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); analysisService.tokenFilter("my_stop"); @@ -68,6 +69,7 @@ public class StopTokenFilterTests extends ElasticsearchTokenStreamTestCase { } else { // don't specify } + builder.put("path.home", createTempDir().toString()); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(builder.build()); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_stop"); assertThat(tokenFilter, instanceOf(StopTokenFilterFactory.class)); @@ -83,8 +85,11 @@ public class StopTokenFilterTests extends ElasticsearchTokenStreamTestCase { @Test public void testDeprecatedPositionIncrementSettingWithVersions() throws IOException { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.my_stop.type", "stop") - .put("index.analysis.filter.my_stop.enable_position_increments", false).put("index.analysis.filter.my_stop.version", "4.3") + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.my_stop.type", "stop") + .put("index.analysis.filter.my_stop.enable_position_increments", false) + .put("index.analysis.filter.my_stop.version", "4.3") + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_stop"); @@ -100,6 +105,7 @@ public class StopTokenFilterTests extends ElasticsearchTokenStreamTestCase { Settings settings = ImmutableSettings.settingsBuilder() .put("index.analysis.filter.my_stop.type", "stop") .put("index.analysis.filter.my_stop.remove_trailing", false) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_stop"); diff --git a/src/test/java/org/elasticsearch/index/analysis/WordDelimiterTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/WordDelimiterTokenFilterFactoryTests.java index 24aba316d6e..52dc850c12a 100644 --- a/src/test/java/org/elasticsearch/index/analysis/WordDelimiterTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/WordDelimiterTokenFilterFactoryTests.java @@ -34,6 +34,7 @@ public class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre @Test public void testDefault() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .build()); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_word_delimiter"); @@ -47,6 +48,7 @@ public class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre @Test public void testCatenateWords() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.catenate_words", "true") .put("index.analysis.filter.my_word_delimiter.generate_word_parts", "false") @@ -62,6 +64,7 @@ public class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre @Test public void testCatenateNumbers() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.generate_number_parts", "false") .put("index.analysis.filter.my_word_delimiter.catenate_numbers", "true") @@ -77,6 +80,7 @@ public class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre @Test public void testCatenateAll() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.generate_word_parts", "false") .put("index.analysis.filter.my_word_delimiter.generate_number_parts", "false") @@ -93,6 +97,7 @@ public class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre @Test public void testSplitOnCaseChange() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.split_on_case_change", "false") .build()); @@ -107,6 +112,7 @@ public class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre @Test public void testPreserveOriginal() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.preserve_original", "true") .build()); @@ -121,6 +127,7 @@ public class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre @Test public void testStemEnglishPossessive() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.stem_english_possessive", "false") .build()); @@ -136,6 +143,7 @@ public class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre @Test public void testPartsAndCatenate() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.catenate_words", "true") .put("index.analysis.filter.my_word_delimiter.generate_word_parts", "true") @@ -153,6 +161,7 @@ public class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre @Test public void testDeprecatedPartsAndCatenate() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.catenate_words", "true") .put("index.analysis.filter.my_word_delimiter.generate_word_parts", "true") diff --git a/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java index 2792f0c4150..164892ff48c 100644 --- a/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java @@ -39,7 +39,10 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream @Test public void testDefault() throws IOException { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_default.type", "common_grams").build(); + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.common_grams_default.type", "common_grams") + .put("path.home", createTempDir().toString()) + .build(); try { AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -53,6 +56,7 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_default.type", "common_grams") .putArray("index.analysis.filter.common_grams_default.common_words", "chromosome", "protein") + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -69,6 +73,7 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_default.type", "common_grams") .put("index.analysis.filter.common_grams_default.query_mode", false) + .put("path.home", createTempDir().toString()) .putArray("index.analysis.filter.common_grams_default.common_words", "chromosome", "protein") .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -88,6 +93,7 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_1.type", "common_grams") .put("index.analysis.filter.common_grams_1.ignore_case", true) + .put("path.home", createTempDir().toString()) .putArray("index.analysis.filter.common_grams_1.common_words", "the", "Or", "Not", "a", "is", "an", "they", "are") .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -101,6 +107,7 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_2.type", "common_grams") .put("index.analysis.filter.common_grams_2.ignore_case", false) + .put("path.home", createTempDir().toString()) .putArray("index.analysis.filter.common_grams_2.common_words", "the", "Or", "noT", "a", "is", "an", "they", "are") .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -114,6 +121,7 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_3.type", "common_grams") .putArray("index.analysis.filter.common_grams_3.common_words", "the", "or", "not", "a", "is", "an", "they", "are") + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("common_grams_3"); @@ -127,7 +135,10 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream @Test public void testCommonGramsAnalysis() throws IOException { - Settings settings = ImmutableSettings.settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/commongrams/commongrams.json").build(); + Settings settings = ImmutableSettings.settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/commongrams/commongrams.json") + .put("path.home", createTempDir().toString()) + .build(); { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); Analyzer analyzer = analysisService.analyzer("commongramsAnalyzer").analyzer(); @@ -151,6 +162,7 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream .put("index.analysis.filter.common_grams_1.query_mode", true) .putArray("index.analysis.filter.common_grams_1.common_words", "the", "Or", "Not", "a", "is", "an", "they", "are") .put("index.analysis.filter.common_grams_1.ignore_case", true) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("common_grams_1"); @@ -165,6 +177,7 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream .put("index.analysis.filter.common_grams_2.query_mode", true) .putArray("index.analysis.filter.common_grams_2.common_words", "the", "Or", "noT", "a", "is", "an", "they", "are") .put("index.analysis.filter.common_grams_2.ignore_case", false) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("common_grams_2"); @@ -178,6 +191,7 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_3.type", "common_grams") .put("index.analysis.filter.common_grams_3.query_mode", true) .putArray("index.analysis.filter.common_grams_3.common_words", "the", "Or", "noT", "a", "is", "an", "they", "are") + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("common_grams_3"); @@ -191,6 +205,7 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_4.type", "common_grams") .put("index.analysis.filter.common_grams_4.query_mode", true) .putArray("index.analysis.filter.common_grams_4.common_words", "the", "or", "not", "a", "is", "an", "they", "are") + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("common_grams_4"); @@ -204,7 +219,10 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream @Test public void testQueryModeCommonGramsAnalysis() throws IOException { - Settings settings = ImmutableSettings.settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/commongrams/commongrams_query_mode.json").build(); + Settings settings = ImmutableSettings.settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/commongrams/commongrams_query_mode.json") + .put("path.home", createTempDir().toString()) + .build(); { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); Analyzer analyzer = analysisService.analyzer("commongramsAnalyzer").analyzer(); diff --git a/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java b/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java index c1d09a90bb1..6df27d10212 100644 --- a/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java +++ b/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java @@ -59,9 +59,9 @@ public class SynonymsAnalysisTest extends ElasticsearchTestCase { @Test public void testSynonymsAnalysis() throws IOException { - Settings settings = settingsBuilder(). loadFromClasspath("org/elasticsearch/index/analysis/synonyms/synonyms.json") + .put("path.home", createTempDir().toString()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); Index index = new Index("test"); From 9dec558ea1e9da61d88aa0be4d0d19d81cb8f4dc Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 29 Apr 2015 10:43:11 -0400 Subject: [PATCH 03/22] nuke more cwd usage --- .../client/transport/TransportClient.java | 8 --- .../action/bulk/BulkProcessorTests.java | 6 +- .../count/CountRequestBuilderTests.java | 7 ++- .../search/SearchRequestBuilderTests.java | 7 ++- .../client/AbstractClientHeadersTests.java | 6 +- .../TransportClientHeadersTests.java | 3 +- .../common/cli/CheckFileCommandTests.java | 55 +++++++++++-------- .../logging/log4j/Log4jESLoggerTests.java | 1 + .../log4j/LoggingConfigurationTests.java | 21 +++++-- .../index/analysis/AnalysisModuleTests.java | 21 +++++-- .../index/analysis/CharFilterTests.java | 3 + .../index/analysis/CompoundAnalysisTests.java | 12 +++- .../PatternCaptureTokenFilterTests.java | 6 +- .../index/analysis/StopAnalyzerTests.java | 6 +- .../index/query/TemplateQueryParserTest.java | 1 + .../InternalSettingsPreparerTests.java | 13 ++++- .../script/ScriptServiceTests.java | 1 + .../stresstest/client/ClientFailover.java | 5 +- .../ManyIndicesRemoteStressTest.java | 3 +- ...ttyTransportMultiPortIntegrationTests.java | 1 + 20 files changed, 133 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 6dd30b02af3..f99be431f14 100644 --- a/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -103,14 +103,6 @@ public class TransportClient extends AbstractClient { private final TransportClientNodesService nodesService; private final InternalTransportClient internalClient; - /** - * Constructs a new transport client with settings loaded either from the classpath or the file system (the - * elasticsearch.(yml|json) files optionally prefixed with config/). - */ - public TransportClient() { - this(ImmutableSettings.Builder.EMPTY_SETTINGS, true); - } - /** * Constructs a new transport client with explicit settings and settings loaded either from the classpath or the file * system (the elasticsearch.(yml|json) files optionally prefixed with config/). diff --git a/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java b/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java index e357206bc38..68a11b0b8e5 100644 --- a/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java +++ b/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; @@ -157,7 +158,10 @@ public class BulkProcessorTests extends ElasticsearchIntegrationTest { //https://github.com/elasticsearch/elasticsearch/issues/5038 public void testBulkProcessorConcurrentRequestsNoNodeAvailableException() throws Exception { //we create a transport client with no nodes to make sure it throws NoNodeAvailableException - Client transportClient = new TransportClient(); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + Client transportClient = new TransportClient(settings); int bulkActions = randomIntBetween(10, 100); int numDocs = randomIntBetween(bulkActions, bulkActions + 100); diff --git a/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java b/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java index 22387d277e8..85bb2a384cc 100644 --- a/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java +++ b/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java @@ -23,6 +23,8 @@ import org.elasticsearch.action.support.QuerySourceBuilder; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; @@ -46,7 +48,10 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { public static void initClient() { //this client will not be hit by any request, but it needs to be a non null proper client //that is why we create it but we don't add any transport address to it - client = new TransportClient(); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + client = new TransportClient(settings); } @AfterClass diff --git a/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java b/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java index 57a48bbbcc0..9b4b8bc77b8 100644 --- a/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java +++ b/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java @@ -21,6 +21,8 @@ package org.elasticsearch.action.search; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; @@ -45,7 +47,10 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { public static void initClient() { //this client will not be hit by any request, but it needs to be a non null proper client //that is why we create it but we don't add any transport address to it - client = new TransportClient(); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + client = new TransportClient(settings); } @AfterClass diff --git a/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java b/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java index 05561a9dec0..304853543ad 100644 --- a/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java +++ b/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java @@ -88,7 +88,11 @@ public abstract class AbstractClientHeadersTests extends ElasticsearchTestCase { @Before public void initClient() { - client = buildClient(HEADER_SETTINGS, ACTIONS); + Settings settings = ImmutableSettings.builder() + .put(HEADER_SETTINGS) + .put("path.home", createTempDir().toString()) + .build(); + client = buildClient(settings, ACTIONS); } @After diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java index c744c3cd7ee..07dd7f9c73d 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java @@ -59,7 +59,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { .put("client.transport.sniff", false) .put("node.name", "transport_client_" + this.getTestName()) .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName()) - .put(HEADER_SETTINGS) + .put(headersSettings) .build()); client.addTransportAddress(address); @@ -75,6 +75,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { .put("client.transport.nodes_sampler_interval", "1s") .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName()) .put(HEADER_SETTINGS) + .put("path.home", createTempDir().toString()) .build()); try { client.addTransportAddress(address); diff --git a/src/test/java/org/elasticsearch/common/cli/CheckFileCommandTests.java b/src/test/java/org/elasticsearch/common/cli/CheckFileCommandTests.java index 112d8969433..0d131af78ae 100644 --- a/src/test/java/org/elasticsearch/common/cli/CheckFileCommandTests.java +++ b/src/test/java/org/elasticsearch/common/cli/CheckFileCommandTests.java @@ -54,73 +54,73 @@ public class CheckFileCommandTests extends ElasticsearchTestCase { @Test public void testThatCommandLogsErrorMessageOnFail() throws Exception { - executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(captureOutputTerminal, Mode.CHANGE)); + executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.CHANGE)); assertThat(captureOutputTerminal.getTerminalOutput(), hasItem(containsString("Please ensure that the user account running Elasticsearch has read access to this file"))); } @Test public void testThatCommandLogsNothingWhenPermissionRemains() throws Exception { - executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(captureOutputTerminal, Mode.KEEP)); + executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.KEEP)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingWhenDisabled() throws Exception { - executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingIfFilesystemDoesNotSupportPermissions() throws Exception { - executeCommand(jimFsConfigurationWithoutPermissions, new PermissionCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfigurationWithoutPermissions, new PermissionCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsOwnerChange() throws Exception { - executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(captureOutputTerminal, Mode.CHANGE)); + executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.CHANGE)); assertThat(captureOutputTerminal.getTerminalOutput(), hasItem(allOf(containsString("Owner of file ["), containsString("] used to be ["), containsString("], but now is [")))); } @Test public void testThatCommandLogsNothingIfOwnerRemainsSame() throws Exception { - executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(captureOutputTerminal, Mode.KEEP)); + executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.KEEP)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingIfOwnerIsDisabled() throws Exception { - executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingIfFileSystemDoesNotSupportOwners() throws Exception { - executeCommand(jimFsConfigurationWithoutPermissions, new OwnerCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfigurationWithoutPermissions, new OwnerCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsIfGroupChanges() throws Exception { - executeCommand(jimFsConfiguration, new GroupCheckFileCommand(captureOutputTerminal, Mode.CHANGE)); + executeCommand(jimFsConfiguration, new GroupCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.CHANGE)); assertThat(captureOutputTerminal.getTerminalOutput(), hasItem(allOf(containsString("Group of file ["), containsString("] used to be ["), containsString("], but now is [")))); } @Test public void testThatCommandLogsNothingIfGroupRemainsSame() throws Exception { - executeCommand(jimFsConfiguration, new GroupCheckFileCommand(captureOutputTerminal, Mode.KEEP)); + executeCommand(jimFsConfiguration, new GroupCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.KEEP)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingIfGroupIsDisabled() throws Exception { - executeCommand(jimFsConfiguration, new GroupCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfiguration, new GroupCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingIfFileSystemDoesNotSupportGroups() throws Exception { - executeCommand(jimFsConfigurationWithoutPermissions, new GroupCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfigurationWithoutPermissions, new GroupCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @@ -130,7 +130,10 @@ public class CheckFileCommandTests extends ElasticsearchTestCase { try (FileSystem fs = Jimfs.newFileSystem(configuration)) { Path path = fs.getPath(randomAsciiOfLength(10)); - new CreateFileCommand(captureOutputTerminal, path).execute(ImmutableSettings.EMPTY, new Environment(ImmutableSettings.EMPTY)); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + new CreateFileCommand(captureOutputTerminal, path).execute(settings, new Environment(settings)); assertThat(Files.exists(path), is(true)); } @@ -145,7 +148,10 @@ public class CheckFileCommandTests extends ElasticsearchTestCase { Path path = fs.getPath(randomAsciiOfLength(10)); Files.write(path, "anything".getBytes(Charsets.UTF_8)); - new DeleteFileCommand(captureOutputTerminal, path).execute(ImmutableSettings.EMPTY, new Environment(ImmutableSettings.EMPTY)); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + new DeleteFileCommand(captureOutputTerminal, path).execute(settings, new Environment(settings)); assertThat(Files.exists(path), is(false)); } @@ -163,16 +169,21 @@ public class CheckFileCommandTests extends ElasticsearchTestCase { protected final Mode mode; protected FileSystem fs; protected Path[] paths; + final Path baseDir; - public AbstractTestCheckFileCommand(Terminal terminal, Mode mode) throws IOException { + public AbstractTestCheckFileCommand(Path baseDir, Terminal terminal, Mode mode) throws IOException { super(terminal); this.mode = mode; + this.baseDir = baseDir; } public CliTool.ExitStatus execute(FileSystem fs) throws Exception { this.fs = fs; this.paths = new Path[] { writePath(fs, "p1", "anything"), writePath(fs, "p2", "anything"), writePath(fs, "p3", "anything") }; - return super.execute(ImmutableSettings.EMPTY, new Environment(ImmutableSettings.EMPTY)); + Settings settings = ImmutableSettings.settingsBuilder() + .put("path.home", baseDir.toString()) + .build(); + return super.execute(ImmutableSettings.EMPTY, new Environment(settings)); } private Path writePath(FileSystem fs, String name, String content) throws IOException { @@ -192,8 +203,8 @@ public class CheckFileCommandTests extends ElasticsearchTestCase { */ class PermissionCheckFileCommand extends AbstractTestCheckFileCommand { - public PermissionCheckFileCommand(Terminal terminal, Mode mode) throws IOException { - super(terminal, mode); + public PermissionCheckFileCommand(Path baseDir, Terminal terminal, Mode mode) throws IOException { + super(baseDir, terminal, mode); } @Override @@ -221,8 +232,8 @@ public class CheckFileCommandTests extends ElasticsearchTestCase { */ class OwnerCheckFileCommand extends AbstractTestCheckFileCommand { - public OwnerCheckFileCommand(Terminal terminal, Mode mode) throws IOException { - super(terminal, mode); + public OwnerCheckFileCommand(Path baseDir, Terminal terminal, Mode mode) throws IOException { + super(baseDir, terminal, mode); } @Override @@ -251,8 +262,8 @@ public class CheckFileCommandTests extends ElasticsearchTestCase { */ class GroupCheckFileCommand extends AbstractTestCheckFileCommand { - public GroupCheckFileCommand(Terminal terminal, Mode mode) throws IOException { - super(terminal, mode); + public GroupCheckFileCommand(Path baseDir, Terminal terminal, Mode mode) throws IOException { + super(baseDir, terminal, mode); } @Override diff --git a/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java b/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java index c39c8a5b90f..24df66c77e8 100644 --- a/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java +++ b/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java @@ -56,6 +56,7 @@ public class Log4jESLoggerTests extends ElasticsearchTestCase { // Need to set custom path.conf so we can use a custom logging.yml file for the test Settings settings = ImmutableSettings.builder() .put("path.conf", configDir.toAbsolutePath()) + .put("path.home", createTempDir().toString()) .build(); LogConfigurator.configure(settings); diff --git a/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java b/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java index b53b434a492..1010ea734b3 100644 --- a/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java +++ b/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java @@ -59,6 +59,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { Path configDir = getDataPath("config"); Settings settings = ImmutableSettings.builder() .put("path.conf", configDir.toAbsolutePath()) + .put("path.home", createTempDir().toString()) .build(); LogConfigurator.configure(settings); @@ -87,7 +88,10 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { Path loggingConf = tmpDir.resolve(loggingConfiguration("json")); Files.write(loggingConf, "{\"json\": \"foo\"}".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( - ImmutableSettings.builder().put("path.conf", tmpDir.toAbsolutePath()).build()); + ImmutableSettings.builder() + .put("path.conf", tmpDir.toAbsolutePath()) + .put("path.home", createTempDir().toString()) + .build()); ImmutableSettings.Builder builder = ImmutableSettings.builder(); LogConfigurator.resolveConfig(environment, builder); @@ -102,7 +106,10 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { Path loggingConf = tmpDir.resolve(loggingConfiguration("properties")); Files.write(loggingConf, "key: value".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( - ImmutableSettings.builder().put("path.conf", tmpDir.toAbsolutePath()).build()); + ImmutableSettings.builder() + .put("path.conf", tmpDir.toAbsolutePath()) + .put("path.home", createTempDir().toString()) + .build()); ImmutableSettings.Builder builder = ImmutableSettings.builder(); LogConfigurator.resolveConfig(environment, builder); @@ -119,7 +126,10 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { Files.write(loggingConf1, "yml: bar".getBytes(StandardCharsets.UTF_8)); Files.write(loggingConf2, "yaml: bar".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( - ImmutableSettings.builder().put("path.conf", tmpDir.toAbsolutePath()).build()); + ImmutableSettings.builder() + .put("path.conf", tmpDir.toAbsolutePath()) + .put("path.home", createTempDir().toString()) + .build()); ImmutableSettings.Builder builder = ImmutableSettings.builder(); LogConfigurator.resolveConfig(environment, builder); @@ -135,7 +145,10 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { Path invalidSuffix = tmpDir.resolve(loggingConfiguration(randomFrom(LogConfigurator.ALLOWED_SUFFIXES)) + randomInvalidSuffix()); Files.write(invalidSuffix, "yml: bar".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( - ImmutableSettings.builder().put("path.conf", invalidSuffix.toAbsolutePath()).build()); + ImmutableSettings.builder() + .put("path.conf", invalidSuffix.toAbsolutePath()) + .put("path.home", createTempDir().toString()) + .build()); ImmutableSettings.Builder builder = ImmutableSettings.builder(); LogConfigurator.resolveConfig(environment, builder); diff --git a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java index fb9024a460d..8fb9a29488f 100644 --- a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java @@ -77,8 +77,11 @@ public class AnalysisModuleTests extends ElasticsearchTestCase { return injector.getInstance(AnalysisService.class); } - private static Settings loadFromClasspath(String path) { - return settingsBuilder().loadFromClasspath(path).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + private Settings loadFromClasspath(String path) { + return settingsBuilder().loadFromClasspath(path) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir().toString()) + .build(); } @@ -103,8 +106,11 @@ public class AnalysisModuleTests extends ElasticsearchTestCase { @Test public void testVersionedAnalyzers() throws Exception { - Settings settings2 = settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/test1.yml") - .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_0_90_0).build(); + Settings settings2 = settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/test1.yml") + .put("path.home", createTempDir().toString()) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_0_90_0) + .build(); AnalysisService analysisService2 = getAnalysisService(settings2); // indicesanalysisservice always has the current version @@ -202,11 +208,14 @@ public class AnalysisModuleTests extends ElasticsearchTestCase { @Test public void testWordListPath() throws Exception { - Environment env = new Environment(ImmutableSettings.Builder.EMPTY_SETTINGS); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + Environment env = new Environment(settings); String[] words = new String[]{"donau", "dampf", "schiff", "spargel", "creme", "suppe"}; Path wordListFile = generateWordList(words); - Settings settings = settingsBuilder().loadFromSource("index: \n word_list_path: " + wordListFile.toAbsolutePath()).build(); + settings = settingsBuilder().loadFromSource("index: \n word_list_path: " + wordListFile.toAbsolutePath()).build(); Set wordList = Analysis.getWordSet(env, settings, "index.word_list"); MatcherAssert.assertThat(wordList.size(), equalTo(6)); diff --git a/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java b/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java index e2715f690c8..c592579c801 100644 --- a/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java @@ -22,6 +22,7 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.ModulesBuilder; +import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; @@ -49,6 +50,7 @@ public class CharFilterTests extends ElasticsearchTokenStreamTestCase { .putArray("index.analysis.char_filter.my_mapping.mappings", "ph=>f", "qu=>q") .put("index.analysis.analyzer.custom_with_char_filter.tokenizer", "standard") .putArray("index.analysis.analyzer.custom_with_char_filter.char_filter", "my_mapping") + .put("path.home", createTempDir().toString()) .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector(); Injector injector = new ModulesBuilder().add( @@ -74,6 +76,7 @@ public class CharFilterTests extends ElasticsearchTokenStreamTestCase { .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("index.analysis.analyzer.custom_with_char_filter.tokenizer", "standard") .putArray("index.analysis.analyzer.custom_with_char_filter.char_filter", "html_strip") + .put("path.home", createTempDir().toString()) .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector(); Injector injector = new ModulesBuilder().add( diff --git a/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java b/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java index a3e7552f50b..37b3bfc21a7 100644 --- a/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java @@ -110,10 +110,18 @@ public class CompoundAnalysisTests extends ElasticsearchTestCase { } private Settings getJsonSettings() { - return settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/test1.json").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + return settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/test1.json") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir().toString()) + .build(); } private Settings getYamlSettings() { - return settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/test1.yml").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + return settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/test1.yml") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir().toString()) + .build(); } } diff --git a/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java b/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java index 996471a205c..eaab794e500 100644 --- a/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java @@ -42,7 +42,11 @@ public class PatternCaptureTokenFilterTests extends ElasticsearchTokenStreamTest @Test public void testPatternCaptureTokenFilter() throws Exception { Index index = new Index("test"); - Settings settings = settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/pattern_capture.json").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + Settings settings = settingsBuilder() + .put("path.home", createTempDir()) + .loadFromClasspath("org/elasticsearch/index/analysis/pattern_capture.json") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector(); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, settings), diff --git a/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java b/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java index 134b2cd5e3e..00e59547a69 100644 --- a/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java @@ -42,7 +42,11 @@ public class StopAnalyzerTests extends ElasticsearchTokenStreamTestCase { @Test public void testDefaultsCompoundAnalysis() throws Exception { Index index = new Index("test"); - Settings settings = settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/stop.json").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + Settings settings = settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/stop.json") + .put("path.home", createTempDir().toString()) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector(); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, settings), diff --git a/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java b/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java index 654a377a4f1..15872851d45 100644 --- a/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java +++ b/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java @@ -67,6 +67,7 @@ public class TemplateQueryParserTest extends ElasticsearchTestCase { @Before public void setup() throws IOException { Settings settings = ImmutableSettings.settingsBuilder() + .put("path.home", createTempDir().toString()) .put("path.conf", this.getDataPath("config")) .put("name", getClass().getName()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) diff --git a/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java b/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java index 8db6fd4e5c0..25cc99820b6 100644 --- a/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java +++ b/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java @@ -44,11 +44,20 @@ public class InternalSettingsPreparerTests extends ElasticsearchTestCase { @Test public void testIgnoreSystemProperties() { - Tuple tuple = InternalSettingsPreparer.prepareSettings(settingsBuilder().put("node.zone", "bar").build(), true); + Settings settings = settingsBuilder() + .put("node.zone", "bar") + .put("path.home", createTempDir().toString()) + .build(); + Tuple tuple = InternalSettingsPreparer.prepareSettings(settings, true); // Should use setting from the system property assertThat(tuple.v1().get("node.zone"), equalTo("foo")); - tuple = InternalSettingsPreparer.prepareSettings(settingsBuilder().put("config.ignore_system_properties", true).put("node.zone", "bar").build(), true); + settings = settingsBuilder() + .put("config.ignore_system_properties", true) + .put("node.zone", "bar") + .put("path.home", createTempDir().toString()) + .build(); + tuple = InternalSettingsPreparer.prepareSettings(settings, true); // Should use setting from the system property assertThat(tuple.v1().get("node.zone"), equalTo("bar")); } diff --git a/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index 69aa8685835..c3f164ab25f 100644 --- a/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -69,6 +69,7 @@ public class ScriptServiceTests extends ElasticsearchTestCase { public void setup() throws IOException { Path genericConfigFolder = createTempDir(); baseSettings = settingsBuilder() + .put("path.home", createTempDir().toString()) .put("path.conf", genericConfigFolder) .build(); resourceWatcherService = new ResourceWatcherService(baseSettings, null); diff --git a/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java b/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java index 86ae03992e2..c00ceec27b3 100644 --- a/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java +++ b/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java @@ -21,6 +21,7 @@ package org.elasticsearch.stresstest.client; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; @@ -38,8 +39,10 @@ public class ClientFailover { for (int i = 0; i < nodes.length; i++) { nodes[i] = NodeBuilder.nodeBuilder().node(); } + + // TODO: what is this? a public static void main test?!?! - final TransportClient client = new TransportClient() + final TransportClient client = new TransportClient(ImmutableSettings.EMPTY) .addTransportAddress(new InetSocketTransportAddress("localhost", 9300)) .addTransportAddress(new InetSocketTransportAddress("localhost", 9301)) .addTransportAddress(new InetSocketTransportAddress("localhost", 9302)); diff --git a/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java b/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java index 66239f34347..fb113a604b7 100644 --- a/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java +++ b/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java @@ -47,8 +47,9 @@ public class ManyIndicesRemoteStressTest { Client client; Node node = null; + // TODO: what is this? a public static void main test?!?!?! if (true) { - client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); + client = new TransportClient(ImmutableSettings.EMPTY).addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); } else { node = NodeBuilder.nodeBuilder().client(true).node(); client = node.client(); diff --git a/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java b/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java index 10b7fa91ac0..53919f8a718 100644 --- a/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java +++ b/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java @@ -66,6 +66,7 @@ public class NettyTransportMultiPortIntegrationTests extends ElasticsearchIntegr Settings settings = settingsBuilder() .put("cluster.name", internalCluster().getClusterName()) .put(TransportModule.TRANSPORT_TYPE_KEY, NettyTransport.class.getName()) + .put("path.home", createTempDir().toString()) .build(); try (TransportClient transportClient = new TransportClient(settings, false)) { transportClient.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", randomPort)); From 5236a3d226fa9e0e477ac81596af56a015b402af Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 29 Apr 2015 16:32:54 -0700 Subject: [PATCH 04/22] fix some tests, all fast tests now pass --- .../java/org/elasticsearch/tribe/TribeService.java | 1 + .../client/transport/TransportClientRetryTests.java | 3 ++- .../client/transport/TransportClientTests.java | 9 ++++++--- .../elasticsearch/common/cli/CliToolTestCase.java | 12 ++++++++++++ .../query/plugin/IndexQueryParserPlugin2Tests.java | 8 +++++++- .../query/plugin/IndexQueryParserPluginTests.java | 8 +++++++- .../org/elasticsearch/script/NativeScriptTests.java | 5 ++++- .../java/org/elasticsearch/tribe/TribeUnitTests.java | 3 ++- 8 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/elasticsearch/tribe/TribeService.java b/src/main/java/org/elasticsearch/tribe/TribeService.java index 51cb9d0ecab..d0cfe765817 100644 --- a/src/main/java/org/elasticsearch/tribe/TribeService.java +++ b/src/main/java/org/elasticsearch/tribe/TribeService.java @@ -127,6 +127,7 @@ public class TribeService extends AbstractLifecycleComponent { for (Map.Entry entry : nodesSettings.entrySet()) { ImmutableSettings.Builder sb = ImmutableSettings.builder().put(entry.getValue()); sb.put("node.name", settings.get("name") + "/" + entry.getKey()); + sb.put("path.home", settings.get("path.home")); // pass through ES home dir sb.put(TRIBE_NAME, entry.getKey()); sb.put("config.ignore_system_properties", true); if (sb.get("http.enabled") == null) { diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java index c1d11bb2312..716296bd0f2 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java @@ -62,7 +62,8 @@ public class TransportClientRetryTests extends ElasticsearchIntegrationTest { .put("node.mode", InternalTestCluster.nodeMode()) .put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) .put(ClusterName.SETTING, internalCluster().getClusterName()) - .put("config.ignore_system_properties", true); + .put("config.ignore_system_properties", true) + .put("path.home", createTempDir()); try (TransportClient transportClient = new TransportClient(builder.build())) { transportClient.addTransportAddresses(addresses); diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java index 8e347935241..b540800c5d1 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java @@ -25,7 +25,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.node.Node; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; @@ -35,7 +34,10 @@ import org.junit.Test; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.elasticsearch.node.NodeBuilder.nodeBuilder; import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.startsWith; @ClusterScope(scope = Scope.TEST, numDataNodes = 0, transportClientRatio = 1.0) public class TransportClientTests extends ElasticsearchIntegrationTest { @@ -92,7 +94,8 @@ public class TransportClientTests extends ElasticsearchIntegrationTest { @Test public void testThatTransportClientSettingCannotBeChanged() { - try (TransportClient client = new TransportClient(settingsBuilder().put(Client.CLIENT_TYPE_SETTING, "anything"))) { + Settings baseSettings = settingsBuilder().put(Client.CLIENT_TYPE_SETTING, "anything").put("path.home", createTempDir()).build(); + try (TransportClient client = new TransportClient(baseSettings)) { Settings settings = client.injector.getInstance(Settings.class); assertThat(settings.get(Client.CLIENT_TYPE_SETTING), is("transport")); } diff --git a/src/test/java/org/elasticsearch/common/cli/CliToolTestCase.java b/src/test/java/org/elasticsearch/common/cli/CliToolTestCase.java index df633b57c7b..278869388ce 100644 --- a/src/test/java/org/elasticsearch/common/cli/CliToolTestCase.java +++ b/src/test/java/org/elasticsearch/common/cli/CliToolTestCase.java @@ -22,6 +22,8 @@ package org.elasticsearch.common.cli; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.Strings; import org.elasticsearch.test.ElasticsearchTestCase; +import org.junit.After; +import org.junit.Before; import org.junit.Ignore; import java.io.IOException; @@ -37,6 +39,16 @@ import java.util.Locale; @Ignore public abstract class CliToolTestCase extends ElasticsearchTestCase { + @Before + public void setPathHome() { + System.setProperty("es.default.path.home", createTempDir().toString()); + } + + @After + public void clearPathHome() { + System.clearProperty("es.default.path.home"); + } + protected static String[] args(String command) { if (!Strings.hasLength(command)) { return Strings.EMPTY_ARRAY; diff --git a/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPlugin2Tests.java b/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPlugin2Tests.java index 75cccb7000f..a7d30c465dd 100644 --- a/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPlugin2Tests.java +++ b/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPlugin2Tests.java @@ -29,6 +29,8 @@ import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; +import org.elasticsearch.env.Environment; +import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.analysis.AnalysisModule; @@ -56,7 +58,10 @@ public class IndexQueryParserPlugin2Tests extends ElasticsearchTestCase { @Test public void testCustomInjection() throws InterruptedException { - Settings settings = ImmutableSettings.builder().put("name", "testCustomInjection").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + Settings settings = ImmutableSettings.builder() + .put("name", "testCustomInjection") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir()).build(); IndexQueryParserModule queryParserModule = new IndexQueryParserModule(settings); queryParserModule.addQueryParser("my", PluginJsonQueryParser.class); @@ -64,6 +69,7 @@ public class IndexQueryParserPlugin2Tests extends ElasticsearchTestCase { Index index = new Index("test"); Injector injector = new ModulesBuilder().add( + new EnvironmentModule(new Environment(settings)), new SettingsModule(settings), new ThreadPoolModule(settings), new IndicesQueriesModule(), diff --git a/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPluginTests.java b/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPluginTests.java index 92ce6bcde20..bbbee452284 100644 --- a/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPluginTests.java +++ b/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPluginTests.java @@ -29,6 +29,8 @@ import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; +import org.elasticsearch.env.Environment; +import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.analysis.AnalysisModule; @@ -56,7 +58,10 @@ public class IndexQueryParserPluginTests extends ElasticsearchTestCase { @Test public void testCustomInjection() throws InterruptedException { - Settings settings = ImmutableSettings.builder().put("name", "testCustomInjection").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + Settings settings = ImmutableSettings.builder() + .put("name", "testCustomInjection") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir()).build(); IndexQueryParserModule queryParserModule = new IndexQueryParserModule(settings); queryParserModule.addProcessor(new IndexQueryParserModule.QueryParsersProcessor() { @@ -73,6 +78,7 @@ public class IndexQueryParserPluginTests extends ElasticsearchTestCase { Index index = new Index("test"); Injector injector = new ModulesBuilder().add( + new EnvironmentModule(new Environment(settings)), new SettingsModule(settings), new ThreadPoolModule(settings), new IndicesQueriesModule(), diff --git a/src/test/java/org/elasticsearch/script/NativeScriptTests.java b/src/test/java/org/elasticsearch/script/NativeScriptTests.java index 951f605801e..04c2e63e020 100644 --- a/src/test/java/org/elasticsearch/script/NativeScriptTests.java +++ b/src/test/java/org/elasticsearch/script/NativeScriptTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; +import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -50,8 +51,10 @@ public class NativeScriptTests extends ElasticsearchTestCase { Settings settings = ImmutableSettings.settingsBuilder() .put("script.native.my.type", MyNativeScriptFactory.class.getName()) .put("name", "testNativeScript") + .put("path.home", createTempDir()) .build(); Injector injector = new ModulesBuilder().add( + new EnvironmentModule(new Environment(settings)), new ThreadPoolModule(settings), new SettingsModule(settings), new ScriptModule(settings)).createInjector(); @@ -73,7 +76,7 @@ public class NativeScriptTests extends ElasticsearchTestCase { String scriptContext = randomFrom(ScriptContext.Standard.values()).getKey(); builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + scriptContext, randomFrom(ScriptMode.values())); } - Settings settings = builder.build(); + Settings settings = builder.put("path.home", createTempDir()).build(); Environment environment = new Environment(settings); ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, null); Map nativeScriptFactoryMap = new HashMap<>(); diff --git a/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java b/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java index 2089404165c..2f1e81eead7 100644 --- a/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java +++ b/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java @@ -95,7 +95,8 @@ public class TribeUnitTests extends ElasticsearchTestCase { //tribe node doesn't need the node.mode setting, as it's forced local internally anyways. The tribe clients do need it to make sure //they can find their corresponding tribes using the proper transport Settings settings = ImmutableSettings.builder().put("http.enabled", false).put("node.name", "tribe_node") - .put("tribe.t1.node.mode", NODE_MODE).put("tribe.t2.node.mode", NODE_MODE).put(extraSettings).build(); + .put("tribe.t1.node.mode", NODE_MODE).put("tribe.t2.node.mode", NODE_MODE) + .put("path.home", createTempDir()).put(extraSettings).build(); try (Node node = NodeBuilder.nodeBuilder().settings(settings).node()) { try (Client client = node.client()) { From 09ff11812ee07a88a5ef5b551c62b19f43933795 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 1 May 2015 14:58:18 -0400 Subject: [PATCH 05/22] add debugging --- .../org/elasticsearch/bootstrap/Security.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index 67ac531f0e7..d5910e36202 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -20,8 +20,10 @@ package org.elasticsearch.bootstrap; import com.google.common.io.ByteStreams; + import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.StringHelper; +import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.env.Environment; import java.io.*; @@ -29,6 +31,9 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; +import java.security.NoSuchAlgorithmException; +import java.security.Policy; +import java.security.URIParameter; /** * Initializes securitymanager with necessary permissions. @@ -45,6 +50,7 @@ class Security { * Initializes securitymanager for the environment * Can only happen once! */ + @SuppressForbidden(reason = "just debugging") static void configure(Environment environment) throws IOException { // init lucene random seed. it will use /dev/urandom where available. StringHelper.randomId(); @@ -54,8 +60,19 @@ class Security { } Path newConfig = processTemplate(config, environment); System.setProperty("java.security.policy", newConfig.toString()); + try { + Policy policy = Policy.getInstance("JavaPolicy", new URIParameter(newConfig.toUri())); + System.out.println(policy.getPermissions(Security.class.getProtectionDomain())); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(); + } System.setSecurityManager(new SecurityManager()); - IOUtils.deleteFilesIgnoringExceptions(newConfig); // TODO: maybe log something if it fails? + try { + // don't hide securityexception here, it means java.io.tmpdir is not accessible! + Files.delete(newConfig); + } catch (IOException ignore) { + // e.g. virus scanner on windows + } } // package-private for testing From 6e6949d3f4183f223b2b74553b9400d28e3aaaed Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 1 May 2015 15:47:50 -0400 Subject: [PATCH 06/22] Add debugging when security init screws up (or at trace level if you wish) --- .../org/elasticsearch/bootstrap/Security.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index d5910e36202..49c2bccf827 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -21,9 +21,9 @@ package org.elasticsearch.bootstrap; import com.google.common.io.ByteStreams; -import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.StringHelper; -import org.elasticsearch.common.SuppressForbidden; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.env.Environment; import java.io.*; @@ -32,6 +32,7 @@ import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.security.NoSuchAlgorithmException; +import java.security.PermissionCollection; import java.security.Policy; import java.security.URIParameter; @@ -50,8 +51,8 @@ class Security { * Initializes securitymanager for the environment * Can only happen once! */ - @SuppressForbidden(reason = "just debugging") static void configure(Environment environment) throws IOException { + ESLogger log = Loggers.getLogger(Security.class); // init lucene random seed. it will use /dev/urandom where available. StringHelper.randomId(); InputStream config = Security.class.getResourceAsStream(POLICY_RESOURCE); @@ -60,16 +61,23 @@ class Security { } Path newConfig = processTemplate(config, environment); System.setProperty("java.security.policy", newConfig.toString()); + // retrieve the parsed policy we created: its useful if something goes wrong + Policy policy = null; try { - Policy policy = Policy.getInstance("JavaPolicy", new URIParameter(newConfig.toUri())); - System.out.println(policy.getPermissions(Security.class.getProtectionDomain())); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(); + policy = Policy.getInstance("JavaPolicy", new URIParameter(newConfig.toUri())); + } catch (NoSuchAlgorithmException impossible) { + throw new RuntimeException(impossible); } + PermissionCollection permissions = policy.getPermissions(Security.class.getProtectionDomain()); + log.trace("generated permissions: {}", permissions); + System.setSecurityManager(new SecurityManager()); try { // don't hide securityexception here, it means java.io.tmpdir is not accessible! Files.delete(newConfig); + } catch (SecurityException broken) { + log.error("unable to properly access temporary files, permissions: {}", permissions); + throw broken; } catch (IOException ignore) { // e.g. virus scanner on windows } From dbcdb40f68c3b85f9dda3c28a5796a7205d70079 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 1 May 2015 16:02:00 -0400 Subject: [PATCH 07/22] fix sigar policy line that cannot be really working --- src/main/resources/org/elasticsearch/bootstrap/security.policy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index ffc0032d4a0..4b9b9699e80 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -34,7 +34,7 @@ grant { // project base directory permission java.io.FilePermission "${project.basedir}${/}target${/}-", "read"; // read permission for lib sigar - permission java.io.FilePermission "${project.basedir}${/}lib/sigar{/}-", "read"; + permission java.io.FilePermission "${project.basedir}${/}lib${/}sigar${/}-", "read"; // mvn custom ./m2/repository for dependency jars permission java.io.FilePermission "${m2.repository}${/}-", "read"; From 50a785c5463e1e810d6cdaf6ab25662579a14024 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 1 May 2015 16:41:49 -0400 Subject: [PATCH 08/22] add a hack to see if this fixes windows issues --- src/main/resources/org/elasticsearch/bootstrap/security.policy | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index 4b9b9699e80..0b88aba449d 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -28,6 +28,7 @@ grant { // temporary files permission java.io.FilePermission "${java.io.tmpdir}", "read,write"; + permission java.io.FilePermission "${java.io.tmpdir}-", "read,write,delete"; permission java.io.FilePermission "${java.io.tmpdir}${/}-", "read,write,delete"; // paths used for running tests From db003a0b32de7dcd499f71a5d15f6accd20b2590 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 2 May 2015 10:52:27 -0400 Subject: [PATCH 09/22] remove hack --- src/main/resources/org/elasticsearch/bootstrap/security.policy | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index 0b88aba449d..4b9b9699e80 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -28,7 +28,6 @@ grant { // temporary files permission java.io.FilePermission "${java.io.tmpdir}", "read,write"; - permission java.io.FilePermission "${java.io.tmpdir}-", "read,write,delete"; permission java.io.FilePermission "${java.io.tmpdir}${/}-", "read,write,delete"; // paths used for running tests From ff44f45af160b5ccdf0a0362c4e0215431f5e1ed Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 2 May 2015 12:08:46 -0400 Subject: [PATCH 10/22] log this --- src/main/java/org/elasticsearch/bootstrap/Security.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index 49c2bccf827..7f3b450cbc0 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -53,6 +53,7 @@ class Security { */ static void configure(Environment environment) throws IOException { ESLogger log = Loggers.getLogger(Security.class); + log.info("java.io.tmpdir: {}", System.getProperty("java.io.tmpdir")); // init lucene random seed. it will use /dev/urandom where available. StringHelper.randomId(); InputStream config = Security.class.getResourceAsStream(POLICY_RESOURCE); From e1238c5e4c722498b5e6515a932d7cbd8018bd87 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 2 May 2015 12:11:33 -0400 Subject: [PATCH 11/22] add 2 more x --- src/main/java/org/elasticsearch/bootstrap/Security.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index 7f3b450cbc0..f0181fee243 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -71,12 +71,14 @@ class Security { } PermissionCollection permissions = policy.getPermissions(Security.class.getProtectionDomain()); log.trace("generated permissions: {}", permissions); - + log.info("java.io.tmpdir: {}", System.getProperty("java.io.tmpdir")); + System.setSecurityManager(new SecurityManager()); try { // don't hide securityexception here, it means java.io.tmpdir is not accessible! Files.delete(newConfig); } catch (SecurityException broken) { + log.info("java.io.tmpdir: {}", System.getProperty("java.io.tmpdir")); log.error("unable to properly access temporary files, permissions: {}", permissions); throw broken; } catch (IOException ignore) { From bdd6d9c705ad0a2176364a7dc06e7af8bcb6cba2 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 2 May 2015 12:27:38 -0400 Subject: [PATCH 12/22] heisenbug --- src/main/java/org/elasticsearch/bootstrap/Security.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index f0181fee243..2a216626c66 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -53,7 +53,8 @@ class Security { */ static void configure(Environment environment) throws IOException { ESLogger log = Loggers.getLogger(Security.class); - log.info("java.io.tmpdir: {}", System.getProperty("java.io.tmpdir")); + //String prop = System.getProperty("java.io.tmpdir"); + //log.trace("java.io.tmpdir {}", prop); // init lucene random seed. it will use /dev/urandom where available. StringHelper.randomId(); InputStream config = Security.class.getResourceAsStream(POLICY_RESOURCE); @@ -71,14 +72,12 @@ class Security { } PermissionCollection permissions = policy.getPermissions(Security.class.getProtectionDomain()); log.trace("generated permissions: {}", permissions); - log.info("java.io.tmpdir: {}", System.getProperty("java.io.tmpdir")); System.setSecurityManager(new SecurityManager()); try { // don't hide securityexception here, it means java.io.tmpdir is not accessible! Files.delete(newConfig); } catch (SecurityException broken) { - log.info("java.io.tmpdir: {}", System.getProperty("java.io.tmpdir")); log.error("unable to properly access temporary files, permissions: {}", permissions); throw broken; } catch (IOException ignore) { From 8c0d03c3ee1b45d3b21c184606d088aca18aa6d4 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 2 May 2015 12:41:38 -0400 Subject: [PATCH 13/22] add a hack for windows --- .../org/elasticsearch/bootstrap/Security.java | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index 2a216626c66..536ccd47908 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -31,10 +31,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.security.NoSuchAlgorithmException; -import java.security.PermissionCollection; -import java.security.Policy; -import java.security.URIParameter; /** * Initializes securitymanager with necessary permissions. @@ -53,8 +49,6 @@ class Security { */ static void configure(Environment environment) throws IOException { ESLogger log = Loggers.getLogger(Security.class); - //String prop = System.getProperty("java.io.tmpdir"); - //log.trace("java.io.tmpdir {}", prop); // init lucene random seed. it will use /dev/urandom where available. StringHelper.randomId(); InputStream config = Security.class.getResourceAsStream(POLICY_RESOURCE); @@ -63,22 +57,12 @@ class Security { } Path newConfig = processTemplate(config, environment); System.setProperty("java.security.policy", newConfig.toString()); - // retrieve the parsed policy we created: its useful if something goes wrong - Policy policy = null; - try { - policy = Policy.getInstance("JavaPolicy", new URIParameter(newConfig.toUri())); - } catch (NoSuchAlgorithmException impossible) { - throw new RuntimeException(impossible); - } - PermissionCollection permissions = policy.getPermissions(Security.class.getProtectionDomain()); - log.trace("generated permissions: {}", permissions); - System.setSecurityManager(new SecurityManager()); try { // don't hide securityexception here, it means java.io.tmpdir is not accessible! Files.delete(newConfig); } catch (SecurityException broken) { - log.error("unable to properly access temporary files, permissions: {}", permissions); + log.error("unable to properly access temporary files, run with -Djava.security.debug=policy for more information"); throw broken; } catch (IOException ignore) { // e.g. virus scanner on windows @@ -108,6 +92,11 @@ class Security { addPath(writer, environment.configFile(), "read,readlink,write,delete"); addPath(writer, environment.logsFile(), "read,readlink,write,delete"); addPath(writer, environment.pluginsFile(), "read,readlink,write,delete"); + + // generate explicit perms for actual temp dir: + // (in case there is java.io.tmpdir sheistiness on windows) + addPath(writer, processed.getParent(), "read,readlink,write,delete"); + for (Path path : environment.dataFiles()) { addPath(writer, path, "read,readlink,write,delete"); } From 86fc8ceac71fbcfe95d6675eeb6b2ffc2cb71d41 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 2 May 2015 14:42:06 -0400 Subject: [PATCH 14/22] simplify security rules --- .../org/elasticsearch/bootstrap/Security.java | 139 ++++++++---------- .../bootstrap/SecurityTests.java | 36 ++--- 2 files changed, 79 insertions(+), 96 deletions(-) diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index 536ccd47908..a9eedb7816a 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -19,18 +19,19 @@ package org.elasticsearch.bootstrap; -import com.google.common.io.ByteStreams; - import org.apache.lucene.util.StringHelper; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.env.Environment; import java.io.*; -import java.nio.charset.StandardCharsets; +import java.net.URI; import java.nio.file.Files; -import java.nio.file.NoSuchFileException; import java.nio.file.Path; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Permissions; +import java.security.Policy; +import java.security.ProtectionDomain; +import java.security.URIParameter; /** * Initializes securitymanager with necessary permissions. @@ -47,84 +48,74 @@ class Security { * Initializes securitymanager for the environment * Can only happen once! */ - static void configure(Environment environment) throws IOException { - ESLogger log = Loggers.getLogger(Security.class); - // init lucene random seed. it will use /dev/urandom where available. + static void configure(Environment environment) throws Exception { + // init lucene random seed. it will use /dev/urandom where available: StringHelper.randomId(); - InputStream config = Security.class.getResourceAsStream(POLICY_RESOURCE); - if (config == null) { - throw new NoSuchFileException(POLICY_RESOURCE); - } - Path newConfig = processTemplate(config, environment); - System.setProperty("java.security.policy", newConfig.toString()); + + // enable security policy: union of template and environment-based paths. + URI template = Security.class.getResource(POLICY_RESOURCE).toURI(); + Policy.setPolicy(new ESPolicy(template, createPermissions(environment))); + + // enable security manager System.setSecurityManager(new SecurityManager()); - try { - // don't hide securityexception here, it means java.io.tmpdir is not accessible! - Files.delete(newConfig); - } catch (SecurityException broken) { - log.error("unable to properly access temporary files, run with -Djava.security.debug=policy for more information"); - throw broken; - } catch (IOException ignore) { - // e.g. virus scanner on windows - } + + // do some basic tests + selfTest(); } - - // package-private for testing - static Path processTemplate(InputStream template, Environment environment) throws IOException { - Path processed = Files.createTempFile(null, null); - try (OutputStream output = new BufferedOutputStream(Files.newOutputStream(processed))) { - // copy the template as-is. - try (InputStream in = new BufferedInputStream(template)) { - ByteStreams.copy(in, output); - } - // all policy files are UTF-8: - // https://docs.oracle.com/javase/7/docs/technotes/guides/security/PolicyFiles.html - try (Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) { - writer.write(System.lineSeparator()); - writer.write("grant {"); - writer.write(System.lineSeparator()); - - // add permissions for all configured paths. - // TODO: improve test infra so we can reduce permissions where read/write - // is not really needed... - addPath(writer, environment.homeFile(), "read,readlink,write,delete"); - addPath(writer, environment.configFile(), "read,readlink,write,delete"); - addPath(writer, environment.logsFile(), "read,readlink,write,delete"); - addPath(writer, environment.pluginsFile(), "read,readlink,write,delete"); - - // generate explicit perms for actual temp dir: - // (in case there is java.io.tmpdir sheistiness on windows) - addPath(writer, processed.getParent(), "read,readlink,write,delete"); - - for (Path path : environment.dataFiles()) { - addPath(writer, path, "read,readlink,write,delete"); - } - for (Path path : environment.dataWithClusterFiles()) { - addPath(writer, path, "read,readlink,write,delete"); - } - - writer.write("};"); - writer.write(System.lineSeparator()); - } + /** returns dynamic Permissions to configured paths */ + static Permissions createPermissions(Environment environment) throws IOException { + // TODO: improve test infra so we can reduce permissions where read/write + // is not really needed... + Permissions policy = new Permissions(); + addPath(policy, environment.homeFile(), "read,readlink,write,delete"); + addPath(policy, environment.configFile(), "read,readlink,write,delete"); + addPath(policy, environment.logsFile(), "read,readlink,write,delete"); + addPath(policy, environment.pluginsFile(), "read,readlink,write,delete"); + for (Path path : environment.dataFiles()) { + addPath(policy, path, "read,readlink,write,delete"); } - return processed; + for (Path path : environment.dataWithClusterFiles()) { + addPath(policy, path, "read,readlink,write,delete"); + } + + return policy; } - static void addPath(Writer writer, Path path, String permissions) throws IOException { + /** Add access to path (and all files underneath it */ + static void addPath(Permissions policy, Path path, String permissions) throws IOException { // paths may not exist yet Files.createDirectories(path); // add each path twice: once for itself, again for files underneath it - writer.write("permission java.io.FilePermission \"" + encode(path) + "\", \"" + permissions + "\";"); - writer.write(System.lineSeparator()); - writer.write("permission java.io.FilePermission \"" + encode(path) + "${/}-\", \"" + permissions + "\";"); - writer.write(System.lineSeparator()); + policy.add(new FilePermission(path.toString(), permissions)); + policy.add(new FilePermission(path.toString() + path.getFileSystem().getSeparator() + "-", permissions)); } - - // Any backslashes in paths must be escaped, because it is the escape character when parsing. - // See "Note Regarding File Path Specifications on Windows Systems". - // https://docs.oracle.com/javase/7/docs/technotes/guides/security/PolicyFiles.html - static String encode(Path path) { - return path.toString().replace("\\", "\\\\"); + + /** Simple checks that everything is ok */ + static void selfTest() { + // check we can manipulate temporary files + try { + Files.delete(Files.createTempFile(null, null)); + } catch (IOException ignored) { + // potentially virus scanner + } catch (SecurityException problem) { + throw new SecurityException("Security misconfiguration: cannot access java.io.tmpdir", problem); + } + } + + /** custom policy for union of static and dynamic permissions */ + static class ESPolicy extends Policy { + final Policy template; + final PermissionCollection dynamic; + + ESPolicy(URI template, PermissionCollection dynamic) throws Exception { + this.template = Policy.getInstance("JavaPolicy", new URIParameter(template)); + this.dynamic = dynamic; + } + + @Override + public boolean implies(ProtectionDomain domain, Permission permission) { + return template.implies(domain, permission) || dynamic.implies(permission); + } } } diff --git a/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java b/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java index 4c2ddcd47eb..edbcafdddbd 100644 --- a/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java +++ b/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java @@ -24,12 +24,9 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.test.ElasticsearchTestCase; -import java.io.ByteArrayInputStream; import java.io.FilePermission; import java.nio.file.Path; -import java.security.Policy; -import java.security.ProtectionDomain; -import java.security.URIParameter; +import java.security.Permissions; public class SecurityTests extends ElasticsearchTestCase { @@ -42,17 +39,15 @@ public class SecurityTests extends ElasticsearchTestCase { settingsBuilder.put("path.home", esHome.toString()); Settings settings = settingsBuilder.build(); - Environment environment = new Environment(settings); - Path policyFile = Security.processTemplate(new ByteArrayInputStream(new byte[0]), environment); + Environment environment = new Environment(settings); + Permissions permissions = Security.createPermissions(environment); - ProtectionDomain domain = getClass().getProtectionDomain(); - Policy policy = Policy.getInstance("JavaPolicy", new URIParameter(policyFile.toUri())); // the fake es home - assertTrue(policy.implies(domain, new FilePermission(esHome.toString(), "read"))); + assertTrue(permissions.implies(new FilePermission(esHome.toString(), "read"))); // its parent - assertFalse(policy.implies(domain, new FilePermission(path.toString(), "read"))); + assertFalse(permissions.implies(new FilePermission(path.toString(), "read"))); // some other sibling - assertFalse(policy.implies(domain, new FilePermission(path.resolve("other").toString(), "read"))); + assertFalse(permissions.implies(new FilePermission(path.resolve("other").toString(), "read"))); } /** test generated permissions for all configured paths */ @@ -67,29 +62,26 @@ public class SecurityTests extends ElasticsearchTestCase { settingsBuilder.put("path.logs", path.resolve("logs").toString()); Settings settings = settingsBuilder.build(); - Environment environment = new Environment(settings); - Path policyFile = Security.processTemplate(new ByteArrayInputStream(new byte[0]), environment); - - ProtectionDomain domain = getClass().getProtectionDomain(); - Policy policy = Policy.getInstance("JavaPolicy", new URIParameter(policyFile.toUri())); + Environment environment = new Environment(settings); + Permissions permissions = Security.createPermissions(environment); // check that all directories got permissions: // homefile: this is needed unless we break out rules for "lib" dir. // TODO: make read-only - assertTrue(policy.implies(domain, new FilePermission(environment.homeFile().toString(), "read,readlink,write,delete"))); + assertTrue(permissions.implies(new FilePermission(environment.homeFile().toString(), "read,readlink,write,delete"))); // config file // TODO: make read-only - assertTrue(policy.implies(domain, new FilePermission(environment.configFile().toString(), "read,readlink,write,delete"))); + assertTrue(permissions.implies(new FilePermission(environment.configFile().toString(), "read,readlink,write,delete"))); // plugins: r/w, TODO: can this be minimized? - assertTrue(policy.implies(domain, new FilePermission(environment.pluginsFile().toString(), "read,readlink,write,delete"))); + assertTrue(permissions.implies(new FilePermission(environment.pluginsFile().toString(), "read,readlink,write,delete"))); // data paths: r/w for (Path dataPath : environment.dataFiles()) { - assertTrue(policy.implies(domain, new FilePermission(dataPath.toString(), "read,readlink,write,delete"))); + assertTrue(permissions.implies(new FilePermission(dataPath.toString(), "read,readlink,write,delete"))); } for (Path dataPath : environment.dataWithClusterFiles()) { - assertTrue(policy.implies(domain, new FilePermission(dataPath.toString(), "read,readlink,write,delete"))); + assertTrue(permissions.implies(new FilePermission(dataPath.toString(), "read,readlink,write,delete"))); } // logs: r/w - assertTrue(policy.implies(domain, new FilePermission(environment.logsFile().toString(), "read,readlink,write,delete"))); + assertTrue(permissions.implies(new FilePermission(environment.logsFile().toString(), "read,readlink,write,delete"))); } } From fc54ff5f10d27291d2cd8734b411936f413ffd03 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 2 May 2015 15:19:01 -0400 Subject: [PATCH 15/22] remove now-unnecessary test permission --- src/main/resources/org/elasticsearch/bootstrap/security.policy | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index 4b9b9699e80..027e4bd3ea5 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -86,7 +86,6 @@ grant { // needed for testing access rules etc permission java.lang.RuntimePermission "createSecurityManager"; - permission java.security.SecurityPermission "createPolicy.JavaPolicy"; // reflection hacks: // needed for Striped64 (what is this doing), also enables unmap hack From 3a89b990ead0600458ed58035359ae4738b6f632 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sun, 3 May 2015 23:37:05 -0400 Subject: [PATCH 16/22] remove another unnecessary permission --- src/main/resources/org/elasticsearch/bootstrap/security.policy | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index 027e4bd3ea5..438fa87d333 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -84,9 +84,6 @@ grant { // needed for natives calls permission java.lang.RuntimePermission "loadLibrary.*"; - // needed for testing access rules etc - permission java.lang.RuntimePermission "createSecurityManager"; - // reflection hacks: // needed for Striped64 (what is this doing), also enables unmap hack permission java.lang.RuntimePermission "accessClassInPackage.sun.misc"; From b87d360e79726813db90c7acecc965057a4a39ed Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sun, 3 May 2015 23:58:39 +0200 Subject: [PATCH 17/22] Automatically thread client based action listeners Today, we rely on the user to set request listener threads to true when they are on the client side in order not to block the IO threads on heavy operations. This proves to be very trappy for users, and end up creating problems that are very hard to debug. Instead, we can do the right thing, and automatically thread listeners that are used from the client when the client is a node client or a transport client. This change also removes the ability to set request level listener threading, in the effort of simplifying the code path and reasoning around when something is threaded and when it is not. closes #10940 --- .../elasticsearch/action/ActionRequest.java | 21 ---- .../action/ActionRequestBuilder.java | 8 +- .../action/TransportActionNodeProxy.java | 32 +---- .../get/TransportGetFieldMappingsAction.java | 2 - .../mlt/TransportMoreLikeThisAction.java | 4 +- .../search/SearchScrollRequestBuilder.java | 8 -- .../AbstractListenableActionFuture.java | 40 ++----- .../support/HandledTransportAction.java | 2 - .../support/PlainListenableActionFuture.java | 4 +- .../support/ThreadedActionListener.java | 110 ++++++++++++++++++ .../action/support/TransportAction.java | 73 ------------ .../TransportMasterNodeOperationAction.java | 14 +-- ...nsportShardReplicationOperationAction.java | 2 - .../TransportShardSingleOperationAction.java | 2 - .../elasticsearch/client/node/NodeClient.java | 17 ++- .../client/node/NodeClusterAdminClient.java | 22 ++-- .../client/node/NodeIndicesAdminClient.java | 22 ++-- .../client/transport/TransportClient.java | 2 +- .../TransportClientNodesService.java | 37 +----- .../support/InternalTransportClient.java | 12 +- .../InternalTransportClusterAdminClient.java | 13 ++- .../InternalTransportIndicesAdminClient.java | 11 +- .../health/RestClusterHealthAction.java | 1 - .../node/info/RestNodesInfoAction.java | 2 - .../node/stats/RestNodesStatsAction.java | 1 - .../delete/RestDeleteRepositoryAction.java | 1 - .../put/RestPutRepositoryAction.java | 1 - .../verify/RestVerifyRepositoryAction.java | 1 - .../reroute/RestClusterRerouteAction.java | 1 - .../RestClusterGetSettingsAction.java | 1 - .../RestClusterUpdateSettingsAction.java | 1 - .../shards/RestClusterSearchShardsAction.java | 1 - .../create/RestCreateSnapshotAction.java | 1 - .../cluster/state/RestClusterStateAction.java | 1 - .../cluster/stats/RestClusterStatsAction.java | 1 - .../alias/RestIndicesAliasesAction.java | 1 - .../get/RestGetIndicesAliasesAction.java | 1 - .../indices/analyze/RestAnalyzeAction.java | 1 - .../clear/RestClearIndicesCacheAction.java | 1 - .../indices/close/RestCloseIndexAction.java | 1 - .../indices/create/RestCreateIndexAction.java | 1 - .../indices/delete/RestDeleteIndexAction.java | 1 - .../indices/RestIndicesExistsAction.java | 1 - .../exists/types/RestTypesExistsAction.java | 1 - .../admin/indices/flush/RestFlushAction.java | 1 - .../mapping/put/RestPutMappingAction.java | 1 - .../indices/open/RestOpenIndexAction.java | 1 - .../indices/optimize/RestOptimizeAction.java | 1 - .../indices/recovery/RestRecoveryAction.java | 1 - .../indices/refresh/RestRefreshAction.java | 1 - .../segments/RestIndicesSegmentsAction.java | 1 - .../settings/RestUpdateSettingsAction.java | 1 - .../indices/stats/RestIndicesStatsAction.java | 1 - .../delete/RestDeleteIndexTemplateAction.java | 1 - .../get/RestGetIndexTemplateAction.java | 2 - .../put/RestPutIndexTemplateAction.java | 1 - .../query/RestValidateQueryAction.java | 1 - .../warmer/delete/RestDeleteWarmerAction.java | 1 - .../warmer/put/RestPutWarmerAction.java | 1 - .../rest/action/bulk/RestBulkAction.java | 1 - .../rest/action/cat/RestRecoveryAction.java | 1 - .../rest/action/count/RestCountAction.java | 1 - .../rest/action/delete/RestDeleteAction.java | 1 - .../rest/action/exists/RestExistsAction.java | 1 - .../fieldstats/RestFieldStatsAction.java | 1 - .../rest/action/get/RestGetAction.java | 1 - .../rest/action/get/RestGetSourceAction.java | 1 - .../rest/action/get/RestHeadAction.java | 1 - .../rest/action/get/RestMultiGetAction.java | 1 - .../rest/action/index/RestIndexAction.java | 1 - .../action/mlt/RestMoreLikeThisAction.java | 2 - .../action/percolate/RestPercolateAction.java | 2 - .../script/RestPutIndexedScriptAction.java | 2 +- .../action/search/RestMultiSearchAction.java | 1 - .../rest/action/search/RestSearchAction.java | 1 - .../action/search/RestSearchScrollAction.java | 1 - .../action/suggest/RestSuggestAction.java | 1 - .../RestMultiTermVectorsAction.java | 1 - .../rest/action/update/RestUpdateAction.java | 1 - .../elasticsearch/river/RiversService.java | 9 +- .../action/ListenerActionTests.java | 75 ++++++++++++ .../TransportActionFilterChainTests.java | 4 +- .../client/AbstractClientHeadersTests.java | 6 +- .../client/node/NodeClientHeadersTests.java | 16 +-- .../transport/TransportClientRetryTests.java | 2 +- 85 files changed, 300 insertions(+), 332 deletions(-) create mode 100644 src/main/java/org/elasticsearch/action/support/ThreadedActionListener.java create mode 100644 src/test/java/org/elasticsearch/action/ListenerActionTests.java diff --git a/src/main/java/org/elasticsearch/action/ActionRequest.java b/src/main/java/org/elasticsearch/action/ActionRequest.java index 98eb6f946bf..3cae6449117 100644 --- a/src/main/java/org/elasticsearch/action/ActionRequest.java +++ b/src/main/java/org/elasticsearch/action/ActionRequest.java @@ -30,8 +30,6 @@ import java.io.IOException; */ public abstract class ActionRequest extends TransportRequest { - private boolean listenerThreaded = false; - protected ActionRequest() { super(); } @@ -43,25 +41,6 @@ public abstract class ActionRequest extends TransportRe //this.listenerThreaded = request.listenerThreaded(); } - /** - * Should the response listener be executed on a thread or not. - *

- *

When not executing on a thread, it will either be executed on the calling thread, or - * on an expensive, IO based, thread. - */ - public final boolean listenerThreaded() { - return this.listenerThreaded; - } - - /** - * Sets if the response listener be executed on a thread or not. - */ - @SuppressWarnings("unchecked") - public final T listenerThreaded(boolean listenerThreaded) { - this.listenerThreaded = listenerThreaded; - return (T) this; - } - public abstract ActionRequestValidationException validate(); @Override diff --git a/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java b/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java index 4335a40e030..78b0886162e 100644 --- a/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java @@ -48,12 +48,6 @@ public abstract class ActionRequestBuilder execute() { - PlainListenableActionFuture future = new PlainListenableActionFuture<>(request.listenerThreaded(), threadPool); + PlainListenableActionFuture future = new PlainListenableActionFuture<>(threadPool); execute(future); return future; } diff --git a/src/main/java/org/elasticsearch/action/TransportActionNodeProxy.java b/src/main/java/org/elasticsearch/action/TransportActionNodeProxy.java index b2410f95827..dccf9b0fd57 100644 --- a/src/main/java/org/elasticsearch/action/TransportActionNodeProxy.java +++ b/src/main/java/org/elasticsearch/action/TransportActionNodeProxy.java @@ -24,20 +24,15 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.BaseTransportResponseHandler; -import org.elasticsearch.transport.TransportException; -import org.elasticsearch.transport.TransportRequestOptions; -import org.elasticsearch.transport.TransportService; +import org.elasticsearch.transport.*; /** * A generic proxy that will execute the given action against a specific node. */ public class TransportActionNodeProxy extends AbstractComponent { - protected final TransportService transportService; - + private final TransportService transportService; private final GenericAction action; - private final TransportRequestOptions transportOptions; @Inject @@ -48,36 +43,17 @@ public class TransportActionNodeProxy listener) { + public void execute(final DiscoveryNode node, final Request request, final ActionListener listener) { ActionRequestValidationException validationException = request.validate(); if (validationException != null) { listener.onFailure(validationException); return; } - transportService.sendRequest(node, action.name(), request, transportOptions, new BaseTransportResponseHandler() { + transportService.sendRequest(node, action.name(), request, transportOptions, new ActionListenerResponseHandler(listener) { @Override public Response newInstance() { return action.newResponse(); } - - @Override - public String executor() { - if (request.listenerThreaded()) { - return ThreadPool.Names.LISTENER; - } - return ThreadPool.Names.SAME; - } - - @Override - public void handleResponse(Response response) { - listener.onResponse(response); - } - - @Override - public void handleException(TransportException exp) { - listener.onFailure(exp); - } }); } - } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java index ee4a6d6f076..3c8d1b7affa 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java @@ -64,8 +64,6 @@ public class TransportGetFieldMappingsAction extends HandledTransportAction() { @Override public void onResponse(GetFieldMappingsResponse result) { diff --git a/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java b/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java index ab119e169f0..679ef533307 100644 --- a/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java +++ b/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java @@ -119,7 +119,6 @@ public class TransportMoreLikeThisAction extends HandledTransportAction() { @@ -197,8 +196,7 @@ public class TransportMoreLikeThisAction extends HandledTransportAction extends AdapterActionFuture implements ListenableActionFuture { - final boolean listenerThreaded; + private final static ESLogger logger = Loggers.getLogger(AbstractListenableActionFuture.class); + final ThreadPool threadPool; volatile Object listeners; boolean executedListeners = false; - protected AbstractListenableActionFuture(boolean listenerThreaded, ThreadPool threadPool) { - this.listenerThreaded = listenerThreaded; + protected AbstractListenableActionFuture(ThreadPool threadPool) { this.threadPool = threadPool; } - public boolean listenerThreaded() { - return false; // we control execution of the listener - } - public ThreadPool threadPool() { return threadPool; } @@ -57,6 +53,7 @@ public abstract class AbstractListenableActionFuture extends AdapterAction } public void internalAddListener(ActionListener listener) { + listener = new ThreadedActionListener<>(logger, threadPool, ThreadPool.Names.LISTENER, listener); boolean executeImmediate = false; synchronized (this) { if (executedListeners) { @@ -101,27 +98,10 @@ public abstract class AbstractListenableActionFuture extends AdapterAction } private void executeListener(final ActionListener listener) { - if (listenerThreaded) { - try { - threadPool.executor(ThreadPool.Names.LISTENER).execute(new Runnable() { - @Override - public void run() { - try { - listener.onResponse(actionGet()); - } catch (ElasticsearchException e) { - listener.onFailure(e); - } - } - }); - } catch (EsRejectedExecutionException e) { - listener.onFailure(e); - } - } else { - try { - listener.onResponse(actionGet()); - } catch (Throwable e) { - listener.onFailure(e); - } + try { + listener.onResponse(actionGet()); + } catch (Throwable e) { + listener.onFailure(e); } } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/support/HandledTransportAction.java b/src/main/java/org/elasticsearch/action/support/HandledTransportAction.java index f939893a98e..e2e1072feb3 100644 --- a/src/main/java/org/elasticsearch/action/support/HandledTransportAction.java +++ b/src/main/java/org/elasticsearch/action/support/HandledTransportAction.java @@ -41,8 +41,6 @@ public abstract class HandledTransportAction() { @Override public void onResponse(Response response) { diff --git a/src/main/java/org/elasticsearch/action/support/PlainListenableActionFuture.java b/src/main/java/org/elasticsearch/action/support/PlainListenableActionFuture.java index 3d6cb28bced..1ec30606312 100644 --- a/src/main/java/org/elasticsearch/action/support/PlainListenableActionFuture.java +++ b/src/main/java/org/elasticsearch/action/support/PlainListenableActionFuture.java @@ -26,8 +26,8 @@ import org.elasticsearch.threadpool.ThreadPool; */ public class PlainListenableActionFuture extends AbstractListenableActionFuture { - public PlainListenableActionFuture(boolean listenerThreaded, ThreadPool threadPool) { - super(listenerThreaded, threadPool); + public PlainListenableActionFuture(ThreadPool threadPool) { + super(threadPool); } @Override diff --git a/src/main/java/org/elasticsearch/action/support/ThreadedActionListener.java b/src/main/java/org/elasticsearch/action/support/ThreadedActionListener.java new file mode 100644 index 00000000000..30011bcf571 --- /dev/null +++ b/src/main/java/org/elasticsearch/action/support/ThreadedActionListener.java @@ -0,0 +1,110 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action.support; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.client.Client; +import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.AbstractRunnable; +import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; +import org.elasticsearch.threadpool.ThreadPool; + +import java.util.concurrent.Future; + +/** + * An action listener that wraps another action listener and threading its execution. + */ +public final class ThreadedActionListener implements ActionListener { + + /** + * Wrapper that can be used to automatically wrap a listener in a threaded listener if needed. + */ + public static class Wrapper { + + private final ESLogger logger; + private final ThreadPool threadPool; + + private final boolean threadedListener; + + public Wrapper(ESLogger logger, Settings settings, ThreadPool threadPool) { + this.logger = logger; + this.threadPool = threadPool; + // Should the action listener be threaded or not by default. Action listeners are automatically threaded for client + // nodes and transport client in order to make sure client side code is not executed on IO threads. + this.threadedListener = DiscoveryNode.clientNode(settings) || TransportClient.CLIENT_TYPE.equals(settings.get(Client.CLIENT_TYPE_SETTING)); + } + + public ActionListener wrap(ActionListener listener) { + if (threadedListener == false) { + return listener; + } + // if its a future, the callback is very lightweight (flipping a bit) so no need to wrap it + if (listener instanceof Future) { + return listener; + } + return new ThreadedActionListener<>(logger, threadPool, ThreadPool.Names.LISTENER, listener); + } + } + + private final ESLogger logger; + private final ThreadPool threadPool; + private final String executor; + private final ActionListener listener; + + public ThreadedActionListener(ESLogger logger, ThreadPool threadPool, String executor, ActionListener listener) { + this.logger = logger; + this.threadPool = threadPool; + this.executor = executor; + this.listener = listener; + } + + @Override + public void onResponse(final Response response) { + threadPool.executor(executor).execute(new AbstractRunnable() { + @Override + protected void doRun() throws Exception { + listener.onResponse(response); + } + + @Override + public void onFailure(Throwable t) { + listener.onFailure(t); + } + }); + } + + @Override + public void onFailure(final Throwable e) { + threadPool.executor(executor).execute(new AbstractRunnable() { + @Override + protected void doRun() throws Exception { + listener.onFailure(e); + } + + @Override + public void onFailure(Throwable t) { + logger.warn("failed to execute failure callback on [{}], failure [{}]", t, listener, e); + } + }); + } +} diff --git a/src/main/java/org/elasticsearch/action/support/TransportAction.java b/src/main/java/org/elasticsearch/action/support/TransportAction.java index 7d3f3564693..c1a9f6098f6 100644 --- a/src/main/java/org/elasticsearch/action/support/TransportAction.java +++ b/src/main/java/org/elasticsearch/action/support/TransportAction.java @@ -19,12 +19,10 @@ package org.elasticsearch.action.support; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.*; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.threadpool.ThreadPool; import java.util.concurrent.atomic.AtomicInteger; @@ -49,21 +47,11 @@ public abstract class TransportAction execute(Request request) { PlainActionFuture future = newFuture(); - // since we don't have a listener, and we release a possible lock with the future - // there is no need to execute it under a listener thread - request.listenerThreaded(false); execute(request, future); return future; } public final void execute(Request request, ActionListener listener) { - if (forceThreadedListener()) { - request.listenerThreaded(true); - } - if (request.listenerThreaded()) { - listener = new ThreadedActionListener<>(threadPool, listener, logger); - } - ActionRequestValidationException validationException = request.validate(); if (validationException != null) { listener.onFailure(validationException); @@ -83,69 +71,8 @@ public abstract class TransportAction listener); - static final class ThreadedActionListener implements ActionListener { - - private final ThreadPool threadPool; - - private final ActionListener listener; - - private final ESLogger logger; - - ThreadedActionListener(ThreadPool threadPool, ActionListener listener, ESLogger logger) { - this.threadPool = threadPool; - this.listener = listener; - this.logger = logger; - } - - @Override - public void onResponse(final Response response) { - try { - threadPool.executor(ThreadPool.Names.LISTENER).execute(new Runnable() { - @Override - public void run() { - try { - listener.onResponse(response); - } catch (Throwable e) { - listener.onFailure(e); - } - } - }); - } catch (EsRejectedExecutionException ex) { - logger.debug("Can not run threaded action, execution rejected [{}] running on current thread", listener); - /* we don't care if that takes long since we are shutting down. But if we not respond somebody could wait - * for the response on the listener side which could be a remote machine so make sure we push it out there.*/ - try { - listener.onResponse(response); - } catch (Throwable e) { - listener.onFailure(e); - } - } - } - - @Override - public void onFailure(final Throwable e) { - try { - threadPool.executor(ThreadPool.Names.LISTENER).execute(new Runnable() { - @Override - public void run() { - listener.onFailure(e); - } - }); - } catch (EsRejectedExecutionException ex) { - logger.debug("Can not run threaded action, execution rejected for listener [{}] running on current thread", listener); - /* we don't care if that takes long since we are shutting down (or queue capacity). But if we not respond somebody could wait - * for the response on the listener side which could be a remote machine so make sure we push it out there.*/ - listener.onFailure(e); - } - } - } - private static class RequestFilterChain implements ActionFilterChain { private final TransportAction action; diff --git a/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java b/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java index 15e90c0784d..4ff18e68db0 100644 --- a/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java +++ b/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java @@ -25,6 +25,7 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionRunnable; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.HandledTransportAction; +import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.action.support.TransportAction; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterService; @@ -75,14 +76,11 @@ public abstract class TransportMasterNodeOperationAction listener) { + protected void doExecute(final Request request, ActionListener listener) { + // TODO do we really need to wrap it in a listener? the handlers should be cheap + if ((listener instanceof ThreadedActionListener) == false) { + listener = new ThreadedActionListener<>(logger, threadPool, ThreadPool.Names.LISTENER, listener); + } innerExecute(request, listener, new ClusterStateObserver(clusterService, request.masterNodeTimeout(), logger), false); } diff --git a/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java b/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java index 0e488a602ff..efdc5ab0d4c 100644 --- a/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java +++ b/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java @@ -186,8 +186,6 @@ public abstract class TransportShardReplicationOperationAction { @Override public void messageReceived(final Request request, final TransportChannel channel) throws Exception { - // no need to have a threaded listener since we just send back a response - request.listenerThreaded(false); // if we have a local operation, execute it on a thread since we don't spawn request.operationThreaded(true); execute(request, new ActionListener() { diff --git a/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java b/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java index 1c91a7753dd..db6260e6f85 100644 --- a/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java +++ b/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java @@ -232,8 +232,6 @@ public abstract class TransportShardSingleOperationAction() { diff --git a/src/main/java/org/elasticsearch/client/node/NodeClient.java b/src/main/java/org/elasticsearch/client/node/NodeClient.java index ae85454ba50..0c7495e3412 100644 --- a/src/main/java/org/elasticsearch/client/node/NodeClient.java +++ b/src/main/java/org/elasticsearch/client/node/NodeClient.java @@ -21,6 +21,8 @@ package org.elasticsearch.client.node; import com.google.common.collect.ImmutableMap; import org.elasticsearch.action.*; +import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.action.support.TransportAction; import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; @@ -28,6 +30,8 @@ import org.elasticsearch.client.support.AbstractClient; import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; @@ -38,6 +42,7 @@ import java.util.Map; */ public class NodeClient extends AbstractClient { + private final ESLogger logger; private final Settings settings; private final ThreadPool threadPool; @@ -46,9 +51,11 @@ public class NodeClient extends AbstractClient { private final ImmutableMap actions; private final Headers headers; + private final ThreadedActionListener.Wrapper threadedWrapper; @Inject public NodeClient(Settings settings, ThreadPool threadPool, NodeAdminClient admin, Map actions, Headers headers) { + this.logger = Loggers.getLogger(getClass(), settings); this.settings = settings; this.threadPool = threadPool; this.admin = admin; @@ -60,6 +67,7 @@ public class NodeClient extends AbstractClient { } } this.actions = actionsBuilder.immutableMap(); + this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); } @Override @@ -84,16 +92,17 @@ public class NodeClient extends AbstractClient { @SuppressWarnings("unchecked") @Override - public > ActionFuture execute(Action action, Request request) { - headers.applyTo(request); - TransportAction transportAction = actions.get((ClientAction)action); - return transportAction.execute(request); + public > ActionFuture execute(final Action action, final Request request) { + PlainActionFuture actionFuture = PlainActionFuture.newFuture(); + execute(action, request, actionFuture); + return actionFuture; } @SuppressWarnings("unchecked") @Override public > void execute(Action action, Request request, ActionListener listener) { headers.applyTo(request); + listener = threadedWrapper.wrap(listener); TransportAction transportAction = actions.get((ClientAction)action); transportAction.execute(request, listener); } diff --git a/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java b/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java index 41af331a93f..3e5144b5449 100644 --- a/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java +++ b/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java @@ -22,12 +22,17 @@ package org.elasticsearch.client.node; import com.google.common.collect.ImmutableMap; import org.elasticsearch.action.*; import org.elasticsearch.action.admin.cluster.ClusterAction; +import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.action.support.TransportAction; import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.support.AbstractClusterAdminClient; import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import java.util.Map; @@ -37,14 +42,15 @@ import java.util.Map; */ public class NodeClusterAdminClient extends AbstractClusterAdminClient implements ClusterAdminClient { + private final ESLogger logger; private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; + private final ThreadedActionListener.Wrapper threadedWrapper; @Inject - public NodeClusterAdminClient(ThreadPool threadPool, Map actions, Headers headers) { + public NodeClusterAdminClient(Settings settings, ThreadPool threadPool, Map actions, Headers headers) { + this.logger = Loggers.getLogger(getClass(), settings); this.threadPool = threadPool; this.headers = headers; MapBuilder actionsBuilder = new MapBuilder<>(); @@ -54,6 +60,7 @@ public class NodeClusterAdminClient extends AbstractClusterAdminClient implement } } this.actions = actionsBuilder.immutableMap(); + this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); } @Override @@ -63,16 +70,17 @@ public class NodeClusterAdminClient extends AbstractClusterAdminClient implement @SuppressWarnings("unchecked") @Override - public > ActionFuture execute(Action action, Request request) { - headers.applyTo(request); - TransportAction transportAction = actions.get((ClusterAction)action); - return transportAction.execute(request); + public > ActionFuture execute(final Action action, final Request request) { + PlainActionFuture actionFuture = PlainActionFuture.newFuture(); + execute(action, request, actionFuture); + return actionFuture; } @SuppressWarnings("unchecked") @Override public > void execute(Action action, Request request, ActionListener listener) { headers.applyTo(request); + listener = threadedWrapper.wrap(listener); TransportAction transportAction = actions.get((ClusterAction)action); transportAction.execute(request, listener); } diff --git a/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java index c74d68d494f..6db38103f59 100644 --- a/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java +++ b/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java @@ -22,12 +22,17 @@ package org.elasticsearch.client.node; import com.google.common.collect.ImmutableMap; import org.elasticsearch.action.*; import org.elasticsearch.action.admin.indices.IndicesAction; +import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.action.support.TransportAction; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.support.AbstractIndicesAdminClient; import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import java.util.Map; @@ -37,14 +42,15 @@ import java.util.Map; */ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implements IndicesAdminClient { + private final ESLogger logger; private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; + private final ThreadedActionListener.Wrapper threadedWrapper; @Inject - public NodeIndicesAdminClient(ThreadPool threadPool, Map actions, Headers headers) { + public NodeIndicesAdminClient(Settings settings, ThreadPool threadPool, Map actions, Headers headers) { + this.logger = Loggers.getLogger(getClass(), settings); this.threadPool = threadPool; this.headers = headers; MapBuilder actionsBuilder = new MapBuilder<>(); @@ -54,6 +60,7 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement } } this.actions = actionsBuilder.immutableMap(); + this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); } @Override @@ -63,16 +70,17 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement @SuppressWarnings("unchecked") @Override - public > ActionFuture execute(Action action, Request request) { - headers.applyTo(request); - TransportAction transportAction = actions.get((IndicesAction)action); - return transportAction.execute(request); + public > ActionFuture execute(final Action action, final Request request) { + PlainActionFuture actionFuture = PlainActionFuture.newFuture(); + execute(action, request, actionFuture); + return actionFuture; } @SuppressWarnings("unchecked") @Override public > void execute(Action action, Request request, ActionListener listener) { headers.applyTo(request); + listener = threadedWrapper.wrap(listener); TransportAction transportAction = actions.get((IndicesAction)action); transportAction.execute(request, listener); } diff --git a/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 6dd30b02af3..2d62100ef0d 100644 --- a/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -93,7 +93,7 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde */ public class TransportClient extends AbstractClient { - private static final String CLIENT_TYPE = "transport"; + public static final String CLIENT_TYPE = "transport"; final Injector injector; diff --git a/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java b/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java index e2cf962f65a..44d6e0d7851 100644 --- a/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java +++ b/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java @@ -23,7 +23,6 @@ import com.carrotsearch.hppc.cursors.ObjectCursor; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; @@ -38,11 +37,9 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.common.util.concurrent.FutureUtils; import org.elasticsearch.threadpool.ThreadPool; @@ -199,7 +196,7 @@ public class TransportClientNodesService extends AbstractComponent { ImmutableList nodes = this.nodes; ensureNodesAreAvailable(nodes); int index = getNodeNumber(); - RetryListener retryListener = new RetryListener<>(callback, listener, nodes, index, threadPool, logger); + RetryListener retryListener = new RetryListener<>(callback, listener, nodes, index); DiscoveryNode node = nodes.get((index) % nodes.size()); try { callback.doWithNode(node, retryListener); @@ -213,20 +210,15 @@ public class TransportClientNodesService extends AbstractComponent { private final NodeListenerCallback callback; private final ActionListener listener; private final ImmutableList nodes; - private final ESLogger logger; private final int index; - private ThreadPool threadPool; private volatile int i; - public RetryListener(NodeListenerCallback callback, ActionListener listener, ImmutableList nodes, - int index, ThreadPool threadPool, ESLogger logger) { + public RetryListener(NodeListenerCallback callback, ActionListener listener, ImmutableList nodes, int index) { this.callback = callback; this.listener = listener; this.nodes = nodes; this.index = index; - this.threadPool = threadPool; - this.logger = logger; } @Override @@ -239,38 +231,21 @@ public class TransportClientNodesService extends AbstractComponent { if (ExceptionsHelper.unwrapCause(e) instanceof ConnectTransportException) { int i = ++this.i; if (i >= nodes.size()) { - runFailureInListenerThreadPool(new NoNodeAvailableException("None of the configured nodes were available: " + nodes, e)); + listener.onFailure(new NoNodeAvailableException("None of the configured nodes were available: " + nodes, e)); } else { try { callback.doWithNode(nodes.get((index + i) % nodes.size()), this); } catch(final Throwable t) { // this exception can't come from the TransportService as it doesn't throw exceptions at all - runFailureInListenerThreadPool(t); + listener.onFailure(t); } } } else { - runFailureInListenerThreadPool(e); + listener.onFailure(e); } } - // need to ensure to not block the netty I/O thread, in case of retry due to the node sampling - private void runFailureInListenerThreadPool(final Throwable t) { - threadPool.executor(ThreadPool.Names.LISTENER).execute(new AbstractRunnable() { - @Override - protected void doRun() throws Exception { - listener.onFailure(t); - } - @Override - public void onFailure(Throwable t) { - if (logger.isDebugEnabled()) { - logger.debug("Could not execute failure listener: [{}]", t, t.getMessage()); - } else { - logger.error("Could not execute failure listener: [{}]", t.getMessage()); - } - } - }); - } } public void close() { @@ -505,7 +480,7 @@ public class TransportClientNodesService extends AbstractComponent { } } - public static interface NodeListenerCallback { + public interface NodeListenerCallback { void doWithNode(DiscoveryNode node, ActionListener listener); } diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java index 11a9959019f..0aff540cb9e 100644 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java +++ b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java @@ -22,6 +22,7 @@ package org.elasticsearch.client.transport.support; import com.google.common.collect.ImmutableMap; import org.elasticsearch.action.*; import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; import org.elasticsearch.client.support.AbstractClient; @@ -30,6 +31,8 @@ import org.elasticsearch.client.transport.TransportClientNodesService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -41,21 +44,20 @@ import java.util.Map; */ public class InternalTransportClient extends AbstractClient { + private final ESLogger logger; private final Settings settings; private final ThreadPool threadPool; - private final TransportClientNodesService nodesService; - private final InternalTransportAdminClient adminClient; - private final ImmutableMap actions; - private final Headers headers; + private final ThreadedActionListener.Wrapper threadedWrapper; @Inject public InternalTransportClient(Settings settings, ThreadPool threadPool, TransportService transportService, TransportClientNodesService nodesService, InternalTransportAdminClient adminClient, Map actions, Headers headers) { + this.logger = Loggers.getLogger(getClass(), settings); this.settings = settings; this.threadPool = threadPool; this.nodesService = nodesService; @@ -68,6 +70,7 @@ public class InternalTransportClient extends AbstractClient { } } this.actions = actionsBuilder.immutableMap(); + this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); } @Override @@ -102,6 +105,7 @@ public class InternalTransportClient extends AbstractClient { @Override public > void execute(final Action action, final Request request, ActionListener listener) { headers.applyTo(request); + listener = threadedWrapper.wrap(listener); final TransportActionNodeProxy proxy = actions.get(action); nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { @Override diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java index 74be67d0009..5ede20849a3 100644 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java +++ b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap; import org.elasticsearch.action.*; import org.elasticsearch.action.admin.cluster.ClusterAction; import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.support.AbstractClusterAdminClient; import org.elasticsearch.client.support.Headers; @@ -30,6 +31,8 @@ import org.elasticsearch.client.transport.TransportClientNodesService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -42,17 +45,17 @@ import java.util.Map; @SuppressWarnings("unchecked") public class InternalTransportClusterAdminClient extends AbstractClusterAdminClient implements ClusterAdminClient { + private final ESLogger logger; private final TransportClientNodesService nodesService; - private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; + private final ThreadedActionListener.Wrapper threadedWrapper; @Inject public InternalTransportClusterAdminClient(Settings settings, TransportClientNodesService nodesService, ThreadPool threadPool, TransportService transportService, Map actions, Headers headers) { + this.logger = Loggers.getLogger(getClass(), settings); this.nodesService = nodesService; this.threadPool = threadPool; this.headers = headers; @@ -63,6 +66,7 @@ public class InternalTransportClusterAdminClient extends AbstractClusterAdminCli } } this.actions = actionsBuilder.immutableMap(); + this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); } @Override @@ -80,8 +84,9 @@ public class InternalTransportClusterAdminClient extends AbstractClusterAdminCli @SuppressWarnings("unchecked") @Override - public > void execute(final Action action, final Request request, final ActionListener listener) { + public > void execute(final Action action, final Request request, ActionListener listener) { headers.applyTo(request); + listener = threadedWrapper.wrap(listener); final TransportActionNodeProxy proxy = actions.get(action); nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { @Override diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java index 8cb63a17c7d..49295b1c968 100644 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java +++ b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap; import org.elasticsearch.action.*; import org.elasticsearch.action.admin.indices.IndicesAction; import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.support.AbstractIndicesAdminClient; import org.elasticsearch.client.support.Headers; @@ -30,6 +31,8 @@ import org.elasticsearch.client.transport.TransportClientNodesService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -42,17 +45,17 @@ import java.util.Map; @SuppressWarnings("unchecked") public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminClient implements IndicesAdminClient { + private final ESLogger logger; private final TransportClientNodesService nodesService; - private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; + private final ThreadedActionListener.Wrapper threadedWrapper; @Inject public InternalTransportIndicesAdminClient(Settings settings, TransportClientNodesService nodesService, TransportService transportService, ThreadPool threadPool, Map actions, Headers headers) { + this.logger = Loggers.getLogger(getClass(), settings); this.nodesService = nodesService; this.threadPool = threadPool; this.headers = headers; @@ -63,6 +66,7 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli } } this.actions = actionsBuilder.immutableMap(); + this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); } @Override @@ -82,6 +86,7 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli @Override public > void execute(final Action action, final Request request, ActionListener listener) { headers.applyTo(request); + listener = threadedWrapper.wrap(listener); final TransportActionNodeProxy proxy = actions.get(action); nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { @Override diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java index b080e51055d..dfcb4438d57 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java @@ -50,7 +50,6 @@ public class RestClusterHealthAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index"))); clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local())); - clusterHealthRequest.listenerThreaded(false); clusterHealthRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterHealthRequest.masterNodeTimeout())); clusterHealthRequest.timeout(request.paramAsTime("timeout", clusterHealthRequest.timeout())); String waitForStatus = request.param("wait_for_status"); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java index dbda82ff387..a78c90aca63 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java @@ -81,8 +81,6 @@ public class RestNodesInfoAction extends BaseRestHandler { } final NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodeIds); - nodesInfoRequest.listenerThreaded(false); - // shortcut, dont do checks if only all is specified if (metrics.size() == 1 && metrics.contains("_all")) { nodesInfoRequest.all(); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java index 4704d8ee832..d5bb383c33a 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java @@ -60,7 +60,6 @@ public class RestNodesStatsAction extends BaseRestHandler { Set metrics = Strings.splitStringByCommaToSet(request.param("metric", "_all")); NodesStatsRequest nodesStatsRequest = new NodesStatsRequest(nodesIds); - nodesStatsRequest.listenerThreaded(false); if (metrics.size() == 1 && metrics.contains("_all")) { nodesStatsRequest.all(); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/delete/RestDeleteRepositoryAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/delete/RestDeleteRepositoryAction.java index 46c06ecbe75..758ee34505a 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/delete/RestDeleteRepositoryAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/delete/RestDeleteRepositoryAction.java @@ -45,7 +45,6 @@ public class RestDeleteRepositoryAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { DeleteRepositoryRequest deleteRepositoryRequest = deleteRepositoryRequest(request.param("repository")); deleteRepositoryRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteRepositoryRequest.masterNodeTimeout())); - deleteRepositoryRequest.listenerThreaded(false); deleteRepositoryRequest.timeout(request.paramAsTime("timeout", deleteRepositoryRequest.timeout())); deleteRepositoryRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteRepositoryRequest.masterNodeTimeout())); client.admin().cluster().deleteRepository(deleteRepositoryRequest, new AcknowledgedRestListener(channel)); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/put/RestPutRepositoryAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/put/RestPutRepositoryAction.java index 60e68b25f42..b974a9be0fb 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/put/RestPutRepositoryAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/put/RestPutRepositoryAction.java @@ -47,7 +47,6 @@ public class RestPutRepositoryAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { PutRepositoryRequest putRepositoryRequest = putRepositoryRequest(request.param("repository")); - putRepositoryRequest.listenerThreaded(false); putRepositoryRequest.source(request.content().toUtf8()); putRepositoryRequest.verify(request.paramAsBoolean("verify", true)); putRepositoryRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putRepositoryRequest.masterNodeTimeout())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/verify/RestVerifyRepositoryAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/verify/RestVerifyRepositoryAction.java index cdfe3b7992b..bbc39cbd2f3 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/verify/RestVerifyRepositoryAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/repositories/verify/RestVerifyRepositoryAction.java @@ -50,7 +50,6 @@ public class RestVerifyRepositoryAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { VerifyRepositoryRequest verifyRepositoryRequest = verifyRepositoryRequest(request.param("repository")); - verifyRepositoryRequest.listenerThreaded(false); verifyRepositoryRequest.masterNodeTimeout(request.paramAsTime("master_timeout", verifyRepositoryRequest.masterNodeTimeout())); verifyRepositoryRequest.timeout(request.paramAsTime("timeout", verifyRepositoryRequest.timeout())); client.admin().cluster().verifyRepository(verifyRepositoryRequest, new RestToXContentListener(channel)); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/reroute/RestClusterRerouteAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/reroute/RestClusterRerouteAction.java index 489acf93db1..7d5d2c9d5ff 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/reroute/RestClusterRerouteAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/reroute/RestClusterRerouteAction.java @@ -54,7 +54,6 @@ public class RestClusterRerouteAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { final ClusterRerouteRequest clusterRerouteRequest = Requests.clusterRerouteRequest(); - clusterRerouteRequest.listenerThreaded(false); clusterRerouteRequest.dryRun(request.paramAsBoolean("dry_run", clusterRerouteRequest.dryRun())); clusterRerouteRequest.explain(request.paramAsBoolean("explain", clusterRerouteRequest.explain())); clusterRerouteRequest.timeout(request.paramAsTime("timeout", clusterRerouteRequest.timeout())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterGetSettingsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterGetSettingsAction.java index 5ef9c403ac2..a1cfdb48ddb 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterGetSettingsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterGetSettingsAction.java @@ -42,7 +42,6 @@ public class RestClusterGetSettingsAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest() - .listenerThreaded(false) .routingTable(false) .nodes(false); clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterUpdateSettingsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterUpdateSettingsAction.java index 87363d386ef..8536c037e89 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterUpdateSettingsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterUpdateSettingsAction.java @@ -46,7 +46,6 @@ public class RestClusterUpdateSettingsAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { final ClusterUpdateSettingsRequest clusterUpdateSettingsRequest = Requests.clusterUpdateSettingsRequest(); - clusterUpdateSettingsRequest.listenerThreaded(false); clusterUpdateSettingsRequest.timeout(request.paramAsTime("timeout", clusterUpdateSettingsRequest.timeout())); clusterUpdateSettingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterUpdateSettingsRequest.masterNodeTimeout())); Map source = XContentFactory.xContent(request.content()).createParser(request.content()).mapAndClose(); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/shards/RestClusterSearchShardsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/shards/RestClusterSearchShardsAction.java index 22151e7b0ad..a797a474eb6 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/shards/RestClusterSearchShardsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/shards/RestClusterSearchShardsAction.java @@ -53,7 +53,6 @@ public class RestClusterSearchShardsAction extends BaseRestHandler { String[] indices = Strings.splitStringByCommaToArray(request.param("index")); final ClusterSearchShardsRequest clusterSearchShardsRequest = Requests.clusterSearchShardsRequest(indices); clusterSearchShardsRequest.local(request.paramAsBoolean("local", clusterSearchShardsRequest.local())); - clusterSearchShardsRequest.listenerThreaded(false); clusterSearchShardsRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); clusterSearchShardsRequest.routing(request.param("routing")); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/snapshots/create/RestCreateSnapshotAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/snapshots/create/RestCreateSnapshotAction.java index ff71f7e60f9..c62be2b3db6 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/snapshots/create/RestCreateSnapshotAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/snapshots/create/RestCreateSnapshotAction.java @@ -46,7 +46,6 @@ public class RestCreateSnapshotAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { CreateSnapshotRequest createSnapshotRequest = createSnapshotRequest(request.param("repository"), request.param("snapshot")); - createSnapshotRequest.listenerThreaded(false); createSnapshotRequest.source(request.content().toUtf8()); createSnapshotRequest.masterNodeTimeout(request.paramAsTime("master_timeout", createSnapshotRequest.masterNodeTimeout())); createSnapshotRequest.waitForCompletion(request.paramAsBoolean("wait_for_completion", false)); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java index bac21dd13e4..4e4dc0826ae 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java @@ -57,7 +57,6 @@ public class RestClusterStateAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { final ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest(); - clusterStateRequest.listenerThreaded(false); clusterStateRequest.indicesOptions(IndicesOptions.fromRequest(request, clusterStateRequest.indicesOptions())); clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local())); clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/stats/RestClusterStatsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/stats/RestClusterStatsAction.java index 5dd1c638b83..572a48de633 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/stats/RestClusterStatsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/stats/RestClusterStatsAction.java @@ -43,7 +43,6 @@ public class RestClusterStatsAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { ClusterStatsRequest clusterStatsRequest = new ClusterStatsRequest().nodesIds(request.paramAsStringArray("nodeId", null)); - clusterStatsRequest.listenerThreaded(false); client.admin().cluster().clusterStats(clusterStatsRequest, new RestToXContentListener(channel)); } } diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java index 2019b71426a..4841500cb66 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java @@ -49,7 +49,6 @@ public class RestIndicesAliasesAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest(); - indicesAliasesRequest.listenerThreaded(false); indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout())); try (XContentParser parser = XContentFactory.xContent(request.content()).createParser(request.content())) { // { diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetIndicesAliasesAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetIndicesAliasesAction.java index 060ec3f3012..34cdcb27962 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetIndicesAliasesAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetIndicesAliasesAction.java @@ -61,7 +61,6 @@ public class RestGetIndicesAliasesAction extends BaseRestHandler { .nodes(false) .indices(indices); clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local())); - clusterStateRequest.listenerThreaded(false); client.admin().cluster().state(clusterStateRequest, new RestBuilderListener(channel) { @Override diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeAction.java index 4a5e47b9664..5ce5eaef4ac 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeAction.java @@ -59,7 +59,6 @@ public class RestAnalyzeAction extends BaseRestHandler { AnalyzeRequest analyzeRequest = new AnalyzeRequest(request.param("index")); analyzeRequest.text(text); - analyzeRequest.listenerThreaded(false); analyzeRequest.preferLocal(request.paramAsBoolean("prefer_local", analyzeRequest.preferLocalShard())); analyzeRequest.analyzer(request.param("analyzer")); analyzeRequest.field(request.param("field")); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java index 54d9948537e..8eb83cba0d1 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java @@ -56,7 +56,6 @@ public class RestClearIndicesCacheAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { ClearIndicesCacheRequest clearIndicesCacheRequest = new ClearIndicesCacheRequest(Strings.splitStringByCommaToArray(request.param("index"))); - clearIndicesCacheRequest.listenerThreaded(false); clearIndicesCacheRequest.indicesOptions(IndicesOptions.fromRequest(request, clearIndicesCacheRequest.indicesOptions())); fromRequest(request, clearIndicesCacheRequest); client.admin().indices().clearCache(clearIndicesCacheRequest, new RestBuilderListener(channel) { diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/close/RestCloseIndexAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/close/RestCloseIndexAction.java index 03b5a8c542f..940b6c1cefa 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/close/RestCloseIndexAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/close/RestCloseIndexAction.java @@ -44,7 +44,6 @@ public class RestCloseIndexAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { CloseIndexRequest closeIndexRequest = new CloseIndexRequest(Strings.splitStringByCommaToArray(request.param("index"))); - closeIndexRequest.listenerThreaded(false); closeIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", closeIndexRequest.masterNodeTimeout())); closeIndexRequest.timeout(request.paramAsTime("timeout", closeIndexRequest.timeout())); closeIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, closeIndexRequest.indicesOptions())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java index 2fca3ff6a27..8f3447ff9f8 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java @@ -43,7 +43,6 @@ public class RestCreateIndexAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index")); - createIndexRequest.listenerThreaded(false); if (request.hasContent()) { createIndexRequest.source(request.content()); } diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java index 126c471578e..43201592e31 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java @@ -44,7 +44,6 @@ public class RestDeleteIndexAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(Strings.splitStringByCommaToArray(request.param("index"))); - deleteIndexRequest.listenerThreaded(false); deleteIndexRequest.timeout(request.paramAsTime("timeout", deleteIndexRequest.timeout())); deleteIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteIndexRequest.masterNodeTimeout())); deleteIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, deleteIndexRequest.indicesOptions())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/exists/indices/RestIndicesExistsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/exists/indices/RestIndicesExistsAction.java index a0cf436a468..8ea4e633bc1 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/exists/indices/RestIndicesExistsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/exists/indices/RestIndicesExistsAction.java @@ -49,7 +49,6 @@ public class RestIndicesExistsAction extends BaseRestHandler { IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(Strings.splitStringByCommaToArray(request.param("index"))); indicesExistsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesExistsRequest.indicesOptions())); indicesExistsRequest.local(request.paramAsBoolean("local", indicesExistsRequest.local())); - indicesExistsRequest.listenerThreaded(false); client.admin().indices().exists(indicesExistsRequest, new RestResponseListener(channel) { @Override public RestResponse buildResponse(IndicesExistsResponse response) { diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/exists/types/RestTypesExistsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/exists/types/RestTypesExistsAction.java index c5571313a2f..a03a7f0fe1d 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/exists/types/RestTypesExistsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/exists/types/RestTypesExistsAction.java @@ -48,7 +48,6 @@ public class RestTypesExistsAction extends BaseRestHandler { TypesExistsRequest typesExistsRequest = new TypesExistsRequest( Strings.splitStringByCommaToArray(request.param("index")), Strings.splitStringByCommaToArray(request.param("type")) ); - typesExistsRequest.listenerThreaded(false); typesExistsRequest.local(request.paramAsBoolean("local", typesExistsRequest.local())); typesExistsRequest.indicesOptions(IndicesOptions.fromRequest(request, typesExistsRequest.indicesOptions())); client.admin().indices().typesExists(typesExistsRequest, new RestResponseListener(channel) { diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java index 5bcb775122a..6c95342cf89 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java @@ -53,7 +53,6 @@ public class RestFlushAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { FlushRequest flushRequest = new FlushRequest(Strings.splitStringByCommaToArray(request.param("index"))); - flushRequest.listenerThreaded(false); flushRequest.indicesOptions(IndicesOptions.fromRequest(request, flushRequest.indicesOptions())); flushRequest.force(request.paramAsBoolean("force", flushRequest.force())); flushRequest.waitIfOngoing(request.paramAsBoolean("wait_if_ongoing", flushRequest.waitIfOngoing())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java index d067ed96bd1..6df8edc0c82 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java @@ -67,7 +67,6 @@ public class RestPutMappingAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index"))); - putMappingRequest.listenerThreaded(false); putMappingRequest.type(request.param("type")); putMappingRequest.source(request.content().toUtf8()); putMappingRequest.timeout(request.paramAsTime("timeout", putMappingRequest.timeout())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/open/RestOpenIndexAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/open/RestOpenIndexAction.java index 7ff9a8fb620..e81bca30f6a 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/open/RestOpenIndexAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/open/RestOpenIndexAction.java @@ -44,7 +44,6 @@ public class RestOpenIndexAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { OpenIndexRequest openIndexRequest = new OpenIndexRequest(Strings.splitStringByCommaToArray(request.param("index"))); - openIndexRequest.listenerThreaded(false); openIndexRequest.timeout(request.paramAsTime("timeout", openIndexRequest.timeout())); openIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", openIndexRequest.masterNodeTimeout())); openIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, openIndexRequest.indicesOptions())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java index c49745db629..74379f632c5 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java @@ -53,7 +53,6 @@ public class RestOptimizeAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { OptimizeRequest optimizeRequest = new OptimizeRequest(Strings.splitStringByCommaToArray(request.param("index"))); - optimizeRequest.listenerThreaded(false); optimizeRequest.indicesOptions(IndicesOptions.fromRequest(request, optimizeRequest.indicesOptions())); optimizeRequest.maxNumSegments(request.paramAsInt("max_num_segments", optimizeRequest.maxNumSegments())); optimizeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", optimizeRequest.onlyExpungeDeletes())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/recovery/RestRecoveryAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/recovery/RestRecoveryAction.java index 2abd624a3c4..9d470c4b051 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/recovery/RestRecoveryAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/recovery/RestRecoveryAction.java @@ -51,7 +51,6 @@ public class RestRecoveryAction extends BaseRestHandler { final RecoveryRequest recoveryRequest = new RecoveryRequest(Strings.splitStringByCommaToArray(request.param("index"))); recoveryRequest.detailed(request.paramAsBoolean("detailed", false)); recoveryRequest.activeOnly(request.paramAsBoolean("active_only", false)); - recoveryRequest.listenerThreaded(false); recoveryRequest.indicesOptions(IndicesOptions.fromRequest(request, recoveryRequest.indicesOptions())); client.admin().indices().recoveries(recoveryRequest, new RestBuilderListener(channel) { diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java index aaf8933ea40..949b82270ff 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java @@ -53,7 +53,6 @@ public class RestRefreshAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { RefreshRequest refreshRequest = new RefreshRequest(Strings.splitStringByCommaToArray(request.param("index"))); - refreshRequest.listenerThreaded(false); refreshRequest.indicesOptions(IndicesOptions.fromRequest(request, refreshRequest.indicesOptions())); client.admin().indices().refresh(refreshRequest, new RestBuilderListener(channel) { @Override diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/segments/RestIndicesSegmentsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/segments/RestIndicesSegmentsAction.java index 3806d8cbe1c..b5b2ba6e7c4 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/segments/RestIndicesSegmentsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/segments/RestIndicesSegmentsAction.java @@ -49,7 +49,6 @@ public class RestIndicesSegmentsAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest(Strings.splitStringByCommaToArray(request.param("index"))); indicesSegmentsRequest.verbose(request.paramAsBoolean("verbose", false)); - indicesSegmentsRequest.listenerThreaded(false); indicesSegmentsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesSegmentsRequest.indicesOptions())); client.admin().indices().segments(indicesSegmentsRequest, new RestBuilderListener(channel) { @Override diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestUpdateSettingsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestUpdateSettingsAction.java index d19b5c9a1f4..718d16c4705 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestUpdateSettingsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestUpdateSettingsAction.java @@ -55,7 +55,6 @@ public class RestUpdateSettingsAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { UpdateSettingsRequest updateSettingsRequest = updateSettingsRequest(Strings.splitStringByCommaToArray(request.param("index"))); - updateSettingsRequest.listenerThreaded(false); updateSettingsRequest.timeout(request.paramAsTime("timeout", updateSettingsRequest.timeout())); updateSettingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", updateSettingsRequest.masterNodeTimeout())); updateSettingsRequest.indicesOptions(IndicesOptions.fromRequest(request, updateSettingsRequest.indicesOptions())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java index 52ac511366d..43fcbd57171 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java @@ -53,7 +53,6 @@ public class RestIndicesStatsAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(); - indicesStatsRequest.listenerThreaded(false); indicesStatsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesStatsRequest.indicesOptions())); indicesStatsRequest.indices(Strings.splitStringByCommaToArray(request.param("index"))); indicesStatsRequest.types(Strings.splitStringByCommaToArray(request.param("types"))); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/template/delete/RestDeleteIndexTemplateAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/template/delete/RestDeleteIndexTemplateAction.java index 8ebb8675d76..2b6ebbc6023 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/template/delete/RestDeleteIndexTemplateAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/template/delete/RestDeleteIndexTemplateAction.java @@ -40,7 +40,6 @@ public class RestDeleteIndexTemplateAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { DeleteIndexTemplateRequest deleteIndexTemplateRequest = new DeleteIndexTemplateRequest(request.param("name")); - deleteIndexTemplateRequest.listenerThreaded(false); deleteIndexTemplateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteIndexTemplateRequest.masterNodeTimeout())); client.admin().indices().deleteTemplate(deleteIndexTemplateRequest, new AcknowledgedRestListener(channel)); } diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/template/get/RestGetIndexTemplateAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/template/get/RestGetIndexTemplateAction.java index dac342fab95..a4c2539f226 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/template/get/RestGetIndexTemplateAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/template/get/RestGetIndexTemplateAction.java @@ -58,8 +58,6 @@ public class RestGetIndexTemplateAction extends BaseRestHandler { getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local())); getIndexTemplatesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getIndexTemplatesRequest.masterNodeTimeout())); - getIndexTemplatesRequest.listenerThreaded(false); - final boolean implicitAll = getIndexTemplatesRequest.names().length == 0; client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestBuilderListener(channel) { diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/template/put/RestPutIndexTemplateAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/template/put/RestPutIndexTemplateAction.java index 7875f12259b..e555cfd0fac 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/template/put/RestPutIndexTemplateAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/template/put/RestPutIndexTemplateAction.java @@ -42,7 +42,6 @@ public class RestPutIndexTemplateAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest(request.param("name")); - putRequest.listenerThreaded(false); putRequest.template(request.param("template", putRequest.template())); putRequest.order(request.paramAsInt("order", putRequest.order())); putRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putRequest.masterNodeTimeout())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java index 32a2d24e888..4f237465bd6 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java @@ -57,7 +57,6 @@ public class RestValidateQueryAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(Strings.splitStringByCommaToArray(request.param("index"))); - validateQueryRequest.listenerThreaded(false); validateQueryRequest.indicesOptions(IndicesOptions.fromRequest(request, validateQueryRequest.indicesOptions())); if (RestActions.hasBodyContent(request)) { validateQueryRequest.source(RestActions.getRestContent(request)); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/delete/RestDeleteWarmerAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/delete/RestDeleteWarmerAction.java index da41e80cc97..1d3fae87616 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/delete/RestDeleteWarmerAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/delete/RestDeleteWarmerAction.java @@ -47,7 +47,6 @@ public class RestDeleteWarmerAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { DeleteWarmerRequest deleteWarmerRequest = new DeleteWarmerRequest(Strings.splitStringByCommaToArray(request.param("name"))) .indices(Strings.splitStringByCommaToArray(request.param("index"))); - deleteWarmerRequest.listenerThreaded(false); deleteWarmerRequest.timeout(request.paramAsTime("timeout", deleteWarmerRequest.timeout())); deleteWarmerRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteWarmerRequest.masterNodeTimeout())); deleteWarmerRequest.indicesOptions(IndicesOptions.fromRequest(request, deleteWarmerRequest.indicesOptions())); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/put/RestPutWarmerAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/put/RestPutWarmerAction.java index 9a802f1bf3d..62f666364f5 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/put/RestPutWarmerAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/put/RestPutWarmerAction.java @@ -59,7 +59,6 @@ public class RestPutWarmerAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { PutWarmerRequest putWarmerRequest = new PutWarmerRequest(request.param("name")); - putWarmerRequest.listenerThreaded(false); SearchRequest searchRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index"))) .types(Strings.splitStringByCommaToArray(request.param("type"))) .queryCache(request.paramAsBoolean("query_cache", null)) diff --git a/src/main/java/org/elasticsearch/rest/action/bulk/RestBulkAction.java b/src/main/java/org/elasticsearch/rest/action/bulk/RestBulkAction.java index 9578e078270..1a3a1b38a6e 100644 --- a/src/main/java/org/elasticsearch/rest/action/bulk/RestBulkAction.java +++ b/src/main/java/org/elasticsearch/rest/action/bulk/RestBulkAction.java @@ -71,7 +71,6 @@ public class RestBulkAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { BulkRequest bulkRequest = Requests.bulkRequest(); - bulkRequest.listenerThreaded(false); String defaultIndex = request.param("index"); String defaultType = request.param("type"); String defaultRouting = request.param("routing"); diff --git a/src/main/java/org/elasticsearch/rest/action/cat/RestRecoveryAction.java b/src/main/java/org/elasticsearch/rest/action/cat/RestRecoveryAction.java index a7a7eb53e85..e2d277819e0 100644 --- a/src/main/java/org/elasticsearch/rest/action/cat/RestRecoveryAction.java +++ b/src/main/java/org/elasticsearch/rest/action/cat/RestRecoveryAction.java @@ -68,7 +68,6 @@ public class RestRecoveryAction extends AbstractCatAction { final RecoveryRequest recoveryRequest = new RecoveryRequest(Strings.splitStringByCommaToArray(request.param("index"))); recoveryRequest.detailed(request.paramAsBoolean("detailed", false)); recoveryRequest.activeOnly(request.paramAsBoolean("active_only", false)); - recoveryRequest.listenerThreaded(false); recoveryRequest.indicesOptions(IndicesOptions.fromRequest(request, recoveryRequest.indicesOptions())); client.admin().indices().recoveries(recoveryRequest, new RestResponseListener(channel) { diff --git a/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java b/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java index 58dcfa50973..dc38db49181 100644 --- a/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java +++ b/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java @@ -58,7 +58,6 @@ public class RestCountAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { CountRequest countRequest = new CountRequest(Strings.splitStringByCommaToArray(request.param("index"))); countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions())); - countRequest.listenerThreaded(false); if (RestActions.hasBodyContent(request)) { countRequest.source(RestActions.getRestContent(request)); } else { diff --git a/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java b/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java index fced1421cb0..69f06cef1f1 100644 --- a/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java +++ b/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java @@ -51,7 +51,6 @@ public class RestDeleteAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id")); - deleteRequest.listenerThreaded(false); deleteRequest.operationThreaded(true); deleteRequest.routing(request.param("routing")); diff --git a/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java b/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java index 85f73f61ec4..7cfe7caf3fd 100644 --- a/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java @@ -48,7 +48,6 @@ public class RestExistsAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { final ExistsRequest existsRequest = new ExistsRequest(Strings.splitStringByCommaToArray(request.param("index"))); existsRequest.indicesOptions(IndicesOptions.fromRequest(request, existsRequest.indicesOptions())); - existsRequest.listenerThreaded(false); if (RestActions.hasBodyContent(request)) { existsRequest.source(RestActions.getRestContent(request)); } else { diff --git a/src/main/java/org/elasticsearch/rest/action/fieldstats/RestFieldStatsAction.java b/src/main/java/org/elasticsearch/rest/action/fieldstats/RestFieldStatsAction.java index fd45c5a56d4..ca382f3c642 100644 --- a/src/main/java/org/elasticsearch/rest/action/fieldstats/RestFieldStatsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/fieldstats/RestFieldStatsAction.java @@ -57,7 +57,6 @@ public class RestFieldStatsAction extends BaseRestHandler { fieldStatsRequest.indicesOptions(IndicesOptions.fromRequest(request, fieldStatsRequest.indicesOptions())); fieldStatsRequest.fields(Strings.splitStringByCommaToArray(request.param("fields"))); fieldStatsRequest.level(request.param("level", FieldStatsRequest.DEFAULT_LEVEL)); - fieldStatsRequest.listenerThreaded(false); client.fieldStats(fieldStatsRequest, new RestBuilderListener(channel) { @Override diff --git a/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java b/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java index ae2e76be690..9ed5c4d5fe9 100644 --- a/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java +++ b/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java @@ -50,7 +50,6 @@ public class RestGetAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id")); - getRequest.listenerThreaded(false); getRequest.operationThreaded(true); getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh())); getRequest.routing(request.param("routing")); // order is important, set it after routing, so it will set the routing diff --git a/src/main/java/org/elasticsearch/rest/action/get/RestGetSourceAction.java b/src/main/java/org/elasticsearch/rest/action/get/RestGetSourceAction.java index 4142e667985..db3954ec5e8 100644 --- a/src/main/java/org/elasticsearch/rest/action/get/RestGetSourceAction.java +++ b/src/main/java/org/elasticsearch/rest/action/get/RestGetSourceAction.java @@ -51,7 +51,6 @@ public class RestGetSourceAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id")); - getRequest.listenerThreaded(false); getRequest.operationThreaded(true); getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh())); getRequest.routing(request.param("routing")); // order is important, set it after routing, so it will set the routing diff --git a/src/main/java/org/elasticsearch/rest/action/get/RestHeadAction.java b/src/main/java/org/elasticsearch/rest/action/get/RestHeadAction.java index 9217200a7e6..d0c1433bb47 100644 --- a/src/main/java/org/elasticsearch/rest/action/get/RestHeadAction.java +++ b/src/main/java/org/elasticsearch/rest/action/get/RestHeadAction.java @@ -47,7 +47,6 @@ public class RestHeadAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id")); - getRequest.listenerThreaded(false); getRequest.operationThreaded(true); getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh())); getRequest.routing(request.param("routing")); // order is important, set it after routing, so it will set the routing diff --git a/src/main/java/org/elasticsearch/rest/action/get/RestMultiGetAction.java b/src/main/java/org/elasticsearch/rest/action/get/RestMultiGetAction.java index b9cdd78063c..14e4496085b 100644 --- a/src/main/java/org/elasticsearch/rest/action/get/RestMultiGetAction.java +++ b/src/main/java/org/elasticsearch/rest/action/get/RestMultiGetAction.java @@ -53,7 +53,6 @@ public class RestMultiGetAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { MultiGetRequest multiGetRequest = new MultiGetRequest(); - multiGetRequest.listenerThreaded(false); multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh())); multiGetRequest.preference(request.param("preference")); multiGetRequest.realtime(request.paramAsBoolean("realtime", null)); diff --git a/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java b/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java index d95ef3e9498..a0d5b279e71 100644 --- a/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java +++ b/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java @@ -70,7 +70,6 @@ public class RestIndexAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { IndexRequest indexRequest = new IndexRequest(request.param("index"), request.param("type"), request.param("id")); - indexRequest.listenerThreaded(false); indexRequest.operationThreaded(true); indexRequest.routing(request.param("routing")); indexRequest.parent(request.param("parent")); // order is important, set it after routing, so it will set the routing diff --git a/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java b/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java index a9d60e02aa5..41f28574bdf 100644 --- a/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java +++ b/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java @@ -50,8 +50,6 @@ public class RestMoreLikeThisAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { MoreLikeThisRequest mltRequest = moreLikeThisRequest(request.param("index")).type(request.param("type")).id(request.param("id")); mltRequest.routing(request.param("routing")); - - mltRequest.listenerThreaded(false); //TODO the ParseField class that encapsulates the supported names used for an attribute //needs some work if it is to be used in a REST context like this too // See the MoreLikeThisQueryParser constants that hold the valid syntax diff --git a/src/main/java/org/elasticsearch/rest/action/percolate/RestPercolateAction.java b/src/main/java/org/elasticsearch/rest/action/percolate/RestPercolateAction.java index fb609d3e14a..4ee543f5362 100644 --- a/src/main/java/org/elasticsearch/rest/action/percolate/RestPercolateAction.java +++ b/src/main/java/org/elasticsearch/rest/action/percolate/RestPercolateAction.java @@ -94,8 +94,6 @@ public class RestPercolateAction extends BaseRestHandler { } void executePercolate(final PercolateRequest percolateRequest, final RestChannel restChannel, final Client client) { - // we just send a response, no need to fork - percolateRequest.listenerThreaded(false); client.percolate(percolateRequest, new RestToXContentListener(restChannel)); } diff --git a/src/main/java/org/elasticsearch/rest/action/script/RestPutIndexedScriptAction.java b/src/main/java/org/elasticsearch/rest/action/script/RestPutIndexedScriptAction.java index d63a39ac555..35e3f2cc473 100644 --- a/src/main/java/org/elasticsearch/rest/action/script/RestPutIndexedScriptAction.java +++ b/src/main/java/org/elasticsearch/rest/action/script/RestPutIndexedScriptAction.java @@ -75,7 +75,7 @@ public class RestPutIndexedScriptAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, Client client) { - PutIndexedScriptRequest putRequest = new PutIndexedScriptRequest(getScriptLang(request), request.param("id")).listenerThreaded(false); + PutIndexedScriptRequest putRequest = new PutIndexedScriptRequest(getScriptLang(request), request.param("id")); putRequest.version(request.paramAsLong("version", putRequest.version())); putRequest.versionType(VersionType.fromString(request.param("version_type"), putRequest.versionType())); putRequest.source(request.content()); diff --git a/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java b/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java index 92c0ba9b217..6dfe605d96b 100644 --- a/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java +++ b/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java @@ -56,7 +56,6 @@ public class RestMultiSearchAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { MultiSearchRequest multiSearchRequest = new MultiSearchRequest(); - multiSearchRequest.listenerThreaded(false); String[] indices = Strings.splitStringByCommaToArray(request.param("index")); String[] types = Strings.splitStringByCommaToArray(request.param("type")); diff --git a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 9c3e85a2e94..70060588ded 100644 --- a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -77,7 +77,6 @@ public class RestSearchAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { SearchRequest searchRequest; searchRequest = RestSearchAction.parseSearchRequest(request); - searchRequest.listenerThreaded(false); client.search(searchRequest, new RestStatusToXContentListener(channel)); } diff --git a/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java b/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java index 15de56265bc..c53331bb496 100644 --- a/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java +++ b/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java @@ -60,7 +60,6 @@ public class RestSearchScrollAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { String scrollId = request.param("scroll_id"); SearchScrollRequest searchScrollRequest = new SearchScrollRequest(); - searchScrollRequest.listenerThreaded(false); searchScrollRequest.scrollId(scrollId); String scroll = request.param("scroll"); if (scroll != null) { diff --git a/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java b/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java index 9f9c3946b36..184a62244d1 100644 --- a/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java +++ b/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java @@ -59,7 +59,6 @@ public class RestSuggestAction extends BaseRestHandler { public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { SuggestRequest suggestRequest = new SuggestRequest(Strings.splitStringByCommaToArray(request.param("index"))); suggestRequest.indicesOptions(IndicesOptions.fromRequest(request, suggestRequest.indicesOptions())); - suggestRequest.listenerThreaded(false); if (RestActions.hasBodyContent(request)) { suggestRequest.suggest(RestActions.getRestContent(request)); } else { diff --git a/src/main/java/org/elasticsearch/rest/action/termvectors/RestMultiTermVectorsAction.java b/src/main/java/org/elasticsearch/rest/action/termvectors/RestMultiTermVectorsAction.java index b0cd0bd63a7..400869fff0e 100644 --- a/src/main/java/org/elasticsearch/rest/action/termvectors/RestMultiTermVectorsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/termvectors/RestMultiTermVectorsAction.java @@ -49,7 +49,6 @@ public class RestMultiTermVectorsAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { MultiTermVectorsRequest multiTermVectorsRequest = new MultiTermVectorsRequest(); - multiTermVectorsRequest.listenerThreaded(false); TermVectorsRequest template = new TermVectorsRequest(); template.index(request.param("index")); template.type(request.param("type")); diff --git a/src/main/java/org/elasticsearch/rest/action/update/RestUpdateAction.java b/src/main/java/org/elasticsearch/rest/action/update/RestUpdateAction.java index c884fe4267e..d019e598cac 100644 --- a/src/main/java/org/elasticsearch/rest/action/update/RestUpdateAction.java +++ b/src/main/java/org/elasticsearch/rest/action/update/RestUpdateAction.java @@ -55,7 +55,6 @@ public class RestUpdateAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { UpdateRequest updateRequest = new UpdateRequest(request.param("index"), request.param("type"), request.param("id")); - updateRequest.listenerThreaded(false); updateRequest.routing(request.param("routing")); updateRequest.parent(request.param("parent")); updateRequest.timeout(request.paramAsTime("timeout", updateRequest.timeout())); diff --git a/src/main/java/org/elasticsearch/river/RiversService.java b/src/main/java/org/elasticsearch/river/RiversService.java index ed7369d8ad0..fdb2589a540 100644 --- a/src/main/java/org/elasticsearch/river/RiversService.java +++ b/src/main/java/org/elasticsearch/river/RiversService.java @@ -28,6 +28,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.WriteConsistencyLevel; import org.elasticsearch.action.get.GetRequestBuilder; import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -231,7 +232,7 @@ public class RiversService extends AbstractLifecycleComponent { logger.trace("river {} is already allocated", routing.riverName().getName()); continue; } - prepareGetMetaDocument(routing.riverName().name()).execute(new ActionListener() { + prepareGetMetaDocument(routing.riverName().name()).execute(new ThreadedActionListener<>(logger, threadPool, ThreadPool.Names.LISTENER, new ActionListener() { @Override public void onResponse(GetResponse getResponse) { if (!rivers.containsKey(routing.riverName())) { @@ -255,7 +256,7 @@ public class RiversService extends AbstractLifecycleComponent { logger.debug("failed to get _meta from [{}]/[{}], retrying...", e, routing.riverName().type(), routing.riverName().name()); final ActionListener listener = this; try { - threadPool.schedule(TimeValue.timeValueSeconds(5), ThreadPool.Names.SAME, new Runnable() { + threadPool.schedule(TimeValue.timeValueSeconds(5), ThreadPool.Names.LISTENER, new Runnable() { @Override public void run() { prepareGetMetaDocument(routing.riverName().name()).execute(listener); @@ -268,12 +269,12 @@ public class RiversService extends AbstractLifecycleComponent { logger.warn("failed to get _meta from [{}]/[{}]", e, routing.riverName().type(), routing.riverName().name()); } } - }); + })); } } private GetRequestBuilder prepareGetMetaDocument(String riverName) { - return client.prepareGet(riverIndexName, riverName, "_meta").setPreference("_primary").setListenerThreaded(true); + return client.prepareGet(riverIndexName, riverName, "_meta").setPreference("_primary"); } } } diff --git a/src/test/java/org/elasticsearch/action/ListenerActionTests.java b/src/test/java/org/elasticsearch/action/ListenerActionTests.java new file mode 100644 index 00000000000..50cde99fcdb --- /dev/null +++ b/src/test/java/org/elasticsearch/action/ListenerActionTests.java @@ -0,0 +1,75 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action; + +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.test.ElasticsearchIntegrationTest; +import org.junit.Test; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; + +/** + */ +public class ListenerActionTests extends ElasticsearchIntegrationTest { + + @Test + public void verifyThreadedListeners() throws Throwable { + + final CountDownLatch latch = new CountDownLatch(1); + final AtomicReference failure = new AtomicReference<>(); + final AtomicReference threadName = new AtomicReference<>(); + Client client = client(); + + IndexRequest request = new IndexRequest("test", "type", "1"); + if (randomBoolean()) { + // set the source, without it, we will have a verification failure + request.source("field1", "value1"); + } + + client.index(request, new ActionListener() { + @Override + public void onResponse(IndexResponse indexResponse) { + threadName.set(Thread.currentThread().getName()); + latch.countDown(); + } + + @Override + public void onFailure(Throwable e) { + threadName.set(Thread.currentThread().getName()); + failure.set(e); + latch.countDown(); + } + }); + + latch.await(); + + boolean shouldBeThreaded = DiscoveryNode.clientNode(client.settings()) || TransportClient.CLIENT_TYPE.equals(client.settings().get(Client.CLIENT_TYPE_SETTING)); + if (shouldBeThreaded) { + assertTrue(threadName.get().contains("listener")); + } else { + assertFalse(threadName.get().contains("listener")); + } + } +} diff --git a/src/test/java/org/elasticsearch/action/support/TransportActionFilterChainTests.java b/src/test/java/org/elasticsearch/action/support/TransportActionFilterChainTests.java index 1eccf3521f0..e32eb6cdb7c 100644 --- a/src/test/java/org/elasticsearch/action/support/TransportActionFilterChainTests.java +++ b/src/test/java/org/elasticsearch/action/support/TransportActionFilterChainTests.java @@ -92,7 +92,7 @@ public class TransportActionFilterChainTests extends ElasticsearchTestCase { } } - PlainListenableActionFuture future = new PlainListenableActionFuture<>(false, null); + PlainListenableActionFuture future = new PlainListenableActionFuture<>(null); transportAction.execute(new TestRequest(), future); try { assertThat(future.get(), notNullValue()); @@ -174,7 +174,7 @@ public class TransportActionFilterChainTests extends ElasticsearchTestCase { } } - PlainListenableActionFuture future = new PlainListenableActionFuture<>(false, null); + PlainListenableActionFuture future = new PlainListenableActionFuture<>(null); transportAction.execute(new TestRequest(), future); try { assertThat(future.get(), notNullValue()); diff --git a/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java b/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java index 05561a9dec0..e4484ef3177 100644 --- a/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java +++ b/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java @@ -51,6 +51,7 @@ import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportMessage; import org.junit.After; import org.junit.Before; @@ -84,16 +85,19 @@ public abstract class AbstractClientHeadersTests extends ElasticsearchTestCase { CreateIndexAction.INSTANCE, IndicesStatsAction.INSTANCE, ClearIndicesCacheAction.INSTANCE, FlushAction.INSTANCE }; + protected ThreadPool threadPool; private Client client; @Before public void initClient() { + threadPool = new ThreadPool("test-" + getTestName()); client = buildClient(HEADER_SETTINGS, ACTIONS); } @After - public void cleanupClient() { + public void cleanupClient() throws Exception { client.close(); + terminate(threadPool); } protected abstract Client buildClient(Settings headersSettings, GenericAction[] testedActions); diff --git a/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java b/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java index 1bf3bf5be32..ce4cfa43439 100644 --- a/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java +++ b/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java @@ -42,18 +42,6 @@ public class NodeClientHeadersTests extends AbstractClientHeadersTests { private static final ActionFilters EMPTY_FILTERS = new ActionFilters(ImmutableSet.of()); - private ThreadPool threadPool; - - @Before - public void init() { - threadPool = new ThreadPool("test"); - } - - @After - public void cleanup() throws InterruptedException { - terminate(threadPool); - } - @Override protected Client buildClient(Settings headersSettings, GenericAction[] testedActions) { Settings settings = HEADER_SETTINGS; @@ -61,8 +49,8 @@ public class NodeClientHeadersTests extends AbstractClientHeadersTests { Headers headers = new Headers(settings); Actions actions = new Actions(settings, threadPool, testedActions); - NodeClusterAdminClient clusterClient = new NodeClusterAdminClient(threadPool, actions, headers); - NodeIndicesAdminClient indicesClient = new NodeIndicesAdminClient(threadPool, actions, headers); + NodeClusterAdminClient clusterClient = new NodeClusterAdminClient(settings, threadPool, actions, headers); + NodeIndicesAdminClient indicesClient = new NodeIndicesAdminClient(settings, threadPool, actions, headers); NodeAdminClient adminClient = new NodeAdminClient(settings, clusterClient, indicesClient); return new NodeClient(settings, threadPool, adminClient, actions, headers); } diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java index c1d11bb2312..17e3c0c5d87 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java @@ -84,7 +84,7 @@ public class TransportClientRetryTests extends ElasticsearchIntegrationTest { if (randomBoolean()) { clusterState = transportClient.admin().cluster().state(clusterStateRequest).get().getState(); } else { - PlainListenableActionFuture future = new PlainListenableActionFuture<>(clusterStateRequest.listenerThreaded(), transportClient.threadPool()); + PlainListenableActionFuture future = new PlainListenableActionFuture<>(transportClient.threadPool()); transportClient.admin().cluster().state(clusterStateRequest, future); clusterState = future.get().getState(); } From 70ae862fe45c88c1e9ae894554af9176f00f3424 Mon Sep 17 00:00:00 2001 From: Mikael Mattsson Date: Fri, 1 May 2015 16:58:04 +0200 Subject: [PATCH 18/22] Docs: Add Elasticsearch Indexer for WordPress to integrations.asciidoc Closes #10921 --- docs/community/integrations.asciidoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/community/integrations.asciidoc b/docs/community/integrations.asciidoc index d488e324313..bb2ff6850a0 100644 --- a/docs/community/integrations.asciidoc +++ b/docs/community/integrations.asciidoc @@ -59,6 +59,9 @@ * http://searchbox-io.github.com/wp-elasticsearch/[Wp-Elasticsearch]: Elasticsearch WordPress Plugin + +* https://github.com/wallmanderco/elasticsearch-indexer[Elasticsearch Indexer]: + Elasticsearch WordPress Plugin * https://github.com/OlegKunitsyn/eslogd[eslogd]: Linux daemon that replicates events to a central Elasticsearch server in real-time From 4b3672b7df94291d54b83840513b90a7f513bd7d Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 4 May 2015 10:00:05 -0400 Subject: [PATCH 19/22] Add migration note for hunspell dictionaries --- .../tokenfilters/hunspell-tokenfilter.asciidoc | 12 ++++-------- docs/reference/migration/migrate_2_0.asciidoc | 5 +++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/reference/analysis/tokenfilters/hunspell-tokenfilter.asciidoc b/docs/reference/analysis/tokenfilters/hunspell-tokenfilter.asciidoc index 8108614ab74..47b247e4bd5 100644 --- a/docs/reference/analysis/tokenfilters/hunspell-tokenfilter.asciidoc +++ b/docs/reference/analysis/tokenfilters/hunspell-tokenfilter.asciidoc @@ -3,7 +3,7 @@ Basic support for hunspell stemming. Hunspell dictionaries will be picked up from a dedicated hunspell directory on the filesystem -(defaults to `/hunspell`). Each dictionary is expected to +(`/hunspell`). Each dictionary is expected to have its own directory named after its associated locale (language). This dictionary directory is expected to hold a single `*.aff` and one or more `*.dic` files (all of which will automatically be picked up). @@ -19,10 +19,6 @@ following directory layout will define the `en_US` dictionary: | | |-- en_US.aff -------------------------------------------------- -The location of the hunspell directory can be configured using the -`indices.analysis.hunspell.dictionary.location` settings in -_elasticsearch.yml_. - Each dictionary can be configured with one setting: `ignore_case`:: @@ -91,9 +87,9 @@ the stemming is determined by the quality of the dictionary. [float] ==== Dictionary loading -By default, the configured (`indices.analysis.hunspell.dictionary.location`) -or default Hunspell directory (`config/hunspell/`) is checked for dictionaries -when the node starts up, and any dictionaries are automatically loaded. +By default, the default Hunspell directory (`config/hunspell/`) is checked +for dictionaries when the node starts up, and any dictionaries are +automatically loaded. Dictionary loading can be deferred until they are actually used by setting `indices.analysis.hunspell.dictionary.lazy` to `true`in the config file. diff --git a/docs/reference/migration/migrate_2_0.asciidoc b/docs/reference/migration/migrate_2_0.asciidoc index 292bb633a29..d9409406742 100644 --- a/docs/reference/migration/migrate_2_0.asciidoc +++ b/docs/reference/migration/migrate_2_0.asciidoc @@ -458,3 +458,8 @@ there is not enough disk space to complete this migration, the upgrade will be cancelled and can only be resumed once enough disk space is made available. The `index.store.distributor` setting has also been removed. + +=== Hunspell dictionary configuration + +The parameter `indices.analysis.hunspell.dictionary.location` has been removed, +and `/hunspell` is always used. From 5a701c1f9f48fd68e65aa0c53fe5ccb36b7210d7 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 4 May 2015 10:18:09 -0400 Subject: [PATCH 20/22] remove shutdownHooks permission --- .../org/elasticsearch/bootstrap/Bootstrap.java | 18 +++++++++--------- .../elasticsearch/bootstrap/security.policy | 3 --- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index d351a9d4ea2..9c3c2fdda2b 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -216,15 +216,6 @@ public class Bootstrap { // fail if using broken version JVMCheck.check(); - bootstrap.setup(true, settings, environment); - - stage = "Startup"; - bootstrap.start(); - - if (!foreground) { - closeSysError(); - } - keepAliveLatch = new CountDownLatch(1); // keep this thread alive (non daemon thread) until we shutdown Runtime.getRuntime().addShutdownHook(new Thread() { @@ -234,6 +225,15 @@ public class Bootstrap { } }); + bootstrap.setup(true, settings, environment); + + stage = "Startup"; + bootstrap.start(); + + if (!foreground) { + closeSysError(); + } + keepAliveThread = new Thread(new Runnable() { @Override public void run() { diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index 993868c18b3..49cba2099ce 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -66,9 +66,6 @@ grant { // needed by BootStrap, etc permission java.lang.RuntimePermission "exitVM.*"; - // needed by RandomizedTest.globalTempDir() - permission java.lang.RuntimePermission "shutdownHooks"; - // needed by PluginManager permission java.lang.RuntimePermission "setFactory"; From bffcf5af58052d33f4932b7fd5ef5a78327925e3 Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Mon, 4 May 2015 16:48:53 +0200 Subject: [PATCH 21/22] Docs: Update rolling upgrade Added note about why replica shards may remain unassigned while there is only one node of the higher version in the cluster. Closes #10951 --- docs/reference/setup/upgrade.asciidoc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/reference/setup/upgrade.asciidoc b/docs/reference/setup/upgrade.asciidoc index 9f9e745808f..c477f5ec9c7 100644 --- a/docs/reference/setup/upgrade.asciidoc +++ b/docs/reference/setup/upgrade.asciidoc @@ -121,6 +121,20 @@ This syntax applies to Elasticsearch 1.0 and later: * Repeat this process for all remaining nodes. +[IMPORTANT] +==================================================== +During a rolling upgrade, primary shards assigned to a node with the higher +version will never have their replicas assigned to a node with the lower +version, because the newer version may have a different data format which is +not understood by the older version. + +If it is not possible to assign the replica shards to another node with the +higher version -- e.g. if there is only one node with the higher version in +the cluster -- then the replica shards will remain unassigned, i.e. the +cluster health will be status `yellow`. As soon as another node with the +higher version joins the cluster, the replicas should be assigned and the +cluster health will reach status `green`. +==================================================== It may be possible to perform the upgrade by installing the new software while the service is running. This would reduce downtime by ensuring the service was ready to run on the new version as soon as it is stopped on the node being upgraded. This can be done by installing the new version in its own directory and using the symbolic link method outlined above. It is important to test this procedure first to be sure that site-specific configuration data and production indices will not be overwritten during the upgrade process. From 29e5f76920db03cfed74266bef88874123fdff85 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 27 Apr 2015 17:34:19 +0200 Subject: [PATCH 22/22] [INDICES] Wait forever (or one day) for indices to close Today we wait 30 sec for shards to flush and close and then simply exit the process. This is often not desired and we should by default wait long enough for shards to close etc. This commit adds a default timeout of one day which simplifies the code and gives us _enough_ time to shut down. Closes #10680 --- .../java/org/elasticsearch/indices/IndicesService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/elasticsearch/indices/IndicesService.java b/src/main/java/org/elasticsearch/indices/IndicesService.java index 663fe402729..d932bbb3803 100644 --- a/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -96,6 +96,8 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde */ public class IndicesService extends AbstractLifecycleComponent implements Iterable { + public static final String INDICES_SHARDS_CLOSED_TIMEOUT = "indices.shards_closed_timeout"; + private final InternalIndicesLifecycle indicesLifecycle; private final IndicesAnalysisService indicesAnalysisService; @@ -104,6 +106,7 @@ public class IndicesService extends AbstractLifecycleComponent i private final PluginsService pluginsService; private final NodeEnvironment nodeEnv; + private final TimeValue shardsClosedTimeout; private volatile Map> indices = ImmutableMap.of(); private final Map> pendingDeletes = new HashMap<>(); @@ -119,6 +122,7 @@ public class IndicesService extends AbstractLifecycleComponent i this.pluginsService = injector.getInstance(PluginsService.class); this.indicesLifecycle.addListener(oldShardsStats); this.nodeEnv = nodeEnv; + this.shardsClosedTimeout = settings.getAsTime(INDICES_SHARDS_CLOSED_TIMEOUT, new TimeValue(1, TimeUnit.DAYS)); } @Override @@ -147,8 +151,8 @@ public class IndicesService extends AbstractLifecycleComponent i }); } try { - if (latch.await(30, TimeUnit.SECONDS) == false) { - logger.warn("Not all shards are closed yet, waited 30sec - stopping service"); + if (latch.await(shardsClosedTimeout.seconds(), TimeUnit.SECONDS) == false) { + logger.warn("Not all shards are closed yet, waited {}sec - stopping service", shardsClosedTimeout.seconds()); } } catch (InterruptedException e) { // ignore