From 5887ad9fe730093b5ad4d03dc9d0e8c6ef9a8f7b Mon Sep 17 00:00:00 2001 From: Finn Carroll Date: Wed, 18 Dec 2024 10:32:04 -0800 Subject: [PATCH] Javadocs for Netty4GrpcServerTransport. Signed-off-by: Finn Carroll --- .../transport/grpc/GrpcModulePlugin.java | 7 ++- .../grpc/Netty4GrpcServerTransport.java | 57 +++++++++++++++---- .../transport/grpc/package-info.java | 13 +++++ 3 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/package-info.java diff --git a/plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/GrpcModulePlugin.java b/plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/GrpcModulePlugin.java index 0f4335e0c9abf..50c12885044a4 100644 --- a/plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/GrpcModulePlugin.java +++ b/plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/GrpcModulePlugin.java @@ -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> getAuxTransports( Settings settings, diff --git a/plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/Netty4GrpcServerTransport.java b/plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/Netty4GrpcServerTransport.java index 35a64c2b96b06..627ea9eb70bdc 100644 --- a/plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/Netty4GrpcServerTransport.java +++ b/plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/Netty4GrpcServerTransport.java @@ -49,22 +49,35 @@ 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 SETTING_GRPC_PORTS = AUX_TRANSPORT_PORTS.getConcreteSettingForNamespace( GRPC_TRANSPORT_SETTING_KEY ); - public static final Setting 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 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> SETTING_GRPC_HOST = listSetting( "grpc.host", emptyList(), @@ -72,20 +85,36 @@ public class Netty4GrpcServerTransport extends NetworkPlugin.AuxTransport { Setting.Property.NodeScope ); - public static final Setting> SETTING_GRPC_PUBLISH_HOST = listSetting( - "grpc.publish_host", + /** + * Host list to bind. + */ + public static final Setting> SETTING_GRPC_BIND_HOST = listSetting( + "grpc.bind_host", SETTING_GRPC_HOST, Function.identity(), Setting.Property.NodeScope ); - public static final Setting> SETTING_GRPC_BIND_HOST = listSetting( - "grpc.bind_host", + /** + * Host list published to peers. + */ + public static final Setting> 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 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 services; @@ -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 services, NetworkService networkService) { this.settings = Objects.requireNonNull(settings); this.services = Objects.requireNonNull(services); diff --git a/plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/package-info.java b/plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/package-info.java new file mode 100644 index 0000000000000..4a5d9d02b5b91 --- /dev/null +++ b/plugins/transport-grpc/src/main/java/org/opensearch/transport/grpc/package-info.java @@ -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;