[POLICY-76] Remove/rename ATT internal stuffs
[policy/drools-applications.git] / controlloop / common / policy-yaml / README-guard-v2.0.0.md
1 ONAP Control Loop Guard
2
3 A control loop guard is a YAML specification for creating policy guard for ControlLoop.
4
5 ONAP Control Loop Guard Features:
6
7 * The Control Loop Guard can specify the frequency limiter and the blacklist of target entities but not both in the same Guard.
8 * Two parts are incorporated. One is the common guard header including guard version while the other part is a set of guard policies. 
9 * The Control Loop Guard should contain at least one guard policies.
10 * Each guard policy is bound to a specific Actor and Recipe.
11 * Each guard policy should have at least one limit constraints which define how the guard policy should be enforced.
12 * Supported Actors are APPC and SO. 
13
14 This SDK helps build the YAML specification for ONAP Control Loop Guard.
15
16 # Create Builder Object
17
18 To begin with, the ControlLoopGuardBuilder.Factory class has static methods that one should use to begin building a Control Loop Guard. It will return a [ControlLoopGuardBuilder object](src/main/java/org/onap/policy/controlloop/policy/guard/builder/ControlLoopGuardBuilder.java) that can then be used to continue to build and define the Control Loop Guard.
19
20 ```java
21                 ControlLoopGuardBuilder builder = ControlLoopGuardBuilder.Factory.buildControlLoopGuard(new Guard());
22 ```
23
24 # Add Guard Policy
25
26 After a guard builder has been created, the next step would be to add a guard policy to the newly created Control Loop Guard via the builder. To add a guard policy, use the addGuardPolicy() method.
27
28 ```java
29                 GuardPolicy policy = new GuardPolicy(
30                                                                 "unique_guard_vUSP_1", 
31                                                                 "APPC 5 Restart", 
32                                                                 "We only allow 5 restarts over 15 minute window during the day time hours (i.e. avoid midnight to 5am)",
33                                                                 "APPC", 
34                                                                 "Restart");     
35                 builder = builder.addGuardPolicy(policy);
36 ```
37
38 # Add Limit Constraint to a Guard Policy
39
40 The limit constraint defines the details of how to enforce the guard policy. Each limit constraint can contain two types of constraints - frequency limiter and black list. At least one type of constraints should be specified, otherwise the limit constraint will be counted as invalid. To add a limit constraint to an existing guard policy, use the addLimitConstraint() method.
41
42 ```java
43                 Map<String, String> time_in_range = new HashMap<String, String>();
44                 time_in_range.put("arg2", "PT5H");
45                 time_in_range.put("arg3", "PT24H");
46                 List<String> blacklist = new LinkedList<String>();
47                 blacklist.add("vm_name_1");
48                 blacklist.add("vm_name_2");
49                 Constraint cons = new Constraint(5, "PT15M", time_in_range, blacklist);
50                 builder = builder.addLimitConstraint(policy.id, cons);
51 ```
52
53
54 # Build the YAML Specification
55
56 When finished defining the Guard Policies, build the specification and analyze the [Results.java](src/main/java/org/onap/policy/controlloop/policy/builder/Results.java)
57
58 ```java
59                 Results results = builder.buildSpecification();
60                 if (results.isValid()) {
61                         System.out.println(results.getSpecification());
62                 } else {
63                         System.err.println("Builder failed");
64                         for (Message message : results.getMessages()) {
65                                 System.err.println(message.getMessage());
66                         }
67                 }
68 ```
69
70
71 # Use the YAML Specification to Generate the XACML Guard Policies
72
73 Now that you have a valid YAML specification, call the method in [PolicyGuardYamlToXacml.java](guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java) to generate the XACML Guard Policies.
74
75
76 # YAML Specification
77
78 The YAML specification has 2 sections to it: [guard](#guard-object) and [guards](#guards-array). The [guard section](#guard-object) section is simply a header defining the version of this guard. The [guards section](#guards-array) is simply an array of [GuardPolicy objects](#guardpolicy-object).
79
80 ## guard Object
81
82 | Field Name      | Type          | Required   | Description  |
83 | -------------   |:-------------:| -----------| ------------:|
84 | version         | string        | required   | Value for this release if 2.0.0 |
85
86
87 ## guards array
88
89 The guards section is an array of [GuardPolicy objects](#guardpolicy-object).
90
91 ### GuardPolicy Object
92
93 | Field Name      | Type          | Required   | Description  |
94 | -------------   |:-------------:| -----------| ------------:|
95 | id              | string        | required   | Unique ID for the policy. |
96 | name            | string        | required   | Policy name |
97 | description     | string        | optional   | Policy description |
98 | actor           | string        | required   | Name of the actor for this operation: Example: APPC |
99 | recipe          | string        | required   | Name of recipe to be performed. Example "Restart" |
100 | limit_constraints  | array of [constraint](#constraint-object) object | required | Constraints used to enforce the guard policy |
101
102 The guard policy is bound to a specific recipe performed by the actor. When the Control Loop tries to perform the recipe operation by the actor, this guard policy should be evaluated against all the specified constraints. If any of the constraints will be violated, the operation should be abandoned.
103
104 #### constraint Object
105
106 | Field Name      | Type          | Required   | Description  |
107 | -------------   |:-------------:| -----------| ------------:|
108 | num             | integer       | required if blacklist is not specified  | The limited number of the same operations |
109 | duration        | string        | required if blacklist is not specified  | Time window for counting the same operations |
110 | time_in_range   | map<string, string> | optional   | Valid time spans for enforcing the guard policy |
111 | blacklist       | array of string     | required if num and duration are not specified | A list of the entity names that should not be touched by the Control Loop |
112
113 The first three attributes define the frequency limiter which means that only a limited number of the same operations can be allowed within each valid time window. The last attribute defines a blacklist of the target entities on which the Control Loop should not perform the operation.
114   
115 The "duration" parameter should have one of the following values: [5min, 10min, 30min, 1h, 12h, 1d, 5d, 1w, 1mon].
116
117   
118 ## Examples of YAML Control Loop Guards
119
120 [vService-Frequency-Limiter-Guard](src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml)
121 [vService-Blacklist-Guard](src/test/resources/v2.0.0-guard/policy_guard_blacklist.yaml)
122 [ONAP-vDNS-Guard](src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml)
123
124
125 ### vService Frequency Limiter Guard
126 ```
127 guard:
128   version: 2.0.0
129
130 guards:
131   - id: unique_guard_vService_frequency_limiter
132     name: APPC 5 Restart
133     description: 
134       We only allow 5 restarts over 15 minute window during the day time hours (i.e. avoid midnight to 5am)
135     actor: APPC
136     recipe: Restart
137     limit_constraints:
138       - num: 5
139         duration: PT15M
140         time_in_range:
141           arg2: PT5H
142           arg3: PT24H   
143 ```
144
145
146 ### vService Blacklist Guard
147 ```
148 guard:
149   version: 2.0.0
150
151 guards:
152   - id: unique_guard_vService_blacklist
153     name: APPC Restart Blacklist
154     description: |
155       We deny restart of the blacklisted targets (avoid midnight to 5am)
156     actor: APPC
157     recipe: Restart
158     limit_constraints:
159       - blacklist:
160           - TargetName1
161           - TargetName2
162         time_in_range:
163           arg2: 00:00:00-05:00
164           arg3: 23:59:59-05:00
165 ```
166
167
168 ### ONAP vDNS Guard
169 ```
170 guard:
171   version: 2.0.0
172
173 guards:
174   - id: unique_guard_ONAP_vDNS_1
175     name: SO Spinup
176     description: We only spin up 1 instance over a 10 minute window
177     actor: SO
178     recipe: VF Module Create
179     limit_constraints:
180       - num: 1
181         duration: PT10M
182 ```
183