Search in sources :

Example 76 with Environment

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

the class ListPluginsCommandTests method listPlugins.

static MockTerminal listPlugins(Path home, String[] args) throws Exception {
    String[] argsAndHome = new String[args.length + 1];
    System.arraycopy(args, 0, argsAndHome, 0, args.length);
    argsAndHome[args.length] = "-Epath.home=" + home;
    MockTerminal terminal = new MockTerminal();
    int status = new ListPluginsCommand() {

        @Override
        protected Environment createEnv(Map<String, String> settings) throws UserException {
            Settings.Builder builder = Settings.builder().put("path.home", home);
            settings.forEach((k, v) -> builder.put(k, v));
            final Settings realSettings = builder.build();
            return new Environment(realSettings, home.resolve("config"));
        }

        @Override
        protected boolean addShutdownHook() {
            return false;
        }
    }.main(argsAndHome, terminal);
    assertEquals(ExitCodes.OK, status);
    return terminal;
}
Also used : Environment(org.opensearch.env.Environment) UserException(org.opensearch.cli.UserException) TestEnvironment(org.opensearch.env.TestEnvironment) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) MockTerminal(org.opensearch.cli.MockTerminal) Files(java.nio.file.Files) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) IOException(java.io.IOException) Version(org.opensearch.Version) Settings(org.opensearch.common.settings.Settings) Collectors(java.util.stream.Collectors) LegacyESVersion(org.opensearch.LegacyESVersion) Map(java.util.Map) LuceneTestCase(org.apache.lucene.util.LuceneTestCase) ExitCodes(org.opensearch.cli.ExitCodes) Path(java.nio.file.Path) Before(org.junit.Before) Environment(org.opensearch.env.Environment) TestEnvironment(org.opensearch.env.TestEnvironment) UserException(org.opensearch.cli.UserException) MockTerminal(org.opensearch.cli.MockTerminal) Settings(org.opensearch.common.settings.Settings)

Example 77 with Environment

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

the class InstallPluginCommandTests method testSpaceInUrl.

public void testSpaceInUrl() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    String pluginZip = createPluginUrl("fake", pluginDir);
    Path pluginZipWithSpaces = createTempFile("foo bar", ".zip");
    try (InputStream in = FileSystemUtils.openFileURLStream(new URL(pluginZip))) {
        Files.copy(in, pluginZipWithSpaces, StandardCopyOption.REPLACE_EXISTING);
    }
    installPlugin(pluginZipWithSpaces.toUri().toURL().toString(), env.v1());
    assertPlugin("fake", pluginDir, env.v2());
}
Also used : Path(java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) URL(java.net.URL)

Example 78 with Environment

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

the class InstallPluginCommandTests method testUnknownPlugin.

public void testUnknownPlugin() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    UserException e = expectThrows(UserException.class, () -> installPlugin("foo", env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("Unknown plugin foo"));
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) UserException(org.opensearch.cli.UserException)

Example 79 with Environment

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

the class AvailableIndexFoldersBenchmark method setup.

@Setup
public void setup() throws IOException {
    Path path = Files.createTempDirectory("test");
    String[] paths = new String[] { path.toString() };
    nodePath = new NodeEnvironment.NodePath(path);
    LogConfigurator.setNodeName("test");
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), path).putList(Environment.PATH_DATA_SETTING.getKey(), paths).build();
    nodeEnv = new NodeEnvironment(settings, new Environment(settings, null));
    Files.createDirectories(nodePath.indicesPath);
    excludedDirs = new HashSet<>();
    int numIndices = 5000;
    for (int i = 0; i < numIndices; i++) {
        String dirName = "dir" + i;
        Files.createDirectory(nodePath.indicesPath.resolve(dirName));
        excludedDirs.add(dirName);
    }
    if (nodeEnv.availableIndexFoldersForPath(nodePath).size() != numIndices) {
        throw new IllegalStateException("bad size");
    }
    if (nodeEnv.availableIndexFoldersForPath(nodePath, excludedDirs::contains).size() != 0) {
        throw new IllegalStateException("bad size");
    }
}
Also used : Path(java.nio.file.Path) NodeEnvironment(org.opensearch.env.NodeEnvironment) Environment(org.opensearch.env.Environment) NodeEnvironment(org.opensearch.env.NodeEnvironment) Settings(org.opensearch.common.settings.Settings) Setup(org.openjdk.jmh.annotations.Setup)

Example 80 with Environment

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

the class InstallPluginCommandTests method testMissingDescriptor.

public void testMissingDescriptor() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Files.createFile(pluginDir.resolve("fake.yml"));
    String pluginZip = writeZip(pluginDir, null).toUri().toURL().toString();
    NoSuchFileException e = expectThrows(NoSuchFileException.class, () -> installPlugin(pluginZip, env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("plugin-descriptor.properties"));
    assertInstallCleaned(env.v2());
}
Also used : Path(java.nio.file.Path) NoSuchFileException(java.nio.file.NoSuchFileException) 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