diff options
author | Adam Wudzinski <adam.wudzinski@nokia.com> | 2019-03-07 18:07:07 +0100 |
---|---|---|
committer | awudzins <adam.wudzinski@nokia.com> | 2019-03-07 18:07:07 +0100 |
commit | 3848f800174f2ef6a0587da553fe2d18f0993ac8 (patch) | |
tree | 9cce4bb3fffa069f01249a131a2c8b0a428ca011 | |
parent | 1a725044dcdf72a67b9c6be8ee88270058f044ce (diff) |
Fix policy doesn't send payload to APPC
Fix policy doesn't send payload to APPC using AppcLcm. Cassablanca Release.
Change-Id: I6e2186d3f83809e97811162b9cfdf6d20136fa6a
Issue-ID: POLICY-1522
Signed-off-by: awudzins <adam.wudzinski@nokia.com>
-rw-r--r-- | controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java | 21 | ||||
-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 b4151a9f9..2030e2349 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; + } } |