Skip to content

Commit b6b628d

Browse files
authored
Add the pipelines list command to allow users to view all pipelines visible to them (#333)
This PR adds the pipelines list command to the CLI, which allows users to view metadata about all the pipelines that they own. The list() API is a paginated request, and this command continually requests new pages until they've been exhausted before displaying them. This API also includes updates to the sdk/api_client.py and sdk/service.py files, which come from newly auto-generated versions of the files.
1 parent a162ec8 commit b6b628d

5 files changed

Lines changed: 234 additions & 103 deletions

File tree

databricks_cli/pipelines/api.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ def delete(self, pipeline_id, headers=None):
6060
def get(self, pipeline_id, headers=None):
6161
return self.client.get(pipeline_id, headers)
6262

63+
def list(self, headers=None):
64+
def call(page_token=None, max_results=None, order_by=None):
65+
_data = {}
66+
if page_token:
67+
_data["pagination.page_token"] = page_token
68+
if max_results:
69+
_data["pagination.max_results"] = max_results
70+
if order_by:
71+
_data["pagination.order_by"] = order_by
72+
73+
return self.client.client.perform_query(
74+
'GET', '/pipelines', data=_data, headers=headers)
75+
76+
response = call()
77+
pipelines = response["statuses"]
78+
79+
while "next_page_token" in response["pagination"]:
80+
response = call(page_token=response["pagination"]["next_page_token"])
81+
pipelines.extend(response["statuses"])
82+
return pipelines
83+
6384
def reset(self, pipeline_id, headers=None):
6485
self.client.reset(pipeline_id, headers)
6586

databricks_cli/pipelines/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ def get_cli(api_client, pipeline_id):
165165
click.echo(pretty_format(PipelinesApi(api_client).get(pipeline_id)))
166166

167167

168+
@click.command(context_settings=CONTEXT_SETTINGS,
169+
short_help='Gets a delta pipeline\'s current spec and status')
170+
@debug_option
171+
@profile_option
172+
@pipelines_exception_eater
173+
@provide_api_client
174+
def list_cli(api_client):
175+
click.echo(pretty_format(PipelinesApi(api_client).list()))
176+
177+
168178
@click.command(context_settings=CONTEXT_SETTINGS,
169179
short_help='Resets a delta pipeline so data can be reprocessed from scratch')
170180
@click.option('--pipeline-id', default=None, type=PipelineIdClickType(),
@@ -318,6 +328,7 @@ def pipelines_group(): # pragma: no cover
318328
pipelines_group.add_command(deploy_cli, name='deploy')
319329
pipelines_group.add_command(delete_cli, name='delete')
320330
pipelines_group.add_command(get_cli, name='get')
331+
pipelines_group.add_command(list_cli, name='list')
321332
pipelines_group.add_command(reset_cli, name='reset')
322333
pipelines_group.add_command(run_cli, name='run')
323334
pipelines_group.add_command(stop_cli, name='stop')

databricks_cli/sdk/api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ def perform_query(self, method, path, data = {}, headers = None):
123123
if method == 'GET':
124124
translated_data = {k: _translate_boolean_to_query_param(data[k]) for k in data}
125125
resp = self.session.request(method, self.url + path, params = translated_data,
126-
verify = self.verify, headers = headers)
126+
verify = self.verify, headers = headers)
127127
else:
128128
resp = self.session.request(method, self.url + path, data = json.dumps(data),
129-
verify = self.verify, headers = headers)
129+
verify = self.verify, headers = headers)
130130
try:
131131
resp.raise_for_status()
132132
except requests.exceptions.HTTPError as e:

0 commit comments

Comments
 (0)