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

Refactor Netty4 method #166

Merged
merged 17 commits into from
Oct 4, 2022
Merged

Refactor Netty4 method #166

merged 17 commits into from
Oct 4, 2022

Conversation

mloufra
Copy link
Contributor

@mloufra mloufra commented Sep 30, 2022

Description

Create a new class GetNetty4Transport.java to handle getNetty4Transport and initializeExtensionTransportService method for refactoring the class in ExtensionsRunner.java.

Issues Resolved

#116

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

mloufra and others added 14 commits August 26, 2022 16:43
Signed-off-by: mloufra <mloufra@amazon.com>
Signed-off-by: mloufra <mloufra@amazon.com>
Signed-off-by: mloufra <mloufra@amazon.com>
Signed-off-by: mloufra <mloufra@amazon.com>
Signed-off-by: mloufra <mloufra@amazon.com>
Signed-off-by: mloufra <mloufra@amazon.com>
Signed-off-by: mloufra <mloufra@amazon.com>
Signed-off-by: mloufra <mloufra@amazon.com>
@mloufra mloufra requested a review from a team September 30, 2022 22:45
@codecov-commenter
Copy link

Codecov Report

Merging #166 (0e9cd6f) into main (7218f6e) will increase coverage by 0.14%.
The diff coverage is 87.50%.

@@             Coverage Diff              @@
##               main     #166      +/-   ##
============================================
+ Coverage     65.73%   65.87%   +0.14%     
- Complexity       94       95       +1     
============================================
  Files            24       25       +1     
  Lines           464      466       +2     
  Branches         13       13              
============================================
+ Hits            305      307       +2     
  Misses          151      151              
  Partials          8        8              
Impacted Files Coverage Δ
...main/java/org/opensearch/sdk/ExtensionsRunner.java 63.01% <50.00%> (-4.43%) ⬇️
...in/java/org/opensearch/sdk/GetNetty4Transport.java 92.85% <92.85%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

* This class initializes a Netty4Transport object and control communication between the extension and OpenSearch.
*/

public class GetNetty4Transport {
Copy link
Member

@owaiskazi19 owaiskazi19 Oct 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename it here and everywhere to NettyTransport or Netty4Transport

/**
* This field is initialized by a call from {@link GetNetty4Transport}.
*/
public final TransportInterceptor NOOP_TRANSPORT_INTERCEPTOR = new TransportInterceptor() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this to the newly created Netty4Transportclass and make it private.

/**
* This String get a call from {@link GetNetty4Transport}.
*/
public static final String NODE_NAME_SETTING = "node.name";
Copy link
Member

@owaiskazi19 owaiskazi19 Oct 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this to the newly created Netty4Transport class and make it private.

@@ -170,7 +157,7 @@ private ExtensionsRunner(Extension extension) throws IOException {
// save custom settings
this.customSettings = extension.getSettings();
// initialize the transport service
this.initializeExtensionTransportService(this.getSettings());
this.getNetty4Transport.initializeExtensionTransportService(this.getSettings(), null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can be called like

getNetty4Transport.initializeExtensionTransportService(....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we passing null here? We should avoid it.

Copy link
Contributor Author

@mloufra mloufra Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we passing null here? We should avoid it.

The initializeExtensionTransportService method need to call method extensionTransportService from ExtensionsRunner.java, so we should have a reference to the object. And it will be this instead of null. I will change that in next commit.

@@ -591,7 +501,7 @@ public static void main(String[] args) throws IOException {
ExtensionsRunner extensionsRunner = new ExtensionsRunner();

// initialize the transport service
extensionsRunner.initializeExtensionTransportService(extensionsRunner.getSettings());
extensionsRunner.getNetty4Transport.initializeExtensionTransportService(extensionsRunner.getSettings(), extensionsRunner);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid passing the object of extensionRunner here directly. Instead, all of the required methods, variables should be moved to Netty4Transport file.


@BeforeEach
public void setUp() throws IOException {
this.extensionsRunner = new ExtensionsRunner();
new ExtensionsRunner();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we doing here exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we start refactor nettyTransport method, we call the nettyTransport method from ExtensionsRunner.java. Since the getNetty4Transport moved to a new class, we do not need to call this method from ExtensionsRunner.java. So I use IDE delete this line, but the IDE do not help delete whole line, half line has been left. I will delete that in next commit.

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @owaiskazi19 said, we don't need to pass an ExtensionsRunner object to this class, as the only thing we really do with it is set the value of the transport service -- which is returned from the method anyway. I realize the code you're refactoring was already somewhat redundant so it's a bit confusing but this is a good opportunity to clean it up.

NetworkModule.getNamedWriteables().stream(),
indicesModule.getNamedWriteables().stream(),
searchModule.getNamedWriteables().stream(),
null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to include a null in the stream. Just omit it. If there's a reason we are excluding something (I think this is where plugins module goes?) just add a comment explaining why it doesn't look like the other calls.


final ConnectionManager connectionManager = new ClusterConnectionManager(settings, transport);

// Stop any existing transport service
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this code block while it was in the ExtensionsRunner class. Now that it's in its own class we have much better control over its initialization so you can remove these lines.

}

// create transport service
extensionsRunner.extensionTransportService = new TransportService(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not set a field in another class from here. This method returns the initialized transport service, so just return it and in the ExtensionsRunner where this method is called, just set the value there.

I realize the method in the old class was awkward setting a variable we already had access to, but I think that was for tests. Moving it to this class should make everything much more self-contained.

Signed-off-by: mloufra <mloufra@amazon.com>
Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as a refactor. Consider the suggestions but don't hold up the PR for them.

I still think it's really confusing having the transportService object being referenced from outside the class, but that's a more complicated discussion we can deal with at another time.

private ExtensionNamedWriteableRegistry namedWriteableRegistryApi = new ExtensionNamedWriteableRegistry();
private ExtensionsInitRequestHandler extensionsInitRequestHandler = new ExtensionsInitRequestHandler();
private OpensearchRequestHandler opensearchRequestHandler = new OpensearchRequestHandler();
private ExtensionsIndicesModuleRequestHandler extensionsIndicesModuleRequestHandler = new ExtensionsIndicesModuleRequestHandler();
private ExtensionsIndicesModuleNameRequestHandler extensionsIndicesModuleNameRequestHandler =
new ExtensionsIndicesModuleNameRequestHandler();
private ExtensionsRestRequestHandler extensionsRestRequestHandler = new ExtensionsRestRequestHandler();
private NettyTransport nettyTransport = new NettyTransport();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Suggestion) rather than sending this in the initialize call, send this in the constructor here and save it as an instance field so you don't have to pass it later.

emptySet()
);
extensionsRunner.startTransportService(extensionsRunner.extensionTransportService);
return extensionsRunner.extensionTransportService;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Suggestion) We're never using this return value, could just make this method return void.

@mloufra
Copy link
Contributor Author

mloufra commented Oct 4, 2022

LGTM as a refactor. Consider the suggestions but don't hold up the PR for them.

I still think it's really confusing having the transportService object being referenced from outside the class, but that's a more complicated discussion we can deal with at another time.

I will deal with these comment in my next PR.

@saratvemulapalli
Copy link
Member

LGTM as a refactor. Consider the suggestions but don't hold up the PR for them.

I still think it's really confusing having the transportService object being referenced from outside the class, but that's a more complicated discussion we can deal with at another time.

+1

@mloufra mloufra merged commit 8822d95 into opensearch-project:main Oct 4, 2022
@mloufra mloufra deleted the refactor-netty4 branch October 4, 2022 18:40
kokibas pushed a commit to kokibas/opensearch-sdk-java that referenced this pull request Mar 17, 2023
* issue opensearch-project#28

Signed-off-by: mloufra <mloufra@amazon.com>

* Update the lastest coomit

Signed-off-by: mloufra <mloufra@amazon.com>

* Rename the method and fix the conflict

Signed-off-by: mloufra <mloufra@amazon.com>

* fix merge conflict

Signed-off-by: mloufra <mloufra@amazon.com>

* Add code coverage report

Signed-off-by: mloufra <mloufra@amazon.com>

* Rebase the lastest commit

Signed-off-by: mloufra <mloufra@amazon.com>

* update the lastest commit

Signed-off-by: mloufra <mloufra@amazon.com>

* refactor netty4 and initialozaExtensionTransport method

Signed-off-by: mloufra <mloufra@amazon.com>

* resolve comment

Signed-off-by: mloufra <mloufra@amazon.com>

Signed-off-by: mloufra <mloufra@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants