Search in sources :

Example 96 with Environment

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

the class InstallPluginCommandTests method testContainsIntermediateDirectory.

public void testContainsIntermediateDirectory() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Files.createFile(pluginDir.resolve(PluginInfo.OPENSEARCH_PLUGIN_PROPERTIES));
    String pluginZip = writeZip(pluginDir, "opensearch").toUri().toURL().toString();
    UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
    assertThat(e.getMessage(), containsString("This plugin was built with an older plugin structure"));
    assertInstallCleaned(env.v2());
}
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)

Example 97 with Environment

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

the class InstallPluginCommandTests method testJarHell.

public void testJarHell() throws Exception {
    // jar hell test needs a real filesystem
    assumeTrue("real filesystem", isReal);
    Tuple<Path, Environment> environment = createEnv(fs, temp);
    Path pluginDirectory = createPluginDir(temp);
    writeJar(pluginDirectory.resolve("other.jar"), "FakePlugin");
    // adds plugin.jar with FakePlugin
    String pluginZip = createPluginUrl("fake", pluginDirectory);
    IllegalStateException e = expectThrows(IllegalStateException.class, () -> installPlugin(pluginZip, environment.v1(), defaultCommand));
    assertTrue(e.getMessage(), e.getMessage().contains("jar hell"));
    assertInstallCleaned(environment.v2());
}
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)

Example 98 with Environment

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

the class InstallPluginCommandTests method testConfigNotDir.

public void testConfigNotDir() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Files.createDirectories(pluginDir);
    Path configDir = pluginDir.resolve("config");
    Files.createFile(configDir);
    String pluginZip = createPluginUrl("fake", pluginDir);
    UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
    assertInstallCleaned(env.v2());
}
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)

Example 99 with Environment

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

the class IcuTokenizerFactory method parseRules.

// parse a single RBBi rule file
private BreakIterator parseRules(String filename, Environment env) throws IOException {
    final Path path = env.configFile().resolve(filename);
    String rules = Files.readAllLines(path).stream().filter((v) -> v.startsWith("#") == false).collect(Collectors.joining("\n"));
    return new RuleBasedBreakIterator(rules.toString());
}
Also used : Path(java.nio.file.Path) Environment(org.opensearch.env.Environment) UCharacter(com.ibm.icu.lang.UCharacter) Tokenizer(org.apache.lucene.analysis.Tokenizer) UScript(com.ibm.icu.lang.UScript) Files(java.nio.file.Files) RuleBasedBreakIterator(com.ibm.icu.text.RuleBasedBreakIterator) BreakIterator(com.ibm.icu.text.BreakIterator) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) HashMap(java.util.HashMap) OpenSearchException(org.opensearch.OpenSearchException) Collectors(java.util.stream.Collectors) ICUTokenizer(org.apache.lucene.analysis.icu.segmentation.ICUTokenizer) List(java.util.List) DefaultICUTokenizerConfig(org.apache.lucene.analysis.icu.segmentation.DefaultICUTokenizerConfig) Map(java.util.Map) IndexSettings(org.opensearch.index.IndexSettings) UProperty(com.ibm.icu.lang.UProperty) Path(java.nio.file.Path) ICUTokenizerConfig(org.apache.lucene.analysis.icu.segmentation.ICUTokenizerConfig) RuleBasedBreakIterator(com.ibm.icu.text.RuleBasedBreakIterator)

Example 100 with Environment

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

the class ReloadSecureSettingsIT method testReloadLocalNodeWithPasswordWithoutTLSSucceeds.

public void testReloadLocalNodeWithPasswordWithoutTLSSucceeds() throws Exception {
    final Environment environment = internalCluster().getInstance(Environment.class);
    final AtomicReference<AssertionError> reloadSettingsError = new AtomicReference<>();
    final char[] password = randomAlphaOfLength(12).toCharArray();
    writeEmptyKeystore(environment, password);
    final CountDownLatch latch = new CountDownLatch(1);
    client().admin().cluster().prepareReloadSecureSettings().setNodesIds("_local").setSecureStorePassword(new SecureString(password)).execute(new ActionListener<NodesReloadSecureSettingsResponse>() {

        @Override
        public void onResponse(NodesReloadSecureSettingsResponse nodesReloadResponse) {
            try {
                assertThat(nodesReloadResponse, notNullValue());
                final Map<String, NodesReloadSecureSettingsResponse.NodeResponse> nodesMap = nodesReloadResponse.getNodesMap();
                assertThat(nodesMap.size(), equalTo(1));
                assertThat(nodesReloadResponse.getNodes().size(), equalTo(1));
                final NodesReloadSecureSettingsResponse.NodeResponse nodeResponse = nodesReloadResponse.getNodes().get(0);
                assertThat(nodeResponse.reloadException(), nullValue());
            } catch (final AssertionError e) {
                reloadSettingsError.set(e);
            } finally {
                latch.countDown();
            }
        }

        @Override
        public void onFailure(Exception e) {
            reloadSettingsError.set(new AssertionError("Nodes request failed", e));
            latch.countDown();
        }
    });
    latch.await();
    if (reloadSettingsError.get() != null) {
        throw reloadSettingsError.get();
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) OpenSearchException(org.opensearch.OpenSearchException) RemoteTransportException(org.opensearch.transport.RemoteTransportException) AccessControlException(java.security.AccessControlException) Environment(org.opensearch.env.Environment) Map(java.util.Map) SecureString(org.opensearch.common.settings.SecureString) NodesReloadSecureSettingsResponse(org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsResponse)

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