java 使用AWS lambda的本机Quarkus无法构建

dkqlctbz  于 2023-03-28  发布在  Java
关注(0)|答案(2)|浏览(88)

我正在尝试使用Quarkus Native来构建我的AWS Lambda。
我的设置是:

  • Graal虚拟机19.3.0
  • Java 11
  • Ubuntu

当我奔跑

docker run -v /home/mypc/dev/java/quarkus/alexa_swear/target/<my project>-1.0-SNAPSHOT-native-image-source-jar:/project:z --user 1000:1000 --rm quay.io/quarkus/ubi-quarkus-native-image:19.2.1 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -jar <my project>-1.0-SNAPSHOT-runner.jar -J-Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:+AddAllCharsets -H:EnableURLProtocols=http -H:-JNI --no-server -H:-UseServiceLoaderFeature -H:+StackTrace <my project>-1.0-SNAPSHOT-runner

出现以下错误:

[alexa_swear-1.0-SNAPSHOT-runner:23]   (typeflow):  52,070.99 ms
[alexa_swear-1.0-SNAPSHOT-runner:23]    (objects):  25,961.57 ms
[alexa_swear-1.0-SNAPSHOT-runner:23]   (features):     803.41 ms
[alexa_swear-1.0-SNAPSHOT-runner:23]     analysis:  81,015.48 ms
[alexa_swear-1.0-SNAPSHOT-runner:23]     (clinit):   1,277.52 ms
[alexa_swear-1.0-SNAPSHOT-runner:23]     universe:   4,416.32 ms
Error: Unsupported features in 5 methods
Detailed message:
Call path from entry point to java.lang.Runtime.traceInstructions(boolean): 
    at java.lang.Runtime.traceInstructions(Runtime.java)
    at com.oracle.svm.reflect.Runtime_traceInstructions_91eaacf084b9d7e2af6dcc0028ee87fea9223b51_77.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.net.www.protocol.http.NTLMAuthenticationProxy.isTrustedSite(NTLMAuthenticationProxy.java:102)
    at sun.net.www.protocol.http.HttpURLConnection.getServerAuthentication(HttpURLConnection.java:2481)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1743)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
    at io.quarkus.amazon.lambda.runtime.AmazonLambdaRecorder$2.run(AmazonLambdaRecorder.java:171)
    at java.lang.Thread.run(Thread.java:748)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
    at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0) ... 6 more
Error: Image build request failed with exit status 1

上面的错误被截断:相同的调用堆栈指向不同的不受支持的方法,例如java.lang.Thread.stop
我的基本理解是io.quarkus.amazon.lambda.runtime.AmazonLambdaRecorder$2.run(AmazonLambdaRecorder.java引用了一些不支持的方法,比如java.lang.Thread.resume()。我也尝试过Quarkus 19.2.1,但没有成功。
上面的命令由mvn clean install -Pnative -Dnative-image.docker-build=true -e执行。

bis0qfac

bis0qfac1#

2022年更新**

我使用quarkus来获得简化的GraalVM和本地构建支持,以加快启动lambda的启动时间。现在我会首先尝试SnapStart,这是lambda中的jsut配置。

0wi1tuuw

0wi1tuuw2#

我终于找到了我的问题的原因。
在我的代码的非工作版本中,我使用了一个com.amazon.ask.AlexaSkill工厂,它以某种方式注入到入口点中,如下所示:

package io.mirko.lambda;

import com.amazon.ask.AlexaSkill;
import com.amazon.ask.Skills;
import com.amazon.ask.dispatcher.request.handler.HandlerInput;
import com.amazon.ask.dispatcher.request.handler.RequestHandler;
import com.amazon.ask.model.RequestEnvelope;
import com.amazon.ask.model.ResponseEnvelope;
import com.amazon.ask.request.interceptor.GenericRequestInterceptor;
import io.mirko.lambda.handlers.*;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.*;
import java.util.stream.StreamSupport;

public class SkillFactory {
    @Inject
    Instance<RequestHandler> handlers;

    @Produces
    @ApplicationScoped
    @Named
    public AlexaSkill<RequestEnvelope, ResponseEnvelope> createSkill() {
        return Skills.standard()
                .addRequestHandlers(handlers.stream().toArray(RequestHandler[]::new))
                .addRequestInterceptor(new GenericRequestInterceptor<HandlerInput>() {
                    @Override
                    public void process(HandlerInput handlerInput) {
                        System.out.format("Processing %s\n", handlerInput.getRequest());
                    }
                })
                // Add your skill id below
                //.withSkillId("")
                .build();
    }
}

...

public class SwearStreamLambda extends SkillStreamHandler {
    @Named("swearStream")
        public SwearStreamLambda() {
            //noinspection unchecked
            super((AlexaSkill<RequestEnvelope, ResponseEnvelope>)
                getBean(new ParameterizedTypeImpl(AlexaSkill.class, RequestEnvelope.class, ResponseEnvelope.class)));

通过删除SkillFactory类并将其逻辑移动到SwearStreamLambda类中,编译进行得很顺利。
一些注意事项:
1.该问题与CDI无关,因为在整个项目中大量使用CDI
1.该问题与@Produces注解无关,该注解存在于项目的其他部分中
1.该问题与javax.enterprise.inject.Instance无关,因为删除它并不能解决问题
总而言之,我找不到问题的根本原因,但我认为我的问题 * 解决 *。
P.S.原来的问题是根除建设与以下内容:
mvn clean install -Pnative -Dnative-image.docker-build=true -Dquarkus.native.enable-jni=true
请参见https://github.com/quarkusio/quarkus/issues/6395#issuecomment-570755587
这并不能解决所有问题,因为必须配置Quarkus反射,但它解决了特定问题。

相关问题