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