aboutsummaryrefslogtreecommitdiffstats
path: root/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/policy/builder/ControlLoopPolicyBuilder.java
blob: 2fdb6d9df8c56009501599e26f3320581b59657c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*-
 * ============LICENSE_START=======================================================
 * ECOMP Policy Engine
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.policy.controlloop.policy.builder;

import java.util.Map;

import org.openecomp.policy.asdc.Resource;
import org.openecomp.policy.asdc.Service;
import org.openecomp.policy.controlloop.policy.ControlLoop;
import org.openecomp.policy.controlloop.policy.OperationsAccumulateParams;
import org.openecomp.policy.controlloop.policy.Policy;
import org.openecomp.policy.controlloop.policy.PolicyResult;
import org.openecomp.policy.controlloop.policy.Target;
import org.openecomp.policy.controlloop.policy.builder.impl.ControlLoopPolicyBuilderImpl;

public interface ControlLoopPolicyBuilder {
	
	/**
	 * Adds one or more services to the ControlLoop
	 * 
	 * 
	 * @param service
	 * @return
	 * @throws BuilderException
	 */
	public ControlLoopPolicyBuilder	addService(Service... services) throws BuilderException;
	
	/**
	 * @param services
	 * @return
	 * @throws BuilderException
	 */
	public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
	
	/**
	 * @return
	 * @throws BuilderException
	 */
	public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
	
	/**
	 * Adds one or more resources to the ControlLoop
	 * 
	 * 
	 * @param resource
	 * @return
	 * @throws BuilderException
	 */
	public ControlLoopPolicyBuilder	addResource(Resource... resources) throws BuilderException;
	
	/**
	 * @param resources
	 * @return
	 * @throws BuilderException
	 */
	public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
	
	/**
	 * @return
	 * @throws BuilderException
	 */
	public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
	
	/**
	 *  @param abatement
	 *  @return
	 *  @throws BuilderException
	 */
	public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
	
	
	/**
	 * Sets the overall timeout value for the Control Loop. If any operational policies have retries and timeouts,
	 * then this overall timeout value should exceed all those values.
	 * 
	 * @param timeout
	 * @return
	 * @throws BuilderException
	 */
	public ControlLoopPolicyBuilder	setTimeout(Integer timeout) throws BuilderException;
	
	/**
	 * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
	 * 
	 * 
	 * @return Integer
	 */
	public Integer calculateTimeout();
	
	/**
	 * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ECOMP Policy Platform.
	 * 
	 * 
	 * @param name
	 * @param description
	 * @param actor
	 * @param target
	 * @param recipe
	 * @param retries
	 * @param timeout
	 * @return Policy
	 * @throws BuilderException
	 */
	public Policy setTriggerPolicy(String name, String description, String actor, Target target, String recipe, Map<String, String> payload, Integer retries, Integer timeout) throws BuilderException;
	
	/**
	 * 
	 * Changes the trigger policy to point to another existing Policy.
	 * 
	 * 
	 * @param id
	 * @return ControlLoop
	 * @throws BuilderException
	 */
	public ControlLoop	setTriggerPolicy(String id) throws BuilderException;
	
	/**
	 * @return
	 */
	public boolean	isOpenLoop();
	
	/**
	 * @return
	 * @throws BuilderException
	 */
	public Policy	getTriggerPolicy() throws BuilderException;
	
	/**
	 * Simply returns a copy of the ControlLoop information.
	 * 
	 * 
	 * @return ControlLoop
	 */
	public ControlLoop	getControlLoop();
	
	/**
	 * Creates a policy that is chained to the result of another Policy.
	 * 
	 * 
	 * @param name
	 * @param description
	 * @param actor
	 * @param target
	 * @param recipe
	 * @param retries
	 * @param timeout
	 * @param policyID
	 * @param results
	 * @return
	 * @throws BuilderException
	 */
	public Policy setPolicyForPolicyResult(String name, String description, String actor,
			Target target, String recipe, Map<String, String> payload, Integer retries, Integer timeout, String policyID, PolicyResult... results) throws BuilderException;
	
	
	/**
	 * Sets the policy result(s) to an existing Operational Policy.
	 * 
	 * 
	 * @param policyResultID
	 * @param policyID
	 * @param results
	 * @return
	 * @throws BuilderException
	 */
	public Policy setPolicyForPolicyResult(String policyResultID, String policyID, PolicyResult... results) throws BuilderException;
	
	/**
	 * Removes an Operational Policy. Be mindful that if any other Operational Policies have results that point to this policy, any
	 * policies that have results pointing to this policy will have their result reset to the appropriate default FINAL_* result.
	 * 
	 * 
	 * @param policyID
	 * @return
	 * @throws BuilderException
	 */
	public boolean removePolicy(String policyID) throws BuilderException;
	
	/**
	 * Resets a policy's results to defualt FINAL_* codes.
	 * 
	 * 
	 * @return Policy
	 * @throws BuilderException - Policy does not exist
	 */
	public Policy	resetPolicyResults(String policyID) throws BuilderException;
	
	/**
	 * Removes all existing Operational Policies and reverts back to an Open Loop.
	 * 
	 * @return
	 */
	public ControlLoopPolicyBuilder	removeAllPolicies();
		
	/**
	 * Adds an operationsAccumulateParams to an existing operational policy
	 * 
	 * @return Policy
	 * @throws BuilderException - Policy does not exist
	 */
	public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams) throws BuilderException;
	
	/**
	 * This will compile and build the YAML specification for the Control Loop Policy. Please iterate the Results object for details.
	 * The Results object will contains warnings and errors. If the specification compiled successfully, you will be able to retrieve the
	 * YAML.
	 * 
	 * @return Results
	 */
	public Results	buildSpecification();
	
	/**
	 * The Factory is used to build a ControlLoopPolicyBuilder implementation.
	 * 
	 * @author pameladragosh
	 *
	 */
	public static class Factory {
		private Factory(){
			// Private Constructor.
		}
		
		/**
		 * Builds a basic Control Loop with an overall timeout. Use this method if you wish to create an OpenLoop, or if you 
		 * want to interactively build a Closed Loop.
		 * 
		 * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
		 * @param timeout - Overall timeout for the Closed Loop to execute.
		 * @return ControlLoopPolicyBuilder object
		 * @throws BuilderException
		 */
		public static ControlLoopPolicyBuilder	buildControlLoop (String controlLoopName, Integer timeout) throws BuilderException {
			return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
		}
		
		/**
		 * Build a Control Loop for a resource and services associated with the resource.
		 * 
		 * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
		 * @param timeout - Overall timeout for the Closed Loop to execute.
		 * @param resource - Resource this closed loop is for. Should come from ASDC, but if not available use resourceName to distinguish.
		 * @param services - Zero or more services associated with this resource. Should come from ASDC, but if not available use serviceName to distinguish.
		 * @return ControlLoopPolicyBuilder object
		 * @throws BuilderException
		 */
		public static ControlLoopPolicyBuilder	buildControlLoop (String controlLoopName, Integer timeout, Resource resource, Service... services) throws BuilderException {
			
			ControlLoopPolicyBuilder builder = new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
			
			return builder;
		}
		
		/**
		 * @param controlLoopName
		 * @param timeout
		 * @param service
		 * @param resources
		 * @return
		 * @throws BuilderException
		 */
		public static ControlLoopPolicyBuilder	buildControlLoop (String controlLoopName, Integer timeout, Service service, Resource... resources) throws BuilderException {
			
			ControlLoopPolicyBuilder builder = new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
			
			return builder;
		}
	}

}