I have started doing evaluation of Livy for potential case scenarios where this technology could help and I'd like to share some findings with others who would like to approach this interesting Open Source project. It has been started by Cloudera and Microsoft and it is currently in the process of being incubated by the Apache Software Foundation. The official documentation isn't comprehensive at the moment, so I hope my posts on this topic could help someone else.
Apache Livy is a service to interact with Apache Spark through a REST interface. It enables both submissions of Spark jobs or snippets of Spark code. The following features are supported:
In the second part of this series I am going to cover the details on starting a Livy server and submitting PySpark code.
Apache Livy is a service to interact with Apache Spark through a REST interface. It enables both submissions of Spark jobs or snippets of Spark code. The following features are supported:
- The jobs can be submitted as pre-compiled jars, snippets of code or via Java/Scala client API.
- Interactive Scala, Python, and R shells.
- Support for Spark 2.x and Spark1.x, Scala 2.10 and 2.11.
- It doesn't require any change to Spark code.
- It allows long running Spark Contexts that can be used for multiple Spark jobs, by multiple clients.
- Multiple Spark Contexts can be managed simultaneously: they run on the cluster instead of the Livy Server, in order to have good fault tolerance and concurrency.
- Possibility to share cached RDDs or Dataframes across multiple jobs and clients.
- Secure authenticated communication.
In the second part of this series I am going to cover the details on starting a Livy server and submitting PySpark code.
Hi,
ReplyDeleteI have write this class:
import org.apache.livy.Job;
import org.apache.livy.JobContext;
import org.apache.spark.api.java.JavaRDD;
import java.util.ArrayList;
import java.util.Arrays;
public class YourJob implements Job {
public Long call(JobContext jc) throws Exception {
ArrayList list= new ArrayList<>();
list.add(1l);
list.add(2l);
list.add(3l);
list.add(4l);
list.add(5l);
JavaRDD rdd=jc.sc().parallelize(list);
return rdd.count();
}
}
---------------
and then I write the client to contact with GCP spark server
import org.apache.livy.JobHandle;
import org.apache.livy.LivyClient;
import org.apache.livy.LivyClientBuilder;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class YourJobClient {
public static void main(String[]args) throws URISyntaxException, IOException, InterruptedException, ExecutionException, TimeoutException {
LivyClient client = new LivyClientBuilder()
.setURI(new URI("http://localhost:8998"))
// .setURI(new URI("http://35.204.128.185:8998"))
.build();
JobHandle handle =client.submit(new YourJob() );
Long result=handle.get(10000, TimeUnit.SECONDS);
client.stop(true);
}
}
and I have test the client in local and remote server.
In both cases it give me error that livy cannot find YourJob class!