0af1eab68e4f87e06411ad2f24d7368ae1381a3c
[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         public String id = UUID.randomUUID().toString();
30         public String name;
31         public String description;
32         public String actor;
33         public String recipe;
34         public Map<String, String> payload;
35         public Target target;
36         public OperationsAccumulateParams operationsAccumulateParams;
37         public Integer retry = 0;
38         public Integer timeout = 300;
39         public String success = FinalResult.FINAL_SUCCESS.toString();
40         public String failure = FinalResult.FINAL_FAILURE.toString();
41         public String failure_retries = FinalResult.FINAL_FAILURE_RETRIES.toString();
42         public String failure_timeout = FinalResult.FINAL_FAILURE_TIMEOUT.toString();
43         public String failure_exception = FinalResult.FINAL_FAILURE_EXCEPTION.toString();
44         public String failure_guard = FinalResult.FINAL_FAILURE_GUARD.toString();
45         
46         
47         public Policy() {
48                 
49         }
50         
51         public Policy(String id) {
52                 this.id = id;
53         }
54         
55         public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target) {
56                 this.name = name;
57                 this.actor = actor;
58                 this.recipe = recipe;
59                 this.target = target;
60                 if (payload != null) {
61 //                      this.payload = new LinkedList<Map<String, String>>();
62                         this.payload = Collections.unmodifiableMap(payload);
63                 }
64         }
65         
66         public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target, Integer retries, Integer timeout) {
67                 this(name, actor, recipe, payload, target);
68                 this.retry = retries;
69                 this.timeout = timeout;
70         }
71         
72         public Policy(String id, String name, String description, String actor, Map<String, String> payload, Target target, String recipe, Integer retries, Integer timeout) {
73                 this(name, actor, recipe, payload, target, retries, timeout);
74                 this.id = id;
75                 this.description = description;
76         }
77         
78         public Policy(Policy policy) {
79                 this.id = policy.id;
80                 this.name = policy.name;
81                 this.description = policy.description;
82                 this.actor = policy.actor;
83                 this.recipe = policy.recipe;
84                 if (policy.payload != null) {
85 //                      this.payload = new LinkedList<Map<String, String>>();
86 //                      this.payload.addAll(policy.payload);
87                         this.payload = Collections.unmodifiableMap(policy.payload);
88                 }
89                 this.target = policy.target;
90                 this.operationsAccumulateParams = policy.operationsAccumulateParams;
91                 this.retry = policy.retry;
92                 this.timeout = policy.timeout;
93                 this.success = policy.success;
94                 this.failure = policy.failure;
95                 this.failure_exception = policy.failure_exception;
96                 this.failure_guard = policy.failure_guard;
97                 this.failure_retries = policy.failure_retries;
98                 this.failure_timeout = policy.failure_timeout;
99         }
100
101         public boolean isValid() {
102                 try {
103                         if (id == null) {
104                                 throw new NullPointerException();
105                         }
106                         if (name == null) {
107                                 throw new NullPointerException();
108                         }
109                         if (actor == null) {
110                                 throw new NullPointerException();
111                         }
112                         if (recipe == null) {
113                                 throw new NullPointerException();
114                         }
115                         if (target == null) {
116                                 throw new NullPointerException();
117                         }
118                 } catch (Exception e) {
119                         return false;
120                 }
121                 
122                 return true;
123         }
124
125         @Override
126         public String toString() {
127                 return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", actor=" + actor + ", recipe="
128                                 + recipe + ", payload=" + payload + ", target=" + target + ", operationsAccumulateParams=" + operationsAccumulateParams + ", retry=" + retry + ", timeout=" + timeout
129                                 + ", success=" + success + ", failure=" + failure + ", failure_retries=" + failure_retries
130                                 + ", failure_timeout=" + failure_timeout + ", failure_exception=" + failure_exception + ", failure_guard=" + failure_guard + "]";
131         }
132
133         @Override
134         public int hashCode() {
135                 final int prime = 31;
136                 int result = 1;
137                 result = prime * result + ((actor == null) ? 0 : actor.hashCode());
138                 result = prime * result + ((description == null) ? 0 : description.hashCode());
139                 result = prime * result + ((failure == null) ? 0 : failure.hashCode());
140                 result = prime * result + ((failure_exception == null) ? 0 : failure_exception.hashCode());
141                 result = prime * result + ((failure_guard == null) ? 0 : failure_guard.hashCode());
142                 result = prime * result + ((failure_retries == null) ? 0 : failure_retries.hashCode());
143                 result = prime * result + ((failure_timeout == null) ? 0 : failure_timeout.hashCode());
144                 result = prime * result + ((id == null) ? 0 : id.hashCode());
145                 result = prime * result + ((name == null) ? 0 : name.hashCode());
146                 result = prime * result + ((payload == null) ? 0 : payload.hashCode());
147                 result = prime * result + ((recipe == null) ? 0 : recipe.hashCode());
148                 result = prime * result + ((retry == null) ? 0 : retry.hashCode());
149                 result = prime * result + ((success == null) ? 0 : success.hashCode());
150                 result = prime * result + ((target == null) ? 0 : target.hashCode());
151                 result = prime * result + ((operationsAccumulateParams == null) ? 0 : operationsAccumulateParams.hashCode());
152                 result = prime * result + ((timeout == null) ? 0 : timeout.hashCode());
153                 return result;
154         }
155
156         @Override
157         public boolean equals(Object obj) {
158                 if (this == obj)
159                         return true;
160                 if (obj == null)
161                         return false;
162                 if (getClass() != obj.getClass())
163                         return false;
164                 Policy other = (Policy) obj;
165                 if (actor != other.actor)
166                         return false;
167                 if (description == null) {
168                         if (other.description != null)
169                                 return false;
170                 } else if (!description.equals(other.description))
171                         return false;
172                 if (failure == null) {
173                         if (other.failure != null)
174                                 return false;
175                 } else if (!failure.equals(other.failure))
176                         return false;
177                 if (failure_exception == null) {
178                         if (other.failure_exception != null)
179                                 return false;
180                 } else if (!failure_exception.equals(other.failure_exception))
181                         return false;
182                 if (failure_guard == null) {
183                         if (other.failure_guard != null)
184                                 return false;
185                 } else if (!failure_guard.equals(other.failure_guard))
186                         return false;
187                 if (failure_retries == null) {
188                         if (other.failure_retries != null)
189                                 return false;
190                 } else if (!failure_retries.equals(other.failure_retries))
191                         return false;
192                 if (failure_timeout == null) {
193                         if (other.failure_timeout != null)
194                                 return false;
195                 } else if (!failure_timeout.equals(other.failure_timeout))
196                         return false;
197                 if (id == null) {
198                         if (other.id != null)
199                                 return false;
200                 } else if (!id.equals(other.id))
201                         return false;
202                 if (name == null) {
203                         if (other.name != null)
204                                 return false;
205                 } else if (!name.equals(other.name))
206                         return false;
207                 if (payload == null) {
208                         if (other.payload != null)
209                                 return false;
210                 } else if (!payload.equals(other.payload))
211                         return false;
212                 if (recipe == null) {
213                         if (other.recipe != null)
214                                 return false;
215                 } else if (!recipe.equals(other.recipe))
216                         return false;
217                 if (retry == null) {
218                         if (other.retry != null)
219                                 return false;
220                 } else if (!retry.equals(other.retry))
221                         return false;
222                 if (success == null) {
223                         if (other.success != null)
224                                 return false;
225                 } else if (!success.equals(other.success))
226                         return false;
227                 if (operationsAccumulateParams == null) {
228                         if (other.operationsAccumulateParams != null)
229                                 return false;
230                 } else if (!operationsAccumulateParams.equals(other.operationsAccumulateParams))
231                         return false;
232                 if (target == null) {
233                         if (other.target != null)
234                                 return false;
235                 } else if (!target.equals(other.target))
236                         return false;   
237                 if (timeout == null) {
238                         if (other.timeout != null)
239                                 return false;
240                 } else if (!timeout.equals(other.timeout))
241                         return false;
242                 return true;
243         }
244         
245 }