(projectId, region, clusterName, jobFilePath)
| 25 | 'use strict'; |
| 26 | |
| 27 | function main(projectId, region, clusterName, jobFilePath) { |
| 28 | const dataproc = require('@google-cloud/dataproc'); |
| 29 | const {Storage} = require('@google-cloud/storage'); |
| 30 | |
| 31 | // Create a cluster client with the endpoint set to the desired cluster region |
| 32 | const clusterClient = new dataproc.v1.ClusterControllerClient({ |
| 33 | apiEndpoint: `${region}-dataproc.googleapis.com`, |
| 34 | projectId: projectId, |
| 35 | }); |
| 36 | |
| 37 | // Create a job 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 quickstart() { |
| 44 | // Create the cluster config |
| 45 | const cluster = { |
| 46 | projectId: projectId, |
| 47 | region: region, |
| 48 | cluster: { |
| 49 | clusterName: clusterName, |
| 50 | config: { |
| 51 | masterConfig: { |
| 52 | numInstances: 1, |
| 53 | machineTypeUri: 'n1-standard-2', |
| 54 | }, |
| 55 | workerConfig: { |
| 56 | numInstances: 2, |
| 57 | machineTypeUri: 'n1-standard-2', |
| 58 | }, |
| 59 | }, |
| 60 | }, |
| 61 | }; |
| 62 | |
| 63 | // Create the cluster |
| 64 | const [operation] = await clusterClient.createCluster(cluster); |
| 65 | const [response] = await operation.promise(); |
| 66 | |
| 67 | // Output a success message |
| 68 | console.log(`Cluster created successfully: ${response.clusterName}`); |
| 69 | |
| 70 | const job = { |
| 71 | projectId: projectId, |
| 72 | region: region, |
| 73 | job: { |
| 74 | placement: { |
| 75 | clusterName: clusterName, |
| 76 | }, |
| 77 | pysparkJob: { |
| 78 | mainPythonFileUri: jobFilePath, |
| 79 | }, |
| 80 | }, |
| 81 | }; |
| 82 | |
| 83 | const [jobOperation] = await jobClient.submitJobAsOperation(job); |
| 84 | const [jobResponse] = await jobOperation.promise(); |
no test coverage detected