Commit includes ControlLoopPolicy API and bugfixes
[policy/engine.git] / ECOMP-ControlloopPolicy / src / main / java / org / openecomp / policy / controlloop / policy / Policy.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;
22
23 import java.util.Collections;
24 import java.util.Map;
25 import java.util.UUID;
26
27 public class Policy {
28
29         private String id = UUID.randomUUID().toString();
30         private String name;
31         private String description;
32         private String actor;
33         private String recipe;
34         private Map<String, String> payload;
35         private Target target;
36         private OperationsAccumulateParams operationsAccumulateParams;
37         private Integer retry = 0;
38         private Integer timeout = 300;
39         private String success = FinalResult.FINAL_SUCCESS.toString();
40         private String failure = FinalResult.FINAL_FAILURE.toString();
41         private String failure_retries = FinalResult.FINAL_FAILURE_RETRIES.toString();
42         private String failure_timeout = FinalResult.FINAL_FAILURE_TIMEOUT.toString();
43         private String failure_exception = FinalResult.FINAL_FAILURE_EXCEPTION.toString();
44         private String failure_guard = FinalResult.FINAL_FAILURE_GUARD.toString();
45         
46         
47         public Policy() {
48                 //Does Nothing Empty Constructor
49         }
50         
51         public String getId() {
52                 return id;
53         }
54
55         public void setId(String id) {
56                 this.id = id;
57         }
58
59         public String getName() {
60                 return name;
61         }
62
63         public void setName(String name) {
64                 this.name = name;
65         }
66
67         public String getDescription() {
68                 return description;
69         }
70
71         public void setDescription(String description) {
72                 this.description = description;
73         }
74
75         public String getActor() {
76                 return actor;
77         }
78
79         public void setActor(String actor) {
80                 this.actor = actor;
81         }
82
83         public String getRecipe() {
84                 return recipe;
85         }
86
87         public void setRecipe(String recipe) {
88                 this.recipe = recipe;
89         }
90
91         public Map<String, String> getPayload() {
92                 return payload;
93         }
94
95         public void setPayload(Map<String, String> payload) {
96                 this.payload = payload;
97         }
98
99         public Target getTarget() {
100                 return target;
101         }
102
103         public void setTarget(Target target) {
104                 this.target = target;
105         }
106
107         public OperationsAccumulateParams getOperationsAccumulateParams() {
108                 return operationsAccumulateParams;
109         }
110
111         public void setOperationsAccumulateParams(OperationsAccumulateParams operationsAccumulateParams) {
112                 this.operationsAccumulateParams = operationsAccumulateParams;
113         }
114
115         public Integer getRetry() {
116                 return retry;
117         }
118
119         public void setRetry(Integer retry) {
120                 this.retry = retry;
121         }
122
123         public Integer getTimeout() {
124                 return timeout;
125         }
126
127         public void setTimeout(Integer timeout) {
128                 this.timeout = timeout;
129         }
130
131         public String getSuccess() {
132                 return success;
133         }
134
135         public void setSuccess(String success) {
136                 this.success = success;
137         }
138
139         public String getFailure() {
140                 return failure;
141         }
142
143         public void setFailure(String failure) {
144                 this.failure = failure;
145         }
146
147         public String getFailure_retries() {
148                 return failure_retries;
149         }
150
151         public void setFailure_retries(String failure_retries) {
152                 this.failure_retries = failure_retries;
153         }
154
155         public String getFailure_timeout() {
156                 return failure_timeout;
157         }
158
159         public void setFailure_timeout(String failure_timeout) {
160                 this.failure_timeout = failure_timeout;
161         }
162
163         public String getFailure_exception() {
164                 return failure_exception;
165         }
166
167         public void setFailure_exception(String failure_exception) {
168                 this.failure_exception = failure_exception;
169         }
170
171         public String getFailure_guard() {
172                 return failure_guard;
173         }
174
175         public void setFailure_guard(String failure_guard) {
176                 this.failure_guard = failure_guard;
177         }
178
179         public Policy(String id) {
180                 this.id = id;
181         }
182         
183         public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target) {
184                 this.name = name;
185                 this.actor = actor;
186                 this.recipe = recipe;
187                 this.target = target;
188                 if (payload != null) {
189                         this.payload = Collections.unmodifiableMap(payload);
190                 }
191         }
192         
193         public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target, Integer retries, Integer timeout) {
194                 this(name, actor, recipe, payload, target);
195                 this.retry = retries;
196                 this.timeout = timeout;
197         }
198         
199         public Policy(String id, String name, String description, String actor, Map<String, String> payload, Target target, String recipe, Integer retries, Integer timeout) {
200                 this(name, actor, recipe, payload, target, retries, timeout);
201                 this.id = id;
202                 this.description = description;
203         }
204         
205         public Policy(Policy policy) {
206                 this.id = policy.id;
207                 this.name = policy.name;
208                 this.description = policy.description;
209                 this.actor = policy.actor;
210                 this.recipe = policy.recipe;
211                 if (policy.payload != null) {
212                         this.payload = Collections.unmodifiableMap(policy.payload);
213                 }
214                 this.target = policy.target;
215                 this.operationsAccumulateParams = policy.operationsAccumulateParams;
216                 this.retry = policy.retry;
217                 this.timeout = policy.timeout;
218                 this.success = policy.success;
219                 this.failure = policy.failure;
220                 this.failure_exception = policy.failure_exception;
221                 this.failure_guard = policy.failure_guard;
222                 this.failure_retries = policy.failure_retries;
223                 this.failure_timeout = policy.failure_timeout;
224         }
225
226         public boolean isValid() {
227                 if(id==null || name==null || actor==null|| recipe==null || target==null){
228                         return false;
229                 }
230                 return true;
231         }
232
233         @Override
234         public String toString() {
235                 return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", actor=" + actor + ", recipe="
236                                 + recipe + ", payload=" + payload + ", target=" + target + ", operationsAccumulateParams=" + operationsAccumulateParams + ", retry=" + retry + ", timeout=" + timeout
237                                 + ", success=" + success + ", failure=" + failure + ", failure_retries=" + failure_retries
238                                 + ", failure_timeout=" + failure_timeout + ", failure_exception=" + failure_exception + ", failure_guard=" + failure_guard + "]";
239         }
240
241         @Override
242         public int hashCode() {
243                 final int prime = 31;
244                 int result = 1;
245                 result = prime * result + ((actor == null) ? 0 : actor.hashCode());
246                 result = prime * result + ((description == null) ? 0 : description.hashCode());
247                 result = prime * result + ((failure == null) ? 0 : failure.hashCode());
248                 result = prime * result + ((failure_exception == null) ? 0 : failure_exception.hashCode());
249                 result = prime * result + ((failure_guard == null) ? 0 : failure_guard.hashCode());
250                 result = prime * result + ((failure_retries == null) ? 0 : failure_retries.hashCode());
251                 result = prime * result + ((failure_timeout == null) ? 0 : failure_timeout.hashCode());
252                 result = prime * result + ((id == null) ? 0 : id.hashCode());
253                 result = prime * result + ((name == null) ? 0 : name.hashCode());
254                 result = prime * result + ((payload == null) ? 0 : payload.hashCode());
255                 result = prime * result + ((recipe == null) ? 0 : recipe.hashCode());
256                 result = prime * result + ((retry == null) ? 0 : retry.hashCode());
257                 result = prime * result + ((success == null) ? 0 : success.hashCode());
258                 result = prime * result + ((target == null) ? 0 : target.hashCode());
259                 result = prime * result + ((operationsAccumulateParams == null) ? 0 : operationsAccumulateParams.hashCode());
260                 result = prime * result + ((timeout == null) ? 0 : timeout.hashCode());
261                 return result;
262         }
263
264         @Override
265         public boolean equals(Object obj) {
266                 if (this == obj)
267                         return true;
268                 if (obj == null)
269                         return false;
270                 if (getClass() != obj.getClass())
271                         return false;
272                 Policy other = (Policy) obj;
273                 if (actor != other.actor)
274                         return false;
275                 if (description == null) {
276                         if (other.description != null)
277                                 return false;
278                 } else if (!description.equals(other.description))
279                         return false;
280                 if (failure == null) {
281                         if (other.failure != null)
282                                 return false;
283                 } else if (!failure.equals(other.failure))
284                         return false;
285                 if (failure_exception == null) {
286                         if (other.failure_exception != null)
287                                 return false;
288                 } else if (!failure_exception.equals(other.failure_exception))
289                         return false;
290                 if (failure_guard == null) {
291                         if (other.failure_guard != null)
292                                 return false;
293                 } else if (!failure_guard.equals(other.failure_guard))
294                         return false;
295                 if (failure_retries == null) {
296                         if (other.failure_retries != null)
297                                 return false;
298                 } else if (!failure_retries.equals(other.failure_retries))
299                         return false;
300                 if (failure_timeout == null) {
301                         if (other.failure_timeout != null)
302                                 return false;
303                 } else if (!failure_timeout.equals(other.failure_timeout))
304                         return false;
305                 if (id == null) {
306                         if (other.id != null)
307                                 return false;
308                 } else if (!id.equals(other.id))
309                         return false;
310                 if (name == null) {
311                         if (other.name != null)
312                                 return false;
313                 } else if (!name.equals(other.name))
314                         return false;
315                 if (payload == null) {
316                         if (other.payload != null)
317                                 return false;
318                 } else if (!payload.equals(other.payload))
319                         return false;
320                 if (recipe == null) {
321                         if (other.recipe != null)
322                                 return false;
323                 } else if (!recipe.equals(other.recipe))
324                         return false;
325                 if (retry == null) {
326                         if (other.retry != null)
327                                 return false;
328                 } else if (!retry.equals(other.retry))
329                         return false;
330                 if (success == null) {
331                         if (other.success != null)
332                                 return false;
333                 } else if (!success.equals(other.success))
334                         return false;
335                 if (operationsAccumulateParams == null) {
336                         if (other.operationsAccumulateParams != null)
337                                 return false;
338                 } else if (!operationsAccumulateParams.equals(other.operationsAccumulateParams))
339                         return false;
340                 if (target == null) {
341                         if (other.target != null)
342                                 return false;
343                 } else if (!target.equals(other.target))
344                         return false;   
345                 if (timeout == null) {
346                         if (other.timeout != null)
347                                 return false;
348                 } else if (!timeout.equals(other.timeout))
349                         return false;
350                 return true;
351         }
352         
353 }