2 * ============LICENSE_START=======================================================
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
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
43 * @throws BuilderException
45 public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;
50 * @throws BuilderException
52 public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
56 * @throws BuilderException
58 public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
61 * Adds one or more resources to the ControlLoop
66 * @throws BuilderException
68 public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;
73 * @throws BuilderException
75 public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
79 * @throws BuilderException
81 public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
86 * @throws BuilderException
88 public ControlLoopPolicyBuilder setPNF(Pnf pnf) throws BuilderException;
92 * @throws BuilderException
94 public ControlLoopPolicyBuilder removePNF() throws BuilderException;
99 * @throws BuilderException
101 public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
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.
110 * @throws BuilderException
112 public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
115 * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
120 public Integer calculateTimeout();
123 * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ONAP Policy
135 * @throws BuilderException
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;
142 * Changes the trigger policy to point to another existing Policy.
146 * @return ControlLoop
147 * @throws BuilderException
149 public ControlLoop setTriggerPolicy(String id) throws BuilderException;
154 public boolean isOpenLoop();
158 * @throws BuilderException
160 public Policy getTriggerPolicy() throws BuilderException;
163 * Simply returns a copy of the ControlLoop information.
166 * @return ControlLoop
168 public ControlLoop getControlLoop();
171 * Creates a policy that is chained to the result of another Policy.
184 * @throws BuilderException
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;
192 * Sets the policy result(s) to an existing Operational Policy.
195 * @param policyResultID
199 * @throws BuilderException
201 public Policy setPolicyForPolicyResult(String policyResultID, String policyID, PolicyResult... results)
202 throws BuilderException;
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.
212 * @throws BuilderException
214 public boolean removePolicy(String policyID) throws BuilderException;
217 * Resets a policy's results to defualt FINAL_* codes.
221 * @throws BuilderException - Policy does not exist
223 public Policy resetPolicyResults(String policyID) throws BuilderException;
226 * Removes all existing Operational Policies and reverts back to an Open Loop.
230 public ControlLoopPolicyBuilder removeAllPolicies();
233 * Adds an operationsAccumulateParams to an existing operational policy
236 * @throws BuilderException - Policy does not exist
238 public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams)
239 throws BuilderException;
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.
248 public Results buildSpecification();
251 * The Factory is used to build a ControlLoopPolicyBuilder implementation.
253 * @author pameladragosh
256 public static class Factory {
258 // Private Constructor.
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.
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
269 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout) {
270 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
274 * Build a Control Loop for a resource and services associated with the resource.
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
285 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
286 Resource resource, Service... services) throws BuilderException {
287 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
291 * @param controlLoopName
296 * @throws BuilderException
298 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
299 Service service, Resource... resources) throws BuilderException {
300 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
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
311 public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Pnf pnf)
312 throws BuilderException {
313 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, pnf);