X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=controlloop%2Fcommon%2Feventmanager%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontrolloop%2Feventmanager%2FControlLoopOperationManagerTest.java;h=4cb365a76ac2a4646b975f3347ecaddd89546b95;hb=9398165f5c35e686e2570c68cd0eb4a2e9254a02;hp=9b1633521c8fb3a1f38dcce824040a57f1cb2deb;hpb=fdaae76549bafb2e482c02fb26de719c69431b48;p=policy%2Fdrools-applications.git diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java index 9b1633521..4cb365a76 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java @@ -3,6 +3,7 @@ * unit test * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,16 +44,17 @@ import org.apache.commons.io.IOUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; import org.onap.policy.aai.util.AaiException; import org.onap.policy.appc.CommonHeader; import org.onap.policy.appc.Response; import org.onap.policy.appc.ResponseCode; import org.onap.policy.appc.ResponseStatus; -import org.onap.policy.appclcm.LcmCommonHeader; -import org.onap.policy.appclcm.LcmRequest; -import org.onap.policy.appclcm.LcmRequestWrapper; -import org.onap.policy.appclcm.LcmResponse; -import org.onap.policy.appclcm.LcmResponseWrapper; +import org.onap.policy.appclcm.AppcLcmBody; +import org.onap.policy.appclcm.AppcLcmCommonHeader; +import org.onap.policy.appclcm.AppcLcmDmaapWrapper; +import org.onap.policy.appclcm.AppcLcmInput; +import org.onap.policy.appclcm.AppcLcmOutput; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.utils.io.Serializer; import org.onap.policy.controlloop.ControlLoopEventStatus; @@ -79,6 +81,7 @@ import org.slf4j.LoggerFactory; public class ControlLoopOperationManagerTest { private static final String VSERVER_NAME = "vserver.vserver-name"; private static final String TEST_YAML = "src/test/resources/test.yaml"; + private static final String TEST_CDS_YAML = "src/test/resources/test-cds.yaml"; private static final String ONSET_ONE = "onsetOne"; private static final String VNF_NAME = "generic-vnf.vnf-name"; private static final String VNF_ID = "generic-vnf.vnf-id"; @@ -91,9 +94,8 @@ public class ControlLoopOperationManagerTest { private static final String APPC_FAILURE_REASON = "AppC failed for some reason"; private static final String ACCEPT = "ACCEPT"; - - private static final Logger logger = LoggerFactory.getLogger(ControlLoopOperationManagerTest.class); - + private static final Logger logger = + LoggerFactory.getLogger(ControlLoopOperationManagerTest.class); private static VirtualControlLoopEvent onset; @@ -105,18 +107,21 @@ public class ControlLoopOperationManagerTest { onset.setClosedLoopAlarmStart(Instant.now()); onset.setAai(new HashMap<>()); onset.getAai().put(VNF_NAME, "testTriggerSource"); + onset.getAai().put(VSERVER_NAME, "testVserverName"); onset.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); + onset.setTargetType(ControlLoopTargetType.VNF); /* Set environment properties */ - PolicyEngineConstants.getManager().setEnvironmentProperty("aai.url", "http://localhost:6666"); + PolicyEngineConstants.getManager().setEnvironmentProperty("aai.url", + "http://localhost:6666"); PolicyEngineConstants.getManager().setEnvironmentProperty("aai.username", "AAI"); PolicyEngineConstants.getManager().setEnvironmentProperty("aai.password", "AAI"); + PolicyEngineConstants.getManager().setEnvironmentProperty("aai.customQuery", "false"); } private static EntityManagerFactory emf; private static EntityManager em; - private static int getCount() { // Create a query for number of items in DB String sql = "select count(*) as count from operationshistory"; @@ -125,7 +130,6 @@ public class ControlLoopOperationManagerTest { return ((Number) nq.getSingleResult()).intValue(); } - /** * Set up test class. */ @@ -138,16 +142,18 @@ public class ControlLoopOperationManagerTest { System.setProperty(OPERATIONS_HISTORY_PU, OPERATIONS_HISTORY_PU_TEST); // Enter dummy props to avoid nullPointerException - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL, "a"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, "b"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "c"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL, "a"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, "b"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "c"); // Connect to in-mem db emf = Persistence.createEntityManagerFactory(OPERATIONS_HISTORY_PU_TEST); em = emf.createEntityManager(); } - /** * Clean up test class. */ @@ -165,6 +171,7 @@ public class ControlLoopOperationManagerTest { // final SupportUtil.Pair pair = SupportUtil.loadYaml(TEST_YAML); onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); + onset.getAai().put(VSERVER_NAME, "testVserverName"); // // Create a processor @@ -174,7 +181,7 @@ public class ControlLoopOperationManagerTest { // create the manager // ControlLoopEventManager eventManager = - new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId()); + new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId()); VirtualControlLoopNotification notification = eventManager.activate(onset); assertNotNull(notification); @@ -185,7 +192,7 @@ public class ControlLoopOperationManagerTest { assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status); ControlLoopOperationManager manager = - new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager); + new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager); logger.debug("{}", manager); // // @@ -198,20 +205,22 @@ public class ControlLoopOperationManagerTest { Object request = manager.startOperation(onset); logger.debug("{}", manager); assertNotNull(request); - assertTrue(request instanceof LcmRequestWrapper); - LcmRequestWrapper dmaapRequest = (LcmRequestWrapper) request; - LcmRequest appcRequest = dmaapRequest.getBody(); + assertTrue(request instanceof AppcLcmDmaapWrapper); + AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request; + AppcLcmInput appcRequest = dmaapRequest.getBody().getInput(); assertTrue(appcRequest.getCommonHeader().getSubRequestId().contentEquals("1")); assertFalse(manager.isOperationComplete()); assertTrue(manager.isOperationRunning()); // // Accept // - LcmResponseWrapper dmaapResponse = new LcmResponseWrapper(); - LcmResponse appcResponse = new LcmResponse(appcRequest); + AppcLcmOutput appcResponse = new AppcLcmOutput(appcRequest); appcResponse.getStatus().setCode(100); appcResponse.getStatus().setMessage(ACCEPT); - dmaapResponse.setBody(appcResponse); + AppcLcmBody outputBody = new AppcLcmBody(); + outputBody.setOutput(appcResponse); + AppcLcmDmaapWrapper dmaapResponse = new AppcLcmDmaapWrapper(); + dmaapResponse.setBody(outputBody); // // // @@ -223,10 +232,11 @@ public class ControlLoopOperationManagerTest { // // Now we are going to Fail it // - appcResponse = new LcmResponse(appcRequest); + appcResponse = new AppcLcmOutput(appcRequest); appcResponse.getStatus().setCode(401); appcResponse.getStatus().setMessage(APPC_FAILURE_REASON); - dmaapResponse.setBody(appcResponse); + outputBody.setOutput(appcResponse); + dmaapResponse.setBody(outputBody); result = manager.onResponse(dmaapResponse); logger.debug("{}", manager); assertTrue(result.equals(PolicyResult.FAILURE)); @@ -238,20 +248,21 @@ public class ControlLoopOperationManagerTest { request = manager.startOperation(onset); logger.debug("{}", manager); assertNotNull(request); - assertTrue(request instanceof LcmRequestWrapper); - dmaapRequest = (LcmRequestWrapper) request; - appcRequest = dmaapRequest.getBody(); + assertTrue(request instanceof AppcLcmDmaapWrapper); + dmaapRequest = (AppcLcmDmaapWrapper) request; + appcRequest = dmaapRequest.getBody().getInput(); assertTrue(appcRequest.getCommonHeader().getSubRequestId().contentEquals("2")); assertFalse(manager.isOperationComplete()); assertTrue(manager.isOperationRunning()); // // // - appcResponse = new LcmResponse(appcRequest); + appcResponse = new AppcLcmOutput(appcRequest); logger.debug("{}", manager); appcResponse.getStatus().setCode(100); appcResponse.getStatus().setMessage(ACCEPT); - dmaapResponse.setBody(appcResponse); + outputBody.setOutput(appcResponse); + dmaapResponse.setBody(outputBody); // // // @@ -263,10 +274,11 @@ public class ControlLoopOperationManagerTest { // // Now we are going to Fail it // - appcResponse = new LcmResponse(appcRequest); + appcResponse = new AppcLcmOutput(appcRequest); appcResponse.getStatus().setCode(401); appcResponse.getStatus().setMessage(APPC_FAILURE_REASON); - dmaapResponse.setBody(appcResponse); + outputBody.setOutput(appcResponse); + dmaapResponse.setBody(outputBody); result = manager.onResponse(dmaapResponse); logger.debug("{}", manager); assertTrue(result.equals(PolicyResult.FAILURE)); @@ -287,6 +299,7 @@ public class ControlLoopOperationManagerTest { // final SupportUtil.Pair pair = SupportUtil.loadYaml(TEST_YAML); onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); + onset.getAai().put(VSERVER_NAME, "OzVServer"); // // Create a processor @@ -296,7 +309,7 @@ public class ControlLoopOperationManagerTest { // create the manager // ControlLoopEventManager eventManager = - new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId()); + new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId()); VirtualControlLoopNotification notification = eventManager.activate(onset); assertNotNull(notification); @@ -307,7 +320,7 @@ public class ControlLoopOperationManagerTest { assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status); ControlLoopOperationManager manager = - new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager); + new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager); // // // @@ -320,18 +333,20 @@ public class ControlLoopOperationManagerTest { Object request = manager.startOperation(onset); logger.debug("{}", manager); assertNotNull(request); - assertTrue((request) instanceof LcmRequestWrapper); - LcmRequestWrapper dmaapRequest = (LcmRequestWrapper) request; - LcmRequest appcRequest = dmaapRequest.getBody(); + assertTrue((request) instanceof AppcLcmDmaapWrapper); + AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request; + AppcLcmInput appcRequest = dmaapRequest.getBody().getInput(); assertTrue((appcRequest).getCommonHeader().getSubRequestId().contentEquals("1")); assertFalse(manager.isOperationComplete()); assertTrue(manager.isOperationRunning()); // // Accept // - LcmResponseWrapper dmaapResponse = new LcmResponseWrapper(); - LcmResponse appcResponse = new LcmResponse(appcRequest); - dmaapResponse.setBody(appcResponse); + AppcLcmDmaapWrapper dmaapResponse = new AppcLcmDmaapWrapper(); + AppcLcmOutput appcResponse = new AppcLcmOutput(appcRequest); + AppcLcmBody outputBody = new AppcLcmBody(); + outputBody.setOutput(appcResponse); + dmaapResponse.setBody(outputBody); appcResponse.getStatus().setCode(100); appcResponse.getStatus().setMessage(ACCEPT); // @@ -354,10 +369,11 @@ public class ControlLoopOperationManagerTest { // // Now we are going to Fail the previous request // - appcResponse = new LcmResponse(appcRequest); + appcResponse = new AppcLcmOutput(appcRequest); appcResponse.getStatus().setCode(401); appcResponse.getStatus().setMessage(APPC_FAILURE_REASON); - dmaapResponse.setBody(appcResponse); + outputBody.setOutput(appcResponse); + dmaapResponse.setBody(outputBody); manager.onResponse(dmaapResponse); logger.debug("{}", manager); // @@ -379,13 +395,15 @@ public class ControlLoopOperationManagerTest { onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST); onsetEvent.setRequestId(requestId); onsetEvent.setTarget(VNF_ID); + onsetEvent.setTargetType(ControlLoopTargetType.VNF); onsetEvent.setClosedLoopAlarmStart(Instant.now()); onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); onsetEvent.setAai(new HashMap<>()); onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); + onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); @@ -417,7 +435,8 @@ public class ControlLoopOperationManagerTest { policy.setTarget(savedTarget); policy.getTarget().setType(TargetType.PNF); - assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("PNF target is not supported"); + assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage( + "Target in the onset event is either null or does not match target key expected in AAI section."); onsetEvent.setTarget("Oz"); onsetEvent.getAai().remove(VNF_NAME); @@ -425,7 +444,8 @@ public class ControlLoopOperationManagerTest { onsetEvent.getAai().remove(VSERVER_NAME); policy.getTarget().setType(TargetType.VNF); - assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("Target does not match target type"); + assertThatThrownBy(() -> clom.getTarget(policy)) + .hasMessage("Target does not match target type"); onsetEvent.setTarget(VSERVER_NAME); onsetEvent.getAai().put(VSERVER_NAME, "OzVServer"); @@ -441,16 +461,9 @@ public class ControlLoopOperationManagerTest { manager.onNewEvent(onsetEvent); - onsetEvent.getAai().remove(VNF_ID); - manager.getVnfResponse(); - if (!Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty("aai.customQuery"))) { - clom.getEventManager().getVnfResponse().setVnfId(VNF_ID); - assertEquals(VNF_ID, clom.getTarget(policy)); - } - - policy.getTarget().setType(TargetType.VFC); - assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("The target type is not supported"); + assertThatThrownBy(() -> clom.getTarget(policy)) + .hasMessage("The target type is not supported"); assertEquals(Integer.valueOf(20), clom.getOperationTimeout()); @@ -461,12 +474,13 @@ public class ControlLoopOperationManagerTest { clom.startOperation(onsetEvent); - assertEquals("actor=SO,operation=Restart,target=Target [type=VFC, resourceId=null],subRequestId=1", - clom.getOperationMessage()); assertEquals( - "actor=SO,operation=Restart,target=Target [type=VFC, resourceId=null],subRequestId=1, Guard result: " - + OPER_MSG, - clom.getOperationMessage(OPER_MSG)); + "actor=SO,operation=Restart,target=Target [type=VFC, resourceId=null],subRequestId=1", + clom.getOperationMessage()); + assertEquals( + "actor=SO,operation=Restart,target=Target [type=VFC, resourceId=null],subRequestId=1, Guard result: " + + OPER_MSG, + clom.getOperationMessage(OPER_MSG)); assertEquals("actor=SO,operation=Restart,tar", clom.getOperationHistory().substring(0, 30)); @@ -484,31 +498,35 @@ public class ControlLoopOperationManagerTest { onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST); onsetEvent.setRequestId(requestId); onsetEvent.setTarget(VNF_ID); + onsetEvent.setTargetType(ControlLoopTargetType.VNF); onsetEvent.setClosedLoopAlarmStart(Instant.now()); onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); onsetEvent.setAai(new HashMap<>()); onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); + onsetEvent.getAai().put(VSERVER_NAME, "OzVServer"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); policy.setRecipe("ModifyConfig"); + onsetEvent.getAai().put(VSERVER_NAME, "NonExistentVserver"); policy.getTarget().setResourceID(UUID.randomUUID().toString()); assertThatThrownBy(() -> new ControlLoopOperationManager(onsetEvent, policy, manager)) - .hasMessage("Target vnf-id could not be found"); + .hasMessage("Target vnf-id could not be found"); - policy.getTarget().setResourceID("82194af1-3c2c-485a-8f44-420e22a9eaa4"); + onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); + policy.getTarget().setResourceID("bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38"); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); - policy.setActor("SO"); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); @@ -519,7 +537,7 @@ public class ControlLoopOperationManagerTest { policy.setActor(DOROTHY); assertThatThrownBy(() -> new ControlLoopOperationManager(onsetEvent, policy, manager)) - .hasMessage("ControlLoopEventManager: policy has an unknown actor."); + .hasMessage("ControlLoopEventManager: policy has an unknown actor."); } @Test @@ -532,25 +550,28 @@ public class ControlLoopOperationManagerTest { onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST); onsetEvent.setRequestId(requestId); onsetEvent.setTarget(VNF_ID); + onsetEvent.setTargetType(ControlLoopTargetType.VNF); onsetEvent.setClosedLoopAlarmStart(Instant.now()); onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); onsetEvent.setAai(new HashMap<>()); onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); + onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); clom.startOperation(onsetEvent); ControlLoopOperationManager clom2 = clom; assertThatThrownBy(() -> clom2.startOperation(onsetEvent)) - .hasMessage("current operation is not null (an operation is already running)"); + .hasMessage("current operation is not null (an operation is already running)"); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); @@ -568,7 +589,7 @@ public class ControlLoopOperationManagerTest { assertTrue(clom.isOperationComplete()); ControlLoopOperationManager clom3 = clom; assertThatThrownBy(() -> clom3.startOperation(onsetEvent)) - .hasMessage("current operation failed and retries are not allowed"); + .hasMessage("current operation failed and retries are not allowed"); policy.setRetry(0); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); @@ -578,7 +599,7 @@ public class ControlLoopOperationManagerTest { assertTrue(clom.isOperationComplete()); ControlLoopOperationManager clom4 = clom; assertThatThrownBy(() -> clom4.startOperation(onsetEvent)) - .hasMessage("current operation failed and retries are not allowed"); + .hasMessage("current operation failed and retries are not allowed"); policy.setRetry(1); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); @@ -590,7 +611,7 @@ public class ControlLoopOperationManagerTest { assertTrue(clom.isOperationComplete()); ControlLoopOperationManager clom5 = clom; assertThatThrownBy(() -> clom5.startOperation(onsetEvent)) - .hasMessage("current oepration has failed after 2 retries"); + .hasMessage("current oepration has failed after 2 retries"); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); @@ -607,7 +628,7 @@ public class ControlLoopOperationManagerTest { policy.setActor("Oz"); ControlLoopOperationManager clom6 = clom; assertThatThrownBy(() -> clom6.startOperation(onsetEvent)) - .hasMessage("invalid actor Oz on policy"); + .hasMessage("invalid actor Oz on policy"); } @Test @@ -620,19 +641,22 @@ public class ControlLoopOperationManagerTest { onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST); onsetEvent.setRequestId(requestId); onsetEvent.setTarget(VNF_ID); + onsetEvent.setTargetType(ControlLoopTargetType.VNF); onsetEvent.setClosedLoopAlarmStart(Instant.now()); onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); onsetEvent.setAai(new HashMap<>()); onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); + onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); assertNull(clom.onResponse(null)); @@ -668,17 +692,19 @@ public class ControlLoopOperationManagerTest { responseStatus.setCode(ResponseCode.SUCCESS.getValue()); assertEquals(PolicyResult.SUCCESS, clom.onResponse(appcResponse)); - LcmResponseWrapper lrw = new LcmResponseWrapper(); - LcmResponse body = new LcmResponse(); - LcmCommonHeader lcmCh = new LcmCommonHeader(); - body.setCommonHeader(lcmCh); - lrw.setBody(body); + AppcLcmDmaapWrapper dmaapWrapper = new AppcLcmDmaapWrapper(); + AppcLcmBody body = new AppcLcmBody(); + AppcLcmOutput output = new AppcLcmOutput(); + AppcLcmCommonHeader lcmCh = new AppcLcmCommonHeader(); + output.setCommonHeader(lcmCh); + body.setOutput(output); + dmaapWrapper.setBody(body); lcmCh.setSubRequestId("NotANumber"); - assertEquals(PolicyResult.FAILURE_EXCEPTION, clom.onResponse(lrw)); + assertEquals(PolicyResult.FAILURE_EXCEPTION, clom.onResponse(dmaapWrapper)); lcmCh.setSubRequestId("12345"); - assertEquals(PolicyResult.FAILURE_EXCEPTION, clom.onResponse(lrw)); + assertEquals(PolicyResult.FAILURE_EXCEPTION, clom.onResponse(dmaapWrapper)); SoResponse soResponse = new SoResponse(); SoResponseWrapper soRw = new SoResponseWrapper(soResponse, null); @@ -713,19 +739,22 @@ public class ControlLoopOperationManagerTest { onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST); onsetEvent.setRequestId(requestId); onsetEvent.setTarget(VNF_ID); + onsetEvent.setTargetType(ControlLoopTargetType.VNF); onsetEvent.setClosedLoopAlarmStart(Instant.now()); onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); onsetEvent.setAai(new HashMap<>()); onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); + onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); clom.startOperation(onsetEvent); @@ -734,10 +763,12 @@ public class ControlLoopOperationManagerTest { final SoResponseWrapper soRw = new SoResponseWrapper(soResponse, null); PolicyEngineConstants.getManager().setEnvironmentProperty("guard.disabled", "false"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL, - "http://somewhere.over.the.rainbow"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto"); + PolicyEngineConstants.getManager().setEnvironmentProperty( + org.onap.policy.guard.Util.ONAP_KEY_URL, "http://somewhere.over.the.rainbow"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto"); assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw)); @@ -745,10 +776,52 @@ public class ControlLoopOperationManagerTest { assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw)); } + @Test + public void testStartCdsOperation() throws ControlLoopException, IOException { + + // Prepare + String yamlString; + try (InputStream is = new FileInputStream(new File(TEST_CDS_YAML))) { + yamlString = IOUtils.toString(is, StandardCharsets.UTF_8); + } + + UUID requestId = UUID.randomUUID(); + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + event.setClosedLoopControlName(TWO_ONSET_TEST); + event.setRequestId(requestId); + event.setTarget(VNF_ID); + event.setTargetType(ControlLoopTargetType.VNF); + event.setClosedLoopAlarmStart(Instant.now()); + event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); + event.setAai(new HashMap<>()); + event.getAai().put(VNF_NAME, ONSET_ONE); + event.getAai().put(VSERVER_NAME, "OzVServer"); + + ControlLoopEventManager eventManager = + new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId()); + VirtualControlLoopNotification notification = eventManager.activate(yamlString, event); + assertNotNull(notification); + assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); + + Policy policy = eventManager.getProcessor().getCurrentPolicy(); + ControlLoopOperationManager operationManager = + new ControlLoopOperationManager(event, policy, eventManager); + + // Run + Object result = operationManager.startOperation(event); + + // Verify + assertNotNull(result); + assertTrue(result instanceof ExecutionServiceInput); + ExecutionServiceInput request = (ExecutionServiceInput) result; + logger.debug("request: " + request); + + } + @Test public void testCommitAbatement() throws Exception { - String yamlString = null; + String yamlString; try (InputStream is = new FileInputStream(new File(TEST_YAML))) { yamlString = IOUtils.toString(is, StandardCharsets.UTF_8); } @@ -758,19 +831,22 @@ public class ControlLoopOperationManagerTest { onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST); onsetEvent.setRequestId(requestId); onsetEvent.setTarget(VNF_ID); + onsetEvent.setTargetType(ControlLoopTargetType.VNF); onsetEvent.setClosedLoopAlarmStart(Instant.now()); onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); onsetEvent.setAai(new HashMap<>()); onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); + onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); clom.startOperation(onsetEvent); @@ -797,19 +873,22 @@ public class ControlLoopOperationManagerTest { onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST); onsetEvent.setRequestId(requestId); onsetEvent.setTarget(VNF_ID); + onsetEvent.setTargetType(ControlLoopTargetType.VNF); onsetEvent.setClosedLoopAlarmStart(Instant.now()); onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); onsetEvent.setAai(new HashMap<>()); onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); + onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); clom.startOperation(onsetEvent); @@ -823,10 +902,12 @@ public class ControlLoopOperationManagerTest { final SoResponseWrapper soRw = new SoResponseWrapper(soResponse, null); PolicyEngineConstants.getManager().setEnvironmentProperty("guard.disabled", "false"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL, - "http://somewhere.over.the.rainbow"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto"); + PolicyEngineConstants.getManager().setEnvironmentProperty( + org.onap.policy.guard.Util.ONAP_KEY_URL, "http://somewhere.over.the.rainbow"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto"); assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw)); assertFalse(clom.isOperationRunning());