aboutsummaryrefslogtreecommitdiffstats
path: root/integrity-audit
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-13 12:34:17 -0400
committerJim Hahn <jrh3@att.com>2019-06-13 16:10:38 -0400
commitfe5d78724f723a451ddc0d7cc41d6fc60092b314 (patch)
tree9913cc94014b3e99774e9ec5e39a7211046a765a /integrity-audit
parentea262e6da52fd4da0733f02998f87aebaf502ddb (diff)
More sonar fixes in policy/common
Note: this does not increase code coverage, but should fix other code issues. Resolved cyclomatic complexity issue in ParameterValidationResult. Refactored duplicate code in GroupValidationResult. Removed IOException from NetworkUtil "throws". Replaced null/empty string tests with StringUtils.isBlank(). Added @FunctionalInterface where needed. Replaced anonymous classes with lambda expressions. Replaced duplicate strings with a constant. Added private constructors for utility classes. Removed sleep() from tests. Removed unused parameter from method call. Made some protected methods private. Compute integrity monitor's state-transition table once. Use for-loop instead of iterator. Moved constructors. Fixed some checkstyle issues (tabs => spaces, trailing spaces). Change-Id: I9a962ca45c4ff3f212c6014da799d06f07b232ef Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'integrity-audit')
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java39
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java30
2 files changed, 33 insertions, 36 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 2e996cdb..df979286 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
@@ -7,9 +7,9 @@
* 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.
@@ -32,7 +32,7 @@ import org.onap.policy.common.logging.flexlogger.Logger;
/**
* AuditThread is the main thread for the IntegrityAudit.
- *
+ *
*/
public class AuditThread extends Thread {
@@ -55,7 +55,7 @@ public class AuditThread extends Thread {
* May be modified by JUnit tests.
*/
private static final long AUDIT_THREAD_SLEEP_INTERVAL_MS = 5000L;
-
+
/*
* String constants.
*/
@@ -102,16 +102,11 @@ public class AuditThread extends Thread {
/*
* Used to create a list that is sorted lexicographically by resourceName.
*/
- Comparator<IntegrityAuditEntity> comparator = new Comparator<IntegrityAuditEntity>() {
- @Override
- public int compare(final IntegrityAuditEntity r1, final IntegrityAuditEntity r2) {
- return r1.getResourceName().compareTo(r2.getResourceName());
- }
- };
+ Comparator<IntegrityAuditEntity> comparator = (r1, r2) -> r1.getResourceName().compareTo(r2.getResourceName());
/**
* AuditThread constructor.
- *
+ *
* @param resourceName the resource name
* @param persistenceUnit the persistence unit
* @param properties the properties
@@ -121,7 +116,7 @@ public class AuditThread extends Thread {
*/
public AuditThread(String resourceName, String persistenceUnit, Properties properties,
int integrityAuditPeriodSeconds, IntegrityAudit integrityAudit) throws IntegrityAuditException {
-
+
this.resourceName = resourceName;
this.persistenceUnit = persistenceUnit;
this.properties = properties;
@@ -307,7 +302,7 @@ public class AuditThread extends Thread {
/**
* Determines if an exception is an InterruptedException or was caused by an
* InterruptedException.
- *
+ *
* @param ex exception to be examined
* @return {@code true} if it's an InterruptedException, {@code false} otherwise
*/
@@ -472,7 +467,7 @@ public class AuditThread extends Thread {
/**
* getEntityCurrentlyDesignated() Returns entity that is currently designated.
- *
+ *
* @param integrityAuditEntityList the integrity audit entity list
* @return the currently designated integrity audit entity
*/
@@ -514,7 +509,7 @@ public class AuditThread extends Thread {
/**
* getIntegrityAuditEnityList gets the list of IntegrityAuditEntity.
- *
+ *
* @return the list of IntegrityAuditEntity
* @throws DbDaoTransactionException if an error occurs getting the list of IntegrityAuditEntity
*/
@@ -550,7 +545,7 @@ public class AuditThread extends Thread {
/**
* Returns the IntegrityAuditEntity for this entity.
- *
+ *
* @param integrityAuditEntityList the list of IntegrityAuditEntity
* @return the IntegrityAuditEntity for this entity
*/
@@ -593,7 +588,7 @@ public class AuditThread extends Thread {
* auditCompletionIntervalMillis seconds ago. During an audit, lastUpdated is updated every five
* seconds or so, but when an audit finishes, the node doing the audit stops updating
* lastUpdated.
- *
+ *
* @param integrityAuditEntity the integrityAuditEntity
* @return false if the lastUpdated time for the record in question is more than
* auditCompletionIntervalMillis seconds ago
@@ -645,11 +640,11 @@ public class AuditThread extends Thread {
/*
* If more than (auditCompletionIntervalMillis * 2) milliseconds have elapsed since we last ran
* the audit, reset auditCompleted, so
- *
+ *
* 1) we'll eventually re-run the audit, if no other node picks up the designation.
- *
+ *
* or
- *
+ *
* 2) We'll run the audit when the round robin comes back to us.
*/
private boolean resetAuditCompleted(boolean auditCompleted, IntegrityAuditEntity thisEntity) {
@@ -716,7 +711,7 @@ public class AuditThread extends Thread {
/**
* Indicates that the {@link #run()} method has started. This method simply returns,
* and may overridden by junit tests.
- *
+ *
* @throws InterruptedException can be interrupted
*/
public void runStarted() throws InterruptedException {
@@ -726,7 +721,7 @@ public class AuditThread extends Thread {
/**
* Indicates that an audit has completed. This method simply returns, and may
* overridden by junit tests.
- *
+ *
* @throws InterruptedException can be interrupted
*/
public void auditCompleted() throws InterruptedException {
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 14e0d33a..9a73b79c 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
@@ -7,9 +7,9 @@
* 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.
@@ -46,6 +46,8 @@ public class DbAudit {
private static final Logger logger = FlexLogger.getLogger(DbAudit.class);
+ private static final String COMMA_RESOURCE_NAME = ", resourceName=";
+
private static final long DB_AUDIT_UPDATE_MS = 5000L;
private static final long DB_AUDIT_SLEEP_MS = 2000L;
@@ -53,7 +55,7 @@ public class DbAudit {
/**
* Construct an instance with the given DbDao.
- *
+ *
* @param dbDao the DbDao
*/
public DbAudit(DbDao dbDao) {
@@ -72,7 +74,7 @@ public class DbAudit {
/**
* dbAudit actually does the audit.
- *
+ *
* @param resourceName the resource name
* @param persistenceUnit the persistence unit
* @param nodeType the node type
@@ -165,12 +167,12 @@ public class DbAudit {
for (IntegrityAuditEntity iae : iaeList) {
if (iae.getId() == myIae.getId()) {
if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: My Id=" + iae.getId() + ", resourceName=" + iae.getResourceName());
+ logger.debug("dbAudit: My Id=" + iae.getId() + COMMA_RESOURCE_NAME + iae.getResourceName());
}
continue; // no need to compare with self
} else {
if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Id=" + iae.getId() + ", resourceName=" + iae.getResourceName());
+ logger.debug("dbAudit: Id=" + iae.getId() + COMMA_RESOURCE_NAME + iae.getResourceName());
}
}
// Create properties for the other db node
@@ -268,13 +270,13 @@ public class DbAudit {
for (IntegrityAuditEntity iae : iaeList) {
if (iae.getId() == myIae.getId()) {
if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Second comparison; My Id=" + iae.getId() + ", resourceName="
+ logger.debug("dbAudit: Second comparison; My Id=" + iae.getId() + COMMA_RESOURCE_NAME
+ iae.getResourceName());
}
continue; // no need to compare with self
} else {
if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Second comparison; Id=" + iae.getId() + ", resourceName="
+ logger.debug("dbAudit: Second comparison; Id=" + iae.getId() + COMMA_RESOURCE_NAME
+ iae.getResourceName());
}
}
@@ -345,7 +347,7 @@ public class DbAudit {
/**
* Sleeps a bit.
- *
+ *
* @throws IntegrityAuditException if interrupted
*/
private void sleep() throws IntegrityAuditException {
@@ -360,7 +362,7 @@ public class DbAudit {
/**
* compareEntries() will compare the lists of entries from the DB.
- *
+ *
* @param myEntries the entries
* @param theirEntries the entries to compare against myEntries
* @return the set of differences
@@ -372,10 +374,10 @@ public class DbAudit {
* audit will walk the local repository hash map comparing to the remote cluster hashmap and
* then turn it around and walk the remote hashmap and look for any entries that are not
* present in the local cluster hashmap.
- *
+ *
* If the objects are not identical, the audit will put the object IDs on a list to try
* after completing the audit of the table it is currently working on.
- *
+ *
*/
HashSet<Object> misMatchedKeySet = new HashSet<>();
for (Entry<Object, Object> ent : myEntries.entrySet()) {
@@ -409,7 +411,7 @@ public class DbAudit {
/**
* writeAuditDebugLog() writes the mismatched entry details to the debug log.
- *
+ *
* @param clazzName the class name
* @param resourceName1 resource name 1
* @param resourceName2 resource name 2
@@ -441,7 +443,7 @@ public class DbAudit {
/**
* writeAuditSummaryLog() writes a summary of the DB mismatches to the error log.
- *
+ *
* @param clazzName the name of the class
* @param resourceName1 resource name 1
* @param resourceName2 resource name 2