Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transport service #191

Merged
merged 3 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/java/org/opensearch/sdk/ExtensionsRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class ExtensionsRunner {
private ExtensionsIndicesModuleNameRequestHandler extensionsIndicesModuleNameRequestHandler =
new ExtensionsIndicesModuleNameRequestHandler();
private ExtensionsRestRequestHandler extensionsRestRequestHandler = new ExtensionsRestRequestHandler(extensionRestPathRegistry);
private NettyTransport nettyTransport = new NettyTransport();

private SDKClient client = new SDKClient();

/*
Expand Down Expand Up @@ -131,9 +131,9 @@ protected ExtensionsRunner(Extension extension) throws IOException {
this.customSettings = extension.getSettings();
// save custom transport actions
this.transportActions = new TransportActions(extension.getActions());
// initialize the transport service

ThreadPool threadPool = new ThreadPool(this.getSettings());
nettyTransport.initializeExtensionTransportService(this.getSettings(), threadPool, this);

// create components
extension.createComponents(client, null, threadPool);
}
Expand Down Expand Up @@ -461,6 +461,8 @@ public static void run(Extension extension) throws IOException {
logger.info("Starting extension " + extension.getExtensionSettings().getExtensionName());
@SuppressWarnings("unused")
owaiskazi19 marked this conversation as resolved.
Show resolved Hide resolved
ExtensionsRunner runner = new ExtensionsRunner(extension);
// initialize the transport service
new NettyTransport(runner).initializeExtensionTransportService(runner.getSettings(), new ThreadPool(runner.getSettings()), runner);
owaiskazi19 marked this conversation as resolved.
Show resolved Hide resolved
runner.startActionListener(0);
}
}
14 changes: 11 additions & 3 deletions src/main/java/org/opensearch/sdk/NettyTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@

public class NettyTransport {
private static final String NODE_NAME_SETTING = "node.name";
private final ExtensionsRunner extensionsRunner;
private final TransportInterceptor NOOP_TRANSPORT_INTERCEPTOR = new TransportInterceptor() {
};

/**
* @param extensionsRunner Instantiate this object with a reference to the ExtensionsRunner.
*/
public NettyTransport(ExtensionsRunner extensionsRunner) {
this.extensionsRunner = extensionsRunner;
}

/**
* Initializes a Netty4Transport object. This object will be wrapped in a {@link TransportService} object.
*
Expand Down Expand Up @@ -103,7 +111,7 @@ public TransportService initializeExtensionTransportService(
}

// create transport service
extensionsRunner.extensionTransportService = new TransportService(
TransportService transportService = new TransportService(
settings,
transport,
threadPool,
Expand All @@ -116,8 +124,8 @@ public TransportService initializeExtensionTransportService(
null,
emptySet()
);
extensionsRunner.startTransportService(extensionsRunner.extensionTransportService);
return extensionsRunner.extensionTransportService;
extensionsRunner.startTransportService(transportService);
return transportService;
}

}
16 changes: 1 addition & 15 deletions src/test/java/org/opensearch/sdk/TestExtensionsRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.Collections;
import java.util.HashMap;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opensearch.Version;
Expand Down Expand Up @@ -76,14 +75,12 @@ public class TestExtensionsRunner extends OpenSearchTestCase {
private ExtensionsRunner extensionsRunner;
private TransportService transportService;

private TransportService initialTransportService;

@Override
@BeforeEach
public void setUp() throws Exception {
super.setUp();
this.extensionsRunner = new ExtensionsRunnerForTest();
this.initialTransportService = extensionsRunner.extensionTransportService;

this.transportService = spy(
new TransportService(
Settings.EMPTY,
Expand All @@ -97,17 +94,6 @@ public void setUp() throws Exception {
);
}

@Override
@AfterEach
public void tearDown() throws Exception {
super.tearDown();
if (initialTransportService != null) {
this.initialTransportService.stop();
this.initialTransportService.close();
Thread.sleep(1000);
}
}

// test manager method invokes start on transport service
@Test
public void testTransportServiceStarted() {
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/org/opensearch/sdk/TestNetty4Transport.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.opensearch.sdk;

import java.io.IOException;

owaiskazi19 marked this conversation as resolved.
Show resolved Hide resolved
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opensearch.common.component.Lifecycle;
Expand All @@ -25,11 +26,14 @@
public class TestNetty4Transport extends OpenSearchTestCase {

private ThreadPool threadPool;
private NettyTransport nettyTransport = new NettyTransport();
private ExtensionsRunner extensionsRunner;
private NettyTransport nettyTransport;

@BeforeEach
public void setUp() throws IOException {
this.threadPool = new TestThreadPool("test");
this.extensionsRunner = new ExtensionsRunnerForTest();
this.nettyTransport = new NettyTransport(extensionsRunner);
}

// test Netty can bind to multiple ports, default and additional client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ public class TransportCommunicationIT extends OpenSearchIntegTestCase {
private final int port = 7777;
private final String host = "127.0.0.1";
private volatile String clientResult;
private NettyTransport nettyTransport = new NettyTransport();
private ExtensionsRunner extensionsRunner;
private NettyTransport nettyTransport;

@Override
@BeforeEach
public void setUp() {
public void setUp() throws IOException {

// Configure settings for transport serivce using the same port number used to bind the client
settings = Settings.builder()
.put("node.name", "node_extension_test")
.put(TransportSettings.BIND_HOST.getKey(), host)
.put(TransportSettings.PORT.getKey(), port)
.build();
this.extensionsRunner = new ExtensionsRunnerForTest();
this.nettyTransport = new NettyTransport(extensionsRunner);
}

@Test
Expand Down