-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure-pipelines.yml
223 lines (200 loc) · 7.47 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
variables:
databricks.notebook.path: /Structured Streaming/
databricks.cluster.name: hackathon-Structured Streaming
databricks.cluster.id:
databricks.cluster.spark_version: 7.1.x-scala2.12
databricks.cluster.node_type_id: Standard_DS3_v2
databricks.cluster.driver_node_type_id: Standard_DS3_v2
databricks.cluster.autotermination_minutes: 30
databricks.cluster.workers.min: 2
databricks.cluster.workers.max: 4
databricks.job.createtables.name: '(StructuredStreaming) - [Setup] Build Delta Tables'
databricks.job.createtables.id: 6
databricks.job.autooptimize.name: '(StructuredStreaming) - [Setup] Auto Optimize'
databricks.job.autooptimize.id: 8
databricks.job.import.name: '(StructuredStreaming) - [Setup] Import Parquet'
databricks.job.import.id: 7
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
displayName: 'Set python 3.7'
inputs:
versionSpec: '3.7'
addToPath: true
architecture: 'x64'
- task: Bash@3
displayName: 'Install Databricks-Cli'
inputs:
targetType: 'inline'
script: |
# install databricks-cli
pip install -U databricks-cli
- task: Bash@3
displayName: 'Configure Databricks CLI'
inputs:
targetType: 'inline'
script: |
# We need to write the pipe the conf into databricks configure --token since
# that command only takes inputs from stdin.
conf=`cat << EOM
$(databricks.host)
$(databricks.token)
EOM`
# For password auth there are three lines expected
# hostname, username, password
echo "$conf" | databricks configure --token
- task: Bash@3
displayName: 'Create workspace folder'
inputs:
targetType: 'inline'
script: databricks workspace mkdirs "$(databricks.notebook.path)"
- task: Bash@3
displayName: 'Import notebooks'
inputs:
targetType: 'inline'
script: |
# import notebooks
databricks workspace import_dir -o notebooks "$(databricks.notebook.path)"
- task: Bash@3
displayName: 'Create / Get Cluster'
inputs:
targetType: 'inline'
script: |
cluster_id=$(databricks clusters list | grep "$(databricks.cluster.name)" | awk '{print $1}')
if [ -z "$cluster_id" ]
then
JSON=`cat << EOM
{
"cluster_name": "$(databricks.cluster.name)",
"spark_version": "$(databricks.cluster.spark_version)",
"spark_conf": {
"spark.databricks.delta.preview.enabled": "true"
},
"node_type_id": "$(databricks.cluster.node_type_id)",
"driver_node_type_id": "$(databricks.cluster.driver_node_type_id)",
"spark_env_vars": {
"PYSPARK_PYTHON": "/databricks/python3/bin/python3"
},
"autotermination_minutes": $(databricks.cluster.autotermination_minutes),
"enable_elastic_disk": true,
"autoscale": {
"min_workers": $(databricks.cluster.workers.min),
"max_workers": $(databricks.cluster.workers.max)
},
"init_scripts_safe_mode": false
}
EOM`
cluster_id=$(databricks clusters create --json "$JSON" | jq -r ".cluster_id")
sleep 10
fi
echo "##vso[task.setvariable variable=databricks.cluster.id;]$cluster_id"
- task: Bash@3
displayName: 'Start Cluster'
inputs:
targetType: 'inline'
script: |
echo "Checking Cluster State (Cluster ID: $(databricks.cluster.id))..."
cluster_state=$(databricks clusters get --cluster-id "$(databricks.cluster.id)" | jq -r ".state")
echo "Cluster State: $cluster_state"
if [ $cluster_state == "TERMINATED" ]
then
echo "Starting Databricks Cluster..."
databricks clusters start --cluster-id "$(databricks.cluster.id)"
sleep 30
cluster_state=$(databricks clusters get --cluster-id "$(databricks.cluster.id)" | jq -r ".state")
echo "Cluster State: $cluster_state"
fi
while [ $cluster_state == "PENDING" ]
do
sleep 30
cluster_state=$(databricks clusters get --cluster-id "$(databricks.cluster.id)" | jq -r ".state")
echo "Cluster State: $cluster_state"
done
if [ $cluster_state == "RUNNING" ]
then
exit 0
else
exit 1
fi
- task: Bash@3
displayName: 'Run Create Tables Job'
inputs:
targetType: 'inline'
script: |
echo "Running job with ID $(databricks.job.createtables.id) "
run_id1=$(databricks jobs run-now --job-id $(databricks.job.createtables.id) | jq ".run_id")
echo " Run ID: $run_id1"
run_state=$(databricks runs get --run-id $run_id1 | jq -r ".state.life_cycle_state")
echo "Run State (ID $run_id1): $run_state"
while [ $run_state == "RUNNING" -o $run_state == "PENDING" ]
do
sleep 30
run_state=$(databricks runs get --run-id $run_id1 | jq -r ".state.life_cycle_state")
echo "Run State (ID $run_id1): $run_state"
done
result_state1=$(databricks runs get --run-id $run_id1 | jq -r ".state.result_state")
state_message1=$(databricks runs get --run-id $run_id1 | jq -r ".state.state_message")
echo "Result State (ID $run_id1): $result_state1, Message: $state_message1"
if [ $result_state1 == "SUCCESS" ]
then
exit 0
else
exit 1
fi
- task: Bash@3
displayName: 'Run Auto-Optimize Job'
inputs:
targetType: 'inline'
script: |
echo "Running job with ID $(databricks.job.autooptimize.id) "
run_id1=$(databricks jobs run-now --job-id $(databricks.job.autooptimize.id) | jq ".run_id")
echo " Run ID: $run_id1"
run_state=$(databricks runs get --run-id $run_id1 | jq -r ".state.life_cycle_state")
echo "Run State (ID $run_id1): $run_state"
while [ $run_state == "RUNNING" -o $run_state == "PENDING" ]
do
sleep 30
run_state=$(databricks runs get --run-id $run_id1 | jq -r ".state.life_cycle_state")
echo "Run State (ID $run_id1): $run_state"
done
result_state1=$(databricks runs get --run-id $run_id1 | jq -r ".state.result_state")
state_message1=$(databricks runs get --run-id $run_id1 | jq -r ".state.state_message")
echo "Result State (ID $run_id1): $result_state1, Message: $state_message1"
if [ $result_state1 == "SUCCESS" ]
then
exit 0
else
exit 1
fi
- task: Bash@3
displayName: 'Run Import Job'
inputs:
targetType: 'inline'
script: |
echo "Running job with ID $(databricks.job.import.id) "
run_id1=$(databricks jobs run-now --job-id $(databricks.job.import.id) | jq ".run_id")
echo " Run ID: $run_id1"
run_state=$(databricks runs get --run-id $run_id1 | jq -r ".state.life_cycle_state")
echo "Run State (ID $run_id1): $run_state"
while [ $run_state == "RUNNING" -o $run_state == "PENDING" ]
do
sleep 30
run_state=$(databricks runs get --run-id $run_id1 | jq -r ".state.life_cycle_state")
echo "Run State (ID $run_id1): $run_state"
done
result_state1=$(databricks runs get --run-id $run_id1 | jq -r ".state.result_state")
state_message1=$(databricks runs get --run-id $run_id1 | jq -r ".state.state_message")
echo "Result State (ID $run_id1): $result_state1, Message: $state_message1"
if [ $result_state1 == "SUCCESS" ]
then
exit 0
else
exit 1
fi