Submit a Spark job by using a template
This page shows you how to use an Google APIs Explorer template to run a simple Spark job on an existing Managed Service for Apache Spark cluster.
For other ways to submit a job to a Managed Service for Apache Spark cluster, see:
Before you begin
Before you can run a Managed Service for Apache Spark job, you must create a cluster of one or more virtual machines (VMs) to run it on. You can use the APIs Explorer, the Google Cloud console, the gcloud CLI gcloud command-line tool, or the Quickstarts using Cloud Client Libraries to create a cluster.Submit a job
To submit a sample Apache Spark job that calculates an approximate value for pi, fill in and run the Google APIs Explorer Try this method template on this page.
In the Try this method template at the bottom of this page, configure the Request parameters:
- In the projectId field, enter your Google Cloud project ID.
- In the region field, specify the region where your cluster is located (confirm or replace "us-central1"). Optional: If you need to check your cluster's region, see the Managed Service for Apache Spark Clusters page in the Google Cloud console.
In the Request body section of the Try this method template, configure the following fields:
- job.placement.clusterName: The name of the cluster where the job will run (confirm or replace "example-cluster").
- job.sparkJob.args: "1000", the number of job tasks.
- job.sparkJob.jarFileUris: "file:///usr/lib/spark/examples/jars/spark-examples.jar". This is the local path on the Managed Service for Apache Spark cluster's primary node where the JAR file that contains the Spark Scala job code is installed.
- job.sparkJob.mainClass: "org.apache.spark.examples.SparkPi". This is the main method of the job's pi calculation Scala application.
In the Try this method template, click EXECUTE. The first time you run the API template, you might need to choose and sign in to your Google Account, and then authorize Google APIs Explorer to access your account. If the request succeeds, the JSON response shows that the job submission request is pending.
To view job output, open the Managed Service for Apache Spark Jobs page in the Google Cloud console, and then click the top (most recent) Job ID. Turn LINE WRAP to ON to bring lines that exceed the right margin into view.
... Pi is roughly 3.141804711418047 ...
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
- If you don't need the cluster to explore the other quickstarts or to run other jobs, use the APIs Explorer, the Google Cloud console, the gcloud CLI gcloud command-line tool, or the Cloud Client Libraries to delete the cluster.