Search in sources :

Example 1 with NodeValidationException

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

the class Bootstrap method setup.

private void setup(boolean addShutdownHook, Environment environment) throws BootstrapException {
    Settings settings = environment.settings();
    try {
        spawner.spawnNativePluginControllers(environment);
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                try {
                    spawner.close();
                } catch (IOException e) {
                    throw new ElasticsearchException("Failed to destroy spawned controllers", e);
                }
            }
        });
    } catch (IOException e) {
        throw new BootstrapException(e);
    }
    initializeNatives(environment.tmpFile(), BootstrapSettings.MEMORY_LOCK_SETTING.get(settings), BootstrapSettings.SYSTEM_CALL_FILTER_SETTING.get(settings), BootstrapSettings.CTRLHANDLER_SETTING.get(settings));
    // initialize probes before the security manager is installed
    initializeProbes();
    if (addShutdownHook) {
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                try {
                    IOUtils.close(node);
                    LoggerContext context = (LoggerContext) LogManager.getContext(false);
                    Configurator.shutdown(context);
                } catch (IOException ex) {
                    throw new ElasticsearchException("failed to stop node", ex);
                }
            }
        });
    }
    try {
        // look for jar hell
        JarHell.checkJarHell();
    } catch (IOException | URISyntaxException e) {
        throw new BootstrapException(e);
    }
    // Log ifconfig output before SecurityManager is installed
    IfConfig.logIfNecessary();
    // install SM after natives, shutdown hooks, etc.
    try {
        Security.configure(environment, BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING.get(settings));
    } catch (IOException | NoSuchAlgorithmException e) {
        throw new BootstrapException(e);
    }
    node = new Node(environment) {

        @Override
        protected void validateNodeBeforeAcceptingRequests(final Settings settings, final BoundTransportAddress boundTransportAddress, List<BootstrapCheck> checks) throws NodeValidationException {
            BootstrapChecks.check(settings, boundTransportAddress, checks);
        }
    };
}
Also used : Node(org.elasticsearch.node.Node) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LoggerContext(org.apache.logging.log4j.core.LoggerContext) NodeValidationException(org.elasticsearch.node.NodeValidationException) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) Settings(org.elasticsearch.common.settings.Settings) SecureSettings(org.elasticsearch.common.settings.SecureSettings)

Example 2 with NodeValidationException

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

the class BootstrapChecks method check.

/**
     * Executes the provided checks and fails the node if {@code enforceLimits} is {@code true}, otherwise logs warnings. If the system
     * property {@code es.enforce.bootstrap.checks }is set to {@code true} then the bootstrap checks will be enforced regardless of whether
     * or not the transport protocol is bound to a non-loopback interface.
     *
     * @param enforceLimits {@code true} if the checks should be enforced or otherwise warned
     * @param checks        the checks to execute
     * @param logger        the logger to
     */
static void check(final boolean enforceLimits, final List<BootstrapCheck> checks, final Logger logger) throws NodeValidationException {
    final List<String> errors = new ArrayList<>();
    final List<String> ignoredErrors = new ArrayList<>();
    final String esEnforceBootstrapChecks = System.getProperty(ES_ENFORCE_BOOTSTRAP_CHECKS);
    final boolean enforceBootstrapChecks;
    if (esEnforceBootstrapChecks == null) {
        enforceBootstrapChecks = false;
    } else if (Boolean.TRUE.toString().equals(esEnforceBootstrapChecks)) {
        enforceBootstrapChecks = true;
    } else {
        final String message = String.format(Locale.ROOT, "[%s] must be [true] but was [%s]", ES_ENFORCE_BOOTSTRAP_CHECKS, esEnforceBootstrapChecks);
        throw new IllegalArgumentException(message);
    }
    if (enforceLimits) {
        logger.info("bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks");
    } else if (enforceBootstrapChecks) {
        logger.info("explicitly enforcing bootstrap checks");
    }
    for (final BootstrapCheck check : checks) {
        if (check.check()) {
            if (!(enforceLimits || enforceBootstrapChecks) && !check.alwaysEnforce()) {
                ignoredErrors.add(check.errorMessage());
            } else {
                errors.add(check.errorMessage());
            }
        }
    }
    if (!ignoredErrors.isEmpty()) {
        ignoredErrors.forEach(error -> log(logger, error));
    }
    if (!errors.isEmpty()) {
        final List<String> messages = new ArrayList<>(1 + errors.size());
        messages.add("bootstrap checks failed");
        messages.addAll(errors);
        final NodeValidationException ne = new NodeValidationException(String.join("\n", messages));
        errors.stream().map(IllegalStateException::new).forEach(ne::addSuppressed);
        throw ne;
    }
}
Also used : NodeValidationException(org.elasticsearch.node.NodeValidationException) ArrayList(java.util.ArrayList)

