summaryrefslogtreecommitdiffstats
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.java138
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java251
2 files changed, 379 insertions, 10 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 b61eabc4b..bc7f3c32d 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
@@ -26,7 +26,11 @@ import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
+import java.util.List;
import java.util.UUID;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Iterator;
import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.ControlLoopNotificationType;
@@ -45,6 +49,13 @@ import org.onap.policy.guard.TargetLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.onap.policy.aai.AAIManager;
+import org.onap.policy.aai.AAIGETVserverResponse;
+import org.onap.policy.aai.AAIGETVnfResponse;
+import org.onap.policy.aai.RelatedToPropertyItem;
+import org.onap.policy.aai.RelationshipList;
+import org.onap.policy.aai.Relationship;
+
public class ControlLoopEventManager implements LockCallback, Serializable {
/**
@@ -68,6 +79,8 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<>();
private ControlLoopOperationManager currentOperation = null;
private TargetLock targetLock = null;
+ private static AAIGETVnfResponse vnfResponse = null;
+ private static AAIGETVserverResponse vserverResponse = null;
private static Collection<String> requiredAAIKeys = new ArrayList<>();
static {
@@ -501,6 +514,14 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
return 0;
}
+ public AAIGETVnfResponse getVnfResponse() {
+ return vnfResponse;
+ }
+
+ public AAIGETVserverResponse getVserverResponse() {
+ return vserverResponse;
+ }
+
public static void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException {
if (event.closedLoopEventStatus == null ||
(event.closedLoopEventStatus != ControlLoopEventStatus.ONSET &&
@@ -516,14 +537,34 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (event.AAI == null) {
throw new ControlLoopException("AAI is null");
}
- if (event.AAI.get("vserver.is-closed-loop-disabled") == null) {
- throw new ControlLoopException("vserver.is-closed-loop-disabled information missing");
+ if (event.AAI.get("generic-vnf.vnf-id") == null && event.AAI.get("vserver.vserver-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").equalsIgnoreCase("true") ||
- event.AAI.get("vserver.is-closed-loop-disabled").equalsIgnoreCase("T") ||
- event.AAI.get("vserver.is-closed-loop-disabled").equalsIgnoreCase("yes") ||
- event.AAI.get("vserver.is-closed-loop-disabled").equalsIgnoreCase("Y")) {
- throw new ControlLoopException("vserver.is-closed-loop-disabled is set to true");
+ 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 && 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 && 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 && isClosedLoopDisabled(vserverResponse) == true) {
+ throw new ControlLoopException("is-closed-loop-disabled is set to true");
+ }
+ }
+ } catch (Exception e) {
+ logger.error("Exception from getAAIInfo: ", e);
+ throw new ControlLoopException("Exception from getAAIInfo: " + e.toString());
+ }
+ } 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");
@@ -536,7 +577,90 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
}
}
}
+
+ public static boolean isClosedLoopDisabled(AAIGETVnfResponse aaiResponse) {
+ RelationshipList relationshipList = new RelationshipList();
+ if (aaiResponse != null && aaiResponse.isClosedLoopDisabled != null) {
+ String value = aaiResponse.isClosedLoopDisabled;
+ if ("true".equalsIgnoreCase(value) || "T".equalsIgnoreCase(value) ||
+ "yes".equalsIgnoreCase(value) || "Y".equalsIgnoreCase(value)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static boolean isClosedLoopDisabled(AAIGETVserverResponse aaiResponse) {
+ RelationshipList relationshipList = new RelationshipList();
+ if (aaiResponse != null && aaiResponse.isClosedLoopDisabled != null) {
+ String value = aaiResponse.isClosedLoopDisabled;
+ if ("true".equalsIgnoreCase(value) || "T".equalsIgnoreCase(value) ||
+ "yes".equalsIgnoreCase(value) || "Y".equalsIgnoreCase(value)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static boolean isClosedLoopDisabled(VirtualControlLoopEvent event) {
+ if ("true".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled")) ||
+ "T".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled")) ||
+ "yes".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled")) ||
+ "Y".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled"))) {
+ return true;
+ }
+ return false;
+ }
+
+ 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) {
+ AAIManager manager = new AAIManager();
+ String url = "https://aai-ext1.test.att.com:8443/aai/v11/nodes/vservers?vserver-name=";
+ response = manager.getQueryByVserverName(url, user, password, requestID, vserverName);
+ }
+ } catch (Exception e) {
+ logger.error("getAAIVserverInfo exception: ", e);
+ throw new ControlLoopException("Exception in getAAIVserverInfo: ", e);
+ }
+
+ return response;
+ }
+
+ 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");
+ String vnfID = event.AAI.get("generic-vnf.vnf-id");
+
+ try {
+ if (vnfName != null) {
+ AAIManager manager = new AAIManager();
+ String url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=";
+ response = manager.getQueryByVnfName(url, user, password, requestID, vnfName);
+ } else if (vnfID != null) {
+ AAIManager manager = new AAIManager();
+ String url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf/";
+ response = manager.getQueryByVnfID(url, user, password, requestID, vnfID);
+ }
+ } catch (Exception e) {
+ logger.error("getAAIVnfInfo exception: ", e);
+ throw new ControlLoopException("Exception in getAAIVnfInfo: ", e);
+ }
+
+ return response;
+ }
+
@Override
public boolean isActive() {
// TODO
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 fa52e8557..ef7a1a94c 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,14 +20,259 @@
package org.onap.policy.controlloop.eventmanager;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.time.Instant;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
import org.junit.Test;
+import org.onap.policy.aai.AAIGETVserverResponse;
+import org.onap.policy.aai.AAIGETVnfResponse;
+import org.onap.policy.aai.RelatedToPropertyItem;
+import org.onap.policy.aai.Relationship;
+import org.onap.policy.aai.RelationshipData;
+import org.onap.policy.aai.RelationshipDataItem;
+import org.onap.policy.aai.RelationshipList;
+import org.onap.policy.aai.AAIManager;
+import org.onap.policy.aai.RelatedToProperty;
+import org.onap.policy.appc.Request;
+import org.onap.policy.appc.Response;
+import org.onap.policy.appc.ResponseCode;
+import org.onap.policy.appc.ResponseValue;
+import org.onap.policy.controlloop.ControlLoopEventStatus;
+
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.ControlLoopException;
+import org.onap.policy.controlloop.Util;
+import org.onap.policy.controlloop.policy.ControlLoopPolicy;
+import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.controlloop.processor.ControlLoopProcessor;
+import org.onap.policy.controlloop.processor.ControlLoopProcessorTest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ControlLoopEventManagerTest {
+ private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManagerTest.class);
+
+ private static VirtualControlLoopEvent onset;
+ static {
+ onset = new VirtualControlLoopEvent();
+ onset.closedLoopControlName = "ControlLoop-vUSP";
+ onset.requestID = UUID.randomUUID();
+ onset.target = "VM_NAME";
+ onset.closedLoopAlarmStart = Instant.now();
+ onset.AAI = new HashMap<String, String>();
+ onset.AAI.put("cloud-region.identity-url", "foo");
+ onset.AAI.put("vserver.selflink", "bar");
+ onset.AAI.put("generic-vnf.vnf-id", "83f674e8-7555-44d7-9a39-bdc3770b0491");
+ onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
+ }
+
+ @Test
+ public void testGetAAIInfo() {
+ final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml");
+ onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
+ try {
+ 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);
+ assertNotNull(response);
+ logger.info("testGetAAIInfo test result is " + (response == null ? "null" : "not null"));
+ } catch (Exception e) {
+ fail(e.getMessage());
+ logger.error("testGetAAIInfo Exception: ", e);
+ }
+ }
@Test
- public void test() {
- //fail("MICHAEL - Not yet implemented");
+ public void testIsClosedLoopDisabled() {
+ //
+ // Load up the policy
+ //
+ final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml");
+ onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
+
+ try {
+ ControlLoopEventManager eventManager = new ControlLoopEventManager(onset.closedLoopControlName, onset.requestID);
+ onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
+
+ logger.info("testIsClosedLoopDisabled --");
+ AAIManager manager = new AAIManager();
+ 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);
+ assertNotNull(response);
+ boolean disabled = eventManager.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);
+ assertNotNull(response);
+ disabled = eventManager.isClosedLoopDisabled(response);
+ logger.info("QueryByVnfName2 - isClosedLoopDisabled: " + disabled);
+
+ String vserverName = "USMSO1SX7NJ0103UJZZ01-vjunos0";
+ url = "https://aai-ext1.test.att.com:8443//aai/v11/nodes/vservers?vserver-name=";
+ AAIGETVserverResponse response2 = getQueryByVserverName2(url, user, password, onset.requestID, vserverName);
+ assertNotNull(response);
+ disabled = eventManager.isClosedLoopDisabled(response);
+ logger.info("QueryByVserverName - isClosedLoopDisabled: " + disabled);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ // Simulate a response
+ public static AAIGETVnfResponse getQueryByVnfID2(String urlGet, String username, String password, UUID requestID, String key) {
+ AAIGETVnfResponse response = new AAIGETVnfResponse();
+
+ response.vnfID = "83f674e8-7555-44d7-9a39-bdc3770b0491";
+ response.vnfName = "lll_vnf_010317";
+ response.vnfType = "Basa-122216-Service/VidVsamp12BaseVolume 1";
+ response.serviceId = "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb";
+ response.orchestrationStatus = "Created";
+ response.inMaint = "false";
+ response.isClosedLoopDisabled = "false";
+ response.resourceVersion = "1494001988835";
+ response.modelInvariantId = "f18be3cd-d446-456e-9109-121d9b62feaa";
+
+ RelationshipList relationshipList = new RelationshipList();
+ Relationship relationship = new Relationship();
+ RelationshipData relationshipData = new RelationshipData();
+ RelationshipDataItem relationshipDataItem = new RelationshipDataItem();
+
+ relationshipDataItem.relationshipKey = "customer.global-customer-id";
+ relationshipDataItem.relationshipValue = "MSO_1610_ST";
+ relationshipData.relationshipData.add(relationshipDataItem);
+
+ relationshipDataItem.relationshipKey = "service-subscription.service-type";
+ relationshipDataItem.relationshipValue = "MSO-dev-service-type";
+ relationshipData.relationshipData.add(relationshipDataItem);
+
+ relationshipDataItem.relationshipKey = "service-instance.service-instance-id";
+ relationshipDataItem.relationshipValue = "e1e9c97c-02c0-4919-9b4c-eb5d5ef68970";
+ relationshipData.relationshipData.add(relationshipDataItem);
+
+ RelatedToProperty relatedToProperty = new RelatedToProperty();
+ RelatedToPropertyItem item = new RelatedToPropertyItem();
+ item.propertyKey = "service-instance.service-instance-name";
+ item.propertyValue = "lll_svc_010317";
+ relatedToProperty.relatedTo.add(item);
+
+ relationship.relatedTo = "service-instance";
+ relationship.relatedLink = "/aai/v11/business/customers/customer/MSO_1610_ST/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/e1e9c97c-02c0-4919-9b4c-eb5d5ef68970";
+ relationship.relationshipData = relationshipData;
+ relationship.relatedToProperty = relatedToProperty;
+
+ relationshipList.relationshipList.add(relationship);
+ response.relationshipList = relationshipList;
+
+ return response;
+ }
+
+ public static AAIGETVnfResponse getQueryByVnfName2(String urlGet, String username, String password, UUID requestID, String key) {
+ AAIGETVnfResponse response = new AAIGETVnfResponse();
+
+ response.vnfID = "83f674e8-7555-44d7-9a39-bdc3770b0491";
+ response.vnfName = "lll_vnf_010317";
+ response.vnfType = "Basa-122216-Service/VidVsamp12BaseVolume 1";
+ response.serviceId = "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb";
+ response.orchestrationStatus = "Created";
+ response.inMaint = "false";
+ response.isClosedLoopDisabled = "false";
+ response.resourceVersion = "1494001988835";
+ response.modelInvariantId = "f18be3cd-d446-456e-9109-121d9b62feaa";
+
+ RelationshipList relationshipList = new RelationshipList();
+ Relationship relationship = new Relationship();
+ RelationshipData relationshipData = new RelationshipData();
+ RelationshipDataItem relationshipDataItem = new RelationshipDataItem();
+
+ relationshipDataItem.relationshipKey = "customer.global-customer-id";
+ relationshipDataItem.relationshipValue = "MSO_1610_ST";
+ relationshipData.relationshipData.add(relationshipDataItem);
+
+ relationshipDataItem.relationshipKey = "service-subscription.service-type";
+ relationshipDataItem.relationshipValue = "MSO-dev-service-type";
+ relationshipData.relationshipData.add(relationshipDataItem);
+
+ relationshipDataItem.relationshipKey = "service-instance.service-instance-id";
+ relationshipDataItem.relationshipValue = "e1e9c97c-02c0-4919-9b4c-eb5d5ef68970";
+ relationshipData.relationshipData.add(relationshipDataItem);
+
+ RelatedToProperty relatedToProperty = new RelatedToProperty();
+ RelatedToPropertyItem item = new RelatedToPropertyItem();
+ item.propertyKey = "service-instance.service-instance-name";
+ item.propertyValue = "lll_svc_010317";
+ relatedToProperty.relatedTo.add(item);
+
+ relationship.relatedTo = "service-instance";
+ relationship.relatedLink = "/aai/v11/business/customers/customer/MSO_1610_ST/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/e1e9c97c-02c0-4919-9b4c-eb5d5ef68970";
+ relationship.relationshipData = relationshipData;
+ relationship.relatedToProperty = relatedToProperty;
+
+ relationshipList.relationshipList.add(relationship);
+ response.relationshipList = relationshipList;
+
+ return response;
}
-}
+ public static AAIGETVserverResponse getQueryByVserverName2(String urlGet, String username, String password, UUID requestID, String key) {
+ AAIGETVserverResponse response = new AAIGETVserverResponse();
+
+ response.vserverID = "d0668d4f-c25e-4a1b-87c4-83845c01efd8";
+ response.vserverName = "USMSO1SX7NJ0103UJZZ01-vjunos0";
+ response.vserverName2 = "vjunos0";
+ response.vserverSelflink = "https://aai-ext1.test.att.com:8443/aai/v7/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USMSO1SX7NJ0103UJZZ01%3A%3AuCPE-VMS/vservers/vserver/d0668d4f-c25e-4a1b-87c4-83845c01efd8";
+ response.inMaint = "false";
+ response.isClosedLoopDisabled = "false";
+ response.resourceVersion = "1494001931513";
+
+ RelationshipList relationshipList = new RelationshipList();
+ Relationship relationship = new Relationship();
+ RelationshipData relationshipData = new RelationshipData();
+ RelationshipDataItem relationshipDataItem = new RelationshipDataItem();
+
+ relationshipDataItem.relationshipKey = "customer.global-customer-id";
+ relationshipDataItem.relationshipValue = "MSO_1610_ST";
+ relationshipData.relationshipData.add(relationshipDataItem);
+
+ relationshipDataItem.relationshipKey = "service-subscription.service-type";
+ relationshipDataItem.relationshipValue = "MSO-dev-service-type";
+ relationshipData.relationshipData.add(relationshipDataItem);
+
+ relationshipDataItem.relationshipKey = "service-instance.service-instance-id";
+ relationshipDataItem.relationshipValue = "e1e9c97c-02c0-4919-9b4c-eb5d5ef68970";
+ relationshipData.relationshipData.add(relationshipDataItem);
+
+ RelatedToProperty relatedToProperty = new RelatedToProperty();
+ RelatedToPropertyItem item = new RelatedToPropertyItem();
+ item.propertyKey = "service-instance.service-instance-name";
+ item.propertyValue = "lll_svc_010317";
+ relatedToProperty.relatedTo.add(item);
+
+ relationship.relatedTo = "service-instance";
+ relationship.relatedLink = "/aai/v11/business/customers/customer/MSO_1610_ST/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/e1e9c97c-02c0-4919-9b4c-eb5d5ef68970";
+ relationship.relationshipData = relationshipData;
+ relationship.relatedToProperty = relatedToProperty;
+
+ relationshipList.relationshipList.add(relationship);
+ response.relationshipList = relationshipList;
+
+ return response;
+ }
+} \ No newline at end of file