diff --git a/CHANGELOG.md b/CHANGELOG.md index 3738f964226c4..01e48b5e91090 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - [Segment Replication] Add new cluster setting to set replication strategy by default for all indices in cluster. ([#6791](https://github.com/opensearch-project/OpenSearch/pull/6791)) - Enable sort optimization for all NumericTypes ([#6464](https://github.com/opensearch-project/OpenSearch/pull/6464) - Remove 'cluster_manager' role attachment when using 'node.master' deprecated setting ([#6331](https://github.com/opensearch-project/OpenSearch/pull/6331)) +- Adds ExtensionsManager.lookupExtensionSettingsById ([#7466](https://github.com/opensearch-project/OpenSearch/pull/7466)) ### Dependencies - Bump `org.apache.logging.log4j:log4j-core` from 2.18.0 to 2.20.0 ([#6490](https://github.com/opensearch-project/OpenSearch/pull/6490)) @@ -51,4 +52,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Security [Unreleased 3.0]: https://github.com/opensearch-project/OpenSearch/compare/2.x...HEAD +<<<<<<< HEAD [Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.5...2.x +======= +[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.7...2.x +>>>>>>> 16555e42ca5 (Adds ExtensionsManager.lookupExtensionSettingsById (#7466)) diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java index ccc1bdb620f31..1bf449d6aef3c 100644 --- a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java +++ b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java @@ -127,6 +127,9 @@ public static enum OpenSearchRequestType { private ExtensionTransportActionsHandler extensionTransportActionsHandler; // A list of initialized extensions, a subset of the values of map below which includes all extensions private List extensions; + + private Map extensionSettingsMap; + private Map initializedExtensions; private Map extensionIdMap; private RestActionsRequestHandler restActionsRequestHandler; private CustomSettingsRequestHandler customSettingsRequestHandler; @@ -152,6 +155,7 @@ public ExtensionsManager(Settings settings, Path extensionsPath) throws IOExcept this.extensionsPath = extensionsPath; this.extensions = new ArrayList(); this.extensionIdMap = new HashMap(); + this.extensionSettingsMap = new HashMap(); // will be initialized in initializeServicesAndRestHandler which is called after the Node is initialized this.transportService = null; this.clusterService = null; @@ -205,6 +209,26 @@ public void initializeServicesAndRestHandler( registerRequestHandler(); } + /** + * Lookup an initialized extension by its unique id + * + * @param extensionId The unique extension identifier + * @return An optional of the DiscoveryExtensionNode instance for the matching extension + */ + public Optional lookupInitializedExtensionById(final String extensionId) { + return Optional.ofNullable(this.initializedExtensions.get(extensionId)); + } + + /** + * Lookup the settings for an extension based on unique id for the settings placed in extensions.yml + * + * @param extensionId The unique extension identifier + * @return An optional of the Extension instance for the matching extension + */ + public Optional lookupExtensionSettingsById(final String extensionId) { + return Optional.ofNullable(this.extensionSettingsMap.get(extensionId)); + } + /** * Handles Transport Request from {@link org.opensearch.extensions.action.ExtensionTransportAction} which was invoked by an extension via {@link ExtensionTransportActionsHandler}. * @@ -349,7 +373,9 @@ private void loadExtension(Extension extension) throws IOException { Version.fromString(extension.getMinimumCompatibleVersion()), extension.getDependencies() ); + extensionIdMap.put(extension.getUniqueId(), discoveryExtensionNode); + extensionSettingsMap.put(extension.getUniqueId(), extension); logger.info("Loaded extension with uniqueId " + extension.getUniqueId() + ": " + extension); } catch (OpenSearchException e) { logger.error("Could not load extension with uniqueId " + extension.getUniqueId() + " due to " + e); diff --git a/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java b/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java index 53f5d70b2d5eb..ad2717ae70331 100644 --- a/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java +++ b/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java @@ -241,6 +241,7 @@ public void testDiscover() throws Exception { assertEquals(extension.getVersion(), initializedExtension.getVersion()); assertEquals(extension.getMinimumCompatibleVersion(), initializedExtension.getMinimumCompatibleVersion()); assertEquals(extension.getDependencies(), initializedExtension.getDependencies()); + assertTrue(extensionsManager.lookupExtensionSettingsById(extension.getId()).isPresent()); } }