3c43756c3b04faaa0ceed7ad19081d7174b31c74
[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.PolicyParam;
30 import org.onap.policy.controlloop.policy.PolicyResult;
31 import org.onap.policy.controlloop.policy.Target;
32 import org.onap.policy.controlloop.policy.builder.impl.ControlLoopPolicyBuilderImpl;
33 import org.onap.policy.sdc.Resource;
34 import org.onap.policy.sdc.Service;
35
36 public interface ControlLoopPolicyBuilder {
37
38     /**
39      * Adds one or more services to the ControlLoop.
40      * 
41      * @param services service to add
42      * @return builder object
43      * @throws BuilderException builder exception
44      */
45     public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;
46
47     /**
48      * Remove service.
49      * 
50      * @param services to remove
51      * @return builder object
52      * @throws BuilderException builder exception
53      */
54     public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
55
56     /**
57      * Remove all the services.
58      * 
59      * @return builder object
60      * @throws BuilderException builder exception
61      */
62     public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
63
64     /**
65      * Adds one or more resources to the ControlLoop.
66      * 
67      * @return builder object
68      * @throws BuilderException builder exception
69      */
70     public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;
71
72     /**
73      * Remove the resources.
74      * 
75      * @param resources resources to be removed
76      * @return object
77      * @throws BuilderException builder exception
78      */
79     public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
80
81     /**
82      * Remove all resources.
83      * 
84      * @return object
85      * @throws BuilderException builder exception
86      */
87     public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
88
89     /**
90      * Set the PNF.
91      * 
92      * @param pnf input pnf
93      * @return builder object
94      * @throws BuilderException builder exception
95      */
96     public ControlLoopPolicyBuilder setPNF(Pnf pnf) throws BuilderException;
97
98     /**
99      * Remove PNF.
100      * 
101      * @return the object
102      * @throws BuilderException builder exception
103      */
104     public ControlLoopPolicyBuilder removePNF() throws BuilderException;
105
106     /**
107      * Set the abatement.
108      * 
109      * @param abatement whether abatement is possible
110      * @return object
111      * @throws BuilderException builder exception
112      */
113     public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
114
115
116     /**
117      * Sets the overall timeout value for the Control Loop. If any operational policies have retries
118      * and timeouts, then this overall timeout value should exceed all those values.
119      * 
120      * @param timeout timeout value
121      * @return control loop policy builder
122      * @throws BuilderException builder exception
123      */
124     public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
125
126     /**
127      * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
128      * 
129      * 
130      * @return Integer
131      */
132     public Integer calculateTimeout();
133
134     /**
135      * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ONAP Policy
136      * Platform.
137      * 
138      * 
139      * @param policy Policy parameters object
140      * @return Policy object
141      * @throws BuilderException builder exception
142      */
143     public Policy setTriggerPolicy(PolicyParam policy) throws BuilderException;
144
145     /**
146      * Changes the trigger policy to point to another existing Policy.
147      * 
148      * @param id the id
149      * @return ControlLoop object
150      * @throws BuilderException build exception
151      */
152     public ControlLoop setExistingTriggerPolicy(String id) throws BuilderException;
153
154     /**
155      * Is an open loop.
156      * 
157      * @return true or false
158      */
159     public boolean isOpenLoop();
160
161     /**
162      * Get the trigger policy.
163      * 
164      * @return the policy object
165      * @throws BuilderException if there is a builder exception
166      */
167     public Policy getTriggerPolicy() throws BuilderException;
168
169     /**
170      * Simply returns a copy of the ControlLoop information.
171      * 
172      * 
173      * @return ControlLoop
174      */
175     public ControlLoop getControlLoop();
176
177     /**
178      * Creates a policy that is chained to the result of another Policy.
179      * 
180      * @param policyParam policy parameters object
181      * @param results results
182      * @return Policy that was set
183      * @throws BuilderException builder exception
184      */
185     public Policy setPolicyForPolicyResult(PolicyParam policyParam, PolicyResult... results)
186             throws BuilderException;
187
188
189     /**
190      * Sets the policy result(s) to an existing Operational Policy.
191      * 
192      * @param policyResultId result ID
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 policyResultId, String policyId, PolicyResult... results)
199             throws BuilderException;
200
201     /**
202      * Removes an Operational Policy. Be mindful that if any other Operational Policies have results
203      * that point to this policy, any policies that have results pointing to this policy will have
204      * their result reset to the appropriate default FINAL_* result.
205      * 
206      * 
207      * @param policyID id for the policy
208      * @return true if removed else false
209      * @throws BuilderException builder exception
210      */
211     public boolean removePolicy(String policyID) throws BuilderException;
212
213     /**
214      * Resets a policy's results to defualt FINAL_* codes.
215      * 
216      * @return Policy object
217      * @throws BuilderException - Policy does not exist
218      */
219     public Policy resetPolicyResults(String policyID) throws BuilderException;
220
221     /**
222      * Removes all existing Operational Policies and reverts back to an Open Loop.
223      * 
224      * @return Policy builder object
225      */
226     public ControlLoopPolicyBuilder removeAllPolicies();
227
228     /**
229      * Adds an operationsAccumulateParams to an existing operational policy.
230      * 
231      * @return Policy
232      * @throws BuilderException - Policy does not exist
233      */
234     public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams)
235             throws BuilderException;
236
237     /**
238      * This will compile and build the YAML specification for the Control Loop Policy. Please
239      * iterate the Results object for details. The Results object will contains warnings and errors.
240      * If the specification compiled successfully, you will be able to retrieve the YAML.
241      * 
242      * @return Results
243      */
244     public Results buildSpecification();
245
246     /**
247      * The Factory is used to build a ControlLoopPolicyBuilder implementation.
248      * 
249      * @author pameladragosh
250      *
251      */
252     public static class Factory {
253         private Factory() {
254             // Private Constructor.
255         }
256
257         /**
258          * Builds a basic Control Loop with an overall timeout. Use this method if you wish to
259          * create an OpenLoop, or if you want to interactively build a Closed Loop.
260          * 
261          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
262          * @param timeout - Overall timeout for the Closed Loop to execute.
263          * @return ControlLoopPolicyBuilder object
264          */
265         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout) {
266             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
267         }
268
269         /**
270          * Build a Control Loop for a resource and services associated with the resource.
271          * 
272          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
273          * @param timeout - Overall timeout for the Closed Loop to execute.
274          * @param resource - Resource this closed loop is for. Should come from ASDC, but if not
275          *        available use resourceName to distinguish.
276          * @param services - Zero or more services associated with this resource. Should come from
277          *        ASDC, but if not available use serviceName to distinguish.
278          * @return ControlLoopPolicyBuilder object
279          * @throws BuilderException builder exception
280          */
281         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
282                 Resource resource, Service... services) throws BuilderException {
283             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
284         }
285
286         /**
287          * Build the control loop.
288          * 
289          * @param controlLoopName control loop id
290          * @param timeout timeout
291          * @param service service
292          * @param resources resources
293          * @return builder object
294          * @throws BuilderException builder exception
295          */
296         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
297                 Service service, Resource... resources) throws BuilderException {
298             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
299         }
300
301         /**
302          * Build control loop.
303          * 
304          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
305          * @param timeout - Overall timeout for the Closed Loop to execute.
306          * @param pnf - Physical Network Function. Should come from AIC, but if not available use
307          *        well-known name to distinguish. Eg. eNodeB
308          * @return ControlLoopPolicyBuilder object
309          * @throws BuilderException builder exception
310          */
311         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Pnf pnf)
312                 throws BuilderException {
313             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, pnf);
314         }
315     }
316
317 }