summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-09-21 09:31:25 -0400
committerJim Hahn <jrh3@att.com>2018-09-21 10:12:52 -0400
commitd85e766c5538de762820132ac723d928f5a9bf89 (patch)
tree738c4de12a3a261035bbb25199558a490d550d3e
parentfaf283066f186838665ed5c38c1ba8319041bc1c (diff)
new sonar issues in drools-applications
Don't return null lists from AAI. Transient TargetLock. Extract aai.url, et. al., constants. Don't allocate extra unneeded variable. Re-order fields in xacml attributes. Extract "vserver" constant from simulator. Replace thread sleep with join. Change-Id: Iee1bd182862632af1f131cca5db5b526f5865b9f Issue-ID: POLICY-1129 Signed-off-by: Jim Hahn <jrh3@att.com>
-rw-r--r--controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java2
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java23
-rw-r--r--controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributes.java36
-rw-r--r--controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java23
-rw-r--r--controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java13
-rw-r--r--controlloop/common/model-impl/vfc/src/test/java/org/onap/policy/vfc/TestVfcManager.java20
-rw-r--r--controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java8
7 files changed, 54 insertions, 71 deletions
diff --git a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
index 9904bac37..8775e68a6 100644
--- a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
+++ b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
@@ -393,7 +393,7 @@ public class SOActorServiceProvider implements Actor {
*/
private AaiNqInventoryResponseItem findVfModule(AaiNqResponseWrapper aaiResponseWrapper, boolean baseFlag) {
List<AaiNqInventoryResponseItem> lst = aaiResponseWrapper.getVfModuleItems(baseFlag);
- return (lst == null || lst.isEmpty() ? null : lst.get(lst.size() - 1));
+ return (lst.isEmpty() ? null : lst.get(lst.size() - 1));
}
/**
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 bd1904904..93535efc1 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
@@ -75,6 +75,10 @@ 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 AAI_URL = "aai.url";
+ private static final String AAI_USERNAME = "aai.username";
+ private static final String AAI_PASSWD = "aai.password";
+
private static final String QUERY_AAI_ERROR_MSG = "Exception from queryAai: ";
/**
@@ -101,7 +105,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<>();
private ControlLoopOperationManager currentOperation = null;
private ControlLoopOperationManager lastOperationManager = null;
- private TargetLock targetLock = null;
+ private transient TargetLock targetLock = null;
private AaiGetVnfResponse vnfResponse = null;
private AaiGetVserverResponse vserverResponse = null;
private boolean useTargetLock = true;
@@ -876,9 +880,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
try {
if (vserverName != null) {
- String aaiHostUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url");
- String aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.username");
- String 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_PASSWD);
String aaiGetQueryByVserver = "/aai/v11/nodes/vservers?vserver-name=";
String url = aaiHostUrl + aaiGetQueryByVserver;
logger.info("AAI Host URL by VServer: {}", url);
@@ -906,9 +910,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);
- String aaiHostUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url");
- String aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.username");
- String 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_PASSWD);
try {
if (vnfName != null) {
@@ -955,7 +959,6 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
final AaiNqInstanceFilters aaiNqInstanceFilter = new AaiNqInstanceFilters();
// queryParameters
- // TODO: UUID.fromString($params.getAaiNamedQueryUUID()) AaiNamedQueryUUID
aaiNqNamedQuery.setNamedQueryUuid(UUID.fromString("4ff56a54-9e3f-46b7-a337-07a1d3c6b469"));
aaiNqQueryParam.setNamedQuery(aaiNqNamedQuery);
aaiNqRequest.setQueryParameters(aaiNqQueryParam);
@@ -973,8 +976,8 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
logger.debug("AAI Request sent: {}", Serialization.gsonPretty.toJson(aaiNqRequest));
}
- AaiNqResponse aaiNqResponse = new AaiManager(new RESTManager()).postQuery(getPeManagerEnvProperty("aai.url"),
- getPeManagerEnvProperty("aai.username"), getPeManagerEnvProperty("aai.password"), aaiNqRequest,
+ AaiNqResponse aaiNqResponse = new AaiManager(new RESTManager()).postQuery(getPeManagerEnvProperty(AAI_URL),
+ getPeManagerEnvProperty(AAI_USERNAME), getPeManagerEnvProperty(AAI_PASSWD), aaiNqRequest,
onset.getRequestId());
// Check AAI response
diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributes.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributes.java
index 6b17af804..d7e608cb8 100644
--- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributes.java
+++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributes.java
@@ -28,6 +28,24 @@ import com.att.research.xacml.std.annotations.XACMLSubject;
@XACMLRequest(ReturnPolicyIdList = true, CombinedDecision = true)
public class PolicyGuardXacmlRequestAttributes {
+ @XACMLSubject(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:clname:clname-id")
+ String clnameID;
+
+ @XACMLSubject(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:actor:actor-id")
+ String actorID;
+
+ @XACMLAction(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:operation:operation-id")
+ String operationID;
+
+ @XACMLResource(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:target:target-id")
+ String targetID;
+
+ @XACMLResource(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:request:request-id")
+ String requestID;
+
+ @XACMLResource(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:request:vf-count")
+ Integer vfCount;
+
/**
* Construct an instance.
*
@@ -55,24 +73,6 @@ public class PolicyGuardXacmlRequestAttributes {
+ targetID + ", requestID=" + requestID + "]";
}
- @XACMLSubject(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:clname:clname-id")
- String clnameID;
-
- @XACMLSubject(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:actor:actor-id")
- String actorID;
-
- @XACMLAction(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:operation:operation-id")
- String operationID;
-
- @XACMLResource(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:target:target-id")
- String targetID;
-
- @XACMLResource(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:request:request-id")
- String requestID;
-
- @XACMLResource(includeInResults = true, attributeId = "urn:oasis:names:tc:xacml:1.0:request:vf-count")
- Integer vfCount;
-
public String getActorID() {
return actorID;
}
diff --git a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java
index be84fdfa8..eb4271b5c 100644
--- a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java
+++ b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java
@@ -22,6 +22,7 @@ package org.onap.policy.aai;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
@@ -68,8 +69,7 @@ public class AaiNqResponseWrapper implements Serializable {
* @return the number of VF modules, or {@code 0} if there are none
*/
public int countVfModules() {
- List<AaiNqInventoryResponseItem> lst = getVfModuleItems(false);
- return (lst == null ? 0 : lst.size());
+ return getVfModuleItems(false).size();
}
/**
@@ -80,11 +80,6 @@ public class AaiNqResponseWrapper implements Serializable {
* which to model it)
*/
public String genVfModuleName() {
- List<AaiNqInventoryResponseItem> lst = getVfModuleItems(false);
- if (lst == null) {
- return null;
- }
-
/*
* Loop through the VF modules, extracting the name prefix and the largest number
* suffix
@@ -92,7 +87,7 @@ public class AaiNqResponseWrapper implements Serializable {
String prefix = null;
int maxSuffix = -1;
- for (AaiNqInventoryResponseItem item : lst) {
+ for (AaiNqInventoryResponseItem item : getVfModuleItems(false)) {
String name = item.getVfModule().getVfModuleName();
Matcher matcher = VF_MODULE_NAME_PAT.matcher(name);
if (matcher.matches()) {
@@ -116,7 +111,7 @@ public class AaiNqResponseWrapper implements Serializable {
*
* @param wantBaseModule {@code true} if the the base VF module(s) is desired,
* {@code false} otherwise
- * @return the list of VF module items, or {@code null} if there are no VF modules
+ * @return the list of VF module items
*/
public List<AaiNqInventoryResponseItem> getVfModuleItems(boolean wantBaseModule) {
// get the list of items
@@ -127,18 +122,18 @@ public class AaiNqResponseWrapper implements Serializable {
} catch (NullPointerException | IndexOutOfBoundsException e) {
logger.debug("no VF modules in AAI response", e);
- return null;
+ return Collections.emptyList();
}
if (itemList == null) {
- return null;
+ return Collections.emptyList();
}
/*
* Walk the items looking for VF modules, allocating the list only when an item is
* found.
*/
- List<AaiNqInventoryResponseItem> vfModuleItems = null;
+ List<AaiNqInventoryResponseItem> vfModuleItems = new ArrayList<>(itemList.size());;
for (AaiNqInventoryResponseItem inventoryResponseItem : itemList) {
AaiNqVfModule vfmod = inventoryResponseItem.getVfModule();
@@ -146,10 +141,6 @@ public class AaiNqResponseWrapper implements Serializable {
continue;
}
- if (vfModuleItems == null) {
- vfModuleItems = new ArrayList<>(itemList.size());
- }
-
if (vfmod.getIsBaseVfModule() == wantBaseModule
&& (wantBaseModule || VF_MODULE_NAME_PAT.matcher(vfmod.getVfModuleName()).matches())) {
vfModuleItems.add(inventoryResponseItem);
diff --git a/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java b/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java
index 9acaa117c..d1e8e964e 100644
--- a/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java
+++ b/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java
@@ -22,7 +22,7 @@ package org.onap.policy.aai;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -207,41 +207,38 @@ public class AaiNqResponseWrapperTest {
// null item
resp = new AaiNqResponseWrapper();
- assertNull(resp.getVfModuleItems(true));
+ assertTrue(resp.getVfModuleItems(true).isEmpty());
// missing item
resp = new AaiNqResponseWrapper();
resp.setAaiNqResponse(new AaiNqResponse());
- assertNull(resp.getVfModuleItems(false));
+ assertTrue(resp.getVfModuleItems(false).isEmpty());
// null item list
resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoItems.json"));
resp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems().get(0)
.getItems().setInventoryResponseItems(null);
- assertNull(resp.getVfModuleItems(false));
+ assertTrue(resp.getVfModuleItems(false).isEmpty());
// no modules
resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoModules.json"));
- assertNull(resp.getVfModuleItems(false));
+ assertTrue(resp.getVfModuleItems(false).isEmpty());
// no names
resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoNames.json"));
List<AaiNqInventoryResponseItem> lst;
lst = resp.getVfModuleItems(false);
- assertNotNull(lst);
assertEquals(0, lst.size());
// base VF modules
resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json"));
lst = resp.getVfModuleItems(true);
- assertNotNull(lst);
assertEquals(1, lst.size());
assertEquals("Vfmodule_vLBMS-0809-1", lst.get(0).getVfModule().getVfModuleName());
// non base VF modules
resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json"));
lst = resp.getVfModuleItems(false);
- assertNotNull(lst);
assertEquals(3, lst.size());
int index;
index = 0;
diff --git a/controlloop/common/model-impl/vfc/src/test/java/org/onap/policy/vfc/TestVfcManager.java b/controlloop/common/model-impl/vfc/src/test/java/org/onap/policy/vfc/TestVfcManager.java
index 9913d39b8..7e4bda81d 100644
--- a/controlloop/common/model-impl/vfc/src/test/java/org/onap/policy/vfc/TestVfcManager.java
+++ b/controlloop/common/model-impl/vfc/src/test/java/org/onap/policy/vfc/TestVfcManager.java
@@ -189,9 +189,7 @@ public class TestVfcManager {
anyString()))
.thenThrow(new RuntimeException("OzException"));
- while (managerThread.isAlive()) {
- Thread.sleep(100);
- }
+ managerThread.join();
PolicyEngine.manager.getEnvironment().remove("vfc.password");
PolicyEngine.manager.getEnvironment().remove("vfc.username");
@@ -214,9 +212,7 @@ public class TestVfcManager {
eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString()))
.thenReturn(null);
- while (managerThread.isAlive()) {
- Thread.sleep(100);
- }
+ managerThread.join();
PolicyEngine.manager.getEnvironment().remove("vfc.password");
PolicyEngine.manager.getEnvironment().remove("vfc.username");
@@ -239,9 +235,7 @@ public class TestVfcManager {
eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseErr);
- while (managerThread.isAlive()) {
- Thread.sleep(100);
- }
+ managerThread.join();
PolicyEngine.manager.getEnvironment().remove("vfc.password");
PolicyEngine.manager.getEnvironment().remove("vfc.username");
@@ -264,9 +258,7 @@ public class TestVfcManager {
eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseBadResponse);
- while (managerThread.isAlive()) {
- Thread.sleep(100);
- }
+ managerThread.join();
PolicyEngine.manager.getEnvironment().remove("vfc.password");
PolicyEngine.manager.getEnvironment().remove("vfc.username");
@@ -292,9 +284,7 @@ public class TestVfcManager {
when(mockedRestManager.get(endsWith("1234"), eq("Dorothy"), eq("OK"), anyMap()))
.thenReturn(httpResponseGetOk);
- while (managerThread.isAlive()) {
- Thread.sleep(100);
- }
+ managerThread.join();
PolicyEngine.manager.getEnvironment().remove("vfc.password");
PolicyEngine.manager.getEnvironment().remove("vfc.username");
diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
index f5a4f6e53..3dd8347f2 100644
--- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
+++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
@@ -42,6 +42,8 @@ import org.onap.policy.aai.util.Serialization;
@Path("/aai")
public class AaiSimulatorJaxRs {
+ private static final String VSERVER = "vserver";
+
/**
* A&AI get query.
*
@@ -72,12 +74,12 @@ public class AaiSimulatorJaxRs {
public String aaiPostQuery(final String req) throws IOException {
final AaiNqRequest request = Serialization.gsonPretty.fromJson(req, AaiNqRequest.class);
- if (request.getInstanceFilters().getInstanceFilter().get(0).containsKey("vserver")) {
+ if (request.getInstanceFilters().getInstanceFilter().get(0).containsKey(VSERVER)) {
final String vserverName =
- request.getInstanceFilters().getInstanceFilter().get(0).get("vserver").get("vserver-name");
+ request.getInstanceFilters().getInstanceFilter().get(0).get(VSERVER).get("vserver-name");
if ("error".equals(vserverName)) {
Map<String,String> params = new TreeMap<>();
- params.put("type", "vserver");
+ params.put("type", VSERVER);
return load("aai/AaiNqResponse-Error.json", params);
} else {
// vll format - new