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