diff options
author | Jim Hahn <jrh3@att.com> | 2018-04-24 17:15:52 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2018-04-25 10:34:18 -0400 |
commit | f16ff9d2988c42926a140370b54f17d6c3362e79 (patch) | |
tree | d160f7a6a558ca620ac34f7a503108ffcffc6f92 /controlloop/common/eventmanager/src/main | |
parent | 49bccdce3e434e2e05d0f36ab5e4f2163184825b (diff) |
Prevent AAI re-query
Modified event manager code to not query AAI if there's already
a response from a previous query.
Modified code to store AAI properties in local variables instead
of static to prevent any chance of a race condition in a multi-threaded
situation.
Updated junit tests to use a new manager for each subsequent
query.
Update license.
Change variable name, in junit test, from onsetEvent to event,
because it can be any type of event.
Included fix to prevent initial AAI query if AAI data was already
available in the initial onset event.
Change-Id: Idf3e15ea8c5e297f22f23570c22fd837b72ba200
Issue-ID: POLICY-754
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/eventmanager/src/main')
-rw-r--r-- | controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java | 36 |
1 files changed, 22 insertions, 14 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 92b618f42..bc9d3df79 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 @@ -2,7 +2,7 @@ * ============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. @@ -80,9 +80,6 @@ public class ControlLoopEventManager implements LockCallback, Serializable { 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<>(); @@ -643,10 +640,21 @@ public class ControlLoopEventManager implements LockCallback, Serializable { * @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 { @@ -740,9 +748,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable { 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); @@ -770,9 +778,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable { 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) { |