Search in sources :

Example 26 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class RemoveCustomsCommandIT method testRemoveCustomsAbortedByUser.

public void testRemoveCustomsAbortedByUser() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(0);
    String node = internalCluster().startNode();
    Settings dataPathSettings = internalCluster().dataPathSettings(node);
    ensureStableCluster(1);
    internalCluster().stopRandomDataNode();
    Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
    expectThrows(() -> removeCustoms(environment, true, new String[] { "index-graveyard" }), OpenSearchNodeCommand.ABORTED_BY_USER_MSG);
}
Also used : Environment(org.opensearch.env.Environment) TestEnvironment(org.opensearch.env.TestEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings)

Example 27 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class RemoveCustomsCommandIT method executeCommand.

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);
    final String input;
    if (abort) {
        input = randomValueOtherThanMany(c -> c.equalsIgnoreCase("y"), () -> randomAlphaOfLength(1));
    } else {
        input = randomBoolean() ? "y" : "Y";
    }
    terminal.addTextInput(input);
    try {
        command.execute(terminal, options, environment);
    } finally {
        assertThat(terminal.getOutput(), containsString(OpenSearchNodeCommand.STOP_WARNING_MSG));
    }
    return terminal;
}
Also used : Environment(org.opensearch.env.Environment) UserException(org.opensearch.cli.UserException) TestEnvironment(org.opensearch.env.TestEnvironment) MockTerminal(org.opensearch.cli.MockTerminal) Settings(org.opensearch.common.settings.Settings) OpenSearchException(org.opensearch.OpenSearchException) OpenSearchIntegTestCase(org.opensearch.test.OpenSearchIntegTestCase) Matchers.containsString(org.hamcrest.Matchers.containsString) OptionSet(joptsimple.OptionSet) Matchers.containsString(org.hamcrest.Matchers.containsString) OptionSet(joptsimple.OptionSet) MockTerminal(org.opensearch.cli.MockTerminal)

Example 28 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class UnsafeBootstrapAndDetachCommandIT method test3MasterNodes2Failed.

public void test3MasterNodes2Failed() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(2);
    List<String> masterNodes = new ArrayList<>();
    logger.info("--> start 1st master-eligible node");
    masterNodes.add(internalCluster().startMasterOnlyNode(Settings.builder().put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").build()));
    // node ordinal 0
    logger.info("--> start one data-only node");
    String dataNode = internalCluster().startDataOnlyNode(Settings.builder().put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").build());
    // node ordinal 1
    logger.info("--> start 2nd and 3rd master-eligible nodes and bootstrap");
    // node ordinals 2 and 3
    masterNodes.addAll(internalCluster().startMasterOnlyNodes(2));
    logger.info("--> wait for all nodes to join the cluster");
    ensureStableCluster(4);
    List<String> currentClusterNodes = new ArrayList<>(masterNodes);
    currentClusterNodes.add(dataNode);
    currentClusterNodes.forEach(node -> ensureReadOnlyBlock(false, node));
    logger.info("--> create index test");
    createIndex("test");
    ensureGreen("test");
    Settings master1DataPathSettings = internalCluster().dataPathSettings(masterNodes.get(0));
    Settings master2DataPathSettings = internalCluster().dataPathSettings(masterNodes.get(1));
    Settings master3DataPathSettings = internalCluster().dataPathSettings(masterNodes.get(2));
    Settings dataNodeDataPathSettings = internalCluster().dataPathSettings(dataNode);
    logger.info("--> stop 2nd and 3d master eligible node");
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(1)));
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(2)));
    logger.info("--> ensure NO_MASTER_BLOCK on data-only node");
    assertBusy(() -> {
        ClusterState state = internalCluster().client(dataNode).admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
        assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
    });
    logger.info("--> try to unsafely bootstrap 1st master-eligible node, while node lock is held");
    Environment environmentMaster1 = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(master1DataPathSettings).build());
    expectThrows(() -> unsafeBootstrap(environmentMaster1), UnsafeBootstrapMasterCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG);
    logger.info("--> stop 1st master-eligible node and data-only node");
    NodeEnvironment nodeEnvironment = internalCluster().getMasterNodeInstance(NodeEnvironment.class);
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(0)));
    assertBusy(() -> internalCluster().getInstance(GatewayMetaState.class, dataNode).allPendingAsyncStatesWritten());
    internalCluster().stopRandomDataNode();
    logger.info("--> unsafely-bootstrap 1st master-eligible node");
    MockTerminal terminal = unsafeBootstrap(environmentMaster1, false, true);
    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, metadata.coordinationMetadata().term(), metadata.version())));
    logger.info("--> start 1st master-eligible node");
    String masterNode2 = internalCluster().startMasterOnlyNode(master1DataPathSettings);
    logger.info("--> detach-cluster on data-only node");
    Environment environmentData = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataNodeDataPathSettings).build());
    detachCluster(environmentData, false);
    logger.info("--> start data-only node");
    String dataNode2 = internalCluster().startDataOnlyNode(dataNodeDataPathSettings);
    logger.info("--> ensure there is no NO_MASTER_BLOCK and unsafe-bootstrap is reflected in cluster state");
    assertBusy(() -> {
        ClusterState state = internalCluster().client(dataNode2).admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
        assertFalse(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
        assertTrue(state.metadata().persistentSettings().getAsBoolean(UnsafeBootstrapMasterCommand.UNSAFE_BOOTSTRAP.getKey(), false));
    });
    List<String> bootstrappedNodes = new ArrayList<>();
    bootstrappedNodes.add(dataNode2);
    bootstrappedNodes.add(masterNode2);
    bootstrappedNodes.forEach(node -> ensureReadOnlyBlock(true, node));
    logger.info("--> ensure index test is green");
    ensureGreen("test");
    IndexMetadata indexMetadata = clusterService().state().metadata().index("test");
    assertThat(indexMetadata.getSettings().get(IndexMetadata.SETTING_HISTORY_UUID), notNullValue());
    logger.info("--> detach-cluster on 2nd and 3rd master-eligible nodes");
    Environment environmentMaster2 = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(master2DataPathSettings).build());
    detachCluster(environmentMaster2, false);
    Environment environmentMaster3 = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(master3DataPathSettings).build());
    detachCluster(environmentMaster3, false);
    logger.info("--> start 2nd and 3rd master-eligible nodes and ensure 4 nodes stable cluster");
    bootstrappedNodes.add(internalCluster().startMasterOnlyNode(master2DataPathSettings));
    bootstrappedNodes.add(internalCluster().startMasterOnlyNode(master3DataPathSettings));
    ensureStableCluster(4);
    bootstrappedNodes.forEach(node -> ensureReadOnlyBlock(true, node));
    removeBlock();
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) NodeEnvironment(org.opensearch.env.NodeEnvironment) ArrayList(java.util.ArrayList) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) NodeEnvironment(org.opensearch.env.NodeEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) MockTerminal(org.opensearch.cli.MockTerminal) Settings(org.opensearch.common.settings.Settings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings)

Example 29 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class UnsafeBootstrapAndDetachCommandIT method testDetachNoClusterState.

public void testDetachNoClusterState() throws IOException {
    internalCluster().setBootstrapMasterNodeIndex(0);
    String node = internalCluster().startNode();
    Settings dataPathSettings = internalCluster().dataPathSettings(node);
    ensureStableCluster(1);
    NodeEnvironment nodeEnvironment = internalCluster().getMasterNodeInstance(NodeEnvironment.class);
    internalCluster().stopRandomDataNode();
    Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
    PersistedClusterStateService.deleteAll(nodeEnvironment.nodeDataPaths());
    expectThrows(() -> detachCluster(environment), OpenSearchNodeCommand.NO_NODE_METADATA_FOUND_MSG);
}
Also used : NodeEnvironment(org.opensearch.env.NodeEnvironment) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) NodeEnvironment(org.opensearch.env.NodeEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings)

Example 30 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class UnsafeBootstrapAndDetachCommandIT method testCanRunUnsafeBootstrapAfterErroneousDetachWithoutLoosingMetadata.

public void testCanRunUnsafeBootstrapAfterErroneousDetachWithoutLoosingMetadata() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(0);
    String masterNode = internalCluster().startMasterOnlyNode();
    Settings masterNodeDataPathSettings = internalCluster().dataPathSettings(masterNode);
    ClusterUpdateSettingsRequest req = new ClusterUpdateSettingsRequest().persistentSettings(Settings.builder().put(INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(), "1234kb"));
    internalCluster().client().admin().cluster().updateSettings(req).get();
    ClusterState state = internalCluster().client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.metadata().persistentSettings().get(INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey()), equalTo("1234kb"));
    ensureReadOnlyBlock(false, masterNode);
    internalCluster().stopCurrentMasterNode();
    final Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(masterNodeDataPathSettings).build());
    detachCluster(environment);
    // read-only block will remain same as one before bootstrap, in this case it is false
    unsafeBootstrap(environment);
    String masterNode2 = internalCluster().startMasterOnlyNode(masterNodeDataPathSettings);
    ensureGreen();
    ensureReadOnlyBlock(false, masterNode2);
    state = internalCluster().client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.metadata().settings().get(INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey()), equalTo("1234kb"));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) NodeEnvironment(org.opensearch.env.NodeEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)

Aggregations

Environment (org.opensearch.env.Environment)142 TestEnvironment (org.opensearch.env.TestEnvironment)98 Path (java.nio.file.Path)80 Settings (org.opensearch.common.settings.Settings)79 Matchers.containsString (org.hamcrest.Matchers.containsString)69 Matchers.hasToString (org.hamcrest.Matchers.hasToString)40 NodeEnvironment (org.opensearch.env.NodeEnvironment)32 IOException (java.io.IOException)27 UserException (org.opensearch.cli.UserException)23 ClusterState (org.opensearch.cluster.ClusterState)22 IndexSettings (org.opensearch.index.IndexSettings)22 MockTerminal (org.opensearch.cli.MockTerminal)19 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)19 OpenSearchException (org.opensearch.OpenSearchException)18 Map (java.util.Map)16 OptionSet (joptsimple.OptionSet)15 DiscoverySettings (org.opensearch.node.Node.DiscoverySettings)14 Version (org.opensearch.Version)13 Files (java.nio.file.Files)11 Arrays (java.util.Arrays)11