Search in sources :

Example 11 with NodeValidationException

use of org.elasticsearch.node.NodeValidationException in project metron by apache.

the class ElasticSearchComponent method start.

@Override
public void start() throws UnableToStartException {
    File logDir = new File(indexDir, "/logs");
    File dataDir = new File(indexDir, "/data");
    try {
        cleanDir(logDir);
        cleanDir(dataDir);
    } catch (IOException e) {
        throw new UnableToStartException("Unable to clean log or data directories", e);
    }
    Settings.Builder settingsBuilder = Settings.builder().put("cluster.name", "metron").put("path.logs", logDir.getAbsolutePath()).put("path.data", dataDir.getAbsolutePath()).put("path.home", indexDir.getAbsoluteFile()).put("transport.type", "netty4").put("http.enabled", "false");
    if (extraElasticSearchSettings != null) {
        settingsBuilder = settingsBuilder.put(extraElasticSearchSettings);
    }
    node = new TestNode(settingsBuilder.build(), asList(Netty4Plugin.class));
    client = node.client();
    try {
        node.start();
    } catch (NodeValidationException e) {
        throw new UnableToStartException("Error starting ES node.", e);
    }
    waitForCluster(client, ClusterHealthStatus.YELLOW, STARTUP_TIMEOUT);
    for (Mapping m : Optional.ofNullable(mappings).orElse(new ArrayList<>())) {
        client.admin().indices().prepareCreate(m.index).addMapping(m.docType, m.mapping).get();
    }
}
Also used : NodeValidationException(org.elasticsearch.node.NodeValidationException) UnableToStartException(org.apache.metron.integration.UnableToStartException) IOException(java.io.IOException) File(java.io.File) Settings(org.elasticsearch.common.settings.Settings)

Example 12 with NodeValidationException

use of org.elasticsearch.node.NodeValidationException 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 13 with NodeValidationException

use of org.elasticsearch.node.NodeValidationException in project elasticsearch by elastic.

the class Elasticsearch method execute.

@Override
protected void execute(Terminal terminal, OptionSet options, Environment env) throws UserException {
    if (options.nonOptionArguments().isEmpty() == false) {
        throw new UserException(ExitCodes.USAGE, "Positional arguments not allowed, found " + options.nonOptionArguments());
    }
    if (options.has(versionOption)) {
        if (options.has(daemonizeOption) || options.has(pidfileOption)) {
            throw new UserException(ExitCodes.USAGE, "Elasticsearch version option is mutually exclusive with any other option");
        }
        terminal.println("Version: " + org.elasticsearch.Version.CURRENT + ", Build: " + Build.CURRENT.shortHash() + "/" + Build.CURRENT.date() + ", JVM: " + JvmInfo.jvmInfo().version());
        return;
    }
    final boolean daemonize = options.has(daemonizeOption);
    final Path pidFile = pidfileOption.value(options);
    final boolean quiet = options.has(quietOption);
    try {
        init(daemonize, pidFile, quiet, env);
    } catch (NodeValidationException e) {
        throw new UserException(ExitCodes.CONFIG, e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) NodeValidationException(org.elasticsearch.node.NodeValidationException) UserException(org.elasticsearch.cli.UserException)

Example 14 with NodeValidationException

use of org.elasticsearch.node.NodeValidationException in project elasticsearch by elastic.

the class BootstrapChecksTests method testMaxNumberOfThreadsCheck.

public void testMaxNumberOfThreadsCheck() throws NodeValidationException {
    final int limit = 1 << 11;
    final AtomicLong maxNumberOfThreads = new AtomicLong(randomIntBetween(1, limit - 1));
    final BootstrapChecks.MaxNumberOfThreadsCheck check = new BootstrapChecks.MaxNumberOfThreadsCheck() {

        @Override
        long getMaxNumberOfThreads() {
            return maxNumberOfThreads.get();
        }
    };
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(true, Collections.singletonList(check), "testMaxNumberOfThreadsCheck"));
    assertThat(e.getMessage(), containsString("max number of threads"));
    maxNumberOfThreads.set(randomIntBetween(limit + 1, Integer.MAX_VALUE));
    BootstrapChecks.check(true, Collections.singletonList(check), "testMaxNumberOfThreadsCheck");
    // nothing should happen if current max number of threads is
    // not available
    maxNumberOfThreads.set(-1);
    BootstrapChecks.check(true, Collections.singletonList(check), "testMaxNumberOfThreadsCheck");
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) NodeValidationException(org.elasticsearch.node.NodeValidationException)

Example 15 with NodeValidationException

use of org.elasticsearch.node.NodeValidationException in project elasticsearch by elastic.

the class BootstrapChecksTests method testG1GCCheck.

public void testG1GCCheck() throws NodeValidationException {
    final AtomicBoolean isG1GCEnabled = new AtomicBoolean(true);
    final AtomicBoolean isJava8 = new AtomicBoolean(true);
    final AtomicReference<String> jvmVersion = new AtomicReference<>(String.format(Locale.ROOT, "25.%d-b%d", randomIntBetween(0, 39), randomIntBetween(1, 128)));
    final BootstrapChecks.G1GCCheck oracleCheck = new BootstrapChecks.G1GCCheck() {

        @Override
        String jvmVendor() {
            return "Oracle Corporation";
        }

        @Override
        boolean isG1GCEnabled() {
            return isG1GCEnabled.get();
        }

        @Override
        String jvmVersion() {
            return jvmVersion.get();
        }

        @Override
        boolean isJava8() {
            return isJava8.get();
        }
    };
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(true, Collections.singletonList(oracleCheck), "testG1GCCheck"));
    assertThat(e.getMessage(), containsString("JVM version [" + jvmVersion.get() + "] can cause data corruption when used with G1GC; upgrade to at least Java 8u40"));
    // if G1GC is disabled, nothing should happen
    isG1GCEnabled.set(false);
    BootstrapChecks.check(true, Collections.singletonList(oracleCheck), "testG1GCCheck");
    // if on or after update 40, nothing should happen independent of whether or not G1GC is enabled
    isG1GCEnabled.set(randomBoolean());
    jvmVersion.set(String.format(Locale.ROOT, "25.%d-b%d", randomIntBetween(40, 112), randomIntBetween(1, 128)));
    BootstrapChecks.check(true, Collections.singletonList(oracleCheck), "testG1GCCheck");
    final BootstrapChecks.G1GCCheck nonOracleCheck = new BootstrapChecks.G1GCCheck() {

        @Override
        String jvmVendor() {
            return randomAsciiOfLength(8);
        }
    };
    // if not on an Oracle JVM, nothing should happen
    BootstrapChecks.check(true, Collections.singletonList(nonOracleCheck), "testG1GCCheck");
    final BootstrapChecks.G1GCCheck nonJava8Check = new BootstrapChecks.G1GCCheck() {

        @Override
        boolean isJava8() {
            return false;
        }
    };
    // if not Java 8, nothing should happen
    BootstrapChecks.check(true, Collections.singletonList(nonJava8Check), "testG1GCCheck");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodeValidationException(org.elasticsearch.node.NodeValidationException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Aggregations

NodeValidationException (org.elasticsearch.node.NodeValidationException)20 Matchers.hasToString (org.hamcrest.Matchers.hasToString)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 IOException (java.io.IOException)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Settings (org.elasticsearch.common.settings.Settings)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Logger (org.apache.logging.log4j.Logger)2 SecureSettings (org.elasticsearch.common.settings.SecureSettings)2 Node (org.elasticsearch.node.Node)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Appender (org.apache.logging.log4j.core.Appender)1