Skip to content

Commit

Permalink
Javadocs for Netty4GrpcServerTransport.
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <[email protected]>
  • Loading branch information
finnegancarroll committed Dec 24, 2024
1 parent 6db9aa2 commit 5887ad9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@
import static org.opensearch.transport.grpc.Netty4GrpcServerTransport.SETTING_GRPC_WORKER_COUNT;

/**
* Main class for the gRPC plugin
* Main class for the gRPC plugin.
*/
public final class GrpcModulePlugin extends Plugin implements NetworkPlugin {

/**
* Creates a new GrpcModulePlugin instance.
*/
GrpcModulePlugin() {}

@Override
public Map<String, Supplier<AuxTransport>> getAuxTransports(
Settings settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,72 @@
import static org.opensearch.common.util.concurrent.OpenSearchExecutors.daemonThreadFactory;
import static org.opensearch.transport.TcpTransport.resolveTransportPublishPort;

/**
* Netty4 gRPC server implemented as a LifecycleComponent.
* Services injected through BindableService list.
*/
public class Netty4GrpcServerTransport extends NetworkPlugin.AuxTransport {
private static final Logger logger = LogManager.getLogger(Netty4GrpcServerTransport.class);

/**
* Type key for configuring settings of this auxiliary transport.
*/
public static final String GRPC_TRANSPORT_SETTING_KEY = "experimental-transport-grpc";

/**
* Port range on which to bind.
* Note this setting is configured through AffixSetting AUX_TRANSPORT_PORTS where the aux transport type matches the GRPC_TRANSPORT_SETTING_KEY.
*/
public static final Setting<PortsRange> SETTING_GRPC_PORTS = AUX_TRANSPORT_PORTS.getConcreteSettingForNamespace(
GRPC_TRANSPORT_SETTING_KEY
);

public static final Setting<Integer> SETTING_GRPC_WORKER_COUNT = new Setting<>(
"grpc.netty.worker_count",
(s) -> Integer.toString(OpenSearchExecutors.allocatedProcessors(s)),
(s) -> Setting.parseInt(s, 1, "grpc.netty.worker_count"),
Setting.Property.NodeScope
);

/**
* Port published to peers for this server.
*/
public static final Setting<Integer> SETTING_GRPC_PUBLISH_PORT = intSetting("grpc.publish_port", -1, -1, Setting.Property.NodeScope);

/**
* Host list to bind and publish.
* For distinct bind/publish hosts configure SETTING_GRPC_BIND_HOST + SETTING_GRPC_PUBLISH_HOST separately.
*/
public static final Setting<List<String>> SETTING_GRPC_HOST = listSetting(
"grpc.host",
emptyList(),
Function.identity(),
Setting.Property.NodeScope
);

public static final Setting<List<String>> SETTING_GRPC_PUBLISH_HOST = listSetting(
"grpc.publish_host",
/**
* Host list to bind.
*/
public static final Setting<List<String>> SETTING_GRPC_BIND_HOST = listSetting(
"grpc.bind_host",
SETTING_GRPC_HOST,
Function.identity(),
Setting.Property.NodeScope
);

public static final Setting<List<String>> SETTING_GRPC_BIND_HOST = listSetting(
"grpc.bind_host",
/**
* Host list published to peers.
*/
public static final Setting<List<String>> SETTING_GRPC_PUBLISH_HOST = listSetting(
"grpc.publish_host",
SETTING_GRPC_HOST,
Function.identity(),
Setting.Property.NodeScope
);

/**
* Configure size of thread pool backing this transport server.
*/
public static final Setting<Integer> SETTING_GRPC_WORKER_COUNT = new Setting<>(
"grpc.netty.worker_count",
(s) -> Integer.toString(OpenSearchExecutors.allocatedProcessors(s)),
(s) -> Setting.parseInt(s, 1, "grpc.netty.worker_count"),
Setting.Property.NodeScope
);

private final Settings settings;
private final NetworkService networkService;
private final List<BindableService> services;
Expand All @@ -98,6 +127,12 @@ public class Netty4GrpcServerTransport extends NetworkPlugin.AuxTransport {
private volatile BoundTransportAddress boundAddress;
private volatile EventLoopGroup eventLoopGroup;

/**
* Creates a new Netty4GrpcServerTransport instance.
* @param settings the configured settings.
* @param services the gRPC compatible services to be registered with the server.
* @param networkService the bind/publish addresses.
*/
public Netty4GrpcServerTransport(Settings settings, List<BindableService> services, NetworkService networkService) {
this.settings = Objects.requireNonNull(settings);
this.services = Objects.requireNonNull(services);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.
*/

/**
* gRPC transport implementation for OpenSearch.
* Provides network communication using the gRPC protocol.
*/
package org.opensearch.transport.grpc;

0 comments on commit 5887ad9

Please sign in to comment.