Search in sources :

Example 61 with Environment

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

the class RemoveSettingsCommandIT method testRemoveSettingsAbortedByUser.

public void testRemoveSettingsAbortedByUser() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(0);
    String node = internalCluster().startNode();
    client().admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder().put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.getKey(), false).build()).get();
    Settings dataPathSettings = internalCluster().dataPathSettings(node);
    ensureStableCluster(1);
    internalCluster().stopRandomDataNode();
    Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
    expectThrows(() -> removeSettings(environment, true, new String[] { DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.getKey() }), ElasticsearchNodeCommand.ABORTED_BY_USER_MSG);
}
Also used : TestEnvironment(org.elasticsearch.env.TestEnvironment) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.elasticsearch.common.settings.Settings) DiskThresholdSettings(org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings)

Example 62 with Environment

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

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 = TestEnvironment.newEnvironment(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) TestEnvironment(org.elasticsearch.env.TestEnvironment) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule)

Example 63 with Environment

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

the class ESIntegTestCase method randomRepoPath.

/**
 * Returns path to a random directory that can be used to create a temporary file system repo
 */
public static Path randomRepoPath(Settings settings) {
    Environment environment = TestEnvironment.newEnvironment(settings);
    Path[] repoFiles = environment.repoFiles();
    assert repoFiles.length > 0;
    Path path;
    do {
        path = repoFiles[0].resolve(randomAlphaOfLength(10));
    } while (Files.exists(path));
    return path;
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) TestEnvironment(org.elasticsearch.env.TestEnvironment)

Example 64 with Environment

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

the class Bootstrap method init.

/**
     * This method is invoked by {@link Elasticsearch#main(String[])} to startup elasticsearch.
     */
static void init(final boolean foreground, final Path pidFile, final boolean quiet, final Environment initialEnv) throws BootstrapException, NodeValidationException, UserException {
    // Set the system property before anything has a chance to trigger its use
    initLoggerPrefix();
    // force the class initializer for BootstrapInfo to run before
    // the security manager is installed
    BootstrapInfo.init();
    INSTANCE = new Bootstrap();
    final SecureSettings keystore = loadSecureSettings(initialEnv);
    Environment environment = createEnvironment(foreground, pidFile, keystore, initialEnv.settings());
    try {
        LogConfigurator.configure(environment);
    } catch (IOException e) {
        throw new BootstrapException(e);
    }
    checkForCustomConfFile();
    if (environment.pidFile() != null) {
        try {
            PidFile.create(environment.pidFile(), true);
        } catch (IOException e) {
            throw new BootstrapException(e);
        }
    }
    final boolean closeStandardStreams = (foreground == false) || quiet;
    try {
        if (closeStandardStreams) {
            final Logger rootLogger = ESLoggerFactory.getRootLogger();
            final Appender maybeConsoleAppender = Loggers.findAppender(rootLogger, ConsoleAppender.class);
            if (maybeConsoleAppender != null) {
                Loggers.removeAppender(rootLogger, maybeConsoleAppender);
            }
            closeSystOut();
        }
        // fail if somebody replaced the lucene jars
        checkLucene();
        // install the default uncaught exception handler; must be done before security is
        // initialized as we do not want to grant the runtime permission
        // setDefaultUncaughtExceptionHandler
        Thread.setDefaultUncaughtExceptionHandler(new ElasticsearchUncaughtExceptionHandler(() -> Node.NODE_NAME_SETTING.get(environment.settings())));
        INSTANCE.setup(true, environment);
        /* TODO: close this once s3 repository doesn't try to read during repository construction
            try {
                // any secure settings must be read during node construction
                IOUtils.close(keystore);
            } catch (IOException e) {
                throw new BootstrapException(e);
            }*/
        INSTANCE.start();
        if (closeStandardStreams) {
            closeSysError();
        }
    } catch (NodeValidationException | RuntimeException e) {
        // disable console logging, so user does not see the exception twice (jvm will show it already)
        final Logger rootLogger = ESLoggerFactory.getRootLogger();
        final Appender maybeConsoleAppender = Loggers.findAppender(rootLogger, ConsoleAppender.class);
        if (foreground && maybeConsoleAppender != null) {
            Loggers.removeAppender(rootLogger, maybeConsoleAppender);
        }
        Logger logger = Loggers.getLogger(Bootstrap.class);
        if (INSTANCE.node != null) {
            logger = Loggers.getLogger(Bootstrap.class, Node.NODE_NAME_SETTING.get(INSTANCE.node.settings()));
        }
        // HACK, it sucks to do this, but we will run users out of disk space otherwise
        if (e instanceof CreationException) {
            // guice: log the shortened exc to the log file
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            PrintStream ps = null;
            try {
                ps = new PrintStream(os, false, "UTF-8");
            } catch (UnsupportedEncodingException uee) {
                assert false;
                e.addSuppressed(uee);
            }
            new StartupException(e).printStackTrace(ps);
            ps.flush();
            try {
                logger.error("Guice Exception: {}", os.toString("UTF-8"));
            } catch (UnsupportedEncodingException uee) {
                assert false;
                e.addSuppressed(uee);
            }
        } else if (e instanceof NodeValidationException) {
            logger.error("node validation exception\n{}", e.getMessage());
        } else {
            // full exception
            logger.error("Exception", e);
        }
        // re-enable it if appropriate, so they can see any logging during the shutdown process
        if (foreground && maybeConsoleAppender != null) {
            Loggers.addAppender(rootLogger, maybeConsoleAppender);
        }
        throw e;
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) PrintStream(java.io.PrintStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CreationException(org.elasticsearch.common.inject.CreationException) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(org.apache.logging.log4j.Logger) NodeValidationException(org.elasticsearch.node.NodeValidationException) SecureSettings(org.elasticsearch.common.settings.SecureSettings) Environment(org.elasticsearch.env.Environment)

Example 65 with Environment

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

the class LuceneQueryBuilderTest method createAnalysisService.

private AnalysisService createAnalysisService(Settings indexSettings, Index index) {
    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))).createInjector();
    Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, indexSettings), new IndexNameModule(index), new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector);
    return injector.getInstance(AnalysisService.class);
}
Also used : EnvironmentModule(org.elasticsearch.env.EnvironmentModule) IndexNameModule(org.elasticsearch.index.IndexNameModule) IndicesAnalysisService(org.elasticsearch.indices.analysis.IndicesAnalysisService) Injector(org.elasticsearch.common.inject.Injector) IndexSettingsModule(org.elasticsearch.index.settings.IndexSettingsModule) SettingsModule(org.elasticsearch.common.settings.SettingsModule) Environment(org.elasticsearch.env.Environment) ModulesBuilder(org.elasticsearch.common.inject.ModulesBuilder) IndexSettingsModule(org.elasticsearch.index.settings.IndexSettingsModule) AnalysisModule(org.elasticsearch.index.analysis.AnalysisModule)

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