diff options
author | daniel <dc443y@att.com> | 2017-10-24 06:33:31 -0500 |
---|---|---|
committer | daniel <dc443y@att.com> | 2017-10-24 13:16:10 -0500 |
commit | 1480d327ff8559c1d912108f7d3353fed03fcd2c (patch) | |
tree | 8745bec65ea2ee8962f42048ed0362961d0dfc60 /controlloop/common/actors/actor.appclcm/src | |
parent | baea880ddf0564d81d61bf87ae7f124229bf08f0 (diff) |
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 <dc443y@att.com>
Diffstat (limited to 'controlloop/common/actors/actor.appclcm/src')
2 files changed, 84 insertions, 11 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 4ff1c1d2c..1c7ee9089 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 @@ -33,11 +33,13 @@ import java.util.UUID; import org.onap.policy.aai.AAINQInstanceFilters; import org.onap.policy.aai.AAINQInventoryResponseItem; +import org.onap.policy.aai.AAIGETVnfResponse; import org.onap.policy.aai.AAIManager; import org.onap.policy.aai.AAINQNamedQuery; import org.onap.policy.aai.AAINQQueryParameters; import org.onap.policy.aai.AAINQRequest; import org.onap.policy.aai.AAINQResponse; +import org.onap.policy.aai.util.AAIException; import org.onap.policy.appclcm.LCMCommonHeader; import org.onap.policy.appclcm.LCMRequest; import org.onap.policy.appclcm.LCMRequestWrapper; @@ -138,8 +140,9 @@ public class AppcLcmActorServiceProvider implements Actor { * the vnf id of the source entity reporting the alert * * @return the target entities vnf id to act upon + * @throws AAIException */ - public static String vnfNamedQuery(String resourceId, String sourceVnfId) { + public static String vnfNamedQuery(String resourceId, String sourceVnfId) throws AAIException { //TODO: This request id should not be hard coded in future releases UUID requestId = UUID.fromString("a93ac487-409c-4e8c-9e5f-334ae8f99087"); @@ -170,9 +173,15 @@ public class AppcLcmActorServiceProvider implements Actor { aaiUrl, aaiUsername, aaiPassword, aaiRequest, requestId); + + if (aaiResponse == null) { + throw new AAIException("The named query response was null"); + } - //TODO: What if the resourceId never matches? String targetVnfId = parseAAIResponse(aaiResponse.inventoryResponseItems, resourceId); + if (targetVnfId == null) { + throw new AAIException("Target vnf-id could not be found"); + } return targetVnfId; } @@ -192,9 +201,10 @@ public class AppcLcmActorServiceProvider implements Actor { * the policy the was specified from the yaml generated * by CLAMP or through the Policy GUI/API * @return an APPC request conforming to the lcm API using the DMAAP wrapper + * @throws AAIException */ - public static LCMRequestWrapper constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, - Policy policy) { + public static LCMRequestWrapper constructRequest(VirtualControlLoopEvent onset, + ControlLoopOperation operation, Policy policy, AAIGETVnfResponse vnfResponse) throws AAIException { /* Construct an APPC request using LCM Model */ @@ -225,7 +235,15 @@ public class AppcLcmActorServiceProvider implements Actor { * a vnf-id. */ HashMap<String, String> requestActionIdentifiers = new HashMap<>(); - requestActionIdentifiers.put("vnf-id", onset.AAI.get(DCAE_VNF_ID)); + String vnfId = onset.AAI.get(DCAE_VNF_ID); + if (vnfId == null) { + vnfId = vnfResponse.vnfID; + if (vnfId == null) { + throw new AAIException("No vnf-id found"); + } + } + requestActionIdentifiers.put("vnf-id", vnfId); + appcRequest.setActionIdentifiers(requestActionIdentifiers); /* 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/AppcLcmServiceProviderTest.java index 63ecd2ec9..7c0f1882a 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/AppcLcmServiceProviderTest.java @@ -27,7 +27,11 @@ import java.util.AbstractMap; import java.util.HashMap; 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.appclcm.LCMCommonHeader; import org.onap.policy.appclcm.LCMRequest; import org.onap.policy.appclcm.LCMRequestWrapper; @@ -41,6 +45,9 @@ import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.controlloop.policy.Target; import org.onap.policy.controlloop.policy.TargetType; +import org.onap.policy.drools.http.server.HttpServletServer; +import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.simulators.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,6 +58,7 @@ public class AppcLcmServiceProviderTest { private static VirtualControlLoopEvent onsetEvent; private static ControlLoopOperation operation; private static Policy policy; + private static AAIGETVnfResponse aaiResponse; private static LCMRequestWrapper dmaapRequest; private static LCMResponseWrapper dmaapResponse; @@ -64,11 +72,11 @@ public class AppcLcmServiceProviderTest { onsetEvent.requestID = UUID.randomUUID(); onsetEvent.closedLoopEventClient = "tca.instance00001"; onsetEvent.target_type = ControlLoopTargetType.VM; - 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 restart operation. */ @@ -84,11 +92,15 @@ public class AppcLcmServiceProviderTest { policy.setName("Restart the VM"); policy.setDescription("Upon getting the trigger event, restart the VM"); policy.setActor("APPC"); - policy.setTarget(new Target(TargetType.VM)); + policy.setTarget(new Target(TargetType.VNF)); policy.setRecipe("Restart"); policy.setPayload(null); policy.setRetry(2); policy.setTimeout(300); + + /* Construct a mock A&AI response */ + aaiResponse = new AAIGETVnfResponse(); + aaiResponse.vnfID = "vnf01"; /* A sample DMAAP request wrapper. */ dmaapRequest = new LCMRequestWrapper(); @@ -101,7 +113,12 @@ public class AppcLcmServiceProviderTest { dmaapResponse.setCorrelationId(onsetEvent.requestID.toString() + "-" + "1"); dmaapResponse.setRpcName(policy.getRecipe().toLowerCase()); dmaapResponse.setType("response"); - + + /* Set environment properties */ + PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666"); + PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI"); + PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); + /* A sample APPC LCM request. */ LCMRequest appcRequest = new LCMRequest(); @@ -132,13 +149,33 @@ public class AppcLcmServiceProviderTest { dmaapResponse.setBody(appcResponse); } + @BeforeClass + public static void setUpSimulator() { + try { + Util.buildAaiSim(); + } catch (Exception e) { + fail(e.getMessage()); + } + } + + @AfterClass + public static void tearDownSimulator() { + HttpServletServer.factory.destroy(); + } + /** * A test to construct an APPC LCM restart request. */ @Test public void constructRestartRequestTest() { - LCMRequestWrapper dmaapRequest = AppcLcmActorServiceProvider.constructRequest(onsetEvent, operation, policy); + LCMRequestWrapper dmaapRequest = null; + try { + dmaapRequest = AppcLcmActorServiceProvider.constructRequest(onsetEvent, operation, policy, aaiResponse); + } catch (AAIException e) { + logger.warn(e.toString()); + fail("no vnfid found"); + } /* The service provider must return a non null DMAAP request wrapper */ assertNotNull(dmaapRequest); @@ -162,6 +199,7 @@ public class AppcLcmServiceProviderTest { /* Action Identifiers are required and cannot be null */ assertNotNull(appcRequest.getActionIdentifiers()); assertNotNull(appcRequest.getActionIdentifiers().get("vnf-id")); + assertEquals(appcRequest.getActionIdentifiers().get("vnf-id"), "vnf01"); logger.debug("APPC Request: \n" + appcRequest.toString()); } @@ -267,5 +305,22 @@ public class AppcLcmServiceProviderTest { assertEquals(result.getKey(), PolicyResult.FAILURE_EXCEPTION); } - + /** + * This test ensures that that if the the source entity + * is also the target entity, the source will be used for + * the APPC request + */ + @Test + public void sourceIsTargetTest() { + String resourceId = "82194af1-3c2c-485a-8f44-420e22a9eaa4"; + String targetVnfId = null; + try { + targetVnfId = AppcLcmActorServiceProvider.vnfNamedQuery(resourceId, aaiResponse.vnfID); + } catch (AAIException e) { + logger.warn(e.toString()); + fail("no vnf-id found"); + } + assertNotNull(targetVnfId); + assertEquals(targetVnfId, aaiResponse.vnfID); + } } |