Gareth Healy
2020-02-27 05c8bb4cc58868ff0eaf866dc774dd5149bc9f77
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
---
- name: Check BusinessCentral is running
  command: >
    oc rollout status DeploymentConfig/rhpam-authoring-rhpamcentr --watch=true -n "{{ _namespace }}"
 
- name: Get Business Central route host
  command: >
    oc get route/rhpam-authoring-rhpamcentr -o jsonpath='{.spec.host}' -n "{{ _namespace }}"
  register: businesscentral_host
  retries: "{{ _retry }}"
  delay: "{{ _delay }}"
  until: businesscentral_host.stdout != ""
 
- name: Wait for Business Central route to respond with 200
  uri:
    url: "https://{{ businesscentral_host.stdout }}"
    method: GET
    validate_certs: false
    follow_redirects: yes
  register: bizcentralresult
  retries: "{{ _retry }}"
  delay: "{{ _delay }}"
  until: bizcentralresult.status == 200
 
- name: Check space exists in Business Central (note; error can be ignored)
  uri:
    url: "https://{{ businesscentral_host.stdout }}/rest/spaces/workshop"
    method: GET
    validate_certs: false
    follow_redirects: yes
    user: "{{ _namespace }}"
    password: "{{ _account_password }}"
    force_basic_auth: true
  register: bizcentralspace
  ignore_errors: true
 
- name: Create space in Business Central
  uri:
    url: "https://{{ businesscentral_host.stdout }}/rest/spaces"
    method: POST
    body: "{{ body }}"
    body_format: json
    validate_certs: false
    follow_redirects: yes
    user: "{{ _namespace }}"
    password: "{{ _account_password }}"
    force_basic_auth: true
    status_code: 202
  register: bizcentralclone
  retries: "{{ _retry }}"
  delay: "{{ _delay }}"
  until: bizcentralclone.status == 202
  when: bizcentralspace.status == 404
  vars:
    body:
      name: "workshop"
      description: "Proactive Fraud Management with Case Management, Kafka and DMN Services"
      owner: "admin"
      defaultGroupId: "com.demo"
 
- name: Check project exists in Business Central (note; error can be ignored)
  uri:
    url: "https://{{ businesscentral_host.stdout }}/rest/spaces/workshop/projects/{{ _kie_container_id }}"
    method: GET
    validate_certs: false
    follow_redirects: yes
    user: "{{ _namespace }}"
    password: "{{ _account_password }}"
    force_basic_auth: true
  register: bizcentralproject
  ignore_errors: true
 
### todo: only clone if it doesnt exist
 
- name: Clone case into Business Central
  uri:
    url: "https://{{ businesscentral_host.stdout }}/rest/spaces/workshop/git/clone"
    method: POST
    body: "{{ body }}"
    body_format: json
    validate_certs: false
    follow_redirects: yes
    user: "{{ _namespace }}"
    password: "{{ _account_password }}"
    force_basic_auth: true
    status_code: 202
  register: bizcentralclone
  retries: "{{ _retry }}"
  delay: "{{ _delay }}"
  until: bizcentralclone.status == 202
  when: bizcentralproject.status == 404
  vars:
    body:
      name: "proactive-fraud-detection-case"
      description: "proactive-fraud-detection-case"
      gitURL: "http://mygitea.gitea.svc.cluster.local:3000/{{ _namespace }}/proactive-fraud-detection-case.git"
 
- name: Check job status for clone case in Business Central
  uri:
    url: "https://{{ businesscentral_host.stdout }}/rest/jobs/{{ bizcentralclone.json.jobId }}"
    method: GET
    validate_certs: false
    follow_redirects: yes
    user: "{{ _namespace }}"
    password: "{{ _account_password }}"
    force_basic_auth: true
  register: bizcentralclone_job
  retries: "{{ _retry }}"
  delay: "{{ _delay }}"
  until:
  - bizcentralclone_job is not failed
  - bizcentralclone_job.json is defined
  - bizcentralclone_job.json.status == "SUCCESS"
  when: bizcentralproject.status == 404
 
- name: Maven install for project proactive-fraud-detection-case
  uri:
    url: "https://{{ businesscentral_host.stdout }}/rest/spaces/workshop/projects/{{ _kie_project_id }}/maven/install"
    method: POST
    validate_certs: false
    follow_redirects: yes
    user: "{{ _namespace }}"
    password: "{{ _account_password }}"
    force_basic_auth: true
    status_code: 202
  register: bizcentralinstall
  retries: "{{ _retry }}"
  delay: "{{ _delay }}"
  until: bizcentralinstall.status == 202
 
- name: Check job status for maven install for project proactive-fraud-detection-case
  uri:
    url: "https://{{ businesscentral_host.stdout }}/rest/jobs/{{ bizcentralinstall.json.jobId }}"
    method: GET
    validate_certs: false
    follow_redirects: yes
    user: "{{ _namespace }}"
    password: "{{ _account_password }}"
    force_basic_auth: true
  register: bizcentralinstall_job
  retries: "{{ _retry }}"
  delay: "{{ _delay }}"
  until:
  - bizcentralinstall_job is not failed
  - bizcentralinstall_job.json is defined
  - bizcentralinstall_job.json.status == "SUCCESS"
 
- name: Maven deploy for project proactive-fraud-detection-case
  uri:
    url: "https://{{ businesscentral_host.stdout }}/rest/spaces/workshop/projects/{{ _kie_project_id }}/maven/deploy"
    method: POST
    validate_certs: false
    follow_redirects: yes
    user: "{{ _namespace }}"
    password: "{{ _account_password }}"
    force_basic_auth: true
    status_code: 202
  register: bizcentraldeploy
  retries: "{{ _retry }}"
  delay: "{{ _delay }}"
  until: bizcentraldeploy.status == 202
 
- name: Check job status for maven deplop for project proactive-fraud-detection-case
  uri:
    url: "https://{{ businesscentral_host.stdout }}/rest/jobs/{{ bizcentraldeploy.json.jobId }}"
    method: GET
    validate_certs: false
    follow_redirects: yes
    user: "{{ _namespace }}"
    password: "{{ _account_password }}"
    force_basic_auth: true
  register: bizcentraldeploy_job
  retries: "{{ _retry }}"
  delay: "{{ _delay }}"
  until:
  - bizcentraldeploy_job is not failed
  - bizcentraldeploy_job.json is defined
  - bizcentraldeploy_job.json.status == "SUCCESS"
 
- name: Delete KIE Container proactive-fraud-detection-case (note; error can be ignored)
  uri:
    url: "https://{{ businesscentral_host.stdout }}/rest/controller/management/servers/{{ _kie_server_id }}/containers/{{ _kie_container_id }}"
    method: DELETE
    validate_certs: false
    follow_redirects: yes
    user: "{{ _namespace }}"
    password: "{{ _account_password }}"
    force_basic_auth: true
    status_code: 200
  register: bizcentraldelete_container
  ignore_errors: true
  retries: "{{ _retry }}"
  delay: "{{ _delay }}"
  until: bizcentraldelete_container.status == 404
 
- name: Create KIE Container proactive-fraud-detection-case
  uri:
    url: "https://{{ businesscentral_host.stdout }}/rest/controller/management/servers/{{ _kie_server_id }}/containers/{{ _kie_container_id }}"
    method: PUT
    body: "{{ body }}"
    body_format: json
    validate_certs: false
    follow_redirects: yes
    user: "{{ _namespace }}"
    password: "{{ _account_password }}"
    force_basic_auth: true
    status_code: 201
  register: bizcentralcreate_container
  retries: "{{ _retry }}"
  delay: "{{ _delay }}"
  until: bizcentralcreate_container.status == 201
  vars:
    body:
      container-id: "{{ _kie_container_id }}"
      container-name: "{{ _kie_container_id }}"
      server-template-key :
        server-id: '{{ _kie_server_id }}'
      status: "STARTED"
      release-id:
        group-id: "{{ _kjar_group_id }}"
        artifact-id: "{{ _kjar_artefact_id }}"
        version: "{{ _kjar_version }}"
      configuration:
        'RULE':
          'org.kie.server.controller.api.model.spec.RuleConfig':
            'pollInterval': null
            'scannerStatus': "STOPPED"
        'PROCESS':
          'org.kie.server.controller.api.model.spec.ProcessConfig':
            'runtimeStrategy': "SINGLETON"
            kbase: ''
            ksession: ''
            'mergeMode': "MERGE_COLLECTIONS"