Make drools-pdp work with drools and java versions compatible
[policy/drools-applications.git] / controlloop / common / policy-yaml / README-v2.0.0.md
1 Copyright 2018 AT&T Intellectual Property. All rights reserved.
2 This file is licensed under the CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE
3 Full license text at https://creativecommons.org/licenses/by/4.0/legalcode
4
5 ONAP Control Loop Policy v2.0.0
6
7 A control loop policy is a YAML specification for creating and chaining policies for ControlLoop.
8
9 Features of ONAP Control Loop Policy v2.0.0:
10
11 * Backward compatible with ONAP Control Loop Policy v1.0.0
12 * A single DCAE Closed Loop Event is the trigger for the overall Control Loop Policy. 
13 * An overall timeout for the Control Loop Policy must be provided.
14 * An abatement flag indicating whether Policy will receive abatement event for the Control Loop could be provided.
15 * The Control Loop Policy can contain zero or more Operational Policies each chained together via outcomes of each policy.
16 * If there are zero Operational Policies, i.e. no automated action is to be taken, then the policy is an Open Loop policy.
17 * Operational policies can have target, retries and timeout's given to control how they are processed.
18 * Type and resourceID of the target could be provided to support the target in operational policies.
19 * Payload could be provided to support the recipe. 
20 * Multiple actors along with their supported recipes can be specified in operational policies that Policy will interact with. The following table summarizes the supported actors and recipes.
21
22 | Actor        | Recipe                      | Target   | Payload  |
23 | -------------|:---------------------------:| ---------| ------------:|
24 | APPC         | Restart                     | VM       | CloudVServerSelfLink, CloudIdentity |
25 | APPC         | Rebuild                     | VM       | CloudVServerSelfLink, CloudIdentity |
26 | APPC         | Migrate                                 | VM           | CloudVServerSelfLink, CloudIdentity |
27 | APPC         | ModifyConfig                            | VNF          | generic-vnf.vnf-id |
28 | SO           | VF Module Create                        | VFC          | optional |
29
30
31 This SDK helps build the YAML specification for ONAP Control Loop Policy v2.0.0.
32
33 # Create Builder Object
34
35 To begin with, the ControlLoopPolicyBuilder.Factory class has static methods that one should use to begin building a Control Loop Policy. It will return a [ControlLoopPolicyBuilder object](src/main/java/org/onap/policy/controlloop/policy/builder/ControlLoopPolicyBuilder.java) that can then be used to continue to build and define the Control Loop Policy.
36
37 ```java
38                 ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(
39                                 UUID.randomUUID().toString(), 
40                                 2400, 
41                                 new Resource("sampleResource", ResourceType.VF),
42                                 new Service("sampleService")
43                                 );
44 ```
45
46 # Define the Trigger Policy
47
48 After the name of the Control Loop and the resource and services have been defined, the next step would be to define the Operation Policy that is first to respond to an incoming DCAE Closed Loop Event. Use the setTriggerPolicy() method to do so.
49
50 ```java
51                 Policy triggerPolicy = builder.setTriggerPolicy(
52                                 "Restart the VM", 
53                                 "Upon getting the trigger event, restart the VM", 
54                                 "APPC", 
55                                 new Target(TargetType.VM), 
56                                 "Restart", 
57                                 null,
58                                 2, 
59                                 300);
60 ```
61
62 # Set the Abatement Flag for the Control Loop
63
64 After the trigger policy, the name, the resource(s) and services of the Control Loop have been defined, the next optional step would be to set the abatement flag that indicates whether DCAE will send Policy the abatement event for this Control Loop. If the abatement is not explicitly set, it is assumed that Policy will not receive the abatement event. Use the setAbatement() method to do so.
65
66 ```java 
67             builder = builder.setAbatement(false);
68 ```
69
70 # Chain Operational Policies Together Using Operational Results
71
72 Operational Policies are chained together using the results of each Operational Policy. The results are defined in [PolicyResult.java](src/main/java/org/onap/policy/controlloop/policy/PolicyResult.java). To create an Operational Policy that is tied to the result of another, use the 
73 setPolicyForPolicyResult() method.
74
75 ```java
76                 Policy onRestartFailurePolicy = builder.setPolicyForPolicyResult(
77                                 "Rebuild VM", 
78                                 "If the restart fails, rebuild it.", 
79                                 "APPC", 
80                                 new Target(TargetType.VM), 
81                                 "Rebuild", 
82                                 null,
83                                 1, 
84                                 600, 
85                                 triggerPolicy.id, 
86                                 PolicyResult.FAILURE,
87                                 PolicyResult.FAILURE_RETRIES,
88                                 PolicyResult.FAILURE_TIMEOUT,
89                                 PolicyResult.FAILURE_GUARD);
90 ```
91
92 An Operational Policy MUST have place to go for every one of its results. By default, each result type goes to a Final Result. Optionally, using the setPolicyForPolicyResult() method is what allows the chaining of policies. Be aware of creating loops and set the overall Control Loop timeout to reasonable value. All paths MUST lead to a Final Result.
93
94
95
96 # Build the YAML Specification
97
98 When finished defining the Policies, build the specification and analyze the [Results.java](src/main/java/org/onap/policy/controlloop/policy/builder/Results.java)
99
100 ```java
101                 Results results = builder.buildSpecification();
102                 if (results.isValid()) {
103                         System.out.println(results.getSpecification());
104                 } else {
105                         System.err.println("Builder failed");
106                         for (Message message : results.getMessages()) {
107                                 System.err.println(message.getMessage());
108                         }
109                 }
110 ```
111
112
113 # Use the YAML Specification to call the Create Policy API
114
115 Now that you have a valid YAML specification, call the createPolicy API via the ONAP Policy Platform API.
116
117
118 # YAML Specification
119
120 The YAML specification has 2 sections to it: [controlLoop](#controlloop-object) and [policies](#policies-array). The [controlLoop section](#controlloop-object) section is simply a header defining the Control Loop Policy, what services its for, which resource its for, or if its for a pnf, the overall timeout, the abatement flag, and which Operational Policy is triggered upon receiving the event. The [policies section](#policies-array) is simply an array of [Policy Objects](#policy-object).
121
122 ## controlLoop Object
123
124 | Field Name      | Type          | Required   | Description  |
125 | -------------   |:-------------:| -----------| ------------:|
126 | controlLoopName | string        | required | Unique ID for the control Loop |
127 | version         | string        | required | Value for this release if 1.0.0 |
128 | services        | array of [service](#service-object) objects | optional | Zero or more services associated with this Control Loop |
129 | resources        | array of [resource](#resource-object) object | required (If NOT a pnf control loop) | The resource's associated with this Control Loop. |
130 | pnf             | [pnf](#pnf-object) object | required (If NOT a resource control loop) | The physical network function associated with this Control Loop. |
131 | trigger_policy  | string     | required | Either this is the ID of an Operation Policy (see policy object), or "Final_OpenLoop" indicating an Open Loop |
132 | timeout         | int | required | This is the overall timeout for the Control Loop Policy. It can be 0 for an Open Loop, but otherwise should total more than the timeouts specified in any Operational Policies |
133 | abatement       | boolean       | optional | This is an abatement flag indicating if DCAE will send abatement event to Policy for this Control Loop |
134
135 ### resource Object
136
137 This object was derived via SDC Catalog API and SDC Data Dictionary (POC) in an attempt to use common naming conventions.
138
139 | Field Name      | Type          | Required   | Description  |
140 | -------------   |:-------------:| -----------| ------------:|
141 | resourceInvariantUUID | string - UUID | optional | via SDC, the unique ID for the resource version |
142 | resourceName | string | required if NO resourceUUID available | Name of the resource, ideally from SDC catalog. But if not available, use well-known name. |
143 | resourceType | string | optional | Use values defined by SDC: VF, VFC, VL, CP. |
144 | resourceUUID | string - UUID | required IF available, else populate resourceName | Unique ID for the resource as assigned via SDC.
145 | resourceVersion | string | optional | string version of the resource via SDC catalog
146
147
148 ### service Object
149
150 This object was derived via SDC Catalog API and SDC Data Dictionary (POC) in an attempt to use common naming conventions.
151
152 | Field Name      | Type          | Required   | Description  |
153 | ---------------:| -------------:| ----------:| ------------:|
154 | serviceInvariantUUID | string - UUID | optional | via SDC catalog, the unique ID for the service version |
155 | serviceName | string | required if NO serviceUUID available | Name of the service, ideally from SDC catalog. But if not available, use well-known name. |
156 | serviceUUID | string - UUID | required IF available, else populate serviceName | Unique ID fort he service as assigned via SDC
157 | serviceVersion | string | optional | string version of the service via SDC catalog
158     
159
160 ### pnf Object
161
162 This object is used for a physical network function. Expect this object to change in the future when ONAP Policy fully integrates with A&AI.
163
164 | Field Name      | Type          | Required   | Description  |
165 | -------------   |:-------------:| -----------| ------------:|
166 | PNFName         | string        | required   | Name of the PNF. Should be supplied via A&AI. If not available use a well-known name. |
167 | PNFType         | string        | optional   | Type of PNF if available. |
168
169
170 ## policies array
171
172 The policies section is an array of [Policy objects](#policy-object).
173
174 ### Policy Object
175
176 This is an Operation Policy. It is used to instruct an actor (eg. APPC) to invoke a recipe (eg. "Restart") on a target entity (eg. a "VM"). An operation is simply defined as performing a recipe (or operation) on an actor.
177
178 | Field Name      | Type          | Required   | Description  |
179 | -------------   |:-------------:| -----------| ------------:|
180 | id              | string        | required   | Unique ID for the policy.
181 | name            | string        | required   | Policy name |
182 | description     | string        | optional   | Policy description |
183 | actor           | string        | required   | Name of the actor for this operation: Example: APPC |
184 | recipe          | string        | required   | Name of recipe to be performed. Example "Restart" |
185 | target          | [target](#target-object) object        | required   | Entity being targeted. Example: VM |
186 | timeout         | int           | required   | Timeout for the actor to perform the recipe. |
187 | retry           | int           | optional   | Optional number of retries for ONAP Policy to invoke the recipe on the actor. |
188 | success         | string        | required   | By default, this value should be FINAL_SUCCESS. Otherwise this can be the ID of the operational Policy (included in this specification) to invoke upon successfully completing the recipe on the actor.
189 | failure         | string        | required   | By default, this value should be FINAL_FAILURE. Otherwise this can be the ID of the operational Policy (included in this specification) to invoke upon failure to perform the operation. |
190 | failure_exception | string      | required   | By default, this value should be FINAL_FAILURE_EXCEPTION. Otherwise this can be the ID of an Operational Policy (included in this specification) to invoke upon an exception occurring while attempting to perform the operation. |
191 | failure_retries | string        | required   | By default, this value should be the FINAL_FAILURE_RETRIES. Otherwise this can be the ID of an Operational Policy (included in this specification) to invoke upon maxing out on retries while attempting to perform the operation. |
192 | failure_timeout | string        | required   | By default, this value should be FINAL_FAILURE_TIMEOUT. Otherwise this can be the ID of the operational Policy (included in this specification) to invoke upon a timeout occuring while performing an operation. |
193 | failure_guard   | string        | required   | By default, this value should be FINAL_FAILURE_GUARD. Otherwise this can be the ID of the operational Policy (included in this specification) to invoke upon Guard denies this operation. |
194
195 Every Operational Policy MUST have a place to go for every possible result (success, failure, failure_retries, failure_timeout, failure_exception, failure_guard). By default, all the results are final results.
196   
197 #### target Object
198
199 This object is used for defining a target entity of a recipe.  
200
201 | Field Name      | Type          | Required   | Description  |
202 | -------------   |:-------------:| -----------| ------------:|
203 | type            | enums of VM, PNF and VNC | required   | Type of the target. |
204 | resourceID      | string        | optional   | Resource ID of the target. Should be supplied via SDC Catalog. |
205   
206   
207 ## Examples of YAML Control Loops v2.0.0
208
209 [vService](src/test/resources/v2.0.0/policy_vService.yaml)
210 [ONAP-vFirewall](src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml)
211 [ONAP-vDNS](src/test/resources/v2.0.0/policy_ONAP_demo_vDNS.yaml)
212
213 ### vService
214 ``` 
215 controlLoop:
216   version: 2.0.0
217   controlLoopName: ControlLoop-vService-cbed919f-2212-4ef7-8051-fe6308da1bda
218   services: 
219     - serviceName: service1
220   resources: 
221     - resourceName: resource1
222       resourceType: VFC
223     - resourceName: resource2
224       resourceType: VFC
225     - resourceName: resource3
226       resourceType: VFC
227     - resourceName: resource4
228       resourceType: VFC
229     - resourceName: resource5
230       resourceType: VFC
231   trigger_policy: unique-policy-id-1-restart
232   timeout: 1200
233   abatement: false
234
235 policies:
236   - id: unique-policy-id-1-restart
237     name: Restart Policy
238     description:
239     actor: APPC
240     recipe: Restart
241     target:
242       type: VM
243     retry: 2
244     timeout: 300
245     success: final_success
246     failure: unique-policy-id-2-rebuild
247     failure_timeout: unique-policy-id-2-rebuild
248     failure_retries: unique-policy-id-2-rebuild
249     failure_exception: final_failure_exception
250     failure_guard: unique-policy-id-2-rebuild
251   
252   - id: unique-policy-id-2-rebuild
253     name: Rebuild Policy
254     description:
255     actor: APPC
256     recipe: Rebuild
257     target:
258       type: VM 
259     retry: 0
260     timeout: 600
261     success: final_success
262     failure: unique-policy-id-3-migrate
263     failure_timeout: unique-policy-id-3-migrate
264     failure_retries: unique-policy-id-3-migrate
265     failure_exception: final_failure_exception
266     failure_guard: unique-policy-id-3-migrate
267   
268   - id: unique-policy-id-3-migrate
269     name: Migrate Policy
270     description:
271     actor: APPC
272     recipe: Migrate
273     target: 
274       type: VM
275     retry: 0
276     timeout: 600
277     success: final_success
278     failure: final_failure
279     failure_timeout: final_failure_timeout
280     failure_retries: final_failure_retries
281     failure_exception: final_failure_exception
282     failure_guard: final_failure_guard
283 ```
284
285
286
287 ### ONAP vFirewall
288 ```
289 controlLoop:
290   version: 2.0.0
291   controlLoopName: ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a
292   services: 
293     - serviceInvariantUUID: 5cfe6f4a-41bc-4247-8674-ebd4b98e35cc
294       serviceUUID: 0f40bba5-986e-4b3c-803f-ddd1b7b25f24
295       serviceName: 57e66ea7-0ed6-45c7-970f
296   trigger_policy: unique-policy-id-1-modifyConfig
297   timeout: 1200
298
299 policies:
300   - id: unique-policy-id-1-modifyConfig
301     name: Change the Load Balancer
302     description:
303     actor: APPC
304     recipe: ModifyConfig
305     target:
306       resourceID: Eace933104d443b496b8.nodes.heat.vpg
307     payload:
308       generic-vnf.vnf-id: {generic-vnf.vnf-id}
309       ref$: pgstreams.json
310     retry: 0
311     timeout: 300
312     success: final_success
313     failure: final_failure
314     failure_timeout: final_failure_timeout
315     failure_retries: final_failure_retries
316     failure_exception: final_failure_exception
317     failure_guard: final_failure_guard
318 ```
319
320 ### ONAP vDNS
321 ```
322 controlLoop:
323   version: 2.0.0
324   controlLoopName: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3
325   services: 
326     - serviceName: d4738992-6497-4dca-9db9
327       serviceInvariantUUID: dc112d6e-7e73-4777-9c6f-1a7fb5fd1b6f
328       serviceUUID: 2eea06c6-e1d3-4c3a-b9c4-478c506eeedf
329   trigger_policy: unique-policy-id-1-scale-up
330   timeout: 1200
331
332 policies:
333   - id: unique-policy-id-1-scale-up
334     name: Create a new VF Module
335     description:
336     actor: SO
337     recipe: VF Module Create
338     target:
339       resourceID: 59a2ee3fB58045feB5a1.nodes.heat.vdns
340     retry: 0
341     timeout: 1200
342     success: final_success
343     failure: final_failure
344     failure_timeout: final_failure_timeout
345     failure_retries: final_failure_retries
346     failure_exception: final_failure_exception
347     failure_guard: final_failure_guard
348 ```
349
350
351 # Control Loop Final Results Explained
352
353 A Control Loop Policy has the following set of final results, as defined in [FinalResult.java](src/main/java/org/onap/policy/controlloop/policy/FinalResult.java). A final result indicates when a Control Loop Policy has finished execution and is finished processing a Closed Loop Event. All paths must lead to a Final Result.
354