From: Sébastien Determe Date: Tue, 18 Sep 2018 08:27:51 +0000 (+0000) Subject: Merge "Add plugin in logstash image" X-Git-Tag: 3.0.0~11 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=31b7e68cce37f171af2859e884f35d5d00ecc811;hp=96f162e2e2dbe7c40d019337d29a46f2fd3e73d8;p=clamp.git Merge "Add plugin in logstash image" --- 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 00000000..9287abbc --- /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> 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 00000000..9e8e1b8c --- /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 00000000..f11b492c --- /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> formatAttributes(ClampProperties refProp, + ModelProperties modelProperties, String modelElementId, PolicyItem policyItem) { + Map matchingAttributes = prepareMatchingAttributes(refProp, policyItem, modelProperties); + return createAttributesMap(matchingAttributes); + } + + private static Map prepareMatchingAttributes(ClampProperties refProp, + PolicyItem policyItem, ModelProperties modelProp) { + logger.info("Preparing matching attributes for guard..."); + Map 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> createAttributesMap(Map matchingAttributes) { + Map> 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 cd387b3c..58366d95 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; @@ -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> 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 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. * 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 54a5196c..d3e89fb6 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 getBpmnNames() { + public List 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 7caba41f..2ac51ab4 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 521f3ce2..243881f6 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 names = cldsDao.getBpmnNames(); + List 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 0131015f..530ad61d 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"> 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 48544dfe..d3ffe386 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; -}