apupier commented on code in PR #8372: URL: https://github.com/apache/camel-quarkus/pull/8372#discussion_r2883908789
########## extensions/milvus/deployment/src/main/java/org/apache/camel/quarkus/component/milvus/deployment/MilvusProcessor.java: ########## @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.milvus.deployment; + +import java.util.List; +import java.util.Set; + +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.BytecodeTransformerBuildItem; +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; +import io.quarkus.deployment.builditem.IndexDependencyBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.commons.ClassRemapper; +import org.objectweb.asm.commons.Remapper; + +class MilvusProcessor { + + /** + * Intercepts all Milvus SDK classes during the Quarkus build process to perform + * bytecode transformation. This ensures the SDK points to the correct + * gRPC/Netty implementations, avoiding 'Class Not Found' + */ + + @BuildStep + void relocateAllShadedCalls( + CombinedIndexBuildItem index, + BuildProducer<BytecodeTransformerBuildItem> transformers) { + + index.getIndex().getKnownClasses().stream() + .filter(ci -> { + String name = ci.name().toString(); + return name.startsWith("io.milvus"); + }) + .forEach(ci -> { + transformers.produce(new BytecodeTransformerBuildItem( + ci.name().toString(), + (name, cv) -> new ShadedRelocationVisitor(cv))); + }); + } + + @BuildStep + List<IndexDependencyBuildItem> indexDependencies() { + return List.of( + new IndexDependencyBuildItem("io.milvus", "milvus-sdk-java"), + new IndexDependencyBuildItem("com.google.protobuf", "protobuf-java")); + } + + /** + * Registers gRPC Service Providers (SPI) for the Native executable. + * In Native mode, GraalVM does not automatically discover services in + * META-INF/services. + */ + + @BuildStep + void registerGrpcServiceProvider(BuildProducer<ServiceProviderBuildItem> services) { + + services.produce(new ServiceProviderBuildItem( + "io.grpc.ManagedChannelProvider", + "io.grpc.netty.NettyChannelProvider")); + services.produce(new ServiceProviderBuildItem( + "io.grpc.NameResolverProvider", + "io.grpc.internal.DnsNameResolverProvider")); + + services.produce(new ServiceProviderBuildItem("io.grpc.LoadBalancerProvider", + "io.grpc.internal.PickFirstLoadBalancerProvider", + "io.grpc.util.OutlierDetectionLoadBalancerProvider", + "io.grpc.util.RandomSubsettingLoadBalancerProvider", + "io.grpc.util.SecretRoundRobinLoadBalancerProvider")); + } + + @BuildStep + void registerReflection(CombinedIndexBuildItem index, BuildProducer<ReflectiveClassBuildItem> reflection) { + + // Infrastructure & Clients: gRPC, Netty, and Milvus + reflection.produce(ReflectiveClassBuildItem.builder( + "io.grpc.internal.DnsNameResolverProvider", + "io.grpc.internal.PickFirstLoadBalancerProvider", + "io.grpc.netty.NettyChannelProvider", + "io.grpc.util.SecretRoundRobinLoadBalancerProvider$Provider", + "io.grpc.netty.GrpcSslContexts", + "io.grpc.netty.UdsNettyChannelProvider", + "io.grpc.netty.UdsNameResolverProvider", Review Comment: Have you tried oto use io.quarkus:grpc* to avoid having to configure the processor for grpc classes? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
