aboutsummaryrefslogtreecommitdiffstats
path: root/feature-active-standby-management/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-02-19 16:56:06 -0500
committerJim Hahn <jrh3@att.com>2018-02-20 09:59:15 -0500
commita45f8909871dc1ddb75845f067a602951afc8d11 (patch)
treefa72aff7ceede971d4e6922f62a503a8ee8924d5 /feature-active-standby-management/src/main
parent1708e9a45cb88571613c10b68d392811b2b3f0f4 (diff)
Sonar fixes to drools-pdp
Fixed most of the instances of the following sonar issues: Moved array designator Used diamond operator Changed System.out/err to use a logger Changed several Thread.sleep() in test code to a single sleep() Useless assignments Replaced comparison with "" to string.isEmpty() Merged if's Replaced ArrayList with List in method returns Reordered type modifiers Reordered constructor methods Defined constants for literals, or replaced them with method calls Removed "throws Xxx" for subclasses of RuntimeException Combined identical "catch" blocks Re-interrupted the current thread after catching an InterruptedException Removed tests against the literal "false" Fix indentation of new makeTopicOperError() method. Fix exception variable name in new methods, logNoUebEncoder() and logNoDmaapEncoder(). Change-Id: Iddae5210553662f733b67333b372dec8c3fe2c94 Issue-ID: POLICY-336 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-active-standby-management/src/main')
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ActiveStandbyFeature.java25
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java6
-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.java32
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PMStandbyStateChangeNotifier.java12
-rw-r--r--feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java5
6 files changed, 50 insertions, 54 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 d2c542fb..932ebb2d 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
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * 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,7 +80,7 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
* {@inheritDoc}
*/
@Override
- public void globalInit(String args[], String configDir)
+ public void globalInit(String[] args, String configDir)
{
// This must come first since it initializes myPdp
initializePersistence(configDir);
@@ -164,7 +164,7 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
*/
DroolsPdp existingPdp = conn.getPdp(resourceName);
if (existingPdp != null) {
- System.out.println("Found existing PDP record, pdpId="
+ logger.info("Found existing PDP record, pdpId="
+ existingPdp.getPdpId() + ", isDesignated="
+ existingPdp.isDesignated() + ", updatedDate="
+ existingPdp.getUpdatedDate());
@@ -176,18 +176,17 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
myPdp = new DroolsPdpImpl(resourceName,false,4,new Date());
}
- String site_name = ActiveStandbyProperties.getProperty(ActiveStandbyProperties.SITE_NAME);
- if (site_name == null) {
- site_name = "";
+ String siteName = ActiveStandbyProperties.getProperty(ActiveStandbyProperties.SITE_NAME);
+ if (siteName == null) {
+ siteName = "";
}else{
- site_name = site_name.trim();
+ siteName = siteName.trim();
}
- myPdp.setSiteName(site_name);
+ myPdp.setSiteName(siteName);
if(electionHandler == null){
electionHandler = new DroolsPdpsElectionHandler(conn,myPdp);
}
}
- System.out.println("\n\nThis controller is a standby, waiting to be chosen as primary...\n\n");
logger.info("\n\nThis controller is a standby, waiting to be chosen as primary...\n\n");
}
@@ -199,7 +198,7 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
*/
public static DroolsPdpsConnector getDroolsPdpsConnector(String pu) {
- Map<String, Object> propMap = new HashMap<String, Object>();
+ Map<String, Object> propMap = new HashMap<>();
propMap.put("javax.persistence.jdbc.driver", ActiveStandbyProperties
.getProperty(ActiveStandbyProperties.DB_DRIVER));
propMap.put("javax.persistence.jdbc.url",
@@ -211,9 +210,7 @@ public class ActiveStandbyFeature implements ActiveStandbyFeatureAPI,
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
pu, propMap);
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emf);
-
- return conn;
+ return new JpaDroolsPdpsConnector(emf);
}
/**
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java
index 8c1d9f2e..690b260c 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/DroolsPdpObject.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * 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.
@@ -65,7 +65,7 @@ public abstract class DroolsPdpObject implements DroolsPdp{
}
@Override
public int comparePriority(DroolsPdp other, String previousSite){
- if(previousSite == null || previousSite.equals("")){
+ if(previousSite == null || previousSite.isEmpty()){
return comparePriority(other);
}
if(nullSafeCompare(this.getSiteName(),other.getSiteName()) == 0){
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 2836f92f..1a09d920 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
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * 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.
@@ -23,6 +23,7 @@ package org.onap.policy.drools.activestandby;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
@@ -33,7 +34,7 @@ import org.onap.policy.drools.statemanagement.StateManagementFeatureAPI;
public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
// get an instance of logger
- private final static Logger logger = LoggerFactory.getLogger(DroolsPdpsElectionHandler.class);
+ private static final Logger logger = LoggerFactory.getLogger(DroolsPdpsElectionHandler.class);
private DroolsPdpsConnector pdpsConnector;
private Object checkWaitTimerLock = new Object();
private Object designationWaiterLock = new Object();
@@ -70,13 +71,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
private StateManagementFeatureAPI stateManagementFeature;
private static boolean isUnitTesting = false;
- public static void setIsUnitTesting(boolean val){
- isUnitTesting = val;
- }
private static boolean isStalled = false;
- public static void setIsStalled(boolean val){
- isStalled = val;
- }
public DroolsPdpsElectionHandler(DroolsPdpsConnector pdps, DroolsPdp myPdp){
if (pdps == null) {
@@ -152,6 +147,13 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
}
}
+ public static void setIsUnitTesting(boolean val){
+ isUnitTesting = val;
+ }
+ public static void setIsStalled(boolean val){
+ isStalled = val;
+ }
+
/*
* When the JpaDroolsPdpsConnector.standDown() method is invoked, it needs
* access to myPdp, so it can keep its designation status in sync with the
@@ -194,7 +196,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
//It is possible that multiple PDPs are designated lead. So, we will make a list of all designated
//PDPs and then decide which one really should be designated at the end.
- ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
+ ArrayList<DroolsPdp> listOfDesignated = new ArrayList<>();
Collection<DroolsPdp> pdps = pdpsConnector.getDroolsPdps();
DroolsPdp designatedPdp = null;
@@ -767,7 +769,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
return mostRecentPrimary;
}
- public DroolsPdp computeDesignatedPdp(ArrayList<DroolsPdp> listOfDesignated, DroolsPdp mostRecentPrimary){
+ public DroolsPdp computeDesignatedPdp(List<DroolsPdp> listOfDesignated, DroolsPdp mostRecentPrimary){
DroolsPdp designatedPdp = null;
DroolsPdp lowestPriorityPdp = null;
if(listOfDesignated.size() > 1){
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 0d931acc..dc907b27 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
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * 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.
@@ -53,7 +53,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
em.getTransaction().begin();
Query droolsPdpsListQuery = em.createQuery("SELECT p FROM DroolsPdpEntity p");
List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
- LinkedList<DroolsPdp> droolsPdpsReturnList = new LinkedList<DroolsPdp>();
+ LinkedList<DroolsPdp> droolsPdpsReturnList = new LinkedList<>();
for(Object o : droolsPdpsList){
if(o instanceof DroolsPdp){
//Make sure it is not a cached version
@@ -613,24 +613,22 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
*/
private static void cleanup(EntityManager em, String method)
{
- if (em != null) {
- if (em.isOpen()) {
- if (em.getTransaction().isActive()) {
- // there is an active EntityTransaction -- roll it back
- try {
- em.getTransaction().rollback();
- } catch (Exception e) {
- logger.error(method + ": Caught Exception attempting to rollback EntityTransaction,", e);
- }
- }
-
- // now, close the EntityManager
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ // there is an active EntityTransaction -- roll it back
try {
- em.close();
+ em.getTransaction().rollback();
} catch (Exception e) {
- logger.error(method + ": Caught Exception attempting to close EntityManager, ", e);
+ logger.error(method + ": Caught Exception attempting to rollback EntityTransaction,", e);
}
}
+
+ // now, close the EntityManager
+ try {
+ em.close();
+ } catch (Exception e) {
+ logger.error(method + ": Caught Exception attempting to close EntityManager, ", e);
+ }
}
}
}
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PMStandbyStateChangeNotifier.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PMStandbyStateChangeNotifier.java
index 5a6dd8fa..84cc8dbd 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PMStandbyStateChangeNotifier.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/PMStandbyStateChangeNotifier.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * 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.
@@ -101,11 +101,9 @@ public class PMStandbyStateChangeNotifier extends StateChangeNotifier {
* has synchronize all of its methods. Only one stateManagement operation can occur at a time. Thus,
* only one handleStateChange() call will ever be made at a time.
*/
- if(logger.isInfoEnabled()){
- if(logger.isDebugEnabled()){
- logger.debug("handleStateChange: Entering, message={}, standbyStatus={}",
- super.getMessage(), super.getStateManagement().getStandbyStatus());
- }
+ if(logger.isDebugEnabled()){
+ logger.debug("handleStateChange: Entering, message={}, standbyStatus={}",
+ super.getMessage(), super.getStateManagement().getStandbyStatus());
}
String standbyStatus = super.getStateManagement().getStandbyStatus();
String pdpId = ActiveStandbyProperties
diff --git a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java
index db848ebb..b5fe3071 100644
--- a/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java
+++ b/feature-active-standby-management/src/main/java/org/onap/policy/drools/activestandby/ThreadRunningChecker.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* feature-active-standby-management
* ================================================================================
- * 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.
@@ -20,6 +20,7 @@
package org.onap.policy.drools.activestandby;
+@FunctionalInterface
public interface ThreadRunningChecker {
public void checkThreadStatus();