aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2019-04-05 15:15:31 +0200
committersebdet <sebastien.determe@intl.att.com>2019-04-05 15:15:31 +0200
commitdfa86ca8a3d8380487261da22cbf582b547e3276 (patch)
treecff6e438b2d363d25935a3ed743bac97e0314fdd /src
parent0cb57989949080d6cc3853c432a233605c321388 (diff)
Introduce Camel route
Camel route for Submit operation using http4 component Issue-ID: CLAMP-303 Change-Id: I29804a7db6286dfa84f7eed63813f25299a385e6 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopOperation.java126
-rw-r--r--src/main/java/org/onap/clamp/policy/PolicyOperation.java131
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java38
-rw-r--r--src/main/resources/application-noaaf.properties2
-rw-r--r--src/main/resources/application.properties2
-rw-r--r--src/main/resources/clds/camel/rest/clamp-api-v2.xml235
-rw-r--r--src/main/resources/clds/camel/routes/flexible-flow.xml172
-rw-r--r--src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java64
-rw-r--r--src/test/resources/tosca/guard1-policy-payload.json16
-rw-r--r--src/test/resources/tosca/guard2-policy-payload.json16
-rw-r--r--src/test/resources/tosca/operational-policy-payload.yaml31
-rw-r--r--src/test/resources/tosca/operational-policy-properties.json71
12 files changed, 558 insertions, 346 deletions
diff --git a/src/main/java/org/onap/clamp/loop/LoopOperation.java b/src/main/java/org/onap/clamp/loop/LoopOperation.java
index 7def783b..5b55ab0d 100644
--- a/src/main/java/org/onap/clamp/loop/LoopOperation.java
+++ b/src/main/java/org/onap/clamp/loop/LoopOperation.java
@@ -45,7 +45,6 @@ import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.util.LoggingUtils;
import org.onap.clamp.clds.util.ONAPLogConstants;
import org.onap.clamp.exception.OperationException;
-import org.onap.clamp.policy.PolicyOperation;
import org.onap.clamp.util.HttpConnectionManager;
import org.slf4j.event.Level;
import org.springframework.beans.factory.annotation.Autowired;
@@ -59,30 +58,30 @@ import org.yaml.snakeyaml.Yaml;
@Component
public class LoopOperation {
- protected static final EELFLogger logger = EELFManager.getInstance().getLogger(LoopOperation.class);
- protected static final EELFLogger auditLogger = EELFManager.getInstance().getMetricsLogger();
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(LoopOperation.class);
+ protected static final EELFLogger auditLogger = EELFManager.getInstance().getMetricsLogger();
private final DcaeDispatcherServices dcaeDispatcherServices;
private final LoopService loopService;
private LoggingUtils util = new LoggingUtils(logger);
- private PolicyOperation policyOp;
@Autowired
private HttpServletRequest request;
@Autowired
- public LoopOperation(LoopService loopService, DcaeDispatcherServices dcaeDispatcherServices,
- ClampProperties refProp, HttpConnectionManager httpConnectionManager, PolicyOperation policyOp) {
+ public LoopOperation(LoopService loopService, DcaeDispatcherServices dcaeDispatcherServices,
+ ClampProperties refProp, HttpConnectionManager httpConnectionManager) {
this.loopService = loopService;
this.dcaeDispatcherServices = dcaeDispatcherServices;
- this.policyOp = policyOp;
}
/**
* Deploy the closed loop.
*
- * @param loopName the loop name
+ * @param loopName
+ * the loop name
* @return the updated loop
- * @throws Exceptions during the operation
+ * @throws Exceptions
+ * during the operation
*/
public Loop deployLoop(Exchange camelExchange, String loopName) throws OperationException {
util.entering(request, "CldsService: Deploy model");
@@ -98,10 +97,9 @@ public class LoopOperation {
// verify the current closed loop state
if (loop.getLastComputedState() != LoopState.SUBMITTED) {
- String msg = "Deploy loop exception: This closed loop is in state:" + loop.getLastComputedState()
+ String msg = "Deploy loop exception: This closed loop is in state:" + loop.getLastComputedState()
+ ". It could be deployed only when it is in SUBMITTED state.";
- util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO,
- ONAPLogConstants.ResponseStatus.ERROR);
+ util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
throw new OperationException(msg);
}
@@ -118,25 +116,27 @@ public class LoopOperation {
Map<String, Object> yamlMap = yaml.load(loop.getBlueprint());
JsonObject bluePrint = wrapSnakeObject(yamlMap).getAsJsonObject();
- loop.setDcaeDeploymentStatusUrl(dcaeDispatcherServices.createNewDeployment(deploymentId, loop.getDcaeBlueprintId(), bluePrint));
+ loop.setDcaeDeploymentStatusUrl(
+ dcaeDispatcherServices.createNewDeployment(deploymentId, loop.getDcaeBlueprintId(), bluePrint));
loop.setLastComputedState(LoopState.DEPLOYED);
// save the updated loop
- loopService.saveOrUpdateLoop (loop);
+ loopService.saveOrUpdateLoop(loop);
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
auditLogger.info("Deploy model completed");
util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
- return loop;
+ return loop;
}
/**
* Un deploy closed loop.
*
- * @param loopName the loop name
+ * @param loopName
+ * the loop name
* @return the updated loop
*/
- public Loop unDeployLoop(String loopName) throws OperationException {
+ public Loop unDeployLoop(String loopName) throws OperationException {
util.entering(request, "LoopOperation: Undeploy the closed loop");
Date startTime = new Date();
Loop loop = loopService.getLoop(loopName);
@@ -146,14 +146,13 @@ public class LoopOperation {
util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO,
ONAPLogConstants.ResponseStatus.ERROR);
throw new OperationException(msg);
- }
+ }
// verify the current closed loop state
if (loop.getLastComputedState() != LoopState.DEPLOYED) {
- String msg = "Unploy loop exception: This closed loop is in state:" + loop.getLastComputedState()
+ String msg = "Unploy loop exception: This closed loop is in state:" + loop.getLastComputedState()
+ ". It could be undeployed only when it is in DEPLOYED state.";
- util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO,
- ONAPLogConstants.ResponseStatus.ERROR);
+ util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
throw new OperationException(msg);
}
@@ -165,7 +164,7 @@ public class LoopOperation {
loop.setLastComputedState(LoopState.SUBMITTED);
// save the updated loop
- loopService.saveOrUpdateLoop (loop);
+ loopService.saveOrUpdateLoop(loop);
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
@@ -175,14 +174,14 @@ public class LoopOperation {
}
private JsonElement wrapSnakeObject(Object o) {
- //NULL => JsonNull
+ // NULL => JsonNull
if (o == null)
return JsonNull.INSTANCE;
// Collection => JsonArray
if (o instanceof Collection) {
JsonArray array = new JsonArray();
- for (Object childObj : (Collection<?>)o)
+ for (Object childObj : (Collection<?>) o)
array.add(wrapSnakeObject(childObj));
return array;
}
@@ -192,14 +191,14 @@ public class LoopOperation {
JsonArray array = new JsonArray();
int length = Array.getLength(array);
- for (int i=0; i<length; i++)
+ for (int i = 0; i < length; i++)
array.add(wrapSnakeObject(Array.get(array, i)));
return array;
}
// Map => JsonObject
if (o instanceof Map) {
- Map<?, ?> map = (Map<?, ?>)o;
+ Map<?, ?> map = (Map<?, ?>) o;
JsonObject jsonObject = new JsonObject();
for (final Map.Entry<?, ?> entry : map.entrySet()) {
@@ -217,12 +216,15 @@ public class LoopOperation {
/**
* Submit the Ms policies.
*
- * @param loopName the loop name
+ * @param loopName
+ * the loop name
* @return the updated loop
- * @throws IOException IO exception
- * @throws Exceptions during the operation
+ * @throws IOException
+ * IO exception
+ * @throws Exceptions
+ * during the operation
*/
- public Loop submitMsPolicies (String loopName) throws OperationException, IOException {
+ public Loop submitMsPolicies(String loopName) throws OperationException, IOException {
util.entering(request, "LoopOperation: delete microservice policies");
Date startTime = new Date();
Loop loop = loopService.getLoop(loopName);
@@ -236,33 +238,34 @@ public class LoopOperation {
// verify the current closed loop state
if (loop.getLastComputedState() != LoopState.SUBMITTED && loop.getLastComputedState() != LoopState.DESIGN) {
- String msg = "Submit MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ String msg = "Submit MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ ". It could be deleted only when it is in SUBMITTED state.";
- util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO,
- ONAPLogConstants.ResponseStatus.ERROR);
+ util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
throw new OperationException(msg);
}
// Establish the api call to Policy to create the ms services
- policyOp.createMsPolicy(loop.getMicroServicePolicies());
+ // policyOp.createMsPolicy(loop.getMicroServicePolicies());
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
auditLogger.info("Deletion of MS policies completed");
util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
- return loop;
+ return loop;
}
-
/**
* Delete the Ms policies.
*
- * @param loopName the loop name
+ * @param loopName
+ * the loop name
* @return the updated loop
- * @throws IOException IO exception
- * @throws Exceptions during the operation
+ * @throws IOException
+ * IO exception
+ * @throws Exceptions
+ * during the operation
*/
- public Loop deleteMsPolicies (Exchange camelExchange, String loopName) throws OperationException, IOException {
+ public Loop deleteMsPolicies(Exchange camelExchange, String loopName) throws OperationException, IOException {
util.entering(request, "LoopOperation: delete microservice policies");
Date startTime = new Date();
Loop loop = loopService.getLoop(loopName);
@@ -276,31 +279,32 @@ public class LoopOperation {
// verify the current closed loop state
if (loop.getLastComputedState() != LoopState.SUBMITTED) {
- String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ ". It could be deleted only when it is in SUBMITTED state.";
- util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO,
- ONAPLogConstants.ResponseStatus.ERROR);
+ util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
throw new OperationException(msg);
}
// Establish the api call to Policy to create the ms services
- policyOp.deleteMsPolicy(loop.getMicroServicePolicies());
+ // policyOp.deleteMsPolicy(loop.getMicroServicePolicies());
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
auditLogger.info("Deletion of MS policies completed");
util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
- return loop;
+ return loop;
}
/**
* Delete the operational policy.
*
- * @param loopName the loop name
+ * @param loopName
+ * the loop name
* @return the updated loop
- * @throws Exceptions during the operation
+ * @throws Exceptions
+ * during the operation
*/
- public Loop deleteOpPolicy (Exchange camelExchange, String loopName) throws OperationException {
+ public Loop deleteOpPolicy(Exchange camelExchange, String loopName) throws OperationException {
util.entering(request, "LoopOperation: delete guard policy");
Date startTime = new Date();
Loop loop = loopService.getLoop(loopName);
@@ -314,31 +318,32 @@ public class LoopOperation {
// verify the current closed loop state
if (loop.getLastComputedState() != LoopState.SUBMITTED) {
- String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ ". It could be deleted only when it is in SUBMITTED state.";
- util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO,
- ONAPLogConstants.ResponseStatus.ERROR);
+ util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
throw new OperationException(msg);
}
// Establish the api call to Policy to delete operational policy
- //client.deleteOpPolicy();
+ // client.deleteOpPolicy();
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
auditLogger.info("Deletion of Guard policy completed");
util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
- return loop;
+ return loop;
}
/**
* Delete the Guard policy.
*
- * @param loopName the loop name
+ * @param loopName
+ * the loop name
* @return the updated loop
- * @throws Exceptions during the operation
+ * @throws Exceptions
+ * during the operation
*/
- public Loop deleteGuardPolicy (Exchange camelExchange, String loopName) throws OperationException {
+ public Loop deleteGuardPolicy(Exchange camelExchange, String loopName) throws OperationException {
util.entering(request, "LoopOperation: delete operational policy");
Date startTime = new Date();
Loop loop = loopService.getLoop(loopName);
@@ -352,20 +357,19 @@ public class LoopOperation {
// verify the current closed loop state
if (loop.getLastComputedState() != LoopState.SUBMITTED) {
- String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ ". It could be deleted only when it is in SUBMITTED state.";
- util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO,
- ONAPLogConstants.ResponseStatus.ERROR);
+ util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
throw new OperationException(msg);
}
// Establish the api call to Policy to delete Guard policy
- //client.deleteOpPolicy();
+ // client.deleteOpPolicy();
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
auditLogger.info("Deletion of operational policy completed");
util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
- return loop;
+ return loop;
}
}
diff --git a/src/main/java/org/onap/clamp/policy/PolicyOperation.java b/src/main/java/org/onap/clamp/policy/PolicyOperation.java
deleted file mode 100644
index edce8ff5..00000000
--- a/src/main/java/org/onap/clamp/policy/PolicyOperation.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP CLAMP
- * ================================================================================
- * Copyright (C) 2019 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.policy;
-
-import java.io.IOException;
-import java.util.Set;
-
-import org.onap.clamp.clds.config.ClampProperties;
-import org.onap.clamp.policy.microservice.MicroServicePolicy;
-import org.onap.clamp.util.HttpConnectionManager;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-
-@Component
-public class PolicyOperation {
- protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyOperation.class);
- protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
- public static final String POLICY_MSTYPE_PROPERTY_NAME = "policy.ms.type";
- public static final String POLICY_ONAPNAME_PROPERTY_NAME = "policy.onap.name";
- public static final String POLICY_BASENAME_PREFIX_PROPERTY_NAME = "policy.base.policyNamePrefix";
- public static final String POLICY_OP_NAME_PREFIX_PROPERTY_NAME = "policy.op.policyNamePrefix";
- public static final String POLICY_MS_NAME_PREFIX_PROPERTY_NAME = "policy.ms.policyNamePrefix";
- public static final String POLICY_OP_TYPE_PROPERTY_NAME = "policy.op.type";
- public static final String POLICY_GUARD_SUFFIX = "_Guard";
- public static final String POLICY_URL_PROPERTY_NAME = "clamp.config.policy.url";
- public static final String POLICY_URL_SUFFIX = "/versions/1.0.0/policies";
- public static final String POLICY_USER_NAME = "clamp.config.policy.userName";
- public static final String POLICY_PASSWORD = "clamp.config.policy.password";
-
- public static final String TOSCA_DEF_VERSION = "tosca_definitions_version";
- public static final String TOSCA_DEF_VERSION_VALUE = "tosca_simple_yaml_1_0_0";
- public static final String TEMPLATE = "topology_template";
- public static final String POLICIES = "policies";
- public static final String MS_TYPE = "type";
- public static final String MS_VERSION = "version";
- public static final String MS_VERSION_VALUE = "1.0.0";
- public static final String MS_METADATA = "metadata";
- public static final String MS_POLICY_ID = "policy_id";
- public static final String MS_PROPERTIES = "properties";
- public static final String MS_policy = "tca_policy";
-
- private final ClampProperties refProp;
- private final HttpConnectionManager httpConnectionManager;
-
- @Autowired
- public PolicyOperation(ClampProperties refProp, HttpConnectionManager httpConnectionManager) {
- this.refProp = refProp;
- this.httpConnectionManager = httpConnectionManager;
- }
-
- public void createMsPolicy(Set<MicroServicePolicy> policyList) throws IOException {
- // Get policy first? if exist delete???
- // push pdp group
- for (MicroServicePolicy msPolicy:policyList) {
- JsonObject payload = createMsPolicyPayload(msPolicy);
- String policyType = msPolicy.getModelType();
- String url = refProp.getStringValue(POLICY_URL_PROPERTY_NAME) + policyType + POLICY_URL_SUFFIX;
- String userName = refProp.getStringValue(POLICY_USER_NAME);
- String encodedPass = refProp.getStringValue(POLICY_PASSWORD);
- httpConnectionManager.doHttpRequest(url, "POST", payload.toString(), "application/json", "POLICY", userName, encodedPass);
- }
- }
-
- public void deleteMsPolicy(Set<MicroServicePolicy> policyList) throws IOException {
- for (MicroServicePolicy msPolicy:policyList) {
- String policyType = msPolicy.getModelType();
- String url = refProp.getStringValue(POLICY_URL_PROPERTY_NAME) + policyType + POLICY_URL_SUFFIX + "/" + msPolicy.getName();
- String userName = refProp.getStringValue(POLICY_USER_NAME);
- String encodedPass = refProp.getStringValue(POLICY_PASSWORD);
- httpConnectionManager.doHttpRequest(url, "POST", null, null, "POLICY", userName, encodedPass);
- }
- }
-
- private JsonObject createMsPolicyPayload(MicroServicePolicy microService) {
- JsonObject policyConfig = new JsonObject();
- policyConfig.add(MS_policy, microService.getProperties());
-
- JsonObject properties = new JsonObject();
- properties.add(MS_policy, policyConfig);
-
- JsonObject msPolicy = new JsonObject();
- msPolicy.addProperty(MS_TYPE, microService.getModelType());
- msPolicy.addProperty(MS_VERSION, MS_VERSION_VALUE);
- JsonObject metaData = new JsonObject();
- metaData.addProperty(MS_POLICY_ID, microService.getName());
- msPolicy.add(MS_METADATA, metaData);
- msPolicy.add(MS_PROPERTIES, properties);
-
- JsonObject msPolicyWithName = new JsonObject();
- msPolicyWithName.add(microService.getName(), msPolicy);
-
- JsonArray policyArray = new JsonArray();
- policyArray.add(msPolicyWithName);
-
- JsonObject template = new JsonObject();
- template.add(POLICIES, policyArray);
-
- JsonObject configPolicy = new JsonObject();
- configPolicy.addProperty(TOSCA_DEF_VERSION, TOSCA_DEF_VERSION_VALUE);
- configPolicy.add(TEMPLATE, template);
-
- return configPolicy;
- }
-
-}
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
index 674bd71d..b6b591db 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
@@ -23,12 +23,18 @@
package org.onap.clamp.policy.operational;
+import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -44,6 +50,7 @@ import org.hibernate.annotations.TypeDefs;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
import org.onap.clamp.loop.Loop;
import org.onap.clamp.policy.Policy;
+import org.yaml.snakeyaml.Yaml;
@Entity
@Table(name = "operational_policies")
@@ -156,11 +163,36 @@ public class OperationalPolicy implements Serializable, Policy {
JsonArray policiesArray = new JsonArray();
topologyTemplateNode.add("policies", policiesArray);
- return new GsonBuilder().setPrettyPrinting().create().toJson(policyPayloadResult);
+ JsonObject operationalPolicy = new JsonObject();
+ policiesArray.add(operationalPolicy);
+
+ JsonObject operationalPolicyDetails = new JsonObject();
+ operationalPolicy.add(this.name, operationalPolicyDetails);
+ operationalPolicyDetails.addProperty("type", "onap.policies.controlloop.Operational");
+ operationalPolicyDetails.addProperty("version", "1.0.0");
+
+ JsonObject metadata = new JsonObject();
+ operationalPolicyDetails.add("metadata", metadata);
+ metadata.addProperty("policy-id", this.name);
+
+ operationalPolicyDetails.add("properties", this.configurationsJson.get("operational_policy"));
+
+ Gson gson = new GsonBuilder().create();
+ Map<?, ?> jsonMap = gson.fromJson(gson.toJson(policyPayloadResult), Map.class);
+ return (new Yaml()).dump(jsonMap);
}
- public String createGuardPolicyPayload() {
- return null;
+ public List<String> createGuardPolicyPayloads() {
+ List<String> result = new ArrayList<>();
+
+ JsonObject guard = new JsonObject();
+ JsonElement guardsList = this.getConfigurationsJson().get("guard_policies");
+ for (Entry<String, JsonElement> guardElem : guardsList.getAsJsonObject().entrySet()) {
+ guard.addProperty("policy-id", guardElem.getKey());
+ guard.add("contents", guardElem.getValue());
+ result.add(new GsonBuilder().create().toJson(guard));
+ }
+ return result;
}
}
diff --git a/src/main/resources/application-noaaf.properties b/src/main/resources/application-noaaf.properties
index 82b2a283..84e97ea3 100644
--- a/src/main/resources/application-noaaf.properties
+++ b/src/main/resources/application-noaaf.properties
@@ -135,7 +135,7 @@ clamp.config.dcae.deployment.template=classpath:/clds/templates/dcae-deployment-
#
#
# Configuration Settings for Policy Engine Components
-clamp.config.policy.url=http://localhost:8085/
+clamp.config.policy.url=http://policy.api.simpledemo.onap.org:8081/policy/api/v1
clamp.config.policy.userName=test
clamp.config.policy.password=test
clamp.config.policy.pdpUrl1=http://policy.api.simpledemo.onap.org:8081/pdp/ , testpdp, alpha123
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index b8c63356..4792d057 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -150,7 +150,7 @@ clamp.config.dcae.deployment.template=classpath:/clds/templates/dcae-deployment-
#
#
# Configuration Settings for Policy Engine Components
-clamp.config.policy.url=http://policy.api.simpledemo.onap.org:8081/pdp/
+clamp.config.policy.url=http://policy.api.simpledemo.onap.org:8081/policy/api/v1
clamp.config.policy.userName=test
clamp.config.policy.password=test
clamp.config.policy.pdpUrl1=http://policy.api.simpledemo.onap.org:8081/pdp/ , testpdp, alpha123
diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
index f339d5d7..c17595e1 100644
--- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -1,94 +1,147 @@
-<rests xmlns="http://camel.apache.org/schema/spring" >
- <rest >
- <get uri="/v2/loop/getAllNames"
- outType="java.lang.String[]"
- produces="application/json">
- <route>
- <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')" />
- <to uri="bean:org.onap.clamp.loop.LoopController?method=getLoopNames()" />
- </route>
- </get>
- <get uri="/v2/loop/{loopName}"
- outType="org.onap.clamp.loop.Loop"
- produces="application/json">
- <route>
- <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')" />
- <to uri="bean:org.onap.clamp.loop.LoopController?method=getLoop(${header.loopName})" />
- </route>
- </get>
- <get uri="/v2/loop/svgRepresentation/{loopName}"
- outType="java.lang.String"
- produces="application/xml">
- <route>
- <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')" />
- <to uri="bean:org.onap.clamp.loop.LoopController?method=getSVGRepresentation(${header.loopName})" />
- </route>
- </get>
+<rests xmlns="http://camel.apache.org/schema/spring">
+ <rest>
+ <get
+ uri="/v2/loop/getAllNames"
+ outType="java.lang.String[]"
+ produces="application/json">
+ <route>
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')" />
+ <to
+ uri="bean:org.onap.clamp.loop.LoopController?method=getLoopNames()" />
+ </route>
+ </get>
+ <get
+ uri="/v2/loop/{loopName}"
+ outType="org.onap.clamp.loop.Loop"
+ produces="application/json">
+ <route>
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')" />
+ <to
+ uri="bean:org.onap.clamp.loop.LoopController?method=getLoop(${header.loopName})" />
+ </route>
+ </get>
+ <get
+ uri="/v2/loop/svgRepresentation/{loopName}"
+ outType="java.lang.String"
+ produces="application/xml">
+ <route>
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')" />
+ <to
+ uri="bean:org.onap.clamp.loop.LoopController?method=getSVGRepresentation(${header.loopName})" />
+ </route>
+ </get>
- <post uri="/v2/loop/updateGlobalProperties/{loopName}"
- type="com.google.gson.JsonObject"
- consumes="application/json"
- outType="org.onap.clamp.loop.Loop"
- produces="application/json">
- <route>
- <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
- <to uri="bean:org.onap.clamp.loop.LoopController?method=updateGlobalPropertiesJson(${header.loopName},${body})" />
- </route>
- </post>
- <post uri="/v2/loop/updateOperationalPolicies/{loopName}"
- type="com.google.gson.JsonArray"
- consumes="application/json"
- outType="org.onap.clamp.loop.Loop"
- produces="application/json">
- <route>
- <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
- <to uri="bean:org.onap.clamp.loop.LoopController?method=updateOperationalPolicies(${header.loopName},${body})" />
- </route>
- </post>
- <post uri="/v2/loop/updateMicroservicePolicy/{loopName}"
- type="org.onap.clamp.policy.microservice.MicroServicePolicy"
- consumes="application/json"
- outType="org.onap.clamp.policy.microservice.MicroServicePolicy"
- produces="application/json">
- <route>
- <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
- <to uri="bean:org.onap.clamp.loop.LoopController?method=updateMicroservicePolicy(${header.loopName},${body})" />
- </route>
- </post>
- <put uri="/v2/loop/deployLoop/{loopName}"
- outType="org.onap.clamp.loop.Loop"
- produces="application/json">
- <route>
- <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
- <to uri="bean:org.onap.clamp.operation.LoopOperation?method=deployLoop(*,${header.loopName})" />
- </route>
- </put>
- <put uri="/v2/loop/undeployLoop/{loopName}"
- outType="org.onap.clamp.loop.Loop"
- produces="application/json">
- <route>
- <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
- <to uri="bean:org.onap.clamp.operation.LoopOperation?method=unDeployLoop(${header.loopName})" />
- </route>
- </put>
- <put uri="/v2/loop/submit/{loopName}">
- <route>
- <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
- <to uri="bean:org.onap.clamp.operation.LoopOperation?method=submitMsPolicies(${header.loopName})" />
- <!-- <to uri="bean:org.onap.clamp.operation.LoopOperation?method=submitOpPolicy(${header.loopName})" />-->
- <!--<to uri="bean:org.onap.clamp.operation.LoopOperation?method=submitGuardPolicy(${header.loopName})" /> -->
- </route>
- </put>
- <put uri="/v2/loop/delete/{loopName}"
- outType="org.onap.clamp.loop.Loop"
- produces="application/json">
- <route>
- <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
- <to uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteMsPolicies(${header.loopName})" />
- <to uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteOpPolicy(${header.loopName})" />
- <to uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteGuardPolicy(${header.loopName})" />
- </route>
- </put>
- </rest>
+ <post
+ uri="/v2/loop/updateGlobalProperties/{loopName}"
+ type="com.google.gson.JsonObject"
+ consumes="application/json"
+ outType="org.onap.clamp.loop.Loop"
+ produces="application/json">
+ <route>
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+ <to
+ uri="bean:org.onap.clamp.loop.LoopController?method=updateGlobalPropertiesJson(${header.loopName},${body})" />
+ </route>
+ </post>
+ <post
+ uri="/v2/loop/updateOperationalPolicies/{loopName}"
+ type="com.google.gson.JsonArray"
+ consumes="application/json"
+ outType="org.onap.clamp.loop.Loop"
+ produces="application/json">
+ <route>
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+ <to
+ uri="bean:org.onap.clamp.loop.LoopController?method=updateOperationalPolicies(${header.loopName},${body})" />
+ </route>
+ </post>
+ <post
+ uri="/v2/loop/updateMicroservicePolicy/{loopName}"
+ type="org.onap.clamp.policy.microservice.MicroServicePolicy"
+ consumes="application/json"
+ outType="org.onap.clamp.policy.microservice.MicroServicePolicy"
+ produces="application/json">
+ <route>
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+ <to
+ uri="bean:org.onap.clamp.loop.LoopController?method=updateMicroservicePolicy(${header.loopName},${body})" />
+ </route>
+ </post>
+ <put
+ uri="/v2/loop/deployLoop/{loopName}"
+ outType="org.onap.clamp.loop.Loop"
+ produces="application/json">
+ <route>
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+ <to
+ uri="bean:org.onap.clamp.operation.LoopOperation?method=deployLoop(*,${header.loopName})" />
+ </route>
+ </put>
+ <put
+ uri="/v2/loop/undeployLoop/{loopName}"
+ outType="org.onap.clamp.loop.Loop"
+ produces="application/json">
+ <route>
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+ <to
+ uri="bean:org.onap.clamp.operation.LoopOperation?method=unDeployLoop(${header.loopName})" />
+ </route>
+ </put>
+ <put uri="/v2/loop/submit/{loopName}">
+ <route>
+ <setBody>
+ <simple>${header.loopName}</simple>
+ </setBody>
+ <log
+ loggingLevel="INFO"
+ message="Loop name received: ${body}"></log>
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+ <setHeader headerName="LoopObject">
+ <method
+ ref="org.onap.clamp.loop.LoopService"
+ method="getLoop" />
+ </setHeader>
+ <split streaming="true">
+ <simple>${header.LoopObject.getMicroServicePolicies()}
+ </simple>
+ <setHeader headerName="HttpQueryException">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setHeader>
+ <to uri="direct:delete-micro-service"/>
+
+ <setHeader headerName="HttpQueryException">
+ <simple resultType="java.lang.Boolean">true</simple>
+ </setHeader>
+ <setBody>
+ <simple>${body.createPolicyPayload()}</simple>
+ </setBody>
+ <to uri="direct:create-micro-service"/>
+
+ </split>
+ </route>
+ </put>
+ <put
+ uri="/v2/loop/delete/{loopName}">
+ <route>
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+ <to
+ uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteMsPolicies(${header.loopName})" />
+ <to
+ uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteOpPolicy(${header.loopName})" />
+ <to
+ uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteGuardPolicy(${header.loopName})" />
+ </route>
+ </put>
+ </rest>
</rests>
diff --git a/src/main/resources/clds/camel/routes/flexible-flow.xml b/src/main/resources/clds/camel/routes/flexible-flow.xml
index 2103b4ac..b8244990 100644
--- a/src/main/resources/clds/camel/routes/flexible-flow.xml
+++ b/src/main/resources/clds/camel/routes/flexible-flow.xml
@@ -1,61 +1,117 @@
<routes xmlns="http://camel.apache.org/schema/spring">
- <route id="submit">
- <from uri="direct:processSubmit" />
- <choice>
- <when>
- <simple> ${exchangeProperty.actionCd} == 'SUBMIT' || ${exchangeProperty.actionCd} == 'RESUBMIT'</simple>
- <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" />
- <to uri="bean:org.onap.clamp.clds.client.TcaPolicyDelegate" />
- <to uri="bean:org.onap.clamp.clds.client.HolmesPolicyDelegate" />
- <delay>
- <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?method=addEvent(*,'COMPLETED')" />
- </when>
- <when>
- <simple> ${exchangeProperty.actionCd} == 'DELETE'</simple>
- <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" />
- <to uri="bean:org.onap.clamp.clds.client.TcaPolicyDeleteDelegate" />
- <to uri="bean:org.onap.clamp.clds.client.HolmesPolicyDeleteDelegate" />
- <delay>
- <constant>30000</constant>
- </delay>
- <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.ModelDeleteDelegate" />
- <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'COMPLETED')" />
- </when>
- <when>
- <simple> ${exchangeProperty.actionCd} == 'UPDATE'</simple>
- <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" />
- <to uri="bean:org.onap.clamp.clds.client.TcaPolicyDelegate" />
- <to uri="bean:org.onap.clamp.clds.client.HolmesPolicyDelegate" />
- <delay>
- <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?method=addEvent(*,'COMPLETED')" />
- </when>
- <when>
- <simple> ${exchangeProperty.actionCd} == 'STOP'</simple>
- <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" />
- <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?method=addEvent(*,'COMPLETED')" />
- </when>
- <when>
- <simple> ${exchangeProperty.actionCd} == 'RESTART'</simple>
- <to uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" />
- <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?method=addEvent(*,'COMPLETED')" />
- </when>
- </choice>
- </route>
+ <route id="submit">
+ <from uri="direct:processSubmit" />
+ <choice>
+ <when>
+ <simple> ${exchangeProperty.actionCd} == 'SUBMIT' ||
+ ${exchangeProperty.actionCd} == 'RESUBMIT'
+ </simple>
+ <to
+ uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" />
+ <to uri="bean:org.onap.clamp.clds.client.TcaPolicyDelegate" />
+ <to uri="bean:org.onap.clamp.clds.client.HolmesPolicyDelegate" />
+ <delay>
+ <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?method=addEvent(*,'COMPLETED')" />
+ </when>
+ <when>
+ <simple> ${exchangeProperty.actionCd} == 'DELETE'</simple>
+ <to
+ uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" />
+ <to uri="bean:org.onap.clamp.clds.client.TcaPolicyDeleteDelegate" />
+ <to
+ uri="bean:org.onap.clamp.clds.client.HolmesPolicyDeleteDelegate" />
+ <delay>
+ <constant>30000</constant>
+ </delay>
+ <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.ModelDeleteDelegate" />
+ <to
+ uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'COMPLETED')" />
+ </when>
+ <when>
+ <simple> ${exchangeProperty.actionCd} == 'UPDATE'</simple>
+ <to
+ uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" />
+ <to uri="bean:org.onap.clamp.clds.client.TcaPolicyDelegate" />
+ <to uri="bean:org.onap.clamp.clds.client.HolmesPolicyDelegate" />
+ <delay>
+ <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?method=addEvent(*,'COMPLETED')" />
+ </when>
+ <when>
+ <simple> ${exchangeProperty.actionCd} == 'STOP'</simple>
+ <to
+ uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" />
+ <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?method=addEvent(*,'COMPLETED')" />
+ </when>
+ <when>
+ <simple> ${exchangeProperty.actionCd} == 'RESTART'</simple>
+ <to
+ uri="bean:org.onap.clamp.clds.client.CldsEventDelegate?method=addEvent(*,'INITIATED')" />
+ <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?method=addEvent(*,'COMPLETED')" />
+ </when>
+ </choice>
+ </route>
+ <route id="delete-micro-service">
+ <from uri="direct:delete-micro-service" />
+
+ <setHeader headerName="CamelHttpMethod">
+ <constant>DELETE</constant>
+ </setHeader>
+ <setHeader headerName="CamelHttpUri">
+ <simple>{{clamp.config.policy.url}}/policyTypes/${body.getModelType()}/versions/1.0.0/policies/${body.getName()}
+ </simple>
+ </setHeader>
+ <setBody>
+ <constant>null</constant>
+ </setBody>
+ <!--<convertBodyTo type="org.onap.clamp.policy.microservice.MicroServicePolicy"/> -->
+ <log
+ loggingLevel="INFO"
+ message="Policy Endpoint for microservice: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
+ <toD
+ uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryException}" />
+
+ </route>
+ <route id="create-micro-service">
+ <from uri="direct:create-micro-service" />
+
+ <setHeader headerName="CamelHttpMethod">
+ <constant>POST</constant>
+ </setHeader>
+ <setHeader headerName="CamelHttpUri">
+ <simple>{{clamp.config.policy.url}}/policyTypes/${body.getModelType()}/versions/1.0.0/policies
+ </simple>
+ </setHeader>
+ <!--<convertBodyTo type="org.onap.clamp.policy.microservice.MicroServicePolicy"/> -->
+ <log
+ loggingLevel="INFO"
+ message="Policy Endpoint for microservice: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
+ <toD
+ uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryException}" />
+ </route>
</routes> \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
new file mode 100644
index 00000000..1f57422c
--- /dev/null
+++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 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.policy.microservice;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.onap.clamp.policy.operational.OperationalPolicy;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+public class OperationalPolicyPayloadTest {
+
+ @Test
+ public void testOperationalPolicyPayloadConstruction() throws IOException {
+ JsonObject jsonConfig = new GsonBuilder().create().fromJson(
+ ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
+ OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig);
+ assertThat(policy.createPolicyPayload())
+ .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.yaml"));
+ }
+
+ @Test
+ public void testGuardPolicyPayloadConstruction() throws IOException {
+ JsonObject jsonConfig = new GsonBuilder().create().fromJson(
+ ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
+ OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig);
+
+ List<String> guardsList = policy.createGuardPolicyPayloads();
+
+ JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/guard1-policy-payload.json"),
+ guardsList.get(0), false);
+
+ JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/guard2-policy-payload.json"),
+ guardsList.get(1), false);
+ }
+}
diff --git a/src/test/resources/tosca/guard1-policy-payload.json b/src/test/resources/tosca/guard1-policy-payload.json
new file mode 100644
index 00000000..bacf174f
--- /dev/null
+++ b/src/test/resources/tosca/guard1-policy-payload.json
@@ -0,0 +1,16 @@
+{
+ "policy-id": "guard1",
+ "contents": {
+ "recipe": "Rebuild",
+ "actor": "SO",
+ "clname": "testloop",
+ "guardTargets": ".*",
+ "minGuard": "3",
+ "maxGuard": "7",
+ "limitGuard": "",
+ "timeUnitsGuard": "",
+ "timeWindowGuard": "",
+ "guardActiveStart": "00:00:01-05:00",
+ "guardActiveEnd": "23:59:01-05:00"
+ }
+} \ No newline at end of file
diff --git a/src/test/resources/tosca/guard2-policy-payload.json b/src/test/resources/tosca/guard2-policy-payload.json
new file mode 100644
index 00000000..89f7ec89
--- /dev/null
+++ b/src/test/resources/tosca/guard2-policy-payload.json
@@ -0,0 +1,16 @@
+{
+ "policy-id": "guard2",
+ "contents": {
+ "recipe": "Migrate",
+ "actor": "SO",
+ "clname": "testloop",
+ "guardTargets": ".*",
+ "minGuard": "1",
+ "maxGuard": "2",
+ "limitGuard": "",
+ "timeUnitsGuard": "",
+ "timeWindowGuard": "",
+ "guardActiveStart": "00:00:01-05:00",
+ "guardActiveEnd": "23:59:01-05:00"
+ }
+} \ No newline at end of file
diff --git a/src/test/resources/tosca/operational-policy-payload.yaml b/src/test/resources/tosca/operational-policy-payload.yaml
new file mode 100644
index 00000000..68116b00
--- /dev/null
+++ b/src/test/resources/tosca/operational-policy-payload.yaml
@@ -0,0 +1,31 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+topology_template:
+ policies:
+ - testPolicy:
+ type: onap.policies.controlloop.Operational
+ version: 1.0.0
+ metadata: {policy-id: testPolicy}
+ properties:
+ controlLoop: {controlLoopName: control loop, version: 2.0.0, trigger_policy: new1,
+ timeout: '30', abatement: 'true'}
+ policies:
+ - id: new1
+ recipe: Rebuild
+ retry: '10'
+ timeout: '20'
+ actor: SO
+ payload: test
+ success: new2
+ failure: new2
+ failure_timeout: new2
+ failure_retries: new2
+ failure_exception: new2
+ failure_guard: new2
+ target: {type: VFC, resourceTargetId: test}
+ - id: new2
+ recipe: Migrate
+ retry: '30'
+ timeout: '40'
+ actor: SDNC
+ payload: test
+ target: {type: VFC, resourceTargetId: test}
diff --git a/src/test/resources/tosca/operational-policy-properties.json b/src/test/resources/tosca/operational-policy-properties.json
new file mode 100644
index 00000000..50361659
--- /dev/null
+++ b/src/test/resources/tosca/operational-policy-properties.json
@@ -0,0 +1,71 @@
+{
+ "guard_policies": {
+ "guard1":{
+ "recipe": "Rebuild",
+ "actor": "SO",
+ "clname": "testloop",
+ "guardTargets": ".*",
+ "minGuard": "3",
+ "maxGuard": "7",
+ "limitGuard": "",
+ "timeUnitsGuard": "",
+ "timeWindowGuard": "",
+ "guardActiveStart": "00:00:01-05:00",
+ "guardActiveEnd": "23:59:01-05:00"
+ },
+ "guard2":{
+ "recipe": "Migrate",
+ "actor": "SO",
+ "clname": "testloop",
+ "guardTargets": ".*",
+ "minGuard": "1",
+ "maxGuard": "2",
+ "limitGuard": "",
+ "timeUnitsGuard": "",
+ "timeWindowGuard": "",
+ "guardActiveStart": "00:00:01-05:00",
+ "guardActiveEnd": "23:59:01-05:00"
+ }
+ },
+ "operational_policy": {
+ "controlLoop": {
+ "controlLoopName": "control loop",
+ "version": "2.0.0",
+ "trigger_policy": "new1",
+ "timeout": "30",
+ "abatement": "true"
+ },
+ "policies": [
+ {
+ "id": "new1",
+ "recipe": "Rebuild",
+ "retry": "10",
+ "timeout": "20",
+ "actor": "SO",
+ "payload": "test",
+ "success": "new2",
+ "failure": "new2",
+ "failure_timeout": "new2",
+ "failure_retries": "new2",
+ "failure_exception": "new2",
+ "failure_guard": "new2",
+ "target": {
+ "type": "VFC",
+ "resourceTargetId": "test"
+ }
+ },
+ {
+ "id": "new2",
+ "recipe": "Migrate",
+ "retry": "30",
+ "timeout": "40",
+ "actor": "SDNC",
+ "payload": "test",
+ "target": {
+ "type": "VFC",
+ "resourceTargetId": "test"
+ }
+ }
+ ]
+ }
+}