Apache Spark™ is a fast and general engine for large-scale data processing. It’s really popular as it’s very fast, easy to use and has a great documentation.
It even comes with handy script to submit an application spark-submit
./bin/spark-submit \ --class org.apache.spark.examples.SparkPi \ --master spark://my-cluster:7077 \ --deploy-mode cluster \ /path/to/examples.jar 1000
spark-submit is great if you need to submit applications from command line but what if you need to submit applications from other applications. Let’s say you have a quartz-scheduler based application and you want to periodically submit applications to perform some batch processing.
One option would be to install spark binaries next to your quartz-scheduler and fork processes from your app to submit application. But first of all it’s hacky and second it’s not clear how to check the status of submitted application or how to cancel it.
The second would be to use an open source project called spark-jobserver which tries to solve the problem by providing REST API to submit applications. But this means you have to add additional statefull service to your tech stack, maintain it and take care of availability.
It turns out there is a third surprisingly easy option which is not documented. Spark has a hidden REST API which handles application submission, status checking and cancellation.
Below is the Spark’s hidden REST API.
Submit an Application
Submission Response
Get the status of a submitted application
Status Response
Kill submitted application
Kill Response
As you can see there is a very easy way to solve the problem at hand.
There's also another hidden UI Json API: http://[master-node]:[master-ui-port]/json/ which exposes all information available on the master UI in JSON format.