29
29
import org .apache .logging .log4j .message .ParameterizedMessage ;
30
30
import org .opensearch .Version ;
31
31
import org .opensearch .action .admin .cluster .node .info .PluginsAndModules ;
32
+ import org .opensearch .action .admin .cluster .state .ClusterStateResponse ;
33
+ import org .opensearch .cluster .*;
32
34
import org .opensearch .cluster .node .DiscoveryNode ;
35
+ import org .opensearch .cluster .service .ClusterService ;
33
36
import org .opensearch .common .io .FileSystemUtils ;
34
37
import org .opensearch .common .io .stream .StreamInput ;
35
38
import org .opensearch .common .settings .Settings ;
49
52
import org .opensearch .plugins .PluginsService ;
50
53
import org .opensearch .threadpool .ThreadPool ;
51
54
import org .opensearch .transport .TransportException ;
55
+ import org .opensearch .transport .TransportResponse ;
52
56
import org .opensearch .transport .TransportResponseHandler ;
53
57
import org .opensearch .transport .TransportService ;
54
58
@@ -61,20 +65,39 @@ public class ExtensionsOrchestrator implements ReportingService<PluginsAndModule
61
65
public static final String REQUEST_EXTENSION_ACTION_NAME = "internal:discovery/extensions" ;
62
66
public static final String INDICES_EXTENSION_POINT_ACTION_NAME = "indices:internal/extensions" ;
63
67
public static final String INDICES_EXTENSION_NAME_ACTION_NAME = "indices:internal/name" ;
68
+ public static final String REQUEST_EXTENSION_CLUSTER_STATE = "internal:discovery/clusterstate" ;
69
+ public static final String REQUEST_EXTENSION_LOCAL_NODE = "internal:discovery/localnode" ;
70
+ public static final String REQUEST_EXTENSION_CLUSTER_SETTINGS = "internal:discovery/clustersettings" ;
64
71
65
72
private static final Logger logger = LogManager .getLogger (ExtensionsOrchestrator .class );
73
+
74
+ /**
75
+ * Enum for Extension Requests
76
+ *
77
+ * @opensearch.internal
78
+ */
79
+ public static enum RequestType {
80
+ REQUEST_EXTENSION_CLUSTER_STATE ,
81
+ REQUEST_EXTENSION_LOCAL_NODE ,
82
+ REQUEST_EXTENSION_CLUSTER_SETTINGS ,
83
+ CREATE_COMPONENT ,
84
+ ON_INDEX_MODULE ,
85
+ GET_SETTINGS
86
+ };
87
+
66
88
private final Path extensionsPath ;
67
89
final Set <DiscoveryExtension > extensionsSet ;
68
90
Set <DiscoveryExtension > extensionsInitializedSet ;
69
91
TransportService transportService ;
92
+ ClusterService clusterService ;
70
93
71
94
public ExtensionsOrchestrator (Settings settings , Path extensionsPath ) throws IOException {
72
95
logger .info ("ExtensionsOrchestrator initialized" );
73
96
this .extensionsPath = extensionsPath ;
74
97
this .transportService = null ;
75
98
this .extensionsSet = new HashSet <DiscoveryExtension >();
76
99
this .extensionsInitializedSet = new HashSet <DiscoveryExtension >();
77
-
100
+ this . clusterService = null ;
78
101
/*
79
102
* Now Discover extensions
80
103
*/
@@ -86,6 +109,34 @@ public void setTransportService(TransportService transportService) {
86
109
this .transportService = transportService ;
87
110
}
88
111
112
+ public void setClusterService (ClusterService clusterService ) {
113
+ this .clusterService = clusterService ;
114
+ transportService .registerRequestHandler (
115
+ REQUEST_EXTENSION_CLUSTER_STATE ,
116
+ ThreadPool .Names .GENERIC ,
117
+ false ,
118
+ false ,
119
+ ExtensionRequest ::new ,
120
+ ((request , channel , task ) -> channel .sendResponse (handleExtensionRequest (request )))
121
+ );
122
+ transportService .registerRequestHandler (
123
+ REQUEST_EXTENSION_LOCAL_NODE ,
124
+ ThreadPool .Names .GENERIC ,
125
+ false ,
126
+ false ,
127
+ ExtensionRequest ::new ,
128
+ ((request , channel , task ) -> channel .sendResponse (handleExtensionRequest (request )))
129
+ );
130
+ transportService .registerRequestHandler (
131
+ REQUEST_EXTENSION_CLUSTER_SETTINGS ,
132
+ ThreadPool .Names .GENERIC ,
133
+ false ,
134
+ false ,
135
+ ExtensionRequest ::new ,
136
+ ((request , channel , task ) -> channel .sendResponse (handleExtensionRequest (request )))
137
+ );
138
+ }
139
+
89
140
@ Override
90
141
public PluginsAndModules info () {
91
142
return null ;
@@ -187,14 +238,33 @@ public String executor() {
187
238
transportService .sendRequest (
188
239
extensionNode ,
189
240
REQUEST_EXTENSION_ACTION_NAME ,
190
- new PluginRequest (extensionNode , new ArrayList <DiscoveryExtension >(extensionsSet )),
241
+ new PluginRequest (transportService . getLocalNode () , new ArrayList <DiscoveryExtension >(extensionsSet )),
191
242
pluginResponseHandler
192
243
);
193
244
} catch (Exception e ) {
194
245
logger .error (e .toString ());
195
246
}
196
247
}
197
248
249
+ TransportResponse handleExtensionRequest (ExtensionRequest extensionRequest ) {
250
+ // Read enum
251
+ if (extensionRequest .getRequestType () == RequestType .REQUEST_EXTENSION_CLUSTER_STATE ) {
252
+ ClusterStateResponse clusterStateResponse = new ClusterStateResponse (
253
+ clusterService .getClusterName (),
254
+ clusterService .state (),
255
+ false
256
+ );
257
+ return clusterStateResponse ;
258
+ } else if (extensionRequest .getRequestType () == RequestType .REQUEST_EXTENSION_LOCAL_NODE ) {
259
+ LocalNodeResponse localNodeResponse = new LocalNodeResponse (clusterService );
260
+ return localNodeResponse ;
261
+ } else if (extensionRequest .getRequestType () == RequestType .REQUEST_EXTENSION_CLUSTER_SETTINGS ) {
262
+ ClusterSettingsResponse clusterSettingsResponse = new ClusterSettingsResponse (clusterService );
263
+ return clusterSettingsResponse ;
264
+ }
265
+ return null ;
266
+ }
267
+
198
268
public void onIndexModule (IndexModule indexModule ) throws UnknownHostException {
199
269
for (DiscoveryNode extensionNode : extensionsSet ) {
200
270
onIndexModule (indexModule , extensionNode );
0 commit comments