Example 3 with NodeValidationException

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

the class BootstrapChecksTests method testMaxMapCountCheck.

public void testMaxMapCountCheck() throws NodeValidationException {
    final int limit = 1 << 18;
    final AtomicLong maxMapCount = new AtomicLong(randomIntBetween(1, limit - 1));
    final BootstrapChecks.MaxMapCountCheck check = new BootstrapChecks.MaxMapCountCheck() {

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

Example 4 with NodeValidationException

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

the class BootstrapChecksTests method runMightForkTest.

private void runMightForkTest(final BootstrapChecks.MightForkCheck check, final AtomicBoolean isSystemCallFilterInstalled, final Runnable disableMightFork, final Runnable enableMightFork, final Consumer<NodeValidationException> consumer) throws NodeValidationException {
    final String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();
    // if system call filter is disabled, nothing should happen
    isSystemCallFilterInstalled.set(false);
    if (randomBoolean()) {
        disableMightFork.run();
    } else {
        enableMightFork.run();
    }
    BootstrapChecks.check(true, Collections.singletonList(check), methodName);
    // if system call filter is enabled, but we will not fork, nothing should
    // happen
    isSystemCallFilterInstalled.set(true);
    disableMightFork.run();
    BootstrapChecks.check(true, Collections.singletonList(check), methodName);
    // if system call filter is enabled, and we might fork, the check should be enforced, regardless of bootstrap checks being enabled
    // or not
    isSystemCallFilterInstalled.set(true);
    enableMightFork.run();
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(randomBoolean(), Collections.singletonList(check), methodName));
    consumer.accept(e);
}
Also used : NodeValidationException(org.elasticsearch.node.NodeValidationException) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 5 with NodeValidationException

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

the class BootstrapChecksTests method testUseSerialGCCheck.

public void testUseSerialGCCheck() throws NodeValidationException {
    final AtomicReference<String> useSerialGC = new AtomicReference<>("true");
    final BootstrapCheck check = new BootstrapChecks.UseSerialGCCheck() {

        @Override
        String getUseSerialGC() {
            return useSerialGC.get();
        }
    };
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(true, Collections.singletonList(check), "testUseSerialGCCheck"));
    assertThat(e.getMessage(), containsString("JVM is using the serial collector but should not be for the best performance; " + "" + "either it's the default for the VM [" + JvmInfo.jvmInfo().getVmName() + "] or -XX:+UseSerialGC was explicitly specified"));
    useSerialGC.set("false");
    BootstrapChecks.check(true, Collections.singletonList(check), "testUseSerialGCCheck");
}
Also used : 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)26 Settings (org.elasticsearch.common.settings.Settings)6 Matchers.hasToString (org.hamcrest.Matchers.hasToString)6 IOException (java.io.IOException)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Logger (org.apache.logging.log4j.Logger)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Node (org.elasticsearch.node.Node)3 BootstrapException (io.crate.bootstrap.BootstrapException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 URISyntaxException (java.net.URISyntaxException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Appender (org.apache.logging.log4j.core.Appender)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2