Skip to content

Commit 3ce3c96

Browse files
committed
Add IndicesAwarePlugin class
Signed-off-by: David Zane <[email protected]>
1 parent 8d19cb9 commit 3ce3c96

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1313
- Add successfulSearchShardIndices in searchRequestContext ([#15967](https://github.com/opensearch-project/OpenSearch/pull/15967))
1414
- Remove identity-related feature flagged code from the RestController ([#15430](https://github.com/opensearch-project/OpenSearch/pull/15430))
1515
- Add support for msearch API to pass search pipeline name - ([#15923](https://github.com/opensearch-project/OpenSearch/pull/15923))
16+
- Add IndicesAwarePlugin class ([#16110](https://github.com/opensearch-project/OpenSearch/pull/16110))
1617

1718
### Dependencies
1819
- Bump `com.azure:azure-identity` from 1.13.0 to 1.13.2 ([#15578](https://github.com/opensearch-project/OpenSearch/pull/15578))

server/src/main/java/org/opensearch/node/Node.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
import org.opensearch.plugins.IdentityAwarePlugin;
206206
import org.opensearch.plugins.IdentityPlugin;
207207
import org.opensearch.plugins.IndexStorePlugin;
208+
import org.opensearch.plugins.IndicesAwarePlugin;
208209
import org.opensearch.plugins.IngestPlugin;
209210
import org.opensearch.plugins.MapperPlugin;
210211
import org.opensearch.plugins.MetadataUpgrader;
@@ -1023,6 +1024,31 @@ protected Node(
10231024
// Add the telemetryAwarePlugin components to the existing pluginComponents collection.
10241025
pluginComponents.addAll(telemetryAwarePluginComponents);
10251026

1027+
Collection<Object> indicesAwarePluginComponents = pluginsService.filterPlugins(IndicesAwarePlugin.class)
1028+
.stream()
1029+
.flatMap(
1030+
p -> p.createComponents(
1031+
client,
1032+
clusterService,
1033+
threadPool,
1034+
resourceWatcherService,
1035+
scriptService,
1036+
xContentRegistry,
1037+
environment,
1038+
nodeEnvironment,
1039+
namedWriteableRegistry,
1040+
clusterModule.getIndexNameExpressionResolver(),
1041+
repositoriesServiceReference::get,
1042+
tracer,
1043+
metricsRegistry,
1044+
indicesService
1045+
).stream()
1046+
)
1047+
.collect(Collectors.toList());
1048+
1049+
// Add the indicesAwarePluginComponents components to the existing pluginComponents collection.
1050+
pluginComponents.addAll(indicesAwarePluginComponents);
1051+
10261052
List<IdentityAwarePlugin> identityAwarePlugins = pluginsService.filterPlugins(IdentityAwarePlugin.class);
10271053
identityService.initializeIdentityAwarePlugins(identityAwarePlugins);
10281054

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugins;
10+
11+
import org.opensearch.client.Client;
12+
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
13+
import org.opensearch.cluster.service.ClusterService;
14+
import org.opensearch.common.annotation.ExperimentalApi;
15+
import org.opensearch.common.lifecycle.LifecycleComponent;
16+
import org.opensearch.core.common.io.stream.NamedWriteable;
17+
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
18+
import org.opensearch.core.xcontent.NamedXContentRegistry;
19+
import org.opensearch.env.Environment;
20+
import org.opensearch.env.NodeEnvironment;
21+
import org.opensearch.indices.IndicesService;
22+
import org.opensearch.repositories.RepositoriesService;
23+
import org.opensearch.script.ScriptService;
24+
import org.opensearch.telemetry.metrics.MetricsRegistry;
25+
import org.opensearch.telemetry.tracing.Tracer;
26+
import org.opensearch.threadpool.ThreadPool;
27+
import org.opensearch.watcher.ResourceWatcherService;
28+
29+
import java.util.Collection;
30+
import java.util.Collections;
31+
import java.util.function.Supplier;
32+
33+
/**
34+
* Plugin that provides the telemetry registries to build component with telemetry and also provide a way to
35+
* pass telemetry registries to the implementing plugins for adding instrumentation in the code.
36+
*
37+
* @opensearch.experimental
38+
*/
39+
@ExperimentalApi
40+
public interface IndicesAwarePlugin {
41+
42+
/**
43+
* Returns components added by this plugin.
44+
* <p>
45+
* Any components returned that implement {@link LifecycleComponent} will have their lifecycle managed.
46+
* Note: To aid in the migration away from guice, all objects returned as components will be bound in guice
47+
* to themselves.
48+
*
49+
* @param client A client to make requests to the system
50+
* @param clusterService A service to allow watching and updating cluster state
51+
* @param threadPool A service to allow retrieving an executor to run an async action
52+
* @param resourceWatcherService A service to watch for changes to node local files
53+
* @param scriptService A service to allow running scripts on the local node
54+
* @param xContentRegistry the registry for extensible xContent parsing
55+
* @param environment the environment for path and setting configurations
56+
* @param nodeEnvironment the node environment used coordinate access to the data paths
57+
* @param namedWriteableRegistry the registry for {@link NamedWriteable} object parsing
58+
* @param indexNameExpressionResolver A service that resolves expression to index and alias names
59+
* @param repositoriesServiceSupplier A supplier for the service that manages snapshot repositories; will return null when this method
60+
* is called, but will return the repositories service once the node is initialized.
61+
* @param tracer the tracer to add tracing instrumentation.
62+
* @param metricsRegistry the registry for metrics instrumentation.
63+
* @param indicesService A service to track indices
64+
*/
65+
default Collection<Object> createComponents(
66+
Client client,
67+
ClusterService clusterService,
68+
ThreadPool threadPool,
69+
ResourceWatcherService resourceWatcherService,
70+
ScriptService scriptService,
71+
NamedXContentRegistry xContentRegistry,
72+
Environment environment,
73+
NodeEnvironment nodeEnvironment,
74+
NamedWriteableRegistry namedWriteableRegistry,
75+
IndexNameExpressionResolver indexNameExpressionResolver,
76+
Supplier<RepositoriesService> repositoriesServiceSupplier,
77+
Tracer tracer,
78+
MetricsRegistry metricsRegistry,
79+
IndicesService indicesService
80+
) {
81+
return Collections.emptyList();
82+
}
83+
}

0 commit comments

Comments
 (0)