Skip to content

Commit

Permalink
Addressed PR Comments
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <[email protected]>
  • Loading branch information
owaiskazi19 committed Jun 21, 2022
1 parent 1a6a502 commit ebeda8a
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/main/java/org/opensearch/sdk/ExtensionsRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@
import static org.opensearch.common.UUIDs.randomBase64UUID;

public class ExtensionsRunner {
private ExtensionSettings extensionSettings = getExtensionSettings();
private ExtensionSettings extensionSettings = readExtensionSettings();
private DiscoveryNode opensearchNode;
private TransportService transportService;

public ExtensionsRunner() throws IOException {}

Expand All @@ -72,25 +71,35 @@ public ExtensionsRunner() throws IOException {}
private final TransportInterceptor NOOP_TRANSPORT_INTERCEPTOR = new TransportInterceptor() {
};

private ExtensionSettings getExtensionSettings() throws IOException {
private ExtensionSettings readExtensionSettings() throws IOException {
File file = new File(ExtensionSettings.EXTENSION_DESCRIPTOR);
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
ExtensionSettings extensionSettings = objectMapper.readValue(file, ExtensionSettings.class);
return extensionSettings;
}

private void setOpensearchNode(DiscoveryNode opensearchNode) {
this.opensearchNode = opensearchNode;
}

private DiscoveryNode getOpensearchNode() {
return opensearchNode;
}

PluginResponse handlePluginsRequest(PluginRequest pluginRequest) {
logger.info("Registering Plugin Request received from OpenSearch");
PluginResponse pluginResponse = new PluginResponse("RealExtension");
opensearchNode = pluginRequest.getSourceNode();
setOpensearchNode(opensearchNode);
return pluginResponse;
}

IndicesModuleResponse handleIndicesModuleRequest(IndicesModuleRequest indicesModuleRequest) {
IndicesModuleResponse handleIndicesModuleRequest(IndicesModuleRequest indicesModuleRequest, TransportService transportService) {
logger.info("Registering Indices Module Request received from OpenSearch");
IndicesModuleResponse indicesModuleResponse = new IndicesModuleResponse(true, true, true);

// CreateComponent
DiscoveryNode opensearchNode = getOpensearchNode();
transportService.connectToNode(opensearchNode);

try {
Expand Down Expand Up @@ -177,7 +186,7 @@ public TransportService createTransportService(Settings settings) throws IOExcep
final ConnectionManager connectionManager = new ClusterConnectionManager(settings, transport);

// create transport service
transportService = new TransportService(
return new TransportService(
settings,
transport,
threadPool,
Expand All @@ -191,8 +200,6 @@ public TransportService createTransportService(Settings settings) throws IOExcep
emptySet(),
connectionManager
);

return transportService;
}

// manager method for transport service
Expand All @@ -216,7 +223,7 @@ public void startTransportService(TransportService transportService) {
false,
false,
IndicesModuleRequest::new,
((request, channel, task) -> channel.sendResponse(handleIndicesModuleRequest(request)))
((request, channel, task) -> channel.sendResponse(handleIndicesModuleRequest(request, transportService)))

);
transportService.registerRequestHandler(
Expand All @@ -230,10 +237,6 @@ public void startTransportService(TransportService transportService) {

}

private TransportService getTransportService() {
return transportService;
}

private Settings getSettings() {
return settings;
}
Expand All @@ -250,9 +253,7 @@ public static void main(String[] args) throws IOException {

// configure and retrieve transport service with settings
Settings settings = extensionsRunner.getSettings();
extensionsRunner.createTransportService(settings);
// extensionsRunner.setTransportService();
TransportService transportService = extensionsRunner.getTransportService();
TransportService transportService = extensionsRunner.createTransportService(settings);

// start transport service and action listener
extensionsRunner.startTransportService(transportService);
Expand Down

0 comments on commit ebeda8a

Please sign in to comment.