I'm trying to run Spark code using Livy's Java API. I'm using the code example from the official documentation.
public class PiJobRunner {
public static void main(String[] args) throws IOException {
String livyUrl = "http://localhost:8998";
String piJar = "target/livy-example-1.0-SNAPSHOT.jar";
int samples = 1000;
LivyClient client = new LivyClientBuilder()
.setURI(URI.create(livyUrl))
.build();
try {
System.err.printf("Uploading %s to the Spark context...\n", piJar);
client.uploadJar(new File(piJar)).get();
System.err.printf("Running PiJob with %d samples...\n", samples);
double pi = client.submit(new PiJob(samples)).get();
System.out.println("Pi is roughly: " + pi);
} catch (Exception e) {
e.printStackTrace();
} finally {
client.stop(true);
}
}
}
But I'm getting the following error when executing the client.uploadJar(new File(piJar)).get(); command:
Uploading target/livy-example-1.0-SNAPSHOT.jar to the Spark context...
java.util.concurrent.ExecutionException: java.io.IOException: Bad Request: {"msg":"requirement failed: Local path /root/.livy-sessions/45d1be96-1e32-4946-8d8f-6167eaa1768d/target/livy-example-1.0-SNAPSHOT.jar cannot be added to user sessions."}
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at com.omma.data.PiJobRunner.main(PiJobRunner.java:22)
Caused by: java.io.IOException: Bad Request: {"msg":"requirement failed: Local path /root/.livy-sessions/45d1be96-1e32-4946-8d8f-6167eaa1768d/target/livy-example-1.0-SNAPSHOT.jar cannot be added to user sessions."}
at org.apache.livy.client.http.LivyConnection.sendRequest(LivyConnection.java:229)
at org.apache.livy.client.http.LivyConnection.post(LivyConnection.java:192)
at org.apache.livy.client.http.HttpClient$2.call(HttpClient.java:152)
at org.apache.livy.client.http.HttpClient$2.call(HttpClient.java:149)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
Process finished with exit code 0
I don't think there are networking issues preventing communication between the Livy server and the Spark cluster, as I'm able to run commands from the command-line and see the results in the Livy's UI. For example:
Invoke-RestMethod -Method Post -Body '{"code": "1 + 1"}' -ContentType "application/json" -Uri http://localhost:8998/sessions/0/statements
I've tried to modify the livy.conf file from:
livy.file.local-dir-whitelist = /
to:
livy.file.local-dir-whitelist =/root/.livy-sessions/
as suggested in other discussions, but the issue persists. Any help is appreciated, thanks in advance!