Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Spark-Job mit einer Vorlage senden
Auf dieser Seite wird beschrieben, wie Sie mit einer Google APIs Explorer-Vorlage einen einfachen Spark-Job auf einem vorhandenen Dataproc-Cluster ausführen.
Weitere Möglichkeiten zum Senden eines Jobs an einen Dataproc-Cluster finden Sie unter:
Bevor Sie einen Dataproc-Job ausführen können, müssen Sie einen Cluster mit einer oder mehreren virtuellen Maschinen (VMs) erstellen, auf denen der Job ausgeführt werden soll. Sie können den APIs Explorer, die Google Cloud Console, das gcloud-Befehlszeilentool gcloud oder die Kurzanleitungen: Cloud-Clientbibliotheken verwenden nutzen, um einen Cluster zu erstellen.
Job senden
Zum Senden eines Apache Spark-Beispieljobs, der einen ungefähren Pi-Wert berechnet, füllen Sie die Google APIs Explorer-Vorlage API testen aus und führen Sie sie aus.
Geben Sie die Region an, in der sich der Cluster befindet, oder bestätigen Sie "us-central1". Die Region Ihres Clusters wird in derGoogle Cloud -Console auf der Dataproc-Seite Cluster aufgeführt.
Anfragetext:
job.Placement.clusterName: Der Name des Clusters, in dem der Job ausgeführt wird (Bestätigen oder Ersetzen von "example-cluster").
job.sparkJob.jarFileUris:
"file:///usr/lib/spark/examples/jars/spark-examples.jar". Dies ist der lokale Dateipfad auf dem Masterknoten des Dataproc-Clusters, in dem die JAR-Datei installiert ist, die den Spark Scala-Jobcode enthält.
job.sparkJob.mainClass:
"org.apache.spark.examples.SparkPi". Das ist die primäre Methode der PI-Berechnungs-Scala-Anwendung des Jobs.
Klicken Sie auf AUSFÜHREN. Wenn Sie die API-Vorlage zum ersten Mal ausführen, werden Sie möglicherweise aufgefordert, ein Google-Konto auszuwählen und sich anzumelden, und autorisieren Sie dann Google APIs Explorer, auf Ihr Konto zuzugreifen. Wenn die Anfrage erfolgreich ist, zeigt die JSON-Antwort, dass die Anfrage zur Jobübermittlung aussteht.
Öffnen Sie zum Anzeigen der Jobausgabe die Seite Dataproc-Jobs in der Google Cloud Console und klicken Sie auf die neueste Job-ID.
Klicken Sie auf "LINE WRAP", um Zeilen zu erstellen, die den rechten Rand überschreiten.
...
Pi is roughly 3.141804711418047
...
Bereinigen
Mit den folgenden Schritten vermeiden Sie, dass Ihrem Google Cloud -Konto die in dieser Anleitung verwendeten Ressourcen in Rechnung gestellt werden:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-22 (UTC)."],[[["\u003cp\u003eThis guide demonstrates how to submit a Spark job to an existing Dataproc cluster using a Google APIs Explorer template.\u003c/p\u003e\n"],["\u003cp\u003eBefore submitting a job, a Dataproc cluster must be created using methods like the APIs Explorer, Google Cloud console, gcloud CLI, or Cloud Client Libraries.\u003c/p\u003e\n"],["\u003cp\u003eThe Spark job example provided calculates a rough value for pi, and requires parameters such as projectId, region, clusterName, and specific job details like task count, jar file path, and main class.\u003c/p\u003e\n"],["\u003cp\u003eAfter submitting the job through the API, you can view the job output in the Dataproc Jobs page in the Google Cloud console.\u003c/p\u003e\n"],["\u003cp\u003eTo avoid incurring charges, delete the Dataproc cluster using one of the provided methods if it is no longer needed.\u003c/p\u003e\n"]]],[],null,["# Quickstart: Submit a Spark job by using a template\n\nSubmit a Spark job by using a template\n======================================\n\nThis page shows you how to use an [Google APIs Explorer](https://developers.google.com/apis-explorer/#p/) template to\nrun a simple Spark job on an existing Dataproc cluster.\n\nFor other ways to submit a job to a Dataproc cluster, see:\n\n- [Create a Dataproc cluster by using the Google Cloud console](/dataproc/docs/quickstarts/create-cluster-console#submit_a_job)\n- [Create a Dataproc cluster by using the Google Cloud CLI](/dataproc/docs/quickstarts/create-cluster-gcloud#submit_a_job)\n- [Create a Dataproc cluster by using client libraries](/dataproc/docs/quickstarts/create-cluster-client-libraries)\n\nBefore you begin\n----------------\n\nBefore you can run a Dataproc job, you must create a cluster of one or more virtual machines (VMs) to run it on. You can use the [APIs Explorer](/dataproc/docs/quickstarts/create-cluster-template), the [Google Cloud console](/dataproc/docs/quickstarts/update-cluster-console#create_a_cluster), the gcloud CLI [gcloud](/dataproc/docs/quickstarts/update-cluster-gcloud#create_a_cluster) command-line tool, or the [Quickstarts using Cloud Client Libraries](/dataproc/docs/quickstarts/create-cluster-client-libraries) to create a cluster.\n\n\u003cbr /\u003e\n\nSubmit a job\n------------\n\nTo submit a sample [Apache Spark](http://spark.apache.org/)\njob that calculates a rough value for\n[pi](https://en.wikipedia.org/wiki/Pi), fill in and\nexecute the Google APIs Explorer **Try this API** template.\n| **Note:** The `region`, `clusterName` and `job` parameter values are filled in for you. Confirm or replace the `region` and `clusterName` parameter values to match your cluster's region and name. The `job` parameter values are required to run the a Spark job that is pre-installed on the Dataproc cluster's master node.\n\n1. **Request parameters:**\n\n 1. Insert your [**projectId**](https://console.cloud.google.com/).\n 2. Specify the [**region**](/compute/docs/regions-zones/regions-zones#available) where your cluster is located (confirm or replace \"us-central1\"). Your cluster's region is listed on the Dataproc [**Clusters**](https://console.cloud.google.com/dataproc/clusters) page in the Google Cloud console.\n2. **Request body:**\n\n 1. [**job.placement.clusterName**](/dataproc/docs/reference/rest/v1/SparkJob#JobPlacement.FIELDS.cluster_name): The name of the cluster where the job will run (confirm or replace \"example-cluster\").\n 2. [**job.sparkJob.args**](/dataproc/docs/reference/rest/v1/SparkJob#FIELDS.args): \"1000\", the number of job tasks.\n 3. [**job.sparkJob.jarFileUris**](/dataproc/docs/reference/rest/v1/SparkJob#FIELDS.jar_file_uris): \"file:///usr/lib/spark/examples/jars/spark-examples.jar\". This is the local file path on the Dataproc cluster's master node where the jar that contains the Spark Scala job code is installed.\n 4. [**job.sparkJob.mainClass**](/dataproc/docs/reference/rest/v1/SparkJob#FIELDS.main_class): \"org.apache.spark.examples.SparkPi\". The is the main method of the job's pi calculation Scala application.\n3. Click **EXECUTE**. The first time you\n run the API template, you may be asked to choose and sign into\n your Google account, then authorize the Google APIs Explorer to access your\n account. If the request is successful, the JSON response\n shows that job submission request is pending.\n\n4. To view job output, open the\n [Dataproc Jobs](https://console.cloud.google.com/dataproc/jobs) page\n in the Google Cloud console, then click the top (most recent) Job ID.\n Click \"LINE WRAP\" to ON to bring lines that exceed the right margin into view.\n\n ```\n ...\n Pi is roughly 3.141804711418047\n ...\n ```\n\nClean up\n--------\n\n\nTo avoid incurring charges to your Google Cloud account for\nthe resources used on this page, follow these steps.\n\n1. If you don't need the cluster to explore the other quickstarts or to run other jobs, use the [APIs Explorer](/dataproc/docs/quickstarts/quickstart-explorer-delete), the [Google Cloud console](/dataproc/docs/quickstarts/update-cluster-console#delete_a_cluster), the gcloud CLI [gcloud](/dataproc/docs/quickstarts/update-cluster-gcloud#delete_a_cluster) command-line tool, or the [Cloud Client Libraries](/dataproc/docs/quickstarts/create-cluster-client-libraries) to delete the cluster.\n\nWhat's next\n-----------\n\n- Learn how to [update a Dataproc cluster by using a template](/dataproc/docs/quickstarts/update-cluster-template)."]]