summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2017-10-25 17:25:05 +0000
committerGerrit Code Review <gerrit@onap.org>2017-10-25 17:25:05 +0000
commita1a5073f6e0cdec19addc5fdec474a5a3758adb3 (patch)
tree184e8e8c0ac2297eaf476d6c8e673e3e37481e60 /controlloop/common/eventmanager/src
parent301a15cc38493f1166075ec80f1c88de5abd0373 (diff)
parent350d7fd09b5be5c8eff381693f5fd1d21beec4b8 (diff)
Merge "Ensure no AAI lookup on subsequent onset"
Diffstat (limited to 'controlloop/common/eventmanager/src')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java23
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java42
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java25
3 files changed, 67 insertions, 23 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
index 2a5a3d0a9..d320b75ee 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
@@ -149,6 +149,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
// Syntax check the event
//
checkEventSyntax(event);
+ checkEventAAISyntax(event);
//
// At this point we are good to go with this event
//
@@ -183,6 +184,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
// Syntax check the event
//
checkEventSyntax(event);
+ checkEventAAISyntax(event);
//
// Check the YAML
@@ -535,6 +537,18 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (event.closedLoopEventStatus == ControlLoopEventStatus.ABATED) {
return;
}
+ if (event.target == null || event.target.length() < 1) {
+ throw new ControlLoopException("No target field");
+ } else if (! "VM_NAME".equalsIgnoreCase(event.target) &&
+ ! "VNF_NAME".equalsIgnoreCase(event.target) &&
+ ! "vserver.vserver-name".equalsIgnoreCase(event.target) &&
+ ! "generic-vnf.vnf-id".equalsIgnoreCase(event.target) &&
+ ! "generic-vnf.vnf-name".equalsIgnoreCase(event.target) ) {
+ throw new ControlLoopException("target field invalid - expecting VM_NAME or VNF_NAME");
+ }
+ }
+
+ public void checkEventAAISyntax(VirtualControlLoopEvent event) throws ControlLoopException {
if (event.AAI == null) {
throw new ControlLoopException("AAI is null");
}
@@ -585,15 +599,6 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
} else if (isClosedLoopDisabled(event)) {
throw new ControlLoopException("is-closed-loop-disabled is set to true");
}
- if (event.target == null || event.target.length() < 1) {
- throw new ControlLoopException("No target field");
- } else if (! event.target.equalsIgnoreCase("VM_NAME") &&
- ! event.target.equalsIgnoreCase("VNF_NAME") &&
- ! event.target.equalsIgnoreCase("vserver.vserver-name") &&
- ! event.target.equalsIgnoreCase("generic-vnf.vnf-id") &&
- ! event.target.equalsIgnoreCase("generic-vnf.vnf-name") ) {
- throw new ControlLoopException("target field invalid - expecting VM_NAME or VNF_NAME");
- }
}
public static boolean isClosedLoopDisabled(AAIGETVnfResponse aaiResponse) {
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
index e723552e8..223361505 100644
--- 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
@@ -20,6 +20,7 @@
package org.onap.policy.controlloop.eventmanager;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
@@ -41,8 +42,10 @@ import org.onap.policy.aai.RelationshipDataItem;
import org.onap.policy.aai.RelationshipList;
import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.ControlLoopException;
+import org.onap.policy.controlloop.ControlLoopNotificationType;
import org.onap.policy.controlloop.Util;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.VirtualControlLoopNotification;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.drools.http.server.HttpServletServer;
import org.onap.policy.drools.system.PolicyEngine;
@@ -207,6 +210,45 @@ public class ControlLoopEventManagerTest {
assertNull(manager.getVserverResponse());
}
+ @Test
+ public void subsequentOnsetTest() {
+ UUID requestId = UUID.randomUUID();
+ VirtualControlLoopEvent event = new VirtualControlLoopEvent();
+ event.closedLoopControlName = "TwoOnsetTest";
+ event.requestID = requestId;
+ event.target = "generic-vnf.vnf-id";
+ event.closedLoopAlarmStart = Instant.now();
+ event.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
+ event.AAI = new HashMap<>();
+ event.AAI.put("generic-vnf.vnf-name", "onsetOne");
+
+ ControlLoopEventManager manager = new ControlLoopEventManager(event.closedLoopControlName, event.requestID);
+ VirtualControlLoopNotification notification = manager.activate(event);
+
+ assertNotNull(notification);
+ assertEquals(ControlLoopNotificationType.ACTIVE, notification.notification);
+ AAIGETVnfResponse response = manager.getVnfResponse();
+ assertNotNull(response);
+ assertNull(manager.getVserverResponse());
+
+ VirtualControlLoopEvent event2 = new VirtualControlLoopEvent();
+ event2.closedLoopControlName = "TwoOnsetTest";
+ event2.requestID = requestId;
+ event2.target = "generic-vnf.vnf-id";
+ event2.closedLoopAlarmStart = Instant.now();
+ event2.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
+ event2.AAI = new HashMap<>();
+ event2.AAI.put("generic-vnf.vnf-name", "onsetTwo");
+
+ ControlLoopEventManager.NEW_EVENT_STATUS status = manager.onNewEvent(event2);
+ assertEquals(ControlLoopEventManager.NEW_EVENT_STATUS.SUBSEQUENT_ONSET, status);
+ AAIGETVnfResponse response2 = manager.getVnfResponse();
+ assertNotNull(response2);
+ // We should not have queried AAI, so the stored response should be the same
+ assertEquals(response, response2);
+ assertNull(manager.getVserverResponse());
+ }
+
// Simulate a response
public static AAIGETVnfResponse getQueryByVnfID2(String urlGet, String username, String password, UUID requestID, String key) {
AAIGETVnfResponse response = new AAIGETVnfResponse();
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 d41d8bf57..e7a31190e 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
@@ -20,6 +20,7 @@
package org.onap.policy.controlloop.eventmanager;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -38,10 +39,12 @@ import org.onap.policy.appclcm.LCMRequestWrapper;
import org.onap.policy.appclcm.LCMResponse;
import org.onap.policy.appclcm.LCMResponseWrapper;
import org.onap.policy.controlloop.ControlLoopEventStatus;
+import org.onap.policy.controlloop.ControlLoopNotificationType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.Util;
+import org.onap.policy.controlloop.VirtualControlLoopNotification;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.controlloop.processor.ControlLoopProcessor;
@@ -99,13 +102,10 @@ public class ControlLoopOperationManagerTest {
// create the manager
//
ControlLoopEventManager eventManager = new ControlLoopEventManager(onset.closedLoopControlName, onset.requestID);
- try {
- eventManager.checkEventSyntax(onset);
- }
- catch (ControlLoopException e) {
- logger.warn(e.toString());
- fail("The onset failed the syntax check");
- }
+ VirtualControlLoopNotification notification = eventManager.activate(onset);
+
+ assertNotNull(notification);
+ assertEquals(ControlLoopNotificationType.ACTIVE, notification.notification);
ControlLoopOperationManager manager = new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager);
logger.debug("{}",manager);
@@ -221,13 +221,10 @@ public class ControlLoopOperationManagerTest {
// create the manager
//
ControlLoopEventManager eventManager = new ControlLoopEventManager(onset.closedLoopControlName, onset.requestID);
- try {
- eventManager.checkEventSyntax(onset);
- }
- catch (ControlLoopException e) {
- logger.warn(e.toString());
- fail("The onset failed the syntax check");
- }
+ VirtualControlLoopNotification notification = eventManager.activate(onset);
+
+ assertNotNull(notification);
+ assertEquals(ControlLoopNotificationType.ACTIVE, notification.notification);
ControlLoopOperationManager manager = new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager);
//