X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-XACML%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fxacml%2Fstd%2Fpap%2FStdPDPGroup.java;h=bdbbf33f75511e474a86e14829108b0bee47a157;hb=6a44b2926f33b427904c2f3e7962d0dfc360c482;hp=28f6a4d035367230914c935f752cc1722211e810;hpb=80f072f60509ef3a35369a60857fe05f6c2a993a;p=policy%2Fengine.git diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java index 28f6a4d03..bdbbf33f7 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,6 @@ import org.onap.policy.xacml.std.pap.StdPDPItemSetChangeNotifier.StdItemSetChang import com.att.research.xacml.api.pap.PAPException; import com.att.research.xacml.api.pap.PDP; -//import com.att.research.xacml.api.pap.PDPGroup; import com.att.research.xacml.api.pap.PDPGroupStatus; import com.att.research.xacml.api.pap.PDPGroupStatus.Status; import com.att.research.xacml.api.pap.PDPPIPConfig; @@ -59,7 +58,9 @@ import com.google.common.base.Splitter; import com.google.common.io.ByteStreams; public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPGroup, StdItemSetChangeListener, Comparable, Serializable { + private static final long serialVersionUID = 1L; + private static final String groupNotExist= "Group directory does NOT exist"; private static Log logger = LogFactory.getLog(StdPDPGroup.class); private String id; @@ -88,6 +89,21 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG @JsonIgnore private Integer jmxport; + public StdPDPGroup() { + // + // Methods needed for JSON deserialization + // + } + + public StdPDPGroup(OnapPDPGroup group) { + this.id = group.getId(); + this.name = group.getName(); + this.description = group.getDescription(); + this.isDefault = group.isDefaultGroup(); + this.pdps = group.getOnapPdps(); + this.policies = group.getPolicies(); + this.pipConfigs = group.getPipConfigs(); + } public StdPDPGroup(String id, Path directory) { this.id = id; @@ -137,8 +153,8 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } else if (key.toString().endsWith(".pdps")) { String pdpList = properties.getProperty(key.toString()); if (pdpList != null && pdpList.length() > 0) { - for (String id : Splitter.on(',').omitEmptyStrings().trimResults().split(pdpList)) { - StdPDP pdp = new StdPDP(id, properties); + for (String pdpId : Splitter.on(',').omitEmptyStrings().trimResults().split(pdpList)) { + StdPDP pdp = new StdPDP(pdpId, properties); pdp.addItemSetChangeListener(this); this.pdps.add(pdp); } @@ -157,10 +173,10 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG logger.warn("Group directory does NOT exist: " + directory.toString()); try { Files.createDirectory(directory); - this.status.addLoadWarning("Group directory does NOT exist"); + this.status.addLoadWarning(groupNotExist); } catch (IOException e) { - PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Group directory does NOT exist"); - this.status.addLoadError("Group directory does NOT exist"); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", groupNotExist); + this.status.addLoadError(groupNotExist); this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS); } } @@ -229,7 +245,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } //Even if we create a new pip file, we still need to parse and load the properties try{ - this.readPIPProperties(directory, pipProperties); + this.readPIPProperties(pipProperties); }catch(Exception e){ throw new PAPException("Failed to load the new pip properties file", e); } @@ -243,7 +259,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } // For all old PIP config's modify to the new PIP Configuration. // If PIP is empty add the new values and save it. - if(pipProperties.get(XACMLProperties.PROP_PIP_ENGINES).toString().trim().equals("")){ + if("".equals(pipProperties.get(XACMLProperties.PROP_PIP_ENGINES).toString().trim())){ pipProperties = setPIPProperties(pipProperties); try (OutputStream os = Files.newOutputStream(file)) { pipProperties.store(os, ""); @@ -252,7 +268,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG // // Parse the pips // - this.readPIPProperties(directory, pipProperties); + this.readPIPProperties(pipProperties); } catch (IOException e) { logger.warn("Failed to open group PIP Config properties file: " + file, e); this.status.addLoadError("Not PIP config properties defined"); @@ -264,20 +280,6 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } public void resetStatus() { -// // -// // If we are updating, don't allow reset -// // -// if (this.status.getStatus() == Status.UPDATING_CONFIGURATION) { -// logger.warn("We are updating, chill."); -// return; -// } -// // -// // Load errors take precedence -// // -// if (this.status.getStatus() == Status.LOAD_ERRORS) { -// logger.warn("We had load errors."); -// return; -// } // // Reset our status object // @@ -312,13 +314,13 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } // priority is worst-cast to best case - if (this.status.getUnknownPDPs().size() > 0) { + if (!this.status.getUnknownPDPs().isEmpty()) { this.status.setStatus(Status.UNKNOWN); - } else if (this.status.getFailedPDPs().size() > 0 || this.status.getLastUpdateFailedPDPs().size() > 0) { + } else if (!this.status.getFailedPDPs().isEmpty() || !this.status.getLastUpdateFailedPDPs().isEmpty()) { this.status.setStatus(Status.LOAD_ERRORS); - } else if (this.status.getOutOfSynchPDPs().size() > 0) { + } else if (!this.status.getOutOfSynchPDPs().isEmpty()) { this.status.setStatus(Status.OUT_OF_SYNCH); - } else if (this.status.getUpdatingPDPs().size() > 0) { + } else if (!this.status.getUpdatingPDPs().isEmpty()) { this.status.setStatus(Status.UPDATING_CONFIGURATION); } else { this.status.setStatus(Status.OK); @@ -346,7 +348,6 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG // to occur: 1) old default=false (don't want to fire) and // then 2) new default=true (yes fire - but we'll have to do that // elsewhere. - //this.firePDPGroupChanged(this); } @Override @@ -404,6 +405,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG this.pdps = pdps; } + @Override public Set getOnapPdps(){ return Collections.unmodifiableSet(pdps); } @@ -430,7 +432,8 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } return null; } - + + @Override public Properties getPolicyProperties() { Properties properties = new Properties(){ @@ -442,9 +445,9 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG public synchronized Enumeration keys() { return Collections.enumeration(new TreeSet(super.keySet())); } - };; - List roots = new ArrayList(); - List refs = new ArrayList(); + }; + List roots = new ArrayList<>(); + List refs = new ArrayList<>(); for (PDPPolicy policy : this.policies) { // for all policies need to tell PDP the "name", which is the base name for the file id @@ -485,7 +488,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG logger.info("Copied " + num + " bytes for policy " + name); StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, isRoot, name, tempFile.toUri()); - if (tempRootPolicy.isValid() == false) { + if (!tempRootPolicy.isValid()) { try { Files.delete(tempFile); } catch(Exception ee) { @@ -555,7 +558,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG // policy is new to this group StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri()); - if (tempRootPolicy.isValid() == false) { + if (!tempRootPolicy.isValid()) { try { Files.delete(policyFile); } catch(Exception ee) { @@ -617,7 +620,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG // policy is new to this group StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri()); - if (tempRootPolicy.isValid() == false) { + if (!tempRootPolicy.isValid()) { try { Files.delete(policyFile); } catch(Exception ee) { @@ -668,7 +671,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } public boolean removePolicy(PDPPolicy policy) { - StdPDPPolicy currentPolicy = (StdPDPPolicy) this.getPolicy(policy.getId()); + PDPPolicy currentPolicy = this.getPolicy(policy.getId()); if (currentPolicy == null) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist."); return false; @@ -718,9 +721,10 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG this.firePDPGroupChanged(this); } + @Override public Properties getPipConfigProperties() { Properties properties = new Properties(); - List configs = new ArrayList(); + List configs = new ArrayList<>(); for (PDPPIPConfig config : this.pipConfigs) { configs.add(config.getId()); @@ -820,11 +824,11 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG isRoot = false; continue; } - for (String id : policyList) { + for (String policyId : policyList) { // // Construct the policy filename // - Path policyPath = Paths.get(directory.toString(), id ); + Path policyPath = Paths.get(directory.toString(), policyId ); // // Create the Policy Object // @@ -854,13 +858,13 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } } - private void readPIPProperties(Path directory, Properties properties) { + private void readPIPProperties(Properties properties) { String list = properties.getProperty(XACMLProperties.PROP_PIP_ENGINES); if (list == null || list.length() == 0) { return; } - for (String id : list.split("[,]")) { - StdPDPPIPConfig config = new StdPDPPIPConfig(id, properties); + for (String pipId : list.split("[,]")) { + StdPDPPIPConfig config = new StdPDPPIPConfig(pipId, properties); if (config.isConfigured()) { this.pipConfigs.add(config); this.status.addLoadedPipConfig(config); @@ -934,30 +938,12 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG this.changed(); } - - // - // Methods needed for JSON deserialization - // - public StdPDPGroup() { - - } - - public StdPDPGroup(OnapPDPGroup group) { - this.id = group.getId(); - this.name = group.getName(); - this.description = group.getDescription(); - this.isDefault = group.isDefaultGroup(); - this.pdps = group.getOnapPdps(); - this.policies = group.getPolicies(); - this.pipConfigs = group.getPipConfigs(); - } - public boolean isDefault() { return isDefault; } - public void setDefault(boolean isDefault) { - this.isDefault = isDefault; - } + public void setDefault(boolean isDefault) { + this.isDefault = isDefault; + } public void setStatus(PDPGroupStatus status) { this.status = new StdPDPGroupStatus(status); }