-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7502353
issue #28
mloufra dbb47f5
Update the lastest coomit
mloufra bea6873
Rename the method and fix the conflict
mloufra 0e5dd7f
fix merge conflict
mloufra 11bd149
Add code coverage report
mloufra bbccd26
Rebase the lastest commit
mloufra b182b35
updata the lastest commit
mloufra 1bcb46c
update the lastest commit
mloufra 50ff5e7
Merge branch 'opensearch-project:main' into main
mloufra 2309183
Merge branch 'main' of https://github.com/mloufra/opensearch-sdk into…
mloufra 05afe09
Merge branch 'main' of https://github.com/mloufra/opensearch-sdk into…
mloufra cdac476
Merge branch 'main' of https://github.com/mloufra/opensearch-sdk into…
mloufra 880001a
Merge branch 'main' of https://github.com/mloufra/opensearch-sdk into…
mloufra 38e7c45
Merge branch 'main' of https://github.com/mloufra/opensearch-sdk into…
mloufra fc39396
Merge branch 'main' of https://github.com/mloufra/opensearch-sdk into…
mloufra 0e9cd6f
refactor netty4 and initialozaExtensionTransport method
mloufra a8f236f
resolve comment
mloufra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.sdk; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import org.opensearch.Version; | ||
import org.opensearch.cluster.ClusterModule; | ||
import org.opensearch.cluster.node.DiscoveryNode; | ||
import org.opensearch.common.io.stream.NamedWriteableRegistry; | ||
import org.opensearch.common.network.NetworkModule; | ||
import org.opensearch.common.network.NetworkService; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.PageCacheRecycler; | ||
import org.opensearch.indices.IndicesModule; | ||
import org.opensearch.indices.breaker.CircuitBreakerService; | ||
import org.opensearch.indices.breaker.NoneCircuitBreakerService; | ||
import org.opensearch.search.SearchModule; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.transport.SharedGroupFactory; | ||
import org.opensearch.transport.TransportInterceptor; | ||
import org.opensearch.transport.TransportService; | ||
import org.opensearch.transport.netty4.Netty4Transport; | ||
|
||
import static java.util.Collections.emptySet; | ||
import static org.opensearch.common.UUIDs.randomBase64UUID; | ||
|
||
/** | ||
* This class initializes a Netty4Transport object and control communication between the extension and OpenSearch. | ||
*/ | ||
|
||
public class NettyTransport { | ||
private static final String NODE_NAME_SETTING = "node.name"; | ||
private final TransportInterceptor NOOP_TRANSPORT_INTERCEPTOR = new TransportInterceptor() { | ||
}; | ||
|
||
/** | ||
* Initializes a Netty4Transport object. This object will be wrapped in a {@link TransportService} object. | ||
* | ||
* @param settings The transport settings to configure. | ||
* @param threadPool A thread pool to use. | ||
* @return The configured Netty4Transport object. | ||
*/ | ||
public Netty4Transport getNetty4Transport(Settings settings, ThreadPool threadPool) { | ||
NetworkService networkService = new NetworkService(Collections.emptyList()); | ||
PageCacheRecycler pageCacheRecycler = new PageCacheRecycler(settings); | ||
IndicesModule indicesModule = new IndicesModule(Collections.emptyList()); | ||
SearchModule searchModule = new SearchModule(settings, Collections.emptyList()); | ||
|
||
List<NamedWriteableRegistry.Entry> namedWriteables = Stream.of( | ||
NetworkModule.getNamedWriteables().stream(), | ||
indicesModule.getNamedWriteables().stream(), | ||
searchModule.getNamedWriteables().stream(), | ||
ClusterModule.getNamedWriteables().stream() | ||
).flatMap(Function.identity()).collect(Collectors.toList()); | ||
|
||
final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(namedWriteables); | ||
|
||
final CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService(); | ||
|
||
Netty4Transport transport = new Netty4Transport( | ||
settings, | ||
Version.CURRENT, | ||
threadPool, | ||
networkService, | ||
pageCacheRecycler, | ||
namedWriteableRegistry, | ||
circuitBreakerService, | ||
new SharedGroupFactory(settings) | ||
); | ||
|
||
return transport; | ||
} | ||
|
||
/** | ||
* Initializes the TransportService object for this extension. This object will control communication between the extension and OpenSearch. | ||
* | ||
* @param settings The transport settings to configure. | ||
* @param extensionsRunner method to call | ||
* @return The initialized TransportService object. | ||
*/ | ||
public TransportService initializeExtensionTransportService(Settings settings, ExtensionsRunner extensionsRunner) { | ||
|
||
ThreadPool threadPool = new ThreadPool(settings); | ||
|
||
Netty4Transport transport = getNetty4Transport(settings, threadPool); | ||
|
||
// Stop any existing transport service | ||
if (extensionsRunner.extensionTransportService != null) { | ||
extensionsRunner.extensionTransportService.stop(); | ||
} | ||
|
||
// create transport service | ||
extensionsRunner.extensionTransportService = new TransportService( | ||
settings, | ||
transport, | ||
threadPool, | ||
NOOP_TRANSPORT_INTERCEPTOR, | ||
boundAddress -> DiscoveryNode.createLocal( | ||
Settings.builder().put(NODE_NAME_SETTING, settings.get(NODE_NAME_SETTING)).build(), | ||
boundAddress.publishAddress(), | ||
randomBase64UUID() | ||
), | ||
null, | ||
emptySet() | ||
); | ||
extensionsRunner.startTransportService(extensionsRunner.extensionTransportService); | ||
return extensionsRunner.extensionTransportService; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, sendthis
in the constructor here and save it as an instance field so you don't have to pass it later.