无法使用java rest client

时间:2018-06-01 14:51:46

标签: apache-flink flink-streaming

我们在使用java REST客户端将jar上传到Flink 1.5.0服务器时收到错误响应{"错误":["内部服务器错误:null"]}。相同的代码在Flink 1.4.2中正常工作。实际上我们可以看到jar已经从Flink GUI上传了。但错误的地位打破了逻辑。有什么建议吗?

        HttpPost uploadFile = new HttpPost(flinkJobManagerUrl + "/jars/upload");
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.addBinaryBody(
                "jarfile",
                new FileInputStream(f),
                ContentType.create("application/x-java-archive"),
                f.getName()
        );

        HttpEntity multipart = builder.build();
        uploadFile.setEntity(multipart);
        CloseableHttpResponse response = restClient.execute(uploadFile);
        rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

==========================

JM日志错误:

018-06-01 16:05:46,514 WARN org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint - 未处理的异常 org.apache.flink.shaded.netty4.io.netty.handler.codec.http.multipart.HttpPostRequestDecoder $ EndOfDataDecoderException         在org.apache.flink.shaded.netty4.io.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder.hasNext(HttpPostMultipartRequestDecoder.java:366)         在org.apache.flink.shaded.netty4.io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.hasNext(HttpPostRequestDecoder.java:241)         在org.apache.flink.runtime.rest.FileUploadHandler.channelRead0(FileUploadHandler.java:92)         在org.apache.flink.runtime.rest.FileUploadHandler.channelRead0(FileUploadHandler.java:51)         在org.apache.flink.shaded.netty4.io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)         at org.apache.flink.shaded.netty4.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339)         at org.apache.flink.shaded.netty4.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)         在org.apache.flink.shaded.netty4.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:242)         在org.apache.flink.shaded.netty4.io.netty.channel.CombinedChannelDuplexHandler.channelRead(combinedChannelDuplexHandler.java:147)         at org.apache.flink.shaded.netty4.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339)         at org.apache.flink.shaded.netty4.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)         在org.apache.flink.shaded.netty4.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:847)         at org.apache.flink.shaded.netty4.io.netty.channel.nio.AbstractNioByteChannel $ NioByteUnsafe.read(AbstractNioByteChannel.java:131)         在org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)         在org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)         在org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)         在org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)         在org.apache.flink.shaded.netty4.io.netty.util.concurrent.SingleThreadEventExecutor $ 2.run(SingleThreadEventExecutor.java:111)         在org.apache.flink.shaded.netty4.io.netty.util.concurrent.DefaultThreadFactory $ DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)         在java.lang.Thread.run(Thread.java:748)

但过了一段时间,你会看到从GUI上传的jar。但是当它运行时它会给出另一个例外:

2018-06-01 16:10:06,752错误org.apache.flink.runtime.webmonitor.handlers.JarRunHandler - REST处理程序中发生异常。 org.apache.flink.runtime.rest.handler.RestHandlerException:预计只有一个值[ - KAFKA_IN a_O@192.168.56.120:9092,192.168.56.121:9092,192.168.56.122:9092 / a_O_124 --ZK_SESSION_TIMEOUT 60000 --ZK_KEEP_CONN_ALIVE 1]。         在org.apache.flink.runtime.rest.handler.util.HandlerRequestUtils.getQueryParameter(HandlerRequestUtils.java:56)         at org.apache.flink.runtime.rest.handler.util.HandlerRequestUtils.getQueryParameter(HandlerRequestUtils.java:44)         在org.apache.flink.runtime.webmonitor.handlers.JarRunHandler.handleRequest(JarRunHandler.java:102)         在org.apache.flink.runtime.webmonitor.handlers.JarRunHandler.handleRequest(JarRunHandler.java:68)         at org.apache.flink.runtime.rest.handler.AbstractRestHandler.respondToRequest(AbstractRestHandler.java:77)         在org.apache.flink.runtime.rest.AbstractHandler.respondAsLeader(AbstractHandler.java:168)         at org.apache.flink.runtime.rest.handler.RedirectHandler.lambda $ null $ 0(RedirectHandler.java:139)         at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:760)         at java.util.concurrent.CompletableFuture $ UniWhenComplete.tryFire(CompletableFuture.java:736)         at java.util.concurrent.CompletableFuture $ Completion.run(CompletableFuture.java:442)         at org.apache.flink.shaded.netty4.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTask​​s(SingleThreadEventExecutor.java:357)         在org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)         在org.apache.flink.shaded.netty4.io.netty.util.concurrent.SingleThreadEventExecutor $ 2.run(SingleThreadEventExecutor.java:111)         在org.apache.flink.shaded.netty4.io.netty.util.concurrent.DefaultThreadFactory $ DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)         在java.lang.Thread.run(Thread.java:748)

2 个答案:

答案 0 :(得分:1)

第一个例外是由于FileUploadHandler中的错误;它没有正确处理EmptyLastHttpContent消息。请参阅https://issues.apache.org/jira/browse/FLINK-9500

第二个例外是由于程序参数中有空格而引起的,从1.5开始不再支持。

答案 1 :(得分:0)

关于第二个异常,您可以将带有逗号的programArgs放入发布请求正文中,例如

{
  "programArgs":"--test=a,b"
}