summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsebdet <sd378r@intl.att.com>2018-09-12 18:52:39 +0200
committersebdet <sd378r@intl.att.com>2018-09-17 16:41:27 +0200
commit19ab2338a2af9daf35835cebf85a7415867d19bb (patch)
treed60bb6f5659f5672ed76daf56cbf0623d4ffa684
parentc95cc5530f73b67537cedec962803b8c3522b3de (diff)
Guard policy Backend
Introduce Guard policy backend code Issue-ID: CLAMP-190 Change-Id: I7d60c6dd700c84607329f5449287465379b94807 Signed-off-by: sebdet <sd378r@intl.att.com>
-rw-r--r--src/main/java/org/onap/clamp/clds/client/GuardPolicyDelegate.java98
-rw-r--r--src/main/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegate.java74
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java78
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java59
-rw-r--r--src/main/java/org/onap/clamp/clds/dao/CldsDao.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java63
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsService.java2
-rw-r--r--src/main/resources/application-noaaf.properties6
-rw-r--r--src/main/resources/application.properties8
-rw-r--r--src/main/resources/clds/camel/routes/flexible-flow.xml5
-rw-r--r--src/main/resources/clds/templates/globalProperties.json17
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java54
12 files changed, 432 insertions, 34 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/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/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