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.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;
35 public interface ControlLoopPolicyBuilder {
38 * Adds one or more services to the ControlLoop.
40 * @param services service to add
41 * @return builder object
42 * @throws BuilderException builder exception
44 public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;
49 * @param services to remove
50 * @return builder object
51 * @throws BuilderException builder exception
53 public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
56 * Remove all the services.
58 * @return builder object
59 * @throws BuilderException builder exception
61 public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
64 * Adds one or more resources to the ControlLoop.
66 * @return builder object
67 * @throws BuilderException builder exception
69 public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;
72 * Remove the resources.
74 * @param resources resources to be removed
76 * @throws BuilderException builder exception
78 public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
81 * Remove all resources.
84 * @throws BuilderException builder exception
86 public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
91 * @param pnf input pnf
92 * @return builder object
93 * @throws BuilderException builder exception
95 public ControlLoopPolicyBuilder setPNF(Pnf pnf) throws BuilderException;
101 * @throws BuilderException builder exception
103 public ControlLoopPolicyBuilder removePNF() throws BuilderException;
108 * @param abatement whether abatement is possible
110 * @throws BuilderException builder exception
112 public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
116 * Sets the overall timeout value for the Control Loop. If any operational policies have retries
117 * and timeouts, then this overall timeout value should exceed all those values.
119 * @param timeout timeout value
120 * @return control loop policy builder
121 * @throws BuilderException builder exception
123 public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
126 * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
131 public Integer calculateTimeout();
134 * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ONAP Policy
139 * @param description description
141 * @param target target
142 * @param recipe recipe
143 * @param retries retries
144 * @param timeout timeout
145 * @return Policy object
146 * @throws BuilderException builder exception
148 public Policy setTriggerPolicy(String name, String description, String actor, Target target, String recipe,
149 Map<String, String> payload, Integer retries, Integer timeout) throws BuilderException;
152 * Changes the trigger policy to point to another existing Policy.
155 * @return ControlLoop object
156 * @throws BuilderException build exception
158 public ControlLoop setTriggerPolicy(String id) throws BuilderException;
163 * @return true or false
165 public boolean isOpenLoop();
168 * Get the trigger policy.
170 * @return the policy object
171 * @throws BuilderException if there is a builder exception
173 public Policy getTriggerPolicy() throws BuilderException;
176 * Simply returns a copy of the ControlLoop information.
179 * @return ControlLoop
181 public ControlLoop getControlLoop();
184 * Creates a policy that is chained to the result of another Policy.
187 * @param description description
189 * @param target target
190 * @param recipe recipe
191 * @param retries retries
192 * @param timeout timeout
194 * @param results results
195 * @return Policy that was set
196 * @throws BuilderException builder exception
198 public Policy setPolicyForPolicyResult(String name, String description, String actor, Target target, String recipe,
199 Map<String, String> payload, Integer retries, Integer timeout, String policyId, PolicyResult... results)
200 throws BuilderException;
204 * Sets the policy result(s) to an existing Operational Policy.
206 * @param policyResultId result ID
208 * @param results results
209 * @return Policy that was set
210 * @throws BuilderException builder exception
212 public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results)
213 throws BuilderException;
216 * Removes an Operational Policy. Be mindful that if any other Operational Policies have results
217 * that point to this policy, any policies that have results pointing to this policy will have
218 * their result reset to the appropriate default FINAL_* result.
221 * @param policyID id for the policy
222 * @return true if removed else false
223 * @throws BuilderException builder exception
225 public boolean removePolicy(String policyID) throws BuilderException;
228 * Resets a policy's results to defualt FINAL_* codes.
230 * @return Policy object
231 * @throws BuilderException - Policy does not exist
233 public Policy resetPolicyResults(String policyID) throws BuilderException;
236 * Removes all existing Operational Policies and reverts back to an Open Loop.
240 public ControlLoopPolicyBuilder removeAllPolicies();
243 * Adds an operationsAccumulateParams to an existing operational policy.
246 * @throws BuilderException - Policy does not exist
248 public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams)
249 throws BuilderException;
252 * This will compile and build the YAML specification for the Control Loop Policy. Please
253 * iterate the Results object for details. The Results object will contains warnings and errors.
254 * If the specification compiled successfully, you will be able to retrieve the YAML.
258 public Results buildSpecification();
261 * The Factory is used to build a ControlLoopPolicyBuilder implementation.
263 * @author pameladragosh
266 public static class Factory {
268 // Private Constructor.
272 * Builds a basic Control Loop with an overall timeout. Use this method if you wish to
273 * create an OpenLoop, or if you want to interactively build a Closed Loop.
275 * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
276 * @param timeout - Overall timeout for the Closed Loop to execute.
277 * @return ControlLoopPolicyBuilder object
279 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout) {
280 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
284 * Build a Control Loop for a resource and services associated with the resource.
286 * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
287 * @param timeout - Overall timeout for the Closed Loop to execute.
288 * @param resource - Resource this closed loop is for. Should come from ASDC, but if not
289 * available use resourceName to distinguish.
290 * @param services - Zero or more services associated with this resource. Should come from
291 * ASDC, but if not available use serviceName to distinguish.
292 * @return ControlLoopPolicyBuilder object
293 * @throws BuilderException builder exception
295 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
296 Resource resource, Service... services) throws BuilderException {
297 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
301 * Build the control loop.
303 * @param controlLoopName control loop id
304 * @param timeout timeout
305 * @param service service
306 * @param resources resources
307 * @return builder object
308 * @throws BuilderException builder exception
310 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
311 Service service, Resource... resources) throws BuilderException {
312 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
316 * Build control loop.
318 * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
319 * @param timeout - Overall timeout for the Closed Loop to execute.
320 * @param pnf - Physical Network Function. Should come from AIC, but if not available use
321 * well-known name to distinguish. Eg. eNodeB
322 * @return ControlLoopPolicyBuilder object
323 * @throws BuilderException builder exception
325 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Pnf pnf)
326 throws BuilderException {
327 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, pnf);