MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

dataproc/submitJob.js:23–80  ·  view source on GitHub ↗
(
  projectId = 'YOUR_PROJECT_ID',
  region = 'YOUR_CLUSTER_REGION',
  clusterName = 'YOUR_CLUSTER_NAME'
)

Source from the content-addressed store, hash-verified

21/*eslint no-warning-comments: [0, { "terms": ["todo", "fixme"], "location": "anywhere" }]*/
22
23function main(
24 projectId = 'YOUR_PROJECT_ID',
25 region = 'YOUR_CLUSTER_REGION',
26 clusterName = 'YOUR_CLUSTER_NAME'
27) {
28 // [START dataproc_submit_job]
29 const dataproc = require('@google-cloud/dataproc');
30 const {Storage} = require('@google-cloud/storage');
31
32 // TODO(developer): Uncomment and set the following variables
33 // projectId = 'YOUR_PROJECT_ID'
34 // region = 'YOUR_CLUSTER_REGION'
35 // clusterName = 'YOUR_CLUSTER_NAME'
36
37 // Create a client with the endpoint set to the desired cluster region
38 const jobClient = new dataproc.v1.JobControllerClient({
39 apiEndpoint: `${region}-dataproc.googleapis.com`,
40 projectId: projectId,
41 });
42
43 async function submitJob() {
44 const job = {
45 projectId: projectId,
46 region: region,
47 job: {
48 placement: {
49 clusterName: clusterName,
50 },
51 sparkJob: {
52 mainClass: 'org.apache.spark.examples.SparkPi',
53 jarFileUris: [
54 'file:///usr/lib/spark/examples/jars/spark-examples.jar',
55 ],
56 args: ['1000'],
57 },
58 },
59 };
60
61 const [jobOperation] = await jobClient.submitJobAsOperation(job);
62 const [jobResponse] = await jobOperation.promise();
63
64 const matches =
65 jobResponse.driverOutputResourceUri.match('gs://(.*?)/(.*)');
66
67 const storage = new Storage();
68
69 const output = await storage
70 .bucket(matches[1])
71 .file(`${matches[2]}.000000000`)
72 .download();
73
74 // Output a success message.
75 console.log(`Job finished successfully: ${output}`);
76 // [END dataproc_submit_job]
77 }
78
79 submitJob();
80}

Callers 1

submitJob.jsFile · 0.70

Calls 1

submitJobFunction · 0.85

Tested by

no test coverage detected