summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-06-03 09:26:33 -0400
committerJim Hahn <jrh3@att.com>2020-07-14 10:29:49 -0400
commite87b18923c23a1a0fbfaae1c75645a577b96c892 (patch)
tree5b7b0e4d52dca3f81b7c9add036b5f6816d5bf78 /controlloop/common/eventmanager/src/test
parentc3879a50de6473b8673faa9f958a0c646a4b8ca9 (diff)
Remove usecases and legacy actor code
Made the following changes to remove usescase and legacy actor code: - deleted the usecases controller and feature - deleted code associated with legacy actors, with the exception of AaiManager, which is needed by RestControlLoopManager - moved the contents of the "guard" project into the m2/guard project, as that is the only thing that still needs it - modified the m2/GuardContext to get the name of its persistence unit from the properties so it could be overridden by junit tests - used eclipselink constants Also fixed a bug in the properties for the VFC actor. Addressed review comment: - removed usecases from Dockerfile Issue-ID: POLICY-2558 Change-Id: I677d68c9efed9247c3d55773abdcc736b577a6b4 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/eventmanager/src/test')
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java2
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java802
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java929
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockCallbackWorkingMemoryTest.java96
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/drools/DroolsPolicyEngineTest.java79
5 files changed, 1 insertions, 1907 deletions
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java
index ab86a5341..aca8d9655 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java
@@ -3,7 +3,7 @@
* eventmanager
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
deleted file mode 100644
index 7479f66b1..000000000
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
+++ /dev/null
@@ -1,802 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.eventmanager;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.time.Instant;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.tuple.Pair;
-import org.jetbrains.annotations.NotNull;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.io.Serializer;
-import org.onap.policy.controlloop.ControlLoopEventStatus;
-import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.ControlLoopNotificationType;
-import org.onap.policy.controlloop.ControlLoopTargetType;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.VirtualControlLoopNotification;
-import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager.NewEventStatus;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.drools.core.lock.Lock;
-import org.onap.policy.drools.core.lock.LockCallback;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.powermock.reflect.Whitebox;
-
-public class ControlLoopEventManagerTest {
- private static final String TARGET_LOCK_FIELD = "targetLock";
- private static final String ONSET_ONE = "onsetOne";
- private static final String VSERVER_NAME = "vserver.vserver-name";
- private static final String TEST_YAML = "src/test/resources/test.yaml";
- private static final String VNF_NAME = "generic-vnf.vnf-name";
- private static final String VNF_ID = "generic-vnf.vnf-id";
- private static final String AAI_USERNAME = "aai.username";
- private static final String AAI_URL = "aai.url";
- private static final String AAI_PASS = "aai.password";
- private static final String TWO_ONSET_TEST = "TwoOnsetTest";
- private static final String VNF_UUID = "83f674e8-7555-44d7-9a39-bdc3770b0491";
-
- private VirtualControlLoopEvent onset;
- private LockCallback callback;
-
- /**
- * Set up test class.
- */
- @BeforeClass
- public static void setUpSimulator() throws Exception {
- org.onap.policy.simulators.Util.buildAaiSim();
-
- PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_USERNAME, "AAI");
- PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_PASS, "AAI");
- PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_URL, "http://localhost:6666");
- PolicyEngineConstants.getManager().setEnvironmentProperty("aai.customQuery", "false");
- }
-
- @AfterClass
- public static void tearDownSimulator() {
- HttpServletServerFactoryInstance.getServerFactory().destroy();
- }
-
- /**
- * Setup.
- */
- @Before
- public void setUp() {
- callback = mock(LockCallback.class);
-
- onset = new VirtualControlLoopEvent();
- onset.setClosedLoopControlName("ControlLoop-vUSP");
- onset.setRequestId(UUID.randomUUID());
- onset.setTarget("VM_NAME");
- onset.setClosedLoopAlarmStart(Instant.now());
- onset.setAai(new HashMap<>());
- onset.getAai().put("cloud-region.identity-url", "foo");
- onset.getAai().put("vserver.selflink", "bar");
- onset.getAai().put(VNF_ID, VNF_UUID);
- onset.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- onset.setTargetType(ControlLoopTargetType.VNF);
-
- PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_URL, "http://localhost:6666");
- }
-
- @Test
- public void testMethods() {
- UUID requestId = UUID.randomUUID();
- ControlLoopEventManager clem = new ControlLoopEventManager("MyClosedLoopName", requestId);
-
- assertEquals("MyClosedLoopName", clem.getClosedLoopControlName());
- assertEquals(requestId, clem.getRequestId());
-
- clem.setActivated(true);
- assertEquals(true, clem.isActivated());
-
- clem.setControlLoopResult("SUCCESS");
- assertEquals("SUCCESS", clem.getControlLoopResult());
-
- clem.setControlLoopTimedOut();
- assertEquals(true, clem.isControlLoopTimedOut());
-
- clem.setNumAbatements(12345);
- assertEquals(Integer.valueOf(12345), clem.getNumAbatements());
-
- clem.setNumOnsets(54321);
- assertEquals(Integer.valueOf(54321), clem.getNumOnsets());
-
- assertNull(clem.getOnsetEvent());
- assertNull(clem.getAbatementEvent());
- assertNull(clem.getProcessor());
-
- assertEquals(true, clem.isControlLoopTimedOut());
-
- assertNull(clem.unlockCurrentOperation());
- }
-
- @Test
- public void testAlreadyActivated() {
- VirtualControlLoopEvent event = getOnsetEvent();
-
- ControlLoopEventManager manager = makeManager(event);
- manager.setActivated(true);
- VirtualControlLoopNotification notification = manager.activate(event);
- assertEquals(ControlLoopNotificationType.REJECTED, notification.getNotification());
- }
-
- @Test
- public void testActivationYaml() throws IOException, CoderException {
-
- VirtualControlLoopEvent event = getOnsetEvent();
- ControlLoopEventManager manager = makeManager(event);
-
- // Null YAML should fail
- VirtualControlLoopNotification notificationNull = manager.activate((String) null, event);
- assertNotNull(notificationNull);
- assertEquals(ControlLoopNotificationType.REJECTED, notificationNull.getNotification());
-
- // Empty YAML should fail
- VirtualControlLoopNotification notificationEmpty = manager.activate("", event);
- assertNotNull(notificationEmpty);
- assertEquals(ControlLoopNotificationType.REJECTED, notificationEmpty.getNotification());
-
- // Bad YAML should fail
- InputStream isBad = new FileInputStream(new File("src/test/resources/notutf8.yaml"));
- final String yamlStringBad = IOUtils.toString(isBad, StandardCharsets.UTF_8);
-
- VirtualControlLoopNotification notificationBad = manager.activate(yamlStringBad, event);
- assertNotNull(notificationBad);
- assertEquals(ControlLoopNotificationType.REJECTED, notificationBad.getNotification());
-
-
- InputStream is = new FileInputStream(new File(TEST_YAML));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- VirtualControlLoopNotification notification = manager.activate(yamlString, event);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- // Another activate should fail
- VirtualControlLoopNotification notificationActive = manager.activate(yamlString, event);
- assertNotNull(notificationActive);
- assertEquals(ControlLoopNotificationType.REJECTED, notificationActive.getNotification());
- }
-
- @Test
- public void testActivateToscaLegacy() throws IOException, CoderException {
- String policy =
- new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-legacy-vcpe.json")));
- ToscaPolicy toscaPolicy = new StandardCoder().decode(policy, ToscaPolicy.class);
-
- VirtualControlLoopEvent event = getOnsetEvent();
- ControlLoopEventManager manager = makeManager(event);
-
- // trigger a reject by passing the wrong policy type
- toscaPolicy.setType("onap.policies.controlloop.operational.common.Drools");
- VirtualControlLoopNotification notification = manager.activate(toscaPolicy, event);
- assertEquals(ControlLoopNotificationType.REJECTED, notification.getNotification());
-
- // place back correct policy type
- toscaPolicy.setType("onap.policies.controlloop.Operational");
- notification = manager.activate(toscaPolicy, event);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- // another activate should fail
- notification = manager.activate(toscaPolicy, event);
- assertEquals(ControlLoopNotificationType.REJECTED, notification.getNotification());
- }
-
- @Test
- public void testControlLoopFinal() throws Exception {
- VirtualControlLoopEvent event = getOnsetEvent();
-
- ControlLoopEventManager manager = makeManager(event);
- ControlLoopEventManager manager2 = manager;
- assertThatThrownBy(manager2::isControlLoopFinal).isInstanceOf(ControlLoopException.class)
- .hasMessage("ControlLoopEventManager MUST be activated first.");
-
- manager.setActivated(true);
- assertThatThrownBy(manager2::isControlLoopFinal).isInstanceOf(ControlLoopException.class)
- .hasMessage("No onset event for ControlLoopEventManager.");
-
- manager.setActivated(false);
-
- InputStream is = new FileInputStream(new File(TEST_YAML));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- VirtualControlLoopNotification notification = manager.activate(yamlString, event);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- VirtualControlLoopNotification clfNotification = manager.isControlLoopFinal();
- assertNull(clfNotification);
-
- // serialize and de-serialize manager
- manager = Serializer.roundTrip(manager);
-
- manager.getProcessor().nextPolicyForResult(PolicyResult.SUCCESS);
- clfNotification = manager.isControlLoopFinal();
- assertNotNull(clfNotification);
- assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, clfNotification.getNotification());
-
- manager = new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
- notification = manager.activate(yamlString, event);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- manager.getProcessor().nextPolicyForResult(PolicyResult.FAILURE_EXCEPTION);
- clfNotification = manager.isControlLoopFinal();
- assertNotNull(clfNotification);
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE, clfNotification.getNotification());
-
- manager = new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
- notification = manager.activate(yamlString, event);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- manager.getProcessor().nextPolicyForResult(PolicyResult.FAILURE_GUARD);
- clfNotification = manager.isControlLoopFinal();
- assertNotNull(clfNotification);
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE, clfNotification.getNotification());
-
- manager.setControlLoopTimedOut();
- clfNotification = manager.isControlLoopFinal();
- assertNotNull(clfNotification);
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE, clfNotification.getNotification());
- }
-
- @NotNull
- private VirtualControlLoopEvent getOnsetEvent() {
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(TWO_ONSET_TEST);
- event.setRequestId(requestId);
- event.setTarget(VNF_ID);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- event.setAai(new HashMap<>());
- event.getAai().put(VNF_NAME, ONSET_ONE);
- event.setTargetType(ControlLoopTargetType.VNF);
- return event;
- }
-
- @Test
- public void testProcessControlLoop() throws Exception {
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(TWO_ONSET_TEST);
- event.setRequestId(requestId);
- event.setTarget(VNF_ID);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- event.setAai(new HashMap<>());
- event.getAai().put(VNF_NAME, ONSET_ONE);
- event.getAai().put(VSERVER_NAME, "testVserverName");
- event.setTargetType(ControlLoopTargetType.VNF);
-
- ControlLoopEventManager manager = makeManager(event);
- ControlLoopEventManager manager2 = manager;
- assertThatThrownBy(manager2::processControlLoop).isInstanceOf(ControlLoopException.class)
- .hasMessage("ControlLoopEventManager MUST be activated first.");
-
- manager.setActivated(true);
- assertThatThrownBy(manager2::processControlLoop).isInstanceOf(ControlLoopException.class)
- .hasMessage("No onset event for ControlLoopEventManager.");
-
- manager.setActivated(false);
-
- InputStream is = new FileInputStream(new File(TEST_YAML));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- VirtualControlLoopNotification notification = manager.activate(yamlString, event);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- ControlLoopOperationManager clom = manager.processControlLoop();
- assertNotNull(clom);
- assertNull(clom.getOperationResult());
-
- // serialize and de-serialize manager
- manager = Serializer.roundTrip(manager);
-
- // Test operation in progress
- ControlLoopEventManager manager3 = manager;
- assertThatThrownBy(manager3::processControlLoop).isInstanceOf(ControlLoopException.class)
- .hasMessage("Already working an Operation, do not call this method.");
-
- manager = new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
- notification = manager.activate(yamlString, event);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- manager.getProcessor().nextPolicyForResult(PolicyResult.FAILURE_GUARD);
- VirtualControlLoopNotification clfNotification = manager.isControlLoopFinal();
- assertNotNull(clfNotification);
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE, clfNotification.getNotification());
-
- // Test operation completed
- ControlLoopEventManager manager4 = manager;
- assertThatThrownBy(manager4::processControlLoop).isInstanceOf(ControlLoopException.class)
- .hasMessage("Control Loop is in FINAL state, do not call this method.");
-
- manager = new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
- notification = manager.activate(yamlString, event);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
- manager.getProcessor().nextPolicyForResult(PolicyResult.FAILURE);
-
- // Test operation with no next policy defined
- ControlLoopEventManager manager5 = manager;
- assertThatThrownBy(manager5::processControlLoop).isInstanceOf(ControlLoopException.class)
- .hasMessage("The target type is null");
- }
-
- @Test
- public void testFinishOperation() throws Exception {
- InputStream isStd = new FileInputStream(new File(TEST_YAML));
- final String yamlStringStd = IOUtils.toString(isStd, StandardCharsets.UTF_8);
-
- VirtualControlLoopEvent event = makeEvent();
-
- ControlLoopEventManager manager = makeManager(event);
- ControlLoopEventManager manager2 = manager;
- assertThatThrownBy(() -> manager2.finishOperation(null)).isInstanceOf(ControlLoopException.class)
- .hasMessage("No operation to finish.");
-
- manager.setActivated(true);
- assertThatThrownBy(() -> manager2.finishOperation(null)).isInstanceOf(ControlLoopException.class)
- .hasMessage("No operation to finish.");
-
- manager.setActivated(false);
-
- InputStream is = new FileInputStream(new File("src/test/resources/testSOactor.yaml"));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- VirtualControlLoopNotification notification = manager.activate(yamlString, event);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- event.getAai().put(VSERVER_NAME, "testVserverName");
-
- // serialize and de-serialize manager
- manager = Serializer.roundTrip(manager);
-
- ControlLoopOperationManager clom = manager.processControlLoop();
- assertNotNull(clom);
- assertNull(clom.getOperationResult());
-
- clom.startOperation(event);
-
- // This call should be exception free
- manager.finishOperation(clom);
-
- ControlLoopEventManager otherManager = makeManager(event);
- VirtualControlLoopNotification otherNotification = otherManager.activate(yamlStringStd, event);
- assertNotNull(otherNotification);
- assertEquals(ControlLoopNotificationType.ACTIVE, otherNotification.getNotification());
-
- ControlLoopOperationManager otherClom = otherManager.processControlLoop();
- assertNotNull(otherClom);
- assertNull(otherClom.getOperationResult());
-
- otherManager.finishOperation(clom);
- }
-
- @Test
- public void testLockCurrentOperation_testUnlockCurrentOperation() throws Exception {
- VirtualControlLoopEvent event = makeEvent();
-
- ControlLoopEventManager manager = makeManager(event);
-
- manager.setActivated(false);
-
- InputStream is = new FileInputStream(new File("src/test/resources/testSOactor.yaml"));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- VirtualControlLoopNotification notification = manager.activate(yamlString, event);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- ControlLoopEventManager manager2 = manager;
- assertThatThrownBy(() -> manager2.lockCurrentOperation(callback)).isInstanceOf(ControlLoopException.class)
- .hasMessage("Do not have a current operation.");
-
- assertNull(manager.unlockCurrentOperation());
-
- event.getAai().put(VSERVER_NAME, "testVserverName");
-
- ControlLoopOperationManager clom = manager.processControlLoop();
- assertNotNull(clom);
- assertNull(clom.getOperationResult());
-
- Pair<Lock, Lock> lockPair = manager.lockCurrentOperation(callback);
- assertNull(lockPair.getLeft());
- assertNotNull(lockPair.getRight());
-
- // pseudo lock - session should NOT have been notified of the change
- verify(callback, never()).lockAvailable(any());
- verify(callback, never()).lockUnavailable(any());
-
- // repeat - should cause an extension
- Lock lock = lockPair.getRight();
- lockPair = manager.lockCurrentOperation(callback);
-
- /*
- * even with a pseudo lock, the session should have been notified that it was
- * extended
- */
-
- verify(callback).lockAvailable(lock);
-
- assertSame(lock, manager.unlockCurrentOperation());
-
- assertNull(lockPair.getLeft());
- assertNull(lockPair.getRight());
-
- // force it to use a pseudo lock
- manager.setUseTargetLock(false);
- lockPair = manager.lockCurrentOperation(callback);
- assertNull(lockPair.getLeft());
- assertNotNull(lockPair.getRight());
-
- lock = lockPair.getRight();
-
- lockPair = manager.lockCurrentOperation(callback);
- assertNull(lockPair.getLeft());
- assertNull(lockPair.getRight());
-
- // first lock uses a pseudo lock, so it will only update when extended
- verify(callback).lockAvailable(lock);
-
- // force it to re-create the lock due to change in resource ID
- lock = mock(Lock.class);
- when(lock.getResourceId()).thenReturn("different");
- Whitebox.setInternalState(manager, TARGET_LOCK_FIELD, lock);
-
- lockPair = manager.lockCurrentOperation(callback);
- assertSame(lock, lockPair.getLeft());
- assertNotNull(lockPair.getRight());
-
- lock = lockPair.getRight();
-
- lockPair = manager.lockCurrentOperation(callback);
- assertNull(lockPair.getLeft());
- assertNull(lockPair.getRight());
-
- // first lock uses a pseudo lock, so it won't do an update
- verify(callback).lockAvailable(lock);
-
- assertSame(lock, manager.unlockCurrentOperation());
- assertNull(manager.unlockCurrentOperation());
-
- // try again - this time don't return the fact handle- no change in count
- lockPair = manager.lockCurrentOperation(callback);
- assertNull(lockPair.getLeft());
- assertNotNull(lockPair.getRight());
- }
-
- @Test
- public void testOnNewEvent() throws Exception {
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- onsetEvent.setClosedLoopControlName(TWO_ONSET_TEST);
- onsetEvent.setRequestId(requestId);
- onsetEvent.setTarget(VNF_ID);
- onsetEvent.setClosedLoopAlarmStart(Instant.now());
- onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- onsetEvent.setAai(new HashMap<>());
- onsetEvent.getAai().put(VNF_NAME, ONSET_ONE);
- onsetEvent.setTargetType(ControlLoopTargetType.VNF);
-
- VirtualControlLoopEvent abatedEvent = new VirtualControlLoopEvent();
- abatedEvent.setClosedLoopControlName(TWO_ONSET_TEST);
- abatedEvent.setRequestId(requestId);
- abatedEvent.setTarget(VNF_ID);
- abatedEvent.setClosedLoopAlarmStart(Instant.now());
- abatedEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED);
- abatedEvent.setAai(new HashMap<>());
- abatedEvent.getAai().put(VNF_NAME, ONSET_ONE);
-
- ControlLoopEventManager manager = makeManager(onsetEvent);
-
- InputStream is = new FileInputStream(new File(TEST_YAML));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- assertEquals(NewEventStatus.FIRST_ONSET, manager.onNewEvent(onsetEvent));
- assertEquals(NewEventStatus.FIRST_ABATEMENT, manager.onNewEvent(abatedEvent));
- assertEquals(NewEventStatus.SUBSEQUENT_ABATEMENT, manager.onNewEvent(abatedEvent));
-
- VirtualControlLoopEvent checkSyntaxEvent = new VirtualControlLoopEvent();
- checkSyntaxEvent.setAai(null);
- checkSyntaxEvent.setClosedLoopAlarmEnd(null);
- checkSyntaxEvent.setClosedLoopAlarmStart(null);
- checkSyntaxEvent.setClosedLoopControlName(null);
- checkSyntaxEvent.setClosedLoopEventClient(null);
- checkSyntaxEvent.setClosedLoopEventStatus(null);
- checkSyntaxEvent.setFrom(null);
- checkSyntaxEvent.setPolicyName(null);
- checkSyntaxEvent.setPolicyScope(null);
- checkSyntaxEvent.setPolicyVersion(null);
- checkSyntaxEvent.setRequestId(null);
- checkSyntaxEvent.setTarget(null);
- checkSyntaxEvent.setTargetType(null);
- checkSyntaxEvent.setVersion(null);
-
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setClosedLoopControlName(null);
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setClosedLoopControlName("");
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setClosedLoopControlName(TWO_ONSET_TEST);
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setRequestId(null);
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setRequestId(requestId);
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setAai(null);
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setAai(new HashMap<>());
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setTargetType("");
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setTarget("");
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setTarget(null);
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setTarget("");
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setTarget("OZ");
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setTarget("VM_NAME");
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setTarget("VNF_NAME");
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setTarget(VSERVER_NAME);
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setTarget(VNF_ID);
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setTarget(VNF_NAME);
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setAai(null);
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.setAai(new HashMap<>());
- assertEquals(NewEventStatus.SYNTAX_ERROR, manager.onNewEvent(checkSyntaxEvent));
-
- checkSyntaxEvent.getAai().put(VNF_NAME, ONSET_ONE);
- assertEquals(NewEventStatus.SUBSEQUENT_ABATEMENT, manager.onNewEvent(abatedEvent));
-
- checkSyntaxEvent.getAai().put(VSERVER_NAME, ONSET_ONE);
- assertEquals(NewEventStatus.SUBSEQUENT_ABATEMENT, manager.onNewEvent(abatedEvent));
-
- checkSyntaxEvent.getAai().put(VNF_ID, ONSET_ONE);
- assertEquals(NewEventStatus.SUBSEQUENT_ABATEMENT, manager.onNewEvent(abatedEvent));
- }
-
- @Test
- public void testControlLoopTimeout() throws IOException {
- VirtualControlLoopEvent onsetEvent = getOnsetEvent();
-
- ControlLoopEventManager manager = makeManager(onsetEvent);
- assertEquals(0, manager.getControlLoopTimeout(null));
- assertEquals(120, manager.getControlLoopTimeout(120));
-
- InputStream is = new FileInputStream(new File(TEST_YAML));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- assertEquals(60, manager.getControlLoopTimeout(null));
- }
-
- @Test
- public void testControlLoopTimeout_ZeroTimeout() throws IOException {
- VirtualControlLoopEvent onsetEvent = getOnsetEvent();
-
- ControlLoopEventManager manager = makeManager(onsetEvent);
-
- InputStream is = new FileInputStream(new File("src/test/resources/test-zero-timeout.yaml"));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- assertEquals(0, manager.getControlLoopTimeout(null));
- assertEquals(120, manager.getControlLoopTimeout(120));
- }
-
- @Test
- public void testControlLoopTimeout_NullTimeout() throws IOException {
- VirtualControlLoopEvent onsetEvent = getOnsetEvent();
-
- ControlLoopEventManager manager = makeManager(onsetEvent);
-
- InputStream is = new FileInputStream(new File("src/test/resources/test-null-timeout.yaml"));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- assertEquals(0, manager.getControlLoopTimeout(null));
- assertEquals(120, manager.getControlLoopTimeout(120));
- }
-
- @Test
- public void testIsClosedLoopDisabled() {
- Map<String, String> aai = onset.getAai();
-
- // null, null
- aai.remove(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED);
- aai.remove(ControlLoopEventManager.VSERVER_IS_CLOSED_LOOP_DISABLED);
- assertFalse(ControlLoopEventManager.isClosedLoopDisabled(onset));
-
- // null, false
- aai.remove(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED);
- aai.put(ControlLoopEventManager.VSERVER_IS_CLOSED_LOOP_DISABLED, Boolean.FALSE.toString());
- assertFalse(ControlLoopEventManager.isClosedLoopDisabled(onset));
-
- // false, null
- aai.put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.FALSE.toString());
- aai.remove(ControlLoopEventManager.VSERVER_IS_CLOSED_LOOP_DISABLED);
- assertFalse(ControlLoopEventManager.isClosedLoopDisabled(onset));
-
- // null, true
- aai.remove(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED);
- aai.put(ControlLoopEventManager.VSERVER_IS_CLOSED_LOOP_DISABLED, Boolean.TRUE.toString());
- assertTrue(ControlLoopEventManager.isClosedLoopDisabled(onset));
-
- // true, null
- aai.put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.TRUE.toString());
- aai.remove(ControlLoopEventManager.VSERVER_IS_CLOSED_LOOP_DISABLED);
- assertTrue(ControlLoopEventManager.isClosedLoopDisabled(onset));
- }
-
- @Test
- public void testIsProvStatusInactive() {
- Map<String, String> aai = onset.getAai();
-
- // null, null
- aai.remove(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS);
- aai.remove(ControlLoopEventManager.VSERVER_PROV_STATUS);
- assertFalse(ControlLoopEventManager.isProvStatusInactive(onset));
-
- // null, active
- aai.remove(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS);
- aai.put(ControlLoopEventManager.VSERVER_PROV_STATUS, ControlLoopEventManager.PROV_STATUS_ACTIVE);
- assertFalse(ControlLoopEventManager.isProvStatusInactive(onset));
-
- // active, null
- aai.put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, ControlLoopEventManager.PROV_STATUS_ACTIVE);
- aai.remove(ControlLoopEventManager.VSERVER_PROV_STATUS);
- assertFalse(ControlLoopEventManager.isProvStatusInactive(onset));
-
- // null, inactive
- aai.remove(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS);
- aai.put(ControlLoopEventManager.VSERVER_PROV_STATUS, "other1");
- assertTrue(ControlLoopEventManager.isProvStatusInactive(onset));
-
- // inactive, null
- aai.put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, "other2");
- aai.remove(ControlLoopEventManager.VSERVER_PROV_STATUS);
- assertTrue(ControlLoopEventManager.isProvStatusInactive(onset));
- }
-
- @Test
- public void testIsAaiTrue() {
- assertTrue(ControlLoopEventManager.isAaiTrue("tRuE"));
- assertTrue(ControlLoopEventManager.isAaiTrue("T"));
- assertTrue(ControlLoopEventManager.isAaiTrue("t"));
- assertTrue(ControlLoopEventManager.isAaiTrue("yES"));
- assertTrue(ControlLoopEventManager.isAaiTrue("Y"));
- assertTrue(ControlLoopEventManager.isAaiTrue("y"));
-
- assertFalse(ControlLoopEventManager.isAaiTrue("no"));
- assertFalse(ControlLoopEventManager.isAaiTrue(null));
- }
-
-
- private VirtualControlLoopEvent makeEvent() {
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(TWO_ONSET_TEST);
- event.setRequestId(requestId);
- event.setTarget(VNF_ID);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- event.setAai(new HashMap<>());
- event.getAai().put(VNF_ID, ONSET_ONE);
- event.getAai().put(VSERVER_NAME, "test-vserver");
- event.setTargetType(ControlLoopTargetType.VNF);
- return event;
- }
-
- private ControlLoopEventManager makeManager(VirtualControlLoopEvent event) {
- return new MyManager(event.getClosedLoopControlName(), event.getRequestId());
- }
-
- private static class MyManager extends ControlLoopEventManager implements Serializable {
- private static final long serialVersionUID = 1L;
-
- public MyManager(String closedLoopControlName, UUID requestId) {
- super(closedLoopControlName, requestId);
- }
-
- @Override
- protected Lock createRealLock(String targetEntity, UUID requestId, int holdSec, LockCallback callback) {
- return createPseudoLock(targetEntity, requestId, holdSec, callback);
- }
- }
-}
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
deleted file mode 100644
index b64d9484e..000000000
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
+++ /dev/null
@@ -1,929 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.eventmanager;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.time.Instant;
-import java.util.HashMap;
-import java.util.UUID;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.persistence.Query;
-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.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;
-import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.ControlLoopNotificationType;
-import org.onap.policy.controlloop.ControlLoopTargetType;
-import org.onap.policy.controlloop.SupportUtil;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.VirtualControlLoopNotification;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-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.controlloop.processor.ControlLoopProcessor;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.so.SoResponse;
-import org.onap.policy.so.SoResponseWrapper;
-import org.onap.policy.vfc.VfcResponse;
-import org.onap.policy.vfc.VfcResponseDescriptor;
-import org.slf4j.Logger;
-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";
- private static final String TWO_ONSET_TEST = "TwoOnsetTest";
- private static final String OPER_MSG = "The Wizard Escaped";
- private static final String OZ_VNF = "OzVNF";
- private static final String OPERATIONS_HISTORY_PU_TEST = "OperationsHistoryPUTest";
- private static final String OPERATIONS_HISTORY_PU = "OperationsHistoryPU";
- private static final String DOROTHY = "Dorothy";
- 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 VirtualControlLoopEvent onset;
-
- static {
- onset = new VirtualControlLoopEvent();
- onset.setRequestId(UUID.randomUUID());
- onset.setTarget(VNF_NAME);
- onset.setTargetType(ControlLoopTargetType.VNF);
- 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.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";
- Query nq = em.createNativeQuery(sql);
-
- return ((Number) nq.getSingleResult()).intValue();
- }
-
- /**
- * Set up test class.
- */
- @BeforeClass
- public static void setUp() throws Exception {
-
- org.onap.policy.simulators.Util.buildAaiSim();
-
- // Set PU
- 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");
-
- // Connect to in-mem db
- emf = Persistence.createEntityManagerFactory(OPERATIONS_HISTORY_PU_TEST);
- em = emf.createEntityManager();
- }
-
- /**
- * Clean up test class.
- */
- @AfterClass
- public static void tearDown() {
- em.close();
- emf.close();
- HttpServletServerFactoryInstance.getServerFactory().destroy();
- }
-
- @Test
- public void testRetriesFail() throws Exception {
- //
- // Load up the policy
- //
- final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML);
- onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName());
- onset.getAai().put(VSERVER_NAME, "testVserverName");
-
- //
- // Create a processor
- //
- final ControlLoopProcessor processor = new ControlLoopProcessor(pair.value);
- //
- // create the manager
- //
- ControlLoopEventManager eventManager =
- new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId());
- VirtualControlLoopNotification notification = eventManager.activate(onset);
-
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- ControlLoopEventManager.NewEventStatus status = eventManager.onNewEvent(onset);
- assertNotNull(status);
- assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status);
-
- ControlLoopOperationManager manager =
- new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager);
- logger.debug("{}", manager);
- //
- //
- //
- assertFalse(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- //
- // Start
- //
- Object request = manager.startOperation(onset);
- logger.debug("{}", manager);
- assertNotNull(request);
- 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
- //
- AppcLcmOutput appcResponse = new AppcLcmOutput(appcRequest);
- appcResponse.getStatus().setCode(100);
- appcResponse.getStatus().setMessage(ACCEPT);
- AppcLcmBody outputBody = new AppcLcmBody();
- outputBody.setOutput(appcResponse);
- AppcLcmDmaapWrapper dmaapResponse = new AppcLcmDmaapWrapper();
- dmaapResponse.setBody(outputBody);
- //
- //
- //
- PolicyResult result = manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- assertNull(result);
- assertFalse(manager.isOperationComplete());
- assertTrue(manager.isOperationRunning());
- //
- // Now we are going to Fail it
- //
- appcResponse = new AppcLcmOutput(appcRequest);
- appcResponse.getStatus().setCode(401);
- appcResponse.getStatus().setMessage(APPC_FAILURE_REASON);
- outputBody.setOutput(appcResponse);
- dmaapResponse.setBody(outputBody);
- result = manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- assertEquals(PolicyResult.FAILURE, result);
- assertFalse(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- //
- // Retry it
- //
- request = manager.startOperation(onset);
- logger.debug("{}", manager);
- assertNotNull(request);
- 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 AppcLcmOutput(appcRequest);
- logger.debug("{}", manager);
- appcResponse.getStatus().setCode(100);
- appcResponse.getStatus().setMessage(ACCEPT);
- outputBody.setOutput(appcResponse);
- dmaapResponse.setBody(outputBody);
- //
- //
- //
- result = manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- assertNull(result);
- assertFalse(manager.isOperationComplete());
- assertTrue(manager.isOperationRunning());
- //
- // Now we are going to Fail it
- //
- appcResponse = new AppcLcmOutput(appcRequest);
- appcResponse.getStatus().setCode(401);
- appcResponse.getStatus().setMessage(APPC_FAILURE_REASON);
- outputBody.setOutput(appcResponse);
- dmaapResponse.setBody(outputBody);
- result = manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- assertEquals(PolicyResult.FAILURE, result);
- //
- // Should be complete now
- //
- assertTrue(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- assertNotNull(manager.getOperationResult());
- assertEquals(PolicyResult.FAILURE_RETRIES, manager.getOperationResult());
- assertEquals(2, manager.getHistory().size());
- }
-
- @Test
- public void testTimeout() throws Exception {
- //
- // Load up the policy
- //
- final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML);
- onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName());
- onset.getAai().put(VSERVER_NAME, "OzVServer");
-
- //
- // Create a processor
- //
- final ControlLoopProcessor processor = new ControlLoopProcessor(pair.value);
- //
- // create the manager
- //
- ControlLoopEventManager eventManager =
- new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId());
- VirtualControlLoopNotification notification = eventManager.activate(onset);
-
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- ControlLoopEventManager.NewEventStatus status = eventManager.onNewEvent(onset);
- assertNotNull(status);
- assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status);
-
- ControlLoopOperationManager manager =
- new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager);
- //
- //
- //
- logger.debug("{}", manager);
- assertFalse(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- //
- // Start
- //
- Object request = manager.startOperation(onset);
- logger.debug("{}", manager);
- assertNotNull(request);
- 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
- //
- 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);
- //
- //
- //
- PolicyResult result = manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- assertNull(result);
- assertFalse(manager.isOperationComplete());
- assertTrue(manager.isOperationRunning());
- //
- // Now we are going to simulate Timeout
- //
- manager.setOperationHasTimedOut();
- logger.debug("{}", manager);
- assertTrue(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- assertEquals(1, manager.getHistory().size());
- assertEquals(PolicyResult.FAILURE_TIMEOUT, manager.getOperationResult());
- //
- // Now we are going to Fail the previous request
- //
- appcResponse = new AppcLcmOutput(appcRequest);
- appcResponse.getStatus().setCode(401);
- appcResponse.getStatus().setMessage(APPC_FAILURE_REASON);
- outputBody.setOutput(appcResponse);
- dmaapResponse.setBody(outputBody);
- manager.onResponse(dmaapResponse);
- logger.debug("{}", manager);
- //
- //
- //
- assertTrue(manager.isOperationComplete());
- assertFalse(manager.isOperationRunning());
- assertEquals(1, manager.getHistory().size());
- assertEquals(PolicyResult.FAILURE_TIMEOUT, manager.getOperationResult());
- }
-
- @Test
- public void testMethods() throws IOException, ControlLoopException, AaiException {
- InputStream is = new FileInputStream(new File("src/test/resources/testSOactor.yaml"));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- 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());
- VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent);
- assertNotNull(notification);
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
- ControlLoopOperationManager clom = manager.processControlLoop();
- assertNotNull(clom);
- assertNull(clom.getOperationResult());
-
- clom.setEventManager(manager);
- assertEquals(manager, clom.getEventManager());
-
- assertNull(clom.getTargetEntity());
-
- clom.setGuardApprovalStatus("WizardOKedIt");
- assertEquals("WizardOKedIt", clom.getGuardApprovalStatus());
-
- assertNull(clom.getOperationResult());
-
- Policy policy = manager.getProcessor().getCurrentPolicy();
- clom.getTarget(policy);
-
- final Target savedTarget = policy.getTarget();
- policy.setTarget(null);
- assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("The target is null");
-
- policy.setTarget(new Target());
- assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("The target type is null");
-
- policy.setTarget(savedTarget);
-
- policy.getTarget().setType(TargetType.PNF);
- 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);
- onsetEvent.getAai().remove(VNF_ID);
- onsetEvent.getAai().remove(VSERVER_NAME);
-
- policy.getTarget().setType(TargetType.VNF);
- assertThatThrownBy(() -> clom.getTarget(policy))
- .hasMessage("Target does not match target type");
-
- onsetEvent.setTarget(VSERVER_NAME);
- onsetEvent.getAai().put(VSERVER_NAME, "OzVServer");
- assertEquals("OzVServer", clom.getTarget(policy));
-
- onsetEvent.getAai().remove(VSERVER_NAME);
- onsetEvent.setTarget(VNF_ID);
- onsetEvent.getAai().put(VNF_ID, OZ_VNF);
- assertEquals(OZ_VNF, clom.getTarget(policy));
-
- onsetEvent.setTarget(VNF_NAME);
- assertEquals(OZ_VNF, clom.getTarget(policy));
-
- manager.onNewEvent(onsetEvent);
-
- policy.getTarget().setType(TargetType.VFC);
- assertThatThrownBy(() -> clom.getTarget(policy))
- .hasMessage("The target type is not supported");
-
- assertEquals(Integer.valueOf(20), clom.getOperationTimeout());
-
- assertEquals("20s", clom.getOperationTimeoutString(100));
-
- assertEquals(null, clom.getOperationMessage());
- assertEquals(null, clom.getOperationMessage(OPER_MSG));
-
- 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));
-
- assertEquals("actor=SO,operation=Restart,tar", clom.getOperationHistory().substring(0, 30));
-
- clom.setOperationHasException("The Wizard is gone");
- clom.setOperationHasGuardDeny();
- }
-
- @Test
- public void testConstructor() throws IOException, ControlLoopException, AaiException {
- InputStream is = new FileInputStream(new File(TEST_YAML));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- 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());
- 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);
- 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");
-
- 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);
-
- policy.setActor("VFC");
- clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
- assertNotNull(clom);
-
- policy.setActor(DOROTHY);
- assertThatThrownBy(() -> new ControlLoopOperationManager(onsetEvent, policy, manager))
- .hasMessage("ControlLoopEventManager: policy has an unknown actor.");
- }
-
- @Test
- public void testStartOperation() throws IOException, ControlLoopException, AaiException {
- InputStream is = new FileInputStream(new File(TEST_YAML));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- 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());
- 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);
- assertNotNull(clom);
-
- clom.startOperation(onsetEvent);
- ControlLoopOperationManager clom2 = clom;
- assertThatThrownBy(() -> clom2.startOperation(onsetEvent))
- .hasMessage("current operation is not null (an operation is already running)");
-
- clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
- assertNotNull(clom);
- final String savedRecipe = policy.getRecipe();
- policy.setRecipe("ModifyConfig");
- policy.getTarget().setResourceID(UUID.randomUUID().toString());
- clom.startOperation(onsetEvent);
- policy.setRecipe(savedRecipe);
-
- policy.setRetry(null);
- clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
- assertNotNull(clom);
- clom.startOperation(onsetEvent);
- clom.setOperationHasTimedOut();
- assertTrue(clom.isOperationComplete());
- ControlLoopOperationManager clom3 = clom;
- assertThatThrownBy(() -> clom3.startOperation(onsetEvent))
- .hasMessage("current operation failed and retries are not allowed");
-
- policy.setRetry(0);
- clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
- assertNotNull(clom);
- clom.startOperation(onsetEvent);
- clom.setOperationHasTimedOut();
- assertTrue(clom.isOperationComplete());
- ControlLoopOperationManager clom4 = clom;
- assertThatThrownBy(() -> clom4.startOperation(onsetEvent))
- .hasMessage("current operation failed and retries are not allowed");
-
- policy.setRetry(1);
- clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
- assertNotNull(clom);
- clom.startOperation(onsetEvent);
- clom.setOperationHasTimedOut();
- clom.startOperation(onsetEvent);
- clom.setOperationHasTimedOut();
- assertTrue(clom.isOperationComplete());
- ControlLoopOperationManager clom5 = clom;
- assertThatThrownBy(() -> clom5.startOperation(onsetEvent))
- .hasMessage("current oepration has failed after 2 retries");
-
- clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
- assertNotNull(clom);
- policy.setActor("SO");
- clom.startOperation(onsetEvent);
-
- clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
- assertNotNull(clom);
- policy.setActor("VFC");
- clom.startOperation(onsetEvent);
-
- clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
- assertNotNull(clom);
- policy.setActor("Oz");
- ControlLoopOperationManager clom6 = clom;
- assertThatThrownBy(() -> clom6.startOperation(onsetEvent))
- .hasMessage("invalid actor Oz on policy");
- }
-
- @Test
- public void testOnResponse() throws IOException, ControlLoopException, AaiException {
- InputStream is = new FileInputStream(new File(TEST_YAML));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- 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());
- 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);
- assertNotNull(clom);
-
- assertNull(clom.onResponse(null));
-
- Response appcResponse = new Response();
- CommonHeader commonHeader = new CommonHeader();
- appcResponse.setCommonHeader(commonHeader);
- assertEquals(PolicyResult.FAILURE_EXCEPTION, clom.onResponse(appcResponse));
-
- commonHeader.setSubRequestId("12345");
- appcResponse.setStatus(null);
- assertEquals(PolicyResult.FAILURE_EXCEPTION, clom.onResponse(appcResponse));
-
- ResponseStatus responseStatus = new ResponseStatus();
- appcResponse.setStatus(responseStatus);
- assertEquals(PolicyResult.FAILURE_EXCEPTION, clom.onResponse(appcResponse));
-
- responseStatus.setCode(0);
- assertEquals(PolicyResult.FAILURE_EXCEPTION, clom.onResponse(appcResponse));
-
- responseStatus.setCode(ResponseCode.ACCEPT.getValue());
- assertEquals(null, clom.onResponse(appcResponse));
-
- responseStatus.setCode(ResponseCode.ERROR.getValue());
- assertEquals(PolicyResult.FAILURE_EXCEPTION, clom.onResponse(appcResponse));
-
- responseStatus.setCode(ResponseCode.FAILURE.getValue());
- assertEquals(PolicyResult.FAILURE, clom.onResponse(appcResponse));
-
- responseStatus.setCode(ResponseCode.REJECT.getValue());
- assertEquals(PolicyResult.FAILURE_EXCEPTION, clom.onResponse(appcResponse));
-
- responseStatus.setCode(ResponseCode.SUCCESS.getValue());
- assertEquals(PolicyResult.SUCCESS, clom.onResponse(appcResponse));
-
- 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(dmaapWrapper));
-
- lcmCh.setSubRequestId("12345");
- assertEquals(PolicyResult.FAILURE_EXCEPTION, clom.onResponse(dmaapWrapper));
-
- SoResponse soResponse = new SoResponse();
- SoResponseWrapper soRw = new SoResponseWrapper(soResponse, null);
-
- soResponse.setHttpResponseCode(200);
- assertEquals(PolicyResult.SUCCESS, clom.onResponse(soRw));
-
- soResponse.setHttpResponseCode(202);
- assertEquals(PolicyResult.SUCCESS, clom.onResponse(soRw));
-
- soResponse.setHttpResponseCode(500);
- assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
-
- VfcResponse vfcResponse = new VfcResponse();
- VfcResponseDescriptor responseDescriptor = new VfcResponseDescriptor();
- vfcResponse.setResponseDescriptor(responseDescriptor);
-
- responseDescriptor.setStatus("finished");
- assertEquals(PolicyResult.SUCCESS, clom.onResponse(vfcResponse));
-
- responseDescriptor.setStatus("unfinished");
- assertEquals(PolicyResult.FAILURE, clom.onResponse(vfcResponse));
- }
-
- @Test
- public void testCompleteOperation() throws ControlLoopException, AaiException, IOException {
- InputStream is = new FileInputStream(new File(TEST_YAML));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- 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());
- 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);
- assertNotNull(clom);
-
- clom.startOperation(onsetEvent);
-
- SoResponse soResponse = new SoResponse();
- 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");
-
- assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
-
- System.setProperty(OPERATIONS_HISTORY_PU, OPERATIONS_HISTORY_PU_TEST);
- 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;
- try (InputStream is = new FileInputStream(new File(TEST_YAML))) {
- yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
- }
-
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- 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());
- 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);
- assertNotNull(clom);
-
- clom.startOperation(onsetEvent);
-
- int numEventsBefore = getCount();
- logger.info("numEventsBefore={}", numEventsBefore);
-
- clom.commitAbatement("Test message", "TEST_RESULT");
-
- int numEventsAfter = getCount();
- logger.info("numEventsAfter={}", numEventsAfter);
-
- int diff = numEventsAfter - numEventsBefore;
- assertEquals(1, diff);
- }
-
- @Test
- public void testSerialization() throws Exception {
- InputStream is = new FileInputStream(new File(TEST_YAML));
- final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
-
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
- 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());
- 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);
- assertNotNull(clom);
-
- clom.startOperation(onsetEvent);
- assertTrue(clom.isOperationRunning());
-
- clom = Serializer.roundTrip(clom);
- assertNotNull(clom);
- assertTrue(clom.isOperationRunning());
-
- SoResponse soResponse = new SoResponse();
- 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");
-
- assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
- assertFalse(clom.isOperationRunning());
- assertEquals(1, clom.getHistory().size());
-
- clom = Serializer.roundTrip(clom);
- assertNotNull(clom);
- assertFalse(clom.isOperationRunning());
- assertEquals(1, clom.getHistory().size());
-
- System.setProperty(OPERATIONS_HISTORY_PU, OPERATIONS_HISTORY_PU_TEST);
- assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
-
- clom = Serializer.roundTrip(clom);
- assertNotNull(clom);
- assertFalse(clom.isOperationRunning());
- assertEquals(1, clom.getHistory().size());
- }
-}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockCallbackWorkingMemoryTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockCallbackWorkingMemoryTest.java
deleted file mode 100644
index 18ab15b5a..000000000
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockCallbackWorkingMemoryTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.eventmanager;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import org.drools.core.WorkingMemory;
-import org.junit.Before;
-import org.junit.Test;
-import org.kie.api.runtime.rule.FactHandle;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.onap.policy.drools.core.lock.Lock;
-
-public class LockCallbackWorkingMemoryTest {
- private static final String MY_NAME = "my-name";
-
- @Mock
- private WorkingMemory workingMemory;
-
- @Mock
- private Lock lock;
-
- @Mock
- private FactHandle fact;
-
- private LockCallbackWorkingMemory callback;
-
-
- /**
- * Initializes mocks and creates a call-back.
- */
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- when(workingMemory.getFactHandle(lock)).thenReturn(fact);
-
- callback = new LockCallbackWorkingMemory(MY_NAME, workingMemory);
- }
-
- @Test
- public void testLockCallbackWorkingMemory() {
- assertEquals(MY_NAME, callback.getName());
- assertSame(workingMemory, callback.getWorkingMemory());
- }
-
- @Test
- public void testLockAvailable() {
- callback.lockAvailable(lock);
- verify(workingMemory).update(fact, lock);
-
- // "remove" from working memory
- when(workingMemory.getFactHandle(lock)).thenReturn(null);
- callback.lockAvailable(lock);
-
- // should be no additional calls
- verify(workingMemory).update(any(), any());
- }
-
- @Test
- public void testLockUnavailable() {
- callback.lockUnavailable(lock);
- verify(workingMemory).update(fact, lock);
-
- // "remove" from working memory
- when(workingMemory.getFactHandle(lock)).thenReturn(null);
- callback.lockUnavailable(lock);
-
- // should be no additional calls
- verify(workingMemory).update(any(), any());
- }
-
-}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/drools/DroolsPolicyEngineTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/drools/DroolsPolicyEngineTest.java
deleted file mode 100644
index 3b61faaf2..000000000
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/drools/DroolsPolicyEngineTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * eventmanager
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-import org.onap.policy.appc.CommonHeader;
-import org.onap.policy.appc.Request;
-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.controlloop.ControlLoopNotification;
-import org.onap.policy.controlloop.VirtualControlLoopNotification;
-import org.onap.policy.drools.impl.PolicyEngineJUnitImpl;
-
-public class DroolsPolicyEngineTest {
- private static final String TOPIC = "TheWizardOfOz";
- private static final String OMNI_BUS = "OmniBus";
-
- @Test
- public void testDroolsPolicyEngine() {
- PolicyEngineJUnitImpl pe = new PolicyEngineJUnitImpl();
- assertNotNull(pe);
-
- pe.addListener(new TestPolicyEngineListener());
- pe.notifyListeners(TOPIC);
-
- pe.subscribe(OMNI_BUS, TOPIC);
-
- pe.deliver(OMNI_BUS, TOPIC, "Dorothy");
-
- pe.subscribe(OMNI_BUS, TOPIC);
- pe.subscribe(OMNI_BUS, "ThisTopicDoesNotExist");
-
- ControlLoopNotification notification = new VirtualControlLoopNotification();
- pe.deliver(OMNI_BUS, TOPIC, notification);
-
- Request request = new Request();
- request.setCommonHeader(new CommonHeader());
- request.getCommonHeader().setSubRequestId("12321");
- pe.deliver(OMNI_BUS, TOPIC, request);
-
- AppcLcmDmaapWrapper lcmRw = new AppcLcmDmaapWrapper();
- lcmRw.setBody(new AppcLcmBody());
- lcmRw.getBody().setInput(new AppcLcmInput());
- lcmRw.getBody().getInput().setCommonHeader(new AppcLcmCommonHeader());
- lcmRw.getBody().getInput().getCommonHeader().setSubRequestId("54321");
- pe.deliver(OMNI_BUS, TOPIC, lcmRw);
- }
-
- private class TestPolicyEngineListener implements PolicyEngineListener {
- @Override
- public void newEventNotification(String topic) {
- assertEquals(TOPIC, topic);
- }
- }
-}