Skip to content

Commit

Permalink
Adds ExtensionsManager.lookupExtensionSettingsById (opensearch-projec…
Browse files Browse the repository at this point in the history
…t#7466)

* Add ExtensionsManager.lookupExtensionSettings

Signed-off-by: Craig Perkins <[email protected]>

* Small change to name

Signed-off-by: Craig Perkins <[email protected]>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <[email protected]>

* Move extensionSettingsMap.put

Signed-off-by: Craig Perkins <[email protected]>

* Re-run CI

Signed-off-by: Craig Perkins <[email protected]>

---------

Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks authored May 9, 2023
1 parent 0d3c61d commit 16555e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -117,4 +118,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
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.7...2.x
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public static enum OpenSearchRequestType {

private final Path extensionsPath;
private ExtensionTransportActionsHandler extensionTransportActionsHandler;

private Map<String, Extension> extensionSettingsMap;
private Map<String, DiscoveryExtensionNode> initializedExtensions;
private Map<String, DiscoveryExtensionNode> extensionIdMap;
private RestActionsRequestHandler restActionsRequestHandler;
Expand All @@ -129,6 +131,7 @@ public ExtensionsManager(Path extensionsPath) throws IOException {
this.extensionsPath = extensionsPath;
this.initializedExtensions = new HashMap<String, DiscoveryExtensionNode>();
this.extensionIdMap = new HashMap<String, DiscoveryExtensionNode>();
this.extensionSettingsMap = new HashMap<String, Extension>();
// will be initialized in initializeServicesAndRestHandler which is called after the Node is initialized
this.transportService = null;
this.clusterService = null;
Expand Down Expand Up @@ -192,6 +195,16 @@ public Optional<DiscoveryExtensionNode> 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<Extension> 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}.
*
Expand Down Expand Up @@ -336,7 +349,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit 16555e4

Please sign in to comment.