带有Apache Livy的Java应用程序

时间:2018-09-15 07:46:24

标签: livy

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

通过 LivyClientBuilder 类创建时,

 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”。

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

2 个答案:

答案 0 :(得分:0)

您只需要将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://gnh1201.wordpress.com/2018/10/09/l4-data-migration-tool-mysql-to-elastic/

答案 1 :(得分:0)