From 7d38fee14379aa4ee59a61fbaefed778fd196119 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Mon, 8 May 2023 16:54:38 -0400 Subject: [PATCH 1/5] Add ExtensionsManager.lookupExtensionSettings Signed-off-by: Craig Perkins --- .../opensearch/extensions/ExtensionsManager.java | 14 ++++++++++++++ .../extensions/ExtensionsManagerTests.java | 1 + 2 files changed, 15 insertions(+) diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java index 94ad9ff84cfdb..06e2c35138cf3 100644 --- a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java +++ b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java @@ -108,6 +108,8 @@ public static enum OpenSearchRequestType { private final Path extensionsPath; private ExtensionTransportActionsHandler extensionTransportActionsHandler; + + private Map extensionSettingsMap; private Map initializedExtensions; private Map extensionIdMap; private RestActionsRequestHandler restActionsRequestHandler; @@ -129,6 +131,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; @@ -192,6 +195,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 lookupExtensionSettings(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}. * @@ -308,6 +321,7 @@ protected void discover() throws IOException { throw new IOException("Could not read from extensions.yml", e); } for (Extension extension : extensions) { + extensionSettingsMap.put(extension.getUniqueId(), extension); loadExtension(extension); } if (!extensionIdMap.isEmpty()) { diff --git a/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java b/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java index 0a9fd2e6b94fe..392bc3c54ae01 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.lookupExtensionSettings(extension.getId()).isPresent()); } } From f188c344347e268353e6b42fda49b549f6b2c841 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Mon, 8 May 2023 16:56:16 -0400 Subject: [PATCH 2/5] Small change to name Signed-off-by: Craig Perkins --- .../main/java/org/opensearch/extensions/ExtensionsManager.java | 2 +- .../java/org/opensearch/extensions/ExtensionsManagerTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java index 06e2c35138cf3..315976fca9a12 100644 --- a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java +++ b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java @@ -201,7 +201,7 @@ public Optional lookupInitializedExtensionById(final Str * @param extensionId The unique extension identifier * @return An optional of the Extension instance for the matching extension */ - public Optional lookupExtensionSettings(final String extensionId) { + public Optional lookupExtensionSettingsById(final String extensionId) { return Optional.ofNullable(this.extensionSettingsMap.get(extensionId)); } diff --git a/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java b/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java index 392bc3c54ae01..65fb0322ffa2f 100644 --- a/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java +++ b/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java @@ -243,7 +243,7 @@ public void testDiscover() throws Exception { assertEquals(extension.getVersion(), initializedExtension.getVersion()); assertEquals(extension.getMinimumCompatibleVersion(), initializedExtension.getMinimumCompatibleVersion()); assertEquals(extension.getDependencies(), initializedExtension.getDependencies()); - assertTrue(extensionsManager.lookupExtensionSettings(extension.getId()).isPresent()); + assertTrue(extensionsManager.lookupExtensionSettingsById(extension.getId()).isPresent()); } } From 140440d0374f5e4e00eaa20c5658087ab03ebd2b Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Mon, 8 May 2023 17:01:26 -0400 Subject: [PATCH 3/5] Add to CHANGELOG Signed-off-by: Craig Perkins --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18c613bd8c89f..3a4b998ba47e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Allow mmap to use new JDK-19 preview APIs in Apache Lucene 9.4+ ([#5151](https://github.com/opensearch-project/OpenSearch/pull/5151)) - Add events correlation engine plugin ([#6854](https://github.com/opensearch-project/OpenSearch/issues/6854)) - Add connectToNodeAsExtension in TransportService ([#6866](https://github.com/opensearch-project/OpenSearch/pull/6866)) +- Adds ExtensionsManager.lookupExtensionSettingsById ([#7466](https://github.com/opensearch-project/OpenSearch/pull/7466)) ### Dependencies - Bump `log4j-core` from 2.18.0 to 2.19.0 @@ -116,4 +117,4 @@ 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 -[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.7...2.x \ No newline at end of file +[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.7...2.x From 48264c2c6b5d56f1d442d44af8607394140eb3d1 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Tue, 9 May 2023 09:29:21 -0400 Subject: [PATCH 4/5] Move extensionSettingsMap.put Signed-off-by: Craig Perkins --- .../main/java/org/opensearch/extensions/ExtensionsManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java index 315976fca9a12..5ad2d26fbd2c7 100644 --- a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java +++ b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java @@ -321,7 +321,6 @@ protected void discover() throws IOException { throw new IOException("Could not read from extensions.yml", e); } for (Extension extension : extensions) { - extensionSettingsMap.put(extension.getUniqueId(), extension); loadExtension(extension); } if (!extensionIdMap.isEmpty()) { @@ -351,6 +350,7 @@ private void loadExtension(Extension extension) throws IOException { 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); From 00f3ece3309bdff56a9139283c47fa477a5e8132 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Tue, 9 May 2023 10:14:21 -0400 Subject: [PATCH 5/5] Re-run CI Signed-off-by: Craig Perkins --- .../main/java/org/opensearch/extensions/ExtensionsManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java index 5ad2d26fbd2c7..f83e371f58943 100644 --- a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java +++ b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java @@ -349,6 +349,7 @@ 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);