Update Documentation for migration
[policy/parent.git] / docs / clamp / acm / design-impl / clamp-runtime-acm.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2
3 .. _clamp-runtime-acm:
4
5 The CLAMP Automation Composition Runtime
6 ########################################
7
8 .. contents::
9     :depth: 3
10
11
12 This article explains how CLAMP Automation Composition Runtime is implemented.
13
14 Terminology
15 ***********
16 - Broadcast message: a message for all participants (participantId=null)
17 - Message to a participant: a message only for a participant (participantId properly filled)
18 - ThreadPoolExecutor: ThreadPoolExecutor executes the given task, into SupervisionAspect class is configured to execute tasks in ordered manner, one by one
19 - Spring Scheduling: into SupervisionAspect class, the @Scheduled annotation invokes "schedule()" method every "runtime.participantParameters.heartBeatMs" milliseconds with a fixed delay
20 - MessageIntercept: "@MessageIntercept" annotation is used into SupervisionHandler class to intercept "handleParticipantMessage" method calls using spring aspect oriented programming
21 - GUI: swagger-ui, Postman or policy-gui
22 - Message Broker: supported message Broker are DMaap and Strimzi-Kafka
23
24 Design of Rest Api
25 ******************
26
27 Check CLAMP Runtime and Participants
28 ++++++++++++++++++++++++++++++++++++
29 - GUI calls GET "/onap/policy/clamp/acm/health" endpoint and receives the "UP" status as response
30 - GUI calls GET "/onap/policy/clamp/acm/v2/participants" endpoint and receives all participants registered with supported Element Types as response
31
32 Order an immediate Participant Report from all participants
33 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34 - GUI calls PUT "/onap/policy/clamp/acm/v2/participants" endpoint
35 - runtime-ACM receives the call by Rest-Api (CommissioningController)
36 - It triggers the execution to send a broadcast PARTICIPANT_STATUS_REQ message
37
38 Create of a Automation Composition Definition Type
39 ++++++++++++++++++++++++++++++++++++++++++++++++++
40 - GUI calls POST "/onap/policy/clamp/acm/v2/compositions" endpoint with a Automation Composition Type Definition (Tosca Service Template) as body
41 - runtime-ACM receives the call by Rest-Api (CommissioningController)
42 - It validates the Automation Composition Type Definition
43 - It saves to DB the Tosca Service Template using AcDefinitionProvider with new compositionId and COMMISSIONED status
44 - the Rest-Api call returns the compositionId generated and the list of Element Definition Type
45
46 Update of a Automation Composition Definition Type
47 ++++++++++++++++++++++++++++++++++++++++++++++++++
48 - GUI calls POST "/onap/policy/clamp/acm/v2/compositions" endpoint with a Automation Composition Type Definition (Tosca Service Template) as body. It have to contain the compositionId
49 - runtime-ACM receives the call by Rest-Api (CommissioningController)
50 - It checks that Automation Composition Type Definition is in COMMISSIONED status
51 - It validates the Automation Composition Type Definition
52 - It updates to DB the Tosca Service Template using AcDefinitionProvider using the compositionId
53 - the Rest-Api call returns the compositionId and the list of Element Definition Type
54
55 Priming of a Automation Composition Definition Type
56 +++++++++++++++++++++++++++++++++++++++++++++++++++
57 - GUI calls POST "/onap/policy/clamp/acm/v2/compositions/{compositionId}" endpoint with PRIME as primeOrder
58 - runtime-ACM receives the call by Rest-Api (CommissioningController)
59 - It checks that Automation Composition Type Definition is in COMMISSIONED status
60 - It validates and update the AC Element Type Definition with supported Element Types by participants
61 - It updates AC Definition to DB with PRIMING as status
62 - It triggers the execution to send a broadcast PARTICIPANT_PRIME message
63 - the message is built by ParticipantPrimePublisher using Tosca Service Template data
64
65 Create of a Automation Composition Instance
66 +++++++++++++++++++++++++++++++++++++++++++
67 - GUI calls POST "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances" endpoint with a Automation Composition Instance as body. It have to contain the compositionId
68 - runtime-ACM receives the call by Rest-Api (InstantiationController)
69 - It validates the AC Instance and checks that the related composition has COMMISSIONED as status
70 - It set the related participantId into the AC Element Instance using the participantId defined in AC Element Type Definition
71 - It saves the Automation Composition to DB with UNDEPLOYED deployState and NONE lockState
72 - the Rest-Api call returns the instanceId and the list of AC Element Instance
73
74 Update of a Automation Composition Instance
75 +++++++++++++++++++++++++++++++++++++++++++
76 - GUI calls POST "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances" endpoint with a Automation Composition Instance as body. It have to contain the compositionId and the instanceId
77 - runtime-ACM receives the call by Rest-Api (InstantiationController)
78 - It checks that AC Instance is in UNDEPLOYED/DEPLOYED deployState
79 - It updates the Automation Composition to DB
80 - the Rest-Api call returns the instanceId and the list of AC Element Instance
81 - the runtime sends an update event to the participants which performs the update operation on the deployed instances.
82
83 Migrate of a Automation Composition Instance
84 ++++++++++++++++++++++++++++++++++++++++++++
85 - GUI has already a new composition definition primed
86 - GUI calls POST "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances" endpoint with a Automation Composition Instance as body. It have to contain the compositionId, the compositionTargetId and the instanceId
87 - runtime-ACM receives the call by Rest-Api (InstantiationController)
88 - It checks that AC Instance is in DEPLOYED deployState
89 - It checks that compositionTargetId is related to a primed composition definition
90 - It updates the Automation Composition to DB
91 - the Rest-Api call returns the instanceId and the list of AC Element Instance
92 - the runtime sends a migrate event to the participants which performs the migrate operation on the deployed instances.
93
94 Issues AC instance to change status
95 +++++++++++++++++++++++++++++++++++
96
97 case **deployOrder: DEPLOY**
98
99 - GUI calls "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances/{instanceId}" endpoint with DEPLOY as deployOrder
100 - runtime-ACM receives the call by Rest-Api (InstantiationController)
101 - It validates the status order issued (related AC Instance has UNDEPLOYED as deployState)
102 - It updates the AC Instance to DB with DEPLOYING deployState
103 - It triggers the execution to send a broadcast AUTOMATION_COMPOSITION_DEPLOY message
104 - the message is built by AutomationCompositionDeployPublisher using Tosca Service Template data and Instance data. (with startPhase = first startPhase)
105
106 case **lockOrder: UNLOCK**
107
108 - GUI calls "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances/{instanceId}" endpoint with UNLOCK as lockOrder
109 - runtime-ACM receives the call by Rest-Api (InstantiationController)
110 - It validates the status order issued (related AC Instance has DEPLOYED as deployState and LOCK as lockOrder)
111 - It updates the AC Instance to DB with LOCKING lockOrder
112 - It triggers the execution to send a broadcast AUTOMATION_COMPOSITION_STATE_CHANGE message
113 - the message is built by AutomationCompositionStateChangePublisher using Instance data. (with startPhase = first startPhase)
114
115 case **lockOrder: LOCK**
116
117 - GUI calls "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances/{instanceId}" endpoint with LOCK as lockOrder
118 - runtime-ACM receives the call by Rest-Api (InstantiationController)
119 - It validates the status order issued (related AC Instance has DEPLOYED as deployState and UNLOCK as lockOrder)
120 - It updates the AC Instance to DB with UNLOCKING lockOrder
121 - It triggers the execution to send a broadcast AUTOMATION_COMPOSITION_STATE_CHANGE message
122 - the message is built by AutomationCompositionStateChangePublisher using Instance data. (with startPhase = last StartPhase)
123
124 case **deployOrder: UNDEPLOY**
125
126 - GUI calls "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances/{instanceId}" endpoint with UNDEPLOY as deployOrder
127 - runtime-ACM receives the call by Rest-Api (InstantiationController)
128 - It validates the status order issued (related AC Instance has DEPLOYED as deployState and LOCK as lockOrder)
129 - It updates the AC Instance to DB with UNDEPLOYING deployState
130 - It triggers the execution to send a broadcast AUTOMATION_COMPOSITION_STATE_CHANGE message
131 - the message is built by AutomationCompositionStateChangePublisher using Instance data. (with startPhase = last StartPhase)
132
133 Delete of a Automation Composition Instance
134 +++++++++++++++++++++++++++++++++++++++++++
135 - GUI calls DELETE "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances/{instanceId}" endpoint
136 - runtime-ACM receives the call by Rest-Api (InstantiationController)
137 - It checks that AC Instance is in UNDEPLOYED deployState
138 - It updates the AC Instance to DB with DELETING deployState
139 - It triggers the execution to send a broadcast AUTOMATION_COMPOSITION_STATE_CHANGE message
140 - the message is built by AutomationCompositionStateChangePublisher using Instance data. (with startPhase = last StartPhase)
141
142 Depriming of a Automation Composition Definition Type
143 +++++++++++++++++++++++++++++++++++++++++++++++++++++
144 - GUI calls POST "/onap/policy/clamp/acm/v2/compositions/{compositionId}" endpoint with DEPRIME as primeOrder
145 - runtime-ACM receives the call by Rest-Api (CommissioningController)
146 - It checks that Automation Composition Type Definition is in PRIMED status
147 - It updates AC Definition to DB with DEPRIMING as status
148 - It triggers the execution to send a broadcast PARTICIPANT_PRIME message
149 - the message is built by ParticipantPrimePublisher using Tosca Service Template data
150
151 Delete of a Automation Composition Definition Type
152 ++++++++++++++++++++++++++++++++++++++++++++++++++
153 - GUI calls DELETE "/onap/policy/clamp/acm/v2/compositions/{compositionId}" endpoint
154 - runtime-ACM receives the call by Rest-Api (CommissioningController)
155 - It checks that AC Definition Type is in COMMISSIONED status
156 - It deletes the Automation Composition Type from DB
157
158 StartPhase
159 **********
160 The startPhase is particularly important in Automation Composition update and Automation Composition state changes because sometime the user wishes to control the order in which the state changes in Automation Composition Elements in a Automation Composition.
161
162 How to define StartPhase
163 ++++++++++++++++++++++++
164 StartPhase is defined as shown below in the Definition of TOSCA fundamental Automation Composition Types yaml file.
165
166 .. code-block:: YAML
167
168   startPhase:
169     type: integer
170     required: false
171     constraints:
172     - greater-or-equal: 0
173     description: A value indicating the start phase in which this Automation Composition element will be started, the
174                  first start phase is zero. Automation Composition Elements are started in their start_phase order and stopped
175                  in reverse start phase order. Automation Composition Elements with the same start phase are started and
176                  stopped simultaneously
177     metadata:
178       common: true
179
180 The "common: true" value in the metadata of the startPhase property identifies that property as being a common property.
181 This property will be set on the CLAMP GUI during Automation Composition commissioning.
182 Example where it could be used:
183
184 .. code-block:: YAML
185
186   org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement:
187     # Consul http config for PMSH.
188     version: 1.2.3
189     type: org.onap.policy.clamp.acm.HttpAutomationCompositionElement
190     type_version: 1.0.1
191     description: Automation Composition element for the http requests of PMSH microservice
192     properties:
193       provider: ONAP
194       uninitializedToPassiveTimeout: 180
195       startPhase: 1
196
197 How StartPhase works
198 ++++++++++++++++++++
199 In state changes from UNDEPLOYED → DEPLOYED or LOCKED → UNLOCKED, Automation Composition elements are started in increasing order of their startPhase.
200
201 Example of DEPLOY order with Http_PMSHMicroserviceAutomationCompositionElement with startPhase to 1 and PMSH_K8SMicroserviceAutomationCompositionElement with startPhase to 0
202
203 - runtime-ACM sends a broadcast AUTOMATION_COMPOSITION_DEPLOY message to all participants with startPhase = 0
204 - participant receives the AUTOMATION_COMPOSITION_DEPLOY message and runs to DEPLOYED state (only AC elements defined as startPhase = 0)
205 - runtime-ACM receives AUTOMATION_COMPOSITION_DEPLOY_ACK messages from participants and set the state (from the AC element of the message) to DEPLOYED
206 - runtime-ACM calculates that all AC elements with startPhase = 0 are set to proper state and sends a broadcast AUTOMATION_COMPOSITION_DEPLOY message with startPhase = 1
207 - participant receives the AUTOMATION_COMPOSITION_DEPLOY message and runs to DEPLOYED state (only AC elements defined as startPhase = 1)
208 - runtime-ACM receives AUTOMATION_COMPOSITION_DEPLOY_ACK messages from participants and set the state (from the AC element of the message) to DEPLOYED
209 - runtime-ACM calculates that all AC elements are set to proper state and set AC to DEPLOYED
210
211 In that scenario the message AUTOMATION_COMPOSITION_DEPLOY has been sent two times.
212
213 Design of managing messages
214 ***************************
215
216 PARTICIPANT_REGISTER
217 ++++++++++++++++++++
218 - A participant starts and send a PARTICIPANT_REGISTER message with participantId and supported Element Types
219 - runtime-ACM collects the message from Message Broker by ParticipantRegisterListener
220 - if not present, it saves participant reference with status ON_LINE to DB
221
222 PARTICIPANT_PRIME_ACK
223 ++++++++++++++++++++++
224 - A participant sends PARTICIPANT_PRIME_ACK message in response to a PARTICIPANT_PRIME message
225 - ParticipantPrimeAckListener collects the message from Message Broker
226 - It updates AC Definition to DB with PRIMED/DEPRIMED as status
227
228 PARTICIPANT_STATUS
229 ++++++++++++++++++
230 - A participant sends a scheduled PARTICIPANT_STATUS message with participantId and supported Element Types
231 - runtime-ACM collects the message from Message Broker by ParticipantStatusListener
232 - if not present, it saves participant reference with status ON_LINE to DB
233 - MessageIntercept intercepts that event and adds a task to handle PARTICIPANT_STATUS in SupervisionScanner
234 - SupervisionScanner clears and starts the monitoring for participantStatus
235
236 AUTOMATION_COMPOSITION_DEPLOY_ACK
237 +++++++++++++++++++++++++++++++++
238 - A participant sends AUTOMATION_COMPOSITION_DEPLOY_ACK message in response to a AUTOMATION_COMPOSITION_DEPLOY message. It will send a AUTOMATION_COMPOSITION_DEPLOY_ACK - for each AC elements moved to the DEPLOYED state
239 - AutomationCompositionUpdateAckListener collects the message from Message Broker
240 - It checks the status of all Automation Composition elements and checks if the Automation Composition is fully DEPLOYED
241 - It updates the AC to DB
242 - MessageIntercept intercepts that event and adds a task to handle a monitoring execution in SupervisionScanner
243
244 AUTOMATION_COMPOSITION_STATECHANGE_ACK
245 ++++++++++++++++++++++++++++++++++++++
246 - A participant sends AUTOMATION_COMPOSITION_STATECHANGE_ACK message in response to a AUTOMATION_COMPOSITION_STATECHANGE message. It will send a AUTOMATION_COMPOSITION_DEPLOY_ACK - for each AC elements moved to the ordered state
247 - AutomationCompositionStateChangeAckListener collects the message from Message Broker
248 - It checks the status of all Automation Composition elements and checks if the transition process of the Automation Composition is terminated
249 - It updates the AC to DB
250 - MessageIntercept intercepts that event and adds a task to handle a monitoring execution in SupervisionScanner
251
252 Design of monitoring execution in SupervisionScanner
253 ****************************************************
254 Monitoring is designed to process the follow operations:
255
256 - to determine the next startPhase in a AUTOMATION_COMPOSITION_DEPLOY message
257 - to update AC deployState: in a scenario that "AutomationComposition.deployState" is in a kind of transitional state (example DEPLOYING), if all  - AC elements are moved properly to the specific state, the "AutomationComposition.deployState" will be updated to that and saved to DB
258 - to update AC lockState: in a scenario that "AutomationComposition.lockState" is in a kind of transitional state (example LOCKING), if all  - AC elements are moved properly to the specific state, the "AutomationComposition.lockState" will be updated to that and saved to DB
259 - to delete AC Instance: in a scenario that "AutomationComposition.deployState" is in DELETING, if all  - AC elements are moved properly to DELETED, the AC Instance will be deleted from DB
260 - to retry AUTOMATION_COMPOSITION_DEPLOY/AUTOMATION_COMPOSITION_STATE_CHANGE messages. if there is a AC Element not in the proper state, it will retry a broadcast message
261
262 The solution Design of retry, timeout, and reporting for all Participant message dialogues are implemented into the monitoring execution.
263
264 - Spring Scheduling inserts the task to monitor retry execution into ThreadPoolExecutor
265 - ThreadPoolExecutor executes the task
266 - a message will be retry if runtime-ACM do no receive Act message before MaxWaitMs milliseconds
267
268 Design of Exception handling
269 ****************************
270 GlobalControllerExceptionHandler
271 ++++++++++++++++++++++++++++++++
272 If error occurred during the Rest Api call, runtime-ACM responses with a proper status error code and a JSON message error.
273 This class is implemented to intercept and handle AutomationCompositionException, PfModelException and PfModelRuntimeException if they are thrown during the Rest Ali calls.
274 All of those classes must implement ErrorResponseInfo that contains message error and status response code.
275 So the Exception is converted in JSON message.
276
277 RuntimeErrorController
278 ++++++++++++++++++++++
279 If wrong end-point is called or an Exception not intercepted by GlobalControllerExceptionHandler, runtime-ACM responses with a proper status error code and a JSON message error.
280 This class is implemented to redirect the standard Web error page to a JSON message error.
281 Typically that happen when a wrong end-point is called, but also could be happen for not authorized call, or any other Exception not intercepted by GlobalControllerExceptionHandler.
282
283 Handle version and "X-ONAP-RequestID"
284 *************************************
285 RequestResponseLoggingFilter class handles version and "X-ONAP-RequestID" during a Rest-Api call; it works as a filter, so intercepts the Rest-Api and adds to the header those information.
286
287 Media Type Support
288 ******************
289 runtime-ACM Rest Api supports **application/json**, **application/yaml** and **text/plain** Media Types. The configuration is implemented in CoderHttpMesageConverter.
290
291 application/json
292 ++++++++++++++++
293 JSON format is a standard for Rest Api. For the conversion from JSON to Object and vice-versa will be used **org.onap.policy.common.utils.coder.StandardCoder**.
294
295 application/yaml
296 ++++++++++++++++
297 YAML format is a standard for Automation Composition Type Definition. For the conversion from YAML to Object and vice-versa will be used **org.onap.policy.common.utils.coder.StandardYamlCoder**.
298
299 text/plain
300 ++++++++++
301 Text format is used by Prometheus. For the conversion from Object to String  will be used **StringHttpMessageConverter**.