diff --git a/CHANGELOG-3.0.md b/CHANGELOG-3.0.md index 8d8adfd1e3566..4b8dedd333884 100644 --- a/CHANGELOG-3.0.md +++ b/CHANGELOG-3.0.md @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Deprecate CamelCase `PathHierarchy` tokenizer name in favor to lowercase `path_hierarchy` ([#10894](https://github.com/opensearch-project/OpenSearch/pull/10894)) - Breaking change: Do not request "search_pipelines" metrics by default in NodesInfoRequest ([#12497](https://github.com/opensearch-project/OpenSearch/pull/12497)) - Refactor `:libs` module `bootstrap` package to eliminate top level split packages [#17117](https://github.com/opensearch-project/OpenSearch/pull/17117)) +- Refactor `:server` and `:distribution:tools:keystore-cli` module to eliminate top level split packages. [#17153](https://github.com/opensearch-project/OpenSearch/pull/17153)) ### Deprecated diff --git a/distribution/build.gradle b/distribution/build.gradle index b04b04062134f..f6ca34dee87c6 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -481,7 +481,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) { } } } - + jreFiles = { Project project, String platform, String architecture -> return copySpec { /* diff --git a/distribution/src/bin/opensearch-keystore b/distribution/src/bin/opensearch-keystore index 9f6cb65feeeeb..d7fad3006b037 100755 --- a/distribution/src/bin/opensearch-keystore +++ b/distribution/src/bin/opensearch-keystore @@ -2,7 +2,7 @@ set -e -o pipefail -OPENSEARCH_MAIN_CLASS=org.opensearch.common.settings.KeyStoreCli \ +OPENSEARCH_MAIN_CLASS=org.opensearch.tools.cli.keystore.KeyStoreCli \ OPENSEARCH_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/keystore-cli \ "`dirname "$0"`"/opensearch-cli \ "$@" diff --git a/distribution/src/bin/opensearch-keystore.bat b/distribution/src/bin/opensearch-keystore.bat index f6ab163199b77..de2c2168704a6 100644 --- a/distribution/src/bin/opensearch-keystore.bat +++ b/distribution/src/bin/opensearch-keystore.bat @@ -3,7 +3,7 @@ setlocal enabledelayedexpansion setlocal enableextensions -set OPENSEARCH_MAIN_CLASS=org.opensearch.common.settings.KeyStoreCli +set OPENSEARCH_MAIN_CLASS=org.opensearch.tools.cli.keystore.KeyStoreCli set OPENSEARCH_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/keystore-cli call "%~dp0opensearch-cli.bat" ^ %%* ^ diff --git a/distribution/src/bin/opensearch-plugin b/distribution/src/bin/opensearch-plugin index b58a2695d2ecf..984d573249afc 100755 --- a/distribution/src/bin/opensearch-plugin +++ b/distribution/src/bin/opensearch-plugin @@ -2,7 +2,7 @@ set -e -o pipefail -OPENSEARCH_MAIN_CLASS=org.opensearch.plugins.PluginCli \ +OPENSEARCH_MAIN_CLASS=org.opensearch.tools.cli.plugin.PluginCli \ OPENSEARCH_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/plugin-cli \ "`dirname "$0"`"/opensearch-cli \ "$@" diff --git a/distribution/src/bin/opensearch-plugin.bat b/distribution/src/bin/opensearch-plugin.bat index f1bd8d92aab4a..6864de9bc46d0 100644 --- a/distribution/src/bin/opensearch-plugin.bat +++ b/distribution/src/bin/opensearch-plugin.bat @@ -3,7 +3,7 @@ setlocal enabledelayedexpansion setlocal enableextensions -set OPENSEARCH_MAIN_CLASS=org.opensearch.plugins.PluginCli +set OPENSEARCH_MAIN_CLASS=org.opensearch.tools.cli.plugin.PluginCli set OPENSEARCH_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/plugin-cli call "%~dp0opensearch-cli.bat" ^ %%* ^ diff --git a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/AddFileKeyStoreCommand.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/AddFileKeyStoreCommand.java similarity index 97% rename from distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/AddFileKeyStoreCommand.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/AddFileKeyStoreCommand.java index b948be24350f4..c6725815efc4c 100644 --- a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/AddFileKeyStoreCommand.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/AddFileKeyStoreCommand.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import joptsimple.OptionSet; import joptsimple.OptionSpec; @@ -39,6 +39,7 @@ import org.opensearch.cli.UserException; import org.opensearch.common.SuppressForbidden; import org.opensearch.common.io.PathUtils; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.env.Environment; import java.nio.file.Files; diff --git a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/AddStringKeyStoreCommand.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/AddStringKeyStoreCommand.java similarity index 97% rename from distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/AddStringKeyStoreCommand.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/AddStringKeyStoreCommand.java index a8bc1dff8838f..74b03b86b88e0 100644 --- a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/AddStringKeyStoreCommand.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/AddStringKeyStoreCommand.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import joptsimple.OptionSet; import joptsimple.OptionSpec; @@ -38,6 +38,7 @@ import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; import org.opensearch.common.CheckedFunction; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.env.Environment; import java.io.BufferedReader; diff --git a/server/src/main/java/org/opensearch/common/settings/BaseKeyStoreCommand.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/BaseKeyStoreCommand.java similarity index 65% rename from server/src/main/java/org/opensearch/common/settings/BaseKeyStoreCommand.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/BaseKeyStoreCommand.java index 73a2fc031fd7c..161cee9f94808 100644 --- a/server/src/main/java/org/opensearch/common/settings/BaseKeyStoreCommand.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/BaseKeyStoreCommand.java @@ -30,14 +30,14 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import joptsimple.OptionSet; import joptsimple.OptionSpec; import org.opensearch.cli.ExitCodes; -import org.opensearch.cli.KeyStoreAwareCommand; import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.core.common.settings.SecureString; import org.opensearch.env.Environment; @@ -53,13 +53,36 @@ public abstract class BaseKeyStoreCommand extends KeyStoreAwareCommand { private KeyStoreWrapper keyStore; private SecureString keyStorePassword; private final boolean keyStoreMustExist; - OptionSpec forceOption; + /** + * Option to force operations without prompting for confirmation. + * When specified, operations proceed without asking for user input. + */ + protected OptionSpec forceOption; + + /** + * Creates a new BaseKeyStoreCommand with the specified description and existence requirement. + * + * @param description The description of the command + * @param keyStoreMustExist If true, the keystore must exist before executing the command. + * If false, a new keystore may be created if none exists. + */ public BaseKeyStoreCommand(String description, boolean keyStoreMustExist) { super(description); this.keyStoreMustExist = keyStoreMustExist; } + /** + * Executes the keystore command by loading/creating the keystore and handling password management. + * If the keystore doesn't exist and keyStoreMustExist is false, prompts to create a new one + * unless the force option is specified. + * + * @param terminal The terminal to use for user interaction + * @param options The command-line options provided + * @param env The environment settings + * @throws Exception if there are errors during keystore operations + * @throws UserException if the keystore is required but doesn't exist + */ @Override protected final void execute(Terminal terminal, OptionSet options, Environment env) throws Exception { try { @@ -96,19 +119,34 @@ protected final void execute(Terminal terminal, OptionSet options, Environment e } } + /** + * Gets the current keystore instance. + * + * @return The current {@link KeyStoreWrapper} instance being operated on + */ protected KeyStoreWrapper getKeyStore() { return keyStore; } + /** + * Gets the password for the current keystore. + * + * @return The {@link SecureString} containing the keystore password + */ protected SecureString getKeyStorePassword() { return keyStorePassword; } /** - * This is called after the keystore password has been read from the stdin and the keystore is decrypted and - * loaded. The keystore and keystore passwords are available to classes extending {@link BaseKeyStoreCommand} - * using {@link BaseKeyStoreCommand#getKeyStore()} and {@link BaseKeyStoreCommand#getKeyStorePassword()} - * respectively. + * Executes the specific keystore command implementation. + * This is called after the keystore password has been read and the keystore + * is decrypted and loaded. The keystore and keystore passwords are available using + * {@link #getKeyStore()} and {@link #getKeyStorePassword()} respectively. + * + * @param terminal The terminal to use for user interaction + * @param options The command line options that were specified + * @param env The environment configuration + * @throws Exception if there is an error executing the command */ protected abstract void executeCommand(Terminal terminal, OptionSet options, Environment env) throws Exception; } diff --git a/server/src/main/java/org/opensearch/common/settings/ChangeKeyStorePasswordCommand.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/ChangeKeyStorePasswordCommand.java similarity index 70% rename from server/src/main/java/org/opensearch/common/settings/ChangeKeyStorePasswordCommand.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/ChangeKeyStorePasswordCommand.java index 74e09f6f233d5..79c8a0a25b916 100644 --- a/server/src/main/java/org/opensearch/common/settings/ChangeKeyStorePasswordCommand.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/ChangeKeyStorePasswordCommand.java @@ -30,12 +30,13 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import joptsimple.OptionSet; import org.opensearch.cli.ExitCodes; import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.core.common.settings.SecureString; import org.opensearch.env.Environment; @@ -44,12 +45,27 @@ * * @opensearch.internal */ -class ChangeKeyStorePasswordCommand extends BaseKeyStoreCommand { +public class ChangeKeyStorePasswordCommand extends BaseKeyStoreCommand { ChangeKeyStorePasswordCommand() { super("Changes the password of a keystore", true); } + /** + * Executes the password change command by prompting for a new password + * and saving the keystore with the updated password. + *

+ * This implementation will: + * 1. Prompt for a new password with verification + * 2. Save the keystore with the new password + * 3. Display a success message upon completion + * + * @param terminal The terminal to use for user interaction + * @param options The command-line options provided + * @param env The environment settings containing configuration directory + * @throws Exception if there are errors during password change + * @throws UserException if there are security-related errors + */ @Override protected void executeCommand(Terminal terminal, OptionSet options, Environment env) throws Exception { try (SecureString newPassword = readPassword(terminal, true)) { diff --git a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/CreateKeyStoreCommand.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/CreateKeyStoreCommand.java similarity index 96% rename from distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/CreateKeyStoreCommand.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/CreateKeyStoreCommand.java index a4ab98ce730ee..647b6aa6dbb85 100644 --- a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/CreateKeyStoreCommand.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/CreateKeyStoreCommand.java @@ -30,14 +30,14 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import joptsimple.OptionSet; import joptsimple.OptionSpec; import org.opensearch.cli.ExitCodes; -import org.opensearch.cli.KeyStoreAwareCommand; import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.core.common.settings.SecureString; import org.opensearch.env.Environment; diff --git a/server/src/main/java/org/opensearch/common/settings/HasPasswordKeyStoreCommand.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/HasPasswordKeyStoreCommand.java similarity index 70% rename from server/src/main/java/org/opensearch/common/settings/HasPasswordKeyStoreCommand.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/HasPasswordKeyStoreCommand.java index 59d8a44846e11..079a78fc41b14 100644 --- a/server/src/main/java/org/opensearch/common/settings/HasPasswordKeyStoreCommand.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/HasPasswordKeyStoreCommand.java @@ -30,18 +30,19 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import joptsimple.OptionSet; -import org.opensearch.cli.KeyStoreAwareCommand; import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.env.Environment; import java.nio.file.Path; /** - * KeyStore command that has a password. + * KeyStore command that checks if the keystore exists and is password-protected. + * Exits with a non-zero status code if the keystore is missing or not password-protected. * * @opensearch.internal */ @@ -49,12 +50,29 @@ public class HasPasswordKeyStoreCommand extends KeyStoreAwareCommand { static final int NO_PASSWORD_EXIT_CODE = 1; + /** + * Creates a new HasPasswordKeyStoreCommand. + * This command checks for the existence of a password-protected keystore + * and exits with {@link #NO_PASSWORD_EXIT_CODE} if the keystore is missing + * or not password-protected. + */ HasPasswordKeyStoreCommand() { super( "Succeeds if the keystore exists and is password-protected, " + "fails with exit code " + NO_PASSWORD_EXIT_CODE + " otherwise." ); } + /** + * Executes the password check command by verifying if the keystore exists + * and is password-protected. + * + * @param terminal The terminal for user interaction and output + * @param options The command-line options provided + * @param env The environment settings containing configuration directory + * @throws UserException with {@link #NO_PASSWORD_EXIT_CODE} if the keystore + * is missing or not password-protected + * @throws Exception if there are other errors during execution + */ @Override protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception { final Path configFile = env.configDir(); diff --git a/server/src/main/java/org/opensearch/cli/KeyStoreAwareCommand.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/KeyStoreAwareCommand.java similarity index 70% rename from server/src/main/java/org/opensearch/cli/KeyStoreAwareCommand.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/KeyStoreAwareCommand.java index 6cd266252b369..2deec53c788dc 100644 --- a/server/src/main/java/org/opensearch/cli/KeyStoreAwareCommand.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/KeyStoreAwareCommand.java @@ -30,9 +30,13 @@ * GitHub history for details. */ -package org.opensearch.cli; +package org.opensearch.tools.cli.keystore; import joptsimple.OptionSet; +import org.opensearch.cli.ExitCodes; +import org.opensearch.cli.Terminal; +import org.opensearch.cli.UserException; +import org.opensearch.common.cli.EnvironmentAwareCommand; import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.core.common.settings.SecureString; import org.opensearch.env.Environment; @@ -42,19 +46,22 @@ import java.util.Arrays; /** - * An {@link org.opensearch.cli.EnvironmentAwareCommand} that needs to access the opensearch keystore, possibly + * An {@link EnvironmentAwareCommand} that needs to access the opensearch keystore, possibly * decrypting it if it is password protected. * * @opensearch.internal */ public abstract class KeyStoreAwareCommand extends EnvironmentAwareCommand { + + /** + * Creates a new KeyStoreAwareCommand with the given description. + * + * @param description A description of the command's purpose and functionality + */ public KeyStoreAwareCommand(String description) { super(description); } - /** Arbitrarily chosen maximum passphrase length */ - public static final int MAX_PASSPHRASE_LENGTH = 128; - /** * Reads the keystore password from the {@link Terminal}, prompting for verification where applicable and returns it as a * {@link SecureString}. @@ -69,9 +76,9 @@ protected static SecureString readPassword(Terminal terminal, boolean withVerifi if (withVerification) { passwordArray = terminal.readSecret( "Enter new password for the opensearch keystore (empty for no password): ", - MAX_PASSPHRASE_LENGTH + EnvironmentAwareCommand.MAX_PASSPHRASE_LENGTH ); - char[] passwordVerification = terminal.readSecret("Enter same password again: ", MAX_PASSPHRASE_LENGTH); + char[] passwordVerification = terminal.readSecret("Enter same password again: ", EnvironmentAwareCommand.MAX_PASSPHRASE_LENGTH); if (Arrays.equals(passwordArray, passwordVerification) == false) { throw new UserException(ExitCodes.DATA_ERROR, "Passwords are not equal, exiting."); } @@ -83,7 +90,15 @@ protected static SecureString readPassword(Terminal terminal, boolean withVerifi } /** - * Decrypt the {@code keyStore}, prompting the user to enter the password in the {@link Terminal} if it is password protected + * Decrypts the provided keystore using a password obtained from the terminal. + * If the keystore is password-protected, prompts the user to enter the password. + * If not password-protected, uses an empty password. + * + * @param keyStore The keystore to decrypt + * @param terminal The terminal to use for password input + * @throws UserException If there is an error with the provided password + * @throws GeneralSecurityException If there is an error during decryption + * @throws IOException If there is an error reading from the terminal */ protected static void decryptKeyStore(KeyStoreWrapper keyStore, Terminal terminal) throws UserException, GeneralSecurityException, IOException { @@ -94,5 +109,13 @@ protected static void decryptKeyStore(KeyStoreWrapper keyStore, Terminal termina } } + /** + * Executes the keystore command with the given parameters. + * + * @param terminal The terminal to use for user interaction + * @param options The command-line options provided + * @param env The environment settings + * @throws Exception if there are any errors during execution + */ protected abstract void execute(Terminal terminal, OptionSet options, Environment env) throws Exception; } diff --git a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/KeyStoreCli.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/KeyStoreCli.java similarity index 95% rename from distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/KeyStoreCli.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/KeyStoreCli.java index 7a772526cd66b..4c7807be6a859 100644 --- a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/KeyStoreCli.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/KeyStoreCli.java @@ -30,10 +30,10 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; -import org.opensearch.cli.LoggingAwareMultiCommand; import org.opensearch.cli.Terminal; +import org.opensearch.common.cli.LoggingAwareMultiCommand; /** * A CLI tool for managing secrets in the OpenSearch keystore. diff --git a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/ListKeyStoreCommand.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/ListKeyStoreCommand.java similarity index 95% rename from distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/ListKeyStoreCommand.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/ListKeyStoreCommand.java index 379b61efc5d32..0e53a03a3c880 100644 --- a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/ListKeyStoreCommand.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/ListKeyStoreCommand.java @@ -30,10 +30,11 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import joptsimple.OptionSet; import org.opensearch.cli.Terminal; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.env.Environment; import java.util.ArrayList; diff --git a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/RemoveSettingKeyStoreCommand.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/RemoveSettingKeyStoreCommand.java similarity index 96% rename from distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/RemoveSettingKeyStoreCommand.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/RemoveSettingKeyStoreCommand.java index c57959117af15..aa05db0a9475b 100644 --- a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/RemoveSettingKeyStoreCommand.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/RemoveSettingKeyStoreCommand.java @@ -30,13 +30,14 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import joptsimple.OptionSet; import joptsimple.OptionSpec; import org.opensearch.cli.ExitCodes; import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.env.Environment; import java.util.List; diff --git a/server/src/main/java/org/opensearch/common/settings/UpgradeKeyStoreCommand.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/UpgradeKeyStoreCommand.java similarity index 64% rename from server/src/main/java/org/opensearch/common/settings/UpgradeKeyStoreCommand.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/UpgradeKeyStoreCommand.java index 46da933e3bf11..22dfbd7a48925 100644 --- a/server/src/main/java/org/opensearch/common/settings/UpgradeKeyStoreCommand.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/UpgradeKeyStoreCommand.java @@ -30,10 +30,11 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import joptsimple.OptionSet; import org.opensearch.cli.Terminal; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.env.Environment; /** @@ -43,10 +44,26 @@ */ public class UpgradeKeyStoreCommand extends BaseKeyStoreCommand { + /** + * Creates a new UpgradeKeyStoreCommand instance. + * Initializes a command that requires an existing keystore to upgrade its format + * to the latest version. This command will fail if the keystore doesn't exist. + */ UpgradeKeyStoreCommand() { super("Upgrade the keystore format", true); } + /** + * Executes the keystore upgrade command by upgrading the format of an existing keystore. + * Uses the current keystore and its password to create a new keystore with an upgraded format + * in the same location. + * + * @param terminal The terminal for user interaction and output messages + * @param options The command-line options provided + * @param env The environment settings containing the configuration directory + * @throws Exception if there are any errors during the upgrade process, + * such as IO errors or encryption/decryption issues + */ @Override protected void executeCommand(final Terminal terminal, final OptionSet options, final Environment env) throws Exception { KeyStoreWrapper.upgrade(getKeyStore(), env.configDir(), getKeyStorePassword().getChars()); diff --git a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/package-info.java b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/package-info.java similarity index 87% rename from distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/package-info.java rename to distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/package-info.java index 3969fb4f91e49..aa1a2075194fd 100644 --- a/distribution/tools/keystore-cli/src/main/java/org/opensearch/common/settings/package-info.java +++ b/distribution/tools/keystore-cli/src/main/java/org/opensearch/tools/cli/keystore/package-info.java @@ -9,4 +9,4 @@ /** * Classes implementing a CLI tool for managing secrets in the OpenSearch keystore. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; diff --git a/distribution/tools/keystore-cli/src/test/java/org/opensearch/bootstrap/BootstrapTests.java b/distribution/tools/keystore-cli/src/test/java/org/opensearch/bootstrap/BootstrapTests.java index e9219de218aef..149145bb2d66b 100644 --- a/distribution/tools/keystore-cli/src/test/java/org/opensearch/bootstrap/BootstrapTests.java +++ b/distribution/tools/keystore-cli/src/test/java/org/opensearch/bootstrap/BootstrapTests.java @@ -31,7 +31,6 @@ package org.opensearch.bootstrap; -import org.opensearch.common.settings.KeyStoreCommandTestCase; import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.common.settings.SecureSettings; import org.opensearch.common.settings.Settings; @@ -39,6 +38,7 @@ import org.opensearch.core.common.settings.SecureString; import org.opensearch.env.Environment; import org.opensearch.test.OpenSearchTestCase; +import org.opensearch.tools.cli.keystore.KeyStoreCommandTestCase; import org.junit.After; import org.junit.Before; diff --git a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/AddFileKeyStoreCommandTests.java b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/AddFileKeyStoreCommandTests.java similarity index 99% rename from distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/AddFileKeyStoreCommandTests.java rename to distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/AddFileKeyStoreCommandTests.java index b3cc7e10fdf8c..3d188590d5c47 100644 --- a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/AddFileKeyStoreCommandTests.java +++ b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/AddFileKeyStoreCommandTests.java @@ -30,12 +30,13 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import org.opensearch.cli.Command; import org.opensearch.cli.ExitCodes; import org.opensearch.cli.UserException; import org.opensearch.common.collect.Tuple; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.env.Environment; import java.io.IOException; diff --git a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/AddStringKeyStoreCommandTests.java b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/AddStringKeyStoreCommandTests.java similarity index 99% rename from distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/AddStringKeyStoreCommandTests.java rename to distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/AddStringKeyStoreCommandTests.java index 059c74ed8971c..22012d1f44986 100644 --- a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/AddStringKeyStoreCommandTests.java +++ b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/AddStringKeyStoreCommandTests.java @@ -30,11 +30,12 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import org.opensearch.cli.Command; import org.opensearch.cli.ExitCodes; import org.opensearch.cli.UserException; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.env.Environment; import java.io.ByteArrayInputStream; diff --git a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/ChangeKeyStorePasswordCommandTests.java b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/ChangeKeyStorePasswordCommandTests.java similarity index 99% rename from distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/ChangeKeyStorePasswordCommandTests.java rename to distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/ChangeKeyStorePasswordCommandTests.java index 55dbf59c8ad86..1ce57332a9a31 100644 --- a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/ChangeKeyStorePasswordCommandTests.java +++ b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/ChangeKeyStorePasswordCommandTests.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import org.opensearch.cli.Command; import org.opensearch.cli.ExitCodes; diff --git a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/CreateKeyStoreCommandTests.java b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/CreateKeyStoreCommandTests.java similarity index 97% rename from distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/CreateKeyStoreCommandTests.java rename to distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/CreateKeyStoreCommandTests.java index f554f17c50813..5a06bc2400176 100644 --- a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/CreateKeyStoreCommandTests.java +++ b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/CreateKeyStoreCommandTests.java @@ -30,11 +30,12 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import org.opensearch.cli.Command; import org.opensearch.cli.ExitCodes; import org.opensearch.cli.UserException; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.env.Environment; import java.nio.charset.StandardCharsets; diff --git a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/HasPasswordKeyStoreCommandTests.java b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/HasPasswordKeyStoreCommandTests.java similarity index 98% rename from distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/HasPasswordKeyStoreCommandTests.java rename to distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/HasPasswordKeyStoreCommandTests.java index 3b5abf30c4b85..9ebc92c55530b 100644 --- a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/HasPasswordKeyStoreCommandTests.java +++ b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/HasPasswordKeyStoreCommandTests.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import org.opensearch.cli.Command; import org.opensearch.cli.UserException; diff --git a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/KeyStoreCommandTestCase.java b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/KeyStoreCommandTestCase.java similarity index 97% rename from distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/KeyStoreCommandTestCase.java rename to distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/KeyStoreCommandTestCase.java index 0ac653d35b07e..b50d1f9c20081 100644 --- a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/KeyStoreCommandTestCase.java +++ b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/KeyStoreCommandTestCase.java @@ -30,13 +30,15 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; import org.apache.lucene.tests.util.LuceneTestCase; import org.opensearch.cli.CommandTestCase; import org.opensearch.common.io.PathUtilsForTesting; +import org.opensearch.common.settings.KeyStoreWrapper; +import org.opensearch.common.settings.Settings; import org.opensearch.common.util.io.IOUtils; import org.opensearch.env.Environment; import org.opensearch.env.TestEnvironment; diff --git a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/KeyStoreWrapperTests.java b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/KeyStoreWrapperTests.java similarity index 99% rename from distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/KeyStoreWrapperTests.java rename to distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/KeyStoreWrapperTests.java index 15771945fa199..efb833e8fd94a 100644 --- a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/KeyStoreWrapperTests.java +++ b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/KeyStoreWrapperTests.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil; import org.apache.lucene.codecs.CodecUtil; @@ -39,6 +39,7 @@ import org.apache.lucene.store.IndexOutput; import org.apache.lucene.store.NIOFSDirectory; import org.opensearch.common.Randomness; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.common.util.io.IOUtils; import org.opensearch.core.common.settings.SecureString; import org.opensearch.env.Environment; diff --git a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/ListKeyStoreCommandTests.java b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/ListKeyStoreCommandTests.java similarity index 98% rename from distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/ListKeyStoreCommandTests.java rename to distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/ListKeyStoreCommandTests.java index 42452d5c12beb..0846e28fb42af 100644 --- a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/ListKeyStoreCommandTests.java +++ b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/ListKeyStoreCommandTests.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import org.opensearch.cli.Command; import org.opensearch.cli.ExitCodes; diff --git a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/RemoveSettingKeyStoreCommandTests.java b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/RemoveSettingKeyStoreCommandTests.java similarity index 99% rename from distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/RemoveSettingKeyStoreCommandTests.java rename to distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/RemoveSettingKeyStoreCommandTests.java index 5dab6eec121bd..66d448400d4e3 100644 --- a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/RemoveSettingKeyStoreCommandTests.java +++ b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/RemoveSettingKeyStoreCommandTests.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import org.opensearch.cli.Command; import org.opensearch.cli.ExitCodes; diff --git a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/UpgradeKeyStoreCommandTests.java b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/UpgradeKeyStoreCommandTests.java similarity index 97% rename from distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/UpgradeKeyStoreCommandTests.java rename to distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/UpgradeKeyStoreCommandTests.java index 0fda83282c1f9..e27762de77020 100644 --- a/distribution/tools/keystore-cli/src/test/java/org/opensearch/common/settings/UpgradeKeyStoreCommandTests.java +++ b/distribution/tools/keystore-cli/src/test/java/org/opensearch/tools/cli/keystore/UpgradeKeyStoreCommandTests.java @@ -30,10 +30,11 @@ * GitHub history for details. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.keystore; import org.opensearch.cli.Command; import org.opensearch.cli.UserException; +import org.opensearch.common.settings.KeyStoreWrapper; import org.opensearch.env.Environment; import java.io.InputStream; diff --git a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/InstallPluginCommand.java b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/InstallPluginCommand.java similarity index 98% rename from distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/InstallPluginCommand.java rename to distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/InstallPluginCommand.java index d5a0102ba86af..1ab2697d5ced8 100644 --- a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/InstallPluginCommand.java +++ b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/InstallPluginCommand.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; import joptsimple.OptionSet; import joptsimple.OptionSpec; @@ -52,16 +52,19 @@ import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider; import org.opensearch.Build; import org.opensearch.Version; -import org.opensearch.cli.EnvironmentAwareCommand; import org.opensearch.cli.ExitCodes; import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; import org.opensearch.common.SuppressForbidden; import org.opensearch.common.bootstrap.JarHell; +import org.opensearch.common.cli.EnvironmentAwareCommand; import org.opensearch.common.collect.Tuple; import org.opensearch.common.hash.MessageDigests; import org.opensearch.common.util.io.IOUtils; import org.opensearch.env.Environment; +import org.opensearch.plugins.Platforms; +import org.opensearch.plugins.PluginInfo; +import org.opensearch.plugins.PluginsService; import java.io.BufferedReader; import java.io.IOException; @@ -92,7 +95,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -827,17 +829,7 @@ void jarHellCheck(PluginInfo candidateInfo, Path candidateDir, Path pluginsDir, }).collect(Collectors.toSet()); // read existing bundles. this does some checks on the installation too. - Set bundles = new HashSet<>(PluginsService.getPluginBundles(pluginsDir)); - bundles.addAll(PluginsService.getModuleBundles(modulesDir)); - bundles.add(new PluginsService.Bundle(candidateInfo, candidateDir)); - List sortedBundles = PluginsService.sortBundles(bundles); - - // check jarhell of all plugins so we know this plugin and anything depending on it are ok together - // TODO: optimize to skip any bundles not connected to the candidate plugin? - Map> transitiveUrls = new HashMap<>(); - for (PluginsService.Bundle bundle : sortedBundles) { - PluginsService.checkBundleJarHell(classpath, bundle, transitiveUrls); - } + PluginsService.checkJarHellForPlugin(classpath, candidateInfo, candidateDir, pluginsDir, modulesDir); // TODO: no jars should be an error // TODO: verify the classname exists in one of the jars! diff --git a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/ListPluginsCommand.java b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/ListPluginsCommand.java similarity index 94% rename from distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/ListPluginsCommand.java rename to distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/ListPluginsCommand.java index 9ca42ac5f4ec1..a54c02651549c 100644 --- a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/ListPluginsCommand.java +++ b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/ListPluginsCommand.java @@ -30,13 +30,15 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; import joptsimple.OptionSet; import org.opensearch.Version; -import org.opensearch.cli.EnvironmentAwareCommand; import org.opensearch.cli.Terminal; +import org.opensearch.common.cli.EnvironmentAwareCommand; import org.opensearch.env.Environment; +import org.opensearch.plugins.PluginInfo; +import org.opensearch.plugins.PluginsService; import java.io.IOException; import java.nio.file.DirectoryStream; diff --git a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/PluginCli.java b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/PluginCli.java similarity index 95% rename from distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/PluginCli.java rename to distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/PluginCli.java index f87b72c7ecb5f..929b8bfe59ddb 100644 --- a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/PluginCli.java +++ b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/PluginCli.java @@ -30,11 +30,11 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; import org.opensearch.cli.Command; -import org.opensearch.cli.LoggingAwareMultiCommand; import org.opensearch.cli.Terminal; +import org.opensearch.common.cli.LoggingAwareMultiCommand; import org.opensearch.common.util.io.IOUtils; import java.io.IOException; diff --git a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/PluginHelper.java b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/PluginHelper.java similarity index 95% rename from distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/PluginHelper.java rename to distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/PluginHelper.java index 13d8ab62c1f8d..334f0f4f14924 100644 --- a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/PluginHelper.java +++ b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/PluginHelper.java @@ -6,7 +6,9 @@ * compatible open source license. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; + +import org.opensearch.plugins.PluginInfo; import java.io.IOException; import java.nio.file.Files; diff --git a/server/src/main/java/org/opensearch/plugins/PluginSecurity.java b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/PluginSecurity.java similarity index 98% rename from server/src/main/java/org/opensearch/plugins/PluginSecurity.java rename to distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/PluginSecurity.java index 1bf8642d1112f..81d7824812361 100644 --- a/server/src/main/java/org/opensearch/plugins/PluginSecurity.java +++ b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/PluginSecurity.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; import org.opensearch.cli.ExitCodes; import org.opensearch.cli.Terminal; @@ -136,7 +136,7 @@ static String formatPermission(Permission permission) { * Parses plugin policy into a set of permissions. Each permission is formatted for output to users. */ @SuppressWarnings("removal") - public static Set parsePermissions(Path file, Path tmpDir) throws IOException { + static Set parsePermissions(Path file, Path tmpDir) throws IOException { // create a zero byte file for "comparison" // this is necessary because the default policy impl automatically grants two permissions: // 1. permission to exitVM (which we ignore) diff --git a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/ProgressInputStream.java b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/ProgressInputStream.java similarity index 98% rename from distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/ProgressInputStream.java rename to distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/ProgressInputStream.java index 02be3dbc82a44..7f79ba3f4f4df 100644 --- a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/ProgressInputStream.java +++ b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/ProgressInputStream.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; import java.io.FilterInputStream; import java.io.IOException; diff --git a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/RemovePluginCommand.java b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/RemovePluginCommand.java similarity index 94% rename from distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/RemovePluginCommand.java rename to distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/RemovePluginCommand.java index 4ac99c816717a..2478a05c3a9cb 100644 --- a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/RemovePluginCommand.java +++ b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/RemovePluginCommand.java @@ -30,16 +30,17 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; import joptsimple.OptionSet; import joptsimple.OptionSpec; -import org.opensearch.cli.EnvironmentAwareCommand; import org.opensearch.cli.ExitCodes; import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; +import org.opensearch.common.cli.EnvironmentAwareCommand; import org.opensearch.common.util.io.IOUtils; import org.opensearch.env.Environment; +import org.opensearch.plugins.PluginsService; import java.io.IOException; import java.nio.file.FileAlreadyExistsException; @@ -49,7 +50,6 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; -import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -98,15 +98,7 @@ void execute(Terminal terminal, Environment env, String pluginName, boolean purg } // first make sure nothing extends this plugin - List usedBy = new ArrayList<>(); - Set bundles = PluginsService.getPluginBundles(env.pluginsDir()); - for (PluginsService.Bundle bundle : bundles) { - for (String extendedPlugin : bundle.plugin.getExtendedPlugins()) { - if (extendedPlugin.equals(pluginName)) { - usedBy.add(bundle.plugin.getName()); - } - } - } + List usedBy = PluginsService.findPluginsByDependency(env.pluginsDir(), pluginName); if (usedBy.isEmpty() == false) { throw new UserException( PLUGIN_STILL_USED, diff --git a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/package-info.java b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/package-info.java similarity index 87% rename from distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/package-info.java rename to distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/package-info.java index b762e59ae8095..b676f8db01a84 100644 --- a/distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/package-info.java +++ b/distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/package-info.java @@ -9,4 +9,4 @@ /** * Classes implementing a CLI tool for managing plugins in OpenSearch. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; diff --git a/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/InstallPluginCommandTests.java b/distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/InstallPluginCommandTests.java similarity index 99% rename from distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/InstallPluginCommandTests.java rename to distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/InstallPluginCommandTests.java index e6c1070f36066..56ef09c5c9128 100644 --- a/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/InstallPluginCommandTests.java +++ b/distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/InstallPluginCommandTests.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; @@ -70,6 +70,9 @@ import org.opensearch.core.util.FileSystemUtils; import org.opensearch.env.Environment; import org.opensearch.env.TestEnvironment; +import org.opensearch.plugins.Platforms; +import org.opensearch.plugins.PluginInfo; +import org.opensearch.plugins.PluginTestUtil; import org.opensearch.semver.SemverRange; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.test.PosixPermissionsResetter; diff --git a/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/ListPluginsCommandTests.java b/distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/ListPluginsCommandTests.java similarity index 98% rename from distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/ListPluginsCommandTests.java rename to distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/ListPluginsCommandTests.java index 6878efce4c804..7fcdab907cbf0 100644 --- a/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/ListPluginsCommandTests.java +++ b/distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/ListPluginsCommandTests.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; import org.apache.lucene.tests.util.LuceneTestCase; import org.opensearch.LegacyESVersion; @@ -41,6 +41,8 @@ import org.opensearch.common.settings.Settings; import org.opensearch.env.Environment; import org.opensearch.env.TestEnvironment; +import org.opensearch.plugins.PluginInfo; +import org.opensearch.plugins.PluginTestUtil; import org.opensearch.test.OpenSearchTestCase; import org.junit.Before; diff --git a/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/ProgressInputStreamTests.java b/distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/ProgressInputStreamTests.java similarity index 98% rename from distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/ProgressInputStreamTests.java rename to distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/ProgressInputStreamTests.java index 13af003591cfa..d045c4256f08c 100644 --- a/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/ProgressInputStreamTests.java +++ b/distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/ProgressInputStreamTests.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; import org.opensearch.test.OpenSearchTestCase; diff --git a/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/RemovePluginCommandTests.java b/distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/RemovePluginCommandTests.java similarity index 99% rename from distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/RemovePluginCommandTests.java rename to distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/RemovePluginCommandTests.java index ab23dfad75683..10d5a376d8289 100644 --- a/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/RemovePluginCommandTests.java +++ b/distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/RemovePluginCommandTests.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; import org.apache.lucene.tests.util.LuceneTestCase; import org.opensearch.Version; @@ -40,6 +40,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.env.Environment; import org.opensearch.env.TestEnvironment; +import org.opensearch.plugins.PluginTestUtil; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.test.VersionUtils; import org.junit.Before; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/DetectEsInstallationTask.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/DetectEsInstallationTask.java similarity index 99% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/DetectEsInstallationTask.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/DetectEsInstallationTask.java index 90067ffd221bf..de2d24dc61ce1 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/DetectEsInstallationTask.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/DetectEsInstallationTask.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportJvmOptionsTask.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportJvmOptionsTask.java similarity index 97% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportJvmOptionsTask.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportJvmOptionsTask.java index 555c553578155..fcb23f02425c6 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportJvmOptionsTask.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportJvmOptionsTask.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import org.opensearch.cli.Terminal; import org.opensearch.common.collect.Tuple; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportKeystoreTask.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportKeystoreTask.java similarity index 96% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportKeystoreTask.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportKeystoreTask.java index 5d35a7fcc0463..f2f36ab3bbe0e 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportKeystoreTask.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportKeystoreTask.java @@ -6,12 +6,11 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import org.opensearch.cli.Terminal; import org.opensearch.common.collect.Tuple; import org.opensearch.common.settings.KeyStoreWrapper; -import org.opensearch.common.settings.KeystoreWrapperUtil; import org.opensearch.core.common.settings.SecureString; import java.io.InputStream; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportLog4jPropertiesTask.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportLog4jPropertiesTask.java similarity index 98% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportLog4jPropertiesTask.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportLog4jPropertiesTask.java index 7934ba43ccfaa..da999a3f91f08 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportLog4jPropertiesTask.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportLog4jPropertiesTask.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import org.opensearch.cli.Terminal; import org.opensearch.common.collect.Tuple; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportYmlConfigTask.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportYmlConfigTask.java similarity index 99% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportYmlConfigTask.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportYmlConfigTask.java index 6e29bd2d04239..2ba8f93cd53ac 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ImportYmlConfigTask.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ImportYmlConfigTask.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import org.opensearch.cli.Terminal; import org.opensearch.common.collect.Tuple; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/InstallPluginsTask.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/InstallPluginsTask.java similarity index 99% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/InstallPluginsTask.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/InstallPluginsTask.java index 781a56e4b53d9..ae2335752bed0 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/InstallPluginsTask.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/InstallPluginsTask.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import org.opensearch.cli.Terminal; import org.opensearch.common.collect.Tuple; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/common/settings/KeystoreWrapperUtil.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/KeystoreWrapperUtil.java similarity index 89% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/common/settings/KeystoreWrapperUtil.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/KeystoreWrapperUtil.java index f9300b6555478..3ef7d09edc046 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/common/settings/KeystoreWrapperUtil.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/KeystoreWrapperUtil.java @@ -6,7 +6,9 @@ * compatible open source license. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.upgrade; + +import org.opensearch.common.settings.KeyStoreWrapper; /** * Utility that has package level access to the {@link KeyStoreWrapper} for diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/TaskInput.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/TaskInput.java similarity index 98% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/TaskInput.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/TaskInput.java index 2fbd5d9a0fa7c..b3c5604275b54 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/TaskInput.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/TaskInput.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import org.opensearch.Version; import org.opensearch.env.Environment; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/UpgradeCli.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/UpgradeCli.java similarity index 95% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/UpgradeCli.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/UpgradeCli.java index e625ad333d218..f609d06b8ed34 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/UpgradeCli.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/UpgradeCli.java @@ -6,13 +6,13 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import joptsimple.OptionSet; -import org.opensearch.cli.EnvironmentAwareCommand; import org.opensearch.cli.ExitCodes; import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; +import org.opensearch.common.cli.EnvironmentAwareCommand; import org.opensearch.common.collect.Tuple; import org.opensearch.env.Environment; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/UpgradeTask.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/UpgradeTask.java similarity index 97% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/UpgradeTask.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/UpgradeTask.java index 708f644bcdeb6..8f84dd8c9817c 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/UpgradeTask.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/UpgradeTask.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import org.opensearch.cli.Terminal; import org.opensearch.common.collect.Tuple; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ValidateInputTask.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ValidateInputTask.java similarity index 98% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ValidateInputTask.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ValidateInputTask.java index 95e055cedda43..bea524e651827 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/ValidateInputTask.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/ValidateInputTask.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import org.opensearch.LegacyESVersion; import org.opensearch.Version; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/common/settings/package-info.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/package-info.java similarity index 87% rename from distribution/tools/upgrade-cli/src/main/java/org/opensearch/common/settings/package-info.java rename to distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/package-info.java index b3a4e9512639a..86ecef5ae5576 100644 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/common/settings/package-info.java +++ b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/tools/cli/upgrade/package-info.java @@ -9,4 +9,4 @@ /** * This exists to get access to the package level methods of KeyStoreWrapper. */ -package org.opensearch.common.settings; +package org.opensearch.tools.cli.upgrade; diff --git a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/package-info.java b/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/package-info.java deleted file mode 100644 index d66b1c9503d9b..0000000000000 --- a/distribution/tools/upgrade-cli/src/main/java/org/opensearch/upgrade/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -/** - * This package contains the classes for the upgrade CLI tool. - * This tool automates the configuring of a node that is to be upgraded to - * OpenSearch from an existing Elasticsearch (v7.10.2 and v6.8.0) installation. - */ - -/** - * Contains the classes which implement a CLI tool for opensearch-upgrade which is - * bundled into the distribution and available inside $ES_HOME/bin. - */ -package org.opensearch.upgrade; diff --git a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/DetectEsInstallationTaskTests.java b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/DetectEsInstallationTaskTests.java similarity index 98% rename from distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/DetectEsInstallationTaskTests.java rename to distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/DetectEsInstallationTaskTests.java index a1391ba70a8e8..e653b3fa8d284 100644 --- a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/DetectEsInstallationTaskTests.java +++ b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/DetectEsInstallationTaskTests.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import org.opensearch.cli.MockTerminal; import org.opensearch.cli.Terminal; diff --git a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ImportLog4jPropertiesTaskTests.java b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/ImportLog4jPropertiesTaskTests.java similarity index 98% rename from distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ImportLog4jPropertiesTaskTests.java rename to distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/ImportLog4jPropertiesTaskTests.java index 529253c9ce824..8136504b15462 100644 --- a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ImportLog4jPropertiesTaskTests.java +++ b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/ImportLog4jPropertiesTaskTests.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; diff --git a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ImportYmlConfigTaskTests.java b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/ImportYmlConfigTaskTests.java similarity index 98% rename from distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ImportYmlConfigTaskTests.java rename to distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/ImportYmlConfigTaskTests.java index be03470b201a1..38dfebce7f21b 100644 --- a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ImportYmlConfigTaskTests.java +++ b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/ImportYmlConfigTaskTests.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; diff --git a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/InstallPluginsTaskTests.java b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/InstallPluginsTaskTests.java similarity index 98% rename from distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/InstallPluginsTaskTests.java rename to distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/InstallPluginsTaskTests.java index 46e189a4765d0..e7ac68331a8ca 100644 --- a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/InstallPluginsTaskTests.java +++ b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/InstallPluginsTaskTests.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import org.opensearch.cli.MockTerminal; import org.opensearch.common.collect.Tuple; diff --git a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/UpgradeCliTests.java b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/UpgradeCliTests.java similarity index 99% rename from distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/UpgradeCliTests.java rename to distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/UpgradeCliTests.java index a139480c71a2f..c1d1ca55ca315 100644 --- a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/UpgradeCliTests.java +++ b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/UpgradeCliTests.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; diff --git a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ValidateInputTaskTests.java b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/ValidateInputTaskTests.java similarity index 98% rename from distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ValidateInputTaskTests.java rename to distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/ValidateInputTaskTests.java index b9a536afb1361..91d708984deb4 100644 --- a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ValidateInputTaskTests.java +++ b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/tools/cli/upgrade/ValidateInputTaskTests.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.upgrade; +package org.opensearch.tools.cli.upgrade; import org.opensearch.LegacyESVersion; import org.opensearch.cli.MockTerminal; diff --git a/libs/cli/build.gradle b/libs/cli/build.gradle index a58c4dafac874..2e5d84a0cab0b 100644 --- a/libs/cli/build.gradle +++ b/libs/cli/build.gradle @@ -33,11 +33,11 @@ apply plugin: 'opensearch.publish' dependencies { api 'net.sf.jopt-simple:jopt-simple:5.0.4' api project(':libs:opensearch-common') -} -test.enabled = false -// Since CLI does not depend on :server, it cannot run the jarHell task -jarHell.enabled = false + testImplementation(project(":test:framework")) { + exclude group: 'org.opensearch', module: 'opensearch-cli' + } +} tasks.named('forbiddenApisMain').configure { replaceSignatureFiles 'jdk-signatures' diff --git a/libs/cli/src/main/java/org/opensearch/cli/Command.java b/libs/cli/src/main/java/org/opensearch/cli/Command.java index cc9230bdb2282..c2ae43946a8c8 100644 --- a/libs/cli/src/main/java/org/opensearch/cli/Command.java +++ b/libs/cli/src/main/java/org/opensearch/cli/Command.java @@ -119,7 +119,7 @@ public final int main(String[] args, Terminal terminal) throws Exception { /** * Executes the command, but all errors are thrown. */ - void mainWithoutErrorHandling(String[] args, Terminal terminal) throws Exception { + protected void mainWithoutErrorHandling(String[] args, Terminal terminal) throws Exception { final OptionSet options = parser.parse(args); if (options.has(helpOption)) { diff --git a/server/src/test/java/org/opensearch/cli/CommandTests.java b/libs/cli/src/test/java/org/opensearch/cli/CommandTests.java similarity index 100% rename from server/src/test/java/org/opensearch/cli/CommandTests.java rename to libs/cli/src/test/java/org/opensearch/cli/CommandTests.java diff --git a/server/src/test/java/org/opensearch/cli/MultiCommandTests.java b/libs/cli/src/test/java/org/opensearch/cli/MultiCommandTests.java similarity index 100% rename from server/src/test/java/org/opensearch/cli/MultiCommandTests.java rename to libs/cli/src/test/java/org/opensearch/cli/MultiCommandTests.java diff --git a/server/src/test/java/org/opensearch/cli/TerminalTests.java b/libs/cli/src/test/java/org/opensearch/cli/TerminalTests.java similarity index 100% rename from server/src/test/java/org/opensearch/cli/TerminalTests.java rename to libs/cli/src/test/java/org/opensearch/cli/TerminalTests.java diff --git a/libs/plugin-classloader/src/main/java/org/opensearch/plugins/ExtendedPluginsClassLoader.java b/libs/plugin-classloader/src/main/java/org/opensearch/plugin_classloader/ExtendedPluginsClassLoader.java similarity index 98% rename from libs/plugin-classloader/src/main/java/org/opensearch/plugins/ExtendedPluginsClassLoader.java rename to libs/plugin-classloader/src/main/java/org/opensearch/plugin_classloader/ExtendedPluginsClassLoader.java index 969fa91b50538..a5c028e69dbb0 100644 --- a/libs/plugin-classloader/src/main/java/org/opensearch/plugins/ExtendedPluginsClassLoader.java +++ b/libs/plugin-classloader/src/main/java/org/opensearch/plugin_classloader/ExtendedPluginsClassLoader.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.plugin_classloader; import java.security.AccessController; import java.security.PrivilegedAction; diff --git a/qa/evil-tests/build.gradle b/qa/evil-tests/build.gradle index 91cb4c7151a69..681ca0c712bb2 100644 --- a/qa/evil-tests/build.gradle +++ b/qa/evil-tests/build.gradle @@ -41,6 +41,7 @@ apply plugin: 'opensearch.standalone-test' dependencies { testImplementation 'com.google.jimfs:jimfs:1.3.0' + testImplementation project(':distribution:tools:plugin-cli') } // TODO: give each evil test its own fresh JVM for more isolation. diff --git a/qa/evil-tests/src/test/java/org/opensearch/cli/EvilEnvironmentAwareCommandTests.java b/qa/evil-tests/src/test/java/org/opensearch/cli/EvilEnvironmentAwareCommandTests.java index 2d232e9694de6..b4164d40081f2 100644 --- a/qa/evil-tests/src/test/java/org/opensearch/cli/EvilEnvironmentAwareCommandTests.java +++ b/qa/evil-tests/src/test/java/org/opensearch/cli/EvilEnvironmentAwareCommandTests.java @@ -35,6 +35,7 @@ import joptsimple.OptionSet; import org.apache.lucene.tests.util.TestRuleRestoreSystemProperties; import org.opensearch.common.SuppressForbidden; +import org.opensearch.common.cli.EnvironmentAwareCommand; import org.opensearch.env.Environment; import org.opensearch.test.OpenSearchTestCase; import org.junit.Rule; diff --git a/qa/evil-tests/src/test/java/org/opensearch/plugins/PluginSecurityTests.java b/qa/evil-tests/src/test/java/org/opensearch/tools/cli/plugin/PluginSecurityTests.java similarity index 92% rename from qa/evil-tests/src/test/java/org/opensearch/plugins/PluginSecurityTests.java rename to qa/evil-tests/src/test/java/org/opensearch/tools/cli/plugin/PluginSecurityTests.java index 04eae95f6fe12..fc210d2ba152d 100644 --- a/qa/evil-tests/src/test/java/org/opensearch/plugins/PluginSecurityTests.java +++ b/qa/evil-tests/src/test/java/org/opensearch/tools/cli/plugin/PluginSecurityTests.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.plugins; +package org.opensearch.tools.cli.plugin; import org.opensearch.test.OpenSearchTestCase; @@ -50,7 +50,7 @@ public void testParsePermissions() throws Exception { "test cannot run with security manager enabled", System.getSecurityManager() == null); Path scratch = createTempDir(); - Path testFile = this.getDataPath("security/simple-plugin-security.policy"); + Path testFile = this.getDataPath("simple-plugin-security.policy"); Set actual = PluginSecurity.parsePermissions(testFile, scratch); assertThat(actual, contains(PluginSecurity.formatPermission(new RuntimePermission("queuePrintJob")))); } @@ -61,7 +61,7 @@ public void testParseTwoPermissions() throws Exception { "test cannot run with security manager enabled", System.getSecurityManager() == null); Path scratch = createTempDir(); - Path testFile = this.getDataPath("security/complex-plugin-security.policy"); + Path testFile = this.getDataPath("complex-plugin-security.policy"); Set actual = PluginSecurity.parsePermissions(testFile, scratch); assertThat(actual, containsInAnyOrder( PluginSecurity.formatPermission(new RuntimePermission("getClassLoader")), @@ -81,7 +81,7 @@ public void testFormatUnresolvedPermission() throws Exception { "test cannot run with security manager enabled", System.getSecurityManager() == null); Path scratch = createTempDir(); - Path testFile = this.getDataPath("security/unresolved-plugin-security.policy"); + Path testFile = this.getDataPath("unresolved-plugin-security.policy"); Set permissions = PluginSecurity.parsePermissions(testFile, scratch); assertThat(permissions, contains("org.fake.FakePermission fakeName")); } diff --git a/qa/evil-tests/src/test/resources/org/opensearch/plugins/security/complex-plugin-security.policy b/qa/evil-tests/src/test/resources/org/opensearch/tools/cli/plugin/complex-plugin-security.policy similarity index 100% rename from qa/evil-tests/src/test/resources/org/opensearch/plugins/security/complex-plugin-security.policy rename to qa/evil-tests/src/test/resources/org/opensearch/tools/cli/plugin/complex-plugin-security.policy diff --git a/qa/evil-tests/src/test/resources/org/opensearch/plugins/security/simple-plugin-security.policy b/qa/evil-tests/src/test/resources/org/opensearch/tools/cli/plugin/simple-plugin-security.policy similarity index 100% rename from qa/evil-tests/src/test/resources/org/opensearch/plugins/security/simple-plugin-security.policy rename to qa/evil-tests/src/test/resources/org/opensearch/tools/cli/plugin/simple-plugin-security.policy diff --git a/qa/evil-tests/src/test/resources/org/opensearch/plugins/security/unresolved-plugin-security.policy b/qa/evil-tests/src/test/resources/org/opensearch/tools/cli/plugin/unresolved-plugin-security.policy similarity index 100% rename from qa/evil-tests/src/test/resources/org/opensearch/plugins/security/unresolved-plugin-security.policy rename to qa/evil-tests/src/test/resources/org/opensearch/tools/cli/plugin/unresolved-plugin-security.policy diff --git a/qa/smoke-test-http/src/test/java/org/opensearch/http/IdentityAuthenticationIT.java b/qa/smoke-test-http/src/test/java/org/opensearch/http/IdentityAuthenticationIT.java index 14346b8910c76..3936a142945a4 100644 --- a/qa/smoke-test-http/src/test/java/org/opensearch/http/IdentityAuthenticationIT.java +++ b/qa/smoke-test-http/src/test/java/org/opensearch/http/IdentityAuthenticationIT.java @@ -17,7 +17,6 @@ import org.opensearch.client.Response; import org.opensearch.client.ResponseException; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.FeatureFlags; import org.opensearch.identity.shiro.ShiroIdentityPlugin; import org.opensearch.plugins.Plugin; import org.opensearch.core.rest.RestStatus; diff --git a/server/src/main/java/org/opensearch/bootstrap/Bootstrap.java b/server/src/main/java/org/opensearch/bootstrap/Bootstrap.java index 95498f2bcbcd1..b40ac67b04917 100644 --- a/server/src/main/java/org/opensearch/bootstrap/Bootstrap.java +++ b/server/src/main/java/org/opensearch/bootstrap/Bootstrap.java @@ -42,12 +42,12 @@ import org.apache.lucene.util.StringHelper; import org.opensearch.OpenSearchException; import org.opensearch.Version; -import org.opensearch.cli.KeyStoreAwareCommand; import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; import org.opensearch.common.PidFile; import org.opensearch.common.SuppressForbidden; import org.opensearch.common.bootstrap.JarHell; +import org.opensearch.common.cli.EnvironmentAwareCommand; import org.opensearch.common.inject.CreationException; import org.opensearch.common.logging.LogConfigurator; import org.opensearch.common.logging.Loggers; @@ -263,7 +263,7 @@ static SecureSettings loadSecureSettings(Environment initialEnv) throws Bootstra SecureString password; try { if (keystore != null && keystore.hasPassword()) { - password = readPassphrase(System.in, KeyStoreAwareCommand.MAX_PASSPHRASE_LENGTH); + password = readPassphrase(System.in, EnvironmentAwareCommand.MAX_PASSPHRASE_LENGTH); } else { password = new SecureString(new char[0]); } diff --git a/server/src/main/java/org/opensearch/bootstrap/OpenSearch.java b/server/src/main/java/org/opensearch/bootstrap/OpenSearch.java index 8eb4f841b9671..162b9be318cd5 100644 --- a/server/src/main/java/org/opensearch/bootstrap/OpenSearch.java +++ b/server/src/main/java/org/opensearch/bootstrap/OpenSearch.java @@ -37,10 +37,10 @@ import joptsimple.OptionSpecBuilder; import joptsimple.util.PathConverter; import org.opensearch.Build; -import org.opensearch.cli.EnvironmentAwareCommand; import org.opensearch.cli.ExitCodes; import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; +import org.opensearch.common.cli.EnvironmentAwareCommand; import org.opensearch.common.logging.LogConfigurator; import org.opensearch.env.Environment; import org.opensearch.monitor.jvm.JvmInfo; diff --git a/server/src/main/java/org/opensearch/cli/LoggingAwareCommand.java b/server/src/main/java/org/opensearch/cli/LoggingAwareCommand.java deleted file mode 100644 index 07a6b7d523a33..0000000000000 --- a/server/src/main/java/org/opensearch/cli/LoggingAwareCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -package org.opensearch.cli; - -/** - * A command that is aware of logging. This class should be preferred over the base {@link Command} class for any CLI tools that depend on - * core OpenSearch as they could directly or indirectly touch classes that touch logging and as such logging needs to be configured. - * - * @opensearch.internal - */ -public abstract class LoggingAwareCommand extends Command { - - /** - * Construct the command with the specified command description. This command will have logging configured without reading OpenSearch - * configuration files. - * - * @param description the command description - */ - public LoggingAwareCommand(final String description) { - super(description, CommandLoggingConfigurator::configureLoggingWithoutConfig); - } - -} diff --git a/server/src/main/java/org/opensearch/cluster/coordination/NodeToolCli.java b/server/src/main/java/org/opensearch/cluster/coordination/NodeToolCli.java index 7d51002150fb9..f895bb07d5b87 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/NodeToolCli.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/NodeToolCli.java @@ -31,9 +31,9 @@ package org.opensearch.cluster.coordination; -import org.opensearch.cli.CommandLoggingConfigurator; import org.opensearch.cli.MultiCommand; import org.opensearch.cli.Terminal; +import org.opensearch.common.cli.CommandLoggingConfigurator; import org.opensearch.env.NodeRepurposeCommand; import org.opensearch.env.OverrideNodeVersionCommand; diff --git a/server/src/main/java/org/opensearch/cluster/coordination/OpenSearchNodeCommand.java b/server/src/main/java/org/opensearch/cluster/coordination/OpenSearchNodeCommand.java index 896fe6fc8024b..92b88cab2dd70 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/OpenSearchNodeCommand.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/OpenSearchNodeCommand.java @@ -40,7 +40,6 @@ import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.admin.indices.rollover.Condition; -import org.opensearch.cli.EnvironmentAwareCommand; import org.opensearch.cli.Terminal; import org.opensearch.cli.UserException; import org.opensearch.cluster.ClusterModule; @@ -50,6 +49,7 @@ import org.opensearch.cluster.metadata.ComponentTemplateMetadata; import org.opensearch.cluster.metadata.DataStreamMetadata; import org.opensearch.cluster.metadata.Metadata; +import org.opensearch.common.cli.EnvironmentAwareCommand; import org.opensearch.common.collect.Tuple; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; diff --git a/server/src/main/java/org/opensearch/cli/CommandLoggingConfigurator.java b/server/src/main/java/org/opensearch/common/cli/CommandLoggingConfigurator.java similarity index 98% rename from server/src/main/java/org/opensearch/cli/CommandLoggingConfigurator.java rename to server/src/main/java/org/opensearch/common/cli/CommandLoggingConfigurator.java index 8918725472160..a25cfb7de3b66 100644 --- a/server/src/main/java/org/opensearch/cli/CommandLoggingConfigurator.java +++ b/server/src/main/java/org/opensearch/common/cli/CommandLoggingConfigurator.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.cli; +package org.opensearch.common.cli; import org.apache.logging.log4j.Level; import org.opensearch.common.logging.LogConfigurator; diff --git a/server/src/main/java/org/opensearch/cli/EnvironmentAwareCommand.java b/server/src/main/java/org/opensearch/common/cli/EnvironmentAwareCommand.java similarity index 96% rename from server/src/main/java/org/opensearch/cli/EnvironmentAwareCommand.java rename to server/src/main/java/org/opensearch/common/cli/EnvironmentAwareCommand.java index 10c59ef673050..a2db1d275c24b 100644 --- a/server/src/main/java/org/opensearch/cli/EnvironmentAwareCommand.java +++ b/server/src/main/java/org/opensearch/common/cli/EnvironmentAwareCommand.java @@ -30,11 +30,15 @@ * GitHub history for details. */ -package org.opensearch.cli; +package org.opensearch.common.cli; import joptsimple.OptionSet; import joptsimple.OptionSpec; import joptsimple.util.KeyValuePair; +import org.opensearch.cli.Command; +import org.opensearch.cli.ExitCodes; +import org.opensearch.cli.Terminal; +import org.opensearch.cli.UserException; import org.opensearch.common.SuppressForbidden; import org.opensearch.common.settings.Settings; import org.opensearch.env.Environment; @@ -53,6 +57,8 @@ */ public abstract class EnvironmentAwareCommand extends Command { + public static final int MAX_PASSPHRASE_LENGTH = 128; + private final OptionSpec settingOption; /** diff --git a/server/src/main/java/org/opensearch/cli/LoggingAwareMultiCommand.java b/server/src/main/java/org/opensearch/common/cli/LoggingAwareMultiCommand.java similarity index 96% rename from server/src/main/java/org/opensearch/cli/LoggingAwareMultiCommand.java rename to server/src/main/java/org/opensearch/common/cli/LoggingAwareMultiCommand.java index 8453ed05a12d3..ff46e44b6faa5 100644 --- a/server/src/main/java/org/opensearch/cli/LoggingAwareMultiCommand.java +++ b/server/src/main/java/org/opensearch/common/cli/LoggingAwareMultiCommand.java @@ -30,7 +30,9 @@ * GitHub history for details. */ -package org.opensearch.cli; +package org.opensearch.common.cli; + +import org.opensearch.cli.MultiCommand; /** * A multi-command that is aware of logging. This class should be preferred over the base {@link MultiCommand} class for any CLI tools that diff --git a/server/src/main/java/org/opensearch/cli/package-info.java b/server/src/main/java/org/opensearch/common/cli/package-info.java similarity index 87% rename from server/src/main/java/org/opensearch/cli/package-info.java rename to server/src/main/java/org/opensearch/common/cli/package-info.java index 8e9f9f6360870..3150d87f323dc 100644 --- a/server/src/main/java/org/opensearch/cli/package-info.java +++ b/server/src/main/java/org/opensearch/common/cli/package-info.java @@ -9,4 +9,4 @@ /** * The command line interface module. */ -package org.opensearch.cli; +package org.opensearch.common.cli; diff --git a/server/src/main/java/org/opensearch/common/settings/KeyStoreWrapper.java b/server/src/main/java/org/opensearch/common/settings/KeyStoreWrapper.java index 1ad3b7ab8875a..ed58e6b21e165 100644 --- a/server/src/main/java/org/opensearch/common/settings/KeyStoreWrapper.java +++ b/server/src/main/java/org/opensearch/common/settings/KeyStoreWrapper.java @@ -134,7 +134,7 @@ private static class Entry { private static final String KEYSTORE_FILENAME = "opensearch.keystore"; /** The version of the metadata written before the keystore data. */ - static final int FORMAT_VERSION = 4; + public static final int FORMAT_VERSION = 4; /** The oldest metadata format version that can be read. */ private static final int MIN_FORMAT_VERSION = 1; @@ -631,7 +631,7 @@ public static void validateSettingName(String setting) { /** * Set a string setting. */ - synchronized void setString(String setting, char[] value) { + public synchronized void setString(String setting, char[] value) { ensureOpen(); validateSettingName(setting); @@ -646,7 +646,7 @@ synchronized void setString(String setting, char[] value) { /** * Set a file setting. */ - synchronized void setFile(String setting, byte[] bytes) { + public synchronized void setFile(String setting, byte[] bytes) { ensureOpen(); validateSettingName(setting); @@ -659,7 +659,7 @@ synchronized void setFile(String setting, byte[] bytes) { /** * Remove the given setting from the keystore. */ - void remove(String setting) { + public void remove(String setting) { ensureOpen(); Entry oldEntry = entries.get().remove(setting); if (oldEntry != null) { diff --git a/server/src/main/java/org/opensearch/index/shard/ShardToolCli.java b/server/src/main/java/org/opensearch/index/shard/ShardToolCli.java index 1b4eb5a3f8c39..04b26904565cc 100644 --- a/server/src/main/java/org/opensearch/index/shard/ShardToolCli.java +++ b/server/src/main/java/org/opensearch/index/shard/ShardToolCli.java @@ -31,8 +31,8 @@ package org.opensearch.index.shard; -import org.opensearch.cli.LoggingAwareMultiCommand; import org.opensearch.cli.Terminal; +import org.opensearch.common.cli.LoggingAwareMultiCommand; /** * Class encapsulating and dispatching commands from the {@code opensearch-shard} command line tool diff --git a/server/src/main/java/org/opensearch/plugins/PluginLoaderIndirection.java b/server/src/main/java/org/opensearch/plugins/PluginLoaderIndirection.java index 199784d1f7630..ecb3e00e99f2c 100644 --- a/server/src/main/java/org/opensearch/plugins/PluginLoaderIndirection.java +++ b/server/src/main/java/org/opensearch/plugins/PluginLoaderIndirection.java @@ -32,6 +32,8 @@ package org.opensearch.plugins; +import org.opensearch.plugin_classloader.ExtendedPluginsClassLoader; + import java.util.List; /** diff --git a/server/src/main/java/org/opensearch/plugins/PluginsService.java b/server/src/main/java/org/opensearch/plugins/PluginsService.java index 72b8ada94a0d1..e5f9fbc483331 100644 --- a/server/src/main/java/org/opensearch/plugins/PluginsService.java +++ b/server/src/main/java/org/opensearch/plugins/PluginsService.java @@ -356,6 +356,37 @@ public int hashCode() { } } + public static void checkJarHellForPlugin( + Set classpath, + PluginInfo candidateInfo, + Path candidateDir, + Path pluginsDir, + Path modulesDir + ) throws Exception { + Set bundles = new HashSet<>(getPluginBundles(pluginsDir)); + bundles.addAll(getModuleBundles(modulesDir)); + bundles.add(new Bundle(candidateInfo, candidateDir)); + + List sortedBundles = sortBundles(bundles); + Map> transitiveUrls = new HashMap<>(); + for (Bundle bundle : sortedBundles) { + checkBundleJarHell(classpath, bundle, transitiveUrls); + } + } + + public static List findPluginsByDependency(Path pluginsDir, String pluginName) throws IOException { + List usedBy = new ArrayList<>(); + Set bundles = getPluginBundles(pluginsDir); + for (Bundle bundle : bundles) { + for (String extendedPlugin : bundle.plugin.getExtendedPlugins()) { + if (extendedPlugin.equals(pluginName)) { + usedBy.add(bundle.plugin.getName()); + } + } + } + return usedBy; + } + /** * Extracts all installed plugin directories from the provided {@code rootPath}. * @@ -388,7 +419,7 @@ public static List findPluginDirs(final Path rootPath) throws IOException /** * Verify the given plugin is compatible with the current OpenSearch installation. */ - static void verifyCompatibility(PluginInfo info) { + public static void verifyCompatibility(PluginInfo info) { if (!isPluginVersionCompatible(info, Version.CURRENT)) { throw new IllegalArgumentException( "Plugin [" @@ -413,7 +444,7 @@ public static boolean isPluginVersionCompatible(final PluginInfo pluginInfo, fin return true; } - static void checkForFailedPluginRemovals(final Path pluginsDirectory) throws IOException { + public static void checkForFailedPluginRemovals(final Path pluginsDirectory) throws IOException { /* * Check for the existence of a marker file that indicates any plugins are in a garbage state from a failed attempt to remove the * plugin. diff --git a/server/src/test/java/org/opensearch/plugins/PluginsServiceTests.java b/server/src/test/java/org/opensearch/plugins/PluginsServiceTests.java index cb549eafc0d21..e9dc2207510e0 100644 --- a/server/src/test/java/org/opensearch/plugins/PluginsServiceTests.java +++ b/server/src/test/java/org/opensearch/plugins/PluginsServiceTests.java @@ -1130,6 +1130,78 @@ public void testPluginCompatibilityWithSemverRange() { assertFalse(PluginsService.isPluginVersionCompatible(getPluginInfoWithWithSemverRange("~1.0.0"), Version.fromString("1.1.0"))); } + public void testFindPluginsByDependency() throws Exception { + Path tempDir = createTempDir(); + Path pluginsDir = tempDir.resolve("plugins"); + Files.createDirectories(pluginsDir); + + Path plugin1Dir = pluginsDir.resolve("plugin1"); + PluginTestUtil.writePluginProperties( + plugin1Dir, + "description", + "Plugin 1", + "name", + "plugin1", + "version", + "1.0", + "opensearch.version", + Version.CURRENT.toString(), + "java.version", + "1.8", + "classname", + "Plugin1", + "extended.plugins", + "base-plugin" + ); + + Path plugin2Dir = pluginsDir.resolve("plugin2"); + PluginTestUtil.writePluginProperties( + plugin2Dir, + "description", + "Plugin 2", + "name", + "plugin2", + "version", + "1.0", + "opensearch.version", + Version.CURRENT.toString(), + "java.version", + "1.8", + "classname", + "Plugin2", + "extended.plugins", + "base-plugin,other-plugin" + ); + + Path plugin3Dir = pluginsDir.resolve("plugin3"); + PluginTestUtil.writePluginProperties( + plugin3Dir, + "description", + "Plugin 3", + "name", + "plugin3", + "version", + "1.0", + "opensearch.version", + Version.CURRENT.toString(), + "java.version", + "1.8", + "classname", + "Plugin3", + "extended.plugins", + "other-plugin" + ); + + List basePluginDependents = PluginsService.findPluginsByDependency(pluginsDir, "base-plugin"); + assertThat(basePluginDependents, containsInAnyOrder("plugin1", "plugin2")); + + List otherPluginDependents = PluginsService.findPluginsByDependency(pluginsDir, "other-plugin"); + assertThat(otherPluginDependents, containsInAnyOrder("plugin2", "plugin3")); + + List nonExistentDependents = PluginsService.findPluginsByDependency(pluginsDir, "non-existent"); + assertTrue(nonExistentDependents.isEmpty()); + } + private PluginInfo getPluginInfoWithWithSemverRange(String semverRange) { return new PluginInfo( "my_plugin",