Search in sources :

Example 11 with NodeValidationException

use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.

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(emptyContext, true, Collections.singletonList(check)));
    assertThat(e.getMessage(), containsString("max number of threads"));
    maxNumberOfThreads.set(randomIntBetween(limit + 1, Integer.MAX_VALUE));
    BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
    // nothing should happen if current max number of threads is
    // not available
    maxNumberOfThreads.set(-1);
    BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) NodeValidationException(org.opensearch.node.NodeValidationException)

Example 12 with NodeValidationException

use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.

the class BootstrapChecksTests method testHeapSizeCheck.

public void testHeapSizeCheck() throws NodeValidationException {
    final int initial = randomIntBetween(0, Integer.MAX_VALUE - 1);
    final int max = randomIntBetween(initial + 1, Integer.MAX_VALUE);
    final AtomicLong initialHeapSize = new AtomicLong(initial);
    final AtomicLong maxHeapSize = new AtomicLong(max);
    final boolean isMemoryLocked = randomBoolean();
    final BootstrapChecks.HeapSizeCheck check = new BootstrapChecks.HeapSizeCheck() {

        @Override
        long getInitialHeapSize() {
            return initialHeapSize.get();
        }

        @Override
        long getMaxHeapSize() {
            return maxHeapSize.get();
        }

        @Override
        boolean isMemoryLocked() {
            return isMemoryLocked;
        }
    };
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(emptyContext, true, Collections.singletonList(check)));
    assertThat(e.getMessage(), containsString("initial heap size [" + initialHeapSize.get() + "] " + "not equal to maximum heap size [" + maxHeapSize.get() + "]"));
    final String memoryLockingMessage = "and prevents memory locking from locking the entire heap";
    final Matcher<String> memoryLockingMatcher;
    if (isMemoryLocked) {
        memoryLockingMatcher = containsString(memoryLockingMessage);
    } else {
        memoryLockingMatcher = not(containsString(memoryLockingMessage));
    }
    assertThat(e.getMessage(), memoryLockingMatcher);
    initialHeapSize.set(maxHeapSize.get());
    BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
    // heap size is not available
    if (randomBoolean()) {
        initialHeapSize.set(0);
    } else {
        maxHeapSize.set(0);
    }
    BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) NodeValidationException(org.opensearch.node.NodeValidationException) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 13 with NodeValidationException

use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.

the class BootstrapChecksTests method testEarlyAccessCheck.

public void testEarlyAccessCheck() throws NodeValidationException {
    final AtomicReference<String> javaVersion = new AtomicReference<>(randomFrom("1.8.0_152-ea", "9-ea"));
    final BootstrapChecks.EarlyAccessCheck eaCheck = new BootstrapChecks.EarlyAccessCheck() {

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

        @Override
        String javaVersion() {
            return javaVersion.get();
        }
    };
    final List<BootstrapCheck> checks = Collections.singletonList(eaCheck);
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> {
        BootstrapChecks.check(emptyContext, true, checks);
    });
    assertThat(e.getMessage(), containsString("Java version [" + javaVersion.get() + "] is an early-access build, only use release builds"));
    // if not on an early-access build, nothing should happen
    javaVersion.set(randomFrom("1.8.0_152", "9"));
    BootstrapChecks.check(emptyContext, true, checks);
}
Also used : NodeValidationException(org.opensearch.node.NodeValidationException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 14 with NodeValidationException

use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.

the class OpenSearch 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)) {
        final String versionOutput = String.format(Locale.ROOT, "Version: %s, Build: %s/%s/%s, JVM: %s", Build.CURRENT.getQualifiedVersion(), Build.CURRENT.type().displayName(), Build.CURRENT.hash(), Build.CURRENT.date(), JvmInfo.jvmInfo().version());
        terminal.println(versionOutput);
        return;
    }
    final boolean daemonize = options.has(daemonizeOption);
    final Path pidFile = pidfileOption.value(options);
    final boolean quiet = options.has(quietOption);
    // a misconfigured java.io.tmpdir can cause hard-to-diagnose problems later, so reject it immediately
    try {
        env.validateTmpFile();
    } catch (IOException e) {
        throw new UserException(ExitCodes.CONFIG, e.getMessage());
    }
    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.opensearch.node.NodeValidationException) UserException(org.opensearch.cli.UserException) IOException(java.io.IOException)

Example 15 with NodeValidationException

use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.

the class BootstrapChecksTests method testAlwaysEnforcedChecks.

public void testAlwaysEnforcedChecks() {
    final BootstrapCheck check = new BootstrapCheck() {

        @Override
        public BootstrapCheckResult check(BootstrapContext context) {
            return BootstrapCheckResult.failure("error");
        }

        @Override
        public boolean alwaysEnforce() {
            return true;
        }
    };
    final NodeValidationException alwaysEnforced = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(emptyContext, randomBoolean(), Collections.singletonList(check)));
    assertThat(alwaysEnforced, hasToString(containsString("error")));
}
Also used : NodeValidationException(org.opensearch.node.NodeValidationException)

Aggregations

NodeValidationException (org.opensearch.node.NodeValidationException)22 Matchers.hasToString (org.hamcrest.Matchers.hasToString)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Logger (org.apache.logging.log4j.Logger)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Settings (org.opensearch.common.settings.Settings)3 Path (java.nio.file.Path)2 DeprecationLogger (org.opensearch.common.logging.DeprecationLogger)2 SecureSettings (org.opensearch.common.settings.SecureSettings)2 BoundTransportAddress (org.opensearch.common.transport.BoundTransportAddress)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1