Skip to content

Commit

Permalink
Refactoring and 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 3dca183 commit 1a6a502
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
import org.opensearch.transport.TransportResponseHandler;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

public class ClusterSettingResponseHandler implements TransportResponseHandler<ClusterSettingsResponse> {
private static final Logger logger = LogManager.getLogger(ClusterSettingResponseHandler.class);
final CountDownLatch inProgressLatch = new CountDownLatch(1);
public class ClusterSettingsResponseHandler implements TransportResponseHandler<ClusterSettingsResponse> {
private static final Logger logger = LogManager.getLogger(ClusterSettingsResponseHandler.class);

@Override
public void handleResponse(ClusterSettingsResponse response) {
logger.info("received {}", response);
inProgressLatch.countDown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@
import org.opensearch.transport.TransportResponseHandler;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

public class ExtensionClusterStateResponseHandler implements TransportResponseHandler<ExtensionClusterStateResponse> {
private static final Logger logger = LogManager.getLogger(ExtensionClusterStateResponseHandler.class);
final CountDownLatch inProgressLatch = new CountDownLatch(1);

@Override
public void handleResponse(ExtensionClusterStateResponse response) {
logger.info("received {}", response);
inProgressLatch.countDown();
}

@Override
public void handleException(TransportException exp) {
logger.info("ClusterStateRequest failed", exp);
logger.info("ExtensionClusterStateRequest failed", exp);
}

@Override
Expand Down
45 changes: 21 additions & 24 deletions src/main/java/org/opensearch/sdk/ExtensionsRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,22 @@
import static org.opensearch.common.UUIDs.randomBase64UUID;

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

static {
try {
extensionSettings = getExtensionSettings();
} catch (IOException e) {
e.printStackTrace();
}
}
public ExtensionsRunner() throws IOException {}

private static final Settings settings = Settings.builder()
private final Settings settings = Settings.builder()
.put("node.name", extensionSettings.getExtensionname())
.put(TransportSettings.BIND_HOST.getKey(), extensionSettings.getHostaddress())
.put(TransportSettings.PORT.getKey(), extensionSettings.getHostport())
.build();
private static final Logger logger = LogManager.getLogger(ExtensionsRunner.class);
public static final TransportInterceptor NOOP_TRANSPORT_INTERCEPTOR = new TransportInterceptor() {
private final Logger logger = LogManager.getLogger(ExtensionsRunner.class);
private final TransportInterceptor NOOP_TRANSPORT_INTERCEPTOR = new TransportInterceptor() {
};

public ExtensionsRunner() throws IOException {}

public static ExtensionSettings getExtensionSettings() throws IOException {
private ExtensionSettings getExtensionSettings() throws IOException {
File file = new File(ExtensionSettings.EXTENSION_DESCRIPTOR);
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
ExtensionSettings extensionSettings = objectMapper.readValue(file, ExtensionSettings.class);
Expand Down Expand Up @@ -111,7 +103,7 @@ IndicesModuleResponse handleIndicesModuleRequest(IndicesModuleRequest indicesMod
clusterStateResponseHandler
);
logger.info("Sending Cluster Settings request to OpenSearch after creating index");
ClusterSettingResponseHandler clusterSettingResponseHandler = new ClusterSettingResponseHandler();
ClusterSettingsResponseHandler clusterSettingResponseHandler = new ClusterSettingsResponseHandler();
transportService.sendRequest(
opensearchNode,
ExtensionsOrchestrator.REQUEST_EXTENSION_CLUSTER_SETTINGS,
Expand All @@ -129,8 +121,7 @@ IndicesModuleResponse handleIndicesModuleRequest(IndicesModuleRequest indicesMod

logger.info("Received response from OpenSearch for ClusterState, ClusterSettings and LocalNode");
} catch (Exception e) {
e.printStackTrace();
logger.error(e.toString());
logger.info("Failed to send request to OpenSearch", e);
}

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

// create transport service
final TransportService transportService = new TransportService(
transportService = new TransportService(
settings,
transport,
threadPool,
Expand Down Expand Up @@ -239,8 +230,12 @@ public void startTransportService(TransportService transportService) {

}

public void setTransportService(TransportService transportService) {
this.transportService = transportService;
private TransportService getTransportService() {
return transportService;
}

private Settings getSettings() {
return settings;
}

// manager method for action listener
Expand All @@ -254,8 +249,10 @@ public static void main(String[] args) throws IOException {
ExtensionsRunner extensionsRunner = new ExtensionsRunner();

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

// start transport service and action listener
extensionsRunner.startTransportService(transportService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
import org.opensearch.transport.TransportResponseHandler;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

public class LocalNodeResponseHandler implements TransportResponseHandler<LocalNodeResponse> {
private static final Logger logger = LogManager.getLogger(LocalNodeResponseHandler.class);
final CountDownLatch inProgressLatch = new CountDownLatch(1);

@Override
public void handleResponse(LocalNodeResponse response) {
logger.info("received {}", response);
inProgressLatch.countDown();
}

@Override
Expand Down

0 comments on commit 1a6a502

Please sign in to comment.