summaryrefslogtreecommitdiffstats
path: root/feature-active-standby-management/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-06 15:33:23 -0400
committerJim Hahn <jrh3@att.com>2020-04-06 19:30:02 -0400
commit15014b8ca386a8bfd5c26435f45de94ca06e95e8 (patch)
tree3cca518b950dfa35da0ea64dab2f9ff2b80f4595 /feature-active-standby-management/src
parentece155048af47ea83ff898c999aa5137dc99a988 (diff)
Address sonar issues in drools-pdp
Addressed the following sonar issues: - add "final" to public static fields - commented code; some were bogus - just updated the comments so sonar is happy - use "{}" instead of string concatenation - junit should assert something - when using logger, invoke compute-intensive tasks conditionally - use superclass name instead of subclass name to access static fields - don't always return the same value - remove "transient" from fields of classes that aren't Serializable - don't nest try/catch blocks - use appropriate class name in Logger.getLogger() - use Predicate<T> instead of Function<T,Boolean> - remove unused parameters from private methods - either log or throw - remove duplicate methods - use remove() TLS instead of set(null) - null check is implicit in instanceof check - do something with return value - don't use volatile - don't return "null" list; used Optional instead - add no-arg constructor to non-Serializable superclass - add callSuper=true for EqualsAndHashCode - don't declare "throws XXX" where XXX is a subclass of RuntimeException - remove serialVersionUID field if the class isn't Serializable Also addressed some eclipse warnings: - unused fields - suppress generic typic cast warnings Issue-ID: POLICY-2305 Change-Id: I906d5bf71c1f86531423e23b3667a585cdba45e1 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-active-standby-management/src')
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java8
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java24
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java6
-rw-r--r--feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifierTest.java5
4 files changed, 24 insertions, 19 deletions
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java
index 91d30d74..2b75ea5e 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 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.
@@ -151,10 +151,8 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureApi,
*/
DroolsPdp existingPdp = conn.getPdp(resourceName);
if (existingPdp != null) {
- logger.info("Found existing PDP record, pdpId="
- + existingPdp.getPdpId() + ", isDesignated="
- + existingPdp.isDesignated() + ", updatedDate="
- + existingPdp.getUpdatedDate());
+ logger.info("Found existing PDP record, pdpId={} isDesignated={}, updatedDate={}",
+ existingPdp.getPdpId(), existingPdp.isDesignated(), existingPdp.getUpdatedDate());
myPdp = existingPdp;
}
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
index 37382e81..f51e0718 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpsElectionHandler.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 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.
@@ -92,7 +92,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
pdpdNowActive = null;
pdpdLastActive = null;
this.pdpsConnector = pdps;
- DroolsPdpsElectionHandler.myPdp = myPdp;
+ setMyPdp(myPdp);
this.isDesignated = false;
// The interval between checks of the DesignationWaiter to be sure it is running.
@@ -152,6 +152,10 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
}
}
+ private static void setMyPdp(DroolsPdp myPdp) {
+ DroolsPdpsElectionHandler.myPdp = myPdp;
+ }
+
public static void setIsUnitTesting(boolean val) {
isUnitTesting = val;
}
@@ -403,9 +407,11 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
}
private void demoteMyPdp(DroolsPdp pdp, String standbyStatus) throws Exception {
- //Keep the order like this. StateManagement is last since it
- //triggers controller shutdown
- //This will change isDesignated and it can enter another if(combination) below
+ /*
+ * Keep the order like this. StateManagement is last since it triggers
+ * controller shutdown. This will change isDesignated and it can enter another
+ * if-combination below
+ */
pdpsConnector.standDownPdp(pdp.getPdpId());
myPdp.setDesignated(false);
isDesignated = false;
@@ -422,8 +428,8 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
private void pdpDesignatedNotCurrent(DroolsPdp pdp) {
/*
- * Changes designated to 0 but it is still potentially providing service
- * Will affect isDesignated, so, it can enter an if(combination) below
+ * Changes designated to 0 but it is still potentially providing service.
+ * Will affect isDesignated, so, it can enter an if-combination below
*/
pdpsConnector.standDownPdp(pdp.getPdpId());
@@ -614,7 +620,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
}
waitTimerLastRunDate = currentTime.getDate();
logger.debug("DesignatedWaiter.run (designatedPdp.getPdpId().equals(myPdp.getPdpId())) "
- + "waitTimerLastRunDate = " + waitTimerLastRunDate);
+ + "waitTimerLastRunDate = {}", waitTimerLastRunDate);
myPdp.setUpdatedDate(waitTimerLastRunDate);
pdpsConnector.update(myPdp);
}
@@ -786,7 +792,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
// So, we must demote it
demoteMyPdp();
}
- } //end: for(DroolsPdp pdp : listOfDesignated)
+ }
DroolsPdp lowestPriorityPdp = data.getLowestPriority();
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java
index 1830d055..6e456962 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/JpaDroolsPdpsConnector.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 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.
@@ -566,7 +566,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
try {
em.getTransaction().rollback();
} catch (Exception e) {
- logger.error(method + ": Caught Exception attempting to rollback EntityTransaction,", e);
+ logger.error("{}: Caught Exception attempting to rollback EntityTransaction", method, e);
}
}
@@ -574,7 +574,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
try {
em.close();
} catch (Exception e) {
- logger.error(method + ": Caught Exception attempting to close EntityManager, ", e);
+ logger.error("{}: Caught Exception attempting to close EntityManager", method, e);
}
}
}
diff --git a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifierTest.java b/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifierTest.java
index 4a89d257..1cf20e21 100644
--- a/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifierTest.java
+++ b/feature-active-standby-management/src/test/java/org/onap/policy/drools/activestandby/PmStandbyStateChangeNotifierTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -20,6 +20,7 @@
package org.onap.policy.drools.activestandby;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
@@ -263,7 +264,7 @@ public class PmStandbyStateChangeNotifierTest {
@Test
public void testGetPolicyEngineManager() {
// use real object with real method - no exception expected
- new PmStandbyStateChangeNotifier().getPolicyEngineManager();
+ assertThatCode(() -> new PmStandbyStateChangeNotifier().getPolicyEngineManager()).doesNotThrowAnyException();
}
private class MyNotifier extends PmStandbyStateChangeNotifier {