Fix minor sonar 11/69611/4
authorPamela Dragosh <pdragosh@research.att.com>
Mon, 1 Oct 2018 18:44:26 +0000 (14:44 -0400)
committerPamela Dragosh <pdragosh@research.att.com>
Tue, 2 Oct 2018 00:15:51 +0000 (20:15 -0400)
These are mainly duplicate strings. But also combined
if statements and fixing some debug messages missing
arguments or format specifiers. Some duplicates I left
alone as it seemed unreadable to change them. Also
moving variables to their correct place (before constructors).

Issue-ID: POLICY-1130
Change-Id: I8018c676b22fe8fec635f129fa37921ad1004569
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java
integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java
integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorProperties.java
integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java
integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransition.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClient.java

index 177391c..5175232 100644 (file)
@@ -55,6 +55,14 @@ public class AuditThread extends Thread {
      * May be modified by JUnit tests.
      */
     private static final long AUDIT_THREAD_SLEEP_INTERVAL_MS = 5000L;
+    
+    /*
+     * String constants.
+     */
+    private static final String AUDIT_THREAD_MESSAGE = "AuditThread.run: resourceName=";
+    private static final String ENTITY_INDEX_MESSAGE = ", entityIndex=";
+    private static final String LAST_UPDATED_MESSAGE = ", lastUpdated=";
+    private static final String PERSISTENCE_MESSAGE = ", persistenceUnit=";
 
     /*
      * DB access class.
@@ -91,6 +99,16 @@ public class AuditThread extends Thread {
      */
     private IntegrityAudit integrityAudit;
 
+    /*
+     * Used to create a list that is sorted lexicographically by resourceName.
+     */
+    Comparator<IntegrityAuditEntity> comparator = new Comparator<IntegrityAuditEntity>() {
+        @Override
+        public int compare(final IntegrityAuditEntity r1, final IntegrityAuditEntity r2) {
+            return r1.getResourceName().compareTo(r2.getResourceName());
+        }
+    };
+
     /**
      * AuditThread constructor.
      * 
@@ -241,19 +259,19 @@ public class AuditThread extends Thread {
                         }
                         AuditorTime.getInstance().sleep(integrityAuditPeriodSeconds * 1000L);
                         if (logger.isDebugEnabled()) {
-                            logger.debug("AuditThread.run: resourceName=" + this.resourceName + " awaking from "
+                            logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + " awaking from "
                                     + integrityAuditPeriodSeconds + "s sleep");
                         }
 
                     } else {
 
                         if (logger.isDebugEnabled()) {
-                            logger.debug("AuditThread.run: resourceName=" + this.resourceName + ": Sleeping "
+                            logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + ": Sleeping "
                                     + AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS + "ms");
                         }
                         AuditorTime.getInstance().sleep(AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS);
                         if (logger.isDebugEnabled()) {
-                            logger.debug("AuditThread.run: resourceName=" + this.resourceName + ": Awaking from "
+                            logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + ": Awaking from "
                                     + AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS + "ms sleep");
                         }
 
@@ -305,16 +323,6 @@ public class AuditThread extends Thread {
         return false;
     }
 
-    /*
-     * Used to create a list that is sorted lexicographically by resourceName.
-     */
-    Comparator<IntegrityAuditEntity> comparator = new Comparator<IntegrityAuditEntity>() {
-        @Override
-        public int compare(final IntegrityAuditEntity r1, final IntegrityAuditEntity r2) {
-            return r1.getResourceName().compareTo(r2.getResourceName());
-        }
-    };
-
     /**
      * getDesignationCandidate() Using round robin algorithm, gets next candidate to be designated.
      * Assumes list is sorted lexicographically by resourceName.
@@ -353,9 +361,9 @@ public class AuditThread extends Thread {
             if (integrityAuditEntity.isDesignated()) {
                 if (logger.isDebugEnabled()) {
                     logger.debug("getDesignationCandidate: Currently designated entity resourceName="
-                            + integrityAuditEntity.getResourceName() + ", persistenceUnit="
-                            + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
-                            + integrityAuditEntity.getLastUpdated() + ", entityIndex=" + entityIndex);
+                            + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+                            + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+                            + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
                 }
                 designatedEntityIndex = entityIndex;
 
@@ -371,9 +379,9 @@ public class AuditThread extends Thread {
 
                     if (logger.isDebugEnabled()) {
                         logger.debug("getDesignationCandidate: Entity is stale; resourceName="
-                                + integrityAuditEntity.getResourceName() + ", persistenceUnit="
-                                + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
-                                + integrityAuditEntity.getLastUpdated() + ", entityIndex=" + entityIndex);
+                                + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+                                + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+                                + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
                     }
 
                     /*
@@ -386,9 +394,9 @@ public class AuditThread extends Thread {
                         if (priorCandidateIndex == -1) {
                             if (logger.isDebugEnabled()) {
                                 logger.debug("getDesignationCandidate: Prior candidate found, resourceName="
-                                        + integrityAuditEntity.getResourceName() + ", persistenceUnit="
-                                        + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
-                                        + integrityAuditEntity.getLastUpdated() + ", entityIndex=" + entityIndex);
+                                        + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+                                        + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+                                        + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
                             }
                             priorCandidateIndex = entityIndex;
                         } else {
@@ -396,18 +404,18 @@ public class AuditThread extends Thread {
                                 logger.debug(
                                         "getDesignationCandidate: Prior entity current but prior candidate already "
                                                 + "found; resourceName=" + integrityAuditEntity.getResourceName()
-                                                + ", persistenceUnit=" + integrityAuditEntity.getPersistenceUnit()
-                                                + ", lastUpdated=" + integrityAuditEntity.getLastUpdated()
-                                                + ", entityIndex=" + entityIndex);
+                                                + PERSISTENCE_MESSAGE + integrityAuditEntity.getPersistenceUnit()
+                                                + LAST_UPDATED_MESSAGE + integrityAuditEntity.getLastUpdated()
+                                                + ENTITY_INDEX_MESSAGE + entityIndex);
                             }
                         }
                     } else {
                         if (subsequentCandidateIndex == -1) {
                             if (logger.isDebugEnabled()) {
                                 logger.debug("getDesignationCandidate: Subsequent candidate found, resourceName="
-                                        + integrityAuditEntity.getResourceName() + ", persistenceUnit="
-                                        + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
-                                        + integrityAuditEntity.getLastUpdated() + ", entityIndex=" + entityIndex);
+                                        + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+                                        + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+                                        + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
                             }
                             subsequentCandidateIndex = entityIndex;
                         } else {
@@ -415,9 +423,9 @@ public class AuditThread extends Thread {
                                 logger.debug(
                                         "getDesignationCandidate: Subsequent entity current but subsequent candidate "
                                                 + "already found; resourceName="
-                                                + integrityAuditEntity.getResourceName() + ", persistenceUnit="
-                                                + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
-                                                + integrityAuditEntity.getLastUpdated() + ", entityIndex="
+                                                + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+                                                + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+                                                + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE
                                                 + entityIndex);
                             }
                         }
@@ -482,8 +490,8 @@ public class AuditThread extends Thread {
             if (integrityAuditEntity.isDesignated()) {
                 if (logger.isDebugEnabled()) {
                     logger.debug("getEntityCurrentlyDesignated: Currently designated entity resourceName="
-                            + integrityAuditEntity.getResourceName() + ", persistenceUnit="
-                            + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
+                            + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+                            + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
                             + integrityAuditEntity.getLastUpdated());
                 }
                 entityCurrentlyDesignated = integrityAuditEntity;
@@ -560,8 +568,8 @@ public class AuditThread extends Thread {
                 if (logger.isDebugEnabled()) {
                     logger.debug(
                             "getThisEntity: For this entity, resourceName=" + integrityAuditEntity.getResourceName()
-                                    + ", persistenceUnit=" + integrityAuditEntity.getPersistenceUnit()
-                                    + ", lastUpdated=" + integrityAuditEntity.getLastUpdated());
+                                    + PERSISTENCE_MESSAGE + integrityAuditEntity.getPersistenceUnit()
+                                    + LAST_UPDATED_MESSAGE + integrityAuditEntity.getLastUpdated());
                 }
                 thisEntity = integrityAuditEntity;
             }
@@ -594,7 +602,7 @@ public class AuditThread extends Thread {
 
         if (logger.isDebugEnabled()) {
             logger.debug("isStale: Entering, resourceName=" + integrityAuditEntity.getResourceName()
-                    + ", persistenceUnit=" + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
+                    + PERSISTENCE_MESSAGE + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
                     + integrityAuditEntity.getLastUpdated());
         }
 
@@ -627,10 +635,10 @@ public class AuditThread extends Thread {
         logger.debug("logIntegrityAuditEntity: id=" + integrityAuditEntity.getId() + ", jdbcDriver="
                 + integrityAuditEntity.getJdbcDriver() + ", jdbcPassword=" + integrityAuditEntity.getJdbcPassword()
                 + ", jdbcUrl=" + integrityAuditEntity.getJdbcUrl() + ", jdbcUser=" + integrityAuditEntity.getJdbcUser()
-                + ", nodeType=" + integrityAuditEntity.getNodeType() + ", persistenceUnit="
+                + ", nodeType=" + integrityAuditEntity.getNodeType() + PERSISTENCE_MESSAGE
                 + integrityAuditEntity.getPersistenceUnit() + ", resourceName=" + integrityAuditEntity.getResourceName()
                 + ", site=" + integrityAuditEntity.getSite() + ", createdDate=" + integrityAuditEntity.getCreatedDate()
-                + ", lastUpdated=" + integrityAuditEntity.getLastUpdated() + ", designated="
+                + LAST_UPDATED_MESSAGE + integrityAuditEntity.getLastUpdated() + ", designated="
                 + integrityAuditEntity.isDesignated());
     }
 
@@ -648,8 +656,8 @@ public class AuditThread extends Thread {
 
         if (logger.isDebugEnabled()) {
             logger.debug("resetAuditCompleted: auditCompleted=" + auditCompleted + "; for thisEntity, resourceName="
-                    + thisEntity.getResourceName() + ", persistenceUnit=" + thisEntity.getPersistenceUnit()
-                    + ", lastUpdated=" + thisEntity.getLastUpdated());
+                    + thisEntity.getResourceName() + PERSISTENCE_MESSAGE + thisEntity.getPersistenceUnit()
+                    + LAST_UPDATED_MESSAGE + thisEntity.getLastUpdated());
         }
 
         long timeDifference;
index ef765f3..611fda9 100644 (file)
@@ -65,6 +65,20 @@ public class DbDAO {
      * Supports designation serialization.
      */
     private static final Object lock = new Object();
+    
+    /*
+     * Common strings.
+     */
+    private static final String RESOURCE_MESSAGE = "Resource: ";
+    private static final String WITH_PERSISTENCE_MESSAGE = " with PersistenceUnit: ";
+    private static final String DBDAO_MESSAGE = "DbDAO: ";
+    private static final String ENCOUNTERED_MESSAGE = "ecountered a problem in execution: ";
+    
+    /*
+     * DB SELECT String.
+     */
+    private static final String SELECT_STRING = "Select i from IntegrityAuditEntity i "
+            + "where i.resourceName=:rn and i.persistenceUnit=:pu";
 
     /**
      * DbDAO Constructor.
@@ -303,7 +317,7 @@ public class DbDAO {
             logger.debug("getIntegrityAuditEntities: Exit, iaeList=" + iaeList);
             return iaeList;
         } catch (Exception e) {
-            String msg = "DbDAO: " + "getIntegrityAuditEntities() " + "ecountered a problem in execution: ";
+            String msg = DBDAO_MESSAGE + "getIntegrityAuditEntities() " + ENCOUNTERED_MESSAGE;
             logger.error(msg, e);
             throw new DbDaoTransactionException(e);
         }
@@ -327,7 +341,7 @@ public class DbDAO {
 
             // if IntegrityAuditEntity entry exists for resourceName and PU, retrieve it
             Query iaequery = em.createQuery(
-                    "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+                    SELECT_STRING);
             iaequery.setParameter("rn", this.resourceName);
             iaequery.setParameter("pu", this.persistenceUnit);
 
@@ -340,12 +354,12 @@ public class DbDAO {
                 iae = (IntegrityAuditEntity) iaeList.get(0);
                 // refresh the object from DB in case cached data was returned
                 em.refresh(iae);
-                logger.info("Resource: " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit
+                logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit
                         + " exists");
             } else {
                 // If it does not exist, log an error
-                logger.error("Attempting to setLastUpdated" + " on an entry that does not exist:" + " resource "
-                        + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit);
+                logger.error("Attempting to setLastUpdated" + " on an entry that does not exist: resource "
+                        + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit);
             }
 
             // close the transaction
@@ -355,7 +369,7 @@ public class DbDAO {
 
             return iae;
         } catch (Exception e) {
-            String msg = "DbDAO: " + "setLastUpdated() " + "ecountered a problem in execution: ";
+            String msg = DBDAO_MESSAGE + "setLastUpdated() " + ENCOUNTERED_MESSAGE;
             logger.error(msg + e);
             throw new DbDaoTransactionException(e);
         }
@@ -385,7 +399,7 @@ public class DbDAO {
 
             return iae;
         } catch (Exception e) {
-            String msg = "DbDAO: " + "getIntegrityAuditEntity() " + "ecountered a problem in execution: ";
+            String msg = DBDAO_MESSAGE + "getIntegrityAuditEntity() " + ENCOUNTERED_MESSAGE;
             logger.error(msg + e);
             throw new DbDaoTransactionException(e);
         }
@@ -428,7 +442,7 @@ public class DbDAO {
             // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not
             // found, create a new entry
             Query iaequery = em.createQuery(
-                    "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+                    SELECT_STRING);
             iaequery.setParameter("rn", this.resourceName);
             iaequery.setParameter("pu", this.persistenceUnit);
 
@@ -442,12 +456,12 @@ public class DbDAO {
                 iae = (IntegrityAuditEntity) iaeList.get(0);
                 // refresh the object from DB in case cached data was returned
                 em.refresh(iae);
-                logger.info("Resource: " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit
+                logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit
                         + " exists and entry be updated");
             } else {
                 // If it does not exist, we also must add teh resourceName, persistenceUnit and
                 // designated values
-                logger.info("Adding resource " + resourceName + " with PersistenceUnit: " + this.persistenceUnit
+                logger.info("Adding resource " + resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit
                         + " to IntegrityAuditEntity table");
                 iae = new IntegrityAuditEntity();
                 iae.setResourceName(this.resourceName);
@@ -470,7 +484,7 @@ public class DbDAO {
             et.commit();
             em.close();
         } catch (Exception e) {
-            String msg = "DbDAO: " + "register() " + "encountered a problem in execution: ";
+            String msg = DBDAO_MESSAGE + "register() " + "encountered a problem in execution: ";
             logger.error(msg + e);
             throw new DbDaoTransactionException(e);
         }
@@ -505,7 +519,7 @@ public class DbDAO {
             // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not
             // found, create a new entry
             Query iaequery = em.createQuery(
-                    "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+                    SELECT_STRING);
             iaequery.setParameter("rn", resourceName);
             iaequery.setParameter("pu", persistenceUnit);
 
@@ -518,7 +532,7 @@ public class DbDAO {
                 iae = (IntegrityAuditEntity) iaeList.get(0);
                 // refresh the object from DB in case cached data was returned
                 em.refresh(iae);
-                logger.info("Resource: " + resourceName + " with PersistenceUnit: " + persistenceUnit
+                logger.info(RESOURCE_MESSAGE + resourceName + WITH_PERSISTENCE_MESSAGE + persistenceUnit
                         + " exists and designated be updated");
                 iae.setDesignated(desig);
 
@@ -528,7 +542,7 @@ public class DbDAO {
             } else {
                 // If it does not exist, log an error
                 logger.error("Attempting to setDesignated(" + desig + ") on an entry that does not exist:"
-                        + " resource " + resourceName + " with PersistenceUnit: " + persistenceUnit);
+                        + " resource " + resourceName + WITH_PERSISTENCE_MESSAGE + persistenceUnit);
             }
 
             // close the transaction
@@ -536,7 +550,7 @@ public class DbDAO {
             // close the EntityManager
             em.close();
         } catch (Exception e) {
-            String msg = "DbDAO: " + "setDesignated() " + "ecountered a problem in execution: ";
+            String msg = DBDAO_MESSAGE + "setDesignated() " + ENCOUNTERED_MESSAGE;
             logger.error(msg + e);
             throw new DbDaoTransactionException(e);
         }
@@ -562,7 +576,7 @@ public class DbDAO {
             // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not
             // found, create a new entry
             Query iaequery = em.createQuery(
-                    "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+                    SELECT_STRING);
             iaequery.setParameter("rn", this.resourceName);
             iaequery.setParameter("pu", this.persistenceUnit);
 
@@ -575,7 +589,7 @@ public class DbDAO {
                 iae = (IntegrityAuditEntity) iaeList.get(0);
                 // refresh the object from DB in case cached data was returned
                 em.refresh(iae);
-                logger.info("Resource: " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit
+                logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit
                         + " exists and lastUpdated be updated");
                 iae.setLastUpdated(AuditorTime.getInstance().getDate());
 
@@ -585,7 +599,7 @@ public class DbDAO {
             } else {
                 // If it does not exist, log an error
                 logger.error("Attempting to setLastUpdated" + " on an entry that does not exist:" + " resource "
-                        + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit);
+                        + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit);
             }
 
             // close the transaction
@@ -593,7 +607,7 @@ public class DbDAO {
             // close the EntityManager
             em.close();
         } catch (Exception e) {
-            String msg = "DbDAO: " + "setLastUpdated() " + "ecountered a problem in execution: ";
+            String msg = DBDAO_MESSAGE + "setLastUpdated() " + ENCOUNTERED_MESSAGE;
             logger.error(msg + e);
             throw new DbDaoTransactionException(e);
         }
@@ -609,7 +623,7 @@ public class DbDAO {
         try {
 
             if (!IntegrityAudit.isUnitTesting()) {
-                String msg = "DbDAO: " + "deleteAllIntegrityAuditEntities() "
+                String msg = DBDAO_MESSAGE + "deleteAllIntegrityAuditEntities() "
                         + "should only be invoked during JUnit testing";
                 logger.error(msg);
                 throw new DbDaoTransactionException(msg);
@@ -636,7 +650,7 @@ public class DbDAO {
             return returnCode;
 
         } catch (Exception e) {
-            String msg = "DbDAO: " + "deleteAllIntegrityAuditEntities() " + "encountered a problem in execution: ";
+            String msg = DBDAO_MESSAGE + "deleteAllIntegrityAuditEntities() " + "encountered a problem in execution: ";
             logger.error(msg + e);
             throw new DbDaoTransactionException(e);
         }
@@ -729,12 +743,12 @@ public class DbDAO {
                 if (em != null) {
                     em.getTransaction().rollback();
 
-                    String msg = "DbDAO: " + "changeDesignated() " + "caught LockTimeoutException, message="
+                    String msg = "DbDAO: changeDesignated() caught LockTimeoutException, message="
                             + e.getMessage();
                     logger.error(msg + e);
                     throw new DbDaoTransactionException(msg, e);
                 } else {
-                    String msg = "DbDAO: " + "changeDesignated() " + "caught LockTimeoutException, message="
+                    String msg = "DbDAO: changeDesignated() caught LockTimeoutException, message="
                             + e.getMessage() + ". Error rolling back transaction.";
                     logger.error(msg + e);
                     throw new DbDaoTransactionException(msg, e);
@@ -743,11 +757,11 @@ public class DbDAO {
                 if (em != null) {
                     em.getTransaction().rollback();
 
-                    String msg = "DbDAO: " + "changeDesignated() " + "caught Exception, message=" + e.getMessage();
+                    String msg = "DbDAO: changeDesignated() caught Exception, message=" + e.getMessage();
                     logger.error(msg + e);
                     throw new DbDaoTransactionException(msg, e);
                 } else {
-                    String msg = "DbDAO: " + "changeDesignated() " + "caught LockTimeoutException, message="
+                    String msg = "DbDAO: changeDesignated() caught Exception, message="
                             + e.getMessage() + ". Error rolling back transaction.";
                     logger.error(msg + e);
                     throw new DbDaoTransactionException(msg, e);
index 9845fc7..4298e7c 100644 (file)
@@ -58,6 +58,23 @@ public class IntegrityMonitor {
     // only allow one instance of IntegrityMonitor
     private static IntegrityMonitor instance = null;
     
+    /*
+     * Common strings
+     */
+    private static final String NULL_PROPERTY_STRING = " property is null";
+    private static final String IGNORE_INVALID_PROPERTY_STRING = "Ignored invalid property: {}";
+    private static final String PROPERTY_EXCEPTION_STRING = "IntegrityMonitor Property Exception: ";
+    private static final String EXCEPTION_STRING = "IntegrityMonitor threw exception.";
+    private static final String STATE_CHECK_STRING = "IntegrityMonitor.stateCheck(): "
+            + "Failed to diableFail dependent resource = ";
+    private static final String RESOURCE_STRING = "Resource ";
+    private static final String LC_RESOURCE_STRING = "resource";
+    
+    /*
+     * Query String
+     */
+    private static final String QUERY_STRING = "Select f from ForwardProgressEntity f where f.resourceName=:rn";
+    
     // may be changed by junit tests
     private static Factory factory = new Factory();
 
@@ -229,7 +246,7 @@ public class IntegrityMonitor {
         try {
             // if ForwardProgress entry exists for resourceName, update it. If
             // not found, create a new entry
-            Query fquery = em.createQuery("Select f from ForwardProgressEntity f where f.resourceName=:rn");
+            Query fquery = em.createQuery(QUERY_STRING);
             fquery.setParameter("rn", resourceName);
 
             @SuppressWarnings("rawtypes")
@@ -476,21 +493,21 @@ public class IntegrityMonitor {
             logger.debug("evaluateSanity dependencyCheckErrorMsg = {}", errorMsg);
             // check op state and throw exception if disabled
             if ((stateManager.getOpState() != null) && stateManager.getOpState().equals(StateManagement.DISABLED)) {
-                String msg = "Resource " + resourceName + " operation state is disabled. " + errorMsg;
+                String msg = RESOURCE_STRING + resourceName + " operation state is disabled. " + errorMsg;
                 logger.debug("{}", msg);
                 throw new IntegrityMonitorException(msg);
             }
 
             // check admin state and throw exception if locked
             if ((stateManager.getAdminState() != null) && stateManager.getAdminState().equals(StateManagement.LOCKED)) {
-                String msg = "Resource " + resourceName + " is administratively locked";
+                String msg = RESOURCE_STRING + resourceName + " is administratively locked";
                 logger.debug("{}", msg);
                 throw new AdministrativeStateException("IntegrityMonitor Admin State Exception: " + msg);
             }
             // check standby state and throw exception if cold standby
             if ((stateManager.getStandbyStatus() != null)
                     && stateManager.getStandbyStatus().equals(StateManagement.COLD_STANDBY)) {
-                String msg = "Resource " + resourceName + " is cold standby";
+                String msg = RESOURCE_STRING + resourceName + " is cold standby";
                 logger.debug("{}", msg);
                 throw new StandbyStatusException("IntegrityMonitor Standby Status Exception: " + msg);
             }
@@ -519,7 +536,7 @@ public class IntegrityMonitor {
 
         try {
             Query query = em.createQuery("Select p from ForwardProgressEntity p where p.resourceName=:resource");
-            query.setParameter("resource", dep);
+            query.setParameter(LC_RESOURCE_STRING, dep);
 
             @SuppressWarnings("rawtypes")
             List fpList = query.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
@@ -555,7 +572,7 @@ public class IntegrityMonitor {
             try {
                 // query if StateManagement entry exists for dependent resource
                 Query query = em.createQuery("Select p from StateManagementEntity p where p.resourceName=:resource");
-                query.setParameter("resource", dep);
+                query.setParameter(LC_RESOURCE_STRING, dep);
 
                 @SuppressWarnings("rawtypes")
                 List smList = query.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
@@ -605,7 +622,7 @@ public class IntegrityMonitor {
                             stateManager.disableFailed(dep);
                         }
                     } catch (Exception e) {
-                        String msg = "IntegrityMonitor.stateCheck(): Failed to diableFail dependent resource = " + dep
+                        String msg = STATE_CHECK_STRING + dep
                                 + "; " + e.getMessage();
                         logger.error("{}", msg, e);
                     }
@@ -613,13 +630,13 @@ public class IntegrityMonitor {
             } else {
 
                 if (forwardProgressEntity == null) {
-                    String msg = "IntegrityMonitor.stateCheck(): Failed to diableFail dependent resource = " + dep
+                    String msg = STATE_CHECK_STRING + dep
                             + "; " + " forwardProgressEntity == null.";
                     logger.error("{}", msg);
                 }
 
                 else {
-                    String msg = "IntegrityMonitor.stateCheck(): Failed to diableFail dependent resource = " + dep
+                    String msg = STATE_CHECK_STRING + dep
                             + "; " + " stateManagementEntity == null.";
                     logger.error("{}", msg);
                 }
@@ -665,7 +682,7 @@ public class IntegrityMonitor {
         EntityTransaction et = em.getTransaction();
         et.begin();
         try {
-            Query fquery = em.createQuery("Select f from ForwardProgressEntity f where f.resourceName=:rn");
+            Query fquery = em.createQuery(QUERY_STRING);
             fquery.setParameter("rn", dep);
 
             @SuppressWarnings("rawtypes")
@@ -876,7 +893,7 @@ public class IntegrityMonitor {
                     errorMsg = errorMsg.concat(resourceName + ": " + e.getMessage());
                     this.stateManager.disableDependency();
                 } catch (Exception ex) {
-                    logger.error("IntegrityMonitor threw exception.", ex);
+                    logger.error(EXCEPTION_STRING, ex);
                     if (!errorMsg.isEmpty()) {
                         errorMsg = errorMsg.concat(",");
                     }
@@ -940,7 +957,7 @@ public class IntegrityMonitor {
                                 this.stateManager.disableDependency();
                             }
                         } catch (Exception e) {
-                            logger.error("IntegrityMonitor threw exception.", e);
+                            logger.error(EXCEPTION_STRING, e);
                             if (!errorMsg.isEmpty()) {
                                 errorMsg = errorMsg.concat(",");
                             }
@@ -971,7 +988,7 @@ public class IntegrityMonitor {
                         // The refreshStateAudit will catch the case where it is disabled but
                         // availStatus != failed
                     } catch (Exception e) {
-                        logger.error("IntegrityMonitor threw exception.", e);
+                        logger.error(EXCEPTION_STRING, e);
                         if (!errorMsg.isEmpty()) {
                             errorMsg = errorMsg.concat(",");
                         }
@@ -996,7 +1013,7 @@ public class IntegrityMonitor {
                     // The refreshStateAudit will catch the case where it is disabled but
                     // availStatus != failed
                 } catch (Exception e) {
-                    logger.error("IntegrityMonitor threw exception.", e);
+                    logger.error(EXCEPTION_STRING, e);
                     if (!errorMsg.isEmpty()) {
                         errorMsg = errorMsg.concat(",");
                     }
@@ -1054,7 +1071,7 @@ public class IntegrityMonitor {
         synchronized (startTransactionLock) {
             // check admin state and throw exception if locked
             if ((stateManager.getAdminState() != null) && stateManager.getAdminState().equals(StateManagement.LOCKED)) {
-                String msg = "Resource " + resourceName + " is administratively locked";
+                String msg = RESOURCE_STRING + resourceName + " is administratively locked";
 
                 throw new AdministrativeStateException("IntegrityMonitor Admin State Exception: " + msg);
             }
@@ -1063,7 +1080,7 @@ public class IntegrityMonitor {
             if ((stateManager.getStandbyStatus() != null)
                     && (stateManager.getStandbyStatus().equals(StateManagement.HOT_STANDBY)
                             || stateManager.getStandbyStatus().equals(StateManagement.COLD_STANDBY))) {
-                String msg = "Resource " + resourceName + " is standby";
+                String msg = RESOURCE_STRING + resourceName + " is standby";
 
                 throw new StandbyStatusException("IntegrityMonitor Standby Status Exception: " + msg);
             }
@@ -1093,19 +1110,14 @@ public class IntegrityMonitor {
                             + "progress counter. \n{}\n", msg);
                     return;
                 } else {
-                    if (logger.isDebugEnabled()) {
-                        if (getAllSeemsWellMap() != null) {
-                            if (!(getAllSeemsWellMap().isEmpty())) {
-                                String msg = "allSeemsWellMap:";
-                                for (Entry<String, String> entry : allSeemsWellMap.entrySet()) {
-                                    msg = msg.concat("\nkey = " + entry.getKey() + " msg = " + entry.getValue());
-                                }
-                                logger.debug(
-                                        "endTransaction: allNotWellMap IS EMPTY and allSeemsWellMap is NOT EMPTY.  "
-                                                + "Advancing forward progress counter. \n{}\n",
-                                        msg);
-                            }
+                    if (logger.isDebugEnabled() && getAllSeemsWellMap() != null && !(getAllSeemsWellMap().isEmpty())) {
+                        String msg = "allSeemsWellMap:";
+                        for (Entry<String, String> entry : allSeemsWellMap.entrySet()) {
+                            msg = msg.concat("\nkey = " + entry.getKey() + " msg = " + entry.getValue());
                         }
+                        logger.debug(
+                                "endTransaction: allNotWellMap IS EMPTY and allSeemsWellMap is NOT EMPTY.  "
+                                        + "Advancing forward progress counter. \n{}\n", msg);
                     }
                 }
             }
@@ -1126,7 +1138,7 @@ public class IntegrityMonitor {
 
         try {
             // query if ForwardProgress entry exists for resourceName
-            Query fquery = em.createQuery("Select f from ForwardProgressEntity f where f.resourceName=:rn");
+            Query fquery = em.createQuery(QUERY_STRING);
             fquery.setParameter("rn", resourceName);
 
             @SuppressWarnings("rawtypes")
@@ -1160,7 +1172,7 @@ public class IntegrityMonitor {
                     }
                 }
             } catch (Exception e1) {
-                logger.error("IntegrityMonitor threw exception.", e1);
+                logger.error(EXCEPTION_STRING, e1);
             }
             logger.error("writeFpc DB table commit failed with exception: {}", e);
             throw e;
@@ -1180,27 +1192,27 @@ public class IntegrityMonitor {
     private static void validateProperties(Properties prop) throws IntegrityMonitorPropertiesException {
 
         if (prop.getProperty(IntegrityMonitorProperties.DB_DRIVER) == null) {
-            String msg = IntegrityMonitorProperties.DB_DRIVER + " property is null";
+            String msg = IntegrityMonitorProperties.DB_DRIVER + NULL_PROPERTY_STRING;
             logger.error("{}", msg);
-            throw new IntegrityMonitorPropertiesException("IntegrityMonitor Property Exception: " + msg);
+            throw new IntegrityMonitorPropertiesException(PROPERTY_EXCEPTION_STRING + msg);
         }
 
         if (prop.getProperty(IntegrityMonitorProperties.DB_URL) == null) {
-            String msg = IntegrityMonitorProperties.DB_URL + " property is null";
+            String msg = IntegrityMonitorProperties.DB_URL + NULL_PROPERTY_STRING;
             logger.error("{}", msg);
-            throw new IntegrityMonitorPropertiesException("IntegrityMonitor Property Exception: " + msg);
+            throw new IntegrityMonitorPropertiesException(PROPERTY_EXCEPTION_STRING + msg);
         }
 
         if (prop.getProperty(IntegrityMonitorProperties.DB_USER) == null) {
-            String msg = IntegrityMonitorProperties.DB_USER + " property is null";
+            String msg = IntegrityMonitorProperties.DB_USER + NULL_PROPERTY_STRING;
             logger.error("{}", msg);
-            throw new IntegrityMonitorPropertiesException("IntegrityMonitor Property Exception: " + msg);
+            throw new IntegrityMonitorPropertiesException(PROPERTY_EXCEPTION_STRING + msg);
         }
 
         if (prop.getProperty(IntegrityMonitorProperties.DB_PWD) == null) {
-            String msg = IntegrityMonitorProperties.DB_PWD + " property is null";
+            String msg = IntegrityMonitorProperties.DB_PWD + NULL_PROPERTY_STRING;
             logger.error("{}", msg);
-            throw new IntegrityMonitorPropertiesException("IntegrityMonitor Property Exception: " + msg);
+            throw new IntegrityMonitorPropertiesException(PROPERTY_EXCEPTION_STRING + msg);
         }
 
         if (prop.getProperty(IntegrityMonitorProperties.FP_MONITOR_INTERVAL) != null) {
@@ -1208,7 +1220,7 @@ public class IntegrityMonitor {
                 monitorIntervalMs = toMillis(
                         Integer.parseInt(prop.getProperty(IntegrityMonitorProperties.FP_MONITOR_INTERVAL).trim()));
             } catch (NumberFormatException e) {
-                logger.warn("Ignored invalid property: {}", IntegrityMonitorProperties.FP_MONITOR_INTERVAL, e);
+                logger.warn(IGNORE_INVALID_PROPERTY_STRING, IntegrityMonitorProperties.FP_MONITOR_INTERVAL, e);
             }
         }
 
@@ -1217,7 +1229,7 @@ public class IntegrityMonitor {
                 failedCounterThreshold =
                         Integer.parseInt(prop.getProperty(IntegrityMonitorProperties.FAILED_COUNTER_THRESHOLD).trim());
             } catch (NumberFormatException e) {
-                logger.warn("Ignored invalid property: {}", IntegrityMonitorProperties.FAILED_COUNTER_THRESHOLD, e);
+                logger.warn(IGNORE_INVALID_PROPERTY_STRING, IntegrityMonitorProperties.FAILED_COUNTER_THRESHOLD, e);
             }
         }
 
@@ -1226,7 +1238,7 @@ public class IntegrityMonitor {
                 testTransIntervalMs = toMillis(
                         Integer.parseInt(prop.getProperty(IntegrityMonitorProperties.TEST_TRANS_INTERVAL).trim()));
             } catch (NumberFormatException e) {
-                logger.warn("Ignored invalid property: {}", IntegrityMonitorProperties.TEST_TRANS_INTERVAL, e);
+                logger.warn(IGNORE_INVALID_PROPERTY_STRING, IntegrityMonitorProperties.TEST_TRANS_INTERVAL, e);
             }
         }
 
@@ -1235,7 +1247,7 @@ public class IntegrityMonitor {
                 writeFpcIntervalMs = toMillis(
                         Integer.parseInt(prop.getProperty(IntegrityMonitorProperties.WRITE_FPC_INTERVAL).trim()));
             } catch (NumberFormatException e) {
-                logger.warn("Ignored invalid property: {}", IntegrityMonitorProperties.WRITE_FPC_INTERVAL, e);
+                logger.warn(IGNORE_INVALID_PROPERTY_STRING, IntegrityMonitorProperties.WRITE_FPC_INTERVAL, e);
             }
         }
 
@@ -1244,7 +1256,7 @@ public class IntegrityMonitor {
                 checkDependencyIntervalMs = toMillis(Integer
                         .parseInt(prop.getProperty(IntegrityMonitorProperties.CHECK_DEPENDENCY_INTERVAL).trim()));
             } catch (NumberFormatException e) {
-                logger.warn("Ignored invalid property: {}", IntegrityMonitorProperties.CHECK_DEPENDENCY_INTERVAL, e);
+                logger.warn(IGNORE_INVALID_PROPERTY_STRING, IntegrityMonitorProperties.CHECK_DEPENDENCY_INTERVAL, e);
             }
         }
 
@@ -1259,30 +1271,30 @@ public class IntegrityMonitor {
                     logger.debug("dependency groups property = {}", Arrays.toString(depGroups));
                 }
             } catch (Exception e) {
-                logger.warn("Ignored invalid property: {}", IntegrityMonitorProperties.DEPENDENCY_GROUPS, e);
+                logger.warn(IGNORE_INVALID_PROPERTY_STRING, IntegrityMonitorProperties.DEPENDENCY_GROUPS, e);
             }
         }
 
         siteName = prop.getProperty(IntegrityMonitorProperties.SITE_NAME);
         if (siteName == null) {
-            String msg = IntegrityMonitorProperties.SITE_NAME + " property is null";
+            String msg = IntegrityMonitorProperties.SITE_NAME + NULL_PROPERTY_STRING;
             logger.error("{}", msg);
-            throw new IntegrityMonitorPropertiesException("IntegrityMonitor Property Exception: " + msg);
+            throw new IntegrityMonitorPropertiesException(PROPERTY_EXCEPTION_STRING + msg);
         } else {
             siteName = siteName.trim();
         }
 
         nodeType = prop.getProperty(IntegrityMonitorProperties.NODE_TYPE);
         if (nodeType == null) {
-            String msg = IntegrityMonitorProperties.NODE_TYPE + " property is null";
+            String msg = IntegrityMonitorProperties.NODE_TYPE + NULL_PROPERTY_STRING;
             logger.error("{}", msg);
-            throw new IntegrityMonitorPropertiesException("IntegrityMonitor Property Exception: " + msg);
+            throw new IntegrityMonitorPropertiesException(PROPERTY_EXCEPTION_STRING + msg);
         } else {
             nodeType = nodeType.trim();
             if (!isNodeTypeEnum(nodeType)) {
                 String msg = IntegrityMonitorProperties.NODE_TYPE + " property " + nodeType + " is invalid";
                 logger.error("{}", msg);
-                throw new IntegrityMonitorPropertiesException("IntegrityMonitor Property Exception: " + msg);
+                throw new IntegrityMonitorPropertiesException(PROPERTY_EXCEPTION_STRING + msg);
             }
         }
 
@@ -1303,7 +1315,7 @@ public class IntegrityMonitor {
                 maxFpcUpdateIntervalMs = toMillis(
                         Integer.parseInt(prop.getProperty(IntegrityMonitorProperties.MAX_FPC_UPDATE_INTERVAL).trim()));
             } catch (NumberFormatException e) {
-                logger.warn("Ignored invalid property: {}", IntegrityMonitorProperties.MAX_FPC_UPDATE_INTERVAL, e);
+                logger.warn(IGNORE_INVALID_PROPERTY_STRING, IntegrityMonitorProperties.MAX_FPC_UPDATE_INTERVAL, e);
             }
         }
 
@@ -1312,7 +1324,7 @@ public class IntegrityMonitor {
                 stateAuditIntervalMs =
                         Long.parseLong(prop.getProperty(IntegrityMonitorProperties.STATE_AUDIT_INTERVAL_MS));
             } catch (NumberFormatException e) {
-                logger.warn("Ignored invalid property: {}", IntegrityMonitorProperties.STATE_AUDIT_INTERVAL_MS, e);
+                logger.warn(IGNORE_INVALID_PROPERTY_STRING, IntegrityMonitorProperties.STATE_AUDIT_INTERVAL_MS, e);
             }
         }
 
@@ -1321,15 +1333,13 @@ public class IntegrityMonitor {
                 refreshStateAuditIntervalMs =
                         Long.parseLong(prop.getProperty(IntegrityMonitorProperties.REFRESH_STATE_AUDIT_INTERVAL_MS));
             } catch (NumberFormatException e) {
-                logger.warn("Ignored invalid property: {}", IntegrityMonitorProperties.REFRESH_STATE_AUDIT_INTERVAL_MS,
+                logger.warn(IGNORE_INVALID_PROPERTY_STRING, IntegrityMonitorProperties.REFRESH_STATE_AUDIT_INTERVAL_MS,
                         e);
             }
         }
 
-        logger.debug("IntegrityMonitor.validateProperties(): Property values \n" + "maxFpcUpdateIntervalMs = {}\n",
+        logger.debug("IntegrityMonitor.validateProperties(): Property values \nmaxFpcUpdateIntervalMs = {}\n",
                 maxFpcUpdateIntervalMs);
-
-        return;
     }
 
     /**
@@ -1342,7 +1352,7 @@ public class IntegrityMonitor {
             try {
                 validateProperties(newprop);
             } catch (IntegrityMonitorPropertiesException e) {
-                logger.error("IntegrityMonitor threw exception.", e);
+                logger.error(EXCEPTION_STRING, e);
             }
         } else {
             logger.debug("Update integrity monitor properties not allowed");
@@ -1441,11 +1451,10 @@ public class IntegrityMonitor {
             return;
         }
         if (!stateManager.getStandbyStatus().equals(StateManagement.NULL_VALUE)
-                && stateManager.getStandbyStatus() != null) {
-            if (!stateManager.getStandbyStatus().equals(StateManagement.PROVIDING_SERVICE)) {
-                logger.debug("IntegrityMonitor.stateAudit(): NOT PROVIDING_SERVICE. returning");
-                return;
-            }
+            && stateManager.getStandbyStatus() != null
+            && !stateManager.getStandbyStatus().equals(StateManagement.PROVIDING_SERVICE)) {
+            logger.debug("IntegrityMonitor.stateAudit(): NOT PROVIDING_SERVICE. returning");
+            return;
         }
 
         Date date = MonitorTime.getInstance().getDate();
@@ -1496,7 +1505,8 @@ public class IntegrityMonitor {
             if (diffMs > staleMs) {
                 // ForwardProgress is stale. Disable it
                 // Start a transaction
-                logger.debug("IntegrityMonitor.executeStateAudit(): resource = {}, FPC is stale. Disabling it");
+                logger.debug("IntegrityMonitor.executeStateAudit(): resource = {}, FPC is stale. Disabling it", 
+                        fpe.getResourceName());
                 EntityTransaction et = em.getTransaction();
                 et.begin();
                 StateManagementEntity sme = null;
@@ -1504,7 +1514,7 @@ public class IntegrityMonitor {
                     // query if StateManagement entry exists for fpe resource
                     Query query =
                             em.createQuery("Select p from StateManagementEntity p where p.resourceName=:resource");
-                    query.setParameter("resource", fpe.getResourceName());
+                    query.setParameter(LC_RESOURCE_STRING, fpe.getResourceName());
 
                     @SuppressWarnings("rawtypes")
                     List smList =
@@ -1609,7 +1619,7 @@ public class IntegrityMonitor {
             try {
                 writeFpc();
             } catch (Exception e) {
-                logger.error("IntegrityMonitor threw exception.", e);
+                logger.error(EXCEPTION_STRING, e);
             }
         }
         logger.debug("checkWriteFpc(): exit");
@@ -1722,7 +1732,7 @@ public class IntegrityMonitor {
                 }
 
             } catch (InterruptedException e) {
-                logger.debug("IntegrityMonitor threw exception.", e);
+                logger.debug(EXCEPTION_STRING, e);
                 Thread.currentThread().interrupt();
             }
         }
index 8589170..4cdbe6b 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * Integrity Monitor
  * ================================================================================
- * 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.
@@ -22,8 +22,6 @@ package org.onap.policy.common.im;
 
 public class IntegrityMonitorProperties {
 
-    private IntegrityMonitorProperties() {}
-
     public static final String DB_DRIVER = "javax.persistence.jdbc.driver";
     public static final String DB_URL = "javax.persistence.jdbc.url";
     public static final String DB_USER = "javax.persistence.jdbc.user";
@@ -57,5 +55,6 @@ public class IntegrityMonitorProperties {
     public static final Boolean ALLNOTWELL = Boolean.FALSE;
     public static final Boolean ALLSEEMSWELL = Boolean.TRUE;
 
+    private IntegrityMonitorProperties() {}
 
 }
index 20bf9b0..35b33be 100644 (file)
@@ -45,6 +45,7 @@ public class StateManagement extends Observable {
     private static final String RESOURCE_NAME = "resource";
     private static final String GET_STATE_MANAGEMENT_ENTITY_QUERY =
             "Select p from StateManagementEntity p where p.resourceName=:" + RESOURCE_NAME;
+    private static final String FIND_MESSAGE = "findStateManagementEntity for {}";
     private static final Logger logger = LoggerFactory.getLogger(StateManagement.class);
     public static final String LOCKED = "locked";
     public static final String UNLOCKED = "unlocked";
@@ -118,7 +119,7 @@ public class StateManagement extends Observable {
             try {
                 // Create a StateManagementEntity object
                 if (logger.isDebugEnabled()) {
-                    logger.debug("findStateManagementEntity for {}", this.resourceName);
+                    logger.debug(FIND_MESSAGE, this.resourceName);
                 }
                 final StateManagementEntity sm = findStateManagementEntity(em, this.resourceName);
 
@@ -161,7 +162,7 @@ public class StateManagement extends Observable {
             try (EntityMgrCloser emc = new EntityMgrCloser(em); MyTransaction et = new MyTransaction(em)) {
 
                 if (logger.isDebugEnabled()) {
-                    logger.debug("findStateManagementEntity for {}", this.resourceName);
+                    logger.debug(FIND_MESSAGE, this.resourceName);
                 }
                 final StateManagementEntity sm = findStateManagementEntity(em, this.resourceName);
                 // set state
@@ -202,7 +203,7 @@ public class StateManagement extends Observable {
             try (EntityMgrCloser emc = new EntityMgrCloser(em); MyTransaction et = new MyTransaction(em)) {
 
                 if (logger.isDebugEnabled()) {
-                    logger.debug("findStateManagementEntity for {}", this.resourceName);
+                    logger.debug(FIND_MESSAGE, this.resourceName);
                 }
                 final StateManagementEntity sm = findStateManagementEntity(em, this.resourceName);
 
@@ -246,7 +247,7 @@ public class StateManagement extends Observable {
             try (EntityMgrCloser emc = new EntityMgrCloser(em); MyTransaction et = new MyTransaction(em)) {
 
                 if (logger.isDebugEnabled()) {
-                    logger.debug("findStateManagementEntity for {}", this.resourceName);
+                    logger.debug(FIND_MESSAGE, this.resourceName);
                 }
                 final StateManagementEntity sm = findStateManagementEntity(em, this.resourceName);
                 final StateElement stateElement = st.getEndingState(sm.getAdminState(), sm.getOpState(),
@@ -291,7 +292,7 @@ public class StateManagement extends Observable {
             try (EntityMgrCloser emc = new EntityMgrCloser(em); MyTransaction et = new MyTransaction(em)) {
 
                 if (logger.isDebugEnabled()) {
-                    logger.debug("findStateManagementEntity for {}", this.resourceName);
+                    logger.debug(FIND_MESSAGE, this.resourceName);
                 }
                 final StateManagementEntity sm = findStateManagementEntity(em, this.resourceName);
                 final StateElement stateElement = st.getEndingState(sm.getAdminState(), sm.getOpState(),
@@ -338,7 +339,7 @@ public class StateManagement extends Observable {
             try (EntityMgrCloser emc = new EntityMgrCloser(em); MyTransaction et = new MyTransaction(em)) {
 
                 if (logger.isDebugEnabled()) {
-                    logger.debug("findStateManagementEntity for {}", this.resourceName);
+                    logger.debug(FIND_MESSAGE, this.resourceName);
                 }
                 final StateManagementEntity sm = findStateManagementEntity(em, this.resourceName);
                 final StateElement stateElement = st.getEndingState(sm.getAdminState(), sm.getOpState(),
@@ -389,7 +390,7 @@ public class StateManagement extends Observable {
             try (EntityMgrCloser emc = new EntityMgrCloser(em); MyTransaction et = new MyTransaction(em)) {
 
                 if (logger.isDebugEnabled()) {
-                    logger.debug("findStateManagementEntity for " + otherResourceName);
+                    logger.debug(FIND_MESSAGE, otherResourceName);
                 }
                 final StateManagementEntity sm = findStateManagementEntity(em, otherResourceName);
                 final StateElement stateElement = st.getEndingState(sm.getAdminState(), sm.getOpState(),
@@ -436,7 +437,7 @@ public class StateManagement extends Observable {
             try (EntityMgrCloser emc = new EntityMgrCloser(em); MyTransaction et = new MyTransaction(em)) {
 
                 if (logger.isDebugEnabled()) {
-                    logger.debug("findStateManagementEntity for {}", this.resourceName);
+                    logger.debug(FIND_MESSAGE, this.resourceName);
                 }
                 final StateManagementEntity sm = findStateManagementEntity(em, this.resourceName);
                 final StateElement stateElement = st.getEndingState(sm.getAdminState(), sm.getOpState(),
@@ -482,7 +483,7 @@ public class StateManagement extends Observable {
             try (EntityMgrCloser emc = new EntityMgrCloser(em); MyTransaction et = new MyTransaction(em)) {
 
                 if (logger.isDebugEnabled()) {
-                    logger.debug("findStateManagementEntity for {}", this.resourceName);
+                    logger.debug(FIND_MESSAGE, this.resourceName);
                 }
                 final StateManagementEntity sm = findStateManagementEntity(em, this.resourceName);
                 final StateElement stateElement = st.getEndingState(sm.getAdminState(), sm.getOpState(),
@@ -530,7 +531,7 @@ public class StateManagement extends Observable {
             try (EntityMgrCloser emc = new EntityMgrCloser(em); MyTransaction et = new MyTransaction(em)) {
 
                 if (logger.isDebugEnabled()) {
-                    logger.debug("findStateManagementEntity for {}", this.resourceName);
+                    logger.debug(FIND_MESSAGE, this.resourceName);
                 }
                 sm = findStateManagementEntity(em, this.resourceName);
                 final StateElement stateElement = st.getEndingState(sm.getAdminState(), sm.getOpState(),
@@ -551,7 +552,7 @@ public class StateManagement extends Observable {
             }
 
             if (logger.isDebugEnabled()) {
-                logger.debug("StateManagement: promote() operation completed, resourceName = ", this.resourceName);
+                logger.debug("StateManagement: promote() operation completed, resourceName = {}", this.resourceName);
             }
             if (sm.getStandbyStatus().equals(StateManagement.COLD_STANDBY)) {
                 final String msg =
@@ -569,15 +570,17 @@ public class StateManagement extends Observable {
     public void demote() throws StateManagementException {
         synchronized (SYNCLOCK) {
             if (logger.isDebugEnabled()) {
-                logger.debug("\nStateManagement: SYNCLOCK demote() operation for resourceName = \n", this.resourceName);
-                logger.debug("StateManagement: demote() operation started, resourceName = {}", this.resourceName);
+                logger.debug("\nStateManagement: SYNCLOCK demote() operation for resourceName = {}\n", 
+                        this.resourceName);
+                logger.debug("StateManagement: demote() operation started, resourceName = {}", 
+                        this.resourceName);
             }
             final EntityManager em = emf.createEntityManager();
 
             try (EntityMgrCloser emc = new EntityMgrCloser(em); MyTransaction et = new MyTransaction(em)) {
 
                 if (logger.isDebugEnabled()) {
-                    logger.debug("findStateManagementEntity for {}", this.resourceName);
+                    logger.debug(FIND_MESSAGE, this.resourceName);
                 }
                 final StateManagementEntity sm = findStateManagementEntity(em, this.resourceName);
                 final StateElement stateElement = st.getEndingState(sm.getAdminState(), sm.getOpState(),
index 6ff869f..a921b3e 100644 (file)
@@ -39,6 +39,15 @@ public class StateTransition {
     public static final String AVAILABLE_STATUS = "availStatus";
     public static final String STANDBY_STATUS = "standbyStatus";
     public static final String ACTOIN_NAME = "actionName";
+    
+    /*
+     * Common strings.
+     */
+    private static final String EXCEPTION_STRING = "Exception:StateTransition unable to process state: adminState=[";
+    private static final String OPSTATE_STRING = "], opState=[";
+    private static final String AVAILSTATUS_STRING = "], availStatus=[";
+    private static final String STANDBY_STRING = "], standbyStatus=[";
+    private static final String ACTION_STRING = "], actionName=[";
 
     private HashMap<String, String> stateTable = new HashMap<>();
 
@@ -91,38 +100,38 @@ public class StateTransition {
             standbyStatus = "null";
         }
         if (adminState == null || opState == null || actionName == null) {
-            throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=["
-                    + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=["
-                    + standbyStatus + "], actionName=[" + actionName + "]");
+            throw new StateTransitionException(EXCEPTION_STRING
+                    + adminState + OPSTATE_STRING + opState + AVAILSTATUS_STRING + availStatus + STANDBY_STRING
+                    + standbyStatus + ACTION_STRING + actionName + "]");
         } else if (!(adminState.equals(StateManagement.LOCKED) || adminState.equals(StateManagement.UNLOCKED))) {
-            throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=["
-                    + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=["
-                    + standbyStatus + "], actionName=[" + actionName + "]");
+            throw new StateTransitionException(EXCEPTION_STRING
+                    + adminState + OPSTATE_STRING + opState + AVAILSTATUS_STRING + availStatus + STANDBY_STRING
+                    + standbyStatus + ACTION_STRING + actionName + "]");
         } else if (!(opState.equals(StateManagement.ENABLED) || opState.equals(StateManagement.DISABLED))) {
-            throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=["
-                    + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=["
-                    + standbyStatus + "], actionName=[" + actionName + "]");
+            throw new StateTransitionException(EXCEPTION_STRING
+                    + adminState + OPSTATE_STRING + opState + AVAILSTATUS_STRING + availStatus + STANDBY_STRING
+                    + standbyStatus + ACTION_STRING + actionName + "]");
         } else if (!(standbyStatus.equals(StateManagement.NULL_VALUE)
                 || standbyStatus.equals(StateManagement.COLD_STANDBY)
                 || standbyStatus.equals(StateManagement.HOT_STANDBY)
                 || standbyStatus.equals(StateManagement.PROVIDING_SERVICE))) {
-            throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=["
-                    + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=["
-                    + standbyStatus + "], actionName=[" + actionName + "]");
+            throw new StateTransitionException(EXCEPTION_STRING
+                    + adminState + OPSTATE_STRING + opState + AVAILSTATUS_STRING + availStatus + STANDBY_STRING
+                    + standbyStatus + ACTION_STRING + actionName + "]");
         } else if (!(availStatus.equals(StateManagement.NULL_VALUE) || availStatus.equals(StateManagement.DEPENDENCY)
                 || availStatus.equals(StateManagement.DEPENDENCY_FAILED)
                 || availStatus.equals(StateManagement.FAILED))) {
-            throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=["
-                    + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=["
-                    + standbyStatus + "], actionName=[" + actionName + "]");
+            throw new StateTransitionException(EXCEPTION_STRING
+                    + adminState + OPSTATE_STRING + opState + AVAILSTATUS_STRING + availStatus + STANDBY_STRING
+                    + standbyStatus + ACTION_STRING + actionName + "]");
         } else if (!(actionName.equals(StateManagement.DEMOTE) || actionName.equals(StateManagement.DISABLE_DEPENDENCY)
                 || actionName.equals(StateManagement.DISABLE_FAILED)
                 || actionName.equals(StateManagement.ENABLE_NO_DEPENDENCY)
                 || actionName.equals(StateManagement.ENABLE_NOT_FAILED) || actionName.equals(StateManagement.LOCK)
                 || actionName.equals(StateManagement.PROMOTE) || actionName.equals(StateManagement.UNLOCK))) {
-            throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=["
-                    + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=["
-                    + standbyStatus + "], actionName=[" + actionName + "]");
+            throw new StateTransitionException(EXCEPTION_STRING
+                    + adminState + OPSTATE_STRING + opState + AVAILSTATUS_STRING + availStatus + STANDBY_STRING
+                    + standbyStatus + ACTION_STRING + actionName + "]");
         }
 
         StateElement stateElement = new StateElement();
@@ -158,8 +167,8 @@ public class StateTransition {
                 }
 
             } else {
-                String msg = "Ending state not found, adminState=[" + adminState + "], opState=[" + opState
-                        + "], availStatus=[" + availStatus + "], standbyStatus=[" + standbyStatus + "], actionName=["
+                String msg = "Ending state not found, adminState=[" + adminState + OPSTATE_STRING + opState
+                        + AVAILSTATUS_STRING + availStatus + STANDBY_STRING + standbyStatus + ACTION_STRING
                         + actionName + "]";
                 logger.error("{}", msg);
                 throw new StateTransitionException(msg);
@@ -167,8 +176,8 @@ public class StateTransition {
         } catch (Exception ex) {
             logger.error("StateTransition threw exception.", ex);
             throw new StateTransitionException("Exception: " + ex.toString() + ", adminState=[" + adminState
-                    + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=[" + standbyStatus
-                    + "], actionName=[" + actionName + "]");
+                    + OPSTATE_STRING + opState + AVAILSTATUS_STRING + availStatus + STANDBY_STRING + standbyStatus
+                    + ACTION_STRING + actionName + "]");
         }
 
         return stateElement;
index 6e8865f..72847b1 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * policy-endpoints
  * ================================================================================
- * 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.
@@ -29,6 +29,8 @@ import org.onap.policy.common.capabilities.Startable;
 
 public interface HttpClient extends Startable {
 
+    public static final HttpClientFactory factory = new IndexedHttpClientFactory();
+
     public Response get(String path);
 
     public Response get();
@@ -57,7 +59,4 @@ public interface HttpClient extends Startable {
 
     public String getBaseUrl();
 
-
-    public static final HttpClientFactory factory = new IndexedHttpClientFactory();
-
 }