2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.policy.xacml.std.pap;
22 import java.util.Collections;
23 import java.util.HashSet;
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;
32 public class StdPDPGroupStatus implements PDPGroupStatus {
34 private Status status = Status.UNKNOWN;
36 private Set<String> loadErrors = new HashSet<>();
38 private Set<String> loadWarnings = new HashSet<>();
40 private Set<PDPPolicy> loadedPolicies = new HashSet<>();
42 private Set<PDPPolicy> failedPolicies = new HashSet<>();
44 private Set<PDPPIPConfig> loadedPIPConfigs = new HashSet<>();
46 private Set<PDPPIPConfig> failedPIPConfigs = new HashSet<>();
48 private Set<PDP> inSynchPDPs = new HashSet<>();
50 private Set<PDP> outOfSynchPDPs = new HashSet<>();
52 private Set<PDP> failedPDPs = new HashSet<>();
54 private Set<PDP> updatingPDPs = new HashSet<>();
56 private Set<PDP> lastUpdateFailedPDPs = new HashSet<>();
58 private Set<PDP> unknownPDPs = new HashSet<>();
62 public StdPDPGroupStatus() {
64 // Constructor needed for JSON deserialization
68 public StdPDPGroupStatus(Status status) {
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());
100 public Set<PDPPIPConfig> getLoadedPIPConfigs() {
101 return loadedPIPConfigs;
103 public void setLoadedPIPConfigs(Set<PDPPIPConfig> loadedPIPConfigs) {
104 this.loadedPIPConfigs = loadedPIPConfigs;
106 public Set<PDPPIPConfig> getFailedPIPConfigs() {
107 return failedPIPConfigs;
109 public void setFailedPIPConfigs(Set<PDPPIPConfig> failedPIPConfigs) {
110 this.failedPIPConfigs = failedPIPConfigs;
112 public Set<PDP> getUnknownPDPs() {
115 public void setUnknownPDPs(Set<PDP> unknownPDPs) {
116 this.unknownPDPs = unknownPDPs;
118 public void setLoadErrors(Set<String> loadErrors) {
119 this.loadErrors = loadErrors;
121 public void setLoadWarnings(Set<String> loadWarnings) {
122 this.loadWarnings = loadWarnings;
124 public void setLoadedPolicies(Set<PDPPolicy> loadedPolicies) {
125 this.loadedPolicies = loadedPolicies;
127 public void setFailedPolicies(Set<PDPPolicy> failedPolicies) {
128 this.failedPolicies = failedPolicies;
130 public void setInSynchPDPs(Set<PDP> inSynchPDPs) {
131 this.inSynchPDPs = inSynchPDPs;
133 public void setOutOfSynchPDPs(Set<PDP> outOfSynchPDPs) {
134 this.outOfSynchPDPs = outOfSynchPDPs;
136 public void setFailedPDPs(Set<PDP> failedPDPs) {
137 this.failedPDPs = failedPDPs;
139 public void setUpdatingPDPs(Set<PDP> updatingPDPs) {
140 this.updatingPDPs = updatingPDPs;
142 public void setLastUpdateFailedPDPs(Set<PDP> lastUpdateFailedPDPs) {
143 this.lastUpdateFailedPDPs = lastUpdateFailedPDPs;
148 public Status getStatus() {
152 public void setStatus(Status status) {
153 this.status = status;
157 public Set<String> getLoadErrors() {
158 return Collections.unmodifiableSet(this.loadErrors);
161 public void addLoadError(String error) {
162 this.loadErrors.add(error);
166 public Set<String> getLoadWarnings() {
167 return Collections.unmodifiableSet(this.loadWarnings);
170 public void addLoadWarning(String warning) {
171 this.loadWarnings.add(warning);
175 public Set<PDPPolicy> getLoadedPolicies() {
176 return Collections.unmodifiableSet(this.loadedPolicies);
179 public void addLoadedPolicy(PDPPolicy policy) {
180 this.loadedPolicies.add(policy);
184 public Set<PDPPolicy> getFailedPolicies() {
185 return Collections.unmodifiableSet(this.failedPolicies);
188 public void addFailedPolicy(PDPPolicy policy) {
189 this.failedPolicies.add(policy);
193 public boolean policiesOK() {
194 if (!this.failedPolicies.isEmpty()) {
201 public Set<PDPPIPConfig> getLoadedPipConfigs() {
202 return Collections.unmodifiableSet(this.loadedPIPConfigs);
205 public void addLoadedPipConfig(PDPPIPConfig config) {
206 this.loadedPIPConfigs.add(config);
210 public Set<PDPPIPConfig> getFailedPipConfigs() {
211 return Collections.unmodifiableSet(this.failedPIPConfigs);
214 public void addFailedPipConfig(PDPPIPConfig config) {
215 this.failedPIPConfigs.add(config);
219 public boolean pipConfigOK() {
220 if (!this.failedPIPConfigs.isEmpty()) {
227 public Set<PDP> getInSynchPDPs() {
228 return Collections.unmodifiableSet(this.inSynchPDPs);
231 public void addInSynchPDP(PDP pdp) {
232 this.inSynchPDPs.add(pdp);
236 public Set<PDP> getOutOfSynchPDPs() {
237 return Collections.unmodifiableSet(this.outOfSynchPDPs);
240 public void addOutOfSynchPDP(PDP pdp) {
241 this.outOfSynchPDPs.add(pdp);
245 public Set<PDP> getFailedPDPs() {
246 return Collections.unmodifiableSet(this.failedPDPs);
249 public void addFailedPDP(PDP pdp) {
250 this.failedPDPs.add(pdp);
254 public Set<PDP> getUpdatingPDPs() {
255 return Collections.unmodifiableSet(this.updatingPDPs);
258 public void addUpdatingPDP(PDP pdp) {
259 this.updatingPDPs.add(pdp);
263 public Set<PDP> getLastUpdateFailedPDPs() {
264 return Collections.unmodifiableSet(this.lastUpdateFailedPDPs);
267 public void addLastUpdateFailedPDP(PDP pdp) {
268 this.lastUpdateFailedPDPs.add(pdp);
273 public Set<PDP> getUnknownStatusPDPs() {
274 return Collections.unmodifiableSet(this.unknownPDPs);
277 public void addUnknownPDP(PDP pdp) {
278 this.unknownPDPs.add(pdp);
282 public boolean pdpsOK() {
283 if (!this.outOfSynchPDPs.isEmpty()) {
286 if (!this.failedPDPs.isEmpty()) {
289 if (!this.lastUpdateFailedPDPs.isEmpty()) {
292 if (!this.unknownPDPs.isEmpty()) {
300 public boolean isGroupOk() {
301 if (!this.policiesOK()) {
304 if (!this.pipConfigOK()) {
307 if (!this.pdpsOK()) {
310 if (!this.loadErrors.isEmpty()) {
313 return this.status == Status.OK;
316 public void reset() {
317 this.status = Status.OK;
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();
334 public int hashCode() {
335 final int prime = 31;
337 result = prime * result
338 + (failedPDPs.hashCode());
341 + (failedPIPConfigs.hashCode());
342 result = prime * result
343 + (failedPolicies.hashCode());
344 result = prime * result
345 + (inSynchPDPs.hashCode());
348 + (lastUpdateFailedPDPs.hashCode());
349 result = prime * result
350 + (loadErrors.hashCode());
351 result = prime * result
352 + (loadWarnings.hashCode());
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());
369 public boolean equals(Object obj) {
374 if (getClass() != obj.getClass())
376 StdPDPGroupStatus other = (StdPDPGroupStatus) obj;
377 if (!failedPDPs.equals(other.failedPDPs))
379 if (!failedPIPConfigs.equals(other.failedPIPConfigs))
381 if (!failedPolicies.equals(other.failedPolicies))
383 if (!inSynchPDPs.equals(other.inSynchPDPs))
385 if (!lastUpdateFailedPDPs.equals(other.lastUpdateFailedPDPs))
387 if (!loadErrors.equals(other.loadErrors))
389 if (!loadWarnings.equals(other.loadWarnings))
391 if (!loadedPIPConfigs.equals(other.loadedPIPConfigs))
393 if (!loadedPolicies.equals(other.loadedPolicies))
395 if (!outOfSynchPDPs.equals(other.outOfSynchPDPs))
397 if (status != other.status)
399 if (!unknownPDPs.equals(other.unknownPDPs))
401 if (!updatingPDPs.equals(other.updatingPDPs))
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 + "]";