diff options
19 files changed, 528 insertions, 257 deletions
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 index 000000000..9287abbce --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/client/GuardPolicyDelegate.java @@ -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 index 000000000..9e8e1b8c5 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegate.java @@ -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 index 000000000..f11b492c0 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java @@ -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; + } +} diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java index cd387b3c3..58366d954 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java @@ -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; @@ -80,6 +82,40 @@ public class PolicyClient { 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. * * @param attributes @@ -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) { @@ -392,6 +428,27 @@ public class PolicyClient { } /** + * 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. * * @param prop diff --git a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java index 54a5196c1..d3e89fb6b 100644 --- a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java +++ b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java @@ -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()); } diff --git a/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java b/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java index 7caba41f0..2ac51ab46 100644 --- a/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java +++ b/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java @@ -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; + } + } diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index 521f3ce27..243881f67 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -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"); diff --git a/src/main/resources/META-INF/resources/designer/menu_simplified.html b/src/main/resources/META-INF/resources/designer/menu_simplified.html index 0131015f1..530ad61df 100644 --- a/src/main/resources/META-INF/resources/designer/menu_simplified.html +++ b/src/main/resources/META-INF/resources/designer/menu_simplified.html @@ -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"> - <b>Closed Loop Definition</b> + <b>CLAMP</b> </div> </div> diff --git a/src/main/resources/META-INF/resources/designer/partials/menu.html b/src/main/resources/META-INF/resources/designer/partials/menu.html index 48544dfe8..d3ffe3861 100644 --- a/src/main/resources/META-INF/resources/designer/partials/menu.html +++ b/src/main/resources/META-INF/resources/designer/partials/menu.html @@ -60,35 +60,6 @@ .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" diff --git a/src/main/resources/META-INF/resources/designer/partials/portfolios/PolicyWindow_properties.html b/src/main/resources/META-INF/resources/designer/partials/portfolios/PolicyWindow_properties.html index 5109c1bfe..25cc9a028 100644 --- a/src/main/resources/META-INF/resources/designer/partials/portfolios/PolicyWindow_properties.html +++ b/src/main/resources/META-INF/resources/designer/partials/portfolios/PolicyWindow_properties.html @@ -32,35 +32,6 @@ 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"); diff --git a/src/main/resources/META-INF/resources/designer/partials/portfolios/Template_model.html b/src/main/resources/META-INF/resources/designer/partials/portfolios/Template_model.html index 53204f41e..0ca4e7ca8 100644 --- a/src/main/resources/META-INF/resources/designer/partials/portfolios/Template_model.html +++ b/src/main/resources/META-INF/resources/designer/partials/portfolios/Template_model.html @@ -21,39 +21,6 @@ --> -<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">×</button> diff --git a/src/main/resources/META-INF/resources/designer/partials/portfolios/refresh_asdc.html b/src/main/resources/META-INF/resources/designer/partials/portfolios/refresh_asdc.html index 7f6e9e195..441766d42 100644 --- a/src/main/resources/META-INF/resources/designer/partials/portfolios/refresh_asdc.html +++ b/src/main/resources/META-INF/resources/designer/partials/portfolios/refresh_asdc.html @@ -22,56 +22,12 @@ --> <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)" diff --git a/src/main/resources/META-INF/resources/designer/partials/portfolios/tca_properties.html b/src/main/resources/META-INF/resources/designer/partials/portfolios/tca_properties.html index 8332e6962..89b13fa11 100644 --- a/src/main/resources/META-INF/resources/designer/partials/portfolios/tca_properties.html +++ b/src/main/resources/META-INF/resources/designer/partials/portfolios/tca_properties.html @@ -33,35 +33,6 @@ 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; @@ -127,29 +98,6 @@ </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)" diff --git a/src/main/resources/application-noaaf.properties b/src/main/resources/application-noaaf.properties index fe7eabc5e..0ce8a7b65 100644 --- a/src/main/resources/application-noaaf.properties +++ b/src/main/resources/application-noaaf.properties @@ -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 ! diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9e2e3c979..cdbe61337 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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 ! diff --git a/src/main/resources/boot-message.txt b/src/main/resources/boot-message.txt index d8763e269..eea540beb 100644 --- a/src/main/resources/boot-message.txt +++ b/src/main/resources/boot-message.txt @@ -1,10 +1,10 @@ + + +╔═╗╔╗╔╔═╗╔═╗ ╔═╗┌─┐┌─┐┌─┐┌┐ ┬ ┌─┐┌┐┌┌─┐┌─┐ +║ ║║║║╠═╣╠═╝ ║ ├─┤└─┐├─┤├┴┐│ ├─┤││││ ├─┤ +╚═╝╝╚╝╩ ╩╩ ╚═╝┴ ┴└─┘┴ ┴└─┘┴─┘┴ ┴┘└┘└─┘┴ ┴ + ╔═╗╦ ╔═╗╔╦╗╔═╗ + ║ ║ ╠═╣║║║╠═╝ + ╚═╝╩═╝╩ ╩╩ ╩╩ - __ __ __ __ __ __ -/ \|\ | /\ |__) __ / ` /\ /__` /\ |__)| /\ |\ |/ ` /\ -\__/| \|/~~\| \__,/~~\.__//~~\|__)|___/~~\| \|\__,/~~\ - -\ __ / __ __ \ __ / - \ / \ / / `| /\ |\/||__) ||| \ / \ / - \\__// \__,|___/~~\| || ||| \\__// - - Starting ::
\ No newline at end of file + :: Starting ::
\ No newline at end of file diff --git a/src/main/resources/clds/camel/routes/flexible-flow.xml b/src/main/resources/clds/camel/routes/flexible-flow.xml index 8305c2e49..c7f7ec3b7 100644 --- a/src/main/resources/clds/camel/routes/flexible-flow.xml +++ b/src/main/resources/clds/camel/routes/flexible-flow.xml @@ -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> @@ -31,16 +33,19 @@ <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> diff --git a/src/main/resources/clds/templates/globalProperties.json b/src/main/resources/clds/templates/globalProperties.json index 880b9927e..b6f68f64c 100644 --- a/src/main/resources/clds/templates/globalProperties.json +++ b/src/main/resources/clds/templates/globalProperties.json @@ -78,7 +78,22 @@ "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": { diff --git a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java index 8e7e70d89..3c508bd31 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java @@ -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 |