aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/eventmanager/src')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java38
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java113
2 files changed, 112 insertions, 39 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 4b5d6c935..0d4aa938c 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
@@ -45,6 +45,7 @@ import org.onap.policy.guard.LockCallback;
import org.onap.policy.guard.PolicyGuard;
import org.onap.policy.guard.PolicyGuard.LockResult;
import org.onap.policy.guard.TargetLock;
+import org.onap.policy.drools.system.PolicyEngine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -73,6 +74,12 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
private transient TargetLock targetLock = null;
private static AAIGETVnfResponse vnfResponse = null;
private static AAIGETVserverResponse vserverResponse = null;
+ private static String aaiHostURL;
+ private static String aaiUser;
+ private static String aaiPassword;
+ private static String aaiGetQueryByVserver;
+ private static String aaiGetQueryByVnfID;
+ private static String aaiGetQueryByVnfName;
private static Collection<String> requiredAAIKeys = new ArrayList<>();
static {
@@ -615,16 +622,19 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
}
public static AAIGETVserverResponse getAAIVserverInfo(VirtualControlLoopEvent event) throws ControlLoopException {
- String user = "POLICY";
- String password = "POLICY";
UUID requestID = event.requestID;
AAIGETVserverResponse response = null;
String vserverName = event.AAI.get("vserver.vserver-name");
try {
if (vserverName != null) {
- String url = "https://aai-ext1.test.att.com:8443/aai/v11/nodes/vservers?vserver-name=";
- response = AAIManager.getQueryByVserverName(url, user, password, requestID, vserverName);
+ aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url");
+ aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.user");
+ aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
+ String aaiGetQueryByVserver = "/aai/v11/nodes/vservers?vserver-name=";
+ String url = aaiHostURL + aaiGetQueryByVserver;
+ logger.info("url: " + url);
+ response = AAIManager.getQueryByVserverName(url, aaiUser, aaiPassword, requestID, vserverName);
}
} catch (Exception e) {
logger.error("getAAIVserverInfo exception: ", e);
@@ -635,8 +645,6 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
}
public static AAIGETVnfResponse getAAIVnfInfo(VirtualControlLoopEvent event) throws ControlLoopException {
- String user = "POLICY";
- String password = "POLICY";
UUID requestID = event.requestID;
AAIGETVnfResponse response = null;
String vnfName = event.AAI.get("generic-vnf.vnf-name");
@@ -644,11 +652,21 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
try {
if (vnfName != null) {
- String url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=";
- response = AAIManager.getQueryByVnfName(url, user, password, requestID, vnfName);
+ aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url");
+ aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.user");
+ aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
+ String aaiGetQueryByVnfName = "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=";
+ String url = aaiHostURL + aaiGetQueryByVnfName;
+ logger.info("url: " + url);
+ response = AAIManager.getQueryByVnfName(url, aaiUser, aaiPassword, requestID, vnfName);
} else if (vnfID != null) {
- String url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf/";
- response = AAIManager.getQueryByVnfID(url, user, password, requestID, vnfID);
+ aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url");
+ aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.user");
+ aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
+ String aaiGetQueryByVnfID = "/aai/v11/network/generic-vnfs/generic-vnf/";
+ String url = aaiHostURL + aaiGetQueryByVnfID;
+ logger.info("url: " + url);
+ response = AAIManager.getQueryByVnfID(url, aaiUser, aaiPassword, requestID, vnfID);
}
} catch (Exception e) {
logger.error("getAAIVnfInfo exception: ", e);
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 2e208748f..745841049 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
@@ -27,6 +27,8 @@ import java.time.Instant;
import java.util.HashMap;
import java.util.UUID;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.aai.AAIGETVnfResponse;
import org.onap.policy.aai.AAIGETVserverResponse;
@@ -40,6 +42,8 @@ import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.Util;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
+import org.onap.policy.drools.http.server.HttpServletServer;
+import org.onap.policy.drools.system.PolicyEngine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,27 +64,79 @@ public class ControlLoopEventManagerTest {
onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
}
+ @BeforeClass
+ public static void setUpSimulator() {
+ try {
+ org.onap.policy.simulators.Util.buildAaiSim();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @AfterClass
+ public static void tearDownSimulator() {
+ HttpServletServer.factory.destroy();
+ }
+
+ @Test
+ public void testAAIVnfInfo() {
+ final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml");
+ onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
+ try {
+ 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.password"),
+ UUID.randomUUID(), "5e49ca06-2972-4532-9ed4-6d071588d792");
+ assertNotNull(response);
+ logger.info("testAAIVnfInfo test result is " + (response == null ? "null" : "not null"));
+ } catch (Exception e) {
+ logger.error("testAAIVnfInfo Exception: ", e);
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testAAIVnfInfo2() {
+ 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.password"),
+ UUID.randomUUID(), "lll_vnf_010317");
+ assertNotNull(response);
+ logger.info("testAAIVnfInfo2 test result is " + (response == null ? "null" : "not null"));
+ } catch (Exception e) {
+ logger.error("testAAIVnfInfo2 Exception: ", e);
+ fail(e.getMessage());
+ }
+ }
+
@Test
- public void testGetAAIInfo() {
+ public void testAAIVserver() {
final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml");
onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
try {
- @SuppressWarnings("unused")
- ControlLoopEventManager eventManager = new ControlLoopEventManager(onset.closedLoopControlName, onset.requestID);
- onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
-
- String user = "POLICY";
- String password = "POLICY";
- String vnfID = "83f674e8-7555-44d7-9a39-bdc3770b0491";
- String url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf/";
- AAIGETVnfResponse response = getQueryByVnfID2(url, user, password, onset.requestID, vnfID);
+ setAAIProperties();
+ AAIGETVserverResponse response = getQueryByVserverName2(PolicyEngine.manager.getEnvironmentProperty("aai.url") + "/aai/v11/nodes/vservers?vserver-name=",
+ PolicyEngine.manager.getEnvironmentProperty("aai.user"),
+ PolicyEngine.manager.getEnvironmentProperty("aai.password"),
+ UUID.randomUUID(), "USMSO1SX7NJ0103UJZZ01-vjunos0");
assertNotNull(response);
- logger.info("testGetAAIInfo test result is " + (response == null ? "null" : "not null"));
+ logger.info("testAAIVserver test result is " + (response == null ? "null" : "not null"));
} catch (Exception e) {
+ logger.error("testAAIVserver Exception: ", e);
fail(e.getMessage());
- logger.error("testGetAAIInfo Exception: ", e);
}
}
+
+ 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() {
@@ -91,31 +147,30 @@ public class ControlLoopEventManagerTest {
onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
try {
- onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
-
logger.info("testIsClosedLoopDisabled --");
- String user = "POLICY";
- String password = "POLICY";
- String vnfID = "83f674e8-7555-44d7-9a39-bdc3770b0491";
- String url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf/";
- AAIGETVnfResponse response = getQueryByVnfID2(url, user, password, onset.requestID, vnfID);
+ 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.password"),
+ UUID.randomUUID(), "5e49ca06-2972-4532-9ed4-6d071588d792");
assertNotNull(response);
boolean disabled = ControlLoopEventManager.isClosedLoopDisabled(response);
logger.info("QueryByVnfID - isClosedLoopDisabled: " + disabled);
- String vnfName = "lll_vnf_010317";
- url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=";
- response = getQueryByVnfName2(url, user, password, onset.requestID, vnfName);
+ 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.password"),
+ UUID.randomUUID(), "lll_vnf_010317");
assertNotNull(response);
disabled = ControlLoopEventManager.isClosedLoopDisabled(response);
- logger.info("QueryByVnfName2 - isClosedLoopDisabled: " + disabled);
+ logger.info("QueryByVnfName - isClosedLoopDisabled: " + disabled);
- String vserverName = "USMSO1SX7NJ0103UJZZ01-vjunos0";
- url = "https://aai-ext1.test.att.com:8443//aai/v11/nodes/vservers?vserver-name=";
- @SuppressWarnings("unused")
- AAIGETVserverResponse response2 = getQueryByVserverName2(url, user, password, onset.requestID, vserverName);
- assertNotNull(response);
- disabled = ControlLoopEventManager.isClosedLoopDisabled(response);
+ AAIGETVserverResponse response2 = getQueryByVserverName2(PolicyEngine.manager.getEnvironmentProperty("aai.url") + "/aai/v11/nodes/vservers?vserver-name=",
+ PolicyEngine.manager.getEnvironmentProperty("aai.user"),
+ PolicyEngine.manager.getEnvironmentProperty("aai.password"),
+ UUID.randomUUID(), "USMSO1SX7NJ0103UJZZ01-vjunos0");
+ assertNotNull(response2);
+ disabled = ControlLoopEventManager.isClosedLoopDisabled(response2);
logger.info("QueryByVserverName - isClosedLoopDisabled: " + disabled);
} catch (Exception e) {
fail(e.getMessage());