【问题标题】:Java application with Apache Livy使用 Apache Livy 的 Java 应用程序
【发布时间】:2018-09-15 07:46:24
【问题描述】:

我决定使用 Apache Livy 为 Apache Spark 构建一个 Web 服务(应用程序)。
根据 Livy 配置默认值,Livy 服务器已启动并在 localhost 端口 8998 上运行。
我的测试程序是 Apache Livy 文档中的示例应用程序:https://livy.incubator.apache.org/docs/latest/programmatic-api.html

通过 LivyClientBuilder 类创建 LivyClient 时,

 client = new LivyClientBuilder().setURI(new 
 URI("http","user:info","localhost",8998,"","",""))
    .build();

我得到“任何注册的客户端工厂都不支持 URI”异常:

Exception in thread "main" java.lang.IllegalArgumentException: URI 'http://%5Bredacted%5D@localhost:8998?#' is not supported by any registered client factories.
at org.apache.livy.LivyClientBuilder.build(LivyClientBuilder.java:155)
at Client.<init>(Client.java:17)
at Client.main(Client.java:25)

我发现客户端实例在 LivyClientBuilder 类中保持为空。

client = factory.createClient(uri, this.config);

factory 是 LivyClientFactory 接口的一个实例。
实现该接口的唯一类是 RSCClientFactory
RSCClientFactory 我们有这段代码:

if (!"rsc".equals(uri.getScheme())) {
     return null;
 }

我试过“rsc”而不是“http”,这是错误:

    2018-09-15 11:32:55 ERROR RSCClient:340 - RPC error.
  java.util.concurrent.ExecutionException: javax.security.sasl.SaslException: Client closed before SASL negotiation finished.
  javax.security.sasl.SaslException: Client closed before SASL negotiation finished.
    at io.netty.util.concurrent.AbstractFuture.get(AbstractFuture.java:41)
    at org.apache.livy.rsc.rpc.Rpc$SaslClientHandler.dispose(Rpc.java:419)
    at org.apache.livy.rsc.JobHandleImpl.get(JobHandleImpl.java:60)
    at org.apache.livy.rsc.rpc.SaslHandler.channelInactive(SaslHandler.java:92)
    at Client.main(Client.java:39)

Apache Livy 在http://localhost:8998 上运行,那么我认为我们需要将我们的 jar 文件提交到这个地址,但我不明白那里的“rsc”。

如果有人指导我解决这些问题,我将不胜感激。

【问题讨论】:

    标签: livy


    【解决方案1】:

    您只需将 URL 作为字符串传递:

    LivyClient client = new LivyClientBuilder()
                    .setURI(new URI("http://localhost:8998"))
                    .build();
    

    之后,您可以添加 *.jar 文件:

    client.addJar("file://...yourPathToJarHere.../*.jar");
    

    client.uploadJar(new File("...."));
    

    这取决于您的集群配置。你可以在这里找到完整的 java API 描述:https://livy.incubator.apache.org/docs/latest/api/java/index.html

    【讨论】:

    • 感谢您的帮助,我做了这些事情,但重置所有项目都有帮助,可能问题出在机器配置上。但总的来说,我认为 Livy 的文档很少。
    • 如何使用 Livy 客户端以编程方式设置 spark master?
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    相关资源
    最近更新 更多