Search in sources :

Example 76 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class InternalScriptedMetricTests method mockScriptService.

/**
     * Mock of the script service. The script that is run looks at the
     * "_aggs" parameter visible when executing the script and simply returns the count.
     * This should be equal to the number of input InternalScriptedMetrics that are reduced
     * in total.
     */
@Override
protected ScriptService mockScriptService() {
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), "false").build();
    // mock script always retuns the size of the input aggs list as result
    @SuppressWarnings("unchecked") MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap(REDUCE_SCRIPT_NAME, script -> {
        return ((List<Object>) script.get("_aggs")).size();
    }));
    ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
    ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
    ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    try {
        return new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
    } catch (IOException e) {
        throw new ElasticsearchException(e);
    }
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) Script(org.elasticsearch.script.Script) PipelineAggregator(org.elasticsearch.search.aggregations.pipeline.PipelineAggregator) ScriptEngineRegistry(org.elasticsearch.script.ScriptEngineRegistry) Environment(org.elasticsearch.env.Environment) InternalAggregationTestCase(org.elasticsearch.search.aggregations.InternalAggregationTestCase) ScriptType(org.elasticsearch.script.ScriptType) Reader(org.elasticsearch.common.io.stream.Writeable.Reader) IOException(java.io.IOException) HashMap(java.util.HashMap) ScriptSettings(org.elasticsearch.script.ScriptSettings) ScriptContextRegistry(org.elasticsearch.script.ScriptContextRegistry) List(java.util.List) Settings(org.elasticsearch.common.settings.Settings) MockScriptEngine(org.elasticsearch.script.MockScriptEngine) Map(java.util.Map) ScriptService(org.elasticsearch.script.ScriptService) Collections(java.util.Collections) ScriptService(org.elasticsearch.script.ScriptService) ScriptSettings(org.elasticsearch.script.ScriptSettings) ScriptEngineRegistry(org.elasticsearch.script.ScriptEngineRegistry) MockScriptEngine(org.elasticsearch.script.MockScriptEngine) Environment(org.elasticsearch.env.Environment) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ScriptSettings(org.elasticsearch.script.ScriptSettings) Settings(org.elasticsearch.common.settings.Settings) ScriptContextRegistry(org.elasticsearch.script.ScriptContextRegistry)

Example 77 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class IcuTokenizerFactory method parseRules.

//parse a single RBBi rule file
private BreakIterator parseRules(String filename, Environment env) throws IOException {
    final Path path = env.configFile().resolve(filename);
    String rules = Files.readAllLines(path).stream().filter((v) -> v.startsWith("#") == false).collect(Collectors.joining("\n"));
    return new RuleBasedBreakIterator(rules.toString());
}
Also used : Path(java.nio.file.Path) ElasticsearchException(org.elasticsearch.ElasticsearchException) UCharacter(com.ibm.icu.lang.UCharacter) Tokenizer(org.apache.lucene.analysis.Tokenizer) UScript(com.ibm.icu.lang.UScript) Files(java.nio.file.Files) RuleBasedBreakIterator(com.ibm.icu.text.RuleBasedBreakIterator) Environment(org.elasticsearch.env.Environment) BreakIterator(com.ibm.icu.text.BreakIterator) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ICUTokenizer(org.apache.lucene.analysis.icu.segmentation.ICUTokenizer) DefaultICUTokenizerConfig(org.apache.lucene.analysis.icu.segmentation.DefaultICUTokenizerConfig) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) IndexSettings(org.elasticsearch.index.IndexSettings) UProperty(com.ibm.icu.lang.UProperty) Path(java.nio.file.Path) ICUTokenizerConfig(org.apache.lucene.analysis.icu.segmentation.ICUTokenizerConfig) RuleBasedBreakIterator(com.ibm.icu.text.RuleBasedBreakIterator)

Example 78 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class IndexModuleTests method testForceCustomQueryCache.

public void testForceCustomQueryCache() throws IOException {
    Settings indexSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings("foo", indexSettings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    module.forceQueryCacheProvider((a, b) -> new CustomQueryCache());
    expectThrows(AlreadySetException.class, () -> module.forceQueryCacheProvider((a, b) -> new CustomQueryCache()));
    IndexService indexService = newIndexService(module);
    assertTrue(indexService.cache().query() instanceof CustomQueryCache);
    indexService.close("simon says", false);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Property(org.elasticsearch.common.settings.Setting.Property) BigArrays(org.elasticsearch.common.util.BigArrays) ScriptEngineRegistry(org.elasticsearch.script.ScriptEngineRegistry) IndexSettingsModule(org.elasticsearch.test.IndexSettingsModule) Environment(org.elasticsearch.env.Environment) Term(org.apache.lucene.index.Term) IndicesQueryCache(org.elasticsearch.indices.IndicesQueryCache) MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) AssertingDirectoryReader(org.apache.lucene.index.AssertingDirectoryReader) ScriptContextRegistry(org.elasticsearch.script.ScriptContextRegistry) Settings(org.elasticsearch.common.settings.Settings) SearchOperationListener(org.elasticsearch.index.shard.SearchOperationListener) ThreadPool(org.elasticsearch.threadpool.ThreadPool) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) QueryCachingPolicy(org.apache.lucene.search.QueryCachingPolicy) AlreadySetException(org.apache.lucene.util.SetOnce.AlreadySetException) TestSearchContext(org.elasticsearch.test.TestSearchContext) Setting(org.elasticsearch.common.settings.Setting) IndexStore(org.elasticsearch.index.store.IndexStore) Collections.emptyList(java.util.Collections.emptyList) DirectoryReader(org.apache.lucene.index.DirectoryReader) AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Engine(org.elasticsearch.index.engine.Engine) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) FieldInvertState(org.apache.lucene.index.FieldInvertState) Version(org.elasticsearch.Version) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) SimilarityProvider(org.elasticsearch.index.similarity.SimilarityProvider) IndexingOperationListener(org.elasticsearch.index.shard.IndexingOperationListener) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) IndexSearcher(org.apache.lucene.search.IndexSearcher) InternalEngineTests(org.elasticsearch.index.engine.InternalEngineTests) ResourceWatcherService(org.elasticsearch.watcher.ResourceWatcherService) Weight(org.apache.lucene.search.Weight) ClusterService(org.elasticsearch.cluster.service.ClusterService) SearchContext(org.elasticsearch.search.internal.SearchContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) ScriptSettings(org.elasticsearch.script.ScriptSettings) IndexRemovalReason(org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason) MockEngineFactory(org.elasticsearch.test.engine.MockEngineFactory) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) IndexSearcherWrapper(org.elasticsearch.index.shard.IndexSearcherWrapper) Similarity(org.apache.lucene.search.similarities.Similarity) IndicesModule(org.elasticsearch.indices.IndicesModule) ESTestCase(org.elasticsearch.test.ESTestCase) TermStatistics(org.apache.lucene.search.TermStatistics) EngineException(org.elasticsearch.index.engine.EngineException) Collections.emptyMap(java.util.Collections.emptyMap) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IndexFieldDataCache(org.elasticsearch.index.fielddata.IndexFieldDataCache) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) IOUtils(org.apache.lucene.util.IOUtils) IOException(java.io.IOException) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) ShardLock(org.elasticsearch.env.ShardLock) IndexQueryCache(org.elasticsearch.index.cache.query.IndexQueryCache) TimeUnit(java.util.concurrent.TimeUnit) CollectionStatistics(org.apache.lucene.search.CollectionStatistics) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) QueryCache(org.elasticsearch.index.cache.query.QueryCache) ClusterServiceUtils(org.elasticsearch.test.ClusterServiceUtils) ScriptService(org.elasticsearch.script.ScriptService) Collections(java.util.Collections) AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings)

Example 79 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class InternalSettingsPreparerTests method testDefaultPropertiesOverride.

public void testDefaultPropertiesOverride() throws Exception {
    Path configDir = homeDir.resolve("config");
    Files.createDirectories(configDir);
    Files.write(configDir.resolve("elasticsearch.yml"), Collections.singletonList("setting: bar"), StandardCharsets.UTF_8);
    Map<String, String> props = Collections.singletonMap("default.setting", "foo");
    Environment env = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null, props);
    assertEquals("bar", env.settings().get("setting"));
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) SecureString(org.elasticsearch.common.settings.SecureString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 80 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class InternalSettingsPreparerTests method testDefaultProperties.

public void testDefaultProperties() throws Exception {
    Map<String, String> props = Collections.singletonMap("default.setting", "foo");
    Environment env = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null, props);
    assertEquals("foo", env.settings().get("setting"));
}
Also used : Environment(org.elasticsearch.env.Environment) SecureString(org.elasticsearch.common.settings.SecureString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

Environment (org.elasticsearch.env.Environment)130 Settings (org.elasticsearch.common.settings.Settings)84 Path (java.nio.file.Path)66 Matchers.containsString (org.hamcrest.Matchers.containsString)42 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)26 TestEnvironment (org.elasticsearch.env.TestEnvironment)22 IndexSettings (org.elasticsearch.index.IndexSettings)21 UserException (org.elasticsearch.cli.UserException)17 IOException (java.io.IOException)15 AnalysisModule (org.elasticsearch.indices.analysis.AnalysisModule)9 MockTerminal (org.elasticsearch.cli.MockTerminal)8 ClusterState (org.elasticsearch.cluster.ClusterState)8 ScriptService (org.elasticsearch.script.ScriptService)8 HashMap (java.util.HashMap)7 ScriptContextRegistry (org.elasticsearch.script.ScriptContextRegistry)7 ScriptEngineRegistry (org.elasticsearch.script.ScriptEngineRegistry)7 ScriptSettings (org.elasticsearch.script.ScriptSettings)7 ArrayList (java.util.ArrayList)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 Before (org.junit.Before)6