summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org
diff options
context:
space:
mode:
authorMichael Mokry <mm117s@att.com>2018-09-10 15:23:15 -0500
committerMichael Mokry <mm117s@att.com>2018-09-11 10:31:26 -0500
commite957a1d9a9fa6bd0f9f8348d1e864c09cfe2cb92 (patch)
treea09024bc2c7e6a3b69affd95de9352c7d4d5c468 /ONAP-PAP-REST/src/main/java/org
parent1134bd40da28d3833a0dd4f821e75ec938f6061f (diff)
New min/max Guard Policy
Made changes to support Guard policy create/update and other policy manager functions including deletePolicy and pushPolicy. Includes changes for new Guard policy support using GUI and API (Rest and Java Client) Made changes to address Jim's comments Made changes to address Liam's comments Change-Id: I133fe1fd9287ea77ea41a2788de90c7642c36b6a Issue-ID: POLICY-1038 Signed-off-by: Mike Mokry <mm117s@att.com>
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java29
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java38
2 files changed, 51 insertions, 16 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java
index 47ab45894..03fbe0763 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java
@@ -90,9 +90,11 @@ public class DecisionPolicy extends Policy {
private static final String AAFPROVIDER = "AAF";
public static final String GUARD_YAML = "GUARD_YAML";
public static final String GUARD_BL_YAML = "GUARD_BL_YAML";
+ public static final String GUARD_MIN_MAX = "GUARD_MIN_MAX";
public static final String RAINY_DAY = "Rainy_Day";
private static final String XACML_GUARD_TEMPLATE = "Decision_GuardPolicyTemplate.xml";
private static final String XACML_BLGUARD_TEMPLATE = "Decision_GuardBLPolicyTemplate.xml";
+ private static final String XACML_GUARD_MIN_MAX_TEMPLATE = "Decision_GuardMinMaxPolicyTemplate.xml";
private static final String ONAPNAME = "ONAPName";
private static final String POLICY_NAME = "PolicyName";
@@ -194,8 +196,10 @@ public class DecisionPolicy extends Policy {
}
policyName = policyAdapter.getNewFileName();
- if (policyAdapter.getRuleProvider().equals(GUARD_YAML)
- || policyAdapter.getRuleProvider().equals(GUARD_BL_YAML)) {
+ if(policyAdapter.getRuleProvider().equals(GUARD_YAML) ||
+ policyAdapter.getRuleProvider().equals(GUARD_BL_YAML) ||
+ policyAdapter.getRuleProvider().equals(GUARD_MIN_MAX)){
+
Map<String, String> yamlParams = new HashMap<>();
String blackListEntryType = policyAdapter.getBlackListEntryType() != null
? policyAdapter.getBlackListEntryType() : "Use Manual Entry";
@@ -353,6 +357,12 @@ public class DecisionPolicy extends Policy {
}
cons.setBlacklist(blackList);
break;
+ case GUARD_MIN_MAX:
+ templateFile = new File(classLoader.getResource(XACML_GUARD_MIN_MAX_TEMPLATE).getFile());
+ xacmlTemplatePath = templateFile.toPath();
+ cons = new Constraint(Integer.parseInt(yamlParams.get("min")),
+ Integer.parseInt(yamlParams.get("max")), activeTimeRange);
+ break;
default:
templateFile = new File(classLoader.getResource(XACML_GUARD_TEMPLATE).getFile());
xacmlTemplatePath = templateFile.toPath();
@@ -372,6 +382,7 @@ public class DecisionPolicy extends Policy {
cons = new Constraint(Integer.parseInt(yamlParams.get("limit")), timeWindow, activeTimeRange);
break;
}
+
builder = builder.addLimitConstraint(policy1.getId(), cons);
// Build the specification
Results results = builder.buildSpecification();
@@ -399,6 +410,18 @@ public class DecisionPolicy extends Policy {
yamlSpecs.put("twUnits", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst()
.getTime_window().get("units"));
}
+
+ if (yamlGuardObject.getGuards().getFirst().getLimit_constraints().
+ getFirst().getMaxVnfCount() != null) {
+ yamlSpecs.put("max", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst()
+ .getMaxVnfCount().toString());
+ }
+ if (yamlGuardObject.getGuards().getFirst().getLimit_constraints().
+ getFirst().getMinVnfCount() != null) {
+ yamlSpecs.put("min", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst()
+ .getMinVnfCount().toString());
+ }
+
yamlSpecs.put("guardActiveStart", yamlGuardObject.getGuards().getFirst().getLimit_constraints()
.getFirst().getActive_time_range().get("start"));
yamlSpecs.put("guardActiveEnd", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst()
@@ -406,9 +429,11 @@ public class DecisionPolicy extends Policy {
String xacmlPolicyContent = SafePolicyBuilder.generateXacmlGuard(xacmlTemplateContent, yamlSpecs,
yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getBlacklist(),
yamlGuardObject.getGuards().getFirst().getMatch_parameters().getTargets());
+
// Convert the Policy into Stream input to Policy Adapter.
Object policy = XACMLPolicyScanner
.readPolicy(new ByteArrayInputStream(xacmlPolicyContent.getBytes(StandardCharsets.UTF_8)));
+
return (PolicyType) policy;
} catch (IOException e) {
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error while creating the policy " + e.getMessage(),
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
index 951f25c25..de5d1cf49 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
@@ -402,46 +402,56 @@ public class PolicyCreation extends AbstractPolicyCreation{
}
}
}
- if(policyData.getRuleProvider()!=null && (policyData.getRuleProvider().equals(DecisionPolicy.GUARD_YAML)|| policyData.getRuleProvider().equals(DecisionPolicy.GUARD_BL_YAML))
- && policyData.getYamlparams()!=null){
+ if (policyData.getRuleProvider() != null
+ && (policyData.getRuleProvider().equals(DecisionPolicy.GUARD_YAML)
+ || policyData.getRuleProvider().equals(DecisionPolicy.GUARD_BL_YAML)
+ || policyData.getRuleProvider().equals(DecisionPolicy.GUARD_MIN_MAX))
+ && policyData.getYamlparams() != null) {
attributeMap.put("actor", policyData.getYamlparams().getActor());
attributeMap.put("recipe", policyData.getYamlparams().getRecipe());
attributeMap.put("clname", policyData.getYamlparams().getClname());
attributeMap.put("limit", policyData.getYamlparams().getLimit());
+ attributeMap.put("min", policyData.getYamlparams().getMin());
+ attributeMap.put("max", policyData.getYamlparams().getMax());
attributeMap.put("timeWindow", policyData.getYamlparams().getTimeWindow());
attributeMap.put("timeUnits", policyData.getYamlparams().getTimeUnits());
attributeMap.put("guardActiveStart", policyData.getYamlparams().getGuardActiveStart());
attributeMap.put("guardActiveEnd", policyData.getYamlparams().getGuardActiveEnd());
- if(policyData.getYamlparams().getBlackList()!=null){
+ if (policyData.getYamlparams().getBlackList() != null) {
String blackList = StringUtils.join(policyData.getYamlparams().getBlackList(), ",");
attributeMap.put("blackList", blackList);
}
- if(DecisionPolicy.GUARD_BL_YAML.equals(policyData.getRuleProvider()) && "Use File Upload".equals(policyData.getBlackListEntryType())){
- if(policyData.getBlackListEntries() != null && !policyData.getBlackListEntries().isEmpty()){
+ if (DecisionPolicy.GUARD_BL_YAML.equals(policyData.getRuleProvider())
+ && "Use File Upload".equals(policyData.getBlackListEntryType())) {
+ if (policyData.getBlackListEntries() != null
+ && !policyData.getBlackListEntries().isEmpty()) {
String blackList = StringUtils.join(policyData.getBlackListEntries(), ",");
attributeMap.put("blackList", blackList);
}
- if(policyData.getAppendBlackListEntries() != null && !policyData.getAppendBlackListEntries().isEmpty()){
+ if (policyData.getAppendBlackListEntries() != null
+ && !policyData.getAppendBlackListEntries().isEmpty()) {
String blackList = StringUtils.join(policyData.getAppendBlackListEntries(), ",");
attributeMap.put("appendBlackList", blackList);
}
}
- if(policyData.getYamlparams().getTargets()!=null){
- String targets = StringUtils.join(policyData.getYamlparams().getTargets(),",");
+ if (policyData.getYamlparams().getTargets() != null) {
+ String targets = StringUtils.join(policyData.getYamlparams().getTargets(), ",");
attributeMap.put("targets", targets);
}
}
- if(policyData.getRuleProvider()!=null && policyData.getRuleProvider().equals(DecisionPolicy.RAINY_DAY)){
+ if (policyData.getRuleProvider() != null
+ && policyData.getRuleProvider().equals(DecisionPolicy.RAINY_DAY)) {
attributeMap.put("ServiceType", policyData.getRainyday().getServiceType());
attributeMap.put("VNFType", policyData.getRainyday().getVnfType());
attributeMap.put("BB_ID", policyData.getRainyday().getBbid());
attributeMap.put("WorkStep", policyData.getRainyday().getWorkstep());
- if(policyData.getRainyday().getTreatmentTableChoices()!=null && policyData.getRainyday().getTreatmentTableChoices().size() > 0){
- for (Object table : policyData.getRainyday().getTreatmentTableChoices()){
- if(table instanceof LinkedHashMap<?,?>){
- String errorcode = ((LinkedHashMap<?,?>) table).get("errorcode").toString();
- String treatment = ((LinkedHashMap<?,?>) table).get("treatment").toString();
+ if (policyData.getRainyday().getTreatmentTableChoices() != null
+ && policyData.getRainyday().getTreatmentTableChoices().isEmpty()) {
+ for (Object table : policyData.getRainyday().getTreatmentTableChoices()) {
+ if (table instanceof LinkedHashMap<?, ?>) {
+ String errorcode = ((LinkedHashMap<?, ?>) table).get("errorcode").toString();
+ String treatment = ((LinkedHashMap<?, ?>) table).get("treatment").toString();
treatmentMap.put(errorcode, treatment);
}
}