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));
}
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));
}
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);
}
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());
}
}
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")));
}
Aggregations