Addressing Technical Debt for ONAP-XACML
[policy/engine.git] / ONAP-XACML / src / main / java / org / onap / policy / xacml / std / pap / StdPDPGroupStatus.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-XACML
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 package org.onap.policy.xacml.std.pap;
21
22 import java.util.Collections;
23 import java.util.HashSet;
24 import java.util.Set;
25
26 import com.att.research.xacml.api.pap.PDP;
27 import com.att.research.xacml.api.pap.PDPGroupStatus;
28 import com.att.research.xacml.api.pap.PDPPIPConfig;
29 import com.att.research.xacml.api.pap.PDPPolicy;
30 import com.fasterxml.jackson.annotation.JsonIgnore;
31
32 public class StdPDPGroupStatus implements PDPGroupStatus {
33         
34         private Status status = Status.UNKNOWN;
35         
36         private Set<String>     loadErrors = new HashSet<>();
37         
38         private Set<String> loadWarnings = new HashSet<>();
39         
40         private Set<PDPPolicy> loadedPolicies = new HashSet<>();
41         
42         private Set<PDPPolicy> failedPolicies = new HashSet<>();
43         
44         private Set<PDPPIPConfig>       loadedPIPConfigs = new HashSet<>();
45         
46         private Set<PDPPIPConfig>       failedPIPConfigs = new HashSet<>();
47         
48         private Set<PDP>                        inSynchPDPs = new HashSet<>();
49         
50         private Set<PDP>                        outOfSynchPDPs = new HashSet<>();
51         
52         private Set<PDP>                        failedPDPs = new HashSet<>();
53         
54         private Set<PDP>                        updatingPDPs = new HashSet<>();
55         
56         private Set<PDP>                        lastUpdateFailedPDPs = new HashSet<>();
57         
58         private Set<PDP>                        unknownPDPs = new HashSet<>();
59         
60         
61         
62         public StdPDPGroupStatus() {
63                 //
64                 // Constructor needed for JSON deserialization
65                 //
66         }
67         
68         public StdPDPGroupStatus(Status status) {
69                 this.status = status;
70         }
71
72         public StdPDPGroupStatus(PDPGroupStatus stat) {
73                 this.status = stat.getStatus();
74                 this.failedPDPs.clear(); this.failedPDPs.addAll(stat.getFailedPDPs());
75                 this.failedPIPConfigs.clear(); this.failedPIPConfigs.addAll(stat.getFailedPipConfigs());
76                 this.failedPolicies.clear(); this.failedPolicies.addAll(stat.getFailedPolicies());
77                 this.inSynchPDPs.clear(); this.inSynchPDPs.addAll(stat.getInSynchPDPs());
78                 this.lastUpdateFailedPDPs.clear(); this.lastUpdateFailedPDPs.addAll(stat.getLastUpdateFailedPDPs());
79                 this.loadedPIPConfigs.clear(); this.loadedPIPConfigs.addAll(stat.getLoadedPipConfigs());
80                 this.loadedPolicies.clear(); this.loadedPolicies.addAll(stat.getLoadedPolicies());
81                 this.loadErrors.clear(); this.loadErrors.addAll(stat.getLoadErrors());
82                 this.loadWarnings.clear(); this.loadWarnings.addAll(stat.getLoadWarnings());
83                 this.outOfSynchPDPs.clear(); this.outOfSynchPDPs.addAll(stat.getOutOfSynchPDPs());
84                 this.unknownPDPs.clear(); this.unknownPDPs.addAll(stat.getUpdatingPDPs());
85                 this.updatingPDPs.clear(); this.updatingPDPs.addAll(stat.getUpdatingPDPs());
86         }
87
88         public Set<PDPPIPConfig> getLoadedPIPConfigs() {
89                 return loadedPIPConfigs;
90         }
91         public void setLoadedPIPConfigs(Set<PDPPIPConfig> loadedPIPConfigs) {
92                 this.loadedPIPConfigs = loadedPIPConfigs;
93         }
94         public Set<PDPPIPConfig> getFailedPIPConfigs() {
95                 return failedPIPConfigs;
96         }
97         public void setFailedPIPConfigs(Set<PDPPIPConfig> failedPIPConfigs) {
98                 this.failedPIPConfigs = failedPIPConfigs;
99         }
100         public Set<PDP> getUnknownPDPs() {
101                 return unknownPDPs;
102         }
103         public void setUnknownPDPs(Set<PDP> unknownPDPs) {
104                 this.unknownPDPs = unknownPDPs;
105         }
106         public void setLoadErrors(Set<String> loadErrors) {
107                 this.loadErrors = loadErrors;
108         }
109         public void setLoadWarnings(Set<String> loadWarnings) {
110                 this.loadWarnings = loadWarnings;
111         }
112         public void setLoadedPolicies(Set<PDPPolicy> loadedPolicies) {
113                 this.loadedPolicies = loadedPolicies;
114         }
115         public void setFailedPolicies(Set<PDPPolicy> failedPolicies) {
116                 this.failedPolicies = failedPolicies;
117         }
118         public void setInSynchPDPs(Set<PDP> inSynchPDPs) {
119                 this.inSynchPDPs = inSynchPDPs;
120         }
121         public void setOutOfSynchPDPs(Set<PDP> outOfSynchPDPs) {
122                 this.outOfSynchPDPs = outOfSynchPDPs;
123         }
124         public void setFailedPDPs(Set<PDP> failedPDPs) {
125                 this.failedPDPs = failedPDPs;
126         }
127         public void setUpdatingPDPs(Set<PDP> updatingPDPs) {
128                 this.updatingPDPs = updatingPDPs;
129         }
130         public void setLastUpdateFailedPDPs(Set<PDP> lastUpdateFailedPDPs) {
131                 this.lastUpdateFailedPDPs = lastUpdateFailedPDPs;
132         }
133         
134
135         @Override
136         public Status getStatus() {
137                 return status;
138         }
139
140         public void setStatus(Status status) {
141                 this.status = status;
142         }
143
144         @Override
145         public Set<String> getLoadErrors() {
146                 return Collections.unmodifiableSet(this.loadErrors);
147         }
148
149         public void addLoadError(String error) {
150                 this.loadErrors.add(error);
151         }
152
153         @Override
154         public Set<String> getLoadWarnings() {
155                 return Collections.unmodifiableSet(this.loadWarnings);
156         }
157
158         public void addLoadWarning(String warning) {
159                 this.loadWarnings.add(warning);
160         }
161
162         @Override
163         public Set<PDPPolicy> getLoadedPolicies() {
164                 return Collections.unmodifiableSet(this.loadedPolicies);
165         }
166         
167         public void addLoadedPolicy(PDPPolicy policy) {
168                 this.loadedPolicies.add(policy);
169         }
170
171         @Override
172         public Set<PDPPolicy> getFailedPolicies() {
173                 return Collections.unmodifiableSet(this.failedPolicies);
174         }
175         
176         public void addFailedPolicy(PDPPolicy policy) {
177                 this.failedPolicies.add(policy);
178         }
179
180         @Override
181         public boolean policiesOK() {
182                 if (!this.failedPolicies.isEmpty()) {
183                         return false;
184                 }
185                 return true;
186         }
187
188         @Override
189         public Set<PDPPIPConfig> getLoadedPipConfigs() {
190                 return Collections.unmodifiableSet(this.loadedPIPConfigs);
191         }
192         
193         public void addLoadedPipConfig(PDPPIPConfig config) {
194                 this.loadedPIPConfigs.add(config);
195         }
196
197         @Override
198         public Set<PDPPIPConfig> getFailedPipConfigs() {
199                 return Collections.unmodifiableSet(this.failedPIPConfigs);
200         }
201         
202         public void addFailedPipConfig(PDPPIPConfig config) {
203                 this.failedPIPConfigs.add(config);
204         }
205
206         @Override
207         public boolean pipConfigOK() {
208                 if (!this.failedPIPConfigs.isEmpty()) {
209                         return false;
210                 }
211                 return true;
212         }
213
214         @Override
215         public Set<PDP> getInSynchPDPs() {
216                 return Collections.unmodifiableSet(this.inSynchPDPs);
217         }
218
219         public void addInSynchPDP(PDP pdp) {
220                 this.inSynchPDPs.add(pdp);
221         }
222
223         @Override
224         public Set<PDP> getOutOfSynchPDPs() {
225                 return Collections.unmodifiableSet(this.outOfSynchPDPs);
226         }
227
228         public void addOutOfSynchPDP(PDP pdp) {
229                 this.outOfSynchPDPs.add(pdp);
230         }
231
232         @Override
233         public Set<PDP> getFailedPDPs() {
234                 return Collections.unmodifiableSet(this.failedPDPs);
235         }
236
237         public void addFailedPDP(PDP pdp) {
238                 this.failedPDPs.add(pdp);
239         }
240
241         @Override
242         public Set<PDP> getUpdatingPDPs() {
243                 return Collections.unmodifiableSet(this.updatingPDPs);
244         }
245
246         public void addUpdatingPDP(PDP pdp) {
247                 this.updatingPDPs.add(pdp);
248         }
249
250         @Override
251         public Set<PDP> getLastUpdateFailedPDPs() {
252                 return Collections.unmodifiableSet(this.lastUpdateFailedPDPs);
253         }
254
255         public void addLastUpdateFailedPDP(PDP pdp) {
256                 this.lastUpdateFailedPDPs.add(pdp);
257         }
258
259         @Override
260         @JsonIgnore
261         public Set<PDP> getUnknownStatusPDPs() {
262                 return Collections.unmodifiableSet(this.unknownPDPs);
263         }
264
265         public void addUnknownPDP(PDP pdp) {
266                 this.unknownPDPs.add(pdp);
267         }
268
269         @Override
270         public boolean pdpsOK() {
271                 if (!this.outOfSynchPDPs.isEmpty()) {
272                         return false;
273                 }
274                 if (!this.failedPDPs.isEmpty()) {
275                         return false;
276                 }
277                 if (!this.lastUpdateFailedPDPs.isEmpty()) {
278                         return false;
279                 }
280                 if (!this.unknownPDPs.isEmpty()) {
281                         return false;
282                 }
283                 return true;
284         }
285
286         @Override
287         @JsonIgnore
288         public boolean isGroupOk() {
289                 if (this.policiesOK() == false) {
290                         return false;
291                 }
292                 if (this.pipConfigOK() == false) {
293                         return false;
294                 }
295                 if (this.pdpsOK() == false) {
296                         return false;
297                 }
298                 if (this.loadErrors.isEmpty() == false) {
299                         return false;
300                 }
301                 return this.status == Status.OK;
302         }
303         
304         public void reset() {
305                 this.status = Status.OK;
306                 
307                 this.loadErrors.clear();
308                 this.loadWarnings.clear();
309                 this.loadedPolicies.clear();
310                 this.failedPolicies.clear();
311                 this.loadedPIPConfigs.clear();
312                 this.failedPIPConfigs.clear();
313                 this.inSynchPDPs.clear();
314                 this.outOfSynchPDPs.clear();
315                 this.failedPDPs.clear();
316                 this.updatingPDPs.clear();
317                 this.lastUpdateFailedPDPs.clear();
318                 this.unknownPDPs.clear();
319         }
320
321         @Override
322         public int hashCode() {
323                 final int prime = 31;
324                 int result = 1;
325                 result = prime * result
326                                 + (failedPDPs.hashCode());
327                 result = prime
328                                 * result
329                                 + (failedPIPConfigs.hashCode());
330                 result = prime * result
331                                 + (failedPolicies.hashCode());
332                 result = prime * result
333                                 + (inSynchPDPs.hashCode());
334                 result = prime
335                                 * result
336                                 + (lastUpdateFailedPDPs.hashCode());
337                 result = prime * result
338                                 + (loadErrors.hashCode());
339                 result = prime * result
340                                 + (loadWarnings.hashCode());
341                 result = prime
342                                 * result
343                                 + (loadedPIPConfigs.hashCode());
344                 result = prime * result
345                                 + (loadedPolicies.hashCode());
346                 result = prime * result
347                                 + (outOfSynchPDPs.hashCode());
348                 result = prime * result + (status.hashCode());
349                 result = prime * result
350                                 + (unknownPDPs.hashCode());
351                 result = prime * result
352                                 + (updatingPDPs.hashCode());
353                 return result;
354         }
355
356         @Override
357         public boolean equals(Object obj) {
358                 if (this == obj)
359                         return true;
360                 if (obj == null)
361                         return false;
362                 if (getClass() != obj.getClass())
363                         return false;
364                 StdPDPGroupStatus other = (StdPDPGroupStatus) obj;
365                 if (!failedPDPs.equals(other.failedPDPs))
366                         return false;
367                 if (!failedPIPConfigs.equals(other.failedPIPConfigs))
368                         return false;
369                 if (!failedPolicies.equals(other.failedPolicies))
370                         return false;
371                 if (!inSynchPDPs.equals(other.inSynchPDPs))
372                         return false;
373                 if (!lastUpdateFailedPDPs.equals(other.lastUpdateFailedPDPs))
374                         return false;
375                 if (!loadErrors.equals(other.loadErrors))
376                         return false;
377                 if (!loadWarnings.equals(other.loadWarnings))
378                         return false;
379                 if (!loadedPIPConfigs.equals(other.loadedPIPConfigs))
380                         return false;
381                 if (!loadedPolicies.equals(other.loadedPolicies))
382                         return false;
383                 if (!outOfSynchPDPs.equals(other.outOfSynchPDPs))
384                         return false;
385                 if (status != other.status)
386                         return false;
387                 if (!unknownPDPs.equals(other.unknownPDPs))
388                         return false;
389                 if (!updatingPDPs.equals(other.updatingPDPs))
390                         return false;
391                 return true;
392         }
393
394         @Override
395         public String toString() {
396                 return "StdPDPGroupStatus [status=" + status + ", loadErrors="
397                                 + loadErrors + ", loadWarnings=" + loadWarnings
398                                 + ", loadedPolicies=" + loadedPolicies + ", failedPolicies="
399                                 + failedPolicies + ", loadedPIPConfigs=" + loadedPIPConfigs
400                                 + ", failedPIPConfigs=" + failedPIPConfigs + ", inSynchPDPs="
401                                 + inSynchPDPs + ", outOfSynchPDPs=" + outOfSynchPDPs
402                                 + ", failedPDPs=" + failedPDPs + ", updatingPDPs="
403                                 + updatingPDPs + ", lastUpdateFailedPDPs="
404                                 + lastUpdateFailedPDPs + ", unknownPDPs=" + unknownPDPs + "]";
405         }
406
407 }