dd6348c835da293f2ba2c63d19d70e7781067c52
[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 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
82 Issues AC instance to change status
83 +++++++++++++++++++++++++++++++++++
84
85 case **deployOrder: DEPLOY**
86
87 - GUI calls "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances/{instanceId}" endpoint with DEPLOY as deployOrder
88 - runtime-ACM receives the call by Rest-Api (InstantiationController)
89 - It validates the status order issued (related AC Instance has UNDEPLOYED as deployState)
90 - It updates the AC Instance to DB with DEPLOYING deployState
91 - It triggers the execution to send a broadcast AUTOMATION_COMPOSITION_DEPLOY message
92 - the message is built by AutomationCompositionDeployPublisher using Tosca Service Template data and Instance data. (with startPhase = first startPhase)
93
94 case **lockOrder: UNLOCK**
95
96 - GUI calls "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances/{instanceId}" endpoint with UNLOCK as lockOrder
97 - runtime-ACM receives the call by Rest-Api (InstantiationController)
98 - It validates the status order issued (related AC Instance has DEPLOYED as deployState and LOCK as lockOrder)
99 - It updates the AC Instance to DB with LOCKING lockOrder
100 - It triggers the execution to send a broadcast AUTOMATION_COMPOSITION_STATE_CHANGE message
101 - the message is built by AutomationCompositionStateChangePublisher using Instance data. (with startPhase = first startPhase)
102
103 case **lockOrder: LOCK**
104
105 - GUI calls "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances/{instanceId}" endpoint with LOCK as lockOrder
106 - runtime-ACM receives the call by Rest-Api (InstantiationController)
107 - It validates the status order issued (related AC Instance has DEPLOYED as deployState and UNLOCK as lockOrder)
108 - It updates the AC Instance to DB with UNLOCKING lockOrder
109 - It triggers the execution to send a broadcast AUTOMATION_COMPOSITION_STATE_CHANGE message
110 - the message is built by AutomationCompositionStateChangePublisher using Instance data. (with startPhase = last StartPhase)
111
112 case **deployOrder: UNDEPLOY**
113
114 - GUI calls "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances/{instanceId}" endpoint with UNDEPLOY as deployOrder
115 - runtime-ACM receives the call by Rest-Api (InstantiationController)
116 - It validates the status order issued (related AC Instance has DEPLOYED as deployState and LOCK as lockOrder)
117 - It updates the AC Instance to DB with UNDEPLOYING deployState
118 - It triggers the execution to send a broadcast AUTOMATION_COMPOSITION_STATE_CHANGE message
119 - the message is built by AutomationCompositionStateChangePublisher using Instance data. (with startPhase = last StartPhase)
120
121 Delete of a Automation Composition Instance
122 +++++++++++++++++++++++++++++++++++++++++++
123 - GUI calls DELETE "/onap/policy/clamp/acm/v2/compositions/{compositionId}/instances/{instanceId}" endpoint
124 - runtime-ACM receives the call by Rest-Api (InstantiationController)
125 - It checks that AC Instance is in UNDEPLOYED deployState
126 - It updates the AC Instance to DB with DELETING deployState
127 - It triggers the execution to send a broadcast AUTOMATION_COMPOSITION_STATE_CHANGE message
128 - the message is built by AutomationCompositionStateChangePublisher using Instance data. (with startPhase = last StartPhase)
129
130 Depriming of a Automation Composition Definition Type
131 +++++++++++++++++++++++++++++++++++++++++++++++++++++
132 - GUI calls POST "/onap/policy/clamp/acm/v2/compositions/{compositionId}" endpoint with DEPRIME as primeOrder
133 - runtime-ACM receives the call by Rest-Api (CommissioningController)
134 - It checks that Automation Composition Type Definition is in PRIMED status
135 - It updates AC Definition to DB with DEPRIMING as status
136 - It triggers the execution to send a broadcast PARTICIPANT_PRIME message
137 - the message is built by ParticipantPrimePublisher using Tosca Service Template data
138
139 Delete of a Automation Composition Definition Type
140 ++++++++++++++++++++++++++++++++++++++++++++++++++
141 - GUI calls DELETE "/onap/policy/clamp/acm/v2/compositions/{compositionId}" endpoint
142 - runtime-ACM receives the call by Rest-Api (CommissioningController)
143 - It checks that AC Definition Type is in COMMISSIONED status
144 - It deletes the Automation Composition Type from DB
145
146 StartPhase
147 **********
148 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.
149
150 How to define StartPhase
151 ++++++++++++++++++++++++
152 StartPhase is defined as shown below in the Definition of TOSCA fundamental Automation Composition Types yaml file.
153
154 .. code-block:: YAML
155
156   startPhase:
157     type: integer
158     required: false
159     constraints:
160     - greater-or-equal: 0
161     description: A value indicating the start phase in which this Automation Composition element will be started, the
162                  first start phase is zero. Automation Composition Elements are started in their start_phase order and stopped
163                  in reverse start phase order. Automation Composition Elements with the same start phase are started and
164                  stopped simultaneously
165     metadata:
166       common: true
167
168 The "common: true" value in the metadata of the startPhase property identifies that property as being a common property.
169 This property will be set on the CLAMP GUI during Automation Composition commissioning.
170 Example where it could be used:
171
172 .. code-block:: YAML
173
174   org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement:
175     # Consul http config for PMSH.
176     version: 1.2.3
177     type: org.onap.policy.clamp.acm.HttpAutomationCompositionElement
178     type_version: 1.0.1
179     description: Automation Composition element for the http requests of PMSH microservice
180     properties:
181       provider: ONAP
182       uninitializedToPassiveTimeout: 180
183       startPhase: 1
184
185 How StartPhase works
186 ++++++++++++++++++++
187 In state changes from UNDEPLOYED → DEPLOYED or LOCKED → UNLOCKED, Automation Composition elements are started in increasing order of their startPhase.
188
189 Example of DEPLOY order with Http_PMSHMicroserviceAutomationCompositionElement with startPhase to 1 and PMSH_K8SMicroserviceAutomationCompositionElement with startPhase to 0
190
191 - runtime-ACM sends a broadcast AUTOMATION_COMPOSITION_DEPLOY message to all participants with startPhase = 0
192 - participant receives the AUTOMATION_COMPOSITION_DEPLOY message and runs to DEPLOYED state (only AC elements defined as startPhase = 0)
193 - runtime-ACM receives AUTOMATION_COMPOSITION_DEPLOY_ACK messages from participants and set the state (from the AC element of the message) to DEPLOYED
194 - 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
195 - participant receives the AUTOMATION_COMPOSITION_DEPLOY message and runs to DEPLOYED state (only AC elements defined as startPhase = 1)
196 - runtime-ACM receives AUTOMATION_COMPOSITION_DEPLOY_ACK messages from participants and set the state (from the AC element of the message) to DEPLOYED
197 - runtime-ACM calculates that all AC elements are set to proper state and set AC to DEPLOYED
198
199 In that scenario the message AUTOMATION_COMPOSITION_DEPLOY has been sent two times.
200
201 Design of managing messages
202 ***************************
203
204 PARTICIPANT_REGISTER
205 ++++++++++++++++++++
206 - A participant starts and send a PARTICIPANT_REGISTER message with participantId and supported Element Types
207 - runtime-ACM collects the message from Message Broker by ParticipantRegisterListener
208 - if not present, it saves participant reference with status ON_LINE to DB
209
210 PARTICIPANT_PRIME_ACK
211 ++++++++++++++++++++++
212 - A participant sends PARTICIPANT_PRIME_ACK message in response to a PARTICIPANT_PRIME message
213 - ParticipantPrimeAckListener collects the message from Message Broker
214 - It updates AC Definition to DB with PRIMED/DEPRIMED as status
215
216 PARTICIPANT_STATUS
217 ++++++++++++++++++
218 - A participant sends a scheduled PARTICIPANT_STATUS message with participantId and supported Element Types
219 - runtime-ACM collects the message from Message Broker by ParticipantStatusListener
220 - if not present, it saves participant reference with status ON_LINE to DB
221 - MessageIntercept intercepts that event and adds a task to handle PARTICIPANT_STATUS in SupervisionScanner
222 - SupervisionScanner clears and starts the monitoring for participantStatus
223
224 AUTOMATION_COMPOSITION_DEPLOY_ACK
225 +++++++++++++++++++++++++++++++++
226 - 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
227 - AutomationCompositionUpdateAckListener collects the message from Message Broker
228 - It checks the status of all Automation Composition elements and checks if the Automation Composition is fully DEPLOYED
229 - It updates the AC to DB
230 - MessageIntercept intercepts that event and adds a task to handle a monitoring execution in SupervisionScanner
231
232 AUTOMATION_COMPOSITION_STATECHANGE_ACK
233 ++++++++++++++++++++++++++++++++++++++
234 - 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
235 - AutomationCompositionStateChangeAckListener collects the message from Message Broker
236 - It checks the status of all Automation Composition elements and checks if the transition process of the Automation Composition is terminated
237 - It updates the AC to DB
238 - MessageIntercept intercepts that event and adds a task to handle a monitoring execution in SupervisionScanner
239
240 Design of monitoring execution in SupervisionScanner
241 ****************************************************
242 Monitoring is designed to process the follow operations:
243
244 - to determine the next startPhase in a AUTOMATION_COMPOSITION_DEPLOY message
245 - 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
246 - 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
247 - 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
248 - 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
249
250 The solution Design of retry, timeout, and reporting for all Participant message dialogues are implemented into the monitoring execution.
251
252 - Spring Scheduling inserts the task to monitor retry execution into ThreadPoolExecutor
253 - ThreadPoolExecutor executes the task
254 - a message will be retry if runtime-ACM do no receive Act message before MaxWaitMs milliseconds
255
256 Design of Exception handling
257 ****************************
258 GlobalControllerExceptionHandler
259 ++++++++++++++++++++++++++++++++
260 If error occurred during the Rest Api call, runtime-ACM responses with a proper status error code and a JSON message error.
261 This class is implemented to intercept and handle AutomationCompositionException, PfModelException and PfModelRuntimeException if they are thrown during the Rest Ali calls.
262 All of those classes must implement ErrorResponseInfo that contains message error and status response code.
263 So the Exception is converted in JSON message.
264
265 RuntimeErrorController
266 ++++++++++++++++++++++
267 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.
268 This class is implemented to redirect the standard Web error page to a JSON message error.
269 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.
270
271 Handle version and "X-ONAP-RequestID"
272 *************************************
273 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.
274
275 Media Type Support
276 ******************
277 runtime-ACM Rest Api supports **application/json**, **application/yaml** and **text/plain** Media Types. The configuration is implemented in CoderHttpMesageConverter.
278
279 application/json
280 ++++++++++++++++
281 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**.
282
283 application/yaml
284 ++++++++++++++++
285 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**.
286
287 text/plain
288 ++++++++++
289 Text format is used by Prometheus. For the conversion from Object to String  will be used **StringHttpMessageConverter**.