diff options
author | Jim Hahn <jrh3@att.com> | 2018-02-16 18:11:21 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2018-02-16 18:29:40 -0500 |
commit | 45f97b0b7735c9ac75c3f0d010b9524b47807cb8 (patch) | |
tree | 2fc61fb13e587c9f5af1a9e3b02ca512504d3631 /integrity-audit/src | |
parent | 2b0b96e27b11904bb36d8f4887aa28a913727fad (diff) |
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 <jrh3@att.com>
Diffstat (limited to 'integrity-audit/src')
8 files changed, 75 insertions, 45 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<CountDownLatch> 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"); } @@ -348,6 +348,20 @@ public class DbAudit { } /** + * 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 * @param persistenceUnit @@ -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<CountDownLatch> queue) throws Exception { + protected boolean startAuditThread(BlockingQueue<CountDownLatch> 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); + } } } |