From e957a1d9a9fa6bd0f9f8348d1e864c09cfe2cb92 Mon Sep 17 00:00:00 2001 From: Michael Mokry Date: Mon, 10 Sep 2018 15:23:15 -0500 Subject: 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 --- .../org/onap/policy/rest/adapter/YAMLParams.java | 21 ++++++- .../onap/policy/rest/util/PolicyValidation.java | 64 +++++++++++++++------- .../rest/util/PolicyValidationRequestWrapper.java | 6 +- 3 files changed, 70 insertions(+), 21 deletions(-) (limited to 'ONAP-REST/src') diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/YAMLParams.java b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/YAMLParams.java index ec43a19f2..c7063b86e 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/YAMLParams.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/YAMLParams.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * 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. @@ -27,6 +27,8 @@ public class YAMLParams { private String recipe; private String clname; private String limit; + private String min; + private String max; private String timeWindow; private String timeUnits; private String guardActiveStart; @@ -52,6 +54,23 @@ public class YAMLParams { public void setLimit(String limit) { this.limit = limit; } + + public String getMin() { + return min; + } + + public void setMin(String min) { + this.min = min; + } + + public String getMax() { + return max; + } + + public void setMax(String max) { + this.max = max; + } + public String getTimeWindow() { return timeWindow; } diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java index 42f94cfa7..df4e4726d 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java @@ -900,48 +900,74 @@ public class PolicyValidation { } } - if("GUARD_YAML".equals(policyData.getRuleProvider()) || "GUARD_BL_YAML".equals(policyData.getRuleProvider())){ - if(policyData.getYamlparams()==null){ + if ("GUARD_YAML".equals(policyData.getRuleProvider()) + || "GUARD_BL_YAML".equals(policyData.getRuleProvider()) + || "GUARD_MIN_MAX".equals(policyData.getRuleProvider())) { + if (policyData.getYamlparams() == null) { responseString.append(" Guard Params are Required " + HTML_ITALICS_LNBREAK); valid = false; - }else{ - if(Strings.isNullOrEmpty(policyData.getYamlparams().getActor())){ + } else { + if (Strings.isNullOrEmpty(policyData.getYamlparams().getActor())) { responseString.append("Guard Params Actor is Required " + HTML_ITALICS_LNBREAK); valid = false; } - if(Strings.isNullOrEmpty(policyData.getYamlparams().getRecipe())){ + if (Strings.isNullOrEmpty(policyData.getYamlparams().getRecipe())) { responseString.append("Guard Params Recipe is Required " + HTML_ITALICS_LNBREAK); valid = false; } - if(Strings.isNullOrEmpty(policyData.getYamlparams().getGuardActiveStart())){ - responseString.append("Guard Params Guard Active Start is Required " + HTML_ITALICS_LNBREAK); + if (Strings.isNullOrEmpty(policyData.getYamlparams().getGuardActiveStart())) { + responseString.append( + "Guard Params Guard Active Start is Required " + HTML_ITALICS_LNBREAK); valid = false; } - if(Strings.isNullOrEmpty(policyData.getYamlparams().getGuardActiveEnd())){ - responseString.append("Guard Params Guard Active End is Required " + HTML_ITALICS_LNBREAK); + if (Strings.isNullOrEmpty(policyData.getYamlparams().getGuardActiveEnd())) { + responseString + .append("Guard Params Guard Active End is Required " + HTML_ITALICS_LNBREAK); valid = false; } - if("GUARD_YAML".equals(policyData.getRuleProvider())){ - if(Strings.isNullOrEmpty(policyData.getYamlparams().getLimit())){ + if ("GUARD_YAML".equals(policyData.getRuleProvider())) { + if (Strings.isNullOrEmpty(policyData.getYamlparams().getLimit())) { responseString.append(" Guard Params Limit is Required " + HTML_ITALICS_LNBREAK); valid = false; - }else if(!PolicyUtils.isInteger(policyData.getYamlparams().getLimit())){ - responseString.append(" Guard Params Limit Should be Integer " + HTML_ITALICS_LNBREAK); + } else if (!PolicyUtils.isInteger(policyData.getYamlparams().getLimit())) { + responseString + .append(" Guard Params Limit Should be Integer " + HTML_ITALICS_LNBREAK); + valid = false; + } + if (Strings.isNullOrEmpty(policyData.getYamlparams().getTimeWindow())) { + responseString + .append("Guard Params Time Window is Required" + HTML_ITALICS_LNBREAK); + valid = false; + } else if (!PolicyUtils.isInteger(policyData.getYamlparams().getTimeWindow())) { + responseString.append( + " Guard Params Time Window Should be Integer " + HTML_ITALICS_LNBREAK); valid = false; } - if(Strings.isNullOrEmpty(policyData.getYamlparams().getTimeWindow())){ - responseString.append("Guard Params Time Window is Required" + HTML_ITALICS_LNBREAK); + if (Strings.isNullOrEmpty(policyData.getYamlparams().getTimeUnits())) { + responseString + .append("Guard Params Time Units is Required" + HTML_ITALICS_LNBREAK); + valid = false; + } + } else if ("GUARD_MIN_MAX".equals(policyData.getRuleProvider())) { + if (Strings.isNullOrEmpty(policyData.getYamlparams().getMin())) { + responseString.append(" Guard Params Min is Required " + HTML_ITALICS_LNBREAK); valid = false; - }else if(!PolicyUtils.isInteger(policyData.getYamlparams().getTimeWindow())){ - responseString.append(" Guard Params Time Window Should be Integer " + HTML_ITALICS_LNBREAK); + } else if (!PolicyUtils.isInteger(policyData.getYamlparams().getMin())) { + responseString + .append(" Guard Params Min Should be Integer " + HTML_ITALICS_LNBREAK); valid = false; } - if(Strings.isNullOrEmpty(policyData.getYamlparams().getTimeUnits())){ - responseString.append("Guard Params Time Units is Required" + HTML_ITALICS_LNBREAK); + if (Strings.isNullOrEmpty(policyData.getYamlparams().getMax())) { + responseString.append(" Guard Params Max is Required " + HTML_ITALICS_LNBREAK); + valid = false; + } else if (!PolicyUtils.isInteger(policyData.getYamlparams().getMax())) { + responseString + .append(" Guard Params Max Should be Integer " + HTML_ITALICS_LNBREAK); valid = false; } } else if ("GUARD_BL_YAML".equals(policyData.getRuleProvider()) && "Use Manual Entry".equals(policyData.getBlackListEntryType())) { + if (policyData.getYamlparams().getBlackList() == null || policyData.getYamlparams().getBlackList().isEmpty()) { responseString diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java index 66628e2da..779c5227a 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java @@ -176,7 +176,8 @@ public class PolicyValidationRequestWrapper { rainyday.setTreatmentTableChoices(treatmentsTableChoices); policyData.setRainyday(rainyday); - }else if("GUARD_YAML".equals(ruleProvider) || "GUARD_BL_YAML".equals(ruleProvider)) { + } else if ("GUARD_YAML".equals(ruleProvider) || "GUARD_BL_YAML".equals(ruleProvider) + || "GUARD_MIN_MAX".equals(ruleProvider)) { // Set Matching attributes in YAMLParams in adapter YAMLParams yamlparams = new YAMLParams(); @@ -191,6 +192,9 @@ public class PolicyValidationRequestWrapper { yamlparams.setLimit(matching.get("limit")); yamlparams.setTimeWindow(matching.get("timeWindow")); yamlparams.setTimeUnits(matching.get("timeUnits")); + } else if ("GUARD_MIN_MAX".equals(ruleProvider)) { + yamlparams.setMin(matching.get("min")); + yamlparams.setMax(matching.get("max")); }else{ List blackList = new ArrayList<>(); -- cgit 1.2.3-korg