Fix Guard policy Push 26/69726/3
authorsebdet <sd378r@intl.att.com>
Wed, 3 Oct 2018 09:48:00 +0000 (11:48 +0200)
committersebdet <sebastien.determe@intl.att.com>
Wed, 3 Oct 2018 16:36:25 +0000 (18:36 +0200)
Fix push to policy of Guard policies due to interface changes

Issue-ID: CLAMP-225
Change-Id: If0832385c20824ad86ca53bcaa07e6fa1ad61691
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
pom.xml
src/main/java/org/onap/clamp/clds/client/GuardPolicyDelegate.java
src/main/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegate.java
src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java
src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java
src/main/resources/META-INF/resources/designer/partials/portfolios/PolicyWindow_properties.html
src/test/resources/example/model-properties/tca_new/model-properties.json

diff --git a/pom.xml b/pom.xml
index e522573..fe6bab0 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                <version>3.0.0-SNAPSHOT</version>
                <name>clamp</name>
 
-               <parent>
-                               <groupId>org.onap.oparent</groupId>
-                               <artifactId>oparent</artifactId>
-                               <version>1.2.0</version>
-               </parent>
+<!--           <parent> -->
+<!--                           <groupId>org.onap.oparent</groupId> -->
+<!--                           <artifactId>oparent</artifactId> -->
+<!--                           <version>1.2.0</version> -->
+<!--           </parent> -->
 
                <description>
            This project build the ONAP CLAMP JAR that contains CLAMP back-end code and its UI part.
                                <dependency>
                                                <groupId>org.onap.policy.engine</groupId>
                                                <artifactId>PolicyEngineAPI</artifactId>
-                                               <version>1.2.3</version>
+                                               <version>1.3.0-SNAPSHOT</version>
                                                <exclusions>
                                                                <exclusion>
                                                                                <groupId>com.google.guava</groupId>
                                <dependency>
                                                <groupId>com.google.guava</groupId>
                                                <artifactId>guava</artifactId>
-
+                                               <version>25.1-jre</version>
                                </dependency>
                                <!-- Remove the MYSQL connector and replace it by Mariadb -->
                                <dependency>
index 9287abb..fb91d9c 100644 (file)
@@ -27,7 +27,6 @@ import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 
 import java.io.UnsupportedEncodingException;
-import java.util.Map;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Handler;
@@ -39,14 +38,13 @@ import org.onap.clamp.clds.model.properties.Policy;
 import org.onap.clamp.clds.model.properties.PolicyChain;
 import org.onap.clamp.clds.model.properties.PolicyItem;
 import org.onap.clamp.clds.util.LoggingUtils;
-import org.onap.policy.api.AttributeType;
 import org.onap.policy.controlloop.policy.builder.BuilderException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 /**
- * Send Guard Policy info to policy API. It uses the policy code to define
- * the model and communicate with it. See also the PolicyClient class.
+ * Send Guard Policy info to policy API. It uses the policy code to define the
+ * model and communicate with it. See also the PolicyClient class.
  */
 @Component
 public class GuardPolicyDelegate {
@@ -74,25 +72,20 @@ public class GuardPolicyDelegate {
      */
     @Handler
     public void execute(Exchange camelExchange) throws BuilderException, UnsupportedEncodingException {
-        String responseMessageGuard = null;
         ModelProperties prop = ModelProperties.create(camelExchange);
         Policy policy = prop.getType(Policy.class);
         if (policy.isFound()) {
             for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) {
-                for(PolicyItem policyItem:policyChain.getPolicyItems()) {
-                    if ("on".equals(policyItem.getEnableGuardPolicy()))
-                        responseMessageGuard = createGuardPolicy(prop, policyItem);
+                for(PolicyItem policyItem:GuardPolicyAttributesConstructor.getAllPolicyGuardsFromPolicyChain(policyChain)) {
+                    prop.setCurrentModelElementId(policy.getId());
+                    prop.setPolicyUniqueId(policyChain.getPolicyId());
+                    prop.setGuardUniqueId(policyItem.getId());
+                    policyClient.sendGuardPolicy(GuardPolicyAttributesConstructor
+                        .formatAttributes(prop, policyItem), prop, LoggingUtils.getRequestId(), policyItem);
                 }
             }
-            if (responseMessageGuard != null) {
-                camelExchange.setProperty("guardPolicyResponseMessage", responseMessageGuard.getBytes());
-            }
         }
     }
 
-    private String createGuardPolicy(ModelProperties prop, PolicyItem policyItem) {
-        Map<AttributeType, Map<String, String>> attributes = GuardPolicyAttributesConstructor
-            .formatAttributes(refProp, prop, prop.getType(Policy.class).getId(), policyItem);
-        return policyClient.sendGuardPolicy(attributes, prop, LoggingUtils.getRequestId());
-    }
+
 }
index 9e8e1b8..36eb147 100644 (file)
@@ -28,11 +28,14 @@ import com.att.eelf.configuration.EELFManager;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Handler;
+import org.onap.clamp.clds.client.req.policy.GuardPolicyAttributesConstructor;
 import org.onap.clamp.clds.client.req.policy.PolicyClient;
+import org.onap.clamp.clds.config.ClampProperties;
 import org.onap.clamp.clds.model.CldsEvent;
 import org.onap.clamp.clds.model.properties.ModelProperties;
 import org.onap.clamp.clds.model.properties.Policy;
 import org.onap.clamp.clds.model.properties.PolicyChain;
+import org.onap.clamp.clds.model.properties.PolicyItem;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -45,9 +48,14 @@ public class GuardPolicyDeleteDelegate {
     protected static final EELFLogger logger = EELFManager.getInstance()
         .getLogger(GuardPolicyDeleteDelegate.class);
     protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
-    @Autowired
-    private PolicyClient policyClient;
+    private final PolicyClient policyClient;
+    private final ClampProperties refProp;
 
+    @Autowired
+    public GuardPolicyDeleteDelegate(PolicyClient policyClient, ClampProperties refProp) {
+        this.policyClient = policyClient;
+        this.refProp = refProp;
+    }
     /**
      * Perform activity. Delete Operational Policy via policy api.
      *
@@ -58,17 +66,18 @@ public class GuardPolicyDeleteDelegate {
     public void execute(Exchange camelExchange) {
         ModelProperties prop = ModelProperties.create(camelExchange);
         Policy policy = prop.getType(Policy.class);
-        prop.setCurrentModelElementId(policy.getId());
+
         String eventAction = (String) camelExchange.getProperty("eventAction");
-        String responseMessage = "";
         if (!eventAction.equalsIgnoreCase(CldsEvent.ACTION_CREATE) && policy.isFound()) {
-            for (PolicyChain policyChain : policy.getPolicyChains()) {
-                prop.setPolicyUniqueId(policyChain.getPolicyId());
-                responseMessage = policyClient.deleteBrms(prop);
-            }
-            if (responseMessage != null) {
-                camelExchange.setProperty("operationalPolicyDeleteResponseMessage", responseMessage.getBytes());
+            for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) {
+                for(PolicyItem policyItem:GuardPolicyAttributesConstructor.getAllPolicyGuardsFromPolicyChain(policyChain)) {
+                    prop.setCurrentModelElementId(policy.getId());
+                    prop.setPolicyUniqueId(policyChain.getPolicyId());
+                    prop.setGuardUniqueId(policyItem.getId());
+                    policyClient.deleteGuard(prop);
+                }
             }
         }
     }
+
 }
index f11b492..de86faa 100644 (file)
@@ -26,13 +26,16 @@ package org.onap.clamp.clds.client.req.policy;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
-import org.onap.clamp.clds.config.ClampProperties;
 import org.onap.clamp.clds.model.properties.ModelProperties;
+import org.onap.clamp.clds.model.properties.PolicyChain;
 import org.onap.clamp.clds.model.properties.PolicyItem;
 import org.onap.policy.api.AttributeType;
+import org.onap.policy.api.RuleProvider;
 
 public class GuardPolicyAttributesConstructor {
     private static final EELFLogger logger = EELFManager.getInstance()
@@ -41,24 +44,32 @@ public class GuardPolicyAttributesConstructor {
     private GuardPolicyAttributesConstructor() {
     }
 
-    public static Map<AttributeType, Map<String, String>> formatAttributes(ClampProperties refProp,
-        ModelProperties modelProperties, String modelElementId, PolicyItem policyItem) {
-        Map<String, String> matchingAttributes = prepareMatchingAttributes(refProp, policyItem, modelProperties);
+    public static Map<AttributeType, Map<String, String>> formatAttributes(ModelProperties modelProperties, PolicyItem policyItem) {
+        Map<String, String> matchingAttributes = prepareMatchingAttributes(policyItem, modelProperties);
         return createAttributesMap(matchingAttributes);
     }
 
-    private static Map<String, String> prepareMatchingAttributes(ClampProperties refProp,
-        PolicyItem policyItem, ModelProperties modelProp) {
+    public static List<PolicyItem> getAllPolicyGuardsFromPolicyChain(PolicyChain policyChain) {
+        List<PolicyItem> listItem = new ArrayList<>();
+        for (PolicyItem policyItem : policyChain.getPolicyItems()) {
+            if ("on".equals(policyItem.getEnableGuardPolicy())) {
+                listItem.add(policyItem);
+            }
+        }
+        return listItem;
+    }
+
+    private static Map<String, String> prepareMatchingAttributes(PolicyItem policyItem, ModelProperties modelProp) {
         logger.info("Preparing matching attributes for guard...");
         Map<String, String> matchingAttributes = new HashMap<>();
         matchingAttributes.put("actor",policyItem.getActor());
         matchingAttributes.put("recipe",policyItem.getRecipe());
         matchingAttributes.put("targets",policyItem.getGuardTargets());
         matchingAttributes.put("clname",modelProp.getControlNameAndPolicyUniqueId());
-        if ("MinMax".equals(policyItem.getGuardPolicyType())) {
+        if (RuleProvider.GUARD_MIN_MAX.equals(RuleProvider.valueOf(policyItem.getGuardPolicyType()))) {
             matchingAttributes.put("min",policyItem.getMinGuard());
             matchingAttributes.put("max",policyItem.getMaxGuard());
-        } else if ("FrequencyLimiter".equals(policyItem.getGuardPolicyType())) {
+        } else if (RuleProvider.GUARD_YAML.equals(RuleProvider.valueOf(policyItem.getGuardPolicyType()))) {
             matchingAttributes.put("limit",policyItem.getLimitGuard());
             matchingAttributes.put("timeWindow",policyItem.getTimeWindowGuard());
             matchingAttributes.put("timeUnits",policyItem.getTimeUnitsGuard());
index 58366d9..c26b15c 100644 (file)
@@ -37,11 +37,13 @@ import org.onap.clamp.clds.config.ClampProperties;
 import org.onap.clamp.clds.config.PolicyConfiguration;
 import org.onap.clamp.clds.exception.policy.PolicyClientException;
 import org.onap.clamp.clds.model.properties.ModelProperties;
+import org.onap.clamp.clds.model.properties.PolicyItem;
 import org.onap.clamp.clds.util.LoggingUtils;
 import org.onap.policy.api.AttributeType;
 import org.onap.policy.api.ConfigRequestParameters;
 import org.onap.policy.api.DeletePolicyCondition;
 import org.onap.policy.api.DeletePolicyParameters;
+import org.onap.policy.api.DictionaryType;
 import org.onap.policy.api.PolicyChangeResponse;
 import org.onap.policy.api.PolicyClass;
 import org.onap.policy.api.PolicyConfigException;
@@ -74,6 +76,8 @@ public class PolicyClient {
     public static final String POLICY_OP_NAME_PREFIX_PROPERTY_NAME = "policy.op.policyNamePrefix";
     public static final String POLICY_MS_NAME_PREFIX_PROPERTY_NAME = "policy.ms.policyNamePrefix";
     public static final String POLICY_OP_TYPE_PROPERTY_NAME = "policy.op.type";
+    public static final String POLICY_GUARD_SUFFIX = "_Guard";
+
     @Autowired
     protected ApplicationContext appContext;
     @Autowired
@@ -85,33 +89,32 @@ public class PolicyClient {
      * Perform Guard policy type.
      *
      * @param attributes
-     *            A map of attributes
+     *        A map of attributes
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @param policyRequestUuid
-     *            PolicyRequest UUID
+     *        PolicyRequest UUID
      * @return The response message of policy
      */
     public String sendGuardPolicy(Map<AttributeType, Map<String, String>> attributes, ModelProperties prop,
-        String policyRequestUuid) {
+        String policyRequestUuid, PolicyItem policyItem) {
         PolicyParameters policyParameters = new PolicyParameters();
         // Set Policy Type(Mandatory)
         policyParameters.setPolicyClass(PolicyClass.Decision);
         // Set Policy Name(Mandatory)
-        policyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueId()+"Guard");
+        policyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueGuardId());
         // documentation says this is options, but when tested, got the
         // following failure: java.lang.Exception: Policy send failed: PE300 -
         // Data Issue: No policyDescription given.
         policyParameters.setPolicyDescription(refProp.getStringValue("op.policyDescription"));
         policyParameters.setOnapName("PDPD");
-        policyParameters.setRuleProvider(RuleProvider.GUARD_YAML);
+        policyParameters.setRuleProvider(RuleProvider.valueOf(policyItem.getGuardPolicyType()));
         policyParameters.setAttributes(attributes);
         // Set a random UUID(Mandatory)
         policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
-        String policyNamePrefix = refProp.getStringValue(POLICY_OP_NAME_PREFIX_PROPERTY_NAME);
-        String rtnMsg = send(policyParameters, prop, policyNamePrefix);
-        String policyType = "Decision";
-        push(policyType, prop);
+
+        String rtnMsg = send(policyParameters, prop, null);
+        push(DictionaryType.Decision.toString(), prop);
         return rtnMsg;
     }
 
@@ -119,11 +122,11 @@ public class PolicyClient {
      * Perform BRMS policy type.
      *
      * @param attributes
-     *            A map of attributes
+     *        A map of attributes
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @param policyRequestUuid
-     *            PolicyRequest UUID
+     *        PolicyRequest UUID
      * @return The response message of policy
      */
     public String sendBrmsPolicy(Map<AttributeType, Map<String, String>> attributes, ModelProperties prop,
@@ -151,11 +154,11 @@ public class PolicyClient {
      * Perform send of microservice policy in JSON.
      *
      * @param policyJson
-     *            The policy JSON
+     *        The policy JSON
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @param policyRequestUuid
-     *            The policy Request UUID
+     *        The policy Request UUID
      * @return The response message of policy
      */
     public String sendMicroServiceInJson(String policyJson, ModelProperties prop, String policyRequestUuid) {
@@ -181,14 +184,14 @@ public class PolicyClient {
      * Perform send of base policy in OTHER type.
      *
      * @param configBody
-     *            The config policy string body
+     *        The config policy string body
      * @param configPolicyName
-     *            The config policy name of the component that has been
-     *            pre-deployed in DCAE
+     *        The config policy name of the component that has been pre-deployed in
+     *        DCAE
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @param policyRequestUuid
-     *            The policy request UUID
+     *        The policy request UUID
      * @return The answer from policy call
      */
     public String sendBasePolicyInOther(String configBody, String configPolicyName, ModelProperties prop,
@@ -215,9 +218,9 @@ public class PolicyClient {
      * Perform send of Microservice policy in OTHER type.
      *
      * @param configBody
-     *            The config policy string body
+     *        The config policy string body
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @return The answer from policy call
      */
     public String sendMicroServiceInOther(String configBody, ModelProperties prop) {
@@ -238,12 +241,12 @@ public class PolicyClient {
     }
 
     /**
-     * Perform send of policy.
+     * Perform send of Configuration or Decision policies.
      *
      * @param policyParameters
-     *            The PolicyParameters
+     *        The PolicyParameters
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @return The response message of Policy
      */
     protected String send(PolicyParameters policyParameters, ModelProperties prop, String policyNamePrefix) {
@@ -256,7 +259,9 @@ public class PolicyClient {
         String responseMessage = "";
         Date startTime = new Date();
         try {
-            if (!checkPolicyExists(policyNamePrefix, prop)) {
+            if ((PolicyClass.Decision.equals(policyParameters.getPolicyClass()) && !checkDecisionPolicyExists(prop))
+                || (PolicyClass.Config.equals(policyParameters.getPolicyClass())
+                    && !checkPolicyExists(policyNamePrefix, prop))) {
                 LoggingUtils.setTargetContext("Policy", "createPolicy");
                 logger.info("Attempting to create policy for action=" + prop.getActionCd());
                 response = getPolicyEngine().createPolicy(policyParameters);
@@ -292,9 +297,9 @@ public class PolicyClient {
      * Format and send push of policy.
      *
      * @param policyType
-     *            The policy Type
+     *        The policy Type
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @return The response message of policy
      */
     protected String push(String policyType, ModelProperties prop) {
@@ -305,7 +310,11 @@ public class PolicyClient {
         PushPolicyParameters pushPolicyParameters = new PushPolicyParameters();
         // Parameter arguments
         if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
-            pushPolicyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueId());
+            if (DictionaryType.Decision.toString().equals(policyType)) {
+                pushPolicyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueGuardId());
+            } else {
+                pushPolicyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueId());
+            }
         } else {
             pushPolicyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
         }
@@ -343,37 +352,64 @@ public class PolicyClient {
         return responseMessage;
     }
 
+    /**
+     * Use list Decision policy to know if the decision policy exists.
+     *
+     * @param prop
+     *        The model properties
+     * @return true if it exists, false otherwise
+     */
+    protected boolean checkDecisionPolicyExists(ModelProperties prop) {
+        boolean policyexists = false;
+
+        logger.info("Search in Policy Engine for DecisionpolicyName=" + prop.getPolicyScopeAndNameWithUniqueGuardId());
+        try {
+            // No other choice than pushing to see if it exists or not
+            String response = push(DictionaryType.Decision.toString(), prop);
+            if (response != null) {
+                policyexists = true;
+            }
+        } catch (BadRequestException e) {
+            // just print warning - if no policy version found
+            logger.warn("Policy not found...policy name - " + prop.getPolicyScopeAndNameWithUniqueGuardId(), e);
+        }
+        return policyexists;
+    }
+
     /**
      * Use list Policy API to retrieve the policy. Return true if policy exists
      * otherwise return false.
      *
      * @param policyNamePrefix
-     *            The Policy Name Prefix
+     *        The Policy Name Prefix
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @return The response message from policy
      * @throws PolicyConfigException
-     *             In case of issues with policy engine
+     *         In case of issues with policy engine
      */
-    protected boolean checkPolicyExists(String policyNamePrefix, ModelProperties prop) throws PolicyConfigException {
+    protected boolean checkPolicyExists(String policyNamePrefix, ModelProperties prop) {
         boolean policyexists = false;
-        ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
         String policyName = "";
-        if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
-            policyName = prop.getCurrentPolicyScopeAndFullPolicyName(policyNamePrefix) + "_" + prop.getPolicyUniqueId();
-        } else {
-            policyName = prop.getCurrentPolicyScopeAndFullPolicyName(policyNamePrefix);
-        }
-        logger.info("Search in Policy Engine for policyName=" + policyName);
-        configRequestParameters.setPolicyName(policyName);
         try {
+
+            if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
+                policyName = prop.getCurrentPolicyScopeAndFullPolicyName(policyNamePrefix) + "_"
+                    + prop.getPolicyUniqueId();
+            } else {
+                policyName = prop.getCurrentPolicyScopeAndFullPolicyName(policyNamePrefix);
+            }
+            logger.info("Search in Policy Engine for policyName=" + policyName);
+
+            ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
+            configRequestParameters.setPolicyName(policyName);
             Collection<String> response = getPolicyEngine().listConfig(configRequestParameters);
             if (response != null && !response.isEmpty() && !response.contains("Policy Name: null")) {
                 policyexists = true;
             }
-        } catch (PolicyConfigException e) {
+        } catch (PolicyConfigException e1) {
             // just print warning - if no policy version found
-            logger.warn("policy not found...policy name - " + policyName, e);
+            logger.warn("Policy not found...policy name - " + policyName, e1);
         }
         return policyexists;
     }
@@ -398,7 +434,7 @@ public class PolicyClient {
      * Format and send delete Micro Service requests to Policy.
      *
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @return The response message from Policy
      */
     public String deleteMicrosService(ModelProperties prop) {
@@ -420,7 +456,7 @@ public class PolicyClient {
      * This method delete the Base policy.
      *
      * @param prop
-     *            The model Properties
+     *        The model Properties
      * @return A string with the answer from policy
      */
     public String deleteBasePolicy(ModelProperties prop) {
@@ -431,15 +467,15 @@ public class PolicyClient {
      * Format and send delete Guard requests to Policy.
      *
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @return The response message from policy
      */
     public String deleteGuard(ModelProperties prop) {
         String deletePolicyResponse = "";
         try {
-            String policyNamePrefix = refProp.getStringValue(POLICY_OP_NAME_PREFIX_PROPERTY_NAME);
-            if (checkPolicyExists(policyNamePrefix, prop)) {
-                deletePolicyResponse = deletePolicy(prop, "Decision");
+
+            if (checkDecisionPolicyExists(prop)) {
+                deletePolicyResponse = deletePolicy(prop, DictionaryType.Decision.toString());
             }
         } catch (Exception e) {
             logger.error("Exception occurred during policy communication", e);
@@ -452,7 +488,7 @@ public class PolicyClient {
      * Format and send delete BRMS requests to Policy.
      *
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @return The response message from policy
      */
     public String deleteBrms(ModelProperties prop) {
@@ -474,13 +510,17 @@ public class PolicyClient {
      * Format and send delete PAP and PDP requests to Policy.
      *
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @return The response message from policy
      */
     protected String deletePolicy(ModelProperties prop, String policyType) {
         DeletePolicyParameters deletePolicyParameters = new DeletePolicyParameters();
         if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
-            deletePolicyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueId());
+            if (DictionaryType.Decision.toString().equals(policyType)) {
+                deletePolicyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueGuardId());
+            } else {
+                deletePolicyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueId());
+            }
         } else {
             deletePolicyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
         }
@@ -503,9 +543,9 @@ public class PolicyClient {
      * Send delete request to Policy.
      *
      * @param deletePolicyParameters
-     *            The DeletePolicyParameters
+     *        The DeletePolicyParameters
      * @param prop
-     *            The ModelProperties
+     *        The ModelProperties
      * @return The response message from policy
      */
     protected String sendDeletePolicy(DeletePolicyParameters deletePolicyParameters, ModelProperties prop) {
index d5f3ae2..f38e8c1 100644 (file)
@@ -18,7 +18,7 @@
  * limitations under the License.
  * ============LICENSE_END============================================
  * ===================================================================
- * 
+ *
  */
 
 package org.onap.clamp.clds.model.properties;
@@ -62,6 +62,8 @@ public class ModelProperties {
     private final Map<String, AbstractModelElement> modelElements = new ConcurrentHashMap<>();
     private String currentModelElementId;
     private String policyUniqueId;
+    private String guardUniqueId;
+    public static final String POLICY_GUARD_SUFFIX = "_Guard_";
     private static final Object lock = new Object();
     private static Map<Class<? extends AbstractModelElement>, String> modelElementClasses = new ConcurrentHashMap<>();
     static {
@@ -91,7 +93,7 @@ public class ModelProperties {
      *            The BPMN parameters for all boxes defined in modelBpmnTest
      */
     public ModelProperties(String modelName, String controlName, String actionCd, boolean isATest, String modelBpmnText,
-            String modelPropText) {
+        String modelPropText) {
         try {
             this.modelName = modelName;
             this.controlName = controlName;
@@ -118,19 +120,19 @@ public class ModelProperties {
             // Parse the list of base Model Elements and build up the
             // ModelElements
             modelElementClasses.entrySet().stream().parallel()
-                    .filter(entry -> (AbstractModelElement.class.isAssignableFrom(entry.getKey())
-                            && missingTypes.contains(entry.getValue())))
-                    .forEach(entry -> {
-                        try {
-                            modelElements.put(entry.getValue(),
-                                    (entry.getKey()
-                                            .getConstructor(ModelProperties.class, ModelBpmn.class, JsonNode.class)
-                                            .newInstance(this, modelBpmn, modelJson)));
-                        } catch (InstantiationException | NoSuchMethodException | IllegalAccessException
-                                | InvocationTargetException e) {
-                            logger.warn("Unable to instantiate a ModelElement, exception follows: ", e);
-                        }
-                    });
+            .filter(entry -> (AbstractModelElement.class.isAssignableFrom(entry.getKey())
+                && missingTypes.contains(entry.getValue())))
+            .forEach(entry -> {
+                try {
+                    modelElements.put(entry.getValue(),
+                        (entry.getKey()
+                            .getConstructor(ModelProperties.class, ModelBpmn.class, JsonNode.class)
+                            .newInstance(this, modelBpmn, modelJson)));
+                } catch (InstantiationException | NoSuchMethodException | IllegalAccessException
+                    | InvocationTargetException e) {
+                    logger.warn("Unable to instantiate a ModelElement, exception follows: ", e);
+                }
+            });
         }
     }
 
@@ -234,7 +236,7 @@ public class ModelProperties {
      */
     public String getPolicyNameForDcaeDeploy(ClampProperties refProp) {
         return normalizePolicyScopeName(modelName + createScopeSeparator(modelName)
-                + refProp.getStringValue(PolicyClient.POLICY_MS_NAME_PREFIX_PROPERTY_NAME) + getCurrentPolicyName());
+        + refProp.getStringValue(PolicyClient.POLICY_MS_NAME_PREFIX_PROPERTY_NAME) + getCurrentPolicyName());
     }
 
     /**
@@ -242,7 +244,15 @@ public class ModelProperties {
      */
     public String getPolicyScopeAndNameWithUniqueId() {
         return normalizePolicyScopeName(
-                modelName + createScopeSeparator(modelName) + getCurrentPolicyName() + "_" + policyUniqueId);
+            modelName + createScopeSeparator(modelName) + getCurrentPolicyName() + "_" + policyUniqueId);
+    }
+
+    /**
+     * @return the policyScopeAndNameWithUniqueId
+     */
+    public String getPolicyScopeAndNameWithUniqueGuardId() {
+        return normalizePolicyScopeName(
+            modelName + createScopeSeparator(modelName) + getCurrentPolicyName() + "_" + policyUniqueId+POLICY_GUARD_SUFFIX+guardUniqueId);
     }
 
     /**
@@ -250,7 +260,7 @@ public class ModelProperties {
      */
     public String getCurrentPolicyScopeAndFullPolicyName(String policyNamePrefix) {
         return normalizePolicyScopeName(
-                modelName + createScopeSeparator(modelName) + policyNamePrefix + getCurrentPolicyName());
+            modelName + createScopeSeparator(modelName) + policyNamePrefix + getCurrentPolicyName());
     }
 
     /**
@@ -288,6 +298,14 @@ public class ModelProperties {
         return policyUniqueId;
     }
 
+    public String getGuardUniqueId() {
+        return guardUniqueId;
+    }
+
+    public void setGuardUniqueId(String guardUniqueId) {
+        this.guardUniqueId = guardUniqueId;
+    }
+
     /**
      * When generating a policy request for a model element, must set the unique
      * id of that policy using this method. Used to generate the policy name.
@@ -318,17 +336,17 @@ public class ModelProperties {
      */
     public boolean isCreateRequest() {
         switch (actionCd) {
-            case CldsEvent.ACTION_SUBMIT:
-            case CldsEvent.ACTION_RESTART:
-                return true;
+        case CldsEvent.ACTION_SUBMIT:
+        case CldsEvent.ACTION_RESTART:
+            return true;
         }
         return false;
     }
 
     public boolean isStopRequest() {
         switch (actionCd) {
-            case CldsEvent.ACTION_STOP:
-                return true;
+        case CldsEvent.ACTION_STOP:
+            return true;
         }
         return false;
     }
@@ -344,7 +362,7 @@ public class ModelProperties {
     }
 
     public static final synchronized void registerModelElement(Class<? extends AbstractModelElement> modelElementClass,
-            String type) {
+        String type) {
         if (!modelElementClasses.containsKey(modelElementClass.getClass())) {
             modelElementClasses.put(modelElementClass, type);
         }
index 25cc9a0..a527f53 100644 (file)
@@ -293,8 +293,8 @@ label {
                                                                                <select class="form-control"
                                                                                name="guardPolicyType" id="guardPolicyType"
                                                                                onchange="changeGuardPolicyType();">
-                                                                               <option value="MinMax">MinMax</option>
-                                                                               <option value="FrequencyLimiter">FrequencyLimiter</option>
+                                                                               <option value="GUARD_MIN_MAX">MinMax</option>
+                                                                               <option value="GUARD_YAML">FrequencyLimiter</option>
                                                                        </select>
                                                                </div>
                                                                <label for="guardTargets" class="col-sm-4 control-label">Guard
@@ -378,16 +378,14 @@ label {
                        $("#targetResourceIdOther").val("");
                }
        }
-       
+
        function changeGuardPolicyType() {
                console.log("executing GuardPolicyType")
                console.log("GuardPolicyType value:"+$("#guardPolicyType").val())
-               if ($("#guardPolicyType").val()==="MinMax") {
-                       console.log("executing GuardPolicyType")
+               if ($("#guardPolicyType").val()==="GUARD_MIN_MAX") {
                        $("#minMaxGuardPolicyDiv").show();
                        $("#frequencyLimiterGuardPolicyDiv").hide();
-               } else if ($("#guardPolicyType").val()==="FrequencyLimiter") {
-                       console.log("executing GuardPolicyType")
+               } else if ($("#guardPolicyType").val()==="GUARD_YAML") {
                        $("#minMaxGuardPolicyDiv").hide();
                        $("#frequencyLimiterGuardPolicyDiv").show();
                }
index c4299fa..8ea3bb4 100644 (file)
                                                {
                                                        "name": "guardPolicyType",
                                                        "value": [
-                                                               "FrequencyLimiter"
+                                                               "GUARD_YAML"
                                                        ]
                                                },
                                                {
                                                {
                                                        "name": "guardPolicyType",
                                                        "value": [
-                                                               "MinMax"
+                                                               "GUARD_MIN_MAX"
                                                        ]
                                                },
                                                {