diff --git a/CHANGELOG.md b/CHANGELOG.md index 409f756ca967c..4a65ca15f9371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Add 'unsigned_long' numeric field type ([#6237](https://github.com/opensearch-project/OpenSearch/pull/6237)) - Add back primary shard preference for queries ([#7375](https://github.com/opensearch-project/OpenSearch/pull/7375)) - Add descending order search optimization through reverse segment read. ([#7244](https://github.com/opensearch-project/OpenSearch/pull/7244)) +- Adds ExtensionsManager.lookupExtensionSettingsById ([#7466](https://github.com/opensearch-project/OpenSearch/pull/7466)) ### Dependencies - Bump `com.netflix.nebula:gradle-info-plugin` from 12.0.0 to 12.1.0 diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java index fffe1dc4740af..62f526d3f0437 100644 --- a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java +++ b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java @@ -107,6 +107,8 @@ public static enum OpenSearchRequestType { private final Path extensionsPath; private ExtensionTransportActionsHandler extensionTransportActionsHandler; + + private Map extensionSettingsMap; private Map initializedExtensions; private Map extensionIdMap; private RestActionsRequestHandler restActionsRequestHandler; @@ -128,6 +130,7 @@ public ExtensionsManager(Path extensionsPath) throws IOException { this.extensionsPath = extensionsPath; this.initializedExtensions = new HashMap(); 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; @@ -191,6 +194,16 @@ public Optional lookupInitializedExtensionById(final Str 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}. * @@ -335,7 +348,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 9f35ad8be858c..b7acd57694396 100644 --- a/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java +++ b/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java @@ -243,6 +243,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()); } }