diff --git a/bom/application/pom.xml b/bom/application/pom.xml index e4baad4035d037..e660e6648ab95f 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 00000000000000..2c4ba0037b1974 --- /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 00000000000000..ebff9fee027540 --- /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 00000000000000..12e5ca80aafec1 --- /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 00000000000000..d848a51985b4fc --- /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 - parent + 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 00000000000000..a524fd3c8e102a --- /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 4337cbbb391b1c..4bd57480ce5a2c 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 5d8faa629d379d..cc41a3a9ac477c 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 00000000000000..fd36e68616d825 --- /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 ae9625c872094d..6b0dd348e6f1c4 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 f3b72e7e7fa8a2..83dab824bedc63 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 d3b0d5a3bfc8d4..0622b15779daa7 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 96924164b9dc6f..053e26cf6f3f7f 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 40d6aa0db23938..cdcd94c84ef92e 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -189,6 +189,7 @@ picocli google-cloud-functions-http google-cloud-functions + grpc-common