Search in sources :

Example 31 with Environment

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

the class SpawnerNoBootstrapTests method testControllerSpawn.

/**
     * Two plugins - one with a controller daemon and one without.
     */
public void testControllerSpawn() throws IOException, InterruptedException {
    // On Windows you cannot directly run a batch file - you have to run cmd.exe with the batch file
    // as an argument and that's out of the remit of the controller daemon process spawner.  If
    // you need to build on Windows, just don't run this test.  The process spawner itself will work
    // with native processes.
    assumeFalse("This test does not work on Windows", Constants.WINDOWS);
    Path esHome = createTempDir().resolve("esHome");
    Settings.Builder settingsBuilder = Settings.builder();
    settingsBuilder.put(Environment.PATH_HOME_SETTING.getKey(), esHome.toString());
    Settings settings = settingsBuilder.build();
    Environment environment = new Environment(settings);
    // This plugin WILL have a controller daemon
    Path plugin = environment.pluginsFile().resolve("test_plugin");
    Files.createDirectories(plugin);
    Path controllerProgram = Spawner.makeSpawnPath(plugin);
    createControllerProgram(controllerProgram);
    // This plugin will NOT have a controller daemon
    Path otherPlugin = environment.pluginsFile().resolve("other_plugin");
    Files.createDirectories(otherPlugin);
    Spawner spawner = new Spawner();
    spawner.spawnNativePluginControllers(environment);
    List<Process> processes = spawner.getProcesses();
    // 1 because there should only be a reference in the list for the plugin that had the controller daemon, not the other plugin
    assertEquals(1, processes.size());
    Process process = processes.get(0);
    try (BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
        String line = stdoutReader.readLine();
        assertEquals("I am alive", line);
        spawner.close();
        // Fail if the process doesn't die within 1 second - usually it will be even quicker but it depends on OS scheduling
        assertTrue(process.waitFor(1, TimeUnit.SECONDS));
    }
}
Also used : Path(java.nio.file.Path) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Example 32 with Environment

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

the class ESTestCase method createTestAnalysis.

/**
     * Creates an TestAnalysis with all the default analyzers configured.
     */
public static TestAnalysis createTestAnalysis(IndexSettings indexSettings, Settings nodeSettings, AnalysisPlugin... analysisPlugins) throws IOException {
    Environment env = new Environment(nodeSettings);
    AnalysisModule analysisModule = new AnalysisModule(env, Arrays.asList(analysisPlugins));
    AnalysisRegistry analysisRegistry = analysisModule.getAnalysisRegistry();
    return new TestAnalysis(analysisRegistry.build(indexSettings), analysisRegistry.buildTokenFilterFactories(indexSettings), analysisRegistry.buildTokenizerFactories(indexSettings), analysisRegistry.buildCharFilterFactories(indexSettings));
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Environment(org.elasticsearch.env.Environment) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule)

Example 33 with Environment

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

the class IndexModuleTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    indicesQueryCache = new IndicesQueryCache(settings);
    indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
    index = indexSettings.getIndex();
    environment = new Environment(settings);
    threadPool = new TestThreadPool("test");
    circuitBreakerService = new NoneCircuitBreakerService();
    bigArrays = new BigArrays(settings, circuitBreakerService);
    ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(emptyList());
    ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
    ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    scriptService = new ScriptService(settings, environment, new ResourceWatcherService(settings, threadPool), scriptEngineRegistry, scriptContextRegistry, scriptSettings);
    clusterService = ClusterServiceUtils.createClusterService(threadPool);
    nodeEnvironment = new NodeEnvironment(settings, environment);
    mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry();
}
Also used : IndicesQueryCache(org.elasticsearch.indices.IndicesQueryCache) ScriptService(org.elasticsearch.script.ScriptService) BigArrays(org.elasticsearch.common.util.BigArrays) IndicesModule(org.elasticsearch.indices.IndicesModule) ScriptSettings(org.elasticsearch.script.ScriptSettings) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) ScriptEngineRegistry(org.elasticsearch.script.ScriptEngineRegistry) Environment(org.elasticsearch.env.Environment) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ResourceWatcherService(org.elasticsearch.watcher.ResourceWatcherService) ScriptContextRegistry(org.elasticsearch.script.ScriptContextRegistry) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 34 with Environment

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

the class CompoundAnalysisTests method testDefaultsCompoundAnalysis.

public void testDefaultsCompoundAnalysis() throws Exception {
    Settings settings = getJsonSettings();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings);
    AnalysisModule analysisModule = new AnalysisModule(new Environment(settings), singletonList(new AnalysisPlugin() {

        @Override
        public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
            return singletonMap("myfilter", MyFilterTokenFilterFactory::new);
        }
    }));
    TokenFilterFactory filterFactory = analysisModule.getAnalysisRegistry().buildTokenFilterFactories(idxSettings).get("dict_dec");
    MatcherAssert.assertThat(filterFactory, instanceOf(DictionaryCompoundWordTokenFilterFactory.class));
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Environment(org.elasticsearch.env.Environment) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule) MyFilterTokenFilterFactory(org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory) AnalysisProvider(org.elasticsearch.indices.analysis.AnalysisModule.AnalysisProvider) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) MyFilterTokenFilterFactory(org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory) DictionaryCompoundWordTokenFilterFactory(org.elasticsearch.index.analysis.compound.DictionaryCompoundWordTokenFilterFactory) DictionaryCompoundWordTokenFilterFactory(org.elasticsearch.index.analysis.compound.DictionaryCompoundWordTokenFilterFactory) AnalysisPlugin(org.elasticsearch.plugins.AnalysisPlugin)

Example 35 with Environment

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

the class CompoundAnalysisTests method analyze.

private List<String> analyze(Settings settings, String analyzerName, String text) throws IOException {
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings);
    AnalysisModule analysisModule = new AnalysisModule(new Environment(settings), singletonList(new AnalysisPlugin() {

        @Override
        public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
            return singletonMap("myfilter", MyFilterTokenFilterFactory::new);
        }
    }));
    IndexAnalyzers indexAnalyzers = analysisModule.getAnalysisRegistry().build(idxSettings);
    Analyzer analyzer = indexAnalyzers.get(analyzerName).analyzer();
    AllEntries allEntries = new AllEntries();
    allEntries.addText("field1", text, 1.0f);
    TokenStream stream = AllTokenStream.allTokenStream("_all", text, 1.0f, analyzer);
    stream.reset();
    CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class);
    List<String> terms = new ArrayList<>();
    while (stream.incrementToken()) {
        String tokText = termAtt.toString();
        terms.add(tokText);
    }
    return terms;
}
Also used : AllTokenStream(org.elasticsearch.common.lucene.all.AllTokenStream) TokenStream(org.apache.lucene.analysis.TokenStream) IndexSettings(org.elasticsearch.index.IndexSettings) ArrayList(java.util.ArrayList) Analyzer(org.apache.lucene.analysis.Analyzer) AllEntries(org.elasticsearch.common.lucene.all.AllEntries) CharTermAttribute(org.apache.lucene.analysis.tokenattributes.CharTermAttribute) Environment(org.elasticsearch.env.Environment) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule) MyFilterTokenFilterFactory(org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory) AnalysisProvider(org.elasticsearch.indices.analysis.AnalysisModule.AnalysisProvider) AnalysisPlugin(org.elasticsearch.plugins.AnalysisPlugin)

Aggregations

Environment (org.elasticsearch.env.Environment)103 Settings (org.elasticsearch.common.settings.Settings)63 Path (java.nio.file.Path)60 Matchers.containsString (org.hamcrest.Matchers.containsString)28 IndexSettings (org.elasticsearch.index.IndexSettings)20 UserException (org.elasticsearch.cli.UserException)14 IOException (java.io.IOException)11 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)8 ScriptService (org.elasticsearch.script.ScriptService)8 AnalysisModule (org.elasticsearch.indices.analysis.AnalysisModule)7 ScriptContextRegistry (org.elasticsearch.script.ScriptContextRegistry)7 ScriptEngineRegistry (org.elasticsearch.script.ScriptEngineRegistry)7 ScriptSettings (org.elasticsearch.script.ScriptSettings)7 Collections (java.util.Collections)5 Before (org.junit.Before)5 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Logger (org.apache.logging.log4j.Logger)4 MockScriptEngine (org.elasticsearch.script.MockScriptEngine)4