71a646ddfae3651a43db2f3021fb272230acf9c6
[policy/parent.git] / docs / clamp / controlloop / defining-controlloops.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2
3 .. _defining-controlloops-label:
4
5 Defining Control Loops in TOSCA for CLAMP
6 #########################################
7
8
9 .. contents::
10     :depth: 4
11
12
13 A Control Loop Type is defined in a TOSCA service template. A TOSCA Service Template has
14 two parts: a definition part in the service template itself, which contains the definitions
15 of concepts that can be used to define the types of concepts that can appear on a Toplogy
16 Template and a Topology Template that defines a topology. See the `Oasis Open TOSCA
17 <https://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.3/>`_ web page
18 for more details on TOSCA.
19
20 Unsurprisingly, to define a Control Loop Type in TOSCA, of Control Loop related concepts
21 that we can use in all control loops exist. They are described in Section 1. Section 2
22 describes how properties are managed. Properties are the configuration parameters that are
23 provided to Control Loops and the Control Loop Elements they use. Section 3 describes how to
24 define a Control Loop using the predefined Control Loop concepts.
25
26
27 1 Standard TOSCA Service Template Concepts for Control Loops
28 ============================================================
29
30 These concepts are the base concepts available to users who write definitions for control
31 loops in TOSCA. TOSCA control loop definitions are written using these concepts.
32
33 1.1 Fundamental TOSCA Concepts for Control Loops
34 ------------------------------------------------
35
36 The following TOSCA concepts are the fundamental concepts in a TOSCA Service Template for
37 defining control loops.
38
39 .. image:: images/defining-controlloops/fundamental-concepts.png
40
41 The TOSCA concepts above may be declared in the TOSCA Service Template of a control loop.
42 If the concepts already exist in the Design Time Catalogue or the Runtime Inventory, they
43 may be omitted from a TOSCA service template that defines a control loop type.
44
45 The *start_phase* is a value indicating the start phase in which this control loop element
46 will be started, the first start phase is zero. Control Loop Elements are started in their
47 start_phase order and stopped in reverse start phase order. Control Loop Elements with the
48 same start phase are started and stopped simultaneously.
49
50 The Yaml file that holds the Definition of `TOSCA fundamental Control Loop Types is available in Github
51 <https://github.com/onap/policy-clamp/blob/master/common/src/main/resources/tosca/ControlLoopTOSCAServiceTemplateTypes.yaml>`_
52 and is the canonical definition of the Control Loop concepts.
53
54 1.2 TOSCA Concepts for Control Loop Elements delivered by ONAP
55 --------------------------------------------------------------
56
57 TOSCA Standard Control Loop Elements
58
59 .. image:: images/defining-controlloops/standard-cle.png
60
61 1.2.1 Policy Control Loop Element
62 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63
64 The Policy Participant runs Policy Control Loop Elements. Each Policy Control Loop Element
65 manages the deployment of the policy specified in the Policy Control Loop Element definition.
66 The Yaml file that holds the `Policy Control Loop Element Type definition is available in Github
67 <https://github.com/onap/policy-clamp/blob/master/common/src/main/resources/tosca/PolicyControlLoopElementType.yaml>`_
68 and is the canonical definition of the Policy Control Loop Element type. For a description of
69 the Policy Control Loop Element and Policy Participant, please see `The CLAMP Policy Framework
70 Participant <#>`_ page.
71
72 1.2.2 HTTP Control Loop Element
73 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74
75 The HTTP Participant runs HTTP Control Loop Elements. Each HTTP Control Loop Element manages
76 REST communication towards a REST endpoint using the REST calls a user has specified in the
77 configuration of the HTTP Control Loop Element. The Yaml file that holds the
78 `HTTP Control Loop Element Type definition is available in Github
79 <https://github.com/onap/policy-clamp/blob/master/common/src/main/resources/tosca/HttpControlLoopElementType.yaml>`_
80 and is the canonical definition of the HTTP Control Loop Element type. For a description of
81 the HTTP Control Loop Element and HTTP Participant, please see `The CLAMP HTTP Participant <#>`_ page.
82
83 .. _kubernetes-cl-element:
84
85 1.2.3 Kubernetes Control Loop Element
86 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87
88 The Kubernetes Participant runs Kubernetes Control Loop Elements. Each Kubernetes Control Loop
89 Element manages a Kubernetes microservice using Helm. The user defines the Helm chart for the
90 Kubernetes microservice as well as other properties that the microservice requires in order to
91 execute. The Yaml file that holds the
92 `Kubernetes Control Loop Element Type defintion is available in Github
93 <https://github.com/onap/policy-clamp/blob/master/common/src/main/resources/tosca/KubernetesControlLoopElementType.yaml>`_
94 and is the canonical definition of the Kubernetes Control Loop Element type. For a description
95 of the Kubernetes Control Loop Element and Kubernetes Participant,please see
96 `The CLAMP Kubernetes Participant <#>`_ page.
97
98 1.2.4 CDS Control Loop Element
99 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100
101 The CDS Participant runs CDS Control Loop Elements. Each CDS Control Loop Element manages the
102 deployment of the CDS blueprint specified in the CDS Control Loop Element definition. The Yaml
103 file that holds the `CDS Control Loop Element Type definition is available in Github
104 <https://github.com/onap/policy-clamp/blob/master/common/src/main/resources/tosca/CdsControlLoopElementType.yaml>`_
105 and is the canonical definition of the CDS Control Loop Element type. For a description of the
106 CDS Control Loop Element and CDS Participant, please see `The CLAMP CDS Participant page <#>`_.
107
108 1.2.5 DCAE Participant
109 ~~~~~~~~~~~~~~~~~~~~~~
110
111 The DCAE Participant runs DCAE Control Loop Elements. Each DCAE Control Loop Element manages
112 a DCAE microservice on DCAE. The user defines the DCAE blueprint for the DCAE microservice as
113 well as other properties that the microservice requires in order to execute. The Yaml file that
114 holds the `DCAE Control Loop Type definition is available in Github
115 <https://github.com/onap/policy-clamp/blob/master/common/src/main/resources/tosca/DcaeControlLoopElementType.yaml>`_
116 and is the canonical definition of the DCAE Control Loop Element type. For a description of
117 the DCAE Control Loop Element and DCAE Participant, please see `The CLAMP DCAE Participant <#>`_ page.
118
119
120 2 Common and Instance Specific Properties
121 =========================================
122
123 Properties are used to define the configuration for Control Loops and Control Loop Elements.
124 At design time, the types, constraints, and descriptions of the properties are specified.
125 The values for properties are specified in the CLAMP GUI at runtime. TOSCA provides support
126 for defining properties, see `Section 3.6.10: TOSCA Property Definition
127 <https://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.3/os/TOSCA-Simple-Profile-YAML-v1.3-os.html#DEFN_ELEMENT_PROPERTY_DEFN>`_
128 in the TOSCA documentation.
129
130 2.1 Terminology for Properties
131 ------------------------------
132
133 **Property:** Metadata defined in TOSCA that is associated with a Control Loop, a Control
134 Loop Element, or a Participant.
135
136 **TOSCA Property Type:** The TOSCA definition of the type of a property. A property can have
137 a generic type such as string or integer or can have a user defined TOSCA data type.
138
139 **TOSCA Property Value:** The value of a Property Type. Property values are assigned at run
140 time in CLAMP.
141
142 **Common Property Type:** Property Types that apply to all instances of a Control Loop Type.
143
144 **Common Property Value:** The value of a Property Type. It is assigned at run time once for
145 all instances of a Control Loop Type.
146
147 **Instance Specific Property Type:** Property Types that apply to an individual instance of
148 a Control Loop Type.
149
150 **Instance Specific Property Value:** The value of a Property Type that applies to an
151 individual instance of a Control Loop Type. The value is assigned at run time for each
152 control loop instance.
153
154 Control Loop Properties can be *common* or *instance specific*. See Section 2 of
155 :ref:`TOSCA Defined Control Loops: Architecture and Design <controlloop-capabilities>`
156 for a detailed description of the usage of common and instance specific properties.
157
158 2.2 Common Properties
159 ---------------------
160
161 Common properties apply to all instances of a control loop. Common properties are identified
162 by a special metadata flag in Control Loop and Control Loop Element definitions. For example,
163 the startPhase parameter on any Control Loop Element has the same value for any instance of
164 that control loop element, so it is defined as shown below in the
165 `Definition of TOSCA fundamental Control Loop Types
166 <https://github.com/onap/policy-clamp/blob/master/common/src/main/resources/tosca/ControlLoopTOSCAServiceTemplateTypes.yaml>`_
167 yaml file.
168
169 .. code-block:: yaml
170
171     startPhase:
172       type: integer
173       required: false
174       constraints:
175       - greater-or-equal: 0
176       description: A value indicating the start phase in which this control loop element will be started, the
177                   first start phase is zero. Control Loop Elements are started in their start_phase order and stopped
178                   in reverse start phase order. Control Loop Elements with the same start phase are started and
179                   stopped simultaneously
180       metadata:
181         common: true
182
183 The "common: true" value in the metadata of the startPhase property identifies that property
184 as being a common property. This property will be set on the CLAMP GUI during control loop
185 commissioning.
186
187 2.3 Instance Specific Properties
188 --------------------------------
189
190 Instance Specific  properties apply to individual instances of a Control Loop and/or Control
191 Loop Element and must be set individually for Control Loop and Control Loop Element instance.
192 Properties are instance specific by default, but can be identified by a special metadata flag
193 in Control Loop and Control Loop Element definitions. For example, the chart parameter on a
194 Kubernetes Control Loop Element has a different value for every instance of a Kubernetes Control
195 Loop Element, so it can be defined as shown below in the :ref:`Kubernetes Control Loop Type definition
196 <kubernetes-cl-element>` yaml file.
197
198
199 .. code-block:: yaml
200
201     # Definition that omits the common flag metadata
202     chart:
203       type: org.onap.datatypes.policy.clamp.controlloop.kubernetesControlLoopElement.Chart
204       typeVersion: 1.0.0
205       description: The helm chart for the microservice
206       required: true
207     
208     # Definition that specifies the common flag metadata
209     chart:
210       type: org.onap.datatypes.policy.clamp.controlloop.kubernetesControlLoopElement.Chart
211       typeVersion: 1.0.0
212       description: The helm chart for the microservice
213       required: true
214       metadata:
215         common: false
216
217 The "common: false" value in the metadata of the chart property identifies that property as
218 being an instance specific property. This property will be set on the CLAMP GUI during control
219 loop instantiation.
220
221
222 3 Writing a Control Loop Type Definition
223 =========================================
224
225 The TOSCA definition of a control loop contains a TOSCA Node Template for the control loop
226 itself, which contains TOSCA Node Templates for each Control Loop Element that makes up the
227 Control Loop.
228
229 .. image:: images/defining-controlloops/controlloop-node-template.png
230
231 To create a control loop, a user creates a TOSCA Topology Template. In the Topology Template,
232 the user creates a TOSCA Node Template for each Control Loop Element that will be in the
233 Control Loop Definition. Finally, the user creates the Node Template that defines the Control
234 Loop itself, and references the Control Loop Element definitions that make up the Control Loop
235 Definition.
236
237 3.1 The Gentle Guidance Control Loop
238 ------------------------------------
239
240 The best way to explain how to create a Control Loop Definition is by example.
241
242 .. image:: images/defining-controlloops/gentle-guidance-controlloop.png
243
244 The example Gentle Guidance control loop is illustrated in the diagram above. The domain logic
245 for the control loop is implemented in a microservice running in Kubernetes, a policy, a CDS
246 blueprint, and some configuration that is passed to the microservice over a REST endpoint.
247 We want to manage the life cycle of the domain logic for our Gentle Guidance control loop using
248 our TOSCA based Control Loop Life Cycle Management approach. To do this we create four Control
249 Loop Element definitions, one for the Kubernetes microservice, one for the policy, one for the
250 CDS blueprint and one or the REST configuration.
251
252 3.2 The TOSCA Control Loop Definition
253 -------------------------------------
254
255 We use a TOSCA Topology Template to specify a Control Loop definition and the definitions of
256 its Control Loop Elements. Optionally, we can specify default parameter values in the TOSCA
257 Topology Template. The actual values of Control Loop common and instance specific parameters
258 are set at run time in the CLAMP GUI.
259
260 In the case of the Gentle Guidance control loop, we define a Control Loop Element Node Template
261 for each part of the domain logic we are managing. We then define the Control Loop Node Template
262 for the control loop itself.
263
264 Please refer to the `No Properties yaml file in Github
265 <https://github.com/onap/policy-clamp/blob/master/common/src/test/resources/gentleguidance/GentleGuidanceNoPropeties.yaml>`_
266 for the definitive Yaml specification for the TOSCA Topology Template for the Gentle Guidance
267 domain when no parameters are defined.
268
269 Please refer to the `Default Properties yaml file in Github
270 <https://github.com/onap/policy-clamp/blob/master/common/src/test/resources/gentleguidance/GentleGuidanceDefaultPropeties.yaml>`_
271 for the definitive Yaml specification for the TOSCA Topology Template for the Gentle Guidance
272 domain when the default values of parameters are defined.
273
274
275 4 Creating Custom Control Loop Elements
276 ========================================
277
278 Any organization can include their own component in the framework and use the framework and have
279 the Policy Framework CLAMP manage the lifecycle of domain logic in their component as part of a
280 Control Loop. To do this, a participant for the component must be developed that allows Control
281 Loop Elements for that component to be run. To develop a participant, the participant must comply
282 with the `CLAMP Participants <#>`_
283 framework and in particular comply with `The CLAMP Control Loop Participant Protocol <#>`_.
284 The organization must also specify a new Control Loop Element type definition in TOSCA similar to
285 those supplied in ONAP and described in Section 1.2. This Control Loop Element type tells the
286 CLAMP Control Loop Lifecycle management that the Control Loop Element exists and can be included
287 in control loops. It also specifies the properties that can be specified for the Control Loop Element.
288
289 An organization can supply the code for the Participant (for example as a Java jar file) and a
290 TOSCA artifact with the Control Loop Element definition and it can be added to the platform. In
291 future releases, support will be provided to include participants and their Control Loop Element
292 definitions as packaged plugins that can be installed on the platform.
293
294 End of document