Merge "Add plugin in logstash image"
authorSébastien Determe <sd378r@intl.att.com>
Tue, 18 Sep 2018 08:27:51 +0000 (08:27 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 18 Sep 2018 08:27:51 +0000 (08:27 +0000)
19 files changed:
src/main/java/org/onap/clamp/clds/client/GuardPolicyDelegate.java [new file with mode: 0644]
src/main/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegate.java [new file with mode: 0644]
src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java [new file with mode: 0644]
src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
src/main/java/org/onap/clamp/clds/dao/CldsDao.java
src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java
src/main/java/org/onap/clamp/clds/service/CldsService.java
src/main/resources/META-INF/resources/designer/menu_simplified.html
src/main/resources/META-INF/resources/designer/partials/menu.html
src/main/resources/META-INF/resources/designer/partials/portfolios/PolicyWindow_properties.html
src/main/resources/META-INF/resources/designer/partials/portfolios/Template_model.html
src/main/resources/META-INF/resources/designer/partials/portfolios/refresh_asdc.html
src/main/resources/META-INF/resources/designer/partials/portfolios/tca_properties.html
src/main/resources/application-noaaf.properties
src/main/resources/application.properties
src/main/resources/boot-message.txt
src/main/resources/clds/camel/routes/flexible-flow.xml
src/main/resources/clds/templates/globalProperties.json
src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java

diff --git a/src/main/java/org/onap/clamp/clds/client/GuardPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/GuardPolicyDelegate.java
new file mode 100644 (file)
index 0000000..9287abb
--- /dev/null
@@ -0,0 +1,98 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds.client;
+
+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;
+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.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.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.
+ */
+@Component
+public class GuardPolicyDelegate {
+
+    protected static final EELFLogger logger = EELFManager.getInstance().getLogger(GuardPolicyDelegate.class);
+    protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+    private final PolicyClient policyClient;
+    private final ClampProperties refProp;
+
+    @Autowired
+    public GuardPolicyDelegate(PolicyClient policyClient, ClampProperties refProp) {
+        this.policyClient = policyClient;
+        this.refProp = refProp;
+    }
+
+    /**
+     * Perform activity. Send Guard Policies info to policy api.
+     *
+     * @param camelExchange
+     *        The Camel Exchange object containing the properties
+     * @throws BuilderException
+     *         In case of issues with OperationalPolicyRequestAttributesConstructor
+     * @throws UnsupportedEncodingException
+     *         In case of issues with the Charset encoding
+     */
+    @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);
+                }
+            }
+            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());
+    }
+}
diff --git a/src/main/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegate.java b/src/main/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegate.java
new file mode 100644 (file)
index 0000000..9e8e1b8
--- /dev/null
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds.client;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Handler;
+import org.onap.clamp.clds.client.req.policy.PolicyClient;
+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.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * Delete Operational Policy via policy api.
+ */
+@Component
+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;
+
+    /**
+     * Perform activity. Delete Operational Policy via policy api.
+     *
+     * @param camelExchange
+     *            The Camel Exchange object containing the properties
+     */
+    @Handler
+    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());
+            }
+        }
+    }
+}
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java b/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java
new file mode 100644 (file)
index 0000000..f11b492
--- /dev/null
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds.client.req.policy;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.util.HashMap;
+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.PolicyItem;
+import org.onap.policy.api.AttributeType;
+
+public class GuardPolicyAttributesConstructor {
+    private static final EELFLogger logger = EELFManager.getInstance()
+        .getLogger(GuardPolicyAttributesConstructor.class);
+
+    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);
+        return createAttributesMap(matchingAttributes);
+    }
+
+    private static Map<String, String> prepareMatchingAttributes(ClampProperties refProp,
+        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())) {
+            matchingAttributes.put("min",policyItem.getMinGuard());
+            matchingAttributes.put("max",policyItem.getMaxGuard());
+        } else if ("FrequencyLimiter".equals(policyItem.getGuardPolicyType())) {
+            matchingAttributes.put("limit",policyItem.getLimitGuard());
+            matchingAttributes.put("timeWindow",policyItem.getTimeWindowGuard());
+            matchingAttributes.put("timeUnits",policyItem.getTimeUnitsGuard());
+        }
+        matchingAttributes.put("guardActiveStart",policyItem.getGuardActiveStart());
+        matchingAttributes.put("guardActiveEnd",policyItem.getGuardActiveEnd());
+
+        logger.info("Prepared: " + matchingAttributes);
+        return matchingAttributes;
+    }
+
+    private static Map<AttributeType, Map<String, String>> createAttributesMap(Map<String, String> matchingAttributes) {
+        Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
+        attributes.put(AttributeType.MATCHING, matchingAttributes);
+        return attributes;
+    }
+}
index cd387b3..58366d9 100644 (file)
@@ -43,6 +43,7 @@ import org.onap.policy.api.ConfigRequestParameters;
 import org.onap.policy.api.DeletePolicyCondition;
 import org.onap.policy.api.DeletePolicyParameters;
 import org.onap.policy.api.PolicyChangeResponse;
+import org.onap.policy.api.PolicyClass;
 import org.onap.policy.api.PolicyConfigException;
 import org.onap.policy.api.PolicyConfigType;
 import org.onap.policy.api.PolicyEngine;
@@ -50,6 +51,7 @@ import org.onap.policy.api.PolicyEngineException;
 import org.onap.policy.api.PolicyParameters;
 import org.onap.policy.api.PolicyType;
 import org.onap.policy.api.PushPolicyParameters;
+import org.onap.policy.api.RuleProvider;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Primary;
@@ -79,6 +81,40 @@ public class PolicyClient {
     @Autowired
     private PolicyConfiguration policyConfiguration;
 
+    /**
+     * Perform Guard policy type.
+     *
+     * @param attributes
+     *            A map of attributes
+     * @param prop
+     *            The ModelProperties
+     * @param policyRequestUuid
+     *            PolicyRequest UUID
+     * @return The response message of policy
+     */
+    public String sendGuardPolicy(Map<AttributeType, Map<String, String>> attributes, ModelProperties prop,
+        String policyRequestUuid) {
+        PolicyParameters policyParameters = new PolicyParameters();
+        // Set Policy Type(Mandatory)
+        policyParameters.setPolicyClass(PolicyClass.Decision);
+        // Set Policy Name(Mandatory)
+        policyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueId()+"Guard");
+        // 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.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);
+        return rtnMsg;
+    }
+
     /**
      * Perform BRMS policy type.
      *
@@ -332,7 +368,7 @@ public class PolicyClient {
         configRequestParameters.setPolicyName(policyName);
         try {
             Collection<String> response = getPolicyEngine().listConfig(configRequestParameters);
-            if (response != null && !response.isEmpty()) {
+            if (response != null && !response.isEmpty() && !response.contains("Policy Name: null")) {
                 policyexists = true;
             }
         } catch (PolicyConfigException e) {
@@ -391,6 +427,27 @@ public class PolicyClient {
         return deletePolicy(prop, PolicyConfigType.Base.toString());
     }
 
+    /**
+     * Format and send delete Guard requests to Policy.
+     *
+     * @param prop
+     *            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");
+            }
+        } catch (Exception e) {
+            logger.error("Exception occurred during policy communication", e);
+            throw new PolicyClientException("Exception while communicating with Policy", e);
+        }
+        return deletePolicyResponse;
+    }
+
     /**
      * Format and send delete BRMS requests to Policy.
      *
index 54a5196..d3e89fb 100644 (file)
@@ -277,7 +277,7 @@ public class CldsDao {
      *
      * @return model names
      */
-    public List<ValueItem> getBpmnNames() {
+    public List<ValueItem> getModelNames() {
         String sql = "SELECT model_name FROM model ORDER BY 1;";
         return jdbcTemplateObject.query(sql, new ValueItemMapper());
     }
index 7caba41..2ac51ab 100644 (file)
@@ -71,6 +71,17 @@ public class PolicyItem implements Cloneable {
     private String oapRop;
     private String oapLimit;
 
+    private String enableGuardPolicy;
+    private String guardPolicyType;
+    private String guardTargets;
+    private String minGuard;
+    private String maxGuard;
+    private String limitGuard;
+    private String timeUnitsGuard;
+    private String timeWindowGuard;
+    private String guardActiveStart;
+    private String guardActiveEnd;
+
     /**
      * Parse Policy given json node.
      *
@@ -99,6 +110,17 @@ public class PolicyItem implements Cloneable {
         oapRop = AbstractModelElement.getValueByName(node, "oapRop");
         oapLimit = AbstractModelElement.getValueByName(node, "oapLimit");
         actor = AbstractModelElement.getValueByName(node, "actor");
+
+        enableGuardPolicy = AbstractModelElement.getValueByName(node, "enableGuardPolicy");
+        guardPolicyType = AbstractModelElement.getValueByName(node, "guardPolicyType");
+        guardTargets = AbstractModelElement.getValueByName(node, "guardTargets");
+        minGuard = AbstractModelElement.getValueByName(node, "minGuard");
+        maxGuard = AbstractModelElement.getValueByName(node, "maxGuard");
+        limitGuard = AbstractModelElement.getValueByName(node, "limitGuard");
+        timeUnitsGuard = AbstractModelElement.getValueByName(node, "timeUnitsGuard");
+        timeWindowGuard = AbstractModelElement.getValueByName(node, "timeWindowGuard");
+        guardActiveStart = AbstractModelElement.getValueByName(node, "guardActiveStart");
+        guardActiveEnd = AbstractModelElement.getValueByName(node, "guardActiveEnd");
     }
 
     /**
@@ -236,4 +258,45 @@ public class PolicyItem implements Cloneable {
         }
         return oapLimit;
     }
+
+    public String getEnableGuardPolicy() {
+        return enableGuardPolicy;
+    }
+
+    public String getGuardPolicyType() {
+        return guardPolicyType;
+    }
+
+    public String getGuardTargets() {
+        return guardTargets;
+    }
+
+    public String getMinGuard() {
+        return minGuard;
+    }
+
+    public String getMaxGuard() {
+        return maxGuard;
+    }
+
+    public String getLimitGuard() {
+        return limitGuard;
+    }
+
+    public String getTimeUnitsGuard() {
+        return timeUnitsGuard;
+    }
+
+    public String getTimeWindowGuard() {
+        return timeWindowGuard;
+    }
+
+    public String getGuardActiveStart() {
+        return guardActiveStart;
+    }
+
+    public String getGuardActiveEnd() {
+        return guardActiveEnd;
+    }
+
 }
index 521f3ce..243881f 100644 (file)
@@ -300,7 +300,7 @@ public class CldsService extends SecureServiceBase {
         Date startTime = new Date();
         isAuthorized(permissionReadCl);
         logger.info("GET list of model names");
-        List<ValueItem> names = cldsDao.getBpmnNames();
+        List<ValueItem> names = cldsDao.getModelNames();
         // audit log
         LoggingUtils.setTimeContext(startTime, new Date());
         auditLogger.info("GET model names completed");
index 0131015..530ad61 100644 (file)
@@ -46,7 +46,7 @@
                                width="234px" style="display: inline-block; float: left">
                        <div class="navbar-brand logo" ng-href=""
                                style="display: inline-block; float: left">
-                               &nbsp;&nbsp;<b>Closed Loop Definition</b>
+                               &nbsp;&nbsp;<b>CLAMP</b>
                        </div>
                </div>
 
index 48544df..d3ffe38 100644 (file)
 .ThisLink a.blur:hover,.ThisLink a.blur:focus {
        color: #933;
 }
-
-.fileUpload {
-       position: relative;
-       overflow: hidden;
-       margin: 10px;
-}
-
-.fileUpload input.upload {
-       position: absolute;
-       top: 0;
-       right: 0;
-       margin: 0;
-       padding: 0;
-       font-size: 20px;
-       cursor: pointer;
-       opacity: 0;
-       filter: alpha(opacity = 0);
-       float: left;
-}
-
-.fileDisplay {
-       display: inline-block;
-       overflow: hidden;
-       float: right;
-       margin-left: 0px;
-       z-index: initial;
-       text-align: center;
-       margin-top: 17px;
-}
 </style>
 
 <nav attribute-test="menu" class="navbar navbar-default navbar-fixed-top" role="navigation"
index 5109c1b..25cc9a0 100644 (file)
        background-color: #dddd;
 }
 
-.fileUpload {
-       position: relative;
-       overflow: hidden;
-       margin: 10px;
-}
-
-.fileUpload input.upload {
-       position: absolute;
-       top: 0;
-       right: 0;
-       margin: 0;
-       padding: 0;
-       font-size: 20px;
-       cursor: pointer;
-       opacity: 0;
-       filter: alpha(opacity = 0);
-       float: left;
-}
-
-.fileDisplay {
-       display: inline-block;
-       overflow: hidden;
-       float: right;
-       margin-left: 0px;
-       z-index: initial;
-       text-align: center;
-       margin-top: 17px;
-}
-
 .modelSearchBox {
        position: absolute;
        padding: 25px 12px;
@@ -141,28 +112,6 @@ label {
 }
 </style>
 
-<script type="text/javascript">
-       function disablefile() {
-
-               document.getElementById("fileUpload").disabled = true;
-
-       }
-
-       function disableSVN() {
-               var selectLength = document.querySelectorAll(".disabled-block-container .tab-close-popup");
-               if(selectLength && selectLength.length>0){
-                       for(var i = 0; i< selectLength.length ; i++){
-                               selectLength[i].disabled = true;
-                       }       
-               }
-
-               document.getElementById("schemaLocation").disabled = true;
-               document.getElementById("userID").disabled = true;
-               document.getElementById("password").disabled = true;
-
-       }
-</script>
-
 
 <div attribute-test="policywindowproperties" id="configure-widgets"
        class="disabled-block-container">
@@ -306,8 +255,7 @@ label {
                                                        <label for="payload" class="col-sm-4 control-label">
                                                                Payload</label>
                                                        <div class="col-sm-8">
-                                                               <textarea class="form-control" id="recipeInput"
-                                                                       name=recipeInput></textarea >
+                                                               <textarea class="form-control" id="recipeInput" name=recipeInput></textarea>
                                                        </div>
                                                </div>
                                                <div class="form-group clearfix">
@@ -331,6 +279,75 @@ label {
                                                        <input type="text" style="display: none" class="form-control"
                                                                id="targetResourceIdOther" name="targetResourceIdOther" value=""></input>
                                                </div>
+                                               <div style="border: 2px dotted gray;">
+                                                       <div class="form-group clearfix">
+                                                               <label for="enableGuardPolicy" class="col-sm-4 control-label">
+                                                                       Enable Guard Policy</label>
+                                                               <div class="col-sm-8">
+                                                                       <input type="checkbox" class="form-control"
+                                                                               name="enableGuardPolicy" id="enableGuardPolicy">
+                                                               </div>
+                                                               <div class="col-sm-8">
+                                                                       <label for="guardPolicyType" class="col-sm-4 control-label">
+                                                                               Guard Policy Type</label> 
+                                                                               <select class="form-control"
+                                                                               name="guardPolicyType" id="guardPolicyType"
+                                                                               onchange="changeGuardPolicyType();">
+                                                                               <option value="MinMax">MinMax</option>
+                                                                               <option value="FrequencyLimiter">FrequencyLimiter</option>
+                                                                       </select>
+                                                               </div>
+                                                               <label for="guardTargets" class="col-sm-4 control-label">Guard
+                                                                       targets</label>
+                                                               <div class="col-sm-8">
+                                                                       <input class="form-control" name="guardTargets"
+                                                                               id="guardTargets" />
+                                                               </div>
+                                                       </div>
+
+                                                       <div class="form-group clearfix" id="minMaxGuardPolicyDiv">
+                                                               <label for="minGuard" class="col-sm-4 control-label">
+                                                                       Min Guard</label>
+                                                               <div class="col-sm-8">
+                                                                       <input class="form-control" name="minGuard" id="minGuard" />
+                                                               </div>
+                                                               <label for="maxGuard" class="col-sm-4 control-label">
+                                                                       Max Guard</label>
+                                                               <div class="col-sm-8">
+                                                                       <input class="form-control" name="maxGuard" id="maxGuard" />
+                                                               </div>
+                                                       </div>
+                                                       <div class="form-group clearfix"
+                                                               id="frequencyLimiterGuardPolicyDiv" style="display: none">
+                                                               <label for="limitGuard" class="col-sm-4 control-label">Limit</label>
+                                                               <div class="col-sm-8">
+                                                                       <input class="form-control" name="limitGuard" id="limitGuard" />
+                                                               </div>
+                                                               <div class="col-sm-8">
+                                                                       <select class="form-control" name="timeUnitsGuard"
+                                                                               id="timeUnitsGuard" /> <label for="timeWindowGuard"
+                                                                               class="col-sm-4 control-label">Time Window</label>
+                                                               </div>
+                                                               <div class="col-sm-8">
+                                                                       <input class="form-control" name="timeWindowGuard"
+                                                                               id="timeWindowGuard" />
+                                                               </div>
+                                                       </div>
+                                                       <div class="form-group clearfix">
+                                                               <label for="guardActiveStart" class="col-sm-4 control-label">
+                                                                       Guard Active Start</label>
+                                                               <div class="col-sm-8">
+                                                                       <input class="form-control" name="guardActiveStart"
+                                                                               id="guardActiveStart" />
+                                                               </div>
+                                                               <label for="guardActiveEnd" class="col-sm-4 control-label">
+                                                                       Guard Active End</label>
+                                                               <div class="col-sm-8">
+                                                                       <input class="form-control" name="guardActiveEnd"
+                                                                               id="guardActiveEnd" />
+                                                               </div>
+                                                       </div>
+                                               </div>
                                        </div>
                                </form>
                        </span>
@@ -361,6 +378,20 @@ label {
                        $("#targetResourceIdOther").val("");
                }
        }
+       
+       function changeGuardPolicyType() {
+               console.log("executing GuardPolicyType")
+               console.log("GuardPolicyType value:"+$("#guardPolicyType").val())
+               if ($("#guardPolicyType").val()==="MinMax") {
+                       console.log("executing GuardPolicyType")
+                       $("#minMaxGuardPolicyDiv").show();
+                       $("#frequencyLimiterGuardPolicyDiv").hide();
+               } else if ($("#guardPolicyType").val()==="FrequencyLimiter") {
+                       console.log("executing GuardPolicyType")
+                       $("#minMaxGuardPolicyDiv").hide();
+                       $("#frequencyLimiterGuardPolicyDiv").show();
+               }
+       }
                //Basically this method will add a new form. All forms share the same class. When you want one form to show(active form) the other forms get the 
                // css attribute display:none
                $("#add_one_more").click(function(event) {
@@ -466,7 +497,7 @@ label {
                        });
                                $('input[value="multiselect-all"]').prop('disabled', true).parent('li').addClass('disabled');
                        }
-                       
+                       changeGuardPolicyType();
                }
 
                        function addSelectListen(count) {
@@ -871,6 +902,7 @@ label {
                
                setASDCFields();
                initTargetResourceId();
+               
                //load metrics dropdown
                if (elementMap["global"]){
                        for (var i = 0; i < (elementMap["global"].length); i++){
@@ -889,7 +921,6 @@ label {
                                };
                        };
                };
-               
                //Show table panel only
                function expandTable() {
                        $(".policyPanel").css("display", "none");
index 53204f4..0ca4e7c 100644 (file)
   
   -->
 
-<style>
-    .fileUpload {
-        position: relative;
-        overflow: hidden;
-        margin: 10px;
-    }
-    .fileUpload input.upload {
-        position: absolute;
-        top: 0;
-        right: 0;
-        margin: 0;
-        padding: 0;
-        font-size: 20px;
-        cursor: pointer;
-        opacity: 0;
-        filter: alpha(opacity=0);
-        float:left;
-    }
-    .fileDisplay {
-
-        display: inline-block;
-        overflow: hidden;
-        float: right;
-        margin-left: 0px;
-        z-index: initial;
-        text-align: center;
-        margin-top: 17px;
-    }
-
-
-</style>
-
-
 <div attribute-test="templatemodel" id="configure-widgets"  >
     <div attribute-test="templatemodelh" class="modal-header">
         <button type="button" class="close" ng-click="close(false)" aria-hidden="true" style="margin-top: -3px">&times;</button>
index 7f6e9e1..441766d 100644 (file)
   -->
 
 <style>
-.fileUpload {
-       position: relative;
-       overflow: hidden;
-       margin: 10px;
-}
 #paramsWarnrefresh {
     display: none;
 }
 
-.fileUpload input.upload {
-       position: absolute;
-       top: 0;
-       right: 0;
-       margin: 0;
-       padding: 0;
-       font-size: 20px;
-       cursor: pointer;
-       opacity: 0;
-       filter: alpha(opacity = 0);
-       float: left;
-}
-
-.fileDisplay {
-       display: inline-block;
-       overflow: hidden;
-       float: right;
-       margin-left: 0px;
-       z-index: initial;
-       text-align: center;
-       margin-top: 17px;
-}
 </style>
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
-<script type="text/javascript">
-       function disablefile() {
-
-               document.getElementById("fileUpload").disabled = true;
-
-       }
-
-       function disableSVN() {
-
-               document.getElementById("schemaLocation").disabled = true;
-               document.getElementById("userID").disabled = true;
-               document.getElementById("password").disabled = true;
-
-       }
-</script>
-
-
 <div attribute-test="refreshasdc" id="configure-widgets">
        <div attribute-test="refreshasdch" class="modal-header">
                <button type="button" class="close" ng-click="close(false)"
index 8332e69..89b13fa 100644 (file)
        background-color:#dddd;
 }
 
-.fileUpload {
-       position: relative;
-       overflow: hidden;
-       margin: 10px;
-}
-
-.fileUpload input.upload {
-       position: absolute;
-       top: 0;
-       right: 0;
-       margin: 0;
-       padding: 0;
-       font-size: 20px;
-       cursor: pointer;
-       opacity: 0;
-       filter: alpha(opacity = 0);
-       float: left;
-}
-
-.fileDisplay {
-       display: inline-block;
-       overflow: hidden;
-       float: right;
-       margin-left: 0px;
-       z-index: initial;
-       text-align: center;
-       margin-top: 17px;
-}
-
 .form-group {
        margin-bottom:15px;
        display:-webkit-flex; 
 
 </style>
 
-<script type="text/javascript">
-       function disablefile() {
-
-               document.getElementById("fileUpload").disabled = true;
-
-       }
-
-       function disableSVN() {
-               var selectLength =  document.querySelectorAll(".disabled-block-container .tab-close-popup");
-               if(selectLength && selectLength.length>0){
-                       for(var i = 0; i< selectLength.length ; i++){
-                               selectLength[i].disabled = true;
-                       }       
-               }
-       
-               document.getElementById("schemaLocation").disabled = true;
-               document.getElementById("userID").disabled = true;
-               document.getElementById("password").disabled = true;
-
-       }
-</script>
-
-
 <div id="configure-widgets" class="disabled-block-container">
        <div class="modal-header">
                <button type="button" class="close" ng-click="close(false)"
index fe7eabc..0ce8a7b 100644 (file)
@@ -197,12 +197,12 @@ clamp.config.clds.service.cache.invalidate.after.seconds=120
 #DCAE Inventory Url Properties
 clamp.config.dcae.inventory.url=http://dcae.api.simpledemo.onap.org:8080
 clamp.config.dcae.intentory.retry.interval=10000
-clamp.config.dcae.intentory.retry.limit=3
+clamp.config.dcae.intentory.retry.limit=5
 
 #DCAE Dispatcher Url Properties
 clamp.config.dcae.dispatcher.url=http://dcae.api.simpledemo.onap.org:8188
-clamp.config.dcae.dispatcher.retry.interval=10000
-clamp.config.dcae.dispatcher.retry.limit=10
+clamp.config.dcae.dispatcher.retry.interval=20000
+clamp.config.dcae.dispatcher.retry.limit=30
 clamp.config.dcae.header.requestId = X-ECOMP-RequestID
 
 #Define user permission related parameters, the permission type can be changed but MUST be redefined in clds-users.properties in that case !
index 9e2e3c9..cdbe613 100644 (file)
@@ -177,7 +177,7 @@ clamp.config.tca.thresholds.template=classpath:/clds/templates/tca-thresholds-te
 #
 # Operational Policy request build properties
 #
-clamp.config.op.policyDescription=from clds
+clamp.config.op.policyDescription=from CLAMP
 # default
 clamp.config.op.templateName=ClosedLoopControlName
 clamp.config.op.operationTopic=APPC-CL
@@ -214,12 +214,12 @@ clamp.config.clds.service.cache.invalidate.after.seconds=120
 #DCAE Inventory Url Properties
 clamp.config.dcae.inventory.url=http://dcae.api.simpledemo.onap.org:8080
 clamp.config.dcae.intentory.retry.interval=10000
-clamp.config.dcae.intentory.retry.limit=3
+clamp.config.dcae.intentory.retry.limit=5
 
 #DCAE Dispatcher Url Properties
 clamp.config.dcae.dispatcher.url=http://dcae.api.simpledemo.onap.org:8188
-clamp.config.dcae.dispatcher.retry.interval=10000
-clamp.config.dcae.dispatcher.retry.limit=10
+clamp.config.dcae.dispatcher.retry.interval=20000
+clamp.config.dcae.dispatcher.retry.limit=30
 clamp.config.dcae.header.requestId = X-ECOMP-RequestID
 
 #Define user permission related parameters, the permission type can be changed but MUST be redefined in clds-users.properties in that case !
index d8763e2..eea540b 100644 (file)
@@ -1,10 +1,10 @@
+     
+         
+╔═╗╔╗╔╔═╗╔═╗  ╔═╗┌─┐┌─┐┌─┐┌┐ ┬  ┌─┐┌┐┌┌─┐┌─┐
+║ ║║║║╠═╣╠═╝  ║  ├─┤└─┐├─┤├┴┐│  ├─┤││││  ├─┤
+╚═╝╝╚╝╩ ╩╩    ╚═╝┴ ┴└─┘┴ ┴└─┘┴─┘┴ ┴┘└┘└─┘┴ ┴
+        ╔═╗╦  ╔═╗╔╦╗╔═╗                     
+        ║  ║  ╠═╣║║║╠═╝                     
+        ╚═╝╩═╝╩ ╩╩ ╩╩                       
 
- __          __          __      __      __              __      
-/  \|\ | /\ |__)   __   /  ` /\ /__` /\ |__)|    /\ |\ |/  ` /\  
-\__/| \|/~~\|           \__,/~~\.__//~~\|__)|___/~~\| \|\__,/~~\ 
-
-\   __   /          __              __                \   __   / 
- \ /  \ /          /  `|    /\ |\/||__)   |||          \ /  \ /  
-  \\__//           \__,|___/~~\|  ||      |||           \\__//   
-
-     Starting ::     
\ No newline at end of file
+   :: Starting ::     
\ No newline at end of file
index 8305c2e..c7f7ec3 100644 (file)
@@ -10,6 +10,7 @@
                                                                                <constant>30000</constant>
                                                                </delay>
                                                                <to uri="bean:org.onap.clamp.clds.client.OperationalPolicyDelegate" />
+                                                               <to uri="bean:org.onap.clamp.clds.client.GuardPolicyDelegate" />
                                                                <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate" />
                                                </when>
                                                <when>
@@ -22,6 +23,7 @@
                                                                </delay>
                                                                <to
                                                                                uri="bean:org.onap.clamp.clds.client.OperationalPolicyDeleteDelegate" />
+                                                               <to uri="bean:org.onap.clamp.clds.client.GuardPolicyDeleteDelegate" />
                                                </when>
                                                <when>
                                                                <simple> ${exchangeProperty.actionCd} == 'UPDATE'</simple>
                                                                                <constant>30000</constant>
                                                                </delay>
                                                                <to uri="bean:org.onap.clamp.clds.client.OperationalPolicyDelegate" />
+                                                               <to uri="bean:org.onap.clamp.clds.client.GuardPolicyDelegate" />
                                                                <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate" />
                                                </when>
                                                <when>
                                                                <simple> ${exchangeProperty.actionCd} == 'STOP'</simple>
                                                                <to
                                                                                uri="bean:org.onap.clamp.clds.client.OperationalPolicyDeleteDelegate" />
+                                                               <to uri="bean:org.onap.clamp.clds.client.GuardPolicyDeleteDelegate" />
                                                                <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate" />
                                                </when>
                                                <when>
                                                                <simple> ${exchangeProperty.actionCd} == 'RESTART'</simple>
+                                                               <to uri="bean:org.onap.clamp.clds.client.GuardPolicyDelegate" />
                                                                <to uri="bean:org.onap.clamp.clds.client.OperationalPolicyDelegate" />
                                                                <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate" />
                                                </when>
index 880b992..b6f68f6 100644 (file)
                        "Failure_Exception": "Failure: Exception",
                        "Failure": "Failure: Other",
                        "Success": "Success"
-               }
+               },
+               "guardTargets": ".*",
+               "minGuard":1,
+               "maxGuard":1,
+               "limitGuard":1,
+               "timeUnitsGuard":{
+                       "minute":"minute",
+                       "hour":"hour",
+                       "day":"day",
+                       "week":"week",
+                       "month":"month",
+                       "year":"year"
+               },
+               "timeWindowGuard":10,
+               "guardActiveStart":"00:00:01-05:00",
+               "guardActiveEnd":"00:00:00-05:00"
        },
        "shared": {
                "byService": {
index 8e7e70d..3c508bd 100644 (file)
@@ -5,20 +5,20 @@
  * 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.
  * You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software 
- * distributed under the License is distributed on an "AS IS" BASIS, 
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
- * See the License for the specific language governing permissions and 
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END============================================
  * ===================================================================
- * 
+ *
  */
 
 package org.onap.clamp.clds.it;
@@ -34,22 +34,22 @@ import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils;
 import java.io.IOException;
 import java.io.InputStream;
 import java.security.GeneralSecurityException;
-import java.security.Principal;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.xml.transform.TransformerException;
 
 import org.apache.commons.codec.DecoderException;
 import org.json.JSONException;
+import org.json.simple.parser.ParseException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mockito;
 import org.onap.clamp.clds.dao.CldsDao;
-import org.onap.clamp.clds.model.CldsHealthCheck;
 import org.onap.clamp.clds.model.CldsInfo;
 import org.onap.clamp.clds.model.CldsModel;
 import org.onap.clamp.clds.model.CldsServiceData;
@@ -62,9 +62,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.context.SecurityContext;
 import org.springframework.security.core.userdetails.User;
 import org.springframework.security.core.userdetails.UserDetails;
@@ -89,7 +89,7 @@ public class CldsServiceItCase {
     private LoggingUtils util;
     /**
      * Setup the variable before the tests execution.
-     * 
+     *
      * @throws IOException
      *             In case of issues when opening the files
      */
@@ -99,6 +99,7 @@ public class CldsServiceItCase {
         imageText = ResourceFileUtil.getResourceAsString("example/dao/image-template.xml");
         bpmnPropText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-prop.json");
 
+        authList.add(new SimpleGrantedAuthority("permission-type-cl-manage|dev|*"));
         authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|read"));
         authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|update"));
         authList.add(new SimpleGrantedAuthority("permission-type-template|dev|read"));
@@ -148,7 +149,7 @@ public class CldsServiceItCase {
     }
 
     @Test
-    public void testPutModel() {
+    public void testCompleteFlow() throws TransformerException, ParseException {
         SecurityContext securityContext = Mockito.mock(SecurityContext.class);
         Mockito.when(securityContext.getAuthentication()).thenReturn(authentication);
 
@@ -166,43 +167,50 @@ public class CldsServiceItCase {
         assertEquals(bpmnText, newTemplateRead.getBpmnText());
         assertEquals(imageText, newTemplateRead.getImageText());
         // Save the model
+        String randomNameModel = RandomStringUtils.randomAlphanumeric(5);
         CldsModel newModel = new CldsModel();
-        newModel.setName(randomNameTemplate);
+        newModel.setName(randomNameModel);
         newModel.setBpmnText(bpmnText);
         newModel.setImageText(imageText);
         newModel.setPropText(bpmnPropText);
         newModel.setControlNamePrefix("ClosedLoop-");
-        newModel.setTemplateName("test-template");
+        newModel.setTemplateName(randomNameTemplate);
         newModel.setTemplateId(newTemplate.getId());
         newModel.setDocText(newTemplate.getPropText());
         // Test the PutModel method
-        String randomNameModel = RandomStringUtils.randomAlphanumeric(5);
+
         cldsService.putModel(randomNameModel, newModel);
         // Verify whether it has been added properly or not
         assertNotNull(cldsDao.getModel(randomNameModel));
+
+        // Verify with GetModel
+        assertEquals(cldsService.getModel(randomNameModel).getTemplateName(),randomNameTemplate);
+        assertEquals(cldsService.getModel(randomNameModel).getName(),randomNameModel);
+
+        assertTrue(cldsService.getModelNames().size() >= 1);
     }
 
     @Test
     public void testGetSdcServices() throws GeneralSecurityException, DecoderException, JSONException, IOException {
         String result = cldsService.getSdcServices();
         JSONAssert.assertEquals(
-                ResourceFileUtil.getResourceAsString("example/sdc/expected-result/all-sdc-services.json"), result,
-                true);
+            ResourceFileUtil.getResourceAsString("example/sdc/expected-result/all-sdc-services.json"), result,
+            true);
     }
 
     @Test
     public void testGetSdcPropertiesByServiceUuidForRefresh()
-            throws GeneralSecurityException, DecoderException, JSONException, IOException {
+        throws GeneralSecurityException, DecoderException, JSONException, IOException {
         SecurityContext securityContext = Mockito.mock(SecurityContext.class);
         Mockito.when(securityContext.getAuthentication()).thenReturn(authentication);
 
         cldsService.setSecurityContext(securityContext);
         // Test basic functionalities
         String result = cldsService.getSdcPropertiesByServiceUUIDForRefresh("4cc5b45a-1f63-4194-8100-cd8e14248c92",
-                false);
+            false);
         JSONAssert.assertEquals(
-                ResourceFileUtil.getResourceAsString("example/sdc/expected-result/sdc-properties-4cc5b45a.json"),
-                result, true);
+            ResourceFileUtil.getResourceAsString("example/sdc/expected-result/sdc-properties-4cc5b45a.json"),
+            result, true);
         // Now test the Cache effect
         CldsServiceData cldsServiceDataCache = cldsDao.getCldsServiceCache("c95b0e7c-c1f0-4287-9928-7964c5377a46");
         // Should not be there, so should be null