Skip to content

Commit ababc1e

Browse files
Add support for CDW partial teardown
Signed-off-by: Saravanan Raju <saravanan.footloose@gmail.com>
1 parent bf69eed commit ababc1e

File tree

6 files changed

+207
-140
lines changed

6 files changed

+207
-140
lines changed

roles/common/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ common__setup_runtime: "{{ ml is defined or de is defined or
132132
common__setup_plat: "{{ env is defined or sequence__setup_runtime | default(False) | bool }}"
133133
common__setup_infra: "{{ infra is defined or sequence__setup_plat | default(False) | bool }}"
134134
common__setup_base: "{{ mgmt is defined or clusters is defined | default(False) | bool }}"
135+
common__teardown_runtime: "{{ common__setup_runtime }}"
136+
common__teardown_plat: "{{ common__setup_plat and dw.teardown is undefined }}"
137+
common__teardown_infra: "{{ common__setup_infra and dw.teardown is undefined }}"
135138

136139
common__include_ml: "{{ ml is defined | bool }}"
137140
common__include_dw: "{{ dw is defined | bool }}"

roles/runtime/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ run__dw_force_delete: "{{ dw.force_delete | default (run__force_te
7575
run__dw_default_vw_type: "{{ dw.default_vw_type | default('hive') }}"
7676
run__dw_default_template_type: "{{ dw.default_template_type | default('xsmall') }}"
7777
run__dw_default_dbc_suffix: "{{ dw.default_dbc_suffix | default('-dl-default') }}"
78+
run__dw_teardown: "{{ dw.teardown | default(omit) }}"
7879

7980
run__df_nodes_min: "{{ df.min_k8s_nodes | default(3) }}"
8081
run__df_nodes_max: "{{ df.max_k8s_nodes | default(5) }}"

roles/runtime/tasks/initialize_teardown.yml

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,111 @@
6868
loop: "{{ run__env_info.environments[0].descendants.ml }}"
6969
loop_control:
7070
loop_var: __ml_config
71-
label: "{{ __ml_config.instanceName }}"
71+
label: "{{ __ml_config.instanceName }}"
72+
73+
- name: Discover CDW deployments
74+
when: run__include_dw
75+
block:
76+
- name: Retrieve CDP DW experiences
77+
cloudera.cloud.dw_cluster_info:
78+
env: "{{ run__env_name }}"
79+
register: __dw_list
80+
81+
- name: Initialize CDP DW cluster id
82+
ansible.builtin.set_fact:
83+
run__dw_cluster_id: "{{ __dw_list.clusters[0].id }}"
84+
85+
- name: Prepare partial teardown for CDW resources
86+
when: run__dw_teardown is defined
87+
block:
88+
- name: Initialize list of CDW database catalogs to be decommissioned
89+
ansible.builtin.set_fact:
90+
run__dw_dbc_ids: "{{ [] }}"
91+
92+
- name: Initialize list of CDW virtual warehouses to be decommissioned
93+
ansible.builtin.set_fact:
94+
run__dw_vw_ids: "{{ [] }}"
95+
96+
- name: Populate CDW database catalogs defined with its id to the teardown list
97+
when: __dbc.id is defined
98+
ansible.builtin.set_fact:
99+
run__dw_dbc_ids: "{{ run__dw_dbc_ids + [ __dbc.id ] }}"
100+
loop: "{{ run__dw_teardown.database_catalogs }}"
101+
loop_control:
102+
loop_var: __dbc
103+
label: "{{ __dbc.id }}"
104+
105+
- name: Fetch the ids of all the CDW database catalogs defined with its name
106+
when: __dbc.name is defined
107+
cloudera.cloud.dw_database_catalog_info:
108+
name: "{{ __dbc.name }}"
109+
cluster_id: "{{ run__dw_cluster_id }}"
110+
loop: "{{ run__dw_teardown.database_catalogs }}"
111+
loop_control:
112+
loop_var: __dbc
113+
label: "{{ __dbc.name }}"
114+
register: __dbc_name_list
115+
116+
- name: Populate CDW database catalogs defined with its name to the teardown list
117+
when:
118+
- __dbc_result.database_catalogs is defined
119+
- __dbc_result.database_catalogs | length > 0
120+
- __dbc_result.database_catalogs[0].id not in run__dw_dbc_ids
121+
ansible.builtin.set_fact:
122+
run__dw_dbc_ids: "{{ run__dw_dbc_ids + [ __dbc_result.database_catalogs[0].id ] }}"
123+
loop: "{{ __dbc_name_list.results }}"
124+
loop_control:
125+
loop_var: __dbc_result
126+
label: "{{ __dbc_result.database_catalogs[0].id }}"
127+
128+
- name: Fetch all the CDW virtual warehouses under a CDW cluster
129+
cloudera.cloud.dw_virtual_warehouse_info:
130+
cluster_id: "{{ run__dw_cluster_id }}"
131+
register: __all_vw_list
132+
133+
- name: Populate all the CDW virtual warehouses of database catalogs scheduled for teardown to the teardown list
134+
when:
135+
- run__dw_dbc_ids is defined
136+
- __vw.dbcId in run__dw_dbc_ids
137+
ansible.builtin.set_fact:
138+
run__dw_vw_ids: "{{ run__dw_vw_ids + [ __vw.id ] }}"
139+
loop: "{{ __all_vw_list.virtual_warehouses }}"
140+
loop_control:
141+
loop_var: __vw
142+
label: "{{ __vw.id }}"
143+
144+
- name: Fetch the ids of all the CDW virtual warehouses defined with its name
145+
when:
146+
- run__dw_teardown.virtual_warehouses is defined
147+
- __vw.name is defined
148+
cloudera.cloud.dw_virtual_warehouse_info:
149+
name: "{{ __vw.name }}"
150+
cluster_id: "{{ run__dw_cluster_id }}"
151+
loop: "{{ run__dw_teardown.virtual_warehouses }}"
152+
loop_control:
153+
loop_var: __vw
154+
label: "{{ __vw.name }}"
155+
register: __vw_name_list
156+
157+
- name: Populate CDW virtual warehouses defined with its id to the teardown list
158+
when:
159+
- __vw.id is defined
160+
- __vw.id not in run__dw_vw_ids
161+
ansible.builtin.set_fact:
162+
run__dw_vw_ids: "{{ run__dw_vw_ids + [ __vw.id ]}}"
163+
loop: "{{ run__dw_teardown.virtual_warehouses }}"
164+
loop_control:
165+
loop_var: __vw
166+
label: "{{ __vw.id }}"
167+
168+
- name: Populate CDW virtual warehouses defined with its name to the teardown list
169+
when:
170+
- __vw_result.virtual_warehouses is defined
171+
- __vw_result.virtual_warehouses | length > 0
172+
- __vw_result.virtual_warehouses[0].id not in run__dw_vw_ids
173+
ansible.builtin.set_fact:
174+
run__dw_vw_ids: "{{ run__dw_vw_ids + [ __vw_result.virtual_warehouses[0].id ]}}"
175+
loop: "{{ __vw_name_list.results }}"
176+
loop_control:
177+
loop_var: __vw_result
178+
label: "{{ __vw_result.virtual_warehouses[0].id }}"

roles/runtime/tasks/teardown_base.yml

Lines changed: 75 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -33,89 +33,32 @@
3333
register: __opdb_teardowns_info
3434

3535
- name: Execute CDP DW teardown
36-
when:
37-
- run__include_dw | bool
38-
- run__env_info.environments | length > 0
39-
- run__env_info.environments[0].descendants.dw | length > 0
40-
block:
41-
- name: Execute CDP DW virtual warehouse teardown
42-
when: run__force_teardown | bool
43-
cloudera.cloud.dw_cluster:
44-
env: "{{ run__env_name }}"
45-
state: absent
46-
wait: no
47-
force: "{{ run__dw_force_delete }}"
48-
register: __dw_cluster_teardown_info
49-
50-
- name: Execute CDP DW virtual warehouse teardown
51-
when: not run__force_teardown | bool
52-
block:
53-
- name: Retrieve CDP DW experiences
54-
cloudera.cloud.dw_cluster_info:
55-
env: "{{ run__env_name }}"
56-
register: __dw_list
57-
58-
- name: Debug output CDP DW
59-
debug:
60-
msg: "CDP DW : {{ __dw_list }}"
61-
62-
- name: Fetch all the CDP DW Database Catalogs under the cluster
63-
cloudera.cloud.dw_database_catalog_info:
64-
cluster_id: "{{ __dw_list.clusters[0].id }}"
65-
register: __dbc_list
66-
67-
- name: Debug output CDP DW DBCs
68-
debug:
69-
msg: "CDP DW DBC : {{ __dbc_list }}"
70-
71-
- name: Fetch all the CDP DW Virtual Warehouse
72-
cloudera.cloud.dw_virtual_warehouse_info:
73-
cluster_id: "{{ __dw_list.clusters[0].id }}"
74-
dbc_id: "{{ __dbc.id }}"
75-
loop: "{{ __dbc_list.database_catalogs }}"
76-
loop_control:
77-
loop_var: __dbc
78-
register: __vw_list
79-
80-
- name: Debug output CDP DW VWs
81-
debug:
82-
msg: "CDP DW VWs : {{ __vw_list }}"
83-
#
84-
# - name: Delete all CDP DW Virtual Warehouses
85-
# cloudera.cloud.dw_virtual_warehouse:
86-
# cluster_id: "{{ __dw_list.clusters[0].id }}"
87-
# id: "{{ __vw.id }}"
88-
# state: absent
89-
# wait: no
90-
# loop: "{{ __vw_list.results[0].virtual_warehouses }}"
91-
# loop_control:
92-
# loop_var: __vw
93-
# async: 3600 # 1 hour timeout
94-
# poll: 0
95-
# register: __dw_vw_teardown_info
96-
97-
# - name: Delete all CDP DW Database Catalogs
98-
# cloudera.cloud.dw_database_catalog:
99-
# cluster_id: "{{ __dw_list.clusters[0].id }}"
100-
# name: "{{ __dbc.name }}"
101-
# state: absent
102-
# wait: no
103-
# loop: "{{ __dbc_list.database_catalogs }}"
104-
# loop_control:
105-
# loop_var: __dbc
106-
# async: 3600 # 1 hour timeout
107-
# poll: 0
108-
# register: __dw_dbc_teardown_info
109-
110-
- name: Execute CDP DW virtual warehouse teardown
111-
cloudera.cloud.dw_cluster:
112-
env: "{{ run__env_name }}"
113-
state: absent
36+
when: run__dw_teardown is not defined
37+
cloudera.cloud.dw_cluster:
38+
env: "{{ run__env_name }}"
39+
state: absent
40+
wait: yes
41+
force: "{{ run__dw_force_delete }}"
42+
async: 3600 # 1 hour timeout
43+
poll: 0
44+
register: __dw_cluster_teardown_info
11445

115-
wait: no
116-
async: 3600 # 1 hour timeout
117-
poll: 0
118-
register: __dw_cluster_teardown_info
46+
- name: Execute CDP virtual warehouse partial teardown
47+
when:
48+
- run__dw_teardown is defined
49+
- run__dw_vw_ids is defined
50+
- run__dw_vw_ids | length > 0
51+
cloudera.cloud.dw_virtual_warehouse:
52+
cluster_id: "{{ run__dw_cluster_id }}"
53+
id: "{{ __vw_id }}"
54+
state: absent
55+
wait: yes
56+
loop: "{{ run__dw_vw_ids }}"
57+
loop_control:
58+
loop_var: __vw_id
59+
async: 3600 # 1 hour timeout
60+
poll: 0
61+
register: __dw_vw_teardown_info
11962

12063
- name: Execute CDP Dataflow teardown
12164
register: __df_teardown_info
@@ -202,61 +145,58 @@
202145
retries: 120
203146
delay: 30
204147

205-
- name: Wait for CDP DW deployments to decommission
206-
when: run__include_dw | bool
207-
block:
208-
# - name: CDW cluster teardown info
209-
# debug:
210-
# msg: "CDW : {{ __dw_vw_teardown_info }}"
211-
#
212-
# - name: Wait for CDW Virtual Warehouse to decommision
213-
# when:
214-
# - __dw_vw_teardown_info is defined
215-
# - __dw_vw_teardown_info.results is defined
216-
# - __dw_vw_teardown_info.results | length > 0
217-
# ansible.builtin.async_status:
218-
# jid: "{{ __dw_vw_teardown.ansible_job_id }}"
219-
# loop_control:
220-
# loop_var: __dw_vw_teardown
221-
# loop: "{{ __dw_vw_teardown_info.results }}"
222-
# register: __dw_vw_teardown_async
223-
# until: __dw_vw_teardown_async.finished
224-
# retries: 120
225-
# delay: 30
226-
#
227-
# - name: Wait for CDW Database Catalog to decommision
228-
# when:
229-
# - __dw_dbc_teardown_info is defined
230-
# - __dw_dbc_teardown_info.results is defined
231-
# - __dw_dbc_teardown_info.results | length > 0
232-
# ansible.builtin.async_status:
233-
# jid: "{{ __dw_dbc_teardown.ansible_job_id }}"
234-
# loop_control:
235-
# loop_var: __dw_dbc_teardown
236-
# loop: "{{ __dw_dbc_teardown_info.results }}"
237-
# register: __dw_dbc_teardown_async
238-
# until: __dw_dbc_teardown_async.finished
239-
# retries: 120
240-
# delay: 30
148+
- name: Wait for CDP DW virtual warehouse to decommission
149+
when:
150+
- __dw_vw_teardown_info is defined
151+
- __dw_vw_teardown_info.results is defined
152+
- __dw_vw_teardown_info.results | length > 0
153+
ansible.builtin.async_status:
154+
jid: "{{ __dw_vw_teardown.ansible_job_id }}"
155+
loop_control:
156+
loop_var: __dw_vw_teardown
157+
loop: "{{ __dw_vw_teardown_info.results }}"
158+
register: __dw_vw_teardown_async
159+
until: __dw_vw_teardown_async.finished
160+
retries: 120
161+
delay: 30
162+
163+
- name: Execute CDP DW Database Catalogs partial teardown
164+
when: run__dw_teardown.database_catalogs is defined
165+
cloudera.cloud.dw_database_catalog:
166+
cluster_id: "{{ run__dw_cluster_id }}"
167+
id: "{{ __dbc_id }}"
168+
state: absent
169+
wait: yes
170+
loop: "{{ run__dw_dbc_ids }}"
171+
loop_control:
172+
loop_var: __dbc_id
173+
async: 3600 # 1 hour timeout
174+
poll: 0
175+
register: __dw_dbc_teardown_info
241176

242-
- name: CDW cluster teardown info
243-
debug:
244-
msg: "CDW : {{ __dw_cluster_teardown_info }}"
177+
- name: Wait for CDW Database Catalog to decommision
178+
when:
179+
- __dw_dbc_teardown_info is defined
180+
- __dw_dbc_teardown_info.results is defined
181+
- __dw_dbc_teardown_info.results | length > 0
182+
ansible.builtin.async_status:
183+
jid: "{{ __dw_dbc_teardown.ansible_job_id }}"
184+
loop_control:
185+
loop_var: __dw_dbc_teardown
186+
loop: "{{ __dw_dbc_teardown_info.results }}"
187+
register: __dw_dbc_teardown_async
188+
until: __dw_dbc_teardown_async.finished
189+
retries: 120
190+
delay: 30
245191

246-
- name: Wait for CDW cluster to decommision
247-
when:
248-
- __dw_cluster_teardown_info is defined
249-
- __dw_cluster_teardown_info.results is defined
250-
- __dw_cluster_teardown_info.results | length > 0
251-
ansible.builtin.async_status:
252-
jid: "{{ __dw_cluster_teardown.ansible_job_id }}"
253-
loop_control:
254-
loop_var: __dw_cluster_teardown
255-
loop: "{{ __dw_cluster_teardown_info }}"
256-
register: __dw_cluster_teardown_async
257-
until: __dw_cluster_teardown_async.finished
258-
retries: 120
259-
delay: 30
192+
- name: Wait for CDW cluster to decommision
193+
when: __dw_cluster_teardown_info.ansible_job_id is defined
194+
ansible.builtin.async_status:
195+
jid: "{{ __dw_cluster_teardown_info.ansible_job_id }}"
196+
register: __dw_cluster_teardown_async
197+
until: __dw_cluster_teardown_async.finished
198+
retries: 120
199+
delay: 30
260200

261201
- name: Wait for CDP OpDB deployments to decommission
262202
when:

roles/sequence/defaults/main.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
---
15-
sequence__setup_runtime: "{{ common__setup_runtime }}"
15+
sequence__setup_runtime: "{{ common__setup_runtime }}"
1616

17-
sequence__setup_plat: "{{ common__setup_plat }}"
17+
sequence__setup_plat: "{{ common__setup_plat }}"
1818

19-
sequence__setup_infra: "{{ common__setup_infra }}"
19+
sequence__setup_infra: "{{ common__setup_infra }}"
2020

21-
sequence_init: "{{ sequence__setup_infra }}"
21+
sequence_init: "{{ sequence__setup_infra }}"
22+
23+
sequence__teardown_runtime: "{{ common__teardown_runtime }}"
24+
25+
sequence__teardown_plat: "{{ common__teardown_plat }}"
26+
27+
sequence__teardown_infra: "{{ common__teardown_infra }}"

0 commit comments

Comments
 (0)