Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16 from aminekaabachi/feature/clusters
Browse files Browse the repository at this point in the history
updating readme and fixing force mode on apis
  • Loading branch information
aminekaabachi committed Sep 30, 2020
2 parents 97d96d8 + 59fe021 commit f1a7e2c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
36 changes: 36 additions & 0 deletions README.md
Expand Up @@ -24,6 +24,42 @@ client = Client(databricks_instance="<instance>", personal_access_token="<token>

```

## Examples

### How to create a cluster

You can use the defined types:

```python

from azure_databricks_sdk_python.types.clusters import AutoScale, ClusterAttributes

spark_conf = {'spark.speculation': True}
autoscale = AutoScale(min_workers=0, max_workers=1)
attributes = ClusterAttributes(cluster_name="my-cluster",
spark_version="7.2.x-scala2.12",
node_type_id="Standard_D3_v2",
spark_conf=spark_conf,
autoscale=autoscale)
created_id = client.clusters.create(attributes)
```

or, you can force an API request with a dict:

```python
attributes = {
'cluster_name': 'my-cluster',
'spark_version': '7.2.x-scala2.12',
'node_type_id': 'Standard_D3_v2',
'spark_conf': {
'spark.speculation': True
},
'num_workers': 1
}
created_id = client.clusters.create(attributes, force=True)
```


## Implementation Progress

Please refer to the progress below:
Expand Down
12 changes: 6 additions & 6 deletions azure_databricks_sdk_python/clusters.py
Expand Up @@ -62,7 +62,7 @@ def get(self, cluster_id):
res = self._get(endpoint, data)
return self._safe_handle(res, res.json(), ClusterInfo)

def events(self, req: ClusterEventRequest, force: bool = True):
def events(self, req: ClusterEventRequest, force: bool = False):
"""Retrieve a list of events about the activity of a cluster.
Args:
Expand All @@ -73,7 +73,7 @@ def events(self, req: ClusterEventRequest, force: bool = True):
ClusterEventResponse: Cluster event request response structure.
"""
endpoint = '/clusters/events'
data = self._validate(req, ClusterEventRequest, force)
data = self._validate(req, ClusterEventRequest, not force)
res = self._post(endpoint, unstructure(data))
return self._safe_handle(res, res.json(), ClusterEventResponse)

Expand Down Expand Up @@ -139,7 +139,7 @@ def permanent_delete(self, cluster_id):
res = self._post(endpoint, data)
return self._safe_handle(res, data, ClusterId)

def resize(self, req: ClusterResizeRequest, force: bool = True):
def resize(self, req: ClusterResizeRequest, force: bool = False):
"""Resize a cluster to have a desired number of workers.
The cluster must be in the RUNNING state.
Expand All @@ -151,7 +151,7 @@ def resize(self, req: ClusterResizeRequest, force: bool = True):
ClusterId: in case of success or will raise an exception.
"""
endpoint = '/clusters/resize'
data = self._validate(req, ClusterResizeRequest, force)
data = self._validate(req, ClusterResizeRequest, not force)
res = self._post(endpoint, unstructure(data))
return self._safe_handle(res, ClusterId(cluster_id=data.get('cluster_id')))

Expand Down Expand Up @@ -186,7 +186,7 @@ def start(self, cluster_id):
res = self._post(endpoint, data)
return self._safe_handle(res, data, ClusterId)

def create(self, req: ClusterAttributes, force: bool = True):
def create(self, req: ClusterAttributes, force: bool = False):
"""Create a new Apache Spark cluster.
This method acquires new instances from the cloud provider if necessary.
Expand All @@ -198,7 +198,7 @@ def create(self, req: ClusterAttributes, force: bool = True):
ClusterId: in case of success or will raise an exception.
"""
endpoint = '/clusters/create'
data = self._validate(req, ClusterAttributes, force)
data = self._validate(req, ClusterAttributes, not force)
res = self._post(endpoint, unstructure(data))
return self._safe_handle(res, res.json(), ClusterId)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_clusters.py
Expand Up @@ -17,7 +17,7 @@

def test_clusters_create_dict_forced():

created_id = client.clusters.create(attributes, False)
created_id = client.clusters.create(attributes, True)
deleted_id = client.clusters.delete(cluster_id=created_id.cluster_id)
assert created_id.cluster_id == deleted_id.cluster_id

Expand Down

0 comments on commit f1a7e2c

Please sign in to comment.