2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.controlloop.policy.builder;
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;
33 public interface ControlLoopPolicyBuilder {
36 * Adds one or more services to the ControlLoop.
38 * @param services service to add
39 * @return builder object
40 * @throws BuilderException builder exception
42 public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;
47 * @param services to remove
48 * @return builder object
49 * @throws BuilderException builder exception
51 public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
54 * Remove all the services.
56 * @return builder object
57 * @throws BuilderException builder exception
59 public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
62 * Adds one or more resources to the ControlLoop.
64 * @return builder object
65 * @throws BuilderException builder exception
67 public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;
70 * Remove the resources.
72 * @param resources resources to be removed
74 * @throws BuilderException builder exception
76 public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
79 * Remove all resources.
82 * @throws BuilderException builder exception
84 public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
89 * @param pnf input pnf
90 * @return builder object
91 * @throws BuilderException builder exception
93 public ControlLoopPolicyBuilder setPNF(Pnf pnf) throws BuilderException;
99 * @throws BuilderException builder exception
101 public ControlLoopPolicyBuilder removePNF() throws BuilderException;
106 * @param abatement whether abatement is possible
108 * @throws BuilderException builder exception
110 public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
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.
117 * @param timeout timeout value
118 * @return control loop policy builder
119 * @throws BuilderException builder exception
121 public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
124 * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
129 public Integer calculateTimeout();
132 * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ONAP Policy
136 * @param policy Policy parameters object
137 * @return Policy object
138 * @throws BuilderException builder exception
140 public Policy setTriggerPolicy(PolicyParam policy) throws BuilderException;
143 * Changes the trigger policy to point to another existing Policy.
146 * @return ControlLoop object
147 * @throws BuilderException build exception
149 public ControlLoop setExistingTriggerPolicy(String id) throws BuilderException;
154 * @return true or false
156 public boolean isOpenLoop();
159 * Get the trigger policy.
161 * @return the policy object
162 * @throws BuilderException if there is a builder exception
164 public Policy getTriggerPolicy() throws BuilderException;
167 * Simply returns a copy of the ControlLoop information.
170 * @return ControlLoop
172 public ControlLoop getControlLoop();
175 * Creates a policy that is chained to the result of another Policy.
177 * @param policyParam policy parameters object
178 * @param results results
179 * @return Policy that was set
180 * @throws BuilderException builder exception
182 public Policy setPolicyForPolicyResult(PolicyParam policyParam, PolicyResult... results)
183 throws BuilderException;
187 * Sets the policy result(s) to an existing Operational Policy.
189 * @param policyResultId result ID
191 * @param results results
192 * @return Policy that was set
193 * @throws BuilderException builder exception
195 public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results)
196 throws BuilderException;
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.
204 * @param policyID id for the policy
205 * @return true if removed else false
206 * @throws BuilderException builder exception
208 public boolean removePolicy(String policyID) throws BuilderException;
211 * Resets a policy's results to defualt FINAL_* codes.
213 * @return Policy object
214 * @throws BuilderException - Policy does not exist
216 public Policy resetPolicyResults(String policyID) throws BuilderException;
219 * Removes all existing Operational Policies and reverts back to an Open Loop.
221 * @return Policy builder object
223 public ControlLoopPolicyBuilder removeAllPolicies();
226 * Adds an operationsAccumulateParams to an existing operational policy.
229 * @throws BuilderException - Policy does not exist
231 public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams)
232 throws BuilderException;
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.
241 public Results buildSpecification();
244 * The Factory is used to build a ControlLoopPolicyBuilder implementation.
246 * @author pameladragosh
249 public static class Factory {
251 // Private Constructor.
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.
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
262 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout) {
263 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
267 * Build a Control Loop for a resource and services associated with the resource.
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
278 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
279 Resource resource, Service... services) throws BuilderException {
280 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
284 * Build the control loop.
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
293 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
294 Service service, Resource... resources) throws BuilderException {
295 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
299 * Build control loop.
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
308 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Pnf pnf)
309 throws BuilderException {
310 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, pnf);