From 1480d327ff8559c1d912108f7d3353fed03fcd2c Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 24 Oct 2017 06:33:31 -0500 Subject: Change vnf-id to vnf-name These changes now allow a lookup of the source vnf-id based on the onset's vnf-name. Issue-Id: POLICY-366 Change-Id: I6f6bd500b892dddbbb9e12156b4486208309e21d Signed-off-by: Daniel Cruz --- .../actor/appc/APPCActorServiceProvider.java | 30 ++++++++++++---------- .../actor/appc/AppcServiceProviderTest.java | 12 ++++++--- 2 files changed, 25 insertions(+), 17 deletions(-) (limited to 'controlloop/common/actors/actor.appc') diff --git a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java index 6ae62bbcd..44411ca72 100644 --- a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java +++ b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java @@ -25,6 +25,7 @@ import java.util.List; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider; +import org.onap.policy.aai.AAIGETVnfResponse; import org.onap.policy.aai.util.AAIException; import org.onap.policy.appc.CommonHeader; import org.onap.policy.appc.Request; @@ -89,7 +90,8 @@ public class APPCActorServiceProvider implements Actor { * @return an APPC request conforming to the legacy API * @throws AAIException */ - public static Request constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) throws AAIException { + public static Request constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, + Policy policy, AAIGETVnfResponse vnfResponse) throws AAIException { /* * Construct an APPC request */ @@ -105,24 +107,24 @@ public class APPCActorServiceProvider implements Actor { * specified in the yaml, the target vnf-id is retrieved by * a named query to A&AI. */ - String vnfId; - if (onset.AAI.get("generic-vnf.vnf-id").equalsIgnoreCase(policy.getTarget().getResourceID())) { - vnfId = onset.AAI.get("generic-vnf.vnf-id"); + String sourceVnf = onset.AAI.get("generic-vnf.vnf-id"); + if (sourceVnf == null) { + /* + * Lets see if the vnf-name is provided + */ + sourceVnf = vnfResponse.vnfID; + if (sourceVnf == null) { + throw new AAIException("No vnf-id found"); + } } - else { - vnfId = AppcLcmActorServiceProvider.vnfNamedQuery( - policy.getTarget().getResourceID(), onset.AAI.get("generic-vnf.vnf-id")); - } - - if (vnfId == null) { - throw new AAIException("No vnf id found"); - } - + String targetVnf = AppcLcmActorServiceProvider.vnfNamedQuery( + policy.getTarget().getResourceID(), sourceVnf); + /* * For now Policy generates the PG Streams as a demo, in the * future the payload can be provided by CLAMP */ - request.Payload.put("generic-vnf.vnf-id", vnfId); + request.Payload.put("generic-vnf.vnf-id", targetVnf); PGRequest pgRequest = new PGRequest(); pgRequest.pgStreams = new PGStreams(); diff --git a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java index 7ab368f6f..5a107f814 100644 --- a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java +++ b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java @@ -29,6 +29,7 @@ import java.util.UUID; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.aai.AAIGETVnfResponse; import org.onap.policy.aai.util.AAIException; import org.onap.policy.appc.Request; import org.onap.policy.appc.Response; @@ -54,6 +55,7 @@ public class AppcServiceProviderTest { private static VirtualControlLoopEvent onsetEvent; private static ControlLoopOperation operation; private static Policy policy; + private static AAIGETVnfResponse aaiResponse; static { /* @@ -65,11 +67,11 @@ public class AppcServiceProviderTest { onsetEvent.requestID = UUID.randomUUID(); onsetEvent.closedLoopEventClient = "tca.instance00001"; onsetEvent.target_type = ControlLoopTargetType.VNF; - onsetEvent.target = "generic-vnf.vnf-id"; + onsetEvent.target = "generic-vnf.vnf-name"; onsetEvent.from = "DCAE"; onsetEvent.closedLoopAlarmStart = Instant.now(); onsetEvent.AAI = new HashMap<>(); - onsetEvent.AAI.put("generic-vnf.vnf-id", "fw0001vm001fw001"); + onsetEvent.AAI.put("generic-vnf.vnf-name", "fw0001vm001fw001"); onsetEvent.closedLoopEventStatus = ControlLoopEventStatus.ONSET; /* Construct an operation with an APPC actor and ModifyConfig operation. */ @@ -92,6 +94,10 @@ public class AppcServiceProviderTest { policy.setRetry(2); policy.setTimeout(300); + /* Construct a mock A&AI response */ + aaiResponse = new AAIGETVnfResponse(); + aaiResponse.vnfID = "vnf01"; + /* Set environment properties */ PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666"); PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI"); @@ -118,7 +124,7 @@ public class AppcServiceProviderTest { Request appcRequest = null; try { - appcRequest = APPCActorServiceProvider.constructRequest(onsetEvent, operation, policy); + appcRequest = APPCActorServiceProvider.constructRequest(onsetEvent, operation, policy, aaiResponse); } catch (AAIException e) { logger.warn(e.toString()); fail("no vnfid found"); -- cgit 1.2.3-korg