9d00793b996bfc4629fef95a11958683cbe95a28
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-yaml
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop.policy.builder;
22
23 import java.util.Map;
24
25 import org.onap.policy.aai.Pnf;
26 import org.onap.policy.controlloop.policy.ControlLoop;
27 import org.onap.policy.controlloop.policy.OperationsAccumulateParams;
28 import org.onap.policy.controlloop.policy.Policy;
29 import org.onap.policy.controlloop.policy.PolicyResult;
30 import org.onap.policy.controlloop.policy.Target;
31 import org.onap.policy.controlloop.policy.builder.impl.ControlLoopPolicyBuilderImpl;
32 import org.onap.policy.sdc.Resource;
33 import org.onap.policy.sdc.Service;
34
35 public interface ControlLoopPolicyBuilder {
36
37     /**
38      * Adds one or more services to the ControlLoop.
39      * 
40      * @param services service to add
41      * @return builder object
42      * @throws BuilderException builder exception
43      */
44     public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;
45
46     /**
47      * Remove service.
48      * 
49      * @param services to remove
50      * @return builder object
51      * @throws BuilderException builder exception
52      */
53     public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
54
55     /**
56      * Remove all the services.
57      * 
58      * @return builder object
59      * @throws BuilderException builder exception
60      */
61     public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
62
63     /**
64      * Adds one or more resources to the ControlLoop.
65      * 
66      * @return builder object
67      * @throws BuilderException builder exception
68      */
69     public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;
70
71     /**
72      * Remove the resources.
73      * 
74      * @param resources resources to be removed
75      * @return object
76      * @throws BuilderException builder exception
77      */
78     public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
79
80     /**
81      * Remove all resources.
82      * 
83      * @return object
84      * @throws BuilderException builder exception
85      */
86     public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
87
88     /**
89      * Set the PNF.
90      * 
91      * @param pnf input pnf
92      * @return builder object
93      * @throws BuilderException builder exception
94      */
95     public ControlLoopPolicyBuilder setPNF(Pnf pnf) throws BuilderException;
96
97     /**
98      * Remove PNF.
99      * 
100      * @return the object
101      * @throws BuilderException builder exception
102      */
103     public ControlLoopPolicyBuilder removePNF() throws BuilderException;
104
105     /**
106      * Set the abatement.
107      * 
108      * @param abatement whether abatement is possible
109      * @return object
110      * @throws BuilderException builder exception
111      */
112     public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
113
114
115     /**
116      * Sets the overall timeout value for the Control Loop. If any operational policies have retries
117      * and timeouts, then this overall timeout value should exceed all those values.
118      * 
119      * @param timeout timeout value
120      * @return control loop policy builder
121      * @throws BuilderException builder exception
122      */
123     public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
124
125     /**
126      * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
127      * 
128      * 
129      * @return Integer
130      */
131     public Integer calculateTimeout();
132
133     /**
134      * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ONAP Policy
135      * Platform.
136      * 
137      * 
138      * @param name name
139      * @param description description
140      * @param actor actor
141      * @param target target
142      * @param recipe recipe
143      * @param retries retries
144      * @param timeout timeout
145      * @return Policy object
146      * @throws BuilderException builder exception
147      */
148     public Policy setTriggerPolicy(String name, String description, String actor, Target target, String recipe,
149             Map<String, String> payload, Integer retries, Integer timeout) throws BuilderException;
150
151     /**
152      * Changes the trigger policy to point to another existing Policy.
153      * 
154      * @param id the id
155      * @return ControlLoop object
156      * @throws BuilderException build exception
157      */
158     public ControlLoop setTriggerPolicy(String id) throws BuilderException;
159
160     /**
161      * Is an open loop.
162      * 
163      * @return true or false
164      */
165     public boolean isOpenLoop();
166
167     /**
168      * Get the trigger policy.
169      * 
170      * @return the policy object
171      * @throws BuilderException if there is a builder exception
172      */
173     public Policy getTriggerPolicy() throws BuilderException;
174
175     /**
176      * Simply returns a copy of the ControlLoop information.
177      * 
178      * 
179      * @return ControlLoop
180      */
181     public ControlLoop getControlLoop();
182
183     /**
184      * Creates a policy that is chained to the result of another Policy.
185      * 
186      * @param name name
187      * @param description description
188      * @param actor actor
189      * @param target target
190      * @param recipe recipe
191      * @param retries retries
192      * @param timeout timeout
193      * @param policyId id
194      * @param results results
195      * @return Policy that was set
196      * @throws BuilderException builder exception
197      */
198     public Policy setPolicyForPolicyResult(String name, String description, String actor, Target target, String recipe,
199             Map<String, String> payload, Integer retries, Integer timeout, String policyId, PolicyResult... results)
200             throws BuilderException;
201
202
203     /**
204      * Sets the policy result(s) to an existing Operational Policy.
205      * 
206      * @param policyResultId result ID
207      * @param policyId id
208      * @param results results
209      * @return Policy that was set
210      * @throws BuilderException builder exception
211      */
212     public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results)
213             throws BuilderException;
214
215     /**
216      * Removes an Operational Policy. Be mindful that if any other Operational Policies have results
217      * that point to this policy, any policies that have results pointing to this policy will have
218      * their result reset to the appropriate default FINAL_* result.
219      * 
220      * 
221      * @param policyID id for the policy
222      * @return true if removed else false
223      * @throws BuilderException builder exception
224      */
225     public boolean removePolicy(String policyID) throws BuilderException;
226
227     /**
228      * Resets a policy's results to defualt FINAL_* codes.
229      * 
230      * @return Policy object
231      * @throws BuilderException - Policy does not exist
232      */
233     public Policy resetPolicyResults(String policyID) throws BuilderException;
234
235     /**
236      * Removes all existing Operational Policies and reverts back to an Open Loop.
237      * 
238      * @return
239      */
240     public ControlLoopPolicyBuilder removeAllPolicies();
241
242     /**
243      * Adds an operationsAccumulateParams to an existing operational policy.
244      * 
245      * @return Policy
246      * @throws BuilderException - Policy does not exist
247      */
248     public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams)
249             throws BuilderException;
250
251     /**
252      * This will compile and build the YAML specification for the Control Loop Policy. Please
253      * iterate the Results object for details. The Results object will contains warnings and errors.
254      * If the specification compiled successfully, you will be able to retrieve the YAML.
255      * 
256      * @return Results
257      */
258     public Results buildSpecification();
259
260     /**
261      * The Factory is used to build a ControlLoopPolicyBuilder implementation.
262      * 
263      * @author pameladragosh
264      *
265      */
266     public static class Factory {
267         private Factory() {
268             // Private Constructor.
269         }
270
271         /**
272          * Builds a basic Control Loop with an overall timeout. Use this method if you wish to
273          * create an OpenLoop, or if you want to interactively build a Closed Loop.
274          * 
275          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
276          * @param timeout - Overall timeout for the Closed Loop to execute.
277          * @return ControlLoopPolicyBuilder object
278          */
279         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout) {
280             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
281         }
282
283         /**
284          * Build a Control Loop for a resource and services associated with the resource.
285          * 
286          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
287          * @param timeout - Overall timeout for the Closed Loop to execute.
288          * @param resource - Resource this closed loop is for. Should come from ASDC, but if not
289          *        available use resourceName to distinguish.
290          * @param services - Zero or more services associated with this resource. Should come from
291          *        ASDC, but if not available use serviceName to distinguish.
292          * @return ControlLoopPolicyBuilder object
293          * @throws BuilderException builder exception
294          */
295         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
296                 Resource resource, Service... services) throws BuilderException {
297             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
298         }
299
300         /**
301          * Build the control loop.
302          * 
303          * @param controlLoopName control loop id
304          * @param timeout timeout
305          * @param service service
306          * @param resources resources
307          * @return builder object
308          * @throws BuilderException builder exception
309          */
310         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
311                 Service service, Resource... resources) throws BuilderException {
312             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
313         }
314
315         /**
316          * Build control loop.
317          * 
318          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
319          * @param timeout - Overall timeout for the Closed Loop to execute.
320          * @param pnf - Physical Network Function. Should come from AIC, but if not available use
321          *        well-known name to distinguish. Eg. eNodeB
322          * @return ControlLoopPolicyBuilder object
323          * @throws BuilderException builder exception
324          */
325         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Pnf pnf)
326                 throws BuilderException {
327             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, pnf);
328         }
329     }
330
331 }