2626
2727import click
2828
29- from databricks_cli .click_types import PipelineSpecClickType
29+ from databricks_cli .click_types import PipelineSpecClickType , PipelineIdClickType
3030from databricks_cli .utils import eat_exceptions , CONTEXT_SETTINGS
3131from databricks_cli .version import print_version_callback , version
3232from databricks_cli .pipelines .api import PipelinesApi
3636@click .command (context_settings = CONTEXT_SETTINGS ,
3737 short_help = 'Deploys a delta pipeline according to the pipeline specification' )
3838@click .argument ('spec_arg' , default = None , required = False )
39- @click .option ('--spec' , default = None , help = PipelineSpecClickType .help )
39+ @click .option ('--spec' , default = None , type = PipelineSpecClickType (), help = PipelineSpecClickType .help )
4040@debug_option
4141@profile_option
4242@eat_exceptions
4343@provide_api_client
4444def deploy_cli (api_client , spec_arg , spec ):
4545 """
46- Deploys a delta pipeline according to the pipeline specification.
47- * The pipeline spec is a deployment specification that explains how to run a
48- Delta Pipeline on Databricks.
49- * The CLI simply forwards the spec to Databricks.
50- * All the local libraries referenced in the spec are uploaded to DBFS.
46+ Deploys a delta pipeline according to the pipeline specification. The pipeline spec is a
47+ specification that explains how to run a Delta Pipeline on Databricks. All local libraries
48+ referenced in the spec are uploaded to DBFS.
49+
50+ Usage:
51+
52+ databricks pipelines deploy example.json
53+
54+ OR
55+
56+ databricks pipelines deploy --spec example.json
5157 """
5258 if bool (spec_arg ) == bool (spec ):
5359 raise RuntimeError ('The spec should be provided either by an option or argument' )
@@ -57,30 +63,97 @@ def deploy_cli(api_client, spec_arg, spec):
5763
5864
5965@click .command (context_settings = CONTEXT_SETTINGS ,
60- short_help = 'Stops a delta pipeline and cleans '
61- 'up Databricks resources associated with it' )
66+ short_help = 'Stops a delta pipeline and deletes its associated Databricks resources' )
6267@click .argument ('spec_arg' , default = None , required = False )
63- @click .option ('--spec' , default = None , help = PipelineSpecClickType .help )
64- @click .option ('--pipeline-id' , default = None ,
65- help = 'id associated with the pipeline to be stopped' )
68+ @click .option ('--spec' , default = None , type = PipelineSpecClickType (), help = PipelineSpecClickType .help )
69+ @click .option ('--pipeline-id' , default = None , type = PipelineIdClickType (),
70+ help = PipelineIdClickType . help )
6671@debug_option
6772@profile_option
6873@eat_exceptions
6974@provide_api_client
7075def delete_cli (api_client , spec_arg , spec , pipeline_id ):
7176 """
72- Stops a delta pipeline and cleans up Databricks resources associated with it
77+ Stops a delta pipeline and deletes its associated Databricks resources. The pipeline can be
78+ resumed by deploying it again.
79+
80+ Usage:
81+
82+ databricks pipelines delete example.json
83+
84+ OR
85+
86+ databricks pipelines delete --spec example.json
87+
88+ OR
89+
90+ databricks pipelines delete --pipeline-id 1234
7391 """
74- # Only one out of spec/pipeline_id/spec_arg should be supplied
75- if bool (spec_arg ) + bool (spec ) + bool (pipeline_id ) != 1 :
76- raise RuntimeError ('Either spec should be provided as an argument '
77- 'or option, or the pipeline-id should be provided' )
78- if bool (spec_arg ) or bool (spec ):
79- src = spec_arg if bool (spec_arg ) else spec
80- pipeline_id = _read_spec (src )["id" ]
92+ pipeline_id = _get_pipeline_id (spec_arg = spec_arg , spec = spec , pipeline_id = pipeline_id )
8193 PipelinesApi (api_client ).delete (pipeline_id )
8294
8395
96+ @click .command (context_settings = CONTEXT_SETTINGS ,
97+ short_help = 'Gets a delta pipeline\' s current spec and status' )
98+ @click .argument ('spec_arg' , default = None , required = False )
99+ @click .option ('--spec' , default = None , type = PipelineSpecClickType (), help = PipelineSpecClickType .help )
100+ @click .option ('--pipeline-id' , default = None , type = PipelineIdClickType (),
101+ help = PipelineIdClickType .help )
102+ @debug_option
103+ @profile_option
104+ @eat_exceptions
105+ @provide_api_client
106+ def get_cli (api_client , spec_arg , spec , pipeline_id ):
107+ """
108+ Gets a delta pipeline's current spec and status.
109+
110+ Usage:
111+
112+ databricks pipelines get example.json
113+
114+ OR
115+
116+ databricks pipelines get --spec example.json
117+
118+ OR
119+
120+ databricks pipelines get --pipeline-id 1234
121+ """
122+ pipeline_id = _get_pipeline_id (spec_arg = spec_arg , spec = spec , pipeline_id = pipeline_id )
123+ PipelinesApi (api_client ).get (pipeline_id )
124+
125+
126+ @click .command (context_settings = CONTEXT_SETTINGS ,
127+ short_help = 'Resets a delta pipeline so data can be reprocessed from scratch' )
128+ @click .argument ('spec_arg' , default = None , required = False )
129+ @click .option ('--spec' , default = None , type = PipelineSpecClickType (), help = PipelineSpecClickType .help )
130+ @click .option ('--pipeline-id' , default = None , type = PipelineIdClickType (),
131+ help = PipelineIdClickType .help )
132+ @debug_option
133+ @profile_option
134+ @eat_exceptions
135+ @provide_api_client
136+ def reset_cli (api_client , spec_arg , spec , pipeline_id ):
137+ """
138+ Resets a delta pipeline by truncating tables and creating new checkpoint folders so data is
139+ reprocessed from scratch.
140+
141+ Usage:
142+
143+ databricks pipelines reset example.json
144+
145+ OR
146+
147+ databricks pipelines reset --spec example.json
148+
149+ OR
150+
151+ databricks pipelines reset --pipeline-id 1234
152+ """
153+ pipeline_id = _get_pipeline_id (spec_arg = spec_arg , spec = spec , pipeline_id = pipeline_id )
154+ PipelinesApi (api_client ).reset (pipeline_id )
155+
156+
84157def _read_spec (src ):
85158 """
86159 Reads the spec at src as a JSON if no file extension is provided, or if in the extension format
@@ -95,6 +168,21 @@ def _read_spec(src):
95168 raise RuntimeError ('The provided file extension for the spec is not supported' )
96169
97170
171+ def _get_pipeline_id (spec_arg , spec , pipeline_id ):
172+ """
173+ Ensures that the user has either specified a spec (either through argument or option) or a
174+ pipeline ID directly, and returns the pipeline id to use.
175+ """
176+ # Only one out of spec/pipeline_id/spec_arg should be supplied
177+ if bool (spec_arg ) + bool (spec ) + bool (pipeline_id ) != 1 :
178+ raise RuntimeError ('Either spec should be provided as an argument '
179+ 'or option, or the pipeline-id should be provided' )
180+ if bool (spec_arg ) or bool (spec ):
181+ src = spec_arg if bool (spec_arg ) else spec
182+ pipeline_id = _read_spec (src )["id" ]
183+ return pipeline_id
184+
185+
98186@click .group (context_settings = CONTEXT_SETTINGS ,
99187 short_help = 'Utility to interact with the Databricks Delta Pipelines.' )
100188@click .option ('--version' , '-v' , is_flag = True , callback = print_version_callback ,
@@ -110,3 +198,5 @@ def pipelines_group():
110198
111199pipelines_group .add_command (deploy_cli , name = 'deploy' )
112200pipelines_group .add_command (delete_cli , name = 'delete' )
201+ pipelines_group .add_command (get_cli , name = 'get' )
202+ pipelines_group .add_command (reset_cli , name = 'reset' )
0 commit comments