aboutsummaryrefslogtreecommitdiffstats
path: root/integrity-audit/src
diff options
context:
space:
mode:
Diffstat (limited to 'integrity-audit/src')
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java88
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java64
2 files changed, 87 insertions, 65 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 177391c3..51752329 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
@@ -55,6 +55,14 @@ public class AuditThread extends Thread {
* May be modified by JUnit tests.
*/
private static final long AUDIT_THREAD_SLEEP_INTERVAL_MS = 5000L;
+
+ /*
+ * String constants.
+ */
+ private static final String AUDIT_THREAD_MESSAGE = "AuditThread.run: resourceName=";
+ private static final String ENTITY_INDEX_MESSAGE = ", entityIndex=";
+ private static final String LAST_UPDATED_MESSAGE = ", lastUpdated=";
+ private static final String PERSISTENCE_MESSAGE = ", persistenceUnit=";
/*
* DB access class.
@@ -91,6 +99,16 @@ public class AuditThread extends Thread {
*/
private IntegrityAudit integrityAudit;
+ /*
+ * Used to create a list that is sorted lexicographically by resourceName.
+ */
+ Comparator<IntegrityAuditEntity> comparator = new Comparator<IntegrityAuditEntity>() {
+ @Override
+ public int compare(final IntegrityAuditEntity r1, final IntegrityAuditEntity r2) {
+ return r1.getResourceName().compareTo(r2.getResourceName());
+ }
+ };
+
/**
* AuditThread constructor.
*
@@ -241,19 +259,19 @@ public class AuditThread extends Thread {
}
AuditorTime.getInstance().sleep(integrityAuditPeriodSeconds * 1000L);
if (logger.isDebugEnabled()) {
- logger.debug("AuditThread.run: resourceName=" + this.resourceName + " awaking from "
+ logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + " awaking from "
+ integrityAuditPeriodSeconds + "s sleep");
}
} else {
if (logger.isDebugEnabled()) {
- logger.debug("AuditThread.run: resourceName=" + this.resourceName + ": Sleeping "
+ logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + ": Sleeping "
+ AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS + "ms");
}
AuditorTime.getInstance().sleep(AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS);
if (logger.isDebugEnabled()) {
- logger.debug("AuditThread.run: resourceName=" + this.resourceName + ": Awaking from "
+ logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + ": Awaking from "
+ AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS + "ms sleep");
}
@@ -305,16 +323,6 @@ public class AuditThread extends Thread {
return false;
}
- /*
- * Used to create a list that is sorted lexicographically by resourceName.
- */
- Comparator<IntegrityAuditEntity> comparator = new Comparator<IntegrityAuditEntity>() {
- @Override
- public int compare(final IntegrityAuditEntity r1, final IntegrityAuditEntity r2) {
- return r1.getResourceName().compareTo(r2.getResourceName());
- }
- };
-
/**
* getDesignationCandidate() Using round robin algorithm, gets next candidate to be designated.
* Assumes list is sorted lexicographically by resourceName.
@@ -353,9 +361,9 @@ public class AuditThread extends Thread {
if (integrityAuditEntity.isDesignated()) {
if (logger.isDebugEnabled()) {
logger.debug("getDesignationCandidate: Currently designated entity resourceName="
- + integrityAuditEntity.getResourceName() + ", persistenceUnit="
- + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
- + integrityAuditEntity.getLastUpdated() + ", entityIndex=" + entityIndex);
+ + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+ + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
}
designatedEntityIndex = entityIndex;
@@ -371,9 +379,9 @@ public class AuditThread extends Thread {
if (logger.isDebugEnabled()) {
logger.debug("getDesignationCandidate: Entity is stale; resourceName="
- + integrityAuditEntity.getResourceName() + ", persistenceUnit="
- + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
- + integrityAuditEntity.getLastUpdated() + ", entityIndex=" + entityIndex);
+ + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+ + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
}
/*
@@ -386,9 +394,9 @@ public class AuditThread extends Thread {
if (priorCandidateIndex == -1) {
if (logger.isDebugEnabled()) {
logger.debug("getDesignationCandidate: Prior candidate found, resourceName="
- + integrityAuditEntity.getResourceName() + ", persistenceUnit="
- + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
- + integrityAuditEntity.getLastUpdated() + ", entityIndex=" + entityIndex);
+ + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+ + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
}
priorCandidateIndex = entityIndex;
} else {
@@ -396,18 +404,18 @@ public class AuditThread extends Thread {
logger.debug(
"getDesignationCandidate: Prior entity current but prior candidate already "
+ "found; resourceName=" + integrityAuditEntity.getResourceName()
- + ", persistenceUnit=" + integrityAuditEntity.getPersistenceUnit()
- + ", lastUpdated=" + integrityAuditEntity.getLastUpdated()
- + ", entityIndex=" + entityIndex);
+ + PERSISTENCE_MESSAGE + integrityAuditEntity.getPersistenceUnit()
+ + LAST_UPDATED_MESSAGE + integrityAuditEntity.getLastUpdated()
+ + ENTITY_INDEX_MESSAGE + entityIndex);
}
}
} else {
if (subsequentCandidateIndex == -1) {
if (logger.isDebugEnabled()) {
logger.debug("getDesignationCandidate: Subsequent candidate found, resourceName="
- + integrityAuditEntity.getResourceName() + ", persistenceUnit="
- + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
- + integrityAuditEntity.getLastUpdated() + ", entityIndex=" + entityIndex);
+ + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+ + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
}
subsequentCandidateIndex = entityIndex;
} else {
@@ -415,9 +423,9 @@ public class AuditThread extends Thread {
logger.debug(
"getDesignationCandidate: Subsequent entity current but subsequent candidate "
+ "already found; resourceName="
- + integrityAuditEntity.getResourceName() + ", persistenceUnit="
- + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
- + integrityAuditEntity.getLastUpdated() + ", entityIndex="
+ + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+ + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE
+ entityIndex);
}
}
@@ -482,8 +490,8 @@ public class AuditThread extends Thread {
if (integrityAuditEntity.isDesignated()) {
if (logger.isDebugEnabled()) {
logger.debug("getEntityCurrentlyDesignated: Currently designated entity resourceName="
- + integrityAuditEntity.getResourceName() + ", persistenceUnit="
- + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
+ + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+ + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ integrityAuditEntity.getLastUpdated());
}
entityCurrentlyDesignated = integrityAuditEntity;
@@ -560,8 +568,8 @@ public class AuditThread extends Thread {
if (logger.isDebugEnabled()) {
logger.debug(
"getThisEntity: For this entity, resourceName=" + integrityAuditEntity.getResourceName()
- + ", persistenceUnit=" + integrityAuditEntity.getPersistenceUnit()
- + ", lastUpdated=" + integrityAuditEntity.getLastUpdated());
+ + PERSISTENCE_MESSAGE + integrityAuditEntity.getPersistenceUnit()
+ + LAST_UPDATED_MESSAGE + integrityAuditEntity.getLastUpdated());
}
thisEntity = integrityAuditEntity;
}
@@ -594,7 +602,7 @@ public class AuditThread extends Thread {
if (logger.isDebugEnabled()) {
logger.debug("isStale: Entering, resourceName=" + integrityAuditEntity.getResourceName()
- + ", persistenceUnit=" + integrityAuditEntity.getPersistenceUnit() + ", lastUpdated="
+ + PERSISTENCE_MESSAGE + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ integrityAuditEntity.getLastUpdated());
}
@@ -627,10 +635,10 @@ public class AuditThread extends Thread {
logger.debug("logIntegrityAuditEntity: id=" + integrityAuditEntity.getId() + ", jdbcDriver="
+ integrityAuditEntity.getJdbcDriver() + ", jdbcPassword=" + integrityAuditEntity.getJdbcPassword()
+ ", jdbcUrl=" + integrityAuditEntity.getJdbcUrl() + ", jdbcUser=" + integrityAuditEntity.getJdbcUser()
- + ", nodeType=" + integrityAuditEntity.getNodeType() + ", persistenceUnit="
+ + ", nodeType=" + integrityAuditEntity.getNodeType() + PERSISTENCE_MESSAGE
+ integrityAuditEntity.getPersistenceUnit() + ", resourceName=" + integrityAuditEntity.getResourceName()
+ ", site=" + integrityAuditEntity.getSite() + ", createdDate=" + integrityAuditEntity.getCreatedDate()
- + ", lastUpdated=" + integrityAuditEntity.getLastUpdated() + ", designated="
+ + LAST_UPDATED_MESSAGE + integrityAuditEntity.getLastUpdated() + ", designated="
+ integrityAuditEntity.isDesignated());
}
@@ -648,8 +656,8 @@ public class AuditThread extends Thread {
if (logger.isDebugEnabled()) {
logger.debug("resetAuditCompleted: auditCompleted=" + auditCompleted + "; for thisEntity, resourceName="
- + thisEntity.getResourceName() + ", persistenceUnit=" + thisEntity.getPersistenceUnit()
- + ", lastUpdated=" + thisEntity.getLastUpdated());
+ + thisEntity.getResourceName() + PERSISTENCE_MESSAGE + thisEntity.getPersistenceUnit()
+ + LAST_UPDATED_MESSAGE + thisEntity.getLastUpdated());
}
long timeDifference;
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 ef765f36..611fda98 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
@@ -65,6 +65,20 @@ public class DbDAO {
* Supports designation serialization.
*/
private static final Object lock = new Object();
+
+ /*
+ * Common strings.
+ */
+ private static final String RESOURCE_MESSAGE = "Resource: ";
+ private static final String WITH_PERSISTENCE_MESSAGE = " with PersistenceUnit: ";
+ private static final String DBDAO_MESSAGE = "DbDAO: ";
+ private static final String ENCOUNTERED_MESSAGE = "ecountered a problem in execution: ";
+
+ /*
+ * DB SELECT String.
+ */
+ private static final String SELECT_STRING = "Select i from IntegrityAuditEntity i "
+ + "where i.resourceName=:rn and i.persistenceUnit=:pu";
/**
* DbDAO Constructor.
@@ -303,7 +317,7 @@ public class DbDAO {
logger.debug("getIntegrityAuditEntities: Exit, iaeList=" + iaeList);
return iaeList;
} catch (Exception e) {
- String msg = "DbDAO: " + "getIntegrityAuditEntities() " + "ecountered a problem in execution: ";
+ String msg = DBDAO_MESSAGE + "getIntegrityAuditEntities() " + ENCOUNTERED_MESSAGE;
logger.error(msg, e);
throw new DbDaoTransactionException(e);
}
@@ -327,7 +341,7 @@ public class DbDAO {
// if IntegrityAuditEntity entry exists for resourceName and PU, retrieve it
Query iaequery = em.createQuery(
- "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+ SELECT_STRING);
iaequery.setParameter("rn", this.resourceName);
iaequery.setParameter("pu", this.persistenceUnit);
@@ -340,12 +354,12 @@ public class DbDAO {
iae = (IntegrityAuditEntity) iaeList.get(0);
// refresh the object from DB in case cached data was returned
em.refresh(iae);
- logger.info("Resource: " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit
+ logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit
+ " exists");
} else {
// If it does not exist, log an error
- logger.error("Attempting to setLastUpdated" + " on an entry that does not exist:" + " resource "
- + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit);
+ logger.error("Attempting to setLastUpdated" + " on an entry that does not exist: resource "
+ + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit);
}
// close the transaction
@@ -355,7 +369,7 @@ public class DbDAO {
return iae;
} catch (Exception e) {
- String msg = "DbDAO: " + "setLastUpdated() " + "ecountered a problem in execution: ";
+ String msg = DBDAO_MESSAGE + "setLastUpdated() " + ENCOUNTERED_MESSAGE;
logger.error(msg + e);
throw new DbDaoTransactionException(e);
}
@@ -385,7 +399,7 @@ public class DbDAO {
return iae;
} catch (Exception e) {
- String msg = "DbDAO: " + "getIntegrityAuditEntity() " + "ecountered a problem in execution: ";
+ String msg = DBDAO_MESSAGE + "getIntegrityAuditEntity() " + ENCOUNTERED_MESSAGE;
logger.error(msg + e);
throw new DbDaoTransactionException(e);
}
@@ -428,7 +442,7 @@ public class DbDAO {
// if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not
// found, create a new entry
Query iaequery = em.createQuery(
- "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+ SELECT_STRING);
iaequery.setParameter("rn", this.resourceName);
iaequery.setParameter("pu", this.persistenceUnit);
@@ -442,12 +456,12 @@ public class DbDAO {
iae = (IntegrityAuditEntity) iaeList.get(0);
// refresh the object from DB in case cached data was returned
em.refresh(iae);
- logger.info("Resource: " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit
+ logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit
+ " exists and entry be updated");
} else {
// If it does not exist, we also must add teh resourceName, persistenceUnit and
// designated values
- logger.info("Adding resource " + resourceName + " with PersistenceUnit: " + this.persistenceUnit
+ logger.info("Adding resource " + resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit
+ " to IntegrityAuditEntity table");
iae = new IntegrityAuditEntity();
iae.setResourceName(this.resourceName);
@@ -470,7 +484,7 @@ public class DbDAO {
et.commit();
em.close();
} catch (Exception e) {
- String msg = "DbDAO: " + "register() " + "encountered a problem in execution: ";
+ String msg = DBDAO_MESSAGE + "register() " + "encountered a problem in execution: ";
logger.error(msg + e);
throw new DbDaoTransactionException(e);
}
@@ -505,7 +519,7 @@ public class DbDAO {
// if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not
// found, create a new entry
Query iaequery = em.createQuery(
- "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+ SELECT_STRING);
iaequery.setParameter("rn", resourceName);
iaequery.setParameter("pu", persistenceUnit);
@@ -518,7 +532,7 @@ public class DbDAO {
iae = (IntegrityAuditEntity) iaeList.get(0);
// refresh the object from DB in case cached data was returned
em.refresh(iae);
- logger.info("Resource: " + resourceName + " with PersistenceUnit: " + persistenceUnit
+ logger.info(RESOURCE_MESSAGE + resourceName + WITH_PERSISTENCE_MESSAGE + persistenceUnit
+ " exists and designated be updated");
iae.setDesignated(desig);
@@ -528,7 +542,7 @@ public class DbDAO {
} else {
// If it does not exist, log an error
logger.error("Attempting to setDesignated(" + desig + ") on an entry that does not exist:"
- + " resource " + resourceName + " with PersistenceUnit: " + persistenceUnit);
+ + " resource " + resourceName + WITH_PERSISTENCE_MESSAGE + persistenceUnit);
}
// close the transaction
@@ -536,7 +550,7 @@ public class DbDAO {
// close the EntityManager
em.close();
} catch (Exception e) {
- String msg = "DbDAO: " + "setDesignated() " + "ecountered a problem in execution: ";
+ String msg = DBDAO_MESSAGE + "setDesignated() " + ENCOUNTERED_MESSAGE;
logger.error(msg + e);
throw new DbDaoTransactionException(e);
}
@@ -562,7 +576,7 @@ public class DbDAO {
// if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not
// found, create a new entry
Query iaequery = em.createQuery(
- "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+ SELECT_STRING);
iaequery.setParameter("rn", this.resourceName);
iaequery.setParameter("pu", this.persistenceUnit);
@@ -575,7 +589,7 @@ public class DbDAO {
iae = (IntegrityAuditEntity) iaeList.get(0);
// refresh the object from DB in case cached data was returned
em.refresh(iae);
- logger.info("Resource: " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit
+ logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit
+ " exists and lastUpdated be updated");
iae.setLastUpdated(AuditorTime.getInstance().getDate());
@@ -585,7 +599,7 @@ public class DbDAO {
} else {
// If it does not exist, log an error
logger.error("Attempting to setLastUpdated" + " on an entry that does not exist:" + " resource "
- + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit);
+ + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit);
}
// close the transaction
@@ -593,7 +607,7 @@ public class DbDAO {
// close the EntityManager
em.close();
} catch (Exception e) {
- String msg = "DbDAO: " + "setLastUpdated() " + "ecountered a problem in execution: ";
+ String msg = DBDAO_MESSAGE + "setLastUpdated() " + ENCOUNTERED_MESSAGE;
logger.error(msg + e);
throw new DbDaoTransactionException(e);
}
@@ -609,7 +623,7 @@ public class DbDAO {
try {
if (!IntegrityAudit.isUnitTesting()) {
- String msg = "DbDAO: " + "deleteAllIntegrityAuditEntities() "
+ String msg = DBDAO_MESSAGE + "deleteAllIntegrityAuditEntities() "
+ "should only be invoked during JUnit testing";
logger.error(msg);
throw new DbDaoTransactionException(msg);
@@ -636,7 +650,7 @@ public class DbDAO {
return returnCode;
} catch (Exception e) {
- String msg = "DbDAO: " + "deleteAllIntegrityAuditEntities() " + "encountered a problem in execution: ";
+ String msg = DBDAO_MESSAGE + "deleteAllIntegrityAuditEntities() " + "encountered a problem in execution: ";
logger.error(msg + e);
throw new DbDaoTransactionException(e);
}
@@ -729,12 +743,12 @@ public class DbDAO {
if (em != null) {
em.getTransaction().rollback();
- String msg = "DbDAO: " + "changeDesignated() " + "caught LockTimeoutException, message="
+ String msg = "DbDAO: changeDesignated() caught LockTimeoutException, message="
+ e.getMessage();
logger.error(msg + e);
throw new DbDaoTransactionException(msg, e);
} else {
- String msg = "DbDAO: " + "changeDesignated() " + "caught LockTimeoutException, message="
+ String msg = "DbDAO: changeDesignated() caught LockTimeoutException, message="
+ e.getMessage() + ". Error rolling back transaction.";
logger.error(msg + e);
throw new DbDaoTransactionException(msg, e);
@@ -743,11 +757,11 @@ public class DbDAO {
if (em != null) {
em.getTransaction().rollback();
- String msg = "DbDAO: " + "changeDesignated() " + "caught Exception, message=" + e.getMessage();
+ String msg = "DbDAO: changeDesignated() caught Exception, message=" + e.getMessage();
logger.error(msg + e);
throw new DbDaoTransactionException(msg, e);
} else {
- String msg = "DbDAO: " + "changeDesignated() " + "caught LockTimeoutException, message="
+ String msg = "DbDAO: changeDesignated() caught Exception, message="
+ e.getMessage() + ". Error rolling back transaction.";
logger.error(msg + e);
throw new DbDaoTransactionException(msg, e);