Skip to content

Commit

Permalink
Rename gRPC transport settings and move to aux package.
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <[email protected]>
  • Loading branch information
finnegancarroll committed Dec 16, 2024
1 parent 8a3f634 commit 1a9170a
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,17 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;

import static java.util.Collections.emptyList;
import static org.opensearch.common.settings.Setting.intSetting;
import static org.opensearch.common.settings.Setting.listSetting;
import static org.opensearch.aux.AuxTransportSettings.SETTING_AUX_BIND_HOST;
import static org.opensearch.aux.AuxTransportSettings.SETTING_AUX_HOST;
import static org.opensearch.aux.AuxTransportSettings.SETTING_AUX_PUBLISH_HOST;

/**
* Main class for the gRPC plugin
*/
public final class GrpcModulePlugin extends Plugin implements NetworkPlugin {
public static final String GRPC_TRANSPORT_NAME = "grpc-transport";
public static final Setting<Integer> SETTING_GRPC_PUBLISH_PORT = intSetting("grpc.publish_port", -1, -1, Setting.Property.NodeScope);

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",
SETTING_GRPC_HOST,
Function.identity(),
Setting.Property.NodeScope
);

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<Integer> SETTING_GRPC_WORKER_COUNT = new Setting<>(
"grpc.netty.worker_count",
Expand Down Expand Up @@ -85,6 +62,6 @@ public Map<String, Supplier<LifecycleComponent>> getAuxTransports(

@Override
public List<Setting<?>> getSettings() {
return List.of(SETTING_GRPC_HOST, SETTING_GRPC_PUBLISH_HOST, SETTING_GRPC_BIND_HOST, SETTING_GRPC_WORKER_COUNT);
return List.of(SETTING_AUX_HOST, SETTING_AUX_PUBLISH_HOST, SETTING_AUX_BIND_HOST, SETTING_GRPC_WORKER_COUNT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
import io.grpc.protobuf.services.HealthStatusManager;
import io.grpc.protobuf.services.ProtoReflectionService;

import static org.opensearch.aux.AuxTransportSettings.SETTING_AUX_BIND_HOST;
import static org.opensearch.aux.AuxTransportSettings.SETTING_AUX_PORT;
import static org.opensearch.aux.AuxTransportSettings.SETTING_AUX_PUBLISH_HOST;
import static org.opensearch.aux.AuxTransportSettings.SETTING_AUX_PUBLISH_PORT;
import static org.opensearch.common.network.NetworkService.resolvePublishPort;
import static org.opensearch.common.util.concurrent.OpenSearchExecutors.daemonThreadFactory;
import static org.opensearch.grpc.AuxTransportSettings.SETTING_AUX_PORT;
import static org.opensearch.transport.grpc.GrpcModulePlugin.SETTING_GRPC_BIND_HOST;
import static org.opensearch.transport.grpc.GrpcModulePlugin.SETTING_GRPC_PUBLISH_HOST;
import static org.opensearch.transport.grpc.GrpcModulePlugin.SETTING_GRPC_PUBLISH_PORT;
import static org.opensearch.transport.grpc.GrpcModulePlugin.SETTING_GRPC_WORKER_COUNT;

public class Netty4GrpcServerTransport extends AbstractLifecycleComponent implements LifecycleComponent {
Expand All @@ -69,12 +69,12 @@ public Netty4GrpcServerTransport(Settings settings, List<BindableService> servic
this.services = Objects.requireNonNull(services);
this.networkService = Objects.requireNonNull(networkService);

final List<String> httpBindHost = SETTING_GRPC_BIND_HOST.get(settings);
final List<String> httpBindHost = SETTING_AUX_BIND_HOST.get(settings);
this.bindHosts = (httpBindHost.isEmpty() ? NetworkService.GLOBAL_NETWORK_BIND_HOST_SETTING.get(settings) : httpBindHost).toArray(
Strings.EMPTY_ARRAY
);

final List<String> httpPublishHost = SETTING_GRPC_PUBLISH_HOST.get(settings);
final List<String> httpPublishHost = SETTING_AUX_PUBLISH_HOST.get(settings);
this.publishHosts = (httpPublishHost.isEmpty() ? NetworkService.GLOBAL_NETWORK_PUBLISH_HOST_SETTING.get(settings) : httpPublishHost)
.toArray(Strings.EMPTY_ARRAY);

Expand Down Expand Up @@ -151,7 +151,7 @@ private void bindServer() {
throw new BindTransportException("Failed to resolve publish address", e);
}

final int publishPort = resolvePublishPort(SETTING_GRPC_PUBLISH_PORT.get(settings), boundAddresses, publishInetAddress);
final int publishPort = resolvePublishPort(SETTING_AUX_PUBLISH_PORT.get(settings), boundAddresses, publishInetAddress);
if (publishPort < 0) {
throw new BindTransportException(
"Failed to auto-resolve grpc publish port, multiple bound addresses "
Expand All @@ -162,7 +162,7 @@ private void bindServer() {
+ "Please specify a unique port by setting "
+ SETTING_AUX_PORT.getKey()
+ " or "
+ SETTING_GRPC_PUBLISH_PORT.getKey()
+ SETTING_AUX_PUBLISH_PORT.getKey()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

package org.opensearch.transport.grpc;

import org.opensearch.aux.AuxTransportSettings;
import org.opensearch.common.network.NetworkService;
import org.opensearch.common.settings.Settings;
import org.opensearch.grpc.AuxTransportSettings;
import org.opensearch.test.OpenSearchTestCase;
import org.hamcrest.MatcherAssert;
import org.junit.Before;
Expand Down
55 changes: 55 additions & 0 deletions server/src/main/java/org/opensearch/aux/AuxTransportSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.aux;

import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Setting.Property;
import org.opensearch.common.transport.PortsRange;

import java.util.List;
import java.util.function.Function;

import static java.util.Collections.emptyList;
import static org.opensearch.common.settings.Setting.intSetting;
import static org.opensearch.common.settings.Setting.listSetting;

/**
* Auxiliary transport server settings.
*
* @opensearch.internal
*/
public final class AuxTransportSettings {

public static final Setting<PortsRange> SETTING_AUX_PORT = new Setting<>("aux.port", "9400-9500", PortsRange::new, Property.NodeScope);

public static final Setting<Integer> SETTING_AUX_PUBLISH_PORT = intSetting("aux.publish_port", -1, -1, Setting.Property.NodeScope);

public static final Setting<List<String>> SETTING_AUX_HOST = listSetting(
"aux.host",
emptyList(),
Function.identity(),
Setting.Property.NodeScope
);

public static final Setting<List<String>> SETTING_AUX_PUBLISH_HOST = listSetting(
"aux.publish_host",
SETTING_AUX_HOST,
Function.identity(),
Setting.Property.NodeScope
);

public static final Setting<List<String>> SETTING_AUX_BIND_HOST = listSetting(
"aux.bind_host",
SETTING_AUX_HOST,
Function.identity(),
Setting.Property.NodeScope
);

private AuxTransportSettings() {}
}
12 changes: 12 additions & 0 deletions server/src/main/java/org/opensearch/aux/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.
*/

/**
* Settings and configuration helpers for optional auxiliary client/server transports provided by installed plugins.
*/
package org.opensearch.aux;
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

package org.opensearch.bootstrap;

import org.opensearch.aux.AuxTransportSettings;
import org.opensearch.cli.Command;
import org.opensearch.common.SuppressForbidden;
import org.opensearch.common.io.PathUtils;
import org.opensearch.common.settings.Settings;
import org.opensearch.env.Environment;
import org.opensearch.grpc.AuxTransportSettings;
import org.opensearch.http.HttpTransportSettings;
import org.opensearch.plugins.PluginInfo;
import org.opensearch.plugins.PluginsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.opensearch.action.support.AutoCreateIndex;
import org.opensearch.action.support.DestructiveOperations;
import org.opensearch.action.support.replication.TransportReplicationAction;
import org.opensearch.aux.AuxTransportSettings;
import org.opensearch.bootstrap.BootstrapSettings;
import org.opensearch.client.Client;
import org.opensearch.cluster.ClusterModule;
Expand Down Expand Up @@ -111,7 +112,6 @@
import org.opensearch.gateway.remote.RemoteClusterStateService;
import org.opensearch.gateway.remote.RemoteIndexMetadataManager;
import org.opensearch.gateway.remote.model.RemoteRoutingTableBlobStore;
import org.opensearch.grpc.AuxTransportSettings;
import org.opensearch.http.HttpTransportSettings;
import org.opensearch.index.IndexModule;
import org.opensearch.index.IndexSettings;
Expand Down
25 changes: 0 additions & 25 deletions server/src/main/java/org/opensearch/grpc/AuxTransportSettings.java

This file was deleted.

0 comments on commit 1a9170a

Please sign in to comment.