First attempt at supporting builds with Java 11
Includes:
- Bump protobuf to 3.8.0 and grpc-java to 1.21.0 (along with transitive
dependencies such as Netty)
- Add jaxb_api at compile time when needed (removed in JDK 11)
- Bump Bnd to 4.1 (adds support for Java 11)
To build with JDK 11, uncomment lines in .bazelrc.
Tested with Bazel 0.26.0.
Change-Id: Ib8e0c7310eacf97328762606e57c01e4834e5565
diff --git a/protocols/gnmi/ctl/BUILD b/protocols/gnmi/ctl/BUILD
index 482a37f..a82dafd 100644
--- a/protocols/gnmi/ctl/BUILD
+++ b/protocols/gnmi/ctl/BUILD
@@ -3,7 +3,7 @@
"//protocols/gnmi/stub:onos-protocols-gnmi-stub",
"//protocols/grpc/api:onos-protocols-grpc-api",
"//protocols/grpc/ctl:onos-protocols-grpc-ctl",
- "//lib:io_grpc_grpc_core_context",
+ "//lib:io_grpc_grpc_api_context",
"//lib:com_google_protobuf_protobuf_java",
"//lib:io_grpc_grpc_netty",
"//lib:io_grpc_grpc_protobuf_lite",
@@ -13,7 +13,7 @@
TEST_DEPS = TEST + [
"@minimal_json//jar",
- "//lib:io_grpc_grpc_core_context",
+ "//lib:io_grpc_grpc_api_context",
"//lib:io_grpc_grpc_protobuf_lite",
]
diff --git a/protocols/gnoi/ctl/BUILD b/protocols/gnoi/ctl/BUILD
index 84322ba..d3659d3 100644
--- a/protocols/gnoi/ctl/BUILD
+++ b/protocols/gnoi/ctl/BUILD
@@ -3,7 +3,7 @@
"//protocols/gnoi/stub:onos-protocols-gnoi-stub",
"//protocols/grpc/api:onos-protocols-grpc-api",
"//protocols/grpc/ctl:onos-protocols-grpc-ctl",
- "//lib:io_grpc_grpc_core_context",
+ "//lib:io_grpc_grpc_api_context",
"//lib:com_google_protobuf_protobuf_java",
"//lib:io_grpc_grpc_netty",
"//lib:io_grpc_grpc_protobuf_lite",
@@ -13,7 +13,7 @@
TEST_DEPS = TEST + [
"@minimal_json//jar",
- "//lib:io_grpc_grpc_core_context",
+ "//lib:io_grpc_grpc_api_context",
"//lib:io_grpc_grpc_protobuf_lite",
]
diff --git a/protocols/grpc/BUILD b/protocols/grpc/BUILD
index 59a99f0..3fa5169 100644
--- a/protocols/grpc/BUILD
+++ b/protocols/grpc/BUILD
@@ -3,7 +3,11 @@
"//protocols/grpc/ctl:onos-protocols-grpc-ctl",
"//protocols/grpc/utils:onos-protocols-grpc-utils",
# gRPC dependencies (with patched core)
- "//lib:io_grpc_grpc_core_context",
+ "//lib:io_grpc_grpc_api_context",
+ "//lib:io_grpc_grpc_core_internal",
+ "//lib:io_grpc_grpc_core_inprocess",
+ "//lib:io_grpc_grpc_core_util",
+ "//lib:io_grpc_grpc_core_perfmark",
"//lib:io_grpc_grpc_stub",
"//lib:io_grpc_grpc_netty",
"//lib:io_grpc_grpc_auth",
diff --git a/protocols/grpc/api/BUILD b/protocols/grpc/api/BUILD
index 5a2b2d7..3247fcd 100644
--- a/protocols/grpc/api/BUILD
+++ b/protocols/grpc/api/BUILD
@@ -1,3 +1,3 @@
osgi_jar(
- deps = CORE_DEPS + ["//lib:io_grpc_grpc_core_context"],
+ deps = CORE_DEPS + ["//lib:io_grpc_grpc_api_context"],
)
diff --git a/protocols/grpc/ctl/BUILD b/protocols/grpc/ctl/BUILD
index 16676c5..77239e4 100644
--- a/protocols/grpc/ctl/BUILD
+++ b/protocols/grpc/ctl/BUILD
@@ -1,6 +1,7 @@
COMPILE_DEPS = CORE_DEPS + [
"//protocols/grpc/api:onos-protocols-grpc-api",
- "//lib:io_grpc_grpc_core_context",
+ "//lib:io_grpc_grpc_api_context",
+ "//lib:io_grpc_grpc_core_internal",
"//lib:io_grpc_grpc_netty",
"//lib:io_grpc_grpc_protobuf_lite",
"//lib:com_google_protobuf_protobuf_java",
diff --git a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcChannelControllerImpl.java b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcChannelControllerImpl.java
index 3be7706..9e2321e 100644
--- a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcChannelControllerImpl.java
+++ b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcChannelControllerImpl.java
@@ -17,8 +17,12 @@
package org.onosproject.grpc.ctl;
import com.google.common.util.concurrent.Striped;
+import io.grpc.LoadBalancerRegistry;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
+import io.grpc.NameResolverRegistry;
+import io.grpc.internal.DnsNameResolverProvider;
+import io.grpc.internal.PickFirstLoadBalancerProvider;
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NettyChannelBuilder;
import io.netty.handler.ssl.SslContext;
@@ -68,6 +72,11 @@
private static final int DEFAULT_MAX_INBOUND_MSG_SIZE = 256; // Megabytes.
private static final int MEGABYTES = 1024 * 1024;
+ private static final PickFirstLoadBalancerProvider PICK_FIRST_LOAD_BALANCER_PROVIDER =
+ new PickFirstLoadBalancerProvider();
+ private static final DnsNameResolverProvider DNS_NAME_RESOLVER_PROVIDER =
+ new DnsNameResolverProvider();
+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected ComponentConfigService componentConfigService;
@@ -89,6 +98,10 @@
componentConfigService.registerProperties(getClass());
channels = new ConcurrentHashMap<>();
interceptors = new ConcurrentHashMap<>();
+ LoadBalancerRegistry.getDefaultRegistry()
+ .register(PICK_FIRST_LOAD_BALANCER_PROVIDER);
+ NameResolverRegistry.getDefaultRegistry()
+ .register(DNS_NAME_RESOLVER_PROVIDER);
log.info("Started");
}
@@ -105,6 +118,10 @@
@Deactivate
public void deactivate() {
+ LoadBalancerRegistry.getDefaultRegistry()
+ .deregister(PICK_FIRST_LOAD_BALANCER_PROVIDER);
+ NameResolverRegistry.getDefaultRegistry()
+ .register(DNS_NAME_RESOLVER_PROVIDER);
componentConfigService.unregisterProperties(getClass(), false);
channels.values().forEach(ManagedChannel::shutdownNow);
channels.clear();
@@ -162,9 +179,12 @@
final boolean useTls = channelUri.getScheme().equals(GRPCS);
final NettyChannelBuilder channelBuilder = NettyChannelBuilder
- .forAddress(channelUri.getHost(),
- channelUri.getPort())
- .maxInboundMessageSize(DEFAULT_MAX_INBOUND_MSG_SIZE * MEGABYTES);
+ .forAddress(channelUri.getHost(), channelUri.getPort())
+ .nameResolverFactory(DNS_NAME_RESOLVER_PROVIDER)
+ .defaultLoadBalancingPolicy(
+ PICK_FIRST_LOAD_BALANCER_PROVIDER.getPolicyName())
+ .maxInboundMessageSize(
+ DEFAULT_MAX_INBOUND_MSG_SIZE * MEGABYTES);
if (useTls) {
try {
diff --git a/protocols/grpc/utils/BUILD b/protocols/grpc/utils/BUILD
index 25a78ad..c3e6e77 100644
--- a/protocols/grpc/utils/BUILD
+++ b/protocols/grpc/utils/BUILD
@@ -1,6 +1,6 @@
COMPILE_DEPS = CORE_DEPS + [
"//protocols/grpc/api:onos-protocols-grpc-api",
- "//lib:io_grpc_grpc_core_context",
+ "//lib:io_grpc_grpc_api_context",
]
osgi_jar(
diff --git a/protocols/grpc/utils/src/main/java/org/onosproject/grpc/utils/AbstractGrpcHandshaker.java b/protocols/grpc/utils/src/main/java/org/onosproject/grpc/utils/AbstractGrpcHandshaker.java
index 4cfb63b..cc06d9e 100644
--- a/protocols/grpc/utils/src/main/java/org/onosproject/grpc/utils/AbstractGrpcHandshaker.java
+++ b/protocols/grpc/utils/src/main/java/org/onosproject/grpc/utils/AbstractGrpcHandshaker.java
@@ -90,12 +90,7 @@
.orElseThrow(() -> new IllegalStateException(
"Missing gRPC channel in controller"));
} else {
- try {
- channel = channelController.create(netcfgUri);
- } catch (IllegalArgumentException ex) {
- throw new IllegalStateException(
- "A gRPC channel with same URI already exists", ex);
- }
+ channel = channelController.create(netcfgUri);
// Store channel URI for future use.
CHANNEL_URIS.put(deviceId, netcfgUri);
// Trigger connection.
@@ -178,7 +173,7 @@
.removeDeviceAgentListener(data().deviceId(), providerId);
}
- private void resetChannelConnectBackoffIfNeeded() {
+ private void resetChannelConnectBackoffIfNeeded() {
// Stimulate channel reconnect if in failure state.
final ManagedChannel channel = getExistingChannel();
if (channel == null) {
@@ -186,7 +181,7 @@
return;
}
if (channel.getState(false)
- .equals(ConnectivityState.TRANSIENT_FAILURE)) {
+ .equals(ConnectivityState.TRANSIENT_FAILURE)) {
channel.resetConnectBackoff();
}
}
diff --git a/protocols/p4runtime/api/BUILD b/protocols/p4runtime/api/BUILD
index 47a4dd2..b958045 100644
--- a/protocols/p4runtime/api/BUILD
+++ b/protocols/p4runtime/api/BUILD
@@ -1,6 +1,6 @@
COMPILE_DEPS = CORE_DEPS + [
"//protocols/grpc/api:onos-protocols-grpc-api",
- "//lib:io_grpc_grpc_core_context",
+ "//lib:io_grpc_grpc_api_context",
]
TEST_DEPS = TEST + [
diff --git a/protocols/p4runtime/ctl/BUILD b/protocols/p4runtime/ctl/BUILD
index 628d162..5f8db80 100644
--- a/protocols/p4runtime/ctl/BUILD
+++ b/protocols/p4runtime/ctl/BUILD
@@ -5,7 +5,7 @@
"//protocols/p4runtime/api:onos-protocols-p4runtime-api",
"//protocols/p4runtime/proto:onos-protocols-p4runtime-proto",
"//lib:com_google_protobuf_protobuf_java",
- "//lib:io_grpc_grpc_core_context",
+ "//lib:io_grpc_grpc_api_context",
"//lib:io_grpc_grpc_netty",
"//lib:io_grpc_grpc_protobuf_lite",
"//lib:io_grpc_grpc_stub",
@@ -14,7 +14,9 @@
TEST_DEPS = TEST + [
"@minimal_json//jar",
- "//lib:io_grpc_grpc_core_context",
+ "//lib:io_grpc_grpc_api_context",
+ "//lib:io_grpc_grpc_core_internal",
+ "//lib:io_grpc_grpc_core_inprocess",
"//lib:io_grpc_grpc_protobuf_lite",
]