Search in sources :

Example 21 with Environment

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

the class SpawnerNoBootstrapTests method testNoControllerSpawn.

/**
 * Simplest case: a module with no controller daemon.
 */
public void testNoControllerSpawn() throws IOException {
    Path esHome = createTempDir().resolve("esHome");
    Settings.Builder settingsBuilder = Settings.builder();
    settingsBuilder.put(Environment.PATH_HOME_SETTING.getKey(), esHome.toString());
    Settings settings = settingsBuilder.build();
    Environment environment = TestEnvironment.newEnvironment(settings);
    // This plugin will NOT have a controller daemon
    Path plugin = environment.modulesFile().resolve("a_plugin");
    Files.createDirectories(environment.modulesFile());
    Files.createDirectories(plugin);
    PluginTestUtil.writePluginProperties(plugin, "description", "a_plugin", "version", Version.CURRENT.toString(), "opensearch.version", Version.CURRENT.toString(), "name", "a_plugin", "java.version", "1.8", "classname", "APlugin", "has.native.controller", "false");
    try (Spawner spawner = new Spawner()) {
        spawner.spawnNativeControllers(environment, false);
        assertThat(spawner.getProcesses(), hasSize(0));
    }
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Settings(org.opensearch.common.settings.Settings)

Example 22 with Environment

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

the class UnsafeBootstrapAndDetachCommandIT method testDetachNodeLocked.

public void testDetachNodeLocked() throws IOException {
    Settings envSettings = buildEnvSettings(Settings.EMPTY);
    Environment environment = TestEnvironment.newEnvironment(envSettings);
    try (NodeEnvironment ignored = new NodeEnvironment(envSettings, environment)) {
        expectThrows(() -> detachCluster(environment), OpenSearchNodeCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG);
    }
}
Also used : NodeEnvironment(org.opensearch.env.NodeEnvironment) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) NodeEnvironment(org.opensearch.env.NodeEnvironment) Settings(org.opensearch.common.settings.Settings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings)

Example 23 with Environment

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

the class UnsafeBootstrapAndDetachCommandIT method testBootstrapNoClusterState.

public void testBootstrapNoClusterState() 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(() -> unsafeBootstrap(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 24 with Environment

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

the class RemoveCustomsCommandIT method testCustomDoesNotMatch.

public void testCustomDoesNotMatch() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(0);
    String node = internalCluster().startNode();
    createIndex("test");
    client().admin().indices().prepareDelete("test").get();
    assertEquals(1, client().admin().cluster().prepareState().get().getState().metadata().indexGraveyard().getTombstones().size());
    Settings dataPathSettings = internalCluster().dataPathSettings(node);
    ensureStableCluster(1);
    internalCluster().stopRandomDataNode();
    Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
    UserException ex = expectThrows(UserException.class, () -> removeCustoms(environment, false, new String[] { "index-greveyard-with-typos" }));
    assertThat(ex.getMessage(), containsString("No custom metadata matching [index-greveyard-with-typos] were " + "found on this node"));
}
Also used : Environment(org.opensearch.env.Environment) TestEnvironment(org.opensearch.env.TestEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException) Settings(org.opensearch.common.settings.Settings)

Example 25 with Environment

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

the class RemoveCustomsCommandIT method testRemoveCustomsSuccessful.

public void testRemoveCustomsSuccessful() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(0);
    String node = internalCluster().startNode();
    createIndex("test");
    client().admin().indices().prepareDelete("test").get();
    assertEquals(1, client().admin().cluster().prepareState().get().getState().metadata().indexGraveyard().getTombstones().size());
    Settings dataPathSettings = internalCluster().dataPathSettings(node);
    ensureStableCluster(1);
    internalCluster().stopRandomDataNode();
    Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
    MockTerminal terminal = removeCustoms(environment, false, randomBoolean() ? new String[] { "index-graveyard" } : new String[] { "index-*" });
    assertThat(terminal.getOutput(), containsString(RemoveCustomsCommand.CUSTOMS_REMOVED_MSG));
    assertThat(terminal.getOutput(), containsString("The following customs will be removed:"));
    assertThat(terminal.getOutput(), containsString("index-graveyard"));
    internalCluster().startNode(dataPathSettings);
    assertEquals(0, client().admin().cluster().prepareState().get().getState().metadata().indexGraveyard().getTombstones().size());
}
Also used : Environment(org.opensearch.env.Environment) TestEnvironment(org.opensearch.env.TestEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) MockTerminal(org.opensearch.cli.MockTerminal) Settings(org.opensearch.common.settings.Settings)

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