diff options
author | Jorge Hernandez <jh1730@att.com> | 2017-08-15 15:23:59 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-08-15 15:23:59 +0000 |
commit | 6b20e15005866454f5cb8d528de0d03aa75f52e7 (patch) | |
tree | fbaa0746b373ae99dd9259b7e385e4082541e2a3 /integrity-monitor | |
parent | 3b6aa335624dbe14963c4dfa1d32ad0336141dc7 (diff) | |
parent | d1077082cafafdd275aa8e210cf5f430ec11934d (diff) |
Merge "Resolve major/critical issues in integrity-monitor"
Diffstat (limited to 'integrity-monitor')
16 files changed, 210 insertions, 122 deletions
diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java index fef1dd54..ce042541 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java @@ -43,7 +43,6 @@ import org.onap.policy.common.im.jpa.ResourceRegistrationEntity; import org.onap.policy.common.im.jpa.StateManagementEntity; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; -//import org.apache.log4j.Logger; import org.onap.policy.common.im.jmx.ComponentAdmin; import org.onap.policy.common.im.jmx.ComponentAdminMBean; import org.onap.policy.common.im.jmx.JmxAgentConnection; @@ -56,7 +55,6 @@ import org.onap.policy.common.im.jmx.JmxAgentConnection; public class IntegrityMonitor { private static final Logger logger = FlexLogger.getLogger(IntegrityMonitor.class.getName()); - //private static final Map<String, IntegrityMonitor> imInstances = new HashMap<String, IntegrityMonitor>(); // only allow one instance of IntegrityMonitor private static IntegrityMonitor instance = null; @@ -124,7 +122,7 @@ public class IntegrityMonitor { // For non-lead subsystems, the dependency_group property will be absent. private static String [] dep_groups = null; - public static boolean isUnitTesting = false; + private static boolean isUnitTesting = false; // can turn on health checking of dependents via jmx test() call by setting this property to true private static boolean testViaJmx = false; @@ -203,7 +201,7 @@ public class IntegrityMonitor { public static void deleteInstance(){ logger.info("deleteInstance() called"); - if(isUnitTesting){ + if(isUnitTesting()){ instance=null; } logger.info("deleteInstance() exit"); @@ -224,7 +222,7 @@ public class IntegrityMonitor { if (instance != null) { String msg = "IM object exists and only one instance allowed"; logger.error(msg); - throw new Exception("IntegrityMonitor constructor exception: " + msg); + throw new IntegrityMonitorException("IntegrityMonitor constructor exception: " + msg); } instance = this; @@ -249,7 +247,7 @@ public class IntegrityMonitor { if (emf == null) { logger.error("Error creating IM entity manager factory with persistence unit: " + PERSISTENCE_UNIT); - throw new Exception("Unable to create IM Entity Manager Factory"); + throw new IntegrityMonitorException("Unable to create IM Entity Manager Factory"); } // add entry to forward progress and resource registration tables in DB @@ -329,7 +327,7 @@ public class IntegrityMonitor { } } } catch (Exception e1) { - // ignore + logger.error("IntegrityMonitor constructor threw exception: " + e1); } throw e; } @@ -358,16 +356,16 @@ public class IntegrityMonitor { } - private static String getJmxUrl() throws Exception { + private static String getJmxUrl() throws IntegrityMonitorException { // get the jmx remote port and construct the JMX URL Properties systemProps = System.getProperties(); String jmx_port = systemProps.getProperty("com.sun.management.jmxremote.port"); - String jmx_err_msg = ""; + String jmx_err_msg; if (jmx_port == null) { jmx_err_msg = "System property com.sun.management.jmxremote.port for JMX remote port is not set"; logger.error(jmx_err_msg); - throw new Exception("getJmxUrl exception: " + jmx_err_msg); + throw new IntegrityMonitorException("getJmxUrl exception: " + jmx_err_msg); } int port = 0; @@ -376,7 +374,7 @@ public class IntegrityMonitor { } catch (NumberFormatException e) { jmx_err_msg = "JMX remote port is not a valid integer value - " + jmx_port; logger.error(jmx_err_msg); - throw new Exception("getJmxUrl exception: " + jmx_err_msg); + throw new IntegrityMonitorException("getJmxUrl exception: " + jmx_err_msg); } try { @@ -386,12 +384,12 @@ public class IntegrityMonitor { } catch (Exception e) { String msg = "getJmxUrl could not get hostname" + e; logger.error(msg); - throw new Exception("getJmxUrl Exception: " + msg); + throw new IntegrityMonitorException("getJmxUrl Exception: " + msg); } if (jmxFqdn == null) { String msg = "getJmxUrl encountered null hostname"; logger.error(msg); - throw new Exception("getJmxUrl error: " + msg); + throw new IntegrityMonitorException("getJmxUrl error: " + msg); } // assemble the jmx url @@ -417,7 +415,7 @@ public class IntegrityMonitor { if ((stateManager.getOpState() != null) && stateManager.getOpState().equals(StateManagement.DISABLED)) { String msg = "Resource " + resourceName + " operation state is disabled. " + error_msg; logger.debug(msg); - throw new Exception(msg); + throw new IntegrityMonitorException(msg); } // check admin state and throw exception if locked @@ -433,18 +431,6 @@ public class IntegrityMonitor { throw new StandbyStatusException("IntegrityMonitor Standby Status Exception: " + msg); } -/* - * This is checked in the FPManager where the state is coordinated - if (fpcError) { - String msg = resourceName + ": no forward progress detected"; - logger.error(msg); - throw new ForwardProgressException(msg); - } - - * Additional testing to be provided by susbsystemTest() which could be overridden - * This has been moved to dependencyCheck where it is treated as testing of a dependency - subsystemTest(); -*/ } } @@ -550,7 +536,7 @@ public class IntegrityMonitor { logger.debug("IntegrityMonitor.stateCheck(): diffMs = " + diffMs); //Threshold for a stale entry - long staleMs = failedCounterThreshold * monitorInterval * 1000; + long staleMs = failedCounterThreshold * monitorInterval * (long)1000; logger.debug("IntegrityMonitor.stateCheck(): staleMs = " + staleMs); if(diffMs > staleMs){ @@ -577,20 +563,12 @@ public class IntegrityMonitor { logger.error(msg); } - else if(stateManagementEntity == null) { + else { String msg = "IntegrityMonitor.stateCheck(): Failed to diableFail dependent resource = " + dep + "; " + " stateManagementEntity == null."; logger.debug(msg); logger.error(msg); } - - else { - String msg = "IntegrityMonitor.stateCheck(): Failed to diableFail dependent resource = " + dep - + "; " + " forwardProgressEntity or stateManagementEntity == null."; - logger.debug(msg); - logger.error(msg); - - } } } @@ -640,7 +618,7 @@ public class IntegrityMonitor { @SuppressWarnings("rawtypes") List fpList = fquery.setLockMode( LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); - ForwardProgressEntity fpx = null; + ForwardProgressEntity fpx; if (!fpList.isEmpty()) { //ignores multiple results fpx = (ForwardProgressEntity) fpList.get(0); @@ -690,7 +668,7 @@ public class IntegrityMonitor { if(logger.isDebugEnabled()){ logger.debug("getAllForwardProgressEntity: entry"); } - ArrayList<ForwardProgressEntity> fpList = new ArrayList<ForwardProgressEntity>(); + ArrayList<ForwardProgressEntity> fpList = new ArrayList<>(); // Start a transaction EntityTransaction et = em.getTransaction(); et.begin(); @@ -883,8 +861,8 @@ public class IntegrityMonitor { if(!dependencyFailure){ try { logger.debug("All dependency groups have at least one viable member. Updating this resource's state to enableNoDependency"); - if( ( (stateManager.getAvailStatus()).equals(StateManagement.DEPENDENCY) || - (stateManager.getAvailStatus()).equals(StateManagement.DEPENDENCY_FAILED) ) ){ + if( (stateManager.getAvailStatus()).equals(StateManagement.DEPENDENCY) || + (stateManager.getAvailStatus()).equals(StateManagement.DEPENDENCY_FAILED) ){ // Note: redundant calls are made by refreshStateAudit this.stateManager.enableNoDependency(); } // The refreshStateAudit will catch the case where it is disabled but availStatus != failed @@ -903,8 +881,8 @@ public class IntegrityMonitor { */ try { logger.debug("There are no dependents. Updating this resource's state to enableNoDependency"); - if( ( (stateManager.getAvailStatus()).equals(StateManagement.DEPENDENCY) || - (stateManager.getAvailStatus()).equals(StateManagement.DEPENDENCY_FAILED) ) ){ + if( (stateManager.getAvailStatus()).equals(StateManagement.DEPENDENCY) || + (stateManager.getAvailStatus()).equals(StateManagement.DEPENDENCY_FAILED) ){ // Note: redundant calls are made by refreshStateAudit this.stateManager.enableNoDependency(); }// The refreshStateAudit will catch the case where it is disabled but availStatus != failed @@ -964,9 +942,7 @@ public class IntegrityMonitor { // start Transaction - resets transaction timer and check admin state try { startTransaction(); - } catch (AdministrativeStateException e) { - // ignore - } catch (StandbyStatusException e) { + } catch (AdministrativeStateException | StandbyStatusException e) { // ignore } @@ -981,7 +957,7 @@ public class IntegrityMonitor { * Additional testing for subsystems that do not have a /test interface (for ex. 3rd party * processes like elk). This method would be overridden by the subsystem. */ - public void subsystemTest() throws Exception { + public void subsystemTest() throws IntegrityMonitorException { // Testing provided by subsystem logger.debug("IntegrityMonitor subsystemTest() OK"); } @@ -998,7 +974,7 @@ public class IntegrityMonitor { // check admin state and throw exception if locked if ((stateManager.getAdminState() != null) && stateManager.getAdminState().equals(StateManagement.LOCKED)) { String msg = "Resource " + resourceName + " is administratively locked"; - // logger.debug(msg); + throw new AdministrativeStateException("IntegrityMonitor Admin State Exception: " + msg); } // check standby state and throw exception if locked @@ -1007,7 +983,7 @@ public class IntegrityMonitor { (stateManager.getStandbyStatus().equals(StateManagement.HOT_STANDBY) || stateManager.getStandbyStatus().equals(StateManagement.COLD_STANDBY))){ String msg = "Resource " + resourceName + " is standby"; - //logger.debug(msg); + throw new StandbyStatusException("IntegrityMonitor Standby Status Exception: " + msg); } @@ -1028,7 +1004,7 @@ public class IntegrityMonitor { } // update FP count in DB with local FP count - private void writeFpc() throws Exception { + private void writeFpc() throws IntegrityMonitorException { // Start a transaction EntityTransaction et = em.getTransaction(); @@ -1045,7 +1021,7 @@ public class IntegrityMonitor { @SuppressWarnings("rawtypes") List fpList = fquery.setLockMode( LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); - ForwardProgressEntity fpx = null; + ForwardProgressEntity fpx; if(!fpList.isEmpty()) { //ignores multiple results fpx = (ForwardProgressEntity) fpList.get(0); @@ -1063,7 +1039,7 @@ public class IntegrityMonitor { else { // Error - FP entry does not exist String msg = "FP entry not found in database for resource " + resourceName; - throw new Exception(msg); + throw new IntegrityMonitorException(msg); } } catch (Exception e) { try { @@ -1223,7 +1199,7 @@ public class IntegrityMonitor { } public static void updateProperties(Properties newprop) { - if (isUnitTesting) { + if (isUnitTesting()) { try { validateProperties(newprop); } catch (IntegrityMonitorPropertiesException e) { @@ -1346,7 +1322,7 @@ public class IntegrityMonitor { logger.debug("IntegrityMonitor.stateAudit(): diffMs = " + diffMs); //Threshold for a stale entry - long staleMs = maxFpcUpdateInterval * 1000; + long staleMs = maxFpcUpdateInterval * (long)1000; logger.debug("IntegrityMonitor.stateAudit(): staleMs = " + staleMs); if(diffMs > staleMs){ @@ -1389,8 +1365,7 @@ public class IntegrityMonitor { } } - if(sme != null){ - if(!sme.getOpState().equals(StateManagement.DISABLED)){ + if(sme != null && !sme.getOpState().equals(StateManagement.DISABLED)){ logger.debug("IntegrityMonitor.stateAudit(): Changing OpStat = disabled for " + sme.getResourceName()); try { stateManager.disableFailed(sme.getResourceName()); @@ -1399,7 +1374,6 @@ public class IntegrityMonitor { logger.debug(msg); logger.error(msg); } - } } }// end if(diffMs > staleMs) }// end for(ForwardProgressEntity fpe : fpList) @@ -1524,6 +1498,14 @@ public class IntegrityMonitor { } } + public static boolean isUnitTesting() { + return isUnitTesting; + } + + public static void setUnitTesting(boolean isUnitTesting) { + IntegrityMonitor.isUnitTesting = isUnitTesting; + } + /** * The following nested class periodically performs the forward progress check, * checks dependencies, does a refresh state audit and runs the stateAudit. @@ -1538,6 +1520,7 @@ public class IntegrityMonitor { this.start(); } + @Override public void run() { logger.info("FPManager thread running"); while (true) { diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorException.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorException.java new file mode 100644 index 00000000..95b0a750 --- /dev/null +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorException.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * Integrity Monitor + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.common.im; + +public class IntegrityMonitorException extends Exception{ + private static final long serialVersionUID = 1L; + public IntegrityMonitorException() { + } + public IntegrityMonitorException(String message) { + super(message); + } + + public IntegrityMonitorException(Throwable cause) { + super(cause); + } + public IntegrityMonitorException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorProperties.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorProperties.java index a6a7da1f..26edd43a 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorProperties.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorProperties.java @@ -22,6 +22,7 @@ package org.onap.policy.common.im; public class IntegrityMonitorProperties { + private IntegrityMonitorProperties() {} public static final String DEFAULT_DB_DRIVER = "org.h2.Driver"; public static final String DEFAULT_DB_URL = "jdbc:h2:file:./sql/imTest"; public static final String DEFAULT_DB_USER = "sa"; @@ -35,7 +36,7 @@ public class IntegrityMonitorProperties { // intervals specified are in seconds public static final int DEFAULT_MONITOR_INTERVAL = 30; public static final int DEFAULT_FAILED_COUNTER_THRESHOLD = 3; - public static final int DEFAULT_TEST_INTERVAL = 10; //20; + public static final int DEFAULT_TEST_INTERVAL = 10; public static final int DEFAULT_WRITE_FPC_INTERVAL = 5; public static final int DEFAULT_MAX_FPC_UPDATE_INTERVAL = 120; diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateChangeNotifier.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateChangeNotifier.java index ee148159..f3f6958e 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateChangeNotifier.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateChangeNotifier.java @@ -35,7 +35,7 @@ import java.util.Observer; * Observer who is monitoring the state changes. */ -//import org.apache.log4j.Logger; + import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateElement.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateElement.java index 58cdde1e..7870e6a3 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateElement.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateElement.java @@ -20,7 +20,7 @@ package org.onap.policy.common.im; -//import org.apache.log4j.Logger; + import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java index 4ed5d35a..d8e0f693 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java @@ -29,7 +29,6 @@ import javax.persistence.FlushModeType; import javax.persistence.LockModeType; import javax.persistence.Query; -//import org.apache.log4j.Logger; import org.onap.policy.common.im.jpa.StateManagementEntity; import org.onap.policy.common.im.StateElement; @@ -100,7 +99,7 @@ public class StateManagement extends Observable { * @param resourceName * @throws Exception */ - public StateManagement(EntityManagerFactory emf, String resourceName) throws Exception + public StateManagement(EntityManagerFactory emf, String resourceName) throws StateManagementException { logger.debug("StateManagement: constructor, resourceName: " + resourceName); em = emf.createEntityManager(); @@ -143,7 +142,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement: Exception: " + ex.toString()); + throw new StateManagementException("StateManagement: Exception: " + ex.toString()); } } @@ -153,7 +152,7 @@ public class StateManagement extends Observable { * Starting from this state, the IntegrityMonitory will determine the Operational State and the * owning application will set the StandbyStatus. */ - public void initializeState() throws Exception + public void initializeState() throws StateManagementException { synchronized (SYNCLOCK){ logger.debug("\nStateManagement: SYNCLOCK initializeState() operation for resourceName = " + this.resourceName + "\n"); @@ -189,7 +188,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement.initializeState() Exception: " + ex); + throw new StateManagementException("StateManagement.initializeState() Exception: " + ex); } } } @@ -198,7 +197,7 @@ public class StateManagement extends Observable { * lock() changes the administrative state to locked. * @throws Exception */ - public void lock() throws Exception + public void lock() throws StateManagementException { synchronized (SYNCLOCK){ logger.debug("\nStateManagement: SYNCLOCK lock() operation for resourceName = " + this.resourceName + "\n"); @@ -237,7 +236,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement.lock() Exception: " + ex.toString()); + throw new StateManagementException("StateManagement.lock() Exception: " + ex.toString()); } } } @@ -246,7 +245,7 @@ public class StateManagement extends Observable { * unlock() changes the administrative state to unlocked. * @throws Exception */ - public void unlock() throws Exception + public void unlock() throws StateManagementException { synchronized (SYNCLOCK){ logger.debug("\nStateManagement: SYNCLOCK unlock() operation for resourceName = " + this.resourceName + "\n"); @@ -284,7 +283,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement.unlock() Exception: " + ex); + throw new StateManagementException("StateManagement.unlock() Exception: " + ex); } } } @@ -294,7 +293,7 @@ public class StateManagement extends Observable { * state to enabled if no dependency is also failed. * @throws Exception */ - public void enableNotFailed() throws Exception + public void enableNotFailed() throws StateManagementException { synchronized (SYNCLOCK){ logger.debug("\nStateManagement: SYNCLOCK enabledNotFailed() operation for resourceName = " + this.resourceName + "\n"); @@ -332,7 +331,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement.enableNotFailed() Exception: " + ex); + throw new StateManagementException("StateManagement.enableNotFailed() Exception: " + ex); } } } @@ -341,7 +340,7 @@ public class StateManagement extends Observable { * disableFailed() changes the operational state to disabled and adds availability status of "failed" * @throws Exception */ - public void disableFailed() throws Exception + public void disableFailed() throws StateManagementException { synchronized (SYNCLOCK){ logger.debug("\nStateManagement: SYNCLOCK disabledFailed() operation for resourceName = " + this.resourceName + "\n"); @@ -378,7 +377,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement.disableFailed() Exception: " + ex); + throw new StateManagementException("StateManagement.disableFailed() Exception: " + ex); } } } @@ -387,7 +386,7 @@ public class StateManagement extends Observable { * that remote resource has failed but its state is still showing that it is viable. * @throws Exception */ - public void disableFailed(String otherResourceName) throws Exception + public void disableFailed(String otherResourceName) throws StateManagementException { synchronized (SYNCLOCK){ if(otherResourceName == null){ @@ -431,7 +430,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement.disableFailed(otherResourceName) Exception: " + ex); + throw new StateManagementException("StateManagement.disableFailed(otherResourceName) Exception: " + ex); } } } @@ -440,7 +439,7 @@ public class StateManagement extends Observable { * disableDependency() changes operational state to disabled and adds availability status of "dependency" * @throws Exception */ - public void disableDependency() throws Exception + public void disableDependency() throws StateManagementException { synchronized (SYNCLOCK){ logger.debug("\nStateManagement: SYNCLOCK disableDependency() operation for resourceName = " + this.resourceName + "\n"); @@ -478,7 +477,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement.disableDependency() Exception: " + ex); + throw new StateManagementException("StateManagement.disableDependency() Exception: " + ex); } } } @@ -488,7 +487,7 @@ public class StateManagement extends Observable { * operational state to enabled if not otherwise failed. * @throws Exception */ - public void enableNoDependency() throws Exception + public void enableNoDependency() throws StateManagementException { synchronized (SYNCLOCK){ logger.debug("\nStateManagement: SYNCLOCK enableNoDependency() operation for resourceName = " + this.resourceName + "\n"); @@ -526,7 +525,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement.enableNoDependency() Exception: " + ex); + throw new StateManagementException("StateManagement.enableNoDependency() Exception: " + ex); } } } @@ -536,7 +535,7 @@ public class StateManagement extends Observable { * @throws StandbyStatusException * @throws Exception */ - public void promote() throws StandbyStatusException, Exception + public void promote() throws StandbyStatusException, StateManagementException { synchronized (SYNCLOCK){ logger.debug("\nStateManagement: SYNCLOCK promote() operation for resourceName = " + this.resourceName + "\n"); @@ -576,7 +575,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement.promote() Exception: " + ex); + throw new StateManagementException("StateManagement.promote() Exception: " + ex); } logger.debug("StateManagement: promote() operation completed, resourceName = " + this.resourceName); @@ -591,7 +590,7 @@ public class StateManagement extends Observable { * demote() changes standbystatus to hotstandby or, if failed, coldstandby * @throws Exception */ - public void demote() throws Exception + public void demote() throws StateManagementException { synchronized (SYNCLOCK){ logger.debug("\nStateManagement: SYNCLOCK demote() operation for resourceName = " + this.resourceName + "\n"); @@ -629,7 +628,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement.demote() Exception: " + ex); + throw new StateManagementException("StateManagement.demote() Exception: " + ex); } } } @@ -643,7 +642,7 @@ public class StateManagement extends Observable { * @param otherResourceName * @throws Exception */ - public void demote(String otherResourceName) throws Exception + public void demote(String otherResourceName) throws StateManagementException { synchronized (SYNCLOCK){ if(otherResourceName==null){ @@ -684,7 +683,7 @@ public class StateManagement extends Observable { et.rollback(); } } - throw new Exception("StateManagement.demote(otherResourceName) Exception: " + ex); + throw new StateManagementException("StateManagement.demote(otherResourceName) Exception: " + ex); } } } @@ -870,7 +869,7 @@ public String getOpState() + otherResourceName + "'"); } - String standbyStatus = null; + String tempStandbyStatus = null; // The transaction is required for the LockModeType EntityTransaction et = em.getTransaction(); @@ -890,10 +889,10 @@ public String getOpState() .get(0); // refresh the object from DB in case cached data was returned em.refresh(stateManagementEntity); - standbyStatus = stateManagementEntity.getStandbyStatus(); + tempStandbyStatus = stateManagementEntity.getStandbyStatus(); if (logger.isDebugEnabled()) { logger.debug("getStandbyStatus: resourceName =" + otherResourceName - + " has standbyStatus=" + standbyStatus); + + " has standbyStatus=" + tempStandbyStatus); } } else { logger.error("getStandbyStatus: resourceName =" + otherResourceName @@ -914,10 +913,10 @@ public String getOpState() } if (logger.isDebugEnabled()) { logger.debug("getStandbyStatus: Returning standbyStatus=" - + standbyStatus); + + tempStandbyStatus); } - return standbyStatus; + return tempStandbyStatus; } /** diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagementException.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagementException.java new file mode 100644 index 00000000..daebed91 --- /dev/null +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagementException.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * Integrity Monitor + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.common.im; + +public class StateManagementException extends Exception{ + private static final long serialVersionUID = 1L; + public StateManagementException() { + } + public StateManagementException(String message) { + super(message); + } + + public StateManagementException(Throwable cause) { + super(cause); + } + public StateManagementException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransition.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransition.java index 746e0cef..a45a536b 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransition.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransition.java @@ -22,7 +22,6 @@ package org.onap.policy.common.im; import java.util.*; -//import org.apache.log4j.Logger; import org.onap.policy.common.im.StateElement; import org.onap.policy.common.im.StateManagement; @@ -41,23 +40,22 @@ public class StateTransition { public static final String STANDBY_STATUS = "standbyStatus"; public static final String ACTOIN_NAME = "actionName"; - private HashMap<String, String> StateTable = new HashMap<String, String>(); + private HashMap<String, String> StateTable = new HashMap<>(); /** * StateTransition constructor * @throws Exception */ - public StateTransition() throws Exception + public StateTransition() throws StateTransitionException { logger.debug("StateTransition constructor"); try { logger.debug("Load StateTable started"); - setupStateTable(); // - //displayStateTable(); + setupStateTable(); } catch(Exception ex) { - throw new Exception("StateTransition Exception: " + ex.toString()); + throw new StateTransitionException("StateTransition Exception: " + ex.toString()); } } @@ -72,7 +70,7 @@ public class StateTransition { * @throws Exception */ public StateElement getEndingState(String adminState, String opState, String availStatus, - String standbyStatus, String actionName) throws Exception + String standbyStatus, String actionName) throws StateTransitionException { logger.info("getEndingState"); logger.info("adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + @@ -84,25 +82,25 @@ public class StateTransition { standbyStatus="null"; } if(adminState==null || opState==null || actionName==null){ - throw new Exception("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + + throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=[" + standbyStatus + "], actionName=[" + actionName + "]"); }else if(!(adminState.equals(StateManagement.LOCKED) || adminState.equals(StateManagement.UNLOCKED))){ - throw new Exception("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + + throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=[" + standbyStatus + "], actionName=[" + actionName + "]"); }else if(!(opState.equals(StateManagement.ENABLED) || opState.equals(StateManagement.DISABLED))){ - throw new Exception("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + + throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=[" + standbyStatus + "], actionName=[" + 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 Exception("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + + throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=[" + standbyStatus + "], actionName=[" + actionName + "]"); }else if(!(availStatus.equals(StateManagement.NULL_VALUE) || availStatus.equals(StateManagement.DEPENDENCY) || availStatus.equals(StateManagement.DEPENDENCY_FAILED) || availStatus.equals(StateManagement.FAILED))){ - throw new Exception("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + + throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=[" + standbyStatus + "], actionName=[" + actionName + "]"); } else if(!(actionName.equals(StateManagement.DEMOTE) || @@ -113,7 +111,7 @@ public class StateTransition { actionName.equals(StateManagement.LOCK) || actionName.equals(StateManagement.PROMOTE) || actionName.equals(StateManagement.UNLOCK))){ - throw new Exception("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + + throw new StateTransitionException("Exception:StateTransition unable to process state: adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=[" + standbyStatus + "], actionName=[" + actionName + "]"); } @@ -151,10 +149,10 @@ public class StateTransition { String msg = "Ending state not found, adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=[" + standbyStatus + "], actionName=[" + actionName + "]"; logger.error(msg); - throw new Exception(msg); + throw new StateTransitionException(msg); } } catch (Exception ex) { - throw new Exception("Exception: " + ex.toString() + ", adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + + throw new StateTransitionException("Exception: " + ex.toString() + ", adminState=[" + adminState + "], opState=[" + opState + "], availStatus=[" + availStatus + "], standbyStatus=[" + standbyStatus + "], actionName=[" + actionName + "]"); } diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransitionException.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransitionException.java new file mode 100644 index 00000000..07a4326f --- /dev/null +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateTransitionException.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * Integrity Monitor + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.common.im; + +public class StateTransitionException extends Exception{ + private static final long serialVersionUID = 1L; + public StateTransitionException() { + } + public StateTransitionException(String message) { + super(message); + } + + public StateTransitionException(Throwable cause) { + super(cause); + } + public StateTransitionException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java index 551e1b09..8ffb1b74 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java @@ -86,14 +86,13 @@ public class ComponentAdmin implements ComponentAdminMBean { MBeanRegistrationException, InstanceNotFoundException, InstanceAlreadyExistsException, NotCompliantMBeanException { - //if (LOGGER.isDebugEnabled()) { + logger.info("Registering " + name + " MBean"); - //} + MBeanServer mbeanServer = findMBeanServer(); if (mbeanServer == null) { - //LOGGER.warn("No MBeanServer to register " + name + " MBean"); return; } @@ -130,9 +129,6 @@ public class ComponentAdmin implements ComponentAdminMBean { return; } - //if (LOGGER.isDebugEnabled()) { - //LOGGER.debug("Unregistering " + name + " MBean"); - //} registeredMBeanServer.unregisterMBean(registeredObjectName); registeredMBeanServer = null; @@ -142,6 +138,7 @@ public class ComponentAdmin implements ComponentAdminMBean { /** * {@inheritDoc} */ + @Override public String toString() { return ComponentAdmin.class.getSimpleName() + "[" + name + "]"; } @@ -155,11 +152,11 @@ public class ComponentAdmin implements ComponentAdminMBean { MBeanServerFactory.findMBeanServer(null); Iterator<MBeanServer> iter = mbeanServers.iterator(); - MBeanServer mbeanServer = null; + MBeanServer mbeanServer; while (iter.hasNext()) { mbeanServer = iter.next(); - if (mbeanServer.getDefaultDomain().equals("DefaultDomain")) { + if ("DefaultDomain".equals(mbeanServer.getDefaultDomain())) { return mbeanServer; } } diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java index 7a7e9a80..9b9bc48c 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java @@ -47,17 +47,10 @@ public final class JmxAgentConnection { private JMXConnector connector; private String jmxUrl = null; - //private final static Logger Log = Logger.getLogger(JmxAgentConnection.class); - /** * Set up the host/port from the properties. Use defaults if missing from the properties. * @param properties the properties used to look for host and port */ - //JmxAgentConnection(Properties properties) { - //host = properties.getProperty("jmxAgent.host", DEFAULT_HOST); - //port = properties.getProperty("jmxAgent.port", DEFAULT_PORT); - //} - public JmxAgentConnection() { host = DEFAULT_HOST; port = DEFAULT_PORT; @@ -98,7 +91,7 @@ public final class JmxAgentConnection { else { url = new JMXServiceURL(jmxUrl); } - Map<String, Object> env = new HashMap<String, Object>(); + Map<String, Object> env = new HashMap<>(); connector = JMXConnectorFactory.newJMXConnector(url, env); connector.connect(); @@ -110,7 +103,6 @@ public final class JmxAgentConnection { Notification notification, Object handback) { if (notification.getType().equals( JMXConnectionNotification.FAILED)) { - //Log.debug("JMXAgent connection failure"); // handle disconnect disconnect(); } diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java index 1dc71a65..2ef3fa8a 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java @@ -71,6 +71,7 @@ public class ForwardProgressEntity implements Serializable { private Date lastUpdated; public ForwardProgressEntity() { + //default constructor } @PrePersist diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ImTestEntity.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ImTestEntity.java index be4470e7..454bf7e1 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ImTestEntity.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ImTestEntity.java @@ -68,6 +68,7 @@ public class ImTestEntity implements Serializable { private Date modifiedDate; public ImTestEntity() { + //default constructor } @PrePersist diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java index c4d4aa68..bd2ba8ab 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java @@ -77,6 +77,7 @@ public class ResourceRegistrationEntity implements Serializable { private Date lastUpdated; public ResourceRegistrationEntity() { + //default constructor } @PrePersist diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/StateManagementEntity.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/StateManagementEntity.java index 2dd18853..e177939d 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/StateManagementEntity.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/StateManagementEntity.java @@ -84,6 +84,7 @@ public class StateManagementEntity implements Serializable { } public StateManagementEntity() { + //default constructor } public String getResourceName() { diff --git a/integrity-monitor/src/test/java/org/onap/policy/common/im/test/IntegrityMonitorTest.java b/integrity-monitor/src/test/java/org/onap/policy/common/im/test/IntegrityMonitorTest.java index afa2ca94..b914bb04 100644 --- a/integrity-monitor/src/test/java/org/onap/policy/common/im/test/IntegrityMonitorTest.java +++ b/integrity-monitor/src/test/java/org/onap/policy/common/im/test/IntegrityMonitorTest.java @@ -79,7 +79,7 @@ public class IntegrityMonitorTest { @Before public void setUp() throws Exception { - IntegrityMonitor.isUnitTesting = true; + IntegrityMonitor.setUnitTesting(true); myProp = new Properties(); myProp.put(IntegrityMonitorProperties.DB_DRIVER, IntegrityMonitorProperties.DEFAULT_DB_DRIVER); |