4e034cb0e950f78834c603c9ce3e8ccc4e387ebe
[policy/drools-applications.git] /
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
106      * and timeouts, 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 ONAP Policy
124      * Platform.
125      * 
126      * 
127      * @param name
128      * @param description
129      * @param actor
130      * @param target
131      * @param recipe
132      * @param retries
133      * @param timeout
134      * @return Policy
135      * @throws BuilderException
136      */
137     public Policy setTriggerPolicy(String name, String description, String actor, Target target, String recipe,
138             Map<String, String> payload, Integer retries, Integer timeout) throws BuilderException;
139
140     /**
141      * 
142      * Changes the trigger policy to point to another existing Policy.
143      * 
144      * 
145      * @param id
146      * @return ControlLoop
147      * @throws BuilderException
148      */
149     public ControlLoop setTriggerPolicy(String id) throws BuilderException;
150
151     /**
152      * @return
153      */
154     public boolean isOpenLoop();
155
156     /**
157      * @return
158      * @throws BuilderException
159      */
160     public Policy getTriggerPolicy() throws BuilderException;
161
162     /**
163      * Simply returns a copy of the ControlLoop information.
164      * 
165      * 
166      * @return ControlLoop
167      */
168     public ControlLoop getControlLoop();
169
170     /**
171      * Creates a policy that is chained to the result of another Policy.
172      * 
173      * 
174      * @param name
175      * @param description
176      * @param actor
177      * @param target
178      * @param recipe
179      * @param retries
180      * @param timeout
181      * @param policyID
182      * @param results
183      * @return
184      * @throws BuilderException
185      */
186     public Policy setPolicyForPolicyResult(String name, String description, String actor, Target target, String recipe,
187             Map<String, String> payload, Integer retries, Integer timeout, String policyID, PolicyResult... results)
188             throws BuilderException;
189
190
191     /**
192      * Sets the policy result(s) to an existing Operational Policy.
193      * 
194      * 
195      * @param policyResultID
196      * @param policyID
197      * @param results
198      * @return
199      * @throws BuilderException
200      */
201     public Policy setPolicyForPolicyResult(String policyResultID, String policyID, PolicyResult... results)
202             throws BuilderException;
203
204     /**
205      * Removes an Operational Policy. Be mindful that if any other Operational Policies have results
206      * that point to this policy, any policies that have results pointing to this policy will have
207      * their result reset to the appropriate default FINAL_* result.
208      * 
209      * 
210      * @param policyID
211      * @return
212      * @throws BuilderException
213      */
214     public boolean removePolicy(String policyID) throws BuilderException;
215
216     /**
217      * Resets a policy's results to defualt FINAL_* codes.
218      * 
219      * 
220      * @return Policy
221      * @throws BuilderException - Policy does not exist
222      */
223     public Policy resetPolicyResults(String policyID) throws BuilderException;
224
225     /**
226      * Removes all existing Operational Policies and reverts back to an Open Loop.
227      * 
228      * @return
229      */
230     public ControlLoopPolicyBuilder removeAllPolicies();
231
232     /**
233      * Adds an operationsAccumulateParams to an existing operational policy
234      * 
235      * @return Policy
236      * @throws BuilderException - Policy does not exist
237      */
238     public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams)
239             throws BuilderException;
240
241     /**
242      * This will compile and build the YAML specification for the Control Loop Policy. Please
243      * iterate the Results object for details. The Results object will contains warnings and errors.
244      * If the specification compiled successfully, you will be able to retrieve the YAML.
245      * 
246      * @return Results
247      */
248     public Results buildSpecification();
249
250     /**
251      * The Factory is used to build a ControlLoopPolicyBuilder implementation.
252      * 
253      * @author pameladragosh
254      *
255      */
256     public static class Factory {
257         private Factory() {
258             // Private Constructor.
259         }
260
261         /**
262          * Builds a basic Control Loop with an overall timeout. Use this method if you wish to
263          * create an OpenLoop, or if you want to interactively build a Closed Loop.
264          * 
265          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
266          * @param timeout - Overall timeout for the Closed Loop to execute.
267          * @return ControlLoopPolicyBuilder object
268          */
269         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout) {
270             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
271         }
272
273         /**
274          * Build a Control Loop for a resource and services associated with the resource.
275          * 
276          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
277          * @param timeout - Overall timeout for the Closed Loop to execute.
278          * @param resource - Resource this closed loop is for. Should come from ASDC, but if not
279          *        available use resourceName to distinguish.
280          * @param services - Zero or more services associated with this resource. Should come from
281          *        ASDC, but if not available use serviceName to distinguish.
282          * @return ControlLoopPolicyBuilder object
283          * @throws BuilderException
284          */
285         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
286                 Resource resource, Service... services) throws BuilderException {
287             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
288         }
289
290         /**
291          * @param controlLoopName
292          * @param timeout
293          * @param service
294          * @param resources
295          * @return
296          * @throws BuilderException
297          */
298         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
299                 Service service, Resource... resources) throws BuilderException {
300             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
301         }
302
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
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 }