summaryrefslogtreecommitdiffstats
path: root/feature-server-pool
diff options
context:
space:
mode:
Diffstat (limited to 'feature-server-pool')
-rw-r--r--feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Bucket.java6
-rw-r--r--feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Server.java7
-rw-r--r--feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/ServerPoolApi.java3
-rw-r--r--feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/persistence/Persistence.java73
-rw-r--r--feature-server-pool/src/test/java/org/onap/policy/drools/serverpool/AdapterImpl.java8
5 files changed, 55 insertions, 42 deletions
diff --git a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Bucket.java b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Bucket.java
index 6241a297..3284a6b7 100644
--- a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Bucket.java
+++ b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Bucket.java
@@ -783,7 +783,11 @@ public class Bucket {
* current host.
*/
UUID key = oldHost.uuid;
- for (int count = new Random().nextInt(rb.testServers.size() - 1); count >= 0; count -= 1) {
+ /*
+ * Disabling sonar, because this Random() is not used for security purposes.
+ */
+ int randomStart = new Random().nextInt(rb.testServers.size() - 1); // NOSONAR
+ for (int count = randomStart; count >= 0; count -= 1) {
key = rb.testServers.higherKey(key);
if (key == null) {
// wrap to the beginning of the list
diff --git a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Server.java b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Server.java
index 80b5891a..ffddf0a0 100644
--- a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Server.java
+++ b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Server.java
@@ -334,11 +334,8 @@ public class Server implements Comparable<Server> {
// add any additional servlets
for (ServerPoolApi feature : ServerPoolApi.impl.getList()) {
- Collection<Class<?>> classes = feature.servletClasses();
- if (classes != null) {
- for (Class<?> clazz : classes) {
- restServer.addServletClass(null, clazz.getName());
- }
+ for (Class<?> clazz : feature.servletClasses()) {
+ restServer.addServletClass(null, clazz.getName());
}
}
diff --git a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/ServerPoolApi.java b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/ServerPoolApi.java
index d267ce82..0442912f 100644
--- a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/ServerPoolApi.java
+++ b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/ServerPoolApi.java
@@ -21,6 +21,7 @@
package org.onap.policy.drools.serverpool;
import java.util.Collection;
+import java.util.Collections;
import org.onap.policy.common.utils.services.OrderedService;
import org.onap.policy.common.utils.services.OrderedServiceImpl;
@@ -39,7 +40,7 @@ public interface ServerPoolApi extends OrderedService {
* @return a Collection of classes implementing REST methods
*/
public default Collection<Class<?>> servletClasses() {
- return null;
+ return Collections.emptyList();
}
/**
diff --git a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/persistence/Persistence.java b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/persistence/Persistence.java
index e8121f3a..c1d7192f 100644
--- a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/persistence/Persistence.java
+++ b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/persistence/Persistence.java
@@ -31,6 +31,7 @@ import java.util.IdentityHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
@@ -698,47 +699,53 @@ public class Persistence implements PolicySessionFeatureApi, ServerPoolApi {
private List<CountDownLatch> restoreBucketDroolsSessions() {
List<CountDownLatch> sessionLatches = new LinkedList<>();
for (Map.Entry<String, ReceiverSessionBucketData> entry : sessionData.entrySet()) {
- String sessionName = entry.getKey();
- ReceiverSessionBucketData rsbd = entry.getValue();
+ restoreBucketDroolsSession(sessionLatches, entry);
+ }
+ return sessionLatches;
+ }
- PolicySession policySession = detmPolicySession(sessionName);
- if (policySession == null) {
- logger.error(RESTORE_BUCKET_ERROR
- + "Can't find PolicySession{}", sessionName);
- continue;
- }
+ private void restoreBucketDroolsSession(List<CountDownLatch> sessionLatches,
+ Entry<String, ReceiverSessionBucketData> entry) {
- final Map<?, ?> droolsObjects = deserializeMap(sessionName, rsbd, policySession);
- if (droolsObjects == null) {
- continue;
- }
+ String sessionName = entry.getKey();
+ ReceiverSessionBucketData rsbd = entry.getValue();
- // if we reach this point, we have decoded the persistent data
+ PolicySession policySession = detmPolicySession(sessionName);
+ if (policySession == null) {
+ logger.error(RESTORE_BUCKET_ERROR
+ + "Can't find PolicySession{}", sessionName);
+ return;
+ }
- // signal when restore is complete
- final CountDownLatch sessionLatch = new CountDownLatch(1);
+ final Map<?, ?> droolsObjects = deserializeMap(sessionName, rsbd, policySession);
+ if (droolsObjects == null) {
+ return;
+ }
- // 'KieSession' object
- final KieSession kieSession = policySession.getKieSession();
+ // if we reach this point, we have decoded the persistent data
- // run the following within the Drools session thread
- DroolsRunnable insertDroolsObjects = () -> {
- try {
- // insert all of the Drools objects into the session
- for (Object droolsObj : droolsObjects.keySet()) {
- kieSession.insert(droolsObj);
- }
- } finally {
- // signal completion
- sessionLatch.countDown();
+ // signal when restore is complete
+ final CountDownLatch sessionLatch = new CountDownLatch(1);
+
+ // 'KieSession' object
+ final KieSession kieSession = policySession.getKieSession();
+
+ // run the following within the Drools session thread
+ DroolsRunnable insertDroolsObjects = () -> {
+ try {
+ // insert all of the Drools objects into the session
+ for (Object droolsObj : droolsObjects.keySet()) {
+ kieSession.insert(droolsObj);
}
- };
- kieSession.insert(insertDroolsObjects);
+ } finally {
+ // signal completion
+ sessionLatch.countDown();
+ }
+ };
+ kieSession.insert(insertDroolsObjects);
- // add this to the set of 'CountDownLatch's we are waiting for
- sessionLatches.add(sessionLatch);
- }
- return sessionLatches;
+ // add this to the set of 'CountDownLatch's we are waiting for
+ sessionLatches.add(sessionLatch);
}
private PolicySession detmPolicySession(String sessionName) {
diff --git a/feature-server-pool/src/test/java/org/onap/policy/drools/serverpool/AdapterImpl.java b/feature-server-pool/src/test/java/org/onap/policy/drools/serverpool/AdapterImpl.java
index 044067a3..865f4e90 100644
--- a/feature-server-pool/src/test/java/org/onap/policy/drools/serverpool/AdapterImpl.java
+++ b/feature-server-pool/src/test/java/org/onap/policy/drools/serverpool/AdapterImpl.java
@@ -55,8 +55,12 @@ public class AdapterImpl extends Adapter {
* Each 'AdapterImpl' instance has it's own class object, making it a
* singleton. There is only a single 'Adapter' class object, and all
* 'AdapterImpl' classes are derived from it.
+ *
+ * Sonar thinks this field isn't used. However, it's value is actually
+ * retrieved via Whitebox, below. Thus it is marked "protected" instead
+ * of "private" to avoid the sonar complaint.
*/
- private static AdapterImpl adapter = null;
+ protected static AdapterImpl adapter = null;
// this is the adapter index
private int index;
@@ -347,7 +351,7 @@ public class AdapterImpl extends Adapter {
boolean rval = false;
ClassLoader myClassLoader = AdapterImpl.class.getClassLoader();
for (Object o : objects) {
- Class clazz = o.getClass();
+ Class<?> clazz = o.getClass();
ClassLoader objClassLoader = clazz.getClassLoader();
try {