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;
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.PolicyParam;
30 import org.onap.policy.controlloop.policy.PolicyResult;
31 import org.onap.policy.controlloop.policy.Target;
32 import org.onap.policy.controlloop.policy.builder.impl.ControlLoopPolicyBuilderImpl;
33 import org.onap.policy.sdc.Resource;
34 import org.onap.policy.sdc.Service;
36 public interface ControlLoopPolicyBuilder {
39 * Adds one or more services to the ControlLoop.
41 * @param services service to add
42 * @return builder object
43 * @throws BuilderException builder exception
45 public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;
50 * @param services to remove
51 * @return builder object
52 * @throws BuilderException builder exception
54 public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
57 * Remove all the services.
59 * @return builder object
60 * @throws BuilderException builder exception
62 public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
65 * Adds one or more resources to the ControlLoop.
67 * @return builder object
68 * @throws BuilderException builder exception
70 public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;
73 * Remove the resources.
75 * @param resources resources to be removed
77 * @throws BuilderException builder exception
79 public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
82 * Remove all resources.
85 * @throws BuilderException builder exception
87 public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
92 * @param pnf input pnf
93 * @return builder object
94 * @throws BuilderException builder exception
96 public ControlLoopPolicyBuilder setPNF(Pnf pnf) throws BuilderException;
102 * @throws BuilderException builder exception
104 public ControlLoopPolicyBuilder removePNF() throws BuilderException;
109 * @param abatement whether abatement is possible
111 * @throws BuilderException builder exception
113 public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
117 * Sets the overall timeout value for the Control Loop. If any operational policies have retries
118 * and timeouts, then this overall timeout value should exceed all those values.
120 * @param timeout timeout value
121 * @return control loop policy builder
122 * @throws BuilderException builder exception
124 public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
127 * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
132 public Integer calculateTimeout();
135 * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ONAP Policy
139 * @param policy Policy parameters object
140 * @return Policy object
141 * @throws BuilderException builder exception
143 public Policy setTriggerPolicy(PolicyParam policy) throws BuilderException;
146 * Changes the trigger policy to point to another existing Policy.
149 * @return ControlLoop object
150 * @throws BuilderException build exception
152 public ControlLoop setExistingTriggerPolicy(String id) throws BuilderException;
157 * @return true or false
159 public boolean isOpenLoop();
162 * Get the trigger policy.
164 * @return the policy object
165 * @throws BuilderException if there is a builder exception
167 public Policy getTriggerPolicy() throws BuilderException;
170 * Simply returns a copy of the ControlLoop information.
173 * @return ControlLoop
175 public ControlLoop getControlLoop();
178 * Creates a policy that is chained to the result of another Policy.
181 * @param description description
183 * @param target target
184 * @param recipe recipe
185 * @param retries retries
186 * @param timeout timeout
188 * @param results results
189 * @return Policy that was set
190 * @throws BuilderException builder exception
192 public Policy setPolicyForPolicyResult(String name, String description, String actor, Target target, String recipe,
193 Map<String, String> payload, Integer retries, Integer timeout, String policyId, PolicyResult... results)
194 throws BuilderException;
198 * Sets the policy result(s) to an existing Operational Policy.
200 * @param policyResultId result ID
202 * @param results results
203 * @return Policy that was set
204 * @throws BuilderException builder exception
206 public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results)
207 throws BuilderException;
210 * Removes an Operational Policy. Be mindful that if any other Operational Policies have results
211 * that point to this policy, any policies that have results pointing to this policy will have
212 * their result reset to the appropriate default FINAL_* result.
215 * @param policyID id for the policy
216 * @return true if removed else false
217 * @throws BuilderException builder exception
219 public boolean removePolicy(String policyID) throws BuilderException;
222 * Resets a policy's results to defualt FINAL_* codes.
224 * @return Policy object
225 * @throws BuilderException - Policy does not exist
227 public Policy resetPolicyResults(String policyID) throws BuilderException;
230 * Removes all existing Operational Policies and reverts back to an Open Loop.
232 * @return Policy builder object
234 public ControlLoopPolicyBuilder removeAllPolicies();
237 * Adds an operationsAccumulateParams to an existing operational policy.
240 * @throws BuilderException - Policy does not exist
242 public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams)
243 throws BuilderException;
246 * This will compile and build the YAML specification for the Control Loop Policy. Please
247 * iterate the Results object for details. The Results object will contains warnings and errors.
248 * If the specification compiled successfully, you will be able to retrieve the YAML.
252 public Results buildSpecification();
255 * The Factory is used to build a ControlLoopPolicyBuilder implementation.
257 * @author pameladragosh
260 public static class Factory {
262 // Private Constructor.
266 * Builds a basic Control Loop with an overall timeout. Use this method if you wish to
267 * create an OpenLoop, or if you want to interactively build a Closed Loop.
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 * @return ControlLoopPolicyBuilder object
273 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout) {
274 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
278 * Build a Control Loop for a resource and services associated with the resource.
280 * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
281 * @param timeout - Overall timeout for the Closed Loop to execute.
282 * @param resource - Resource this closed loop is for. Should come from ASDC, but if not
283 * available use resourceName to distinguish.
284 * @param services - Zero or more services associated with this resource. Should come from
285 * ASDC, but if not available use serviceName to distinguish.
286 * @return ControlLoopPolicyBuilder object
287 * @throws BuilderException builder exception
289 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
290 Resource resource, Service... services) throws BuilderException {
291 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
295 * Build the control loop.
297 * @param controlLoopName control loop id
298 * @param timeout timeout
299 * @param service service
300 * @param resources resources
301 * @return builder object
302 * @throws BuilderException builder exception
304 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
305 Service service, Resource... resources) throws BuilderException {
306 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
310 * Build control loop.
312 * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
313 * @param timeout - Overall timeout for the Closed Loop to execute.
314 * @param pnf - Physical Network Function. Should come from AIC, but if not available use
315 * well-known name to distinguish. Eg. eNodeB
316 * @return ControlLoopPolicyBuilder object
317 * @throws BuilderException builder exception
319 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Pnf pnf)
320 throws BuilderException {
321 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, pnf);