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 <cwperx@amazon.com>

* Small change to name

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Move extensionSettingsMap.put

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Re-run CI

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Craig Perkins <cwperx@amazon.com>
(cherry picked from commit 16555e4)
  • Loading branch information
cwperks committed May 9, 2023
1 parent b8a73f7 commit c281a8e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiscoveryExtensionNode> extensions;

private Map<String, Extension> extensionSettingsMap;
private Map<String, DiscoveryExtensionNode> initializedExtensions;
private Map<String, DiscoveryExtensionNode> extensionIdMap;
private RestActionsRequestHandler restActionsRequestHandler;
private CustomSettingsRequestHandler customSettingsRequestHandler;
Expand All @@ -152,6 +155,7 @@ public ExtensionsManager(Settings settings, Path extensionsPath) throws IOExcept
this.extensionsPath = extensionsPath;
this.extensions = new ArrayList<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 @@ -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<DiscoveryExtensionNode> 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<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 @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit c281a8e

Please sign in to comment.