aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-03-08 12:58:29 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-08 12:58:29 +0000
commit9be9d1e3486d03c13b438dc814376e6832410f8e (patch)
tree64e0515439e07fc771b65dd46c6ba74194648108 /controlloop/common
parent6eef0271414f077f03f836bbbded3b0fcb60f60c (diff)
parent045b2715a73df3c9888f31eac43e93d5a576be4a (diff)
Merge "Fix policy doesn't send payload to APPC"
Diffstat (limited to 'controlloop/common')
-rw-r--r--controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java21
-rw-r--r--controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProviderTest.java (renamed from controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java)110
2 files changed, 127 insertions, 4 deletions
diff --git a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java
index 049a77a3a..5c82a9500 100644
--- a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java
+++ b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java
@@ -236,8 +236,9 @@ public class AppcLcmActorServiceProvider implements Actor {
* APPC will populate the payload based on A&AI look up of the vnd-id provided in the action
* identifiers.
*/
- if (RECIPE_RESTART.equalsIgnoreCase(policy.getRecipe()) || RECIPE_REBUILD.equalsIgnoreCase(policy.getRecipe())
- || RECIPE_MIGRATE.equalsIgnoreCase(policy.getRecipe())) {
+ if (recipeSupportsPayload(policy.getRecipe()) && payloadSupplied(policy.getPayload())) {
+ appcRequest.setPayload(parsePayload(policy.getPayload()));
+ } else {
appcRequest.setPayload(null);
}
@@ -250,6 +251,22 @@ public class AppcLcmActorServiceProvider implements Actor {
return dmaapRequest;
}
+ private static boolean payloadSupplied(Map<String, String> payload) {
+ return payload != null && !payload.isEmpty();
+ }
+
+ private static boolean recipeSupportsPayload(String recipe) {
+ return !RECIPE_RESTART.equalsIgnoreCase(recipe) && !RECIPE_REBUILD.equalsIgnoreCase(recipe)
+ && !RECIPE_MIGRATE.equalsIgnoreCase(recipe);
+ }
+
+ private static String parsePayload(Map<String, String> payload) {
+ StringBuilder payloadString = new StringBuilder("{");
+ payload
+ .forEach((key, value) -> payloadString.append("\"").append(key).append("\": ").append(value).append(","));
+ return payloadString.substring(0, payloadString.length() - 1) + "}";
+ }
+
/**
* Parses the operation attempt using the subRequestId of APPC response.
*
diff --git a/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java b/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProviderTest.java
index f6131b135..79bcf153f 100644
--- a/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java
+++ b/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProviderTest.java
@@ -54,15 +54,19 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class AppcLcmServiceProviderTest {
+public class AppcLcmActorServiceProviderTest {
- private static final Logger logger = LoggerFactory.getLogger(AppcLcmServiceProviderTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(AppcLcmActorServiceProviderTest.class);
private static final VirtualControlLoopEvent onsetEvent;
private static final ControlLoopOperation operation;
private static final Policy policy;
private static final LcmResponseWrapper dmaapResponse;
+ private static final String RECIPE_RESTART = "Restart";
+ private static final String RECIPE_REBUILD = "Rebuild";
+ private static final String RECIPE_MIGRATE = "Migrate";
+
static {
/*
* Construct an onset with an AAI subtag containing generic-vnf.vnf-id and a target type of
@@ -333,4 +337,106 @@ public class AppcLcmServiceProviderTest {
assertEquals("VM", sp.recipeTargets("Restart").get(0));
assertEquals("vm-id", sp.recipePayloads("Restart").get(0));
}
+
+ @Test
+ public void payloadNotPassedWhenNotSupportedByRecipe() {
+ //given
+ Policy migratePolicy = constructPolicyWithRecipe(RECIPE_MIGRATE);
+ Policy rebuildPolicy = constructPolicyWithRecipe(RECIPE_REBUILD);
+ Policy restartPolicy = constructPolicyWithRecipe(RECIPE_RESTART);
+
+ // when
+ LcmRequestWrapper migrateRequest =
+ AppcLcmActorServiceProvider.constructRequest(onsetEvent, operation, migratePolicy, "vnf01");
+ LcmRequestWrapper rebuildRequest =
+ AppcLcmActorServiceProvider.constructRequest(onsetEvent, operation, rebuildPolicy, "vnf01");
+ LcmRequestWrapper restartRequest =
+ AppcLcmActorServiceProvider.constructRequest(onsetEvent, operation, restartPolicy, "vnf01");
+
+ // then
+ assertNull(migrateRequest.getBody().getPayload());
+ assertNull(rebuildRequest.getBody().getPayload());
+ assertNull(restartRequest.getBody().getPayload());
+ }
+
+ @Test
+ public void payloadNotPassedWhenNotSuppliedOrEmpty() {
+ //given
+ Policy noPayloadPolicy = constructHealthCheckPolicyWithPayload(null);
+ Policy emptyPayloadPolicy = constructHealthCheckPolicyWithPayload(new HashMap<>());
+
+ // when
+ LcmRequestWrapper noPayloadRequest =
+ AppcLcmActorServiceProvider.constructRequest(onsetEvent, operation, noPayloadPolicy, "vnf01");
+ LcmRequestWrapper emptyPayloadRequest =
+ AppcLcmActorServiceProvider.constructRequest(onsetEvent, operation, emptyPayloadPolicy, "vnf01");
+
+
+ // then
+ assertNull(noPayloadRequest.getBody().getPayload());
+ assertNull(emptyPayloadRequest.getBody().getPayload());
+ }
+
+ @Test
+ public void payloadParsedProperlyForSinglePayloadParameter() {
+ // given
+ HashMap<String, String> payload = new HashMap<>();
+ payload.put("requestParameters", "{\"host-ip-address\":\"10.183.37.25\"}");
+ Policy otherPolicy = constructHealthCheckPolicyWithPayload(payload);
+
+ // when
+ LcmRequestWrapper dmaapRequest =
+ AppcLcmActorServiceProvider.constructRequest(onsetEvent, operation, otherPolicy, "vnf01");
+
+ // then
+ assertEquals(dmaapRequest.getBody().getPayload(),
+ "{\"requestParameters\": {\"host-ip-address\":\"10.183.37.25\"}}");
+ }
+
+
+ @Test
+ public void payloadParsedProperlyForMultiplePayloadParameters() {
+ // given
+ HashMap<String, String> payload = new HashMap<>();
+ payload.put("requestParameters", "{\"host-ip-address\":\"10.183.37.25\"}");
+ payload.put("configurationParameters", "[{\"ip-addr\":\"$.vf-module-topology.vf-module-parameters.param[9]\","
+ + "\"oam-ip-addr\":\"$.vf-module-topology.vf-module-parameters.param[16]\","
+ + "\"enabled\":\"$.vf-module-topology.vf-module-parameters.param[23]\"}]");
+ Policy otherPolicy = constructHealthCheckPolicyWithPayload(payload);
+
+ // when
+ LcmRequestWrapper dmaapRequest =
+ AppcLcmActorServiceProvider.constructRequest(onsetEvent, operation, otherPolicy, "vnf01");
+
+ // then
+ assertEquals(dmaapRequest.getBody().getPayload(),
+ "{\"requestParameters\": "
+ + "{\"host-ip-address\":\"10.183.37.25\"},"
+ + "\"configurationParameters\": "
+ + "[{\"ip-addr\":\"$.vf-module-topology.vf-module-parameters.param[9]\","
+ + "\"oam-ip-addr\":\"$.vf-module-topology.vf-module-parameters.param[16]\","
+ + "\"enabled\":\"$.vf-module-topology.vf-module-parameters.param[23]\"}]"
+ + "}");
+ }
+
+ private Policy constructHealthCheckPolicyWithPayload(HashMap<String, String> payload) {
+ return constructHealthCheckPolicyWithPayloadAndRecipe(payload, "Health-Check");
+ }
+
+ private Policy constructPolicyWithRecipe(String recipe) {
+ return constructHealthCheckPolicyWithPayloadAndRecipe(null, recipe);
+ }
+
+ private Policy constructHealthCheckPolicyWithPayloadAndRecipe(HashMap<String, String> payload, String recipe) {
+ Policy otherPolicy = new Policy();
+ otherPolicy.setName("Perform health check");
+ otherPolicy.setDescription("Upon getting the trigger event, perform health check");
+ otherPolicy.setActor("APPC");
+ otherPolicy.setTarget(new Target(TargetType.VNF));
+ otherPolicy.setRecipe(recipe);
+ otherPolicy.setPayload(payload);
+ otherPolicy.setRetry(2);
+ otherPolicy.setTimeout(300);
+ return otherPolicy;
+ }
}