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=9289c2461a4dc07ed996ac6ca62a19c541ae76ac;hb=7d3735c062a378b4d5b05859e740c408fd2d0239;hp=9cdb4521d99431d1b7b5584e6515b50298e9a539;hpb=709fe78e311189429a22c4ceebf20f19e89693f3;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 9cdb4521d..9289c2461 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 @@ -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; @@ -137,8 +138,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 +158,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 +230,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 +244,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 +253,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 +265,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 +299,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); @@ -404,6 +391,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG this.pdps = pdps; } + @Override public Set getOnapPdps(){ return Collections.unmodifiableSet(pdps); } @@ -430,7 +418,8 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } return null; } - + + @Override public Properties getPolicyProperties() { Properties properties = new Properties(){ @@ -442,9 +431,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 @@ -718,9 +707,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 +810,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 +844,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); @@ -935,11 +925,10 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } - // - // Methods needed for JSON deserialization - // public StdPDPGroup() { - + // + // Methods needed for JSON deserialization + // } public StdPDPGroup(OnapPDPGroup group) { @@ -955,9 +944,9 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG 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); }