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