forked from opensearch-project/opensearch-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make NamedXContent available to extensions (opensearch-project#244)
* Make NamedXContent available to extensions Signed-off-by: Daniel Widdis <[email protected]> * Add tests Signed-off-by: Daniel Widdis <[email protected]> * No need to save custom list in registry as it's on ExtensionsRunner Signed-off-by: Daniel Widdis <[email protected]> * Add sequence diagram to DESIGN.md Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: Daniel Widdis <[email protected]>
- Loading branch information
Showing
9 changed files
with
380 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/org/opensearch/sdk/ExtensionNamedXContentRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.sdk; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Stream; | ||
|
||
import org.opensearch.cluster.ClusterModule; | ||
import org.opensearch.common.network.NetworkModule; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.xcontent.NamedXContentRegistry; | ||
import org.opensearch.indices.IndicesModule; | ||
import org.opensearch.search.SearchModule; | ||
|
||
/** | ||
* Combines Extension NamedXContent with core OpenSearch NamedXContent | ||
*/ | ||
public class ExtensionNamedXContentRegistry { | ||
private final NamedXContentRegistry namedXContentRegistry; | ||
|
||
/** | ||
* Creates and populates a NamedXContentRegistry with the given NamedXContentRegistry entries for this extension and | ||
* locally defined content. | ||
* | ||
* @param settings OpenSearch environment settings | ||
* @param extensionNamedXContent List of NamedXContentRegistry.Entry to be registered | ||
*/ | ||
public ExtensionNamedXContentRegistry(Settings settings, List<NamedXContentRegistry.Entry> extensionNamedXContent) { | ||
this.namedXContentRegistry = new NamedXContentRegistry( | ||
Stream.of( | ||
extensionNamedXContent.stream(), | ||
NetworkModule.getNamedXContents().stream(), | ||
IndicesModule.getNamedXContents().stream(), | ||
new SearchModule(settings, Collections.emptyList()).getNamedXContents().stream(), | ||
ClusterModule.getNamedXWriteables().stream() | ||
).flatMap(Function.identity()).collect(toList()) | ||
); | ||
} | ||
|
||
/** | ||
* Gets the NamedXContentRegistry. | ||
* | ||
* @return The NamedXContentRegistry. Includes both extension-defined XContent and core OpenSearch XContent. | ||
*/ | ||
public NamedXContentRegistry getRegistry() { | ||
return this.namedXContentRegistry; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.