cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to change cluster size using a script

ksenija
New Contributor III

I want to change instance type or number of max workers via a python script. Does anyone know how to do it/is it possible? I have a lot of background jobs when I want to scale down my workers, so autoscaling is not an option.

 

I was getting an error that node_type_id value must be Standard_DS3_v2 but that is my current one that I want to change

Failed to update cluster size. Status code: 400, Response: {"error_code":"INVALID_PARAMETER_VALUE","message":"Validation failed for node_type_id, the value must be Standard_DS3_v2 (is \"Standard_DS4_v2\")","details":[{"@type":"type.googleapis.com/google.rpc.BadRequest","field_violations":[{"field":"node_type_id","description":"Validation failed for node_type_id, the value must be Standard_DS3_v2 (is \"Standard_DS4_v2\")"}]},{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"CM_API_ERROR_SOURCE_CALLER_ERROR","domain":""}]}

5 REPLIES 5

RKNutalapati
Valued Contributor

We can update cluster configuration prgramatically using databricks api. 

Steps:

 1) Fetch all the clusters info present in your workspace.

 2) Loop through each cluster info

 3) Use the parsed info like cluster id etc.. to update cluster config

Example Psuedo code:

import requests
import json

host = "https://<YOUR-WORKSPACE-URL>"
workspace_access_token = "<YOUR-ACCESS-TOKEN>"
cluster_id = "<YOUR-CLUSTER-ID>"
workers_min = 1
workers_max = 2

response = requests.post(
        f"{host}/api/2.0/clusters/edit",
        headers={
            "Authorization": f"Bearer {workspace_access_token}",
"Content-Type": "application/json"
        },
        data={
"cluster_id": cluster_id,
"min_workers": workers_min,
"max_workers": workers_max
}
    )

 

Wojciech_BUK
Contributor III

Hi ksenija, this is just my guess but maybe you are using Cluster Policy in your cluster that only allows you to use specific cluster size ? E.g. below cluster policy that limits to some cluster sizes only.

Wojciech_BUK_0-1703200311434.png

 

 

Yes, you can only use the node types specified in the policy.

ksenija
New Contributor III

You're right, I didn't even check policies. This means I can't even change min and max workers, right?

ksenija_0-1703238074459.png

 

Correct, please look at my example:
- i have created policy with fixed min and max no. of workers

Wojciech_BUK_0-1703239987614.png

Even UI block me and won;t allow to change min and max no. of workers

Wojciech_BUK_1-1703240012156.png



So your script will fail as it is violating cluster ploticy