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.openecomp.policy.controlloop.policy.builder;
25 import org.openecomp.policy.asdc.Resource;
26 import org.openecomp.policy.asdc.Service;
27 import org.openecomp.policy.controlloop.policy.ControlLoop;
28 import org.openecomp.policy.controlloop.policy.OperationsAccumulateParams;
29 import org.openecomp.policy.controlloop.policy.Policy;
30 import org.openecomp.policy.controlloop.policy.PolicyResult;
31 import org.openecomp.policy.controlloop.policy.Target;
32 import org.openecomp.policy.controlloop.policy.builder.impl.ControlLoopPolicyBuilderImpl;
34 public interface ControlLoopPolicyBuilder {
37 * Adds one or more services to the ControlLoop
42 * @throws BuilderException
44 public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;
49 * @throws BuilderException
51 public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
55 * @throws BuilderException
57 public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
60 * Adds one or more resources to the ControlLoop
65 * @throws BuilderException
67 public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;
72 * @throws BuilderException
74 public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
78 * @throws BuilderException
80 public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
85 * @throws BuilderException
87 public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
91 * Sets the overall timeout value for the Control Loop. If any operational policies have retries and timeouts,
92 * then this overall timeout value should exceed all those values.
96 * @throws BuilderException
98 public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
101 * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
106 public Integer calculateTimeout();
109 * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ECOMP Policy Platform.
120 * @throws BuilderException
122 public Policy setTriggerPolicy(String name, String description, String actor, Target target, String recipe, Map<String, String> payload, Integer retries, Integer timeout) throws BuilderException;
126 * Changes the trigger policy to point to another existing Policy.
130 * @return ControlLoop
131 * @throws BuilderException
133 public ControlLoop setTriggerPolicy(String id) throws BuilderException;
138 public boolean isOpenLoop();
142 * @throws BuilderException
144 public Policy getTriggerPolicy() throws BuilderException;
147 * Simply returns a copy of the ControlLoop information.
150 * @return ControlLoop
152 public ControlLoop getControlLoop();
155 * Creates a policy that is chained to the result of another Policy.
168 * @throws BuilderException
170 public Policy setPolicyForPolicyResult(String name, String description, String actor,
171 Target target, String recipe, Map<String, String> payload, Integer retries, Integer timeout, String policyID, PolicyResult... results) throws BuilderException;
175 * Sets the policy result(s) to an existing Operational Policy.
178 * @param policyResultID
182 * @throws BuilderException
184 public Policy setPolicyForPolicyResult(String policyResultID, String policyID, PolicyResult... results) throws BuilderException;
187 * Removes an Operational Policy. Be mindful that if any other Operational Policies have results that point to this policy, any
188 * policies that have results pointing to this policy will have their result reset to the appropriate default FINAL_* result.
193 * @throws BuilderException
195 public boolean removePolicy(String policyID) throws BuilderException;
198 * Resets a policy's results to defualt FINAL_* codes.
202 * @throws BuilderException - Policy does not exist
204 public Policy resetPolicyResults(String policyID) throws BuilderException;
207 * Removes all existing Operational Policies and reverts back to an Open Loop.
211 public ControlLoopPolicyBuilder removeAllPolicies();
214 * Adds an operationsAccumulateParams to an existing operational policy
217 * @throws BuilderException - Policy does not exist
219 public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams) throws BuilderException;
222 * This will compile and build the YAML specification for the Control Loop Policy. Please iterate the Results object for details.
223 * The Results object will contains warnings and errors. If the specification compiled successfully, you will be able to retrieve the
228 public Results buildSpecification();
231 * The Factory is used to build a ControlLoopPolicyBuilder implementation.
233 * @author pameladragosh
236 public static class Factory {
238 // Private Constructor.
242 * Builds a basic Control Loop with an overall timeout. Use this method if you wish to create an OpenLoop, or if you
243 * want to interactively build a Closed Loop.
245 * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
246 * @param timeout - Overall timeout for the Closed Loop to execute.
247 * @return ControlLoopPolicyBuilder object
248 * @throws BuilderException
250 public static ControlLoopPolicyBuilder buildControlLoop (String controlLoopName, Integer timeout) throws BuilderException {
251 return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
255 * Build a Control Loop for a resource and services associated with the resource.
257 * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
258 * @param timeout - Overall timeout for the Closed Loop to execute.
259 * @param resource - Resource this closed loop is for. Should come from ASDC, but if not available use resourceName to distinguish.
260 * @param services - Zero or more services associated with this resource. Should come from ASDC, but if not available use serviceName to distinguish.
261 * @return ControlLoopPolicyBuilder object
262 * @throws BuilderException
264 public static ControlLoopPolicyBuilder buildControlLoop (String controlLoopName, Integer timeout, Resource resource, Service... services) throws BuilderException {
266 ControlLoopPolicyBuilder builder = new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
272 * @param controlLoopName
277 * @throws BuilderException
279 public static ControlLoopPolicyBuilder buildControlLoop (String controlLoopName, Integer timeout, Service service, Resource... resources) throws BuilderException {
281 ControlLoopPolicyBuilder builder = new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);