Code Review
/
policy
/
engine.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Merge "Adding JUNITs for ONAP-PAP-REST"
[policy/engine.git]
/
ONAP-XACML
/
src
/
main
/
java
/
org
/
onap
/
policy
/
xacml
/
std
/
pap
/
StdEngine.java
diff --git
a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java
b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java
index
14d7c7f
..
4399f71
100644
(file)
--- a/
ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java
+++ b/
ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java
@@
-2,7
+2,7
@@
* ============LICENSE_START=======================================================
* ONAP-XACML
* ================================================================================
* ============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.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-66,8
+66,10
@@
import com.google.common.collect.Sets;
*/
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyEngine {
public static final String pipPropertyFile = "pip.properties";
*/
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyEngine {
public static final String pipPropertyFile = "pip.properties";
+
+ private static final String addGroup = "addGroup ";
-
private static Log
logger = LogFactory.getLog(StdEngine.class);
+
private static Log
logger = LogFactory.getLog(StdEngine.class);
public static final String PROP_PAP_REPO = "xacml.pap.pdps";
public static final String PROP_PAP_GROUPS = "xacml.pap.groups";
public static final String PROP_PAP_REPO = "xacml.pap.pdps";
public static final String PROP_PAP_GROUPS = "xacml.pap.groups";
@@
-123,10
+125,10
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
if (Files.notExists(this.repository)) {
Files.createDirectory(repository);
}
if (Files.notExists(this.repository)) {
Files.createDirectory(repository);
}
- if (
Files.isDirectory(this.repository) == false
) {
+ if (
!Files.isDirectory(this.repository)
) {
throw new PAPException ("Repository is NOT a directory: " + this.repository.toAbsolutePath());
}
throw new PAPException ("Repository is NOT a directory: " + this.repository.toAbsolutePath());
}
- if (
Files.isWritable(this.repository) == false
) {
+ if (
!Files.isWritable(this.repository)
) {
throw new PAPException ("Repository is NOT writable: " + this.repository.toAbsolutePath());
}
//
throw new PAPException ("Repository is NOT writable: " + this.repository.toAbsolutePath());
}
//
@@
-171,6
+173,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
//
PDPGroup group = this.getDefaultGroup();
if (group != null) {
//
PDPGroup group = this.getDefaultGroup();
if (group != null) {
+ wasDefaultGroupJustAdded = true;
return group;
}
//
return group;
}
//
@@
-180,14
+183,14
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
if(defaultId == null){
defaultId = PROP_PAP_GROUPS_DEFAULT_NAME;
}
if(defaultId == null){
defaultId = PROP_PAP_GROUPS_DEFAULT_NAME;
}
- if(
defaultId.equals(""
)){
+ if(
"".equals(defaultId
)){
defaultId = PROP_PAP_GROUPS_DEFAULT_NAME;
}
//we're going to check one more time in case the PROP_PAP_GROUPS_DEFAULT_NAME doesn't exist
if(defaultId == null){
defaultId = "default";
}
defaultId = PROP_PAP_GROUPS_DEFAULT_NAME;
}
//we're going to check one more time in case the PROP_PAP_GROUPS_DEFAULT_NAME doesn't exist
if(defaultId == null){
defaultId = "default";
}
- if(
defaultId.equals(""
)){
+ if(
"".equals(defaultId
)){
defaultId = "default";
}
logger.warn("Default group does NOT exist, creating " + defaultId);
defaultId = "default";
}
logger.warn("Default group does NOT exist, creating " + defaultId);
@@
-317,7
+320,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
// If it exists already
//
if (Files.exists(groupPath)) {
// If it exists already
//
if (Files.exists(groupPath)) {
- logger.warn(
"addGroup "
+ id + " directory exists" + groupPath.toString());
+ logger.warn(
addGroup
+ id + " directory exists" + groupPath.toString());
} else {
try {
//
} else {
try {
//
@@
-335,7
+338,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
Path policyProperties = Paths.get(groupPath.toString(), "xacml.policy.properties");
if (Files.exists(policyProperties)) {
Path policyProperties = Paths.get(groupPath.toString(), "xacml.policy.properties");
if (Files.exists(policyProperties)) {
- logger.warn(
"addGroup "
+ id + " file exists: " + policyProperties.toString());
+ logger.warn(
addGroup
+ id + " file exists: " + policyProperties.toString());
} else {
Properties props = new Properties();
props.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, "");
} else {
Properties props = new Properties();
props.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, "");
@@
-356,7
+359,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
Path pipProperties = Paths.get(groupPath.toString(), "xacml.pip.properties");
Properties props = new Properties();
if (Files.exists(pipProperties)) {
Path pipProperties = Paths.get(groupPath.toString(), "xacml.pip.properties");
Properties props = new Properties();
if (Files.exists(pipProperties)) {
- logger.warn(
"addGroup "
+ id + " file exists: " + pipProperties.toString());
+ logger.warn(
addGroup
+ id + " file exists: " + pipProperties.toString());
} else {
try {
props = setPIPProperties(props);
} else {
try {
props = setPIPProperties(props);
@@
-464,7
+467,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
this.doSave();
} else {
PolicyLogger.error("Failed to add to new group, putting back into original group.");
this.doSave();
} else {
PolicyLogger.error("Failed to add to new group, putting back into original group.");
- if (
((StdPDPGroup) currentGroup).removePDP(pdp) == false
) {
+ if (
!((StdPDPGroup) currentGroup).removePDP(pdp)
) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Failed to put PDP back into original group.");
}
}
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Failed to put PDP back into original group.");
}
}
@@
-489,8
+492,8
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
// the only things that the user can change are name and description
currentPDP.setDescription(pdp.getDescription());
currentPDP.setName(pdp.getName());
// the only things that the user can change are name and description
currentPDP.setDescription(pdp.getDescription());
currentPDP.setName(pdp.getName());
- if (currentPDP instanceof OnapPDP
&& pdp instanceof OnapPDP
) {
- ((OnapPDP)currentPDP).setJmxPort(
((OnapPDP)pdp)
.getJmxPort());
+ if (currentPDP instanceof OnapPDP) {
+ ((OnapPDP)currentPDP).setJmxPort(
pdp
.getJmxPort());
}
this.doSave();
}
}
this.doSave();
}
@@
-535,10
+538,13
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
throw new PAPException("Unknown PDP Group: " + group.getId());
}
throw new PAPException("Unknown PDP Group: " + group.getId());
}
- // Currently not used on the PAP side. This is done by ((StdPDPGroup) group).copyPolicyToFile
+
@Override
public void copyPolicy(PDPPolicy policy, OnapPDPGroup group)
throws PAPException {
@Override
public void copyPolicy(PDPPolicy policy, OnapPDPGroup group)
throws PAPException {
+ //
+ // Currently not used on the PAP side. This is done by ((StdPDPGroup) group).copyPolicyToFile
+ //
}
}
@@
-561,7
+567,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
//
private Set<StdPDPGroup> readProperties(Path repository, Properties properties) throws PAPException {
//
private Set<StdPDPGroup> readProperties(Path repository, Properties properties) throws PAPException {
- Set<StdPDPGroup>
g
roups = new HashSet<>();
+ Set<StdPDPGroup>
pdpG
roups = new HashSet<>();
//
// See if there is a groups property
//
//
// See if there is a groups property
//
@@
-588,15
+594,15
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
//
// Add it in
//
//
// Add it in
//
-
g
roups.add(g);
+
pdpG
roups.add(g);
}
//
// Dump what we got
//
if (logger.isDebugEnabled()) {
}
//
// Dump what we got
//
if (logger.isDebugEnabled()) {
- logger.debug("PDP Group List: " +
g
roups.toString());
+ logger.debug("PDP Group List: " +
pdpG
roups.toString());
}
}
- return
g
roups;
+ return
pdpG
roups;
}
private void saveConfiguration() throws PAPException, IOException {
}
private void saveConfiguration() throws PAPException, IOException {
@@
-619,16
+625,16
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
List<String> ids = new ArrayList<>();
for (PDPGroup group : this.groups) {
ids.add(group.getId());
List<String> ids = new ArrayList<>();
for (PDPGroup group : this.groups) {
ids.add(group.getId());
- properties.setProperty(group.getId() + ".name",
(group.getName() == null ? "" : group.getName()
));
- properties.setProperty(group.getId() + ".description",
(group.getDescription() == null ? "" : group.getDescription()
));
+ properties.setProperty(group.getId() + ".name",
group.getName() == null ? "" : group.getName(
));
+ properties.setProperty(group.getId() + ".description",
group.getDescription() == null ? "" : group.getDescription(
));
//
// Iterate its PDPs
//
List<String> pdps = new ArrayList<>();
for (PDP pdp : group.getPdps()) {
pdps.add(pdp.getId());
//
// Iterate its PDPs
//
List<String> pdps = new ArrayList<>();
for (PDP pdp : group.getPdps()) {
pdps.add(pdp.getId());
- properties.setProperty(pdp.getId() + ".name",
(pdp.getName() == null ? "" : pdp.getName()
));
- properties.setProperty(pdp.getId() + ".description",
(pdp.getDescription() == null ? "" : pdp.getDescription()
));
+ properties.setProperty(pdp.getId() + ".name",
pdp.getName() == null ? "" : pdp.getName(
));
+ properties.setProperty(pdp.getId() + ".description",
pdp.getDescription() == null ? "" : pdp.getDescription(
));
if (pdp instanceof OnapPDP) {
properties.setProperty(pdp.getId() + ".jmxport", (((OnapPDP)pdp).getJmxPort()==0 ? "" : ((OnapPDP)pdp).getJmxPort()).toString());
}
if (pdp instanceof OnapPDP) {
properties.setProperty(pdp.getId() + ".jmxport", (((OnapPDP)pdp).getJmxPort()==0 ? "" : ((OnapPDP)pdp).getJmxPort()).toString());
}
@@
-692,15
+698,17
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
inList = true;
}
}
inList = true;
}
}
- if (
inList == false
) {
+ if (
!inList
) {
Set<String> grps = Sets.newHashSet(groups);
grps.add(group.getId());
Set<String> grps = Sets.newHashSet(groups);
grps.add(group.getId());
- String newGroupList
= "";
;
+ String newGroupList;
if (grps.size() == 1) {
newGroupList = grps.iterator().next();
} else if (grps.size() > 1) {
newGroupList = Joiner.on(',').skipNulls().join(grps);
if (grps.size() == 1) {
newGroupList = grps.iterator().next();
} else if (grps.size() > 1) {
newGroupList = Joiner.on(',').skipNulls().join(grps);
- }
+ } else {
+ newGroupList = "";
+ }
logger.info("New Group List: " + newGroupList);
properties.setProperty(PROP_PAP_GROUPS, newGroupList);
}
logger.info("New Group List: " + newGroupList);
properties.setProperty(PROP_PAP_GROUPS, newGroupList);
}
@@
-712,7
+720,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
//
// Set its PDP list
//
//
// Set its PDP list
//
- if (
group.getPdps().size() > 0
) {
+ if (
!group.getPdps().isEmpty()
) {
String pdpList = "";
if (group.getPdps().size() == 1) {
pdpList = group.getPdps().iterator().next().getId();
String pdpList = "";
if (group.getPdps().size() == 1) {
pdpList = group.getPdps().iterator().next().getId();
@@
-761,9
+769,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
// Save the configuration
//
this.saveConfiguration();
// Save the configuration
//
this.saveConfiguration();
- } catch (IOException e) {
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdEngine", "Failed to save configuration");
- } catch (PAPException e) {
+ } catch (IOException|PAPException e) {
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdEngine", "Failed to save configuration");
}
}
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdEngine", "Failed to save configuration");
}
}
@@
-784,7
+790,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
} catch (IOException e) {
PolicyLogger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "can not load the pip properties from file" +e);
}
} catch (IOException e) {
PolicyLogger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "can not load the pip properties from file" +e);
}
-
props = prop;
+ props = prop;
}
return props;
}
}
return props;
}
@@
-810,7
+816,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
}
@Override
}
@Override
- public void
S
etDefaultGroup(OnapPDPGroup group) throws PAPException {
+ public void
s
etDefaultGroup(OnapPDPGroup group) throws PAPException {
boolean changesMade = false;
for (OnapPDPGroup aGroup : groups) {
if (aGroup.getId().equals(group.getId())) {
boolean changesMade = false;
for (OnapPDPGroup aGroup : groups) {
if (aGroup.getId().equals(group.getId())) {
@@
-848,7
+854,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
if (group == null) {
throw new PAPException("You must specify which group the PDP will belong to.");
}
if (group == null) {
throw new PAPException("You must specify which group the PDP will belong to.");
}
- if (
this.groups.contains(group) == false
) {
+ if (
!this.groups.contains(group)
) {
throw new PAPException("Unknown group, not in our list.");
}
for (OnapPDP p : group.getOnapPdps()) {
throw new PAPException("Unknown group, not in our list.");
}
for (OnapPDP p : group.getOnapPdps()) {
@@
-952,7
+958,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
//
// Does this group exist?
//
//
// Does this group exist?
//
- if (
this.groups.contains(group) == false
) {
+ if (
!this.groups.contains(group)
) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "This group doesn't exist.");
throw new PAPException("The group '" + group.getId() + "' does not exist");
}
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "This group doesn't exist.");
throw new PAPException("The group '" + group.getId() + "' does not exist");
}
@@
-966,13
+972,13
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
//
// Are there PDPs? If so, then we need a target group
//
//
// Are there PDPs? If so, then we need a target group
//
- if (
pdps.isEmpty() == false
&& newGroup == null) {
+ if (
!pdps.isEmpty()
&& newGroup == null) {
throw new NullPointerException("Group targeted for deletion has PDPs, you must provide a new group for them.");
}
//
// Move the PDPs
//
throw new NullPointerException("Group targeted for deletion has PDPs, you must provide a new group for them.");
}
//
// Move the PDPs
//
- if (
pdps.isEmpty() == false
) {
+ if (
!pdps.isEmpty()
) {
if (! (newGroup instanceof StdPDPGroup)) {
throw new PAPException("Unexpected class for newGroup: " + newGroup.getClass().getCanonicalName());
}
if (! (newGroup instanceof StdPDPGroup)) {
throw new PAPException("Unexpected class for newGroup: " + newGroup.getClass().getCanonicalName());
}