-
Notifications
You must be signed in to change notification settings - Fork 58
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
Conversation
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>
Codecov Report
@@ 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
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 { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
.
/** | ||
* This String get a call from {@link GetNetty4Transport}. | ||
*/ | ||
public static final String NODE_NAME_SETTING = "node.name"; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(....
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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>
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
.
I will deal with these comment in my next PR. |
+1 |
* 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>
Description
Create a new class
GetNetty4Transport.java
to handlegetNetty4Transport
andinitializeExtensionTransportService
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.