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