summaryrefslogtreecommitdiffstats
path: root/integrity-audit/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'integrity-audit/src/main/java')
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java117
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/AuditorTime.java56
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java97
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java14
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java44
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java1
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/jpa/IntegrityAuditEntity.java5
7 files changed, 115 insertions, 219 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 58ed8b99..dc396a07 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
@@ -25,7 +25,6 @@ import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Properties;
-import java.util.concurrent.TimeUnit;
import org.onap.policy.common.ia.jpa.IntegrityAuditEntity;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
@@ -43,31 +42,19 @@ public class AuditThread extends Thread {
* Number of milliseconds that must elapse for audit to be considered complete. It's public for
* access by JUnit test logic.
*/
- public static final long AUDIT_COMPLETION_INTERVAL = 30000;
+ public static final long AUDIT_COMPLETION_INTERVAL = 30000L;
- /*
- * Number of iterations for audit simulation.
- */
- public static final long AUDIT_SIMULATION_ITERATIONS = 3;
-
- /*
- * Number of milliseconds to sleep between audit simulation iterations. It's public for access
- * by JUnit test logic.
+ /**
+ * Number of audit cycles before the completion flag is reset.
*/
- public static final long AUDIT_SIMULATION_SLEEP_INTERVAL = 5000;
+ public static final int AUDIT_RESET_CYCLES = 2;
/*
* Unless audit has already been run on this entity, number of milliseconds to sleep between
* audit thread iterations. If audit has already been run, we sleep integrityAuditPeriodMillis.
* May be modified by JUnit tests.
*/
- private static long auditThreadSleepIntervalMillis = 5000;
-
- /*
- * Number of milliseconds that must elapse for audit to be considered complete. May be modified
- * by JUnit tests.
- */
- private static long auditCompletionIntervalMillis = AUDIT_COMPLETION_INTERVAL;
+ private static final long AUDIT_THREAD_SLEEP_INTERVAL_MS = 5000L;
/*
* DB access class.
@@ -97,7 +84,7 @@ public class AuditThread extends Thread {
/*
* See IntegrityAudit class for usage.
*/
- private long integrityAuditPeriodMillis;
+ private int integrityAuditPeriodSeconds;
/*
* The containing IntegrityAudit instance
@@ -116,28 +103,11 @@ public class AuditThread extends Thread {
*/
public AuditThread(String resourceName, String persistenceUnit, Properties properties,
int integrityAuditPeriodSeconds, IntegrityAudit integrityAudit) throws IntegrityAuditException {
-
- this(resourceName, persistenceUnit, properties, TimeUnit.SECONDS.toMillis(integrityAuditPeriodSeconds),
- integrityAudit);
- }
-
- /**
- * AuditThread constructor.
- *
- * @param resourceName the resource name
- * @param persistenceUnit the persistence unit
- * @param properties the properties
- * @param integrityAuditMillis the integrity audit period in milliseconds
- * @param integrityAudit the integrity audit
- * @param queue the queue
- * @throws IntegrityAuditException if an error occurs
- */
- public AuditThread(String resourceName, String persistenceUnit, Properties properties, long integrityAuditMillis,
- IntegrityAudit integrityAudit) throws IntegrityAuditException {
+
this.resourceName = resourceName;
this.persistenceUnit = persistenceUnit;
this.properties = properties;
- this.integrityAuditPeriodMillis = integrityAuditMillis;
+ this.integrityAuditPeriodSeconds = integrityAuditPeriodSeconds;
this.integrityAudit = integrityAudit;
/*
@@ -267,24 +237,24 @@ public class AuditThread extends Thread {
if (logger.isDebugEnabled()) {
logger.debug("AuditThread.run: Audit completed; resourceName=" + this.resourceName
- + " sleeping " + integrityAuditPeriodMillis + "ms");
+ + " sleeping " + integrityAuditPeriodSeconds + "s");
}
- Thread.sleep(integrityAuditPeriodMillis);
+ AuditorTime.getInstance().sleep(integrityAuditPeriodSeconds * 1000L);
if (logger.isDebugEnabled()) {
logger.debug("AuditThread.run: resourceName=" + this.resourceName + " awaking from "
- + integrityAuditPeriodMillis + "ms sleep");
+ + integrityAuditPeriodSeconds + "s sleep");
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("AuditThread.run: resourceName=" + this.resourceName + ": Sleeping "
- + AuditThread.auditThreadSleepIntervalMillis + "ms");
+ + AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS + "ms");
}
- Thread.sleep(AuditThread.auditThreadSleepIntervalMillis);
+ AuditorTime.getInstance().sleep(AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS);
if (logger.isDebugEnabled()) {
logger.debug("AuditThread.run: resourceName=" + this.resourceName + ": Awaking from "
- + AuditThread.auditThreadSleepIntervalMillis + "ms sleep");
+ + AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS + "ms sleep");
}
}
@@ -297,10 +267,10 @@ public class AuditThread extends Thread {
}
String msg = "AuditThread.run loop - Exception thrown: " + e.getMessage()
- + "; Will try audit again in " + (integrityAuditPeriodMillis / 1000) + " seconds";
+ + "; Will try audit again in " + integrityAuditPeriodSeconds + " seconds";
logger.error(MessageCodes.EXCEPTION_ERROR, e, msg);
// Sleep and try again later
- Thread.sleep(integrityAuditPeriodMillis);
+ AuditorTime.getInstance().sleep(integrityAuditPeriodSeconds * 1000L);
}
}
@@ -630,7 +600,7 @@ public class AuditThread extends Thread {
boolean stale = false;
- Date currentTime = new Date();
+ Date currentTime = AuditorTime.getInstance().getDate();
Date lastUpdated = integrityAuditEntity.getLastUpdated();
/*
@@ -641,7 +611,7 @@ public class AuditThread extends Thread {
lastUpdatedTime = lastUpdated.getTime();
}
long timeDifference = currentTime.getTime() - lastUpdatedTime;
- if (timeDifference > auditCompletionIntervalMillis) {
+ if (timeDifference > AUDIT_COMPLETION_INTERVAL) {
stale = true;
}
@@ -684,13 +654,13 @@ public class AuditThread extends Thread {
long timeDifference;
- Date currentTime = new Date();
+ Date currentTime = AuditorTime.getInstance().getDate();
Date lastUpdated = thisEntity.getLastUpdated();
long lastUpdatedTime = lastUpdated.getTime();
timeDifference = currentTime.getTime() - lastUpdatedTime;
- if (timeDifference > (auditCompletionIntervalMillis * 2)) {
+ if (timeDifference > (AUDIT_COMPLETION_INTERVAL * AUDIT_RESET_CYCLES)) {
if (logger.isDebugEnabled()) {
logger.debug("resetAuditCompleted: Resetting auditCompleted for resourceName=" + this.resourceName);
}
@@ -726,12 +696,8 @@ public class AuditThread extends Thread {
logger.debug("runAudit: Running audit for persistenceUnit=" + this.persistenceUnit + " on resourceName="
+ this.resourceName);
}
- if (IntegrityAudit.isUnitTesting()) {
- dbAudit.dbAuditSimulate(this.resourceName, this.persistenceUnit, AuditThread.AUDIT_SIMULATION_ITERATIONS,
- AuditThread.auditThreadSleepIntervalMillis);
- } else {
- dbAudit.dbAudit(this.resourceName, this.persistenceUnit, this.nodeType);
- }
+
+ dbAudit.dbAudit(this.resourceName, this.persistenceUnit, this.nodeType);
if (logger.isDebugEnabled()) {
logger.debug("runAudit: Exiting");
@@ -758,43 +724,4 @@ public class AuditThread extends Thread {
public void auditCompleted() throws InterruptedException {
// does nothing
}
-
- /**
- * Adjusts the thread-sleep-interval to be used when an audit has <i>not</i> been completed.
- * Used by JUnit tests.
- *
- * @param auditThreadSleepIntervalMillis the interval to use in milliseconds
- */
- protected static void setAuditThreadSleepIntervalMillis(long auditThreadSleepIntervalMillis) {
- AuditThread.auditThreadSleepIntervalMillis = auditThreadSleepIntervalMillis;
- }
-
- /**
- * Gets the current thread-sleep-interval to be used when an audit has <i>not</i> been
- * completed. Used by JUnit tests.
- *
- * @return the current sleep interval, in milli-seconds
- */
- protected static long getAuditThreadSleepIntervalMillis() {
- return auditThreadSleepIntervalMillis;
- }
-
- /**
- * Adjusts the audit-completion-interval. Used by JUnit tests.
- *
- * @param auditThreadSleepIntervalMillis the interval to use in milliseconds
- */
- protected static void setAuditCompletionIntervalMillis(long auditThreadSleepIntervalMillis) {
- AuditThread.auditCompletionIntervalMillis = auditThreadSleepIntervalMillis;
- }
-
- /**
- * Gets the audit-completion-interval. Used by JUnit tests.
- *
- * @return the current audit-completion interval, in milli-seconds
- */
- protected static long getAuditCompletionIntervalMillis() {
- return auditCompletionIntervalMillis;
- }
-
}
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditorTime.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditorTime.java
new file mode 100644
index 00000000..9cff742c
--- /dev/null
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditorTime.java
@@ -0,0 +1,56 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Integrity Audit
+ * ================================================================================
+ * Copyright (C) 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.
+ * 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.ia;
+
+import java.util.function.Supplier;
+import org.onap.policy.common.utils.time.CurrentTime;
+
+/**
+ * "Current" time used by IntegrityMonitor classes.
+ */
+public class AuditorTime {
+
+ /**
+ * Instance to be used.
+ */
+ private static final CurrentTime currentTime = new CurrentTime();
+
+ /**
+ * Supplies the instance to be used for accessing the current time. This may be
+ * overridden by junit tests to provide a different time instance for each thread when
+ * multiple threads are run in parallel.
+ */
+ private static Supplier<CurrentTime> supplier = () -> currentTime;
+
+ /**
+ *
+ */
+ private AuditorTime() {
+ super();
+ }
+
+ /**
+ * @return the CurrentTime singleton
+ */
+ public static CurrentTime getInstance() {
+ return supplier.get();
+ }
+}
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 4c4104f6..d7fbd749 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
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
@@ -29,9 +29,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
-
import javax.persistence.Table;
-
import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.builder.RecursiveToStringStyle;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
@@ -48,8 +46,8 @@ public class DbAudit {
private static final Logger logger = FlexLogger.getLogger(DbAudit.class);
- private static long dbAuditUpdateMillis = 5000L;
- private static long dbAuditSleepMillis = 2000L;
+ private static final long DB_AUDIT_UPDATE_MS = 5000L;
+ private static final long DB_AUDIT_SLEEP_MS = 2000L;
DbDAO dbDao = null;
@@ -145,7 +143,7 @@ public class DbAudit {
Map<String, Set<Object>> misMatchedMap = new HashMap<>();
// We need to keep track of how long the audit is taking
- long startTime = System.currentTimeMillis();
+ long startTime = AuditorTime.getInstance().getMillis();
// Retrieve all instances of the class for each node
if (logger.isDebugEnabled()) {
@@ -209,15 +207,15 @@ public class DbAudit {
} // end for (IntegrityAuditEntity iae : iaeList)
// Time check
- if ((System.currentTimeMillis() - startTime) >= dbAuditUpdateMillis) {
+ if ((AuditorTime.getInstance().getMillis() - startTime) >= DB_AUDIT_UPDATE_MS) {
// update the timestamp
dbDao.setLastUpdated();
// reset the startTime
- startTime = System.currentTimeMillis();
+ startTime = AuditorTime.getInstance().getMillis();
} else {
// sleep a couple seconds to break up the activity
if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Sleeping " + dbAuditSleepMillis + "ms");
+ logger.debug("dbAudit: Sleeping " + DB_AUDIT_SLEEP_MS + "ms");
}
sleep();
if (logger.isDebugEnabled()) {
@@ -244,7 +242,7 @@ public class DbAudit {
// again
classNameSet = new HashSet<>(misMatchedMap.keySet());
// We need to keep track of how long the audit is taking
- startTime = System.currentTimeMillis();
+ startTime = AuditorTime.getInstance().getMillis();
// Retrieve all instances of the class for each node
if (logger.isDebugEnabled()) {
@@ -315,15 +313,15 @@ public class DbAudit {
}
}
// Time check
- if ((System.currentTimeMillis() - startTime) >= dbAuditUpdateMillis) {
+ if ((AuditorTime.getInstance().getMillis() - startTime) >= DB_AUDIT_UPDATE_MS) {
// update the timestamp
dbDao.setLastUpdated();
// reset the startTime
- startTime = System.currentTimeMillis();
+ startTime = AuditorTime.getInstance().getMillis();
} else {
// sleep a couple seconds to break up the activity
if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Second comparison; sleeping " + dbAuditSleepMillis + "ms");
+ logger.debug("dbAudit: Second comparison; sleeping " + DB_AUDIT_SLEEP_MS + "ms");
}
sleep();
if (logger.isDebugEnabled()) {
@@ -352,7 +350,7 @@ public class DbAudit {
*/
private void sleep() throws IntegrityAuditException {
try {
- Thread.sleep(dbAuditSleepMillis);
+ AuditorTime.getInstance().sleep(DB_AUDIT_SLEEP_MS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
@@ -361,40 +359,6 @@ public class DbAudit {
}
/**
- * dbAuditSimulate simulates the DB audit.
- *
- * @param resourceName the resouce name
- * @param persistenceUnit the persistence unit
- * @param simulationIterations the simulations iterations
- * @param simulationIntervalMs the simulation interval in milliseconds
- * @throws DbAuditException if an error occurs
- */
- public void dbAuditSimulate(String resourceName, String persistenceUnit, long simulationIterations,
- long simulationIntervalMs) throws DbAuditException {
-
- try {
- logger.info("dbAuditSimulate: Starting audit simulation for resourceName=" + resourceName
- + ", persistenceUnit=" + persistenceUnit);
-
- for (int i = 0; i < simulationIterations; i++) {
- dbDao.setLastUpdated();
- logger.info("dbAuditSimulate: i=" + i + ", sleeping " + simulationIntervalMs + "ms");
- Thread.sleep(simulationIntervalMs);
- }
-
- logger.info("dbAuditSimulate: Finished audit simulation for resourceName=" + resourceName
- + ", persistenceUnit=" + persistenceUnit);
-
- } catch (DbDaoTransactionException e) {
- throw new DbAuditException(e);
-
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new DbAuditException(e);
- }
- }
-
- /**
* compareEntries() will compare the lists of entries from the DB.
*
* @param myEntries the entries
@@ -496,41 +460,4 @@ public class DbAudit {
throw new IntegrityAuditException(e);
}
}
-
- /**
- * Gets the audit-update time.
- *
- * @return the audit-update time, in milliseconds
- */
- protected static long getDbAuditUpdateMillis() {
- return dbAuditUpdateMillis;
- }
-
- /**
- * Sets the audit-update time.
- *
- * @param dbAuditUpdateMillis the new audit update time, in milliseconds
- */
- protected static void setDbAuditUpdateMillis(long dbAuditUpdateMillis) {
- DbAudit.dbAuditUpdateMillis = dbAuditUpdateMillis;
- }
-
- /**
- * Gets the audit-sleep time.
- *
- * @return the audit-sleep time, in milliseconds
- */
- protected static long getDbAuditSleepMillis() {
- return dbAuditSleepMillis;
- }
-
- /**
- * Sets the audit-sleep time.
- *
- * @param dbAuditSleepMillis the new audit sleep time, in milliseconds
- */
- protected static void setDbAuditSleepMillis(long dbAuditSleepMillis) {
- DbAudit.dbAuditSleepMillis = dbAuditSleepMillis;
- }
-
}
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 864adacb..ef765f36 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
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
@@ -20,14 +20,12 @@
package org.onap.policy.common.ia;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
@@ -41,7 +39,6 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.persistence.metamodel.ManagedType;
import javax.persistence.metamodel.Metamodel;
-
import org.onap.policy.common.ia.jpa.IntegrityAuditEntity;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
@@ -52,6 +49,7 @@ import org.onap.policy.common.logging.flexlogger.Logger;
*/
public class DbDAO {
private static final Logger logger = FlexLogger.getLogger(DbDAO.class.getName());
+
private String resourceName;
private String persistenceUnit;
private String dbDriver;
@@ -579,7 +577,7 @@ public class DbDAO {
em.refresh(iae);
logger.info("Resource: " + this.resourceName + " with PersistenceUnit: " + this.persistenceUnit
+ " exists and lastUpdated be updated");
- iae.setLastUpdated(new Date());
+ iae.setLastUpdated(AuditorTime.getInstance().getDate());
em.persist(iae);
// flush to the DB
@@ -672,7 +670,7 @@ public class DbDAO {
+ persistenceUnit + ", nodeType=" + nodeType);
}
- long startTime = System.currentTimeMillis();
+ long startTime = AuditorTime.getInstance().getMillis();
synchronized (lock) {
@@ -759,10 +757,10 @@ public class DbDAO {
} // end synchronized block
if (logger.isDebugEnabled()) {
- logger.debug("changeDesignated: Exiting; time expended=" + (System.currentTimeMillis() - startTime) + "ms");
+ logger.debug("changeDesignated: Exiting; time expended="
+ + (AuditorTime.getInstance().getMillis() - startTime) + "ms");
}
}
-
}
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 b3330faf..4d15205a 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
@@ -47,13 +47,13 @@ public class IntegrityAudit {
* This is the audit period in milliseconds. For example, if it had a value of 3600000, the
* audit can only run once per hour. If it has a value of 6000, it can run once per minute.
*
- * Values: integrityAuditPeriodMillis < 0 (negative number) indicates the audit is off
- * integrityAuditPeriodMillis == 0 indicates the audit is to run continuously
- * integrityAuditPeriodMillis > 0 indicates the audit is to run at most once during the
+ * Values: integrityAuditPeriodSeconds < 0 (negative number) indicates the audit is off
+ * integrityAuditPeriodSeconds == 0 indicates the audit is to run continuously
+ * integrityAuditPeriodSeconds > 0 indicates the audit is to run at most once during the
* indicated period
*
*/
- private int integrityAuditPeriodMillis;
+ private int integrityAuditPeriodSeconds;
/**
* IntegrityAudit constructor.
@@ -82,14 +82,11 @@ public class IntegrityAudit {
// IntegrityAuditProperties.AUDIT_PERIOD_SECONDS and
// IntegrityAuditProperties.AUDIT_PERIOD_MILLISECONDS are allowed to be null
if (properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS) != null) {
- this.integrityAuditPeriodMillis = 1000
- * Integer.parseInt(properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim());
- } else if (properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_MILLISECONDS) != null) {
- this.integrityAuditPeriodMillis =
- Integer.parseInt(properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_MILLISECONDS).trim());
+ this.integrityAuditPeriodSeconds =
+ Integer.parseInt(properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim());
} else {
// If it is null, set it to the default value
- this.integrityAuditPeriodMillis = 1000 * IntegrityAuditProperties.DEFAULT_AUDIT_PERIOD_SECONDS;
+ this.integrityAuditPeriodSeconds = IntegrityAuditProperties.DEFAULT_AUDIT_PERIOD_SECONDS;
}
logger.info("Constructor: Exiting");
@@ -99,7 +96,7 @@ public class IntegrityAudit {
* Used during JUnit testing by AuditPeriodTest.java
*/
public int getIntegrityAuditPeriodSeconds() {
- return (integrityAuditPeriodMillis / 1000);
+ return integrityAuditPeriodSeconds;
}
/**
@@ -192,14 +189,6 @@ public class IntegrityAudit {
+ properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim());
parmsAreBad = true;
}
- } else if (properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_MILLISECONDS) != null) {
- try {
- Integer.parseInt(properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_MILLISECONDS).trim());
- } catch (NumberFormatException nfe) {
- badparams.append(", auditPeriodMilliSeconds="
- + properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_MILLISECONDS).trim());
- parmsAreBad = true;
- }
}
} // End else
logger.debug("parmsAreBad: exit:" + "\nresourceName: " + resourceName + "\npersistenceUnit: " + persistenceUnit
@@ -216,15 +205,14 @@ public class IntegrityAudit {
public void startAuditThread() throws IntegrityAuditException {
logger.info("startAuditThread: Entering");
- if (integrityAuditPeriodMillis >= 0) {
- this.auditThread = makeAuditThread(this.resourceName, this.persistenceUnit, this.properties, integrityAuditPeriodMillis);
- logger.info("startAuditThread: Audit started and will run every " + integrityAuditPeriodMillis / 1000
- + " seconds");
+ if (integrityAuditPeriodSeconds >= 0) {
+ this.auditThread = makeAuditThread(this.resourceName, this.persistenceUnit, this.properties, integrityAuditPeriodSeconds);
+ logger.info("startAuditThread: Audit started and will run every " + integrityAuditPeriodSeconds + " seconds");
this.auditThread.start();
} else {
logger.info("startAuditThread: Suppressing integrity audit, integrityAuditPeriodSeconds="
- + integrityAuditPeriodMillis / 1000);
+ + integrityAuditPeriodSeconds);
}
logger.info("startAuditThread: Exiting");
@@ -294,14 +282,14 @@ public class IntegrityAudit {
* @param resourceName2
* @param persistenceUnit2
* @param properties2
- * @param integrityAuditPeriodMillis2
+ * @param integrityAuditPeriodSeconds2
*
* @return a new audit thread
* @throws IntegrityAuditException
*/
protected AuditThread makeAuditThread(String resourceName2, String persistenceUnit2, Properties properties2,
- long integrityAuditPeriodMillis2) throws IntegrityAuditException {
-
- return new AuditThread(resourceName2, persistenceUnit2, properties2, integrityAuditPeriodMillis2, this);
+ int integrityAuditPeriodSeconds2) throws IntegrityAuditException {
+
+ return new AuditThread(resourceName2, persistenceUnit2, properties2, integrityAuditPeriodSeconds2, this);
}
}
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java
index 2708c090..3afab61f 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java
@@ -29,7 +29,6 @@ public class IntegrityAuditProperties {
public static final String DB_USER = "javax.persistence.jdbc.user";
public static final String DB_PWD = "javax.persistence.jdbc.password";
public static final String AUDIT_PERIOD_SECONDS = "integrity_audit_period_seconds";
- public static final String AUDIT_PERIOD_MILLISECONDS = "integrity_audit_period_milliseconds";
public static final String SITE_NAME = "site_name";
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/jpa/IntegrityAuditEntity.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/jpa/IntegrityAuditEntity.java
index 23b90efc..c1046828 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/jpa/IntegrityAuditEntity.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/jpa/IntegrityAuditEntity.java
@@ -40,6 +40,7 @@ import javax.persistence.TemporalType;
/*
* The Entity class to for management of IntegrityAudits
*/
+import org.onap.policy.common.ia.AuditorTime;
@Entity
@Table(name = "IntegrityAuditEntity")
@@ -101,14 +102,14 @@ public class IntegrityAuditEntity implements Serializable {
*/
@PrePersist
public void prePersist() {
- Date date = new Date();
+ Date date = AuditorTime.getInstance().getDate();
this.createdDate = date;
this.lastUpdated = date;
}
@PreUpdate
public void preUpdate() {
- this.lastUpdated = new Date();
+ this.lastUpdated = AuditorTime.getInstance().getDate();
}
public long getId() {