| 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 | } |