summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager
diff options
context:
space:
mode:
authorCharles Cole <cc847m@att.com>2017-10-24 09:31:03 -0500
committerCharles Cole <cc847m@att.com>2017-10-24 10:02:35 -0500
commitbaea880ddf0564d81d61bf87ae7f124229bf08f0 (patch)
tree39e77eecf6a376a4ae9c0fece9f7d6625351369f /controlloop/common/eventmanager
parentd0bbf403e259c97cd174fd3deebcb6ab5796cc61 (diff)
Ensure no AAI lookup on abatements
Changed check event syntax in the event manager so that it only looks for AAI info if the event is an onset. Issue-Id: POLICY-368 Change-Id: I241e9a110cc5fc4553a5e9cd842d51f76a800368 Signed-off-by: Charles Cole <cc847m@att.com>
Diffstat (limited to 'controlloop/common/eventmanager')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java67
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java62
2 files changed, 80 insertions, 49 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 9b2960e42..91db147c8 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
@@ -531,48 +531,51 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (event.requestID == null) {
throw new ControlLoopException("No request ID");
}
+ if (event.closedLoopEventStatus == ControlLoopEventStatus.ABATED) {
+ return;
+ }
if (event.AAI == null) {
throw new ControlLoopException("AAI is null");
}
if (event.AAI.get("generic-vnf.vnf-id") == null && event.AAI.get("vserver.vserver-name") == null &&
- event.AAI.get("generic-vnf.vnf-name") == null) {
+ event.AAI.get("generic-vnf.vnf-name") == null) {
throw new ControlLoopException("generic-vnf.vnf-id or generic-vnf.vnf-name or vserver.vserver-name information missing");
}
if (event.AAI.get("vserver.is-closed-loop-disabled") == null) {
try {
if (event.AAI.get("generic-vnf.vnf-id") != null) {
- vnfResponse = getAAIVnfInfo(event);
- if (vnfResponse == null) {
- throw new ControlLoopException("AAI Response is null (query by vnf-id)");
- }
- if (vnfResponse.requestError != null) {
- throw new ControlLoopException("AAI Responded with a request error (query by vnf-id)");
- }
- if (isClosedLoopDisabled(vnfResponse) == true) {
- throw new ControlLoopException("is-closed-loop-disabled is set to true");
- }
+ vnfResponse = getAAIVnfInfo(event);
+ if (vnfResponse == null) {
+ throw new ControlLoopException("AAI Response is null (query by vnf-id)");
+ }
+ if (vnfResponse.requestError != null) {
+ throw new ControlLoopException("AAI Responded with a request error (query by vnf-id)");
+ }
+ if (isClosedLoopDisabled(vnfResponse) == true) {
+ throw new ControlLoopException("is-closed-loop-disabled is set to true");
+ }
} else if (event.AAI.get("generic-vnf.vnf-name") != null) {
- vnfResponse = getAAIVnfInfo(event);
- if (vnfResponse == null) {
- throw new ControlLoopException("AAI Response is null (query by vnf-name)");
- }
- if (vnfResponse.requestError != null) {
- throw new ControlLoopException("AAI Responded with a request error (query by vnf-name)");
- }
- if (isClosedLoopDisabled(vnfResponse) == true) {
+ vnfResponse = getAAIVnfInfo(event);
+ if (vnfResponse == null) {
+ throw new ControlLoopException("AAI Response is null (query by vnf-name)");
+ }
+ if (vnfResponse.requestError != null) {
+ throw new ControlLoopException("AAI Responded with a request error (query by vnf-name)");
+ }
+ if (isClosedLoopDisabled(vnfResponse) == true) {
throw new ControlLoopException("is-closed-loop-disabled is set to true");
- }
+ }
} else if (event.AAI.get("vserver.vserver-name") != null) {
- vserverResponse = getAAIVserverInfo(event);
- if (vserverResponse == null) {
- throw new ControlLoopException("AAI Response is null (query by vserver-name)");
- }
- if (vserverResponse.requestError != null) {
- throw new ControlLoopException("AAI responded with a request error (query by vserver-name)");
- }
- if (isClosedLoopDisabled(vserverResponse) == true) {
+ vserverResponse = getAAIVserverInfo(event);
+ if (vserverResponse == null) {
+ throw new ControlLoopException("AAI Response is null (query by vserver-name)");
+ }
+ if (vserverResponse.requestError != null) {
+ throw new ControlLoopException("AAI responded with a request error (query by vserver-name)");
+ }
+ if (isClosedLoopDisabled(vserverResponse) == true) {
throw new ControlLoopException("is-closed-loop-disabled is set to true");
- }
+ }
}
} catch (Exception e) {
logger.error("Exception from getAAIInfo: ", e);
@@ -583,14 +586,12 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
}
if (event.target == null || event.target.length() < 1) {
throw new ControlLoopException("No target field");
- } else {
- if (! event.target.equalsIgnoreCase("VM_NAME") &&
+ } 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");
- }
+ throw new ControlLoopException("target field invalid - expecting VM_NAME or VNF_NAME");
}
}
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 745841049..e723552e8 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
@@ -21,6 +21,7 @@
package org.onap.policy.controlloop.eventmanager;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.time.Instant;
@@ -39,6 +40,7 @@ import org.onap.policy.aai.RelationshipData;
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.Util;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
@@ -71,6 +73,9 @@ public class ControlLoopEventManagerTest {
} catch (Exception e) {
fail(e.getMessage());
}
+ PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
+ PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
+ PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
}
@AfterClass
@@ -82,10 +87,9 @@ public class ControlLoopEventManagerTest {
public void testAAIVnfInfo() {
final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml");
onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
- try {
- setAAIProperties();
+ try {
AAIGETVnfResponse response = getQueryByVnfID2(PolicyEngine.manager.getEnvironmentProperty("aai.url") + "/aai/v11/network/generic-vnfs/generic-vnf/",
- PolicyEngine.manager.getEnvironmentProperty("aai.user"),
+ PolicyEngine.manager.getEnvironmentProperty("aai.username"),
PolicyEngine.manager.getEnvironmentProperty("aai.password"),
UUID.randomUUID(), "5e49ca06-2972-4532-9ed4-6d071588d792");
assertNotNull(response);
@@ -101,9 +105,8 @@ public class ControlLoopEventManagerTest {
final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml");
onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
try {
- setAAIProperties();
AAIGETVnfResponse response = getQueryByVnfName2(PolicyEngine.manager.getEnvironmentProperty("aai.url") + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=",
- PolicyEngine.manager.getEnvironmentProperty("aai.user"),
+ PolicyEngine.manager.getEnvironmentProperty("aai.username"),
PolicyEngine.manager.getEnvironmentProperty("aai.password"),
UUID.randomUUID(), "lll_vnf_010317");
assertNotNull(response);
@@ -119,9 +122,8 @@ public class ControlLoopEventManagerTest {
final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml");
onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
try {
- setAAIProperties();
AAIGETVserverResponse response = getQueryByVserverName2(PolicyEngine.manager.getEnvironmentProperty("aai.url") + "/aai/v11/nodes/vservers?vserver-name=",
- PolicyEngine.manager.getEnvironmentProperty("aai.user"),
+ PolicyEngine.manager.getEnvironmentProperty("aai.username"),
PolicyEngine.manager.getEnvironmentProperty("aai.password"),
UUID.randomUUID(), "USMSO1SX7NJ0103UJZZ01-vjunos0");
assertNotNull(response);
@@ -131,12 +133,6 @@ public class ControlLoopEventManagerTest {
fail(e.getMessage());
}
}
-
- private void setAAIProperties() {
- PolicyEngine.manager.setEnvironmentProperty("aai.user", "AAI");
- PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
- PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
- }
@Test
public void testIsClosedLoopDisabled() {
@@ -148,9 +144,8 @@ public class ControlLoopEventManagerTest {
try {
logger.info("testIsClosedLoopDisabled --");
- setAAIProperties();
AAIGETVnfResponse response = getQueryByVnfID2(PolicyEngine.manager.getEnvironmentProperty("aai.url") + "/aai/v11/network/generic-vnfs/generic-vnf/",
- PolicyEngine.manager.getEnvironmentProperty("aai.user"),
+ PolicyEngine.manager.getEnvironmentProperty("aai.username"),
PolicyEngine.manager.getEnvironmentProperty("aai.password"),
UUID.randomUUID(), "5e49ca06-2972-4532-9ed4-6d071588d792");
assertNotNull(response);
@@ -158,7 +153,7 @@ public class ControlLoopEventManagerTest {
logger.info("QueryByVnfID - isClosedLoopDisabled: " + disabled);
response = getQueryByVnfName2(PolicyEngine.manager.getEnvironmentProperty("aai.url") + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=",
- PolicyEngine.manager.getEnvironmentProperty("aai.user"),
+ PolicyEngine.manager.getEnvironmentProperty("aai.username"),
PolicyEngine.manager.getEnvironmentProperty("aai.password"),
UUID.randomUUID(), "lll_vnf_010317");
assertNotNull(response);
@@ -177,6 +172,41 @@ public class ControlLoopEventManagerTest {
}
}
+ @Test
+ public void abatemetCheckEventSyntaxTest() {
+ VirtualControlLoopEvent event = new VirtualControlLoopEvent();
+ event.closedLoopControlName = "abatementAAI";
+ event.requestID = UUID.randomUUID();
+ event.target = "generic-vnf.vnf-id";
+ event.closedLoopAlarmStart = Instant.now();
+ event.closedLoopEventStatus = ControlLoopEventStatus.ABATED;
+ ControlLoopEventManager manager = new ControlLoopEventManager(event.closedLoopControlName, event.requestID);
+ assertNull(manager.getVnfResponse());
+ assertNull(manager.getVserverResponse());
+ try {
+ manager.checkEventSyntax(event);
+ } catch (ControlLoopException e) {
+ logger.debug("ControlLoopException in abatemetCheckEventSyntaxTest: "+e.getMessage());
+ e.printStackTrace();
+ fail("Exception in check event syntax");
+ }
+ assertNull(manager.getVnfResponse());
+ assertNull(manager.getVserverResponse());
+
+
+ event.AAI = new HashMap<>();
+ event.AAI.put("generic-vnf.vnf-name", "abatementTest");
+ try {
+ manager.checkEventSyntax(event);
+ } catch (ControlLoopException e) {
+ logger.debug("ControlLoopException in abatemetCheckEventSyntaxTest: "+e.getMessage());
+ e.printStackTrace();
+ fail("Exception in check event syntax");
+ }
+ assertNull(manager.getVnfResponse());
+ assertNull(manager.getVserverResponse());
+ }
+
// Simulate a response
public static AAIGETVnfResponse getQueryByVnfID2(String urlGet, String username, String password, UUID requestID, String key) {
AAIGETVnfResponse response = new AAIGETVnfResponse();