[Rename] ElasticsearchNodeCommand class in server module (#175)

This commit refactors the ElasticsearchNodeCommand class located in the server
module to OpenSearchNodeCommand. References and usages throughout the rest of
the codebase are fully refactored.

Signed-off-by: Nicholas Knize <nknize@amazon.com>
This commit is contained in:
Nick Knize 2021-03-03 17:55:07 -06:00
parent 7788250e9e
commit bdc3158020
14 changed files with 42 additions and 42 deletions

View File

@ -42,7 +42,7 @@ public class RemoveCustomsCommandIT extends ESIntegTestCase {
Environment environment = TestEnvironment.newEnvironment(
Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
expectThrows(() -> removeCustoms(environment, true, new String[]{ "index-graveyard" }),
ElasticsearchNodeCommand.ABORTED_BY_USER_MSG);
OpenSearchNodeCommand.ABORTED_BY_USER_MSG);
}
public void testRemoveCustomsSuccessful() throws Exception {
@ -88,7 +88,7 @@ public class RemoveCustomsCommandIT extends ESIntegTestCase {
"found on this node"));
}
private MockTerminal executeCommand(ElasticsearchNodeCommand command, Environment environment, boolean abort, String... args)
private MockTerminal executeCommand(OpenSearchNodeCommand command, Environment environment, boolean abort, String... args)
throws Exception {
final MockTerminal terminal = new MockTerminal();
final OptionSet options = command.getParser().parse(args);
@ -105,7 +105,7 @@ public class RemoveCustomsCommandIT extends ESIntegTestCase {
try {
command.execute(terminal, options, environment);
} finally {
assertThat(terminal.getOutput(), containsString(ElasticsearchNodeCommand.STOP_WARNING_MSG));
assertThat(terminal.getOutput(), containsString(OpenSearchNodeCommand.STOP_WARNING_MSG));
}
return terminal;

View File

@ -48,7 +48,7 @@ public class RemoveSettingsCommandIT extends ESIntegTestCase {
Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
expectThrows(() -> removeSettings(environment, true,
new String[]{ DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.getKey() }),
ElasticsearchNodeCommand.ABORTED_BY_USER_MSG);
OpenSearchNodeCommand.ABORTED_BY_USER_MSG);
}
public void testRemoveSettingsSuccessful() throws Exception {
@ -98,7 +98,7 @@ public class RemoveSettingsCommandIT extends ESIntegTestCase {
"found on this node"));
}
private MockTerminal executeCommand(ElasticsearchNodeCommand command, Environment environment, boolean abort, String... args)
private MockTerminal executeCommand(OpenSearchNodeCommand command, Environment environment, boolean abort, String... args)
throws Exception {
final MockTerminal terminal = new MockTerminal();
final OptionSet options = command.getParser().parse(args);
@ -115,7 +115,7 @@ public class RemoveSettingsCommandIT extends ESIntegTestCase {
try {
command.execute(terminal, options, environment);
} finally {
assertThat(terminal.getOutput(), containsString(ElasticsearchNodeCommand.STOP_WARNING_MSG));
assertThat(terminal.getOutput(), containsString(OpenSearchNodeCommand.STOP_WARNING_MSG));
}
return terminal;

View File

@ -54,7 +54,7 @@ import static org.hamcrest.Matchers.notNullValue;
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false)
public class UnsafeBootstrapAndDetachCommandIT extends ESIntegTestCase {
private MockTerminal executeCommand(ElasticsearchNodeCommand command, Environment environment, int nodeOrdinal, boolean abort)
private MockTerminal executeCommand(OpenSearchNodeCommand command, Environment environment, int nodeOrdinal, boolean abort)
throws Exception {
final MockTerminal terminal = new MockTerminal();
final OptionSet options = command.getParser().parse("-ordinal", Integer.toString(nodeOrdinal));
@ -71,7 +71,7 @@ public class UnsafeBootstrapAndDetachCommandIT extends ESIntegTestCase {
try {
command.execute(terminal, options, environment);
} finally {
assertThat(terminal.getOutput(), containsString(ElasticsearchNodeCommand.STOP_WARNING_MSG));
assertThat(terminal.getOutput(), containsString(OpenSearchNodeCommand.STOP_WARNING_MSG));
}
return terminal;
@ -113,19 +113,19 @@ public class UnsafeBootstrapAndDetachCommandIT extends ESIntegTestCase {
public void testBootstrapNoDataFolder() {
final Environment environment = TestEnvironment.newEnvironment(internalCluster().getDefaultSettings());
expectThrows(() -> unsafeBootstrap(environment), ElasticsearchNodeCommand.NO_NODE_FOLDER_FOUND_MSG);
expectThrows(() -> unsafeBootstrap(environment), OpenSearchNodeCommand.NO_NODE_FOLDER_FOUND_MSG);
}
public void testDetachNoDataFolder() {
final Environment environment = TestEnvironment.newEnvironment(internalCluster().getDefaultSettings());
expectThrows(() -> detachCluster(environment), ElasticsearchNodeCommand.NO_NODE_FOLDER_FOUND_MSG);
expectThrows(() -> detachCluster(environment), OpenSearchNodeCommand.NO_NODE_FOLDER_FOUND_MSG);
}
public void testBootstrapNodeLocked() throws IOException {
Settings envSettings = buildEnvSettings(Settings.EMPTY);
Environment environment = TestEnvironment.newEnvironment(envSettings);
try (NodeEnvironment ignored = new NodeEnvironment(envSettings, environment)) {
expectThrows(() -> unsafeBootstrap(environment), ElasticsearchNodeCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG);
expectThrows(() -> unsafeBootstrap(environment), OpenSearchNodeCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG);
}
}
@ -133,14 +133,14 @@ public class UnsafeBootstrapAndDetachCommandIT extends ESIntegTestCase {
Settings envSettings = buildEnvSettings(Settings.EMPTY);
Environment environment = TestEnvironment.newEnvironment(envSettings);
try (NodeEnvironment ignored = new NodeEnvironment(envSettings, environment)) {
expectThrows(() -> detachCluster(environment), ElasticsearchNodeCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG);
expectThrows(() -> detachCluster(environment), OpenSearchNodeCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG);
}
}
public void testBootstrapNoNodeMetadata() {
Settings envSettings = buildEnvSettings(Settings.EMPTY);
Environment environment = TestEnvironment.newEnvironment(envSettings);
expectThrows(() -> unsafeBootstrap(environment), ElasticsearchNodeCommand.NO_NODE_FOLDER_FOUND_MSG);
expectThrows(() -> unsafeBootstrap(environment), OpenSearchNodeCommand.NO_NODE_FOLDER_FOUND_MSG);
}
public void testBootstrapNotBootstrappedCluster() throws Exception {
@ -174,7 +174,7 @@ public class UnsafeBootstrapAndDetachCommandIT extends ESIntegTestCase {
Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
PersistedClusterStateService.deleteAll(nodeEnvironment.nodeDataPaths());
expectThrows(() -> unsafeBootstrap(environment), ElasticsearchNodeCommand.NO_NODE_METADATA_FOUND_MSG);
expectThrows(() -> unsafeBootstrap(environment), OpenSearchNodeCommand.NO_NODE_METADATA_FOUND_MSG);
}
public void testDetachNoClusterState() throws IOException {
@ -188,7 +188,7 @@ public class UnsafeBootstrapAndDetachCommandIT extends ESIntegTestCase {
Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
PersistedClusterStateService.deleteAll(nodeEnvironment.nodeDataPaths());
expectThrows(() -> detachCluster(environment), ElasticsearchNodeCommand.NO_NODE_METADATA_FOUND_MSG);
expectThrows(() -> detachCluster(environment), OpenSearchNodeCommand.NO_NODE_METADATA_FOUND_MSG);
}
public void testBootstrapAbortedByUser() throws IOException {
@ -200,7 +200,7 @@ public class UnsafeBootstrapAndDetachCommandIT extends ESIntegTestCase {
Environment environment = TestEnvironment.newEnvironment(
Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
expectThrows(() -> unsafeBootstrap(environment, true), ElasticsearchNodeCommand.ABORTED_BY_USER_MSG);
expectThrows(() -> unsafeBootstrap(environment, true), OpenSearchNodeCommand.ABORTED_BY_USER_MSG);
}
public void testDetachAbortedByUser() throws IOException {
@ -212,7 +212,7 @@ public class UnsafeBootstrapAndDetachCommandIT extends ESIntegTestCase {
Environment environment = TestEnvironment.newEnvironment(
Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
expectThrows(() -> detachCluster(environment, true), ElasticsearchNodeCommand.ABORTED_BY_USER_MSG);
expectThrows(() -> detachCluster(environment, true), OpenSearchNodeCommand.ABORTED_BY_USER_MSG);
}
public void test3MasterNodes2Failed() throws Exception {
@ -268,7 +268,7 @@ public class UnsafeBootstrapAndDetachCommandIT extends ESIntegTestCase {
logger.info("--> unsafely-bootstrap 1st master-eligible node");
MockTerminal terminal = unsafeBootstrap(environmentMaster1);
Metadata metadata = ElasticsearchNodeCommand.createPersistedClusterStateService(Settings.EMPTY, nodeEnvironment.nodeDataPaths())
Metadata metadata = OpenSearchNodeCommand.createPersistedClusterStateService(Settings.EMPTY, nodeEnvironment.nodeDataPaths())
.loadBestOnDiskState().metadata;
assertThat(terminal.getOutput(), containsString(
String.format(Locale.ROOT, UnsafeBootstrapMasterCommand.CLUSTER_STATE_TERM_VERSION_MSG_FORMAT,

View File

@ -28,7 +28,7 @@ import org.elasticsearch.gateway.PersistedClusterStateService;
import java.io.IOException;
import java.nio.file.Path;
public class DetachClusterCommand extends ElasticsearchNodeCommand {
public class DetachClusterCommand extends OpenSearchNodeCommand {
static final String NODE_DETACHED_MSG = "Node was successfully detached from the cluster";
static final String CONFIRMATION_MSG =

View File

@ -57,8 +57,8 @@ import java.util.EnumSet;
import java.util.Map;
import java.util.Objects;
public abstract class ElasticsearchNodeCommand extends EnvironmentAwareCommand {
private static final Logger logger = LogManager.getLogger(ElasticsearchNodeCommand.class);
public abstract class OpenSearchNodeCommand extends EnvironmentAwareCommand {
private static final Logger logger = LogManager.getLogger(OpenSearchNodeCommand.class);
protected static final String DELIMITER = "------------------------------------------------------------------------\n";
static final String STOP_WARNING_MSG =
DELIMITER +
@ -110,7 +110,7 @@ public abstract class ElasticsearchNodeCommand extends EnvironmentAwareCommand {
}
};
public ElasticsearchNodeCommand(String description) {
public OpenSearchNodeCommand(String description) {
super(description);
nodeOrdinalOption = parser.accepts("ordinal", "Optional node ordinal, 0 if not specified")
.withRequiredArg().ofType(Integer.class);
@ -199,7 +199,7 @@ public abstract class ElasticsearchNodeCommand extends EnvironmentAwareCommand {
throws IOException, UserException;
protected NodeEnvironment.NodePath[] toNodePaths(Path[] dataPaths) {
return Arrays.stream(dataPaths).map(ElasticsearchNodeCommand::createNodePath).toArray(NodeEnvironment.NodePath[]::new);
return Arrays.stream(dataPaths).map(OpenSearchNodeCommand::createNodePath).toArray(NodeEnvironment.NodePath[]::new);
}
private static NodeEnvironment.NodePath createNodePath(Path path) {

View File

@ -35,7 +35,7 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
public class RemoveCustomsCommand extends ElasticsearchNodeCommand {
public class RemoveCustomsCommand extends OpenSearchNodeCommand {
static final String CUSTOMS_REMOVED_MSG = "Customs were successfully removed from the cluster state";
static final String CONFIRMATION_MSG =

View File

@ -35,7 +35,7 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
public class RemoveSettingsCommand extends ElasticsearchNodeCommand {
public class RemoveSettingsCommand extends OpenSearchNodeCommand {
static final String SETTINGS_REMOVED_MSG = "Settings were successfully removed from the cluster state";
static final String CONFIRMATION_MSG =

View File

@ -39,7 +39,7 @@ import java.nio.file.Path;
import java.util.Collections;
import java.util.Locale;
public class UnsafeBootstrapMasterCommand extends ElasticsearchNodeCommand {
public class UnsafeBootstrapMasterCommand extends OpenSearchNodeCommand {
static final String CLUSTER_STATE_TERM_VERSION_MSG_FORMAT =
"Current node cluster state (term, version) pair is (%s, %s)";

View File

@ -24,7 +24,7 @@ import joptsimple.OptionSet;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.coordination.ElasticsearchNodeCommand;
import org.elasticsearch.cluster.coordination.OpenSearchNodeCommand;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.node.DiscoveryNode;
@ -46,10 +46,10 @@ import java.util.stream.StreamSupport;
import static org.elasticsearch.env.NodeEnvironment.INDICES_FOLDER;
public class NodeRepurposeCommand extends ElasticsearchNodeCommand {
public class NodeRepurposeCommand extends OpenSearchNodeCommand {
static final String ABORTED_BY_USER_MSG = ElasticsearchNodeCommand.ABORTED_BY_USER_MSG;
static final String FAILED_TO_OBTAIN_NODE_LOCK_MSG = ElasticsearchNodeCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG;
static final String ABORTED_BY_USER_MSG = OpenSearchNodeCommand.ABORTED_BY_USER_MSG;
static final String FAILED_TO_OBTAIN_NODE_LOCK_MSG = OpenSearchNodeCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG;
static final String NO_CLEANUP = "Node has node.data=true -> no clean up necessary";
static final String NO_DATA_TO_CLEAN_UP_FOUND = "No data to clean-up found";
static final String NO_SHARD_DATA_TO_CLEAN_UP_FOUND = "No shard data to clean-up found";

View File

@ -23,14 +23,14 @@ import joptsimple.OptionSet;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.Version;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cluster.coordination.ElasticsearchNodeCommand;
import org.elasticsearch.cluster.coordination.OpenSearchNodeCommand;
import org.elasticsearch.gateway.PersistedClusterStateService;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
public class OverrideNodeVersionCommand extends ElasticsearchNodeCommand {
public class OverrideNodeVersionCommand extends OpenSearchNodeCommand {
private static final String TOO_NEW_MESSAGE =
DELIMITER +
"\n" +

View File

@ -34,7 +34,7 @@ import org.apache.lucene.store.NativeFSLockFactory;
import org.elasticsearch.OpenSearchException;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.coordination.ElasticsearchNodeCommand;
import org.elasticsearch.cluster.coordination.OpenSearchNodeCommand;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.routing.AllocationId;
import org.elasticsearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand;
@ -71,7 +71,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.stream.StreamSupport;
public class RemoveCorruptedShardDataCommand extends ElasticsearchNodeCommand {
public class RemoveCorruptedShardDataCommand extends OpenSearchNodeCommand {
private static final Logger logger = LogManager.getLogger(RemoveCorruptedShardDataCommand.class);

View File

@ -73,7 +73,7 @@ public class ElasticsearchNodeCommandTests extends ESTestCase {
builder.endObject();
Metadata loadedMetadata;
try (XContentParser parser = createParser(hasMissingCustoms ? ElasticsearchNodeCommand.namedXContentRegistry : xContentRegistry(),
try (XContentParser parser = createParser(hasMissingCustoms ? OpenSearchNodeCommand.namedXContentRegistry : xContentRegistry(),
JsonXContent.jsonXContent, BytesReference.bytes(builder))) {
loadedMetadata = Metadata.fromXContent(parser);
}
@ -84,7 +84,7 @@ public class ElasticsearchNodeCommandTests extends ESTestCase {
// make sure the index tombstones are the same too
if (hasMissingCustoms) {
assertNotNull(loadedMetadata.custom(IndexGraveyard.TYPE));
assertThat(loadedMetadata.custom(IndexGraveyard.TYPE), instanceOf(ElasticsearchNodeCommand.UnknownMetadataCustom.class));
assertThat(loadedMetadata.custom(IndexGraveyard.TYPE), instanceOf(OpenSearchNodeCommand.UnknownMetadataCustom.class));
if (preserveUnknownCustoms) {
// check that we reserialize unknown metadata correctly again

View File

@ -25,7 +25,7 @@ import org.elasticsearch.cli.MockTerminal;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.coordination.ElasticsearchNodeCommand;
import org.elasticsearch.cluster.coordination.OpenSearchNodeCommand;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
@ -105,7 +105,7 @@ public class NodeRepurposeCommandTests extends ESTestCase {
if (randomBoolean()) {
try (NodeEnvironment env = new NodeEnvironment(noDataMasterSettings, environment)) {
try (PersistedClusterStateService.Writer writer =
ElasticsearchNodeCommand.createPersistedClusterStateService(Settings.EMPTY, env.nodeDataPaths()).createWriter()) {
OpenSearchNodeCommand.createPersistedClusterStateService(Settings.EMPTY, env.nodeDataPaths()).createWriter()) {
writer.writeFullStateAndCommit(1L, ClusterState.EMPTY_STATE);
}
}
@ -233,7 +233,7 @@ public class NodeRepurposeCommandTests extends ESTestCase {
try (NodeEnvironment env = new NodeEnvironment(settings, environment)) {
if (writeClusterState) {
try (PersistedClusterStateService.Writer writer =
ElasticsearchNodeCommand.createPersistedClusterStateService(Settings.EMPTY, env.nodeDataPaths()).createWriter()) {
OpenSearchNodeCommand.createPersistedClusterStateService(Settings.EMPTY, env.nodeDataPaths()).createWriter()) {
writer.writeFullStateAndCommit(1L, ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().put(IndexMetadata.builder(INDEX.getName())
.settings(Settings.builder().put("index.version.created", Version.CURRENT)

View File

@ -70,7 +70,7 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.RestoreInProgress;
import org.elasticsearch.cluster.SnapshotDeletionsInProgress;
import org.elasticsearch.cluster.SnapshotsInProgress;
import org.elasticsearch.cluster.coordination.ElasticsearchNodeCommand;
import org.elasticsearch.cluster.coordination.OpenSearchNodeCommand;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.metadata.IndexGraveyard;
import org.elasticsearch.cluster.metadata.IndexMetadata;
@ -1146,7 +1146,7 @@ public abstract class ESIntegTestCase extends ESTestCase {
final BytesReference compareOriginalBytes = BytesReference.bytes(compareBuilder);
final Metadata loadedMetadata;
try (XContentParser parser = createParser(ElasticsearchNodeCommand.namedXContentRegistry,
try (XContentParser parser = createParser(OpenSearchNodeCommand.namedXContentRegistry,
SmileXContent.smileXContent, originalBytes)) {
loadedMetadata = Metadata.fromXContent(parser);
}
@ -1180,7 +1180,7 @@ public abstract class ESIntegTestCase extends ESTestCase {
final BytesReference compareOriginalBytes = BytesReference.bytes(compareBuilder);
final IndexMetadata loadedIndexMetadata;
try (XContentParser parser = createParser(ElasticsearchNodeCommand.namedXContentRegistry,
try (XContentParser parser = createParser(OpenSearchNodeCommand.namedXContentRegistry,
SmileXContent.smileXContent, originalBytes)) {
loadedIndexMetadata = IndexMetadata.fromXContent(parser);
}