From 45f97b0b7735c9ac75c3f0d010b9524b47807cb8 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 16 Feb 2018 18:11:21 -0500 Subject: Fix more generic exceptions in common Fixed a few more generic exceptions in integrity-audit and integrity-monitor. Fixed license dates. Change-Id: Ibbc21ae5f853896e0d3e416e33b5ea2a13672f62 Issue-ID: POLICY-246 Signed-off-by: Jim Hahn --- .../org/onap/policy/common/ia/AuditThread.java | 10 ++-- .../java/org/onap/policy/common/ia/DbAudit.java | 67 +++++++++++++++------- .../onap/policy/common/ia/DbAuditException.java | 4 +- .../main/java/org/onap/policy/common/ia/DbDAO.java | 10 ++-- .../common/ia/DbDaoTransactionException.java | 4 +- .../org/onap/policy/common/ia/IntegrityAudit.java | 10 ++-- .../ia/IntegrityAuditPropertiesException.java | 4 +- .../policy/common/ia/IntegrityAuditTestBase.java | 11 +++- .../common/im/AdministrativeStateException.java | 4 +- .../policy/common/im/AllSeemsWellException.java | 4 +- .../policy/common/im/ForwardProgressException.java | 4 +- .../onap/policy/common/im/IntegrityMonitor.java | 53 +++++++++-------- .../common/im/IntegrityMonitorException.java | 8 ++- .../im/IntegrityMonitorPropertiesException.java | 4 +- .../policy/common/im/StandbyStatusException.java | 4 +- .../org/onap/policy/common/im/StateManagement.java | 26 ++++----- .../policy/common/im/StateManagementException.java | 4 +- .../org/onap/policy/common/im/StateTransition.java | 6 +- .../policy/common/im/StateTransitionException.java | 4 +- .../onap/policy/common/im/jmx/ComponentAdmin.java | 9 +-- .../common/im/jmx/ComponentAdminException.java | 4 +- .../policy/common/im/jmx/ComponentAdminMBean.java | 16 +++--- .../policy/common/im/jmx/JmxAgentConnection.java | 61 +++++++++++--------- .../org/onap/policy/common/im/ExceptionsTest.java | 2 +- 24 files changed, 193 insertions(+), 140 deletions(-) diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java index 7af82132..efa1b1d3 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java @@ -126,11 +126,11 @@ public class AuditThread extends Thread { * @param properties * @param integrityAuditPeriodSeconds * @param integrityAudit - * @throws Exception + * @throws IntegrityAuditException */ public AuditThread(String resourceName, String persistenceUnit, Properties properties, int integrityAuditPeriodSeconds, IntegrityAudit integrityAudit) - throws Exception { + throws IntegrityAuditException { this(resourceName, persistenceUnit, properties, TimeUnit.SECONDS.toMillis(integrityAuditPeriodSeconds), integrityAudit, null); @@ -144,12 +144,12 @@ public class AuditThread extends Thread { * @param integrityAuditMillis * @param integrityAudit * @param queue - * @throws Exception + * @throws IntegrityAuditException */ public AuditThread(String resourceName, String persistenceUnit, Properties properties, long integrityAuditMillis, IntegrityAudit integrityAudit, BlockingQueue queue) - throws Exception { + throws IntegrityAuditException { this.resourceName = resourceName; this.persistenceUnit = persistenceUnit; this.properties = properties; @@ -833,7 +833,7 @@ public class AuditThread extends Thread { return auditCompleted; } - private void runAudit(DbAudit dbAudit) throws Exception { + private void runAudit(DbAudit dbAudit) throws IntegrityAuditException { if (logger.isDebugEnabled()) { logger.debug("runAudit: Entering, dbAudit=" + dbAudit diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java index 00b79917..6fb619e4 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java @@ -79,7 +79,7 @@ public class DbAudit { * @param nodeType * @throws Exception */ - public void dbAudit(String resourceName, String persistenceUnit, String nodeType) throws Exception { + public void dbAudit(String resourceName, String persistenceUnit, String nodeType) throws IntegrityAuditException { if (logger.isDebugEnabled()) { logger.debug("dbAudit: Entering, resourceName=" + resourceName @@ -225,7 +225,7 @@ public class DbAudit { if (logger.isDebugEnabled()) { logger.debug("dbAudit: Sleeping " + dbAuditSleepMillis + "ms"); } - Thread.sleep(dbAuditSleepMillis); + sleep(); if (logger.isDebugEnabled()) { logger.debug("dbAudit: Waking from sleep"); } @@ -328,7 +328,7 @@ public class DbAudit { if (logger.isDebugEnabled()) { logger.debug("dbAudit: Second comparison; sleeping " + dbAuditSleepMillis + "ms"); } - Thread.sleep(dbAuditSleepMillis); + sleep(); if (logger.isDebugEnabled()) { logger.debug("dbAudit: Second comparison; waking from sleep"); } @@ -347,6 +347,20 @@ public class DbAudit { return; //all done } + /** + * Sleeps a bit. + * @throws IntegrityAuditException + */ + private void sleep() throws IntegrityAuditException { + try { + Thread.sleep(dbAuditSleepMillis); + + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IntegrityAuditException(e); + } + } + /** * dbAuditSimulate simulates the DB audit * @param resourceName @@ -435,19 +449,24 @@ public class DbAudit { * @param resourceName2 * @param entry1 * @param entry2 - * @throws ClassNotFoundException + * @throws IntegrityAuditException */ public void writeAuditDebugLog(String clazzName, String resourceName1, - String resourceName2, Object entry1, Object entry2) throws ClassNotFoundException{ - Class entityClass = Class.forName(clazzName); - String tableName = entityClass.getAnnotation(Table.class).name(); - String msg = "\nDB Audit Error: " - + "\n Table Name: " + tableName - + "\n Entry 1 (short prefix style): " + resourceName1 + ": " + new ReflectionToStringBuilder(entry1,ToStringStyle.SHORT_PREFIX_STYLE).toString() - + "\n Entry 2 (short prefix style): " + resourceName2 + ": " + new ReflectionToStringBuilder(entry2,ToStringStyle.SHORT_PREFIX_STYLE).toString() - + "\n Entry 1 (recursive style): " + resourceName1 + ": " + new ReflectionToStringBuilder(entry1, new RecursiveToStringStyle()).toString() - + "\n Entry 2 (recursive style): " + resourceName2 + ": " + new ReflectionToStringBuilder(entry2, new RecursiveToStringStyle()).toString(); - logger.debug(msg); + String resourceName2, Object entry1, Object entry2) throws IntegrityAuditException{ + try { + Class entityClass = Class.forName(clazzName); + String tableName = entityClass.getAnnotation(Table.class).name(); + String msg = "\nDB Audit Error: " + + "\n Table Name: " + tableName + + "\n Entry 1 (short prefix style): " + resourceName1 + ": " + new ReflectionToStringBuilder(entry1,ToStringStyle.SHORT_PREFIX_STYLE).toString() + + "\n Entry 2 (short prefix style): " + resourceName2 + ": " + new ReflectionToStringBuilder(entry2,ToStringStyle.SHORT_PREFIX_STYLE).toString() + + "\n Entry 1 (recursive style): " + resourceName1 + ": " + new ReflectionToStringBuilder(entry1, new RecursiveToStringStyle()).toString() + + "\n Entry 2 (recursive style): " + resourceName2 + ": " + new ReflectionToStringBuilder(entry2, new RecursiveToStringStyle()).toString(); + logger.debug(msg); + + } catch (ClassNotFoundException e) { + throw new IntegrityAuditException(e); + } } @@ -457,16 +476,20 @@ public class DbAudit { * @param resourceName1 * @param resourceName2 * @param keys - * @throws ClassNotFoundException + * @throws IntegrityAuditException */ public void writeAuditSummaryLog(String clazzName, String resourceName1, - String resourceName2, String keys) throws ClassNotFoundException{ - Class entityClass = Class.forName(clazzName); - String tableName = entityClass.getAnnotation(Table.class).name(); - String msg = " DB Audit Error: Table Name: " + tableName - + "; Mismatch between nodes: " + resourceName1 +" and " + resourceName2 - + "; Mismatched entries (keys): " + keys; - logger.info(msg); + String resourceName2, String keys) throws IntegrityAuditException{ + try { + Class entityClass = Class.forName(clazzName); + String tableName = entityClass.getAnnotation(Table.class).name(); + String msg = " DB Audit Error: Table Name: " + tableName + + "; Mismatch between nodes: " + resourceName1 +" and " + resourceName2 + + "; Mismatched entries (keys): " + keys; + logger.info(msg); + } catch (ClassNotFoundException e) { + throw new IntegrityAuditException(e); + } } /** diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAuditException.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAuditException.java index 8f00bf86..dc629c65 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAuditException.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAuditException.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Audit * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ package org.onap.policy.common.ia; -public class DbAuditException extends Exception{ +public class DbAuditException extends IntegrityAuditException { private static final long serialVersionUID = 1L; public DbAuditException() { super(); diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java index f34b24d5..73beda78 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Audit * ================================================================================ - * 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. @@ -75,9 +75,9 @@ public class DbDAO { * @param resourceName * @param persistenceUnit * @param properties - * @throws Exception + * @throws IntegrityAuditException */ - public DbDAO(String resourceName, String persistenceUnit, Properties properties) throws Exception { + public DbDAO(String resourceName, String persistenceUnit, Properties properties) throws IntegrityAuditException { this(resourceName, persistenceUnit, properties, null); } @@ -89,10 +89,10 @@ public class DbDAO { * @param properties * @param lastUpdateDate may be {@code null} * @param altDbUrl may be {@code null} - * @throws Exception + * @throws IntegrityAuditException */ protected DbDAO(String resourceName, String persistenceUnit, Properties properties, String altDbUrl) - throws Exception { + throws IntegrityAuditException { logger.debug("DbDAO contructor: enter"); validateProperties(resourceName, persistenceUnit, properties); diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDaoTransactionException.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDaoTransactionException.java index 344ea6a5..72716279 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDaoTransactionException.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDaoTransactionException.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Audit * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ package org.onap.policy.common.ia; -public class DbDaoTransactionException extends Exception{ +public class DbDaoTransactionException extends IntegrityAuditException { private static final long serialVersionUID = 1L; public DbDaoTransactionException() { super(); diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java index f1dbfec0..cab08610 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java @@ -63,7 +63,7 @@ public class IntegrityAudit { * @param resourceName * @param persistenceUnit * @param properties - * @throws Exception + * @throws IntegrityAuditException */ public IntegrityAudit(String resourceName, String persistenceUnit, Properties properties) throws IntegrityAuditException { @@ -212,18 +212,18 @@ public class IntegrityAudit { } /** * Starts the audit thread - * @throws Exception + * @throws IntegrityAuditException */ - public void startAuditThread() throws Exception { + public void startAuditThread() throws IntegrityAuditException { startAuditThread(null); } /** * Starts the audit thread * @param queue * @return {@code true} if the thread was started, {@code false} otherwise - * @throws Exception + * @throws IntegrityAuditException */ - protected boolean startAuditThread(BlockingQueue queue) throws Exception { + protected boolean startAuditThread(BlockingQueue queue) throws IntegrityAuditException { logger.info("startAuditThread: Entering"); diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditPropertiesException.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditPropertiesException.java index 0480abf1..766268bc 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditPropertiesException.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditPropertiesException.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Audit * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ package org.onap.policy.common.ia; -public class IntegrityAuditPropertiesException extends Exception{ +public class IntegrityAuditPropertiesException extends IntegrityAuditException { private static final long serialVersionUID = 1L; public IntegrityAuditPropertiesException() { super(); diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java index 474879d1..e30c5631 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java @@ -589,7 +589,7 @@ public class IntegrityAuditTestBase { * with the thread. */ @Override - public final void startAuditThread() throws Exception { + public final void startAuditThread() throws IntegrityAuditException { if (queue != null) { // queue up a bogus latch, in case a thread is still running queue.add(new CountDownLatch(1) { @@ -606,7 +606,14 @@ public class IntegrityAuditTestBase { // wait for the thread to start CountDownLatch latch = new CountDownLatch(1); queue.add(latch); - waitLatch(latch); + + try { + waitLatch(latch); + + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IntegrityAuditException(e); + } } } diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/AdministrativeStateException.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/AdministrativeStateException.java index 31be3cea..600d8601 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/AdministrativeStateException.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/AdministrativeStateException.java @@ -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. @@ -20,7 +20,7 @@ package org.onap.policy.common.im; -public class AdministrativeStateException extends Exception{ +public class AdministrativeStateException extends IntegrityMonitorException { private static final long serialVersionUID = 1L; public AdministrativeStateException() { super(); diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/AllSeemsWellException.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/AllSeemsWellException.java index 5878e1d1..588a4d61 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/AllSeemsWellException.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/AllSeemsWellException.java @@ -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. @@ -20,7 +20,7 @@ package org.onap.policy.common.im; -public class AllSeemsWellException extends Exception { +public class AllSeemsWellException extends IntegrityMonitorException { /** * diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/ForwardProgressException.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/ForwardProgressException.java index fd545cda..5825c3a0 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/ForwardProgressException.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/ForwardProgressException.java @@ -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. @@ -20,7 +20,7 @@ package org.onap.policy.common.im; -public class ForwardProgressException extends Exception{ +public class ForwardProgressException extends IntegrityMonitorException { private static final long serialVersionUID = 1L; public ForwardProgressException() { super(); 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 d272d1c6..880d39f5 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 @@ -197,10 +197,10 @@ public class IntegrityMonitor { * The resource name of the resource * @param properties * a set of properties passed in from the resource - * @throws Exception + * @throws IntegrityMonitorException * if any errors are encountered in the constructor */ - protected IntegrityMonitor(String resourceName, Properties properties) throws Exception { + protected IntegrityMonitor(String resourceName, Properties properties) throws IntegrityMonitorException { this(resourceName, properties, null); } @@ -218,11 +218,11 @@ public class IntegrityMonitor { * a set of properties passed in from the resource * @param queue * queue to use to control the FPManager thread, or {@code null} - * @throws Exception + * @throws IntegrityMonitorException * if any errors are encountered in the constructor */ protected IntegrityMonitor(String resourceName, Properties properties, BlockingQueue queue) - throws Exception { + throws IntegrityMonitorException { // singleton check since this constructor can be called from a child or // sub-class @@ -344,18 +344,23 @@ public class IntegrityMonitor { throw e; } - // create instance of StateMangement class and pass emf to it - stateManager = new StateManagement(emf, resourceName); - - /** - * Initialize the state and status attributes. This will maintain any - * Administrative state value but will set the operational state = - * enabled, availability status = null, standby status = null. The - * integrity monitor will set the operational state via the FPManager - * and the owning application must set the standby status by calling - * promote/demote on the StateManager. - */ - stateManager.initializeState(); + try { + // create instance of StateMangement class and pass emf to it + stateManager = new StateManagement(emf, resourceName); + + /** + * Initialize the state and status attributes. This will maintain any + * Administrative state value but will set the operational state = + * enabled, availability status = null, standby status = null. The + * integrity monitor will set the operational state via the FPManager + * and the owning application must set the standby status by calling + * promote/demote on the StateManager. + */ + stateManager.initializeState(); + + } catch(StateManagementException e) { + throw new IntegrityMonitorException(e); + } // create management bean try { @@ -378,11 +383,11 @@ public class IntegrityMonitor { * @param properties * a set of properties passed in from the resource * @return The new instance of IntegrityMonitor - * @throws Exception + * @throws IntegrityMonitorException * if unable to create jmx url or the constructor returns an * exception */ - public static IntegrityMonitor getInstance(String resourceName, Properties properties) throws Exception { + public static IntegrityMonitor getInstance(String resourceName, Properties properties) throws IntegrityMonitorException { return getInstance(resourceName, properties, null); } @@ -398,12 +403,12 @@ public class IntegrityMonitor { * @param queue * queue to use to control the FPManager thread, or {@code null} * @return The new instance of IntegrityMonitor - * @throws Exception + * @throws IntegrityMonitorException * if unable to create jmx url or the constructor returns an * exception */ protected static IntegrityMonitor getInstance(String resourceName, Properties properties, - BlockingQueue queue) throws Exception { + BlockingQueue queue) throws IntegrityMonitorException { synchronized (getInstanceLock) { logger.debug("getInstance() called - resourceName= {}", resourceName); @@ -420,7 +425,7 @@ public class IntegrityMonitor { } } - public static IntegrityMonitor getInstance() throws Exception { + public static IntegrityMonitor getInstance() throws IntegrityMonitorException { logger.debug("getInstance() called"); if (instance == null) { String msg = "No IntegrityMonitor instance exists." @@ -524,7 +529,7 @@ public class IntegrityMonitor { * disabled, it will include the dependencyCheckErrorMsg which includes * information about any dependency (node) which has failed. */ - public void evaluateSanity() throws Exception { + public void evaluateSanity() throws IntegrityMonitorException { logger.debug("evaluateSanity called ...."); synchronized (evaluateSanityLock) { @@ -1099,7 +1104,7 @@ public class IntegrityMonitor { * throws admin state exception if resource is locked * @throws StandbyStatusException */ - public void startTransaction() throws AdministrativeStateException, StandbyStatusException { + public void startTransaction() throws IntegrityMonitorException { synchronized (startTransactionLock) { // check admin state and throw exception if locked @@ -1225,7 +1230,7 @@ public class IntegrityMonitor { /** * Read and validate properties * - * @throws Exception + * @throws IntegrityMonitorPropertiesException */ private static void validateProperties(Properties prop) throws IntegrityMonitorPropertiesException { 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 index 072af236..f01be279 100644 --- 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 @@ -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. @@ -36,4 +36,10 @@ public class IntegrityMonitorException extends Exception{ super(message, cause); } + public IntegrityMonitorException(String message, Throwable cause, + boolean enableSuppression, boolean writableStackTrace) + { + super(message, cause, enableSuppression, writableStackTrace); + } + } diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorPropertiesException.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorPropertiesException.java index 24a3aeb2..0d73e8b4 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorPropertiesException.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitorPropertiesException.java @@ -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. @@ -20,7 +20,7 @@ package org.onap.policy.common.im; -public class IntegrityMonitorPropertiesException extends Exception{ +public class IntegrityMonitorPropertiesException extends IntegrityMonitorException { private static final long serialVersionUID = 1L; public IntegrityMonitorPropertiesException() { super(); diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StandbyStatusException.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StandbyStatusException.java index b871c9f5..3d27a4c6 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/StandbyStatusException.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StandbyStatusException.java @@ -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. @@ -20,7 +20,7 @@ package org.onap.policy.common.im; -public class StandbyStatusException extends Exception { +public class StandbyStatusException extends IntegrityMonitorException { /** * */ 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 ccc12d48..1d899dee 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 @@ -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. @@ -96,7 +96,7 @@ public class StateManagement extends Observable { * StateManagement constructor * @param entityManagerFactory * @param resourceName - * @throws Exception + * @throws StateManagementException */ public StateManagement(EntityManagerFactory entityManagerFactory, String resourceName) throws StateManagementException { @@ -191,7 +191,7 @@ public class StateManagement extends Observable { /** * lock() changes the administrative state to locked. - * @throws Exception + * @throws StateManagementException */ public void lock() throws StateManagementException { @@ -237,7 +237,7 @@ public class StateManagement extends Observable { /** * unlock() changes the administrative state to unlocked. - * @throws Exception + * @throws StateManagementException */ public void unlock() throws StateManagementException { @@ -283,7 +283,7 @@ public class StateManagement extends Observable { /** * enableNotFailed() removes the "failed" availability status and changes the operational * state to enabled if no dependency is also failed. - * @throws Exception + * @throws StateManagementException */ public void enableNotFailed() throws StateManagementException { @@ -329,7 +329,7 @@ public class StateManagement extends Observable { /** * disableFailed() changes the operational state to disabled and adds availability status of "failed" - * @throws Exception + * @throws StateManagementException */ public void disableFailed() throws StateManagementException { @@ -374,7 +374,7 @@ public class StateManagement extends Observable { /** * This version of disableFailed is to be used to manipulate the state of a remote resource in the event * that remote resource has failed but its state is still showing that it is viable. - * @throws Exception + * @throws StateManagementException */ public void disableFailed(String otherResourceName) throws StateManagementException { @@ -426,7 +426,7 @@ public class StateManagement extends Observable { /** * disableDependency() changes operational state to disabled and adds availability status of "dependency" - * @throws Exception + * @throws StateManagementException */ public void disableDependency() throws StateManagementException { @@ -472,7 +472,7 @@ public class StateManagement extends Observable { /** * enableNoDependency() removes the availability status of "dependency " and will change the * operational state to enabled if not otherwise failed. - * @throws Exception + * @throws StateManagementException */ public void enableNoDependency() throws StateManagementException { @@ -518,9 +518,9 @@ public class StateManagement extends Observable { /** * promote() changes the standby status to providingservice if not otherwise failed. * @throws StandbyStatusException - * @throws Exception + * @throws StateManagementException */ - public void promote() throws StandbyStatusException, StateManagementException + public void promote() throws IntegrityMonitorException { synchronized (SYNCLOCK){ if(logger.isDebugEnabled()){ @@ -570,7 +570,7 @@ public class StateManagement extends Observable { /** * demote() changes standbystatus to hotstandby or, if failed, coldstandby - * @throws Exception + * @throws StateManagementException */ public void demote() throws StateManagementException { @@ -620,7 +620,7 @@ public class StateManagement extends Observable { * this is observed by PDP-D DroolsPdpsElectionHandler when it is trying to determine which PDP-D should * be designated as the lead. * @param otherResourceName - * @throws Exception + * @throws StateManagementException */ public void demote(String otherResourceName) throws StateManagementException { 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 index 7591c1a8..0a375b07 100644 --- 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 @@ -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. @@ -20,7 +20,7 @@ package org.onap.policy.common.im; -public class StateManagementException extends Exception{ +public class StateManagementException extends IntegrityMonitorException { private static final long serialVersionUID = 1L; public StateManagementException() { super(); 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 a7f2d0ed..99c092d0 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 @@ -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. @@ -44,7 +44,7 @@ public class StateTransition { /** * StateTransition constructor - * @throws Exception + * @throws StateTransitionException */ public StateTransition() throws StateTransitionException { @@ -72,7 +72,7 @@ public class StateTransition { * @param standbyStatus * @param actionName * @return - * @throws Exception + * @throws StateTransitionException */ public StateElement getEndingState(String adminState, String opState, String availStatus, String standbyStatus, String actionName) throws StateTransitionException 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 index 3945ddcc..74998427 100644 --- 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 @@ -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. @@ -20,7 +20,7 @@ package org.onap.policy.common.im; -public class StateTransitionException extends Exception{ +public class StateTransitionException extends IntegrityMonitorException { private static final long serialVersionUID = 1L; public StateTransitionException() { super(); 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 a18b1434..eb1d9f8b 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 @@ -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. @@ -36,6 +36,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.onap.policy.common.im.IntegrityMonitor; +import org.onap.policy.common.im.IntegrityMonitorException; import org.onap.policy.common.im.StateManagement; /** @@ -187,7 +188,7 @@ public class ComponentAdmin implements ComponentAdminMBean { } @Override - public void test() throws Exception { + public void test() throws IntegrityMonitorException { // Call evaluateSanity on IntegrityMonitor to run the test logger.debug("test() called..."); if (integrityMonitor != null) { @@ -201,7 +202,7 @@ public class ComponentAdmin implements ComponentAdminMBean { } @Override - public void lock() throws Exception { + public void lock() throws IntegrityMonitorException { logger.debug("lock() called..."); if (stateManager != null) { stateManager.lock(); @@ -213,7 +214,7 @@ public class ComponentAdmin implements ComponentAdminMBean { } @Override - public void unlock() throws Exception { + public void unlock() throws IntegrityMonitorException { logger.debug("unlock() called..."); if (stateManager != null) { stateManager.unlock(); diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminException.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminException.java index e98288eb..5ada6da0 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminException.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminException.java @@ -20,7 +20,9 @@ package org.onap.policy.common.im.jmx; -public class ComponentAdminException extends Exception { +import org.onap.policy.common.im.IntegrityMonitorException; + +public class ComponentAdminException extends IntegrityMonitorException { private static final long serialVersionUID = 1L; public ComponentAdminException() { diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminMBean.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminMBean.java index d61add59..2c011935 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminMBean.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminMBean.java @@ -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. @@ -20,6 +20,8 @@ package org.onap.policy.common.im.jmx; +import org.onap.policy.common.im.IntegrityMonitorException; + /** * Provides operations to test health, lock and unlock components. */ @@ -27,24 +29,24 @@ public interface ComponentAdminMBean { /** * Test health of component. * - * @throws Exception + * @throws IntegrityMonitorException * if the component fails the health check */ - void test() throws Exception; + void test() throws IntegrityMonitorException; /** * Administratively lock component. * - * @throws Exception + * @throws IntegrityMonitorException * if the component lock fails */ - void lock() throws Exception; + void lock() throws IntegrityMonitorException; /** * Administratively unlock component. * - * @throws Exception + * @throws IntegrityMonitorException * if the component unlock fails */ - void unlock() throws Exception; + void unlock() throws IntegrityMonitorException; } 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 d15fc5e7..c9a2ce80 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 @@ -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. @@ -35,6 +35,7 @@ import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; +import org.onap.policy.common.im.IntegrityMonitorException; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; @@ -86,35 +87,41 @@ public final class JmxAgentConnection { /** * Get a connection to the jmxAgent MBeanServer. * @return the connection - * @throws Exception on error + * @throws IntegrityMonitorException on error */ - public MBeanServerConnection getMBeanConnection() throws Exception { - JMXServiceURL url; - if (jmxUrl == null) { - url = new JMXServiceURL(jmxAgentUrl(host, port)); - } - else { - url = new JMXServiceURL(jmxUrl); - } - Map env = new HashMap<>(); - - connector = JMXConnectorFactory.newJMXConnector(url, env); - connector.connect(); - connector.addConnectionNotificationListener( - new NotificationListener() { + public MBeanServerConnection getMBeanConnection() throws IntegrityMonitorException { - @Override - public void handleNotification( - Notification notification, Object handback) { - if (notification.getType().equals( - JMXConnectionNotification.FAILED)) { - // handle disconnect - disconnect(); - } - } - }, null, null); + try { + JMXServiceURL url; + if (jmxUrl == null) { + url = new JMXServiceURL(jmxAgentUrl(host, port)); + } + else { + url = new JMXServiceURL(jmxUrl); + } + Map env = new HashMap<>(); + + connector = JMXConnectorFactory.newJMXConnector(url, env); + connector.connect(); + connector.addConnectionNotificationListener( + new NotificationListener() { - return connector.getMBeanServerConnection(); + @Override + public void handleNotification( + Notification notification, Object handback) { + if (notification.getType().equals( + JMXConnectionNotification.FAILED)) { + // handle disconnect + disconnect(); + } + } + }, null, null); + + return connector.getMBeanServerConnection(); + + } catch (IOException e) { + throw new IntegrityMonitorException(e); + } } /** diff --git a/integrity-monitor/src/test/java/org/onap/policy/common/im/ExceptionsTest.java b/integrity-monitor/src/test/java/org/onap/policy/common/im/ExceptionsTest.java index 5066f9d5..90de7c66 100644 --- a/integrity-monitor/src/test/java/org/onap/policy/common/im/ExceptionsTest.java +++ b/integrity-monitor/src/test/java/org/onap/policy/common/im/ExceptionsTest.java @@ -61,7 +61,7 @@ public class ExceptionsTest extends ExceptionsTester { @Test public void testIntegrityMonitorException() throws Exception { - assertEquals(4, test(IntegrityMonitorException.class)); + assertEquals(5, test(IntegrityMonitorException.class)); } @Test -- cgit 1.2.3-korg