[Rename] Refactor ES and Elasticsearch classes in server module bootstrap package (#197)

This commit refactors the heavily used ESPolicy, Elasticsearch (main class), and Elasticsearch 
prefixed test classes used in the bootstrap package under the server module. Refactoring the 
namespace will come in a separate commit.

Signed-off-by: Nicholas Knize <nknize@amazon.com>
This commit is contained in:
Nick Knize 2021-03-12 11:53:55 -06:00
parent 8a6b294e2e
commit fafa4fc941
15 changed files with 51 additions and 51 deletions

View File

@ -26,7 +26,7 @@ import org.elasticsearch.common.xcontent.XContentType;
import java.io.IOException;
import java.util.Collections;
public class ElasticsearchExceptionTests extends AbstractResponseTestCase<OpenSearchException,
public class OpenSearchExceptionTests extends AbstractResponseTestCase<OpenSearchException,
org.elasticsearch.client.tasks.ElasticsearchException> {
@Override

View File

@ -207,7 +207,7 @@ if not "%SERVICE_USERNAME%" == "" (
set SERVICE_PARAMS=%SERVICE_PARAMS% --ServiceUser "%SERVICE_USERNAME%" --ServicePassword "%SERVICE_PASSWORD%"
)
)
"%EXECUTABLE%" //IS//%SERVICE_ID% --Startup %ES_START_TYPE% --StopTimeout %ES_STOP_TIMEOUT% --StartClass org.elasticsearch.bootstrap.Elasticsearch --StartMethod main ++StartParams --quiet --StopClass org.elasticsearch.bootstrap.Elasticsearch --StopMethod close --Classpath "%ES_CLASSPATH%" --JvmMs %JVM_MS% --JvmMx %JVM_MX% --JvmSs %JVM_SS% --JvmOptions %OTHER_JAVA_OPTS% ++JvmOptions %ES_PARAMS% %LOG_OPTS% --PidFile "%SERVICE_ID%.pid" --DisplayName "%SERVICE_DISPLAY_NAME%" --Description "%SERVICE_DESCRIPTION%" --Jvm "%JAVA_HOME%%JVM_DLL%" --StartMode jvm --StopMode jvm --StartPath "%ES_HOME%" %SERVICE_PARAMS% ++Environment HOSTNAME="%%COMPUTERNAME%%"
"%EXECUTABLE%" //IS//%SERVICE_ID% --Startup %ES_START_TYPE% --StopTimeout %ES_STOP_TIMEOUT% --StartClass org.elasticsearch.bootstrap.OpenSearch --StartMethod main ++StartParams --quiet --StopClass org.elasticsearch.bootstrap.OpenSearch --StopMethod close --Classpath "%ES_CLASSPATH%" --JvmMs %JVM_MS% --JvmMx %JVM_MX% --JvmSs %JVM_SS% --JvmOptions %OTHER_JAVA_OPTS% ++JvmOptions %ES_PARAMS% %LOG_OPTS% --PidFile "%SERVICE_ID%.pid" --DisplayName "%SERVICE_DISPLAY_NAME%" --Description "%SERVICE_DESCRIPTION%" --Jvm "%JAVA_HOME%%JVM_DLL%" --StartMode jvm --StopMode jvm --StartPath "%ES_HOME%" %SERVICE_PARAMS% ++Environment HOSTNAME="%%COMPUTERNAME%%"
if not errorlevel 1 goto installed
echo Failed installing '%SERVICE_ID%' service

View File

@ -101,7 +101,7 @@ ECHO.!KEYSTORE_PASSWORD!| %JAVA% %ES_JAVA_OPTS% -Delasticsearch ^
-Des.path.home="%ES_HOME%" -Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-Des.bundled_jdk="%ES_BUNDLED_JDK%" ^
-cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams!
-cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.OpenSearch" !newparams!
endlocal
endlocal

View File

@ -37,7 +37,7 @@ import java.util.Collections;
* Unit tests for ESPolicy: these cannot run with security manager,
* we don't allow messing with the policy
*/
public class ESPolicyUnitTests extends OpenSearchTestCase {
public class OpenSearchPolicyUnitTests extends OpenSearchTestCase {
/**
* Test policy with null codesource.
* <p>
@ -78,7 +78,7 @@ public class ESPolicyUnitTests extends OpenSearchTestCase {
final ESPolicy policy = new ESPolicy(Collections.emptyMap(), noPermissions, Collections.emptyMap(), true, new Permissions());
assertFalse(
policy.implies(
new ProtectionDomain(ESPolicyUnitTests.class.getProtectionDomain().getCodeSource(), noPermissions),
new ProtectionDomain(OpenSearchPolicyUnitTests.class.getProtectionDomain().getCodeSource(), noPermissions),
new SocketPermission("localhost:" + randomFrom(0, randomIntBetween(49152, 65535)), "listen")));
}

View File

@ -91,7 +91,7 @@ final class Bootstrap {
// bail out
}
}
}, "elasticsearch[keepAlive/" + Version.CURRENT + "]");
}, "opensearch[keepAlive/" + Version.CURRENT + "]");
keepAliveThread.setDaemon(false);
// keep this thread alive (non daemon thread) until we shutdown
Runtime.getRuntime().addShutdownHook(new Thread() {
@ -108,7 +108,7 @@ final class Bootstrap {
// check if the user is running as root, and bail
if (Natives.definitelyRunningAsRoot()) {
throw new RuntimeException("can not run elasticsearch as root");
throw new RuntimeException("can not run opensearch as root");
}
// enable system call filter
@ -333,7 +333,7 @@ final class Bootstrap {
}
/**
* This method is invoked by {@link Elasticsearch#main(String[])} to startup elasticsearch.
* This method is invoked by {@link OpenSearch#main(String[])} to startup opensearch.
*/
static void init(
final boolean foreground,
@ -358,7 +358,7 @@ final class Bootstrap {
if (JavaVersion.current().compareTo(JavaVersion.parse("11")) < 0) {
final String message = String.format(
Locale.ROOT,
"future versions of Elasticsearch will require Java 11; " +
"future versions of OpenSearch will require Java 11; " +
"your Java version from [%s] does not meet this requirement",
System.getProperty("java.home"));
DeprecationLogger.getLogger(Bootstrap.class).deprecate("java_version_11_required", message);
@ -388,7 +388,7 @@ final class Bootstrap {
// 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());
Thread.setDefaultUncaughtExceptionHandler(new OpenSearchUncaughtExceptionHandler());
INSTANCE.setup(true, environment);
@ -402,7 +402,7 @@ final class Bootstrap {
INSTANCE.start();
// We don't close stderr if `--quiet` is passed, because that
// hides fatal startup errors. For example, if Elasticsearch is
// hides fatal startup errors. For example, if OpenSearch is
// running via systemd, the init script only specifies
// `--quiet`, not `-d`, so we want users to be able to see
// startup errors via journalctl.
@ -463,7 +463,7 @@ final class Bootstrap {
private static void checkLucene() {
if (Version.CURRENT.luceneVersion.equals(org.apache.lucene.util.Version.LATEST) == false) {
throw new AssertionError("Lucene version mismatch this version of Elasticsearch requires lucene version ["
throw new AssertionError("Lucene version mismatch this version of OpenSearch requires lucene version ["
+ Version.CURRENT.luceneVersion + "] but the current lucene version is [" + org.apache.lucene.util.Version.LATEST + "]");
}
}

View File

@ -386,7 +386,7 @@ final class BootstrapChecks {
}
/**
* Bootstrap check that the maximum file size is unlimited (otherwise Elasticsearch could run in to an I/O exception writing files).
* Bootstrap check that the maximum file size is unlimited (otherwise OpenSearch could run in to an I/O exception writing files).
*/
static class MaxFileSizeCheck implements BootstrapCheck {
@ -507,7 +507,7 @@ final class BootstrapChecks {
/**
* Checks if the serial collector is in use. This collector is single-threaded and devastating
* for performance and should not be used for a server application like Elasticsearch.
* for performance and should not be used for a server application like OpenSearch.
*/
static class UseSerialGCCheck implements BootstrapCheck {

View File

@ -51,7 +51,7 @@ class JNANatives {
// otherwise they are only inherited for new threads (ES app threads)
static boolean LOCAL_SYSTEM_CALL_FILTER_ALL = false;
// set to the maximum number of threads that can be created for
// the user ID that owns the running Elasticsearch process
// the user ID that owns the running OpenSearch process
static long MAX_NUMBER_OF_THREADS = -1;
static long MAX_SIZE_VIRTUAL_MEMORY = Long.MIN_VALUE;

View File

@ -30,8 +30,8 @@ import org.opensearch.cli.Terminal;
import org.opensearch.cli.UserException;
import org.elasticsearch.common.logging.LogConfigurator;
import org.elasticsearch.env.Environment;
import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.node.NodeValidationException;
import org.opensearch.monitor.jvm.JvmInfo;
import org.opensearch.node.NodeValidationException;
import java.io.IOException;
import java.nio.file.Path;
@ -41,9 +41,9 @@ import java.util.Arrays;
import java.util.Locale;
/**
* This class starts elasticsearch.
* This class starts opensearch.
*/
class Elasticsearch extends EnvironmentAwareCommand {
class OpenSearch extends EnvironmentAwareCommand {
private final OptionSpecBuilder versionOption;
private final OptionSpecBuilder daemonizeOption;
@ -51,12 +51,12 @@ class Elasticsearch extends EnvironmentAwareCommand {
private final OptionSpecBuilder quietOption;
// visible for testing
Elasticsearch() {
super("Starts Elasticsearch", () -> {}); // we configure logging later so we override the base class from configuring logging
OpenSearch() {
super("Starts OpenSearch", () -> {}); // we configure logging later so we override the base class from configuring logging
versionOption = parser.acceptsAll(Arrays.asList("V", "version"),
"Prints Elasticsearch version information and exits");
"Prints OpenSearch version information and exits");
daemonizeOption = parser.acceptsAll(Arrays.asList("d", "daemonize"),
"Starts Elasticsearch in the background")
"Starts OpenSearch in the background")
.availableUnless(versionOption);
pidfileOption = parser.acceptsAll(Arrays.asList("p", "pidfile"),
"Creates a pid file in the specified path on start")
@ -70,7 +70,7 @@ class Elasticsearch extends EnvironmentAwareCommand {
}
/**
* Main entry point for starting elasticsearch
* Main entry point for starting opensearch
*/
public static void main(final String[] args) throws Exception {
overrideDnsCachePolicyProperties();
@ -88,18 +88,18 @@ class Elasticsearch extends EnvironmentAwareCommand {
});
LogConfigurator.registerErrorListener();
final Elasticsearch elasticsearch = new Elasticsearch();
int status = main(args, elasticsearch, Terminal.DEFAULT);
final OpenSearch opensearch = new OpenSearch();
int status = main(args, opensearch, Terminal.DEFAULT);
if (status != ExitCodes.OK) {
final String basePath = System.getProperty("es.logs.base_path");
final String basePath = System.getProperty("opensearch.logs.base_path");
// It's possible to fail before logging has been configured, in which case there's no point
// suggesting that the user look in the log file.
if (basePath != null) {
Terminal.DEFAULT.errorPrintln(
"ERROR: Elasticsearch did not exit normally - check the logs at "
"ERROR: OpenSearch did not exit normally - check the logs at "
+ basePath
+ System.getProperty("file.separator")
+ System.getProperty("es.logs.cluster_name") + ".log"
+ System.getProperty("opensearch.logs.cluster_name") + ".log"
);
}
exit(status);
@ -108,7 +108,7 @@ class Elasticsearch extends EnvironmentAwareCommand {
private static void overrideDnsCachePolicyProperties() {
for (final String property : new String[] {"networkaddress.cache.ttl", "networkaddress.cache.negative.ttl" }) {
final String overrideProperty = "es." + property;
final String overrideProperty = "opensearch." + property;
final String overrideValue = System.getProperty(overrideProperty);
if (overrideValue != null) {
try {
@ -122,8 +122,8 @@ class Elasticsearch extends EnvironmentAwareCommand {
}
}
static int main(final String[] args, final Elasticsearch elasticsearch, final Terminal terminal) throws Exception {
return elasticsearch.main(args, terminal);
static int main(final String[] args, final OpenSearch opensearch, final Terminal terminal) throws Exception {
return opensearch.main(args, terminal);
}
@Override
@ -181,7 +181,7 @@ class Elasticsearch extends EnvironmentAwareCommand {
* http://commons.apache.org/proper/commons-daemon/procrun.html
*
* NOTE: If this method is renamed and/or moved, make sure to
* update elasticsearch-service.bat!
* update opensearch-service.bat!
*/
static void close(String[] args) throws IOException {
Bootstrap.stop();

View File

@ -36,7 +36,7 @@ import java.util.Map;
import java.util.function.Predicate;
/** custom policy for union of static and dynamic permissions */
final class ESPolicy extends Policy {
final class OpenSearchPolicy extends Policy {
/** template policy file, the one used in tests */
static final String POLICY_RESOURCE = "security.policy";
@ -50,8 +50,8 @@ final class ESPolicy extends Policy {
final PermissionCollection dataPathPermission;
final Map<String,Policy> plugins;
ESPolicy(Map<String, URL> codebases, PermissionCollection dynamic, Map<String,Policy> plugins, boolean filterBadDefaults,
PermissionCollection dataPathPermission) {
OpenSearchPolicy(Map<String, URL> codebases, PermissionCollection dynamic, Map<String,Policy> plugins, boolean filterBadDefaults,
PermissionCollection dataPathPermission) {
this.template = Security.readPolicy(getClass().getResource(POLICY_RESOURCE), codebases);
this.dataPathPermission = dataPathPermission;
this.untrusted = Security.readPolicy(getClass().getResource(UNTRUSTED_RESOURCE), Collections.emptyMap());
@ -102,7 +102,7 @@ final class ESPolicy extends Policy {
}
// The FilePermission to check access to the path.data is the hottest permission check in
// Elasticsearch, so we check it first.
// OpenSearch, so we check it first.
if (permission instanceof FilePermission && dataPathPermission.implies(permission)) {
return true;
}

View File

@ -28,8 +28,8 @@ import java.io.IOError;
import java.security.AccessController;
import java.security.PrivilegedAction;
class ElasticsearchUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
private static final Logger logger = LogManager.getLogger(ElasticsearchUncaughtExceptionHandler.class);
class OpenSearchUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
private static final Logger logger = LogManager.getLogger(OpenSearchUncaughtExceptionHandler.class);
@Override
public void uncaughtException(Thread thread, Throwable t) {

View File

@ -118,14 +118,14 @@ final class Security {
// enable security policy: union of template and environment-based paths, and possibly plugin permissions
Map<String, URL> codebases = getCodebaseJarMap(JarHell.parseClassPath());
Policy.setPolicy(new ESPolicy(codebases, createPermissions(environment), getPluginPermissions(environment), filterBadDefaults,
Policy.setPolicy(new OpenSearchPolicy(codebases, createPermissions(environment), getPluginPermissions(environment), filterBadDefaults,
createRecursiveDataPathPermission(environment)));
// enable security manager
final String[] classesThatCanExit =
new String[]{
// SecureSM matches class names as regular expressions so we escape the $ that arises from the nested class name
ElasticsearchUncaughtExceptionHandler.PrivilegedHaltAction.class.getName().replace("$", "\\$"),
OpenSearchUncaughtExceptionHandler.PrivilegedHaltAction.class.getName().replace("$", "\\$"),
Command.class.getName()};
System.setSecurityManager(new SecureSM(classesThatCanExit));

View File

@ -48,7 +48,7 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
public class ElasticsearchNodeCommandTests extends ESTestCase {
public class OpenSearchNodeCommandTests extends ESTestCase {
public void testLoadStateWithoutMissingCustoms() throws IOException {
runLoadStateTest(false, false);

View File

@ -44,7 +44,7 @@ import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import static org.elasticsearch.ElasticsearchExceptionTests.assertDeepEquals;
import static org.opensearch.OpenSearchExceptionTests.assertDeepEquals;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;

View File

@ -139,22 +139,22 @@ public class BootstrapForTesting {
// read test-framework permissions
Map<String, URL> codebases = Security.getCodebaseJarMap(JarHell.parseClassPath());
// when testing server, the main elasticsearch code is not yet in a jar, so we need to manually add it
addClassCodebase(codebases,"elasticsearch", "org.elasticsearch.plugins.PluginsService");
// when testing server, the main opensearch code is not yet in a jar, so we need to manually add it
addClassCodebase(codebases,"opensearch", "org.elasticsearch.plugins.PluginsService");
if (System.getProperty("tests.gradle") == null) {
// intellij and eclipse don't package our internal libs, so we need to set the codebases for them manually
addClassCodebase(codebases,"plugin-classloader", "org.elasticsearch.plugins.ExtendedPluginsClassLoader");
addClassCodebase(codebases,"elasticsearch-nio", "org.elasticsearch.nio.ChannelFactory");
addClassCodebase(codebases, "elasticsearch-secure-sm", "org.elasticsearch.secure_sm.SecureSM");
addClassCodebase(codebases, "elasticsearch-rest-client", "org.elasticsearch.client.RestClient");
addClassCodebase(codebases,"opensearch-nio", "org.elasticsearch.nio.ChannelFactory");
addClassCodebase(codebases, "opensearch-secure-sm", "org.elasticsearch.secure_sm.SecureSM");
addClassCodebase(codebases, "opensearch-rest-client", "org.elasticsearch.client.RestClient");
}
final Policy testFramework = Security.readPolicy(Bootstrap.class.getResource("test-framework.policy"), codebases);
final Policy esPolicy = new ESPolicy(codebases, perms, getPluginPermissions(), true, new Permissions());
final Policy opensearchPolicy = new OpenSearchPolicy(codebases, perms, getPluginPermissions(), true, new Permissions());
Policy.setPolicy(new Policy() {
@Override
public boolean implies(ProtectionDomain domain, Permission permission) {
// implements union
return esPolicy.implies(domain, permission) || testFramework.implies(domain, permission);
return opensearchPolicy.implies(domain, permission) || testFramework.implies(domain, permission);
}
});
System.setSecurityManager(SecureSM.createTestSecureSM());

View File

@ -43,7 +43,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBloc
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
import static org.hamcrest.Matchers.containsString;
public class ElasticsearchAssertionsTests extends ESTestCase {
public class OpenSearchAssertionsTests extends ESTestCase {
public void testAssertXContentEquivalent() throws IOException {
try (XContentBuilder original = JsonXContent.contentBuilder()) {