Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Adds ExtensionsManager.lookupExtensionSettingsById #7492

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,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 @@ -128,6 +130,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 @@ -191,6 +194,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 @@ -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);
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