score:0
Thx, I will try this out. In the meanwhile I found another solution: $ curl -k --user "admin:" -v -H "Content-Type: application/json" -X POST -d @Curl-KindSpark_BrandSampleModel_SessionSetup.json "https://mycluster.azurehdinsight.net/livy/sessions with a JSON file containing { "kind": "spark", "jars": ["adl://skylytics1.azuredatalakestore.net/skylytics11/azuresparklivy_2.11-0.1.jar"] } and with the uploaded jar in the Azure Data Lake Gen1 account containing the Scala object and then post the statement $ curl -k --user "admin:myPassword" -v -H "Content-Type: application/json" -X POST -d @Curl-KindSpark_BrandSampleModel_CodeSubmit.json "https://mycluster.azurehdinsight.net/livy/sessions/4/statements" -H "X-Requested-By: admin" with the content { "code": "import AzureSparkLivy_GL01._; val brandModelSamplesFirstModel = AzureSparkLivyFunction.SampleModelOfBrand(sc, \"Honda\"); brandModelSamplesFirstModel" }.
So I told Livy to start an interactive Spark session and load the specified jar and passed some code to invoke a member of the object in the jar. It works. Will check your advice too.
score:1
Make a uber jar of your Spark app with sbt-assemby plugin.
Upload jar file from the previous step to your HDFS cluster:
hdfs dfs -put /home/hduser/PiNumber.jar /user/hduser
Execute your job via livy:
curl -X POST -d '{"conf": {"kind": "spark" , "jars": "hdfs://localhost:8020/user/hduser/PiNumber.jar"}}' -H "Content-Type: application/json" -H "X-Requested-By: user" localhost:8998/sessions
check it:
curl localhost/sessions/0/statements/3
:
{"id":3,"state":"available","output":{"status":"ok","execution_count":3,"data":{"text/plain":"Pi is roughly 3.14256"}}}
p.s.
Spark Livy API for Scala/Java requires using an uber jar file. sbt-assembly
doesn't make fat jar instantly, it annoys me.
Usually, I use Python API of Livy for smoke tests and tweaking.
Sanity checks with Python:
curl localhost:sessions/0/statements -X POST -H 'Content-Type: application/json' -d '{"code":"print(\"Sanity check for Livy\")"}'
You can put more complicated logic to field code
.
BTW, it's a way in which popular notebooks for Spark works - sending the source code to cluster via Livy.
Source: stackoverflow.com
Related Query
- How to execute a jar-packaged scala program via Apache Livy on Spark that responds with a result directly to a client request?
- DSX - How to re-load a newer jar version that was already added via %AddJar in Scala
- How rewrite spark scala code to use it in apache livy
- How to debug a scala based Spark program on Intellij IDEA
- Scala problem - how to run a program that is in a package?
- How to read json data using scala from kafka topic in apache spark
- How do I ensure that my Apache Spark setup code runs only once?
- How to run Multi threaded jobs in apache spark using scala or python?
- How to Compile Apache Spark with Scala 2.11.1 using SBT?
- How do I group records that are within a specific time interval using Spark Scala or sql?
- Apache Spark - Scala - how to FlatMap (k, {v1,v2,v3,...}) to ((k,v1),(k,v2),(k,v3),...)
- How to flatten a data frame in apache spark | Scala
- How to obtain the raw datatype of a parameter of a field that is specialized in Scala via reflection?
- How to create nested json using Apache Spark with Scala
- How to submit batch jar Spark jobs by livy Programmatic API
- Failed to execute user defined function in Apache Spark using Scala
- How to store the result of an action in apache spark using scala
- How to pass DataSet(s) to a function that accepts DataFrame(s) as arguments in Apache Spark using Scala?
- how to cache data in apache spark that can be used by other spark job
- How do I explode multiple columns of arrays in a Spark Scala dataframe when the columns contain arrays that line up with one another?
- How to replace nulls with empty string ("") in Apache spark using scala
- In a scala spark job, running in yarn, how can I fail the job so that yarn shows a Failed status
- How to run a Scala program via cron?
- How to export Scala Spark project to jar
- Need help to group by then sort by value on an rdd at apache spark via scala
- How to execute shell script (.sh file) in scala program
- how to run a spark scala program in a linux terminal?
- How to get data out of Wrapped Array in Apache Spark / Scala
- How to run Kafka as a stream for Apache Spark using Scala 2.11?
- How to create a Spark Streaming jar that would work in AWS EMR?
More Query from same tag
- call a Task a second time for side effects
- Scala date formatting from Mysql
- Spark dataframe saveAsTable is using a single task
- Scala Play passing variable to view not working
- How to avoid code duplication in companion objects of subclasses
- Are Scala's `AnyVal`s stack allocated?
- Spark - maven clean install: How to compile both Java and Scala classes
- Mocking with Scala Self Type / Parfait Pattern
- Sparksql cut String after special position
- How to prove the principle of explosion (ex falso sequitur quodlibet) in Scala?
- Match "fallthrough": executing same piece of code for more than one case?
- LocaDate/LocalDateTime issue while using Generics
- How to filter a row if the value contains in list in scala spark?
- Using class parameters to assign field value
- In Scala Monix Scheduler how to propagate exceptions to main program?
- apply() returning the same object
- Compile time type check when adding element elements to list
- How to partition RDD by key in Spark?
- Does flatMap keep the order intact?
- Spark - I get a java.lang.UnsupportedOperationException when I invoke a custom function from a map
- How to store old streaming data in Databricks Spark?
- What is the equivalent expression of this spark code (scala) in pyspark?
- Read windows network file in Spark
- Referencing path-dependent type of an argument in the type of another argument to a constructor
- How to provide implicit argument to code block without explicitly creating it
- Scala: How do you add a value to an existing int, via if-else?
- How to extract tables with data from .sql dumps using Spark?
- Scala method with type parameter
- How do I append to a file in Scala?
- Programmatically add/remove executors to a Spark Session