Search in sources :

Example 86 with Environment

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

the class InstallPluginCommandTests method testFileNotMaven.

public void testFileNotMaven() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    String dir = randomAlphaOfLength(10) + ":" + randomAlphaOfLength(5) + "\\" + randomAlphaOfLength(5);
    Exception e = expectThrows(Exception.class, // has two colons, so it appears similar to maven coordinates
    () -> installPlugin("file:" + dir, env.v1()));
    assertFalse(e.getMessage(), e.getMessage().contains("maven.org"));
    assertTrue(e.getMessage(), e.getMessage().contains(dir));
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException) NoSuchFileException(java.nio.file.NoSuchFileException) PGPException(org.bouncycastle.openpgp.PGPException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 87 with Environment

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

the class InstallPluginCommandTests method testMalformedUrlNotMaven.

public void testMalformedUrlNotMaven() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    // has two colons, so it appears similar to maven coordinates
    MalformedURLException e = expectThrows(MalformedURLException.class, () -> installPlugin("://host:1234", env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("no protocol"));
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment)

Example 88 with Environment

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

the class InstallPluginCommandTests method testMissingPluginId.

public void testMissingPluginId() throws IOException {
    final Tuple<Path, Environment> env = createEnv(fs, temp);
    final UserException e = expectThrows(UserException.class, () -> installPlugin(null, env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("at least one plugin id is required"));
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) UserException(org.opensearch.cli.UserException)

Example 89 with Environment

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

the class InstallPluginCommandTests method testTransaction.

public void testTransaction() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    String pluginZip = createPluginUrl("fake", pluginDir);
    final FileNotFoundException e = expectThrows(FileNotFoundException.class, () -> installPlugins(Arrays.asList(pluginZip, pluginZip + "does-not-exist"), env.v1()));
    assertThat(e, hasToString(containsString("does-not-exist")));
    final Path fakeInstallPath = env.v2().pluginsFile().resolve("fake");
    // fake should have been removed when the file not found exception occurred
    assertFalse(Files.exists(fakeInstallPath));
    assertInstallCleaned(env.v2());
}
Also used : Path(java.nio.file.Path) FileNotFoundException(java.io.FileNotFoundException) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 90 with Environment

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

the class InstallPluginCommandTests method testExistingConfig.

public void testExistingConfig() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path envConfigDir = env.v2().configFile().resolve("fake");
    Files.createDirectories(envConfigDir);
    Files.write(envConfigDir.resolve("custom.yml"), "existing config".getBytes(StandardCharsets.UTF_8));
    Path pluginDir = createPluginDir(temp);
    Path configDir = pluginDir.resolve("config");
    Files.createDirectory(configDir);
    Files.write(configDir.resolve("custom.yml"), "new config".getBytes(StandardCharsets.UTF_8));
    Files.createFile(configDir.resolve("other.yml"));
    String pluginZip = createPluginUrl("fake", pluginDir);
    installPlugin(pluginZip, env.v1());
    assertPlugin("fake", pluginDir, env.v2());
    List<String> configLines = Files.readAllLines(envConfigDir.resolve("custom.yml"), StandardCharsets.UTF_8);
    assertEquals(1, configLines.size());
    assertEquals("existing config", configLines.get(0));
    assertTrue(Files.exists(envConfigDir.resolve("other.yml")));
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

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