-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook-demo.yml
269 lines (232 loc) · 12.2 KB
/
playbook-demo.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
---
- name: Demo RHDG and Cross Site Replication
hosts: localhost
connection: local
vars:
site1_base_url: <SITE1-PROJECT>.<SITE1-DOMAIN>
site2_base_url: <SITE2-PROJECT>.<SITE2-DOMAIN>
quarkus_app: jdg-employee-quarkus
dotnet_app: jdg-employee-dotnet
golang_app: jdg-employee-golang
tasks:
- name: "Making sure it is possible to access the applications"
ansible.builtin.uri:
url: "http://{{item.appName}}-{{item.appSite}}/api/employees"
return_content: false
status_code: 200
with_items:
- { appName: "{{ quarkus_app }}", appSite: "{{ site1_base_url }}"}
- { appName: "{{ dotnet_app }}", appSite: "{{site1_base_url}}"}
- { appName: "{{ quarkus_app }}", appSite: "{{site2_base_url}}"}
- { appName: "{{ golang_app }}", appSite: "{{site2_base_url}}"}
- name: "List caches in site 1"
pause:
prompt: "Let's list the caches configured in site 1 (Press Return to continue...)"
- name: "Listing caches in Site 1"
ansible.builtin.uri:
url: "https://dg-external-{{ site1_base_url}}/rest/v2/caches"
return_content: false
validate_certs: false
register: caches_site1
failed_when: "'employees' not in caches_site1.json"
- name: "Printing the caches in Site 1"
debug:
var: caches_site1.json
- name: "List caches in site 2"
pause:
prompt: "Let's list the caches configured in site 2 (Press return to continue...)"
- name: "Listing caches in Site 2"
ansible.builtin.uri:
url: "https://dg-external-{{ site2_base_url}}/rest/v2/caches"
return_content: false
validate_certs: false
register: caches_site2
failed_when: "'employees' not in caches_site2.json"
- name: "Printing the caches in Site 2"
debug:
var: caches_site2.json
- name: "Prompt create user in site 1"
pause:
prompt: "-\nLet's create an employee using the quarkus microservice in site-1 and verify that his UUID has been included in site-1's cache.\n(Press return to continue...)"
- name: "Creating an employee via the Quarkus microservice on site-1"
ansible.builtin.uri:
url: "http://{{ quarkus_app }}-{{ site1_base_url}}/api/employees"
method: POST
headers:
Content-Type: application/json
body_format: json
body: |-
{
"fullName": "User Test Demo",
"designation": "RHDG Specialist",
"department": "IT"
}
status_code: 201
return_content: false
validate_certs: false
register: post_employee
failed_when: "'employeeId' not in post_employee.json"
- name: "Prompt user created in site 1"
pause:
prompt: "-\nThe user was successfully created in site-1.\nYou can query the objects in the cache via the https://dg-external-{{site1_base_url}}/console/cache/employees using the \"Entries\" tab.\nLet's list the identifiers (keys) present in the cache for site-1.\n(Press return to continue...)"
- name: "Listing keys present in site-1"
ansible.builtin.uri:
url: "https://dg-external-{{site1_base_url}}/rest/v2/caches/employees?action=keys"
return_content: false
validate_certs: false
method: GET
register: caches_site1
- name: "Printing the keys present in the cache of Site 1"
debug:
var: caches_site1.json
- name: "Prompt user created in site 1"
pause:
prompt: "\nNow let's list the entries present in site-2's cache. Using the features of the replicated cache between different data centers the employee uuid '{{ caches_site1.json[0]}}' created should also be present in the site-2 cache.\n(Press return to continue...)"
- name: "Listing keys present in site-2"
ansible.builtin.uri:
url: "https://dg-external-{{site2_base_url}}/rest/v2/caches/employees?action=keys"
return_content: false
validate_certs: false
method: GET
register: caches_site2
failed_when: caches_site1.json[0] not in caches_site2.json
- name: "Printing the keys present in the cache of Site 2"
debug:
var: caches_site2.json
- name: "Prompt user created in site 1"
pause:
prompt: "\nYou can check the employee transferred to the site-2 cache via URL https://dg-external-{{site2_base_url}}/console/cache/employees using the \"Entries\" tab.\nSuccess! we have achieved our first goal, which was to transport an employee created in a cache in the site-1 cluster to the site-2 cluster almost instantly.\n(Press return to continue...)"
- pause:
prompt: "\nWe will now create another employee using the Golang application in site-2.\n(Press return to continue...)"
- name: "Creating an employee via the Golang microservice on site-2"
ansible.builtin.uri:
url: "http://{{ golang_app }}-{{ site2_base_url}}/api/employees/"
method: POST
headers:
Content-Type: application/json
body_format: json
body: |-
{
"fullName": "User Test Demo II",
"designation": "RHDG Specialist",
"department": "IT"
}
status_code: 201
return_content: false
validate_certs: false
register: post_employee
failed_when: "'employeeId' not in post_employee.json"
- pause:
prompt: "\nThe employee has been successfully created. If you wish, you can query the cached object UUID {{post_employee.json.uuid}} using the Data Grid console in \nsite-1 https://dg-external-{{site1_base_url}}/console/cache/employees or \nsite-2 https://dg-external-{{site2_base_url}}/console/cache/employees\n(Press return to continue...)"
- pause:
prompt: "\nNow we will import the employee created through the Golang microservice from site-2 into the Net Core microservice deployed in site-1.\n(Press return to continue...)"
- name: "Importing an employee created via the Golang microservice on site-2 into Net Core microservice in site-1"
ansible.builtin.uri:
url: "http://{{ dotnet_app }}-{{ site1_base_url}}/api/employees/fromcache/{{post_employee.json.uuid}}"
method: POST
status_code: 201
return_content: true
validate_certs: false
register: import_employee
failed_when: "'Employee' not in import_employee.content"
- pause:
prompt: "\nWonderful, from this point on we have the same entity being managed by two totally independent microservices.\nGolang Microservice in site-2 and Net Core Microservice in site-1,\nconnected only by the cache that keeps the latest version of the employee.\n(Press return to continue...)"
- pause:
prompt: "\nRight now, the most up-to-date version of the employee UUID {{post_employee.json.uuid}} is 1, both the cache and the microservices are with exactly the same version. Let's update this employee to version 2 via the Net Core microservice in site-1.\n(Press return to continue...)"
- name: "Get the employee ID created into Net Core microservice in site-1"
ansible.builtin.uri:
url: "http://{{ dotnet_app }}-{{ site1_base_url}}/api/employees/uuid/{{post_employee.json.uuid}}"
method: GET
status_code: 200
return_content: false
validate_certs: false
register: import_employee_id
failed_when: "'employeeId' not in import_employee_id.json"
- name: "Updating an employee via the Net Core microservice on site-1"
ansible.builtin.uri:
url: "http://{{ dotnet_app }}-{{ site1_base_url}}/api/employees/{{ import_employee_id.json.employeeId }}"
method: PUT
headers:
Content-Type: application/json
body_format: json
body: |-
{
"employeeId": "{{ import_employee_id.json.employeeId }}",
"fullName": "User Test Demo II Updated",
"designation": "RHDG Specialist",
"department": "Marketing"
}
status_code: 200
return_content: false
validate_certs: false
register: put_employee
failed_when: "'employeeId' not in put_employee.json"
- pause:
prompt: "\nRight now, the employee UUID {{post_employee.json.uuid}} has version 2 in the Net Core microservice and in the Data Grid and version 1 in the local database of the Golang microservice.\nLet's try to update the version of the golang service and observe the result.\n(Press return to continue...)"
- name: "Get the employee ID created into Golang microservice in site-2"
ansible.builtin.uri:
url: "http://{{ golang_app }}-{{ site2_base_url}}/api/employees/uuid/{{post_employee.json.uuid}}"
method: GET
status_code: 200
return_content: false
validate_certs: false
register: import_employee_id
failed_when: "'employeeId' not in import_employee_id.json"
- name: "Updating the employee {{ import_employee_id.json.employeeId }} in the Golang microservice on site-2"
ansible.builtin.uri:
url: "http://{{ golang_app }}-{{ site2_base_url}}/api/employees/{{ import_employee_id.json.employeeId }}"
method: PUT
headers:
Content-Type: application/json
body_format: json
body: |-
{
"employeeId": "{{ import_employee_id.json.employeeId }}",
"fullName": "User Test Demo Must Failed",
"designation": "RHDG Specialist",
"department": "Fail"
}
status_code: 400
return_content: true
validate_certs: false
register: fail_employee
- pause:
prompt: "\nThe employee update fails with the message:\n{{ fail_employee.content }}.\nExactly the behavior we expect\n(Press return to continue...)"
- pause:
prompt: "\nLet's now import the employee UUID {{ post_employee.json.uuid }} into the Quarkus microservice on site-1\n(Press return to continue...)"
- name: "Importing the employee UUID {{ post_employee.json.uuid }} into Quarkus microservice on site-1"
ansible.builtin.uri:
url: "http://{{ quarkus_app }}-{{ site1_base_url}}/api/employees/fromcache/{{ post_employee.json.uuid }}"
method: POST
status_code: 201
return_content: true
validate_certs: false
register: import_employee
failed_when: "'Employee' not in import_employee.content"
- name: "Prompt list employees in the quarkus database"
pause:
prompt: "\nNow, let's list the employees present in the Quarkus application database.\n(Press return to continue...)"
- name: "Listing all employees in the Quarkus microservice on site-1"
ansible.builtin.uri:
url: "http://{{ quarkus_app }}-{{ site1_base_url}}/api/employees"
method: GET
status_code: 200
return_content: true
validate_certs: false
register: employees
- name: "Printing employees present in Quarkus microservices on Site 1"
debug:
var: employees.content
- pause:
prompt: "\nLet's update the employee UUID {{ post_employee.json.uuid }} in the Golang microservice on site-2\nThen all services will have the same version present in the Data Grid.\n(Press return to continue...)"
- name: "Update the employee UUID {{ post_employee.json.uuid }} into Golang microservice on site-2"
ansible.builtin.uri:
url: "http://{{ golang_app }}-{{ site2_base_url}}/api/employees/fromcache/{{ import_employee_id.json.employeeId }}"
method: PUT
status_code: 200
return_content: false
validate_certs: false
register: import_employee
failed_when: "'Employee' not in import_employee.json"
- pause:
prompt: "\nWith this demo, we introduce Red Hat Data Grid's cross-cluster replication feature\nThe functionality boils down to:\n* Create an employee and publish to the cache.\n* The services import the employee from the cache to your local base using the UUID.\n* Before making any changes to the employee the applications check if they have the most up-to-date version from the cache, thus preventing operations from being performed on outdated entities.\n(Press return to Finish)"