summaryrefslogtreecommitdiffstats
path: root/controlloop/common
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-08-16 14:57:15 -0400
committerJim Hahn <jrh3@att.com>2018-08-17 10:23:28 -0400
commit48eb8e2bd1674592ddfadfbbc01a611b6a263393 (patch)
tree76a8e093afee41e5623aac7a490d3ebe05664176 /controlloop/common
parenta9b2b1d16797fefa4c7be8ba0bf01f0fdab22b7b (diff)
fix new sonar issues with prov-status check
Changes made while adding the prov-status check triggered some sonar thresholds in ControlLoopEventManager. Updated the code to resolve them. One of the changes that had been introduced was to check for the existence of both the is-closed-loop-disabled AND the prov-status fields. However, if one is there then the other should be there, thus the second check is redundant and was removed, which should reduce the cyclomatic complexity back under the threshold. Re-ordered the code a little, to make it less ambiguous. Removed trailing white space. Change-Id: If0ce74cedbf947c32cae3df3374cda6ba1305cd2 Issue-ID: POLICY-964 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java73
1 files changed, 37 insertions, 36 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 ff1053482..bd7f14e6f 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
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -66,6 +66,8 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
public static final String GENERIC_VNF_PROV_STATUS = "generic-vnf.prov-status";
public static final String VSERVER_PROV_STATUS = "vserver.prov-status";
+ private static final String QUERY_AAI_ERROR_MSG = "Exception from queryAai: ";
+
/**
* Additional time, in seconds, to add to a "lock" request. This ensures that the lock
* won't expire right before an operation completes.
@@ -161,7 +163,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Activate a control loop event.
- *
+ *
* @param event the event
* @return the VirtualControlLoopNotification
*/
@@ -200,7 +202,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Activate a control loop event.
- *
+ *
* @param yamlSpecification the yaml specification
* @param event the event
* @return the VirtualControlLoopNotification
@@ -274,7 +276,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Check if the control loop is final.
- *
+ *
* @return a VirtualControlLoopNotification if the control loop is final, otherwise
* <code>null</code> is returned
* @throws ControlLoopException if an error occurs
@@ -348,7 +350,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Process the control loop.
- *
+ *
* @return a ControlLoopOperationManager
* @throws ControlLoopException if an error occurs
* @throws AaiException if an error occurs retrieving information from A&AI
@@ -407,7 +409,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Finish an operation.
- *
+ *
* @param operation the operation
*/
public void finishOperation(ControlLoopOperationManager operation) throws ControlLoopException {
@@ -448,7 +450,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Obtain a lock for the current operation.
- *
+ *
* @return the lock result
* @throws ControlLoopException if an error occurs
*/
@@ -493,19 +495,19 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Release the lock for the current operation.
- *
+ *
* @return the target lock
*/
public synchronized TargetLock unlockCurrentOperation() {
if (this.targetLock == null) {
return null;
}
-
+
TargetLock returnLock = this.targetLock;
this.targetLock = null;
-
+
PolicyGuard.unlockTarget(returnLock);
-
+
// always return the old target lock so rules can retract it
return returnLock;
}
@@ -516,7 +518,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* An event onset/abatement.
- *
+ *
* @param event the event
* @return the status
* @throws AaiException if an error occurs retrieving information from A&AI
@@ -580,7 +582,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Set the control loop time out.
- *
+ *
* @return a VirtualControlLoopNotification
*/
public VirtualControlLoopNotification setControlLoopTimedOut() {
@@ -598,7 +600,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Get the control loop timeout.
- *
+ *
* @param defaultTimeout the default timeout
* @return the timeout
*/
@@ -622,7 +624,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Check an event syntax.
- *
+ *
* @param event the event syntax
* @throws ControlLoopException if an error occurs
*/
@@ -661,24 +663,23 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Query A&AI for an event.
- *
+ *
* @param event the event
* @throws AaiException if an error occurs retrieving information from A&AI
*/
public void queryAai(VirtualControlLoopEvent event) throws AaiException {
- if (isClosedLoopDisabled(event)) {
- throw new AaiException("is-closed-loop-disabled is set to true on VServer or VNF");
- }
+ Map<String, String> aai = event.getAai();
- if (isProvStatusInactive(event)) {
- throw new AaiException("prov-status is not ACTIVE on VServer or VNF");
- }
+ if (aai.containsKey(VSERVER_IS_CLOSED_LOOP_DISABLED) || aai.containsKey(GENERIC_VNF_IS_CLOSED_LOOP_DISABLED)) {
- Map<String, String> aai = event.getAai();
+ if (isClosedLoopDisabled(event)) {
+ throw new AaiException("is-closed-loop-disabled is set to true on VServer or VNF");
+ }
- if ((aai.containsKey(VSERVER_IS_CLOSED_LOOP_DISABLED) || aai.containsKey(GENERIC_VNF_IS_CLOSED_LOOP_DISABLED))
- && (aai.containsKey(VSERVER_PROV_STATUS) || aai.containsKey(GENERIC_VNF_PROV_STATUS))) {
+ if (isProvStatusInactive(event)) {
+ throw new AaiException("prov-status is not ACTIVE on VServer or VNF");
+ }
// no need to query, as we already have the data
return;
@@ -698,17 +699,17 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
processVServerResponse(vserverResponse);
}
} catch (AaiException e) {
- logger.error("Exception from queryAai: ", e);
+ logger.error(QUERY_AAI_ERROR_MSG, e);
throw e;
} catch (Exception e) {
- logger.error("Exception from queryAai: ", e);
- throw new AaiException("Exception from queryAai: " + e.toString());
+ logger.error(QUERY_AAI_ERROR_MSG, e);
+ throw new AaiException(QUERY_AAI_ERROR_MSG + e.toString());
}
}
/**
* Process a response from A&AI for a VNF.
- *
+ *
* @param aaiResponse the response from A&AI
* @param queryByVnfId <code>true</code> if the query was based on vnf-id,
* <code>false</code> if the query was based on vnf-name
@@ -735,7 +736,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Process a response from A&AI for a VServer.
- *
+ *
* @param aaiResponse the response from A&AI
* @throws AaiException if an error occurs processing the response
*/
@@ -764,7 +765,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Is closed loop disabled for an event.
- *
+ *
* @param event the event
* @return <code>true</code> if the control loop is disabled, <code>false</code>
* otherwise
@@ -777,7 +778,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Does provisioning status, for an event, have a value other than ACTIVE?
- *
+ *
* @param event the event
* @return {@code true} if the provisioning status is neither ACTIVE nor {@code null},
* {@code false} otherwise
@@ -790,7 +791,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Determines the boolean value represented by the given AAI field value.
- *
+ *
* @param aaiValue value to be examined
* @return the boolean value represented by the field value, or {@code false} if the
* value is {@code null}
@@ -802,7 +803,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Get the A&AI VService information for an event.
- *
+ *
* @param event the event
* @return a AaiGetVserverResponse
* @throws ControlLoopException if an error occurs
@@ -833,7 +834,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
/**
* Get A&AI VNF information for an event.
- *
+ *
* @param event the event
* @return a AaiGetVnfResponse
* @throws ControlLoopException if an error occurs