From c6e7129b6296755125b0f342d098538bf44df722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 20 Oct 2020 17:42:31 +0200 Subject: [PATCH] Extract gRPC common stuff --- bom/application/pom.xml | 10 +++ extensions/grpc-common/deployment/pom.xml | 55 ++++++++++++ .../deployment/GrpcCommonProcessor.java | 65 ++++++++++++++ .../grpc/common/deployment/GrpcDotNames.java | 15 ++++ extensions/grpc-common/pom.xml | 22 +++++ extensions/grpc-common/runtime/pom.xml | 88 +++++++++++++++++++ .../runtime/graal/GrpcNettySubstitutions.java | 2 +- .../runtime/graal/GrpcSubstitutions.java | 2 +- .../resources/META-INF/quarkus-extension.yaml | 11 +++ extensions/grpc/deployment/pom.xml | 8 +- .../quarkus/grpc/deployment/GrpcDotNames.java | 8 -- .../grpc/deployment/GrpcServerProcessor.java | 55 +----------- extensions/grpc/runtime/pom.xml | 42 ++------- extensions/pom.xml | 1 + 14 files changed, 281 insertions(+), 103 deletions(-) create mode 100644 extensions/grpc-common/deployment/pom.xml create mode 100644 extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcCommonProcessor.java create mode 100644 extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcDotNames.java create mode 100644 extensions/grpc-common/pom.xml create mode 100644 extensions/grpc-common/runtime/pom.xml rename extensions/{grpc/runtime/src/main/java/io/quarkus/grpc => grpc-common/runtime/src/main/java/io/quarkus/grpc/common}/runtime/graal/GrpcNettySubstitutions.java (97%) rename extensions/{grpc/runtime/src/main/java/io/quarkus/grpc => grpc-common/runtime/src/main/java/io/quarkus/grpc/common}/runtime/graal/GrpcSubstitutions.java (97%) create mode 100644 extensions/grpc-common/runtime/src/main/resources/META-INF/quarkus-extension.yaml diff --git a/bom/application/pom.xml b/bom/application/pom.xml index e4baad4035d03..e660e6648ab95 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -1343,6 +1343,11 @@ + + io.quarkus + quarkus-grpc-common + ${project.version} + io.quarkus quarkus-grpc-codegen @@ -1358,6 +1363,11 @@ quarkus-grpc-deployment ${project.version} + + io.quarkus + quarkus-grpc-common-deployment + ${project.version} + io.quarkus quarkus-grpc-protoc-plugin diff --git a/extensions/grpc-common/deployment/pom.xml b/extensions/grpc-common/deployment/pom.xml new file mode 100644 index 0000000000000..433317732e477 --- /dev/null +++ b/extensions/grpc-common/deployment/pom.xml @@ -0,0 +1,55 @@ + + + + quarkus-grpc-common-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-grpc-common-deployment + Quarkus - gRPC Common - Deployment + + + + io.quarkus + quarkus-grpc-common + + + io.quarkus + quarkus-core-deployment + + + io.quarkus + quarkus-vertx-deployment + + + + + + + maven-surefire-plugin + + + org.jboss.logmanager.LogManager + + + + + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${project.version} + + + + + + + + \ No newline at end of file diff --git a/extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcCommonProcessor.java b/extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcCommonProcessor.java new file mode 100644 index 0000000000000..ebff9fee02754 --- /dev/null +++ b/extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcCommonProcessor.java @@ -0,0 +1,65 @@ +package io.quarkus.grpc.common.deployment; + +import java.util.Collection; + +import org.jboss.jandex.ClassInfo; + +import io.grpc.internal.DnsNameResolverProvider; +import io.grpc.internal.PickFirstLoadBalancerProvider; +import io.grpc.netty.NettyChannelProvider; +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; +import io.quarkus.deployment.builditem.nativeimage.NativeImageConfigBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; + +public class GrpcCommonProcessor { + + @BuildStep + public void configureNativeExecutable(CombinedIndexBuildItem combinedIndex, + BuildProducer reflectiveClass) { + + // we force the usage of the reflection invoker. + Collection messages = combinedIndex.getIndex() + .getAllKnownSubclasses(GrpcDotNames.GENERATED_MESSAGE_V3); + for (ClassInfo message : messages) { + reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, true, message.name().toString())); + } + Collection builders = combinedIndex.getIndex().getAllKnownSubclasses(GrpcDotNames.MESSAGE_BUILDER); + for (ClassInfo builder : builders) { + reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, true, builder.name().toString())); + } + + Collection lbs = combinedIndex.getIndex().getAllKnownSubclasses(GrpcDotNames.LOAD_BALANCER_PROVIDER); + for (ClassInfo lb : lbs) { + reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, lb.name().toString())); + } + + Collection nrs = combinedIndex.getIndex().getAllKnownSubclasses(GrpcDotNames.NAME_RESOLVER_PROVIDER); + for (ClassInfo nr : nrs) { + reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, nr.name().toString())); + } + + // Built-In providers: + reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, DnsNameResolverProvider.class)); + reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, PickFirstLoadBalancerProvider.class)); + reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, + "io.grpc.util.SecretRoundRobinLoadBalancerProvider$Provider")); + reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, NettyChannelProvider.class)); + } + + @BuildStep + NativeImageConfigBuildItem nativeImageConfiguration() { + NativeImageConfigBuildItem.Builder builder = NativeImageConfigBuildItem.builder() + .addRuntimeInitializedClass("io.grpc.netty.Utils$ByteBufAllocatorPreferDirectHolder") + .addRuntimeInitializedClass("io.grpc.netty.Utils$ByteBufAllocatorPreferHeapHolder") + // substitutions are runtime-only, Utils have to be substituted until we cannot use EPoll + // in native. NettyServerBuilder and NettyChannelBuilder would "bring in" Utils in build time + // if they were not marked as runtime initialized: + .addRuntimeInitializedClass("io.grpc.netty.Utils") + .addRuntimeInitializedClass("io.grpc.netty.NettyServerBuilder") + .addRuntimeInitializedClass("io.grpc.netty.NettyChannelBuilder"); + return builder.build(); + } + +} diff --git a/extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcDotNames.java b/extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcDotNames.java new file mode 100644 index 0000000000000..12e5ca80aafec --- /dev/null +++ b/extensions/grpc-common/deployment/src/main/java/io/quarkus/grpc/common/deployment/GrpcDotNames.java @@ -0,0 +1,15 @@ +package io.quarkus.grpc.common.deployment; + +import org.jboss.jandex.DotName; + +import com.google.protobuf.GeneratedMessageV3; + +import io.grpc.LoadBalancerProvider; +import io.grpc.NameResolverProvider; + +public class GrpcDotNames { + static final DotName MESSAGE_BUILDER = DotName.createSimple(GeneratedMessageV3.Builder.class.getName()); + static final DotName GENERATED_MESSAGE_V3 = DotName.createSimple(GeneratedMessageV3.class.getName()); + static final DotName NAME_RESOLVER_PROVIDER = DotName.createSimple(NameResolverProvider.class.getName()); + static final DotName LOAD_BALANCER_PROVIDER = DotName.createSimple(LoadBalancerProvider.class.getName()); +} diff --git a/extensions/grpc-common/pom.xml b/extensions/grpc-common/pom.xml new file mode 100644 index 0000000000000..eb4f6ebc3e505 --- /dev/null +++ b/extensions/grpc-common/pom.xml @@ -0,0 +1,22 @@ + + + + quarkus-extensions-parent + io.quarkus + 999-SNAPSHOT + ../pom.xml + + 4.0.0 + + quarkus-grpc-common-parent + Quarkus - gRPC Common + pom + + + runtime + deployment + + + \ No newline at end of file diff --git a/extensions/grpc-common/runtime/pom.xml b/extensions/grpc-common/runtime/pom.xml new file mode 100644 index 0000000000000..d66663f38f12a --- /dev/null +++ b/extensions/grpc-common/runtime/pom.xml @@ -0,0 +1,88 @@ + + + + quarkus-grpc-common-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-grpc-common + Quarkus - gRPC Common - Runtime + + + + com.google.code.findbugs + jsr305 + + + io.vertx + vertx-grpc + + + org.codehaus.mojo + animal-sniffer-annotations + + + com.google.code.findbugs + jsr305 + + + org.checkerframework + checker-qual + + + javax.annotation + javax.annotation-api + + + com.google.android + annotations + + + + + io.quarkus + quarkus-vertx + + + org.graalvm.nativeimage + svm + + + + + + + io.quarkus + quarkus-bootstrap-maven-plugin + + + generate-extension-descriptor + + extension-descriptor + + process-resources + + ${project.groupId}:${project.artifactId}-deployment:${project.version} + + + + + + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${project.version} + + + + + + + \ No newline at end of file diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/graal/GrpcNettySubstitutions.java b/extensions/grpc-common/runtime/src/main/java/io/quarkus/grpc/common/runtime/graal/GrpcNettySubstitutions.java similarity index 97% rename from extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/graal/GrpcNettySubstitutions.java rename to extensions/grpc-common/runtime/src/main/java/io/quarkus/grpc/common/runtime/graal/GrpcNettySubstitutions.java index 4337cbbb391b1..4bd57480ce5a2 100644 --- a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/graal/GrpcNettySubstitutions.java +++ b/extensions/grpc-common/runtime/src/main/java/io/quarkus/grpc/common/runtime/graal/GrpcNettySubstitutions.java @@ -1,4 +1,4 @@ -package io.quarkus.grpc.runtime.graal; +package io.quarkus.grpc.common.runtime.graal; import java.security.Provider; import java.util.logging.Level; diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/graal/GrpcSubstitutions.java b/extensions/grpc-common/runtime/src/main/java/io/quarkus/grpc/common/runtime/graal/GrpcSubstitutions.java similarity index 97% rename from extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/graal/GrpcSubstitutions.java rename to extensions/grpc-common/runtime/src/main/java/io/quarkus/grpc/common/runtime/graal/GrpcSubstitutions.java index 5d8faa629d379..cc41a3a9ac477 100644 --- a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/graal/GrpcSubstitutions.java +++ b/extensions/grpc-common/runtime/src/main/java/io/quarkus/grpc/common/runtime/graal/GrpcSubstitutions.java @@ -1,4 +1,4 @@ -package io.quarkus.grpc.runtime.graal; +package io.quarkus.grpc.common.runtime.graal; import static io.grpc.InternalServiceProviders.getCandidatesViaHardCoded; diff --git a/extensions/grpc-common/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/grpc-common/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000000000..fd36e68616d82 --- /dev/null +++ b/extensions/grpc-common/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,11 @@ +--- +name: "gRPC Common" +metadata: + keywords: + - "gRPC" + categories: + - "web" + - "serialization" + - "reactive" + status: "experimental" + unlisted: "true" diff --git a/extensions/grpc/deployment/pom.xml b/extensions/grpc/deployment/pom.xml index ae9625c872094..6b0dd348e6f1c 100644 --- a/extensions/grpc/deployment/pom.xml +++ b/extensions/grpc/deployment/pom.xml @@ -22,10 +22,6 @@ io.quarkus quarkus-arc-deployment - - io.quarkus - quarkus-vertx-deployment - io.quarkus quarkus-devtools-utilities @@ -38,6 +34,10 @@ io.quarkus quarkus-grpc + + io.quarkus + quarkus-grpc-common-deployment + io.quarkus quarkus-smallrye-health-spi diff --git a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcDotNames.java b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcDotNames.java index f3b72e7e7fa8a..83dab824bedc6 100644 --- a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcDotNames.java +++ b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcDotNames.java @@ -2,12 +2,8 @@ import org.jboss.jandex.DotName; -import com.google.protobuf.GeneratedMessageV3; - import io.grpc.BindableService; import io.grpc.Channel; -import io.grpc.LoadBalancerProvider; -import io.grpc.NameResolverProvider; import io.quarkus.gizmo.MethodDescriptor; import io.quarkus.grpc.runtime.annotations.GrpcService; import io.quarkus.grpc.runtime.supports.Channels; @@ -17,10 +13,6 @@ public class GrpcDotNames { static final DotName BINDABLE_SERVICE = DotName.createSimple(BindableService.class.getName()); static final DotName CHANNEL = DotName.createSimple(Channel.class.getName()); static final DotName GRPC_SERVICE = DotName.createSimple(GrpcService.class.getName()); - static final DotName MESSAGE_BUILDER = DotName.createSimple(GeneratedMessageV3.Builder.class.getName()); - static final DotName GENERATED_MESSAGE_V3 = DotName.createSimple(GeneratedMessageV3.class.getName()); - static final DotName NAME_RESOLVER_PROVIDER = DotName.createSimple(NameResolverProvider.class.getName()); - static final DotName LOAD_BALANCER_PROVIDER = DotName.createSimple(LoadBalancerProvider.class.getName()); static final MethodDescriptor CREATE_CHANNEL_METHOD = MethodDescriptor.ofMethod(Channels.class, "createChannel", Channel.class, String.class); diff --git a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcServerProcessor.java b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcServerProcessor.java index d3b0d5a3bfc8d..0622b15779daa 100644 --- a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcServerProcessor.java +++ b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcServerProcessor.java @@ -10,10 +10,7 @@ import org.jboss.jandex.ClassInfo; import org.jboss.logging.Logger; -import io.grpc.internal.DnsNameResolverProvider; -import io.grpc.internal.PickFirstLoadBalancerProvider; import io.grpc.internal.ServerImpl; -import io.grpc.netty.NettyChannelProvider; import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.arc.processor.DotNames; import io.quarkus.deployment.IsDevelopment; @@ -28,8 +25,6 @@ import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; -import io.quarkus.deployment.builditem.nativeimage.NativeImageConfigBuildItem; -import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.grpc.deployment.devmode.FieldDefinalizingVisitor; import io.quarkus.grpc.runtime.GrpcContainer; import io.quarkus.grpc.runtime.GrpcServerRecorder; @@ -98,42 +93,6 @@ void definializeGrpcFieldsForDevMode(BuildProducer new FieldDefinalizingVisitor("interceptors"))); } - @BuildStep - public void configureNativeExecutable(CombinedIndexBuildItem combinedIndex, - BuildProducer reflectiveClass, - BuildProducer extensionSslNativeSupport) { - - // we force the usage of the reflection invoker. - Collection messages = combinedIndex.getIndex() - .getAllKnownSubclasses(GrpcDotNames.GENERATED_MESSAGE_V3); - for (ClassInfo message : messages) { - reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, true, message.name().toString())); - } - Collection builders = combinedIndex.getIndex().getAllKnownSubclasses(GrpcDotNames.MESSAGE_BUILDER); - for (ClassInfo builder : builders) { - reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, true, builder.name().toString())); - } - - Collection lbs = combinedIndex.getIndex().getAllKnownSubclasses(GrpcDotNames.LOAD_BALANCER_PROVIDER); - for (ClassInfo lb : lbs) { - reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, lb.name().toString())); - } - - Collection nrs = combinedIndex.getIndex().getAllKnownSubclasses(GrpcDotNames.NAME_RESOLVER_PROVIDER); - for (ClassInfo nr : nrs) { - reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, nr.name().toString())); - } - - // Built-In providers: - reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, DnsNameResolverProvider.class)); - reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, PickFirstLoadBalancerProvider.class)); - reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, - "io.grpc.util.SecretRoundRobinLoadBalancerProvider$Provider")); - reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, NettyChannelProvider.class)); - - extensionSslNativeSupport.produce(new ExtensionSslNativeSupportBuildItem(GRPC_SERVER)); - } - @BuildStep HealthBuildItem addHealthChecks(GrpcServerBuildTimeConfig config, List bindables, @@ -157,17 +116,7 @@ HealthBuildItem addHealthChecks(GrpcServerBuildTimeConfig config, } @BuildStep - NativeImageConfigBuildItem nativeImageConfiguration() { - NativeImageConfigBuildItem.Builder builder = NativeImageConfigBuildItem.builder() - .addRuntimeInitializedClass("io.grpc.netty.Utils$ByteBufAllocatorPreferDirectHolder") - .addRuntimeInitializedClass("io.grpc.netty.Utils$ByteBufAllocatorPreferHeapHolder") - // substitutions are runtime-only, Utils have to be substituted until we cannot use EPoll - // in native. NettyServerBuilder and NettyChannelBuilder would "bring in" Utils in build time - // if they were not marked as runtime initialized: - .addRuntimeInitializedClass("io.grpc.netty.Utils") - .addRuntimeInitializedClass("io.grpc.netty.NettyServerBuilder") - .addRuntimeInitializedClass("io.grpc.netty.NettyChannelBuilder"); - return builder.build(); + ExtensionSslNativeSupportBuildItem extensionSslNativeSupport() { + return new ExtensionSslNativeSupportBuildItem(GRPC_SERVER); } - } diff --git a/extensions/grpc/runtime/pom.xml b/extensions/grpc/runtime/pom.xml index 96924164b9dc6..053e26cf6f3f7 100644 --- a/extensions/grpc/runtime/pom.xml +++ b/extensions/grpc/runtime/pom.xml @@ -18,34 +18,8 @@ jakarta.annotation-api - com.google.code.findbugs - jsr305 - - - io.vertx - vertx-grpc - - - org.codehaus.mojo - animal-sniffer-annotations - - - com.google.code.findbugs - jsr305 - - - org.checkerframework - checker-qual - - - javax.annotation - javax.annotation-api - - - com.google.android - annotations - - + io.quarkus + quarkus-grpc-common io.quarkus @@ -77,20 +51,16 @@ org.codehaus.mojo animal-sniffer-annotations + + org.checkerframework + checker-qual + io.quarkus quarkus-mutiny - - io.quarkus - quarkus-vertx - - - org.graalvm.nativeimage - svm - io.quarkus diff --git a/extensions/pom.xml b/extensions/pom.xml index 40d6aa0db2393..cdcd94c84ef92 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -189,6 +189,7 @@ picocli google-cloud-functions-http google-cloud-functions + grpc-common