Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sample for updating a cluster in Dataproc. #362

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions dataproc/create_cluster_and_submit_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,35 @@ def get_cluster_id_by_name(cluster_list, cluster_name):
cluster = [c for c in cluster_list if c['clusterName'] == cluster_name][0]
return cluster['clusterUuid'], cluster['config']['configBucket']

# [START update_cluster]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for a region tag unless you're including it from a doc

def update_cluster(dataproc, project, cluster_name, zone, num_workers):
"""Updates the specified cluster to the given number of workers.
Use 'config.worker_config.num_instances' and 'workerConfig' for workers.
Use 'config.secondary_worker_config.num_instances' and
'secondaryWorkerConfig' for preemptible workers."""
print('Updating cluster to %d workers.' % num_workers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use {} and format() rather then % for string interpolation in this repo

zone_uri = \
'https://www.googleapis.com/compute/v1/projects/{}/zones/{}'.format(
project, zone)
cluster_data = {
'projectId': project,
'clusterName': cluster_name,
'config': {
'gceClusterConfig': {
'zoneUri': zone_uri
},
'workerConfig': {
'numInstances': num_workers
}
}
}
result = dataproc.projects().regions().clusters().patch(
projectId = project,
region = REGION,
clusterName = cluster_name,
updateMask = 'config.worker_config.num_instances',
body = cluster_data).execute()
# [END update_cluster]

# [START submit_pyspark_job]
def submit_pyspark_job(dataproc, project, cluster_name, bucket_name, filename):
Expand Down