Add documentation for custom naming of TOSCA node types
[policy/parent.git] / docs / clamp / acm / acm-user-guide.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
3 .. Copyright (c) Nordix Foundation.  All rights reserved.
4
5 .. _acm-user-guide-label:
6
7 ACM user guide
8 ##############
9
10 .. contents::
11     :depth: 4
12
13 This guide helps the user to define their own composition definitions and explains the procedure to execute them via the
14 Clamp Automation Composition Management Framework. This guide briefly talks about the commissioning, instantiation and
15 deployment steps once the composition definitions are created.
16
17 Defining a composition
18 ======================
19
20 A composition can be created in yaml/json format as per the TOSCA standard. Please refer to the below section to understand
21 the Tosca fundamental concepts and how an Automation Composition definition can be realised in the TOSCA.
22
23
24 .. toctree::
25    :maxdepth: 2
26
27    defining-acms
28
29 HowTo: My First Automation Composition
30 ======================================
31
32 An example scenario is considered where we have a microservice that can be installed with a helm chart in kubernetes and
33 configured via REST api to perform some operation.This functionality can be realised as a composition in Tosca standard.
34 The various sections of the composition definition includes:
35
36 Data Types:
37 -----------
38 The user can define their own data types to be used in the composition definition. In this use case, we are defining three data types as follows.
39
40 onap.datatypes.ToscaConceptIdentifier:
41   This is a composite data type that holds two key value pairs in it. This type is used as an identifier for automation
42   element types and participant types.This holds two string properties "name" and "version" and hence this data type can
43   be used for creating the other composition element ids.
44
45 onap.datatypes.clamp.acm.httpAutomationCompositionElement.RestRequest:
46   The rest api request for configuring the microservice can use the RestRequest datatype for defining the request in TOSCA.
47   This holds the string properties "httpMethod", "path", "body" and an integer property "expectedResponse" for defining
48   the rest request.
49
50   Note that the "restRequestId" property which is of type "onap.datatypes.ToscaConceptIdentifier" that was defined in the
51   previous step.
52
53 onap.datatypes.clamp.acm.httpAutomationCompositionElement.ConfigurationEntity:
54   This data type holds a list of rest requests in case a microservice requires more than one rest request for configuration.
55   This holds the "configurationEntityId" which is of type "onap.datatypes.ToscaConceptIdentifier" and "restSequence" property
56   to hold the list of "onap.datatypes.clamp.acm.httpAutomationCompositionElement.RestRequest"
57
58
59 .. literalinclude:: files/acm-datatypes.yaml
60    :language: yaml
61
62
63 Node Types:
64 -----------
65 A Node Type is a reusable entity that defines the type of one or more Node Templates.
66 An Interface Type is a reusable entity that describes a set of operations that can be used to interact with or manage a
67 node or relationship in a TOSCA topology. The actual acm elements will be created under the Node templates deriving from
68 these node types. We are going to define the following element types for ACM:
69
70 org.onap.policy.clamp.acm.Participant:
71   This is a participant element type to define various participants in ACM. It holds the string property "provider".
72
73 org.onap.policy.clamp.acm.AutomationCompositionElement:
74   This node type defines the primitive Automation composition element type that includes various common properties for all
75   the ACM elements.
76   Here we are defining various timeout properties and startPhase parameter that are common for all the AC elements.
77
78   Note: This node type value can be customised if the user wants to change the default name. Please refer the
79         "Configure custom namings for TOSCA node types" section of the Automation Composition Runtime design and implementation.
80
81 org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement:
82   This node type is used to define AC elements that are associated with kubernetes operations. It is further derived from the
83   "org.onap.policy.clamp.acm.AutomationCompositionElement" type and hence supports its common properties and also includes
84   additional properties related to helm charts.
85   We are going to create kubernetes AC elements of this type, under the Node templates.
86
87 org.onap.policy.clamp.acm.HttpAutomationCompositionElement:
88   Node type for AC elements associated with REST operations. It is derived from the "org.onap.policy.clamp.acm.AutomationCompositionElement"
89   type and hence supports its common properties and also supports additional properties for REST operation.
90   We are going to create a REST AC element of this type, under the Node templates.
91
92 org.onap.policy.clamp.acm.AutomationComposition:
93   Primitive node type for defining Automation composition definitions that comprises one or more AC elements in it.
94   The AC definition of this type will be created under the Node templates.
95
96   Note: This node type value can be customised if the user wants to change the default name. Please refer the
97         "Configure custom namings for TOSCA node types" section of the Automation Composition Runtime design and implementation.
98
99 .. literalinclude:: files/acm-nodetypes.yaml
100    :language: yaml
101
102 Node Templates:
103 ---------------
104 A Node Template specifies the occurrence of a manageable software component as part of an application's topology model
105 which is defined in a TOSCA Service Template. We create the actual participants and AC elements involved in this use case
106 under the node templates.
107 There are no element properties supplied at this point since it will be provided by the user during the instantiation.
108
109 org.onap.k8s.acm.K8SAutomationCompositionParticipant:
110   A kubernetes participant element that processes the kubernetes AC elements in the composition.
111   This element is of node type "org.onap.policy.clamp.acm.Participant"
112
113 onap.policy.clamp.ac.element.K8S_AutomationCompositionElement:
114   An AC element for kubernetes helm chart installation of the microservice derived from the node type
115   "org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement".
116   The common element properties are provided with values as part of commissioning the definition.
117
118 org.onap.policy.clamp.acm.HttpParticipant:
119   A http participant element that processes the REST AC elements in the composition.
120   This element is of type "org.onap.policy.clamp.acm.Participant"
121
122 onap.policy.clamp.ac.element.Http_AutomationCompositionElement:
123  An AC element for REST operation in the microservice derived from the node type
124  "org.onap.policy.clamp.acm.HttpAutomationCompositionElement".
125  The common element properties startPhase and timeout are provided with values as part of commissioning the definition.
126
127 onap.policy.clamp.ac.element.AutomationCompositionDefinition:
128  The actual Automation Composition definition that comprises the list of AC elements mapped to it.
129  This element is of node type "org.onap.policy.clamp.acm.AutomationComposition"
130
131 .. literalinclude:: files/acm-nodetemplates.yaml
132    :language: yaml
133
134 Completed tosca template :download:`click here <files/acm-tosca.yaml>`
135
136 Once the Tosca template definition is created, the ACM workflow can be executed to create and deploy the compositions.
137 Please refer the following section for running ACM workflow.
138
139 ACM workflow
140 ============
141
142 ACM framework exposes REST interfaces for creating and deploying the user defined compositions. In this section, the
143 TOSCA template created in the previous step can be commissioned, and then AC instances can be created and deployed for
144 the same.
145
146 This section assumes that the user has read about the ACM APIs and Protocols documentation and understands the ACM
147 operations on a high level before proceeding with the workflow.
148
149
150 Prerequisites:
151   - ACM components including acm-runtime, required participants (http and kubernetes in this case) and Dmaap/kafka clients are deployed in docker or kubernetes environment.
152   - Kubernetes and Helm are installed.
153   - Chartmuseum server is installed to host the acelement microservice helm chart. (`Procedure to install chartmuseum <https://wiki.onap.org/display/DW/Microk8s+and+helm+setup+in+Ubuntu>`_.)
154   - The helm chart for ACM test microservice is available in the policy/clamp repository that can be cloned locally and uploaded to the chartmuseum using helm push.(`AC element helm chart <https://github.com/onap/policy-clamp/tree/master/examples/src/main/resources/clamp/acm/acelement-helm>`_.)
155
156 Please refer the `ACM swagger document <https://raw.githubusercontent.com/onap/policy-clamp/master/runtime-acm/src/main/resources/openapi/openapi.yaml>`_. for REST API information for all the ACM operations.
157 This section guides through the various steps involved in executing the ACM workflow for deploying the test microservice element.
158
159 Commissioning the AC definition
160 -------------------------------
161 Commissioning refers to storing the composition definition on the ACM database. The created tosca template is posted as a request payload.
162
163 .. code-block:: bash
164
165   Invoke a POST request 'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions'
166
167 This returns a 202 response on the successful creation of the composition definition.
168
169 Note:
170   The rest response returns the compositionId on a successful creation that requires to be used in the subsequent requests.
171
172 Prime AC definitions
173 --------------------
174 Priming associates the AC elements with suitable participants and sends the corresponding AC element information to the participants.
175
176 .. code-block:: bash
177
178   Invoke a PUT request 'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions/${compositionId}'
179
180 Request payload
181
182 .. literalinclude:: files/AC-priming.json
183    :language: json
184
185 This returns a 202 response on a successful priming.
186
187 Instantiate AutomationComposition
188 ---------------------------------
189 Instantiation refers to creating an AC instance on the database by initialising the element properties for each element in the composition.
190 These values requires to be provided by the user as per their use case requirement. In this case, we are passing the helm chart information
191 of the test microservice for the Ac element "onap.policy.clamp.ac.element.K8S_AutomationCompositionElement" which will be processed and installed
192 by the kubernetes participant on a deployment request.
193
194 Similarly the REST request data that are to be executed on the microservice will be passed on for the http AC element "onap.policy.clamp.ac.element.Http_AutomationCompositionElement"
195 which will be executed by the http participant. Please refer to the properties of the elements in the json payload.
196
197 Note:
198   In this scenario, the kubernetes element requires to be invoked first to install the helm chart and then the http element needs to be invoked to configure the microservice.
199   This is achieved by using the "startPhase" property on the AC element properties. The elements with the startPhase value defined are executed on a sequence starting from the least value to the higher value.
200   Each element in the request payload is assigned with a uniques UUID which will be automatically generated by the GUI in the upcoming releases.
201
202 .. code-block:: bash
203
204   Invoke a POST request
205   'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions/${compositionId}/instances'
206
207 The compositionId retrieved from the previous step should be updated in the request body. This returns a 201 response on a successful instantiation.
208 This also returns the instanceId in the response that can be used in the subsequent requests.
209
210 Request payload
211
212 .. literalinclude:: files/AC-instantiation.json
213    :language: json
214
215 Update AC instance properties (Optional)
216 ----------------------------------------
217 Before the AC instance is deployed, the user is allowed to update the instance property values if needed. The runtime updates these new values
218 in the database.
219
220 .. code-block:: bash
221
222   Invoke a POST request
223   'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions/${compositionId}/instances'
224
225 Request Payload
226
227 Example payload to update the base url of the http request
228
229 .. literalinclude:: files/AC-update.json
230    :language: json
231
232
233 Deploy AC instance
234 ------------------
235 Once the AC instance is created, the user can deploy the instance which in turn activates the corresponding participants to execute the intended operations.
236 In this case, the kubernetes participant will be installing the test microservice helm chart on the kubernetes cluster and the http participant will be
237 executing the REST requests on the microservice endpoints.
238
239 .. code-block:: bash
240
241   Invoke a PUT request
242   'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}'
243
244 This returns a 202 response on a successful deploy order request. The elements will be in "DEPLOYING" state until the completion and then the state of
245 the elements are updated to "DEPLOYED"
246 The current status of the deployment can be fetched through the following endpoint.
247
248 .. code-block:: bash
249
250   Invoke a GET request
251   'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}'
252
253 Request payload
254
255 .. literalinclude:: files/AC-deploy.json
256    :language: json
257
258 Note:
259   The user can further implement the admin states 'LOCK' and 'UNLOCK' on the participants to further cascade the deployment operations.
260   If these states are implemented, then a subsequent request to LOCK and UNLOCK requires to be triggered following the deployment.
261
262 Once all the AC elements are deployed, there should be a test microservice pod running on the kubernetes cluster which is
263 configured to send events on the kafka by the http participant. This can be verified on the test microservice application logs.
264 The AC instances can also be undeployed and deleted by the user.
265
266 Update AC instance properties after deployment (Optional)
267 ---------------------------------------------------------
268 After the AC instance is deployed, the user can still update the instance property values if needed. In this case, the runtime updates these new values
269 in the database and also sends an update event to the participants. The participants has to implement the update method to perform the
270 required operation.
271
272 .. code-block:: bash
273
274   Invoke a POST request
275   'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions/${compositionId}/instances'
276
277 Note:
278   Please refer the request payload section for updating the instance properties before deployment.
279
280 Migrate AC instance
281 -------------------
282 After the AC instance is deployed, the user can migrate it to other composition definition.
283 The target composition have to be primed and have to contain the same element definitions present in the source composition.
284 The user can update the instance property values if needed.
285
286 .. code-block:: bash
287
288   Invoke a POST request
289   'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions/${compositionId}/instances'
290
291 Request Payload
292
293 Example payload to migrate and update the base url of the http request
294
295 .. literalinclude:: files/AC-migrate.json
296    :language: json
297
298 UnDeploy AutomationComposition
299 ------------------------------
300 The AC instances can be undeployed from the system by the participants.
301
302 .. code-block:: bash
303
304   Invoke a PUT request
305   'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}'
306
307 This returns a 202 response on successful deploy order request.
308
309 Request payload
310
311 .. literalinclude:: files/AC-undeploy.json
312    :language: json
313
314 Uninstantiate AC instance
315 -------------------------
316 This deletes the AC instance from the database including all the element properties that are initialised.
317
318 .. code-block:: bash
319
320   Invoke a DELETE request
321   'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}'
322
323 This returns a 202 response on successful delete order request.
324
325 Deprime Ac defintions
326 ---------------------
327 Once the AC instance is deleted, it can be deprimed from the participants to be safely deleted from the database.
328
329 .. code-block:: bash
330
331   Invoke a PUT request 'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions/${compositionId}'
332
333 This returns a 202 response on a successful operation.
334
335 Request payload
336
337 .. literalinclude:: files/AC-depriming.json
338    :language: json
339
340 Delete AC defintion
341 -------------------
342 The AC definitions can be deleted if there are no instances are running and it is not primed to the participants.
343
344 .. code-block:: bash
345
346   Invoke a DELETE request 'http://policy_runtime_ip:port/onap/policy/clamp/acm/v2/compositions/${compositionId}'
347
348 This return a 200 response on a successful deletion operation.
349
350 Participant simulator
351 =====================
352 Participant simulator do not execute any particular functionality, and can be used to mock one or more participants in debug tests.
353 It should be used to test ACM-runtime and Participant Intermediary in specific scenario that could be difficult to replay in real environment.
354
355 Functionality covered:
356
357 #. Set participantId and supportedElementType by properties file or by parameter environment.
358 #. Set a delay for each operation at runtime by Rest-Api.
359 #. Set success or fail for each operation at runtime by Rest-Api.
360 #. update composition outProperties and send to ACM-runtime by Rest-Api.
361 #. read all AC Definition inProperties/outProperties information by Rest-Api.
362 #. update useState, operationalState and outProperties and send to ACM-runtime by Rest-Api.
363 #. read all AC instance elements information by Rest-Api.
364
365 Mock a participant using docker-compose
366 ---------------------------------------
367 The follow example show a docker-compose configuration to mock http Participant, where 'onap/policy-clamp-ac-sim-ppnt' is the Participant simulator image:
368
369 .. code-block:: yaml
370
371   http-participant:
372     image: onap/policy-clamp-ac-sim-ppnt
373     environment:
374       - participantId=101c62b3-8918-41b9-a747-d21eb79c6c01
375       - supportedElementTypeName=org.onap.policy.clamp.acm.HttpAutomationCompositionElement
376       - SERVER_SSL_ENABLED=false
377       - useHttps=false
378       - SERVER_PORT=8084
379     ports:
380       - "8084:8084"
381
382 Set delay and success/fail
383 --------------------------
384 Parameters like delay and success/fail could be set any time using the following endpoint:
385
386 .. code-block:: bash
387
388   Invoke a PUT request 'http://participant_sim_ip:port/onap/policy/clamp/acm/simparticipant/v2/parameters'
389
390 The Json below is an example of configuration:
391
392 .. code-block:: json
393
394   {
395     "deploySuccess": true,
396     "undeploySuccess": true,
397     "lockSuccess": true,
398     "unlockSuccess": true,
399     "deleteSuccess": true,
400     "updateSuccess": true,
401     "migrateSuccess": true,
402     "primeSuccess": true,
403     "deprimeSuccess": true,
404     "deployTimerMs": 1000,
405     "undeployTimerMs": 1000,
406     "migrateTimerMs": 100,
407     "lockTimerMs": 100,
408     "unlockTimerMs": 100,
409     "updateTimerMs": 100,
410     "deleteTimerMs": 100,
411     "primeTimerMs": 100,
412     "deprimeTimerMs": 100
413   }
414
415 Update and send composition outProperites
416 -----------------------------------------
417 Data like useState operationalState and outProperites could be updated any time using the following endpoint:
418
419 .. code-block:: bash
420
421   Invoke a PUT request 'http://participant_sim_ip:port/onap/policy/clamp/acm/simparticipant/v2/compositiondatas'
422
423 The Json below is an example of update, where {{compositionId}} is the UUID of the AC Definition
424 and ("onap.policy.clamp.ac.element.Http_BridgeAutomationCompositionElement", "1.2.3") is the ToscaConceptIdentifier  of the AC Definition element:
425
426 .. code-block:: json
427
428   {
429         "outProperties": {
430             "list": [
431                 {"id": 10 },
432                 {"id": 20 }
433             ]
434         },
435         "compositionId": "{{compositionId}}",
436         "compositionDefinitionElementId": {
437             "name": "onap.policy.clamp.ac.element.Http_BridgeAutomationCompositionElement",
438             "version": "1.2.3"
439         }
440   }
441
442 Read all AC Definition elements information
443 -------------------------------------------
444 All AC Definition elements information like composition inProperties and outProperties
445 could be read using the following endpoint:
446
447 .. code-block:: bash
448
449   Invoke a GET request 'http://participant_sim_ip:port/onap/policy/clamp/acm/simparticipant/v2/compositiondatas'
450
451 Update and send useState operationalState and instance outProperites
452 --------------------------------------------------------------------
453 Data like useState operationalState and outProperites could be updated any time using the following endpoint:
454
455 .. code-block:: bash
456
457   Invoke a PUT request 'http://participant_sim_ip:port/onap/policy/clamp/acm/simparticipant/v2/datas'
458
459 The Json below is an example of update, where {{instanceId}} is the UUID of the AC instance and {{instanceElementId}} is the UUID of the AC instance element:
460
461 .. code-block:: json
462
463   {
464         "outProperties": {
465             "Opresult": true,
466             "list": [
467                 {"id": 1 },
468                 {"id": 2 }
469             ]
470         },
471         "automationCompositionId": "{{instanceId}}",
472         "automationCompositionElementId": "{{instanceElementId}}",
473         "useState": "IDLE",
474         "operationalState": "ENABLED"
475   }
476
477 Read all AC instance elements information
478 -----------------------------------------
479 All AC instance elements information like deployState, lockState, useState, operationalState, inProperties and outProperties
480 could be read using the following endpoint:
481
482 .. code-block:: bash
483
484   Invoke a GET request 'http://participant_sim_ip:port/onap/policy/clamp/acm/simparticipant/v2/instances'