fb10f292c2dac987d57bd7ef118e11c3d8163a5d
[policy/engine.git] / ECOMP-ControlloopPolicy / src / main / java / org / openecomp / policy / controlloop / policy / builder / ControlLoopPolicyBuilder.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.policy.controlloop.policy.builder;
22
23 import java.util.Map;
24
25 import org.openecomp.policy.controlloop.policy.ControlLoop;
26 import org.openecomp.policy.controlloop.policy.OperationsAccumulateParams;
27 import org.openecomp.policy.controlloop.policy.Policy;
28 import org.openecomp.policy.controlloop.policy.PolicyResult;
29 import org.openecomp.policy.controlloop.policy.Target;
30 import org.openecomp.policy.controlloop.policy.builder.impl.ControlLoopPolicyBuilderImpl;
31
32 public interface ControlLoopPolicyBuilder {
33         
34         /**
35          *  @param abatement
36          *  @return
37          *  @throws BuilderException
38          */
39         public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
40         
41         
42         /**
43          * Sets the overall timeout value for the Control Loop. If any operational policies have retries and timeouts,
44          * then this overall timeout value should exceed all those values.
45          * 
46          * @param timeout
47          * @return
48          * @throws BuilderException
49          */
50         public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
51         
52         /**
53          * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
54          * 
55          * 
56          * @return Integer
57          */
58         public Integer calculateTimeout();
59         
60         /**
61          * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ECOMP Policy Platform.
62          * 
63          * 
64          * @param name
65          * @param description
66          * @param actor
67          * @param target
68          * @param recipe
69          * @param retries
70          * @param timeout
71          * @return Policy
72          * @throws BuilderException
73          */
74         public Policy setTriggerPolicy(String name, String description, String actor, Target target, String recipe, Map<String, String> payload, Integer retries, Integer timeout) throws BuilderException;
75         
76         /**
77          * 
78          * Changes the trigger policy to point to another existing Policy.
79          * 
80          * 
81          * @param id
82          * @return ControlLoop
83          * @throws BuilderException
84          */
85         public ControlLoop      setTriggerPolicy(String id) throws BuilderException;
86         
87         /**
88          * @return
89          */
90         public boolean  isOpenLoop();
91         
92         /**
93          * @return
94          * @throws BuilderException
95          */
96         public Policy   getTriggerPolicy() throws BuilderException;
97         
98         /**
99          * Simply returns a copy of the ControlLoop information.
100          * 
101          * 
102          * @return ControlLoop
103          */
104         public ControlLoop      getControlLoop();
105         
106         /**
107          * Creates a policy that is chained to the result of another Policy.
108          * 
109          * 
110          * @param name
111          * @param description
112          * @param actor
113          * @param target
114          * @param recipe
115          * @param retries
116          * @param timeout
117          * @param policyID
118          * @param results
119          * @return
120          * @throws BuilderException
121          */
122         public Policy setPolicyForPolicyResult(String name, String description, String actor,
123                         Target target, String recipe, Map<String, String> payload, Integer retries, Integer timeout, String policyID, PolicyResult... results) throws BuilderException;
124         
125         
126         /**
127          * Sets the policy result(s) to an existing Operational Policy.
128          * 
129          * 
130          * @param policyResultID
131          * @param policyID
132          * @param results
133          * @return
134          * @throws BuilderException
135          */
136         public Policy setPolicyForPolicyResult(String policyResultID, String policyID, PolicyResult... results) throws BuilderException;
137         
138         /**
139          * Removes an Operational Policy. Be mindful that if any other Operational Policies have results that point to this policy, any
140          * policies that have results pointing to this policy will have their result reset to the appropriate default FINAL_* result.
141          * 
142          * 
143          * @param policyID
144          * @return
145          * @throws BuilderException
146          */
147         public boolean removePolicy(String policyID) throws BuilderException;
148         
149         /**
150          * Resets a policy's results to defualt FINAL_* codes.
151          * 
152          * 
153          * @return Policy
154          * @throws BuilderException - Policy does not exist
155          */
156         public Policy   resetPolicyResults(String policyID) throws BuilderException;
157         
158         /**
159          * Removes all existing Operational Policies and reverts back to an Open Loop.
160          * 
161          * @return
162          */
163         public ControlLoopPolicyBuilder removeAllPolicies();
164                 
165         /**
166          * Adds an operationsAccumulateParams to an existing operational policy
167          * 
168          * @return Policy
169          * @throws BuilderException - Policy does not exist
170          */
171         public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams) throws BuilderException;
172         
173         /**
174          * This will compile and build the YAML specification for the Control Loop Policy. Please iterate the Results object for details.
175          * The Results object will contains warnings and errors. If the specification compiled successfully, you will be able to retrieve the
176          * YAML.
177          * 
178          * @return Results
179          */
180         public Results  buildSpecification();
181         
182         /**
183          * The Factory is used to build a ControlLoopPolicyBuilder implementation.
184          * 
185          * @author pameladragosh
186          *
187          */
188         public static class Factory {
189                 
190                 /**
191                  * Builds a basic Control Loop with an overall timeout. Use this method if you wish to create an OpenLoop, or if you 
192                  * want to interactively build a Closed Loop.
193                  * 
194                  * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
195                  * @param timeout - Overall timeout for the Closed Loop to execute.
196                  * @return ControlLoopPolicyBuilder object
197                  * @throws BuilderException
198                  */
199                 public static ControlLoopPolicyBuilder  buildControlLoop (String controlLoopName, Integer timeout) throws BuilderException {
200                         
201                         ControlLoopPolicyBuilder builder = new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
202                         
203                         return builder;
204                 }               
205                 
206         }
207
208 }