* ============LICENSE_START=======================================================
* controlloop event manager
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
private transient TargetLock targetLock = null;
private AaiGetVnfResponse vnfResponse = null;
private AaiGetVserverResponse vserverResponse = null;
- private static String aaiHostURL;
- private static String aaiUser;
- private static String aaiPassword;
private static Collection<String> requiredAAIKeys = new ArrayList<>();
* @param event the event
* @throws AaiException if an error occurs retrieving information from A&AI
*/
- public void queryAai(VirtualControlLoopEvent event) throws AaiException {
- if ((event.getAai().get(VSERVER_IS_CLOSED_LOOP_DISABLED) != null
- || event.getAai().get(GENERIC_VNF_IS_CLOSED_LOOP_DISABLED) != null) && isClosedLoopDisabled(event)) {
- throw new AaiException("is-closed-loop-disabled is set to true on VServer or VNF");
+ public void queryAai(VirtualControlLoopEvent event) throws AaiException {
+ if (event.getAai().get(VSERVER_IS_CLOSED_LOOP_DISABLED) != null
+ || event.getAai().get(GENERIC_VNF_IS_CLOSED_LOOP_DISABLED) != null) {
+
+ if(isClosedLoopDisabled(event)) {
+ throw new AaiException("is-closed-loop-disabled is set to true on VServer or VNF");
+ }
+
+ // no need to query, as we already have the data
+ return;
+ }
+
+ if(vnfResponse != null || vserverResponse != null) {
+ // query has already been performed
+ return;
}
try {
try {
if (vserverName != null) {
- aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url");
- aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.username");
- aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
+ String aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url");
+ String aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.username");
+ String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
String aaiGetQueryByVserver = "/aai/v11/nodes/vservers?vserver-name=";
String url = aaiHostURL + aaiGetQueryByVserver;
logger.info("AAI Host URL by VServer: {}", url);
String vnfName = event.getAai().get(GENERIC_VNF_VNF_NAME);
String vnfId = event.getAai().get(GENERIC_VNF_VNF_ID);
- aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url");
- aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.username");
- aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
+ String aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url");
+ String aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.username");
+ String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
try {
if (vnfName != null) {
event.setTarget("generic-vnf.vnf-id");
event.setClosedLoopAlarmStart(Instant.now());
event.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED);
- ControlLoopEventManager manager =
- new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
+ ControlLoopEventManager manager = makeManager(event);
assertNull(manager.getVnfResponse());
assertNull(manager.getVserverResponse());
try {
event.setAai(new HashMap<>());
event.getAai().put("generic-vnf.vnf-name", "onsetOne");
- ControlLoopEventManager manager =
- new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
+ ControlLoopEventManager manager = makeManager(event);
VirtualControlLoopNotification notification = manager.activate(event);
assertNotNull(notification);
event.setAai(new HashMap<>());
event.getAai().put("generic-vnf.vnf-name", "onsetOne");
- ControlLoopEventManager manager =
- new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
+ ControlLoopEventManager manager = makeManager(event);
manager.setActivated(true);
VirtualControlLoopNotification notification = manager.activate(event);
assertEquals(ControlLoopNotificationType.REJECTED, notification.getNotification());
event.setAai(new HashMap<>());
event.getAai().put("generic-vnf.vnf-name", "onsetOne");
- ControlLoopEventManager manager =
- new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
+ ControlLoopEventManager manager = makeManager(event);
// Null YAML should fail
VirtualControlLoopNotification notificationNull = manager.activate(null, event);
event.setAai(new HashMap<>());
event.getAai().put("generic-vnf.vnf-name", "onsetOne");
- ControlLoopEventManager manager =
- new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
+ ControlLoopEventManager manager = makeManager(event);
try {
manager.isControlLoopFinal();
fail("test should throw an exception here");
event.setAai(new HashMap<>());
event.getAai().put("generic-vnf.vnf-name", "onsetOne");
- ControlLoopEventManager manager =
- new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
+ ControlLoopEventManager manager = makeManager(event);
try {
manager.processControlLoop();
fail("test should throw an exception here");
event.setAai(new HashMap<>());
event.getAai().put("generic-vnf.vnf-name", "onsetOne");
- ControlLoopEventManager manager =
- new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
+ ControlLoopEventManager manager = makeManager(event);
try {
manager.finishOperation(null);
fail("test should throw an exception here");
// This call should be exception free
manager.finishOperation(clom);
- ControlLoopEventManager otherManager =
- new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
+ ControlLoopEventManager otherManager = makeManager(event);
VirtualControlLoopNotification otherNotification = otherManager.activate(yamlStringStd, event);
assertNotNull(otherNotification);
assertEquals(ControlLoopNotificationType.ACTIVE, otherNotification.getNotification());
abatedEvent.setAai(new HashMap<>());
abatedEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
- ControlLoopEventManager manager =
- new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId());
+ ControlLoopEventManager manager = makeManager(onsetEvent);
VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent);
assertNotNull(notification);
assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
onsetEvent.setAai(new HashMap<>());
onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
- ControlLoopEventManager manager =
- new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId());
+ ControlLoopEventManager manager = makeManager(onsetEvent);
assertTrue(0 == manager.getControlLoopTimeout(null));
assertTrue(120 == manager.getControlLoopTimeout(120));
onsetEvent.setAai(new HashMap<>());
onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
- ControlLoopEventManager manager =
- new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId());
+ ControlLoopEventManager manager = makeManager(onsetEvent);
manager.queryAai(onsetEvent);
VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent);
assertNotNull(notification);
assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
+ // repeat query with same manager
manager.queryAai(onsetEvent);
+
+ // remaining queries each use their own manager so they will be re-executed
+
+ makeManager(onsetEvent).queryAai(onsetEvent);
onsetEvent.getAai().put("generic-vnf.is-closed-loop-disabled", "true");
try {
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
fail("test should throw an exception here");
} catch (Exception e) {
assertEquals("is-closed-loop-disabled is set to true on VServer or VNF", e.getMessage());
}
onsetEvent.getAai().put("vserver.is-closed-loop-disabled", "true");
try {
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
fail("test should throw an exception here");
} catch (Exception e) {
assertEquals("is-closed-loop-disabled is set to true on VServer or VNF", e.getMessage());
}
onsetEvent.getAai().remove("generic-vnf.is-closed-loop-disabled");
try {
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
fail("test should throw an exception here");
} catch (Exception e) {
assertEquals("is-closed-loop-disabled is set to true on VServer or VNF", e.getMessage());
}
onsetEvent.getAai().remove("vserver.is-closed-loop-disabled");
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
onsetEvent.getAai().put("generic-vnf.is-closed-loop-disabled", "false");
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
+
+ onsetEvent.getAai().remove("generic-vnf.is-closed-loop-disabled");
onsetEvent.getAai().put("vserver.is-closed-loop-disabled", "false");
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
onsetEvent.getAai().remove("generic-vnf.vnf-id");
onsetEvent.getAai().remove("generic-vnf.vnf-name");
onsetEvent.getAai().remove("vserver.vserver-name");
- manager.queryAai(onsetEvent);
+ onsetEvent.getAai().remove("generic-vnf.is-closed-loop-disabled");
+ onsetEvent.getAai().remove("vserver.is-closed-loop-disabled");
+ makeManager(onsetEvent).queryAai(onsetEvent);
onsetEvent.getAai().put("vserver.vserver-name", "AVserver");
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
onsetEvent.getAai().put("generic-vnf.vnf-name", "AVNFName");
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
onsetEvent.getAai().put("generic-vnf.vnf-id", "AVNFID");
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
onsetEvent.getAai().remove("vserver.vserver-name");
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
onsetEvent.getAai().remove("generic-vnf.vnf-name");
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
// Force AAI errors
PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:9999");
try {
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
fail("test should throw an exception here");
} catch (Exception e) {
assertEquals("Exception from queryAai: org.onap.policy.aai.util.AaiException: AAI Response is null "
onsetEvent.getAai().remove("generic-vnf.vnf-id");
onsetEvent.getAai().put("generic-vnf.vnf-name", "AVNFName");
try {
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
fail("test should throw an exception here");
} catch (Exception e) {
assertEquals("Exception from queryAai: org.onap.policy.aai.util.AaiException: AAI Response is null "
onsetEvent.getAai().remove("generic-vnf.vnf-name");
onsetEvent.getAai().put("vserver.vserver-name", "AVserver");
try {
- manager.queryAai(onsetEvent);
+ makeManager(onsetEvent).queryAai(onsetEvent);
fail("test should throw an exception here");
} catch (Exception e) {
assertEquals("Exception from queryAai: org.onap.policy.aai.util.AaiException: AAI Response is null "
PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
}
+
+ private ControlLoopEventManager makeManager(VirtualControlLoopEvent event) {
+ return new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
+ }
}