diff --git a/bitrepository-audit-trail-service/src/main/java/org/bitrepository/audittrails/collector/AuditTrailCollector.java b/bitrepository-audit-trail-service/src/main/java/org/bitrepository/audittrails/collector/AuditTrailCollector.java
index 860ce34a9..0d2b1ade2 100644
--- a/bitrepository-audit-trail-service/src/main/java/org/bitrepository/audittrails/collector/AuditTrailCollector.java
+++ b/bitrepository-audit-trail-service/src/main/java/org/bitrepository/audittrails/collector/AuditTrailCollector.java
@@ -31,11 +31,13 @@
import org.bitrepository.common.settings.Settings;
import org.bitrepository.common.utils.SettingsUtils;
import org.bitrepository.common.utils.TimeUtils;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.service.AlarmDispatcher;
import org.bitrepository.settings.repositorysettings.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.time.Duration;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -52,7 +54,7 @@ public class AuditTrailCollector {
/**
* Initial grace period in milliseconds after startup to allow the system to finish startup.
*/
- private static final int DEFAULT_GRACE_PERIOD = 0;
+ private static final Duration DEFAULT_GRACE_PERIOD = Duration.ZERO;
/**
* @param settings The settings for this collector.
@@ -70,7 +72,10 @@ public AuditTrailCollector(Settings settings, AuditTrailClient client, AuditTrai
this.settings = settings;
this.timer = new Timer(true);
- long collectionInterval = settings.getReferenceSettings().getAuditTrailServiceSettings().getCollectAuditInterval();
+ javax.xml.datatype.Duration collectAuditInterval =
+ settings.getReferenceSettings().getAuditTrailServiceSettings().getCollectAuditInterval();
+ Duration collectionInterval = XmlUtils.xmlDurationToDuration(collectAuditInterval);
+ long collectionIntervalMillis = collectionInterval.toMillis();
for (Collection c : settings.getRepositorySettings().getCollections().getCollection()) {
IncrementalCollector collector = new IncrementalCollector(c.getID(),
@@ -79,11 +84,11 @@ public AuditTrailCollector(Settings settings, AuditTrailClient client, AuditTrai
SettingsUtils.getMaxClientPageSize(),
alarmDispatcher);
AuditTrailCollectionTimerTask collectorTask = new AuditTrailCollectionTimerTask(
- collector, collectionInterval, getGracePeriod());
+ collector, collectionIntervalMillis, Math.toIntExact(getGracePeriod().toMillis()));
log.info("Will start collection of audit trail every " +
- TimeUtils.millisecondsToHuman(collectionInterval) + ", " +
- "after a grace period of " + TimeUtils.millisecondsToHuman(getGracePeriod()));
- timer.scheduleAtFixedRate(collectorTask, getGracePeriod(), collectionInterval / 10);
+ TimeUtils.durationToHuman(collectionInterval) + " " +
+ "after a grace period of " + TimeUtils.durationToHuman(getGracePeriod()));
+ timer.scheduleAtFixedRate(collectorTask, getGracePeriod().toMillis(), collectionIntervalMillis / 10);
collectorTasks.put(c.getID(), collectorTask);
}
}
@@ -124,9 +129,11 @@ public void collectNewestAudits(String collectionID) {
* @return The time to wait before starting collection of audit trails. This enables the system to have time to
* finish startup before they have to start delivering/process audit trails.
*/
- private int getGracePeriod() {
+ private Duration getGracePeriod() {
if (settings.getReferenceSettings().getAuditTrailServiceSettings().isSetGracePeriod()) {
- return settings.getReferenceSettings().getAuditTrailServiceSettings().getGracePeriod().intValue();
+ javax.xml.datatype.Duration gracePeriod =
+ settings.getReferenceSettings().getAuditTrailServiceSettings().getGracePeriod();
+ return XmlUtils.xmlDurationToDuration(gracePeriod);
} else {
return DEFAULT_GRACE_PERIOD;
}
diff --git a/bitrepository-audit-trail-service/src/main/java/org/bitrepository/audittrails/preserver/LocalAuditTrailPreserver.java b/bitrepository-audit-trail-service/src/main/java/org/bitrepository/audittrails/preserver/LocalAuditTrailPreserver.java
index a0788a564..86e83fecc 100644
--- a/bitrepository-audit-trail-service/src/main/java/org/bitrepository/audittrails/preserver/LocalAuditTrailPreserver.java
+++ b/bitrepository-audit-trail-service/src/main/java/org/bitrepository/audittrails/preserver/LocalAuditTrailPreserver.java
@@ -37,6 +37,7 @@
import org.bitrepository.common.utils.FileUtils;
import org.bitrepository.common.utils.SettingsUtils;
import org.bitrepository.common.utils.TimeUtils;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.modify.putfile.BlockingPutFileClient;
import org.bitrepository.modify.putfile.PutFileClient;
import org.bitrepository.protocol.CoordinationLayerException;
@@ -50,10 +51,13 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
@@ -119,13 +123,14 @@ public void start() {
log.debug("Cancelling old timer.");
timer.cancel();
}
- long preservationInterval = preservationSettings.getAuditTrailPreservationInterval();
- long timerCheckInterval = preservationInterval / 10;
+ javax.xml.datatype.Duration preservationIntervalXmlDur = preservationSettings.getAuditTrailPreservationInterval();
+ Duration preservationInterval = XmlUtils.xmlDurationToDuration(preservationIntervalXmlDur);
+ long timerCheckIntervalMillis = preservationInterval.dividedBy(10).toMillis();
log.info("Instantiating the preservation of audit trails every {}",
- TimeUtils.millisecondsToHuman(preservationInterval));
+ TimeUtils.durationToHuman(preservationInterval));
timer = new Timer(true);
- preservationTask = new AuditPreservationTimerTask(preservationInterval);
- timer.scheduleAtFixedRate(preservationTask, timerCheckInterval, timerCheckInterval);
+ preservationTask = new AuditPreservationTimerTask(preservationInterval.toMillis());
+ timer.scheduleAtFixedRate(preservationTask, timerCheckIntervalMillis, timerCheckIntervalMillis);
}
@Override
@@ -264,6 +269,7 @@ private class AuditPreservationTimerTask extends TimerTask {
/**
* @param interval The interval between running this timer task.
*/
+ // TODO: Replace old time representation (https://sbforge.org/jira/browse/BITMAG-1180)
private AuditPreservationTimerTask(long interval) {
this.schedule = new TimerTaskSchedule(interval, 0);
}
diff --git a/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/AuditTrailServiceTest.java b/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/AuditTrailServiceTest.java
index 19cd6508d..47e9e77a0 100644
--- a/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/AuditTrailServiceTest.java
+++ b/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/AuditTrailServiceTest.java
@@ -42,6 +42,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import javax.xml.datatype.DatatypeFactory;
import java.util.concurrent.ThreadFactory;
import static org.mockito.ArgumentMatchers.any;
@@ -74,11 +75,14 @@ public void setup() throws Exception {
@Test(groups = {"unstable"})
public void auditTrailServiceTest() throws Exception {
addDescription("Test the Audit Trail Service");
+ DatatypeFactory factory = DatatypeFactory.newInstance();
settings.getRepositorySettings().getGetAuditTrailSettings().getNonPillarContributorIDs().clear();
settings.getRepositorySettings().getGetAuditTrailSettings().getNonPillarContributorIDs().add(DEFAULT_CONTRIBUTOR);
- settings.getReferenceSettings().getAuditTrailServiceSettings().setCollectAuditInterval(800);
+ settings.getReferenceSettings().getAuditTrailServiceSettings()
+ .setCollectAuditInterval(factory.newDuration(800));
settings.getReferenceSettings().getAuditTrailServiceSettings().setTimerTaskCheckInterval(100L);
- settings.getReferenceSettings().getAuditTrailServiceSettings().setGracePeriod(800L);
+ settings.getReferenceSettings().getAuditTrailServiceSettings()
+ .setGracePeriod(factory.newDuration(800));
AuditTrailStore store = mock(AuditTrailStore.class);
AuditTrailClient client = mock(AuditTrailClient.class);
diff --git a/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/collector/AuditCollectorTest.java b/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/collector/AuditCollectorTest.java
index 82533d46e..9032fd6b7 100644
--- a/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/collector/AuditCollectorTest.java
+++ b/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/collector/AuditCollectorTest.java
@@ -39,6 +39,8 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import javax.xml.datatype.DatatypeFactory;
+
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
@@ -65,11 +67,12 @@ public void setup() throws Exception {
@Test(groups = {"regressiontest"})
public void auditCollectorIntervalTest() throws Exception {
addDescription("Test that the collector calls the AuditClient at the correct intervals.");
+ DatatypeFactory factory = DatatypeFactory.newInstance();
settings.getRepositorySettings().getGetAuditTrailSettings().getNonPillarContributorIDs().clear();
settings.getRepositorySettings().getGetAuditTrailSettings().getNonPillarContributorIDs().add(DEFAULT_CONTRIBUTOR);
- settings.getReferenceSettings().getAuditTrailServiceSettings().setCollectAuditInterval(800);
+ settings.getReferenceSettings().getAuditTrailServiceSettings().setCollectAuditInterval(factory.newDuration(800));
settings.getReferenceSettings().getAuditTrailServiceSettings().setTimerTaskCheckInterval(100L);
- settings.getReferenceSettings().getAuditTrailServiceSettings().setGracePeriod(800L);
+ settings.getReferenceSettings().getAuditTrailServiceSettings().setGracePeriod(factory.newDuration(800));
SettingsUtils.initialize(settings);
AuditTrailClient client = mock(AuditTrailClient.class);
diff --git a/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/preserver/LocalAuditPreservationTest.java b/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/preserver/LocalAuditPreservationTest.java
index cbc79cb77..97e1590c1 100644
--- a/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/preserver/LocalAuditPreservationTest.java
+++ b/bitrepository-audit-trail-service/src/test/java/org/bitrepository/audittrails/preserver/LocalAuditPreservationTest.java
@@ -41,6 +41,8 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
import java.io.FileInputStream;
import java.net.URL;
import java.sql.Date;
@@ -90,7 +92,9 @@ public void auditPreservationSchedulingTest() throws Exception {
MockPutClient client = new MockPutClient();
settings.getReferenceSettings().getAuditTrailServiceSettings().setTimerTaskCheckInterval(100);
- settings.getReferenceSettings().getAuditTrailServiceSettings().getAuditTrailPreservation().setAuditTrailPreservationInterval(300);
+ Duration interval = DatatypeFactory.newInstance().newDuration(300);
+ settings.getReferenceSettings().getAuditTrailServiceSettings().getAuditTrailPreservation()
+ .setAuditTrailPreservationInterval(interval);
settings.getRepositorySettings().getGetAuditTrailSettings().getNonPillarContributorIDs().clear();
settings.getRepositorySettings().getGetAuditTrailSettings().getNonPillarContributorIDs().add(PILLAR_ID);
diff --git a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/CollectionBasedConversationMediator.java b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/CollectionBasedConversationMediator.java
index 1e6bf73e3..1990cdfd9 100644
--- a/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/CollectionBasedConversationMediator.java
+++ b/bitrepository-client/src/main/java/org/bitrepository/client/conversation/mediator/CollectionBasedConversationMediator.java
@@ -30,6 +30,8 @@
import org.bitrepository.client.eventhandler.OperationFailedEvent;
import org.bitrepository.common.DefaultThreadFactory;
import org.bitrepository.common.settings.Settings;
+import org.bitrepository.common.utils.TimeUtils;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.protocol.MessageContext;
import org.bitrepository.protocol.messagebus.MessageBus;
import org.bitrepository.protocol.messagebus.MessageBusManager;
@@ -37,6 +39,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -66,8 +70,9 @@ public class CollectionBasedConversationMediator implements ConversationMediator
@Override
public void start() {
messagebus.addListener(settings.getReceiverDestinationID(), this);
- cleanTimer.scheduleAtFixedRate(new ConversationCleaner(), 0,
- settings.getReferenceSettings().getClientSettings().getMediatorCleanupInterval().longValue());
+ javax.xml.datatype.Duration cleanupInterval = settings.getReferenceSettings().getClientSettings().getMediatorCleanupInterval();
+ cleanTimer.scheduleAtFixedRate(new ConversationCleaner(),
+ 0, XmlUtils.xmlDurationToMilliseconds(cleanupInterval));
}
@Override
@@ -136,7 +141,7 @@ public void onMessage(Message message, MessageContext messageContext) {
}
/**
- * Will clean out obsolete conversations in each run. An obsolete conversation is a conversation which satisfies any
+ * Will clean out obsolete conversations in each run. An obsolete conversation is a conversation which satisfies one
* of the following criteria:
* - Returns true for the
hasEnded() method.
* - Is older than the conversationTimeout limit allows.
@@ -149,15 +154,20 @@ private final class ConversationCleaner extends TimerTask {
@Override
public void run() {
Conversation[] conversationArray = conversations.values().toArray(new Conversation[0]);
- long currentTime = System.currentTimeMillis();
+ Duration conversationTimeout = XmlUtils.xmlDurationToDuration(
+ settings.getReferenceSettings().getClientSettings().getConversationTimeout());
+ Instant currentTime = Instant.now();
for (Conversation conversation : conversationArray) {
if (conversation.hasEnded()) {
conversations.remove(conversation.getConversationID());
- } else if (currentTime - conversation.getStartTime() >
- settings.getReferenceSettings().getClientSettings().getConversationTimeout().longValue()) {
- log.warn("Failing timed out conversation " + conversation.getConversationID() + " " + "(Age " +
- (currentTime - conversation.getStartTime()) + "ms)");
- failConversation(conversation, "Failing timed out conversation " + conversation.getConversationID());
+ } else {
+ Instant startTime = Instant.ofEpochMilli(conversation.getStartTime());
+ Instant expirationTime = startTime.plus(conversationTimeout);
+ if (expirationTime.isBefore(currentTime)) {
+ log.warn("Failing timed out conversation {} (Age: {})", conversation.getConversationID(),
+ TimeUtils.durationToHuman(Duration.between(startTime, currentTime)));
+ failConversation(conversation, "Failing timed out conversation " + conversation.getConversationID());
+ }
}
}
}
diff --git a/bitrepository-client/src/test/java/org/bitrepository/access/getfile/GetFileClientComponentTest.java b/bitrepository-client/src/test/java/org/bitrepository/access/getfile/GetFileClientComponentTest.java
index 663b11d7a..4d2f65834 100644
--- a/bitrepository-client/src/test/java/org/bitrepository/access/getfile/GetFileClientComponentTest.java
+++ b/bitrepository-client/src/test/java/org/bitrepository/access/getfile/GetFileClientComponentTest.java
@@ -352,7 +352,8 @@ public void conversationTimeout() throws Exception {
settingsForCUT.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().clear();
settingsForCUT.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(PILLAR1_ID);
- settingsForCUT.getReferenceSettings().getClientSettings().setConversationTimeout(BigInteger.valueOf(100));
+ DatatypeFactory factory = DatatypeFactory.newInstance();
+ settingsForCUT.getReferenceSettings().getClientSettings().setConversationTimeout(factory.newDuration(100));
GetFileClient client = createGetFileClient();
addStep("Request the delivery of a file from a specific pillar. A callback listener should be supplied.",
diff --git a/bitrepository-client/src/test/java/org/bitrepository/client/DefaultClientTest.java b/bitrepository-client/src/test/java/org/bitrepository/client/DefaultClientTest.java
index 077b319cf..3d34ee8a1 100644
--- a/bitrepository-client/src/test/java/org/bitrepository/client/DefaultClientTest.java
+++ b/bitrepository-client/src/test/java/org/bitrepository/client/DefaultClientTest.java
@@ -32,7 +32,6 @@
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
-import java.math.BigInteger;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@@ -285,7 +284,9 @@ public void conversationTimeoutTest() throws Exception {
addDescription("Tests the the client handles lack of IdentifyPillarResponses gracefully ");
addStep("Set a 100 ms ConversationTimeout.", "");
- settingsForCUT.getReferenceSettings().getClientSettings().setConversationTimeout(BigInteger.valueOf(100));
+ DatatypeFactory factory = DatatypeFactory.newInstance();
+ settingsForCUT.getReferenceSettings().getClientSettings()
+ .setConversationTimeout(factory.newDuration(100));
renewConversationMediator();
addStep("Start the operation",
diff --git a/bitrepository-client/src/test/java/org/bitrepository/modify/deletefile/DeleteFileClientComponentTest.java b/bitrepository-client/src/test/java/org/bitrepository/modify/deletefile/DeleteFileClientComponentTest.java
index 6e7a2d42d..d2f989307 100644
--- a/bitrepository-client/src/test/java/org/bitrepository/modify/deletefile/DeleteFileClientComponentTest.java
+++ b/bitrepository-client/src/test/java/org/bitrepository/modify/deletefile/DeleteFileClientComponentTest.java
@@ -219,7 +219,7 @@ public void deleteClientIdentificationTimeout() throws Exception {
Assert.assertEquals(testEventHandler.waitForEvent().getEventType(), OperationEventType.IDENTIFY_REQUEST_SENT);
addStep("Do not respond. Just await the timeout.",
- "Should make send a Failure event to the eventhandler.");
+ "Should make send a Failure event to the event handler.");
Assert.assertEquals(testEventHandler.waitForEvent().getEventType(), OperationEventType.IDENTIFY_TIMEOUT);
Assert.assertEquals(testEventHandler.waitForEvent().getEventType(), OperationEventType.COMPONENT_FAILED);
Assert.assertEquals(testEventHandler.waitForEvent().getEventType(), OperationEventType.FAILED);
@@ -274,7 +274,7 @@ public void deleteClientOperationTimeout() throws Exception {
Assert.assertEquals(testEventHandler.waitForEvent().getEventType(), OperationEventType.REQUEST_SENT);
addStep("Do not respond. Just await the timeout.",
- "Should make send a Failure event to the eventhandler.");
+ "Should make send a Failure event to the event handler.");
Assert.assertEquals(testEventHandler.waitForEvent().getEventType(), OperationEventType.FAILED);
}
diff --git a/bitrepository-core/src/main/java/org/bitrepository/common/settings/Settings.java b/bitrepository-core/src/main/java/org/bitrepository/common/settings/Settings.java
index a941db3cb..57b14aad5 100644
--- a/bitrepository-core/src/main/java/org/bitrepository/common/settings/Settings.java
+++ b/bitrepository-core/src/main/java/org/bitrepository/common/settings/Settings.java
@@ -24,17 +24,15 @@
*/
package org.bitrepository.common.settings;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.settings.referencesettings.ReferenceSettings;
import org.bitrepository.settings.repositorysettings.Collection;
import org.bitrepository.settings.repositorysettings.MessageBusConfiguration;
import org.bitrepository.settings.repositorysettings.Permission;
import org.bitrepository.settings.repositorysettings.RepositorySettings;
-import javax.xml.datatype.DatatypeConstants;
-import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Duration;
-import java.time.temporal.ChronoUnit;
import java.util.List;
/**
@@ -130,52 +128,16 @@ public Duration getOperationTimeout() {
static Duration getDurationFromXmlDurationOrMillis(
javax.xml.datatype.Duration xmlDuration, BigInteger millis) {
+ // Prefer the XML Duration
if (xmlDuration != null) {
- validateNonNegative(xmlDuration);
- return xmlDurationToDuration(xmlDuration);
+ XmlUtils.validateNonNegative(xmlDuration);
+ return XmlUtils.xmlDurationToDuration(xmlDuration);
}
BigInteger[] secondsAndMillis = millis.divideAndRemainder(MILLIS_PER_SECOND);
return Duration.ofSeconds(secondsAndMillis[0].longValueExact())
.plusMillis(secondsAndMillis[1].intValueExact());
}
- public static void validateNonNegative(javax.xml.datatype.Duration xmlDuration) {
- if (xmlDuration.getSign() < 0) {
- throw new IllegalArgumentException("Unexpected negative duration: " + xmlDuration);
- }
- }
-
- /**
- * Converts a javax.xml.datatype.Duration to a java.time.Duration using estimated values for days, months and years.
- */
- static Duration xmlDurationToDuration(javax.xml.datatype.Duration xmlDuration) {
- return unitsToDuration(xmlDuration.getField(DatatypeConstants.YEARS), ChronoUnit.YEARS)
- .plus(unitsToDuration(xmlDuration.getField(DatatypeConstants.MONTHS), ChronoUnit.MONTHS))
- .plus(unitsToDuration(xmlDuration.getField(DatatypeConstants.DAYS), ChronoUnit.DAYS))
- .plus(unitsToDuration(xmlDuration.getField(DatatypeConstants.HOURS), ChronoUnit.HOURS))
- .plus(unitsToDuration(xmlDuration.getField(DatatypeConstants.MINUTES), ChronoUnit.MINUTES))
- .plus(secondsToDuration(xmlDuration.getField(DatatypeConstants.SECONDS)));
- }
-
- /** @param count a BigInteger or null */
- private static Duration unitsToDuration(Number count, ChronoUnit unit) {
- if (count == null) {
- return Duration.ZERO;
- }
- return unit.getDuration().multipliedBy(((BigInteger) count).longValueExact());
- }
-
- /** @param secondsValue a BigDecimal denoting the number of seconds with fraction or null */
- private static Duration secondsToDuration(Number secondsValue) {
- if (secondsValue == null) {
- return Duration.ZERO;
- }
- BigDecimal secondsBigDecimal = (BigDecimal) secondsValue;
- long wholeSeconds = secondsBigDecimal.toBigInteger().longValueExact();
- int nanos = secondsBigDecimal.subtract(BigDecimal.valueOf(wholeSeconds)).scaleByPowerOfTen(9).intValueExact();
- return Duration.ofSeconds(wholeSeconds, nanos);
- }
-
/**
* @return The settings specific to the reference code for a collection.
*/
diff --git a/bitrepository-core/src/main/java/org/bitrepository/common/utils/XmlUtils.java b/bitrepository-core/src/main/java/org/bitrepository/common/utils/XmlUtils.java
new file mode 100644
index 000000000..711cc4b8a
--- /dev/null
+++ b/bitrepository-core/src/main/java/org/bitrepository/common/utils/XmlUtils.java
@@ -0,0 +1,75 @@
+package org.bitrepository.common.utils;
+
+import org.bitrepository.bitrepositoryelements.TimeMeasureTYPE;
+import org.bitrepository.bitrepositoryelements.TimeMeasureUnit;
+
+import javax.xml.datatype.DatatypeConstants;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+
+public class XmlUtils {
+
+ public static void validateNonNegative(javax.xml.datatype.Duration xmlDuration) {
+ if (xmlDuration.getSign() < 0) {
+ throw new IllegalArgumentException("Unexpected negative duration: " + xmlDuration);
+ }
+ }
+
+ /**
+ * Converts a javax.xml.datatype.Duration to a java.time.Duration using estimated values for days, months and years.
+ *
+ * @throws ArithmeticException
+ * if either a field in xmlDuration exceeds a Java long or the total converted duration exceeds a java.time.Duration
+ */
+ public static Duration xmlDurationToDuration(javax.xml.datatype.Duration xmlDuration) {
+ boolean negative = xmlDuration.getSign() == -1;
+ Duration magnitude = unitsToDuration(xmlDuration.getField(DatatypeConstants.YEARS), ChronoUnit.YEARS)
+ .plus(unitsToDuration(xmlDuration.getField(DatatypeConstants.MONTHS), ChronoUnit.MONTHS))
+ .plus(unitsToDuration(xmlDuration.getField(DatatypeConstants.DAYS), ChronoUnit.DAYS))
+ .plus(unitsToDuration(xmlDuration.getField(DatatypeConstants.HOURS), ChronoUnit.HOURS))
+ .plus(unitsToDuration(xmlDuration.getField(DatatypeConstants.MINUTES), ChronoUnit.MINUTES))
+ .plus(secondsToDuration(xmlDuration.getField(DatatypeConstants.SECONDS)));
+ return negative ? magnitude.negated() : magnitude;
+ }
+
+ /** @param count a BigInteger or null */
+ private static Duration unitsToDuration(Number count, ChronoUnit unit) {
+ if (count == null) {
+ return Duration.ZERO;
+ }
+ BigInteger countBigInteger = (BigInteger) count;
+ assert countBigInteger.signum() >= 0 : "Unexpected negative " + count;
+ return unit.getDuration().multipliedBy(countBigInteger.longValueExact());
+ }
+
+ /** @param secondsValue a BigDecimal denoting the number of seconds with fraction or null */
+ private static Duration secondsToDuration(Number secondsValue) {
+ if (secondsValue == null) {
+ return Duration.ZERO;
+ }
+ BigDecimal secondsBigDecimal = (BigDecimal) secondsValue;
+ assert secondsBigDecimal.signum() >= 0 : "Unexpected negative seconds " + secondsValue;
+ long wholeSeconds = secondsBigDecimal.toBigInteger().longValueExact();
+ int nanos = secondsBigDecimal.subtract(BigDecimal.valueOf(wholeSeconds)).scaleByPowerOfTen(9).intValueExact();
+ return Duration.ofSeconds(wholeSeconds, nanos);
+ }
+
+ public static long xmlDurationToMilliseconds(javax.xml.datatype.Duration duration) {
+ return xmlDurationToDuration(duration).toMillis();
+ }
+
+ public static TimeMeasureTYPE xmlDurationToTimeMeasure(javax.xml.datatype.Duration xmlDuration) {
+ Duration duration = xmlDurationToDuration(xmlDuration);
+
+ TimeMeasureTYPE result = new TimeMeasureTYPE();
+ result.setTimeMeasureUnit(TimeMeasureUnit.MILLISECONDS);
+ BigInteger totalMilliseconds = BigInteger.valueOf(duration.toSeconds())
+ .multiply(BigInteger.valueOf(1000))
+ .add(BigInteger.valueOf(duration.toMillisPart()));
+ result.setTimeMeasureValue(totalMilliseconds);
+
+ return result;
+ }
+}
diff --git a/bitrepository-core/src/main/resources/examples/settings/ReferenceSettings.xml b/bitrepository-core/src/main/resources/examples/settings/ReferenceSettings.xml
index c0cc2931b..e7b13c1b8 100644
--- a/bitrepository-core/src/main/resources/examples/settings/ReferenceSettings.xml
+++ b/bitrepository-core/src/main/resources/examples/settings/ReferenceSettings.xml
@@ -35,17 +35,21 @@
- 1000
+ PT1S
- 3600000
+ PT1H
- 1000
+ PT1S
- 3600000
+ PT1H
- 3600000
+ PT1H
- 3600000
+ PT1H
2000
@@ -326,9 +335,12 @@
- 604800000
+ P7D
- 86400000
- TwoPillarCollection
-
+ P1D
+
+ TwoPillarCollection
+
- 360000
- SinglePillarCollection
-
+ PT1H
+
+ SinglePillarCollection
+
@@ -399,11 +413,11 @@
- 3600000
+ PT1H
- 60000
+ PT1M
conf/audittrailservice/auditservicedb
- 3600000
+ PT1H
2000
diff --git a/bitrepository-integration/src/main/resources/quickstart/conf/checksumpillar/ReferenceSettings.xml b/bitrepository-integration/src/main/resources/quickstart/conf/checksumpillar/ReferenceSettings.xml
index 19ca3e89d..5026645cf 100644
--- a/bitrepository-integration/src/main/resources/quickstart/conf/checksumpillar/ReferenceSettings.xml
+++ b/bitrepository-integration/src/main/resources/quickstart/conf/checksumpillar/ReferenceSettings.xml
@@ -27,8 +27,8 @@
- 1000
- 3600000
+ PT1S
+ PT1H
@@ -39,8 +39,8 @@
var/checksumpillar/files
1000000000
- 1000
- 3600000000000
+ PT1S
+ P114Y
org.apache.derby.jdbc.EmbeddedDriver
jdbc:derby:var/checksumpillar/auditcontributerdb
diff --git a/bitrepository-integration/src/main/resources/quickstart/conf/commandline/ReferenceSettings.xml b/bitrepository-integration/src/main/resources/quickstart/conf/commandline/ReferenceSettings.xml
index 1da9dc9d3..36e2bad1e 100644
--- a/bitrepository-integration/src/main/resources/quickstart/conf/commandline/ReferenceSettings.xml
+++ b/bitrepository-integration/src/main/resources/quickstart/conf/commandline/ReferenceSettings.xml
@@ -11,8 +11,8 @@
- 1000
- 3600000
+ PT1S
+ PT1H
HTTP
diff --git a/bitrepository-integration/src/main/resources/quickstart/conf/file1pillar/ReferenceSettings.xml b/bitrepository-integration/src/main/resources/quickstart/conf/file1pillar/ReferenceSettings.xml
index 3bc77938b..cd796a8ae 100644
--- a/bitrepository-integration/src/main/resources/quickstart/conf/file1pillar/ReferenceSettings.xml
+++ b/bitrepository-integration/src/main/resources/quickstart/conf/file1pillar/ReferenceSettings.xml
@@ -27,8 +27,8 @@
- 1000
- 3600000
+ PT1S
+ PT1H
@@ -39,8 +39,8 @@
var/file1pillar/files
1000000000
- 1000
- 3600000
+ PT1S
+ PT1H
org.apache.derby.jdbc.EmbeddedDriver
jdbc:derby:var/file1pillar/auditcontributerdb
diff --git a/bitrepository-integration/src/main/resources/quickstart/conf/file2pillar/ReferenceSettings.xml b/bitrepository-integration/src/main/resources/quickstart/conf/file2pillar/ReferenceSettings.xml
index 985cf5307..65a23f4f1 100644
--- a/bitrepository-integration/src/main/resources/quickstart/conf/file2pillar/ReferenceSettings.xml
+++ b/bitrepository-integration/src/main/resources/quickstart/conf/file2pillar/ReferenceSettings.xml
@@ -27,8 +27,8 @@
- 1000
- 3600000
+ PT1S
+ PT1H
@@ -43,8 +43,8 @@
var/file2pillar/files
1000000000
- 1000
- 3600000
+ PT1S
+ PT1H
org.apache.derby.jdbc.EmbeddedDriver
jdbc:derby:var/file2pillar/auditcontributerdb
diff --git a/bitrepository-integration/src/main/resources/quickstart/conf/integrityservice/ReferenceSettings.xml b/bitrepository-integration/src/main/resources/quickstart/conf/integrityservice/ReferenceSettings.xml
index 961b2ae32..f8198e933 100644
--- a/bitrepository-integration/src/main/resources/quickstart/conf/integrityservice/ReferenceSettings.xml
+++ b/bitrepository-integration/src/main/resources/quickstart/conf/integrityservice/ReferenceSettings.xml
@@ -26,8 +26,8 @@
org.bitrepository.protocol.messagebus.destination.DefaultReceiverDestinationIDFactory
- 1000
- 3600000
+ PT1S
+ PT1H
@@ -37,7 +37,7 @@
CompleteIntegrityCheck
- 86400000
+ P1D
books
dvds
@@ -49,7 +49,7 @@
IncrementalIntegrityCheck
- 3600000
+ PT1H
books
dvds
@@ -62,7 +62,7 @@
- -1
+ -PT1S
books
dvds
@@ -75,7 +75,7 @@
- -1
+ -PT1S
books
dvds
@@ -88,7 +88,7 @@
org.apache.derby.jdbc.EmbeddedDriver
jdbc:derby:conf/integrityservice/integritydb
- 3600000
+ PT1H
org.apache.derby.jdbc.EmbeddedDriver
jdbc:derby:conf/integrityservice/auditcontributerdb
diff --git a/bitrepository-integration/src/main/resources/quickstart/conf/monitoringservice/ReferenceSettings.xml b/bitrepository-integration/src/main/resources/quickstart/conf/monitoringservice/ReferenceSettings.xml
index 04caf59a0..279167b5c 100644
--- a/bitrepository-integration/src/main/resources/quickstart/conf/monitoringservice/ReferenceSettings.xml
+++ b/bitrepository-integration/src/main/resources/quickstart/conf/monitoringservice/ReferenceSettings.xml
@@ -27,15 +27,15 @@
- 1000
- 3600000
+ PT1S
+ PT1H
monitoring-service
- 60000
+ PT1M
3
diff --git a/bitrepository-integration/src/main/resources/quickstart/conf/webclient/ReferenceSettings.xml b/bitrepository-integration/src/main/resources/quickstart/conf/webclient/ReferenceSettings.xml
index 072819f3e..ba3eb7e8d 100644
--- a/bitrepository-integration/src/main/resources/quickstart/conf/webclient/ReferenceSettings.xml
+++ b/bitrepository-integration/src/main/resources/quickstart/conf/webclient/ReferenceSettings.xml
@@ -27,8 +27,8 @@
- 1000
- 3600000
+ PT1S
+ PT1H
diff --git a/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/checking/MaxChecksumAgeProvider.java b/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/checking/MaxChecksumAgeProvider.java
index 454278b38..bdff3cfa2 100644
--- a/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/checking/MaxChecksumAgeProvider.java
+++ b/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/checking/MaxChecksumAgeProvider.java
@@ -22,20 +22,24 @@
package org.bitrepository.integrityservice.checking;
import org.bitrepository.common.ArgumentValidator;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.settings.referencesettings.MaxChecksumAgeForPillar;
import org.bitrepository.settings.referencesettings.ObsoleteChecksumSettings;
-import java.math.BigInteger;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import java.time.Duration;
+import java.util.Objects;
/**
* Provide easy access to the MaxChecksumAge for individual pillars.
*/
public class MaxChecksumAgeProvider {
- private final long defaultMaxAge;
+ private final Duration defaultMaxAge;
private final ObsoleteChecksumSettings settings;
- public MaxChecksumAgeProvider(long defaultMaxAge, ObsoleteChecksumSettings settings) {
- this.defaultMaxAge = defaultMaxAge;
+ public MaxChecksumAgeProvider(Duration defaultMaxAge, ObsoleteChecksumSettings settings) {
+ this.defaultMaxAge = Objects.requireNonNull(defaultMaxAge, "defaultMaxAge");
this.settings = settings;
}
@@ -51,18 +55,20 @@ public MaxChecksumAgeProvider(long defaultMaxAge, ObsoleteChecksumSettings setti
* @param pillarID the ID of the pillar
* @return The MaxChecksumAge for the indicated pillar.
*/
- public long getMaxChecksumAge(String pillarID) {
+ public Duration getMaxChecksumAge(String pillarID) {
ArgumentValidator.checkNotNull(pillarID, "pillarID");
if (settings != null) {
if (settings.getMaxChecksumAgeForPillar() != null) {
for (MaxChecksumAgeForPillar maxChecksumAgeForPillar : settings.getMaxChecksumAgeForPillar()) {
if (pillarID.equals(maxChecksumAgeForPillar.getPillarID())) {
- return maxChecksumAgeForPillar.getMaxChecksumAge().longValue();
+ javax.xml.datatype.Duration maxChecksumAge = maxChecksumAgeForPillar.getMaxChecksumAge();
+ return XmlUtils.xmlDurationToDuration(maxChecksumAge);
}
}
}
- if (settings.getDefaultMaxChecksumAge() != null) {
- return settings.getDefaultMaxChecksumAge().longValue();
+ javax.xml.datatype.Duration defaultMaxChecksumAge = settings.getDefaultMaxChecksumAge();
+ if (defaultMaxChecksumAge != null) {
+ return XmlUtils.xmlDurationToDuration(defaultMaxChecksumAge);
}
}
return defaultMaxAge;
@@ -78,7 +84,11 @@ public long getMaxChecksumAge(String pillarID) {
public static MaxChecksumAgeForPillar createMaxChecksumAgeForPillar(String pillarID, long value) {
MaxChecksumAgeForPillar maxChecksumAgeForPillar = new MaxChecksumAgeForPillar();
maxChecksumAgeForPillar.setPillarID(pillarID);
- maxChecksumAgeForPillar.setMaxChecksumAge(BigInteger.valueOf(value));
+ try {
+ maxChecksumAgeForPillar.setMaxChecksumAge(DatatypeFactory.newInstance().newDuration(value));
+ } catch (DatatypeConfigurationException e) {
+ throw new RuntimeException("createMaxChecksumAgeForPillar(): creating datatype factory failed: ", e);
+ }
return maxChecksumAgeForPillar;
}
}
diff --git a/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/IntegrityCheckWorkflow.java b/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/IntegrityCheckWorkflow.java
index a91fb7e6c..05babead5 100644
--- a/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/IntegrityCheckWorkflow.java
+++ b/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/IntegrityCheckWorkflow.java
@@ -22,6 +22,7 @@
package org.bitrepository.integrityservice.workflow;
import org.bitrepository.common.utils.SettingsUtils;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.integrityservice.IntegrityServiceManager;
import org.bitrepository.integrityservice.reports.BasicIntegrityReporter;
import org.bitrepository.integrityservice.reports.IntegrityReporter;
@@ -42,6 +43,7 @@
import org.slf4j.LoggerFactory;
import java.io.IOException;
+import java.time.Duration;
import java.util.Date;
/**
@@ -116,8 +118,9 @@ public void start() {
}
statisticsCollector.getCollectionStat().setStatsTime(new Date());
- Long missingFileGracePeriod
- = context.getSettings().getReferenceSettings().getIntegrityServiceSettings().getTimeBeforeMissingFileCheck();
+ javax.xml.datatype.Duration timeBeforeMissingFileCheck =
+ context.getSettings().getReferenceSettings().getIntegrityServiceSettings().getTimeBeforeMissingFileCheck();
+ Duration missingFileGracePeriod = XmlUtils.xmlDurationToDuration(timeBeforeMissingFileCheck);
HandleMissingFilesStep handleMissingFilesStep = new HandleMissingFilesStep(context.getStore(), reporter,
statisticsCollector, missingFileGracePeriod);
performStep(handleMissingFilesStep);
diff --git a/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/IntegrityWorkflowManager.java b/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/IntegrityWorkflowManager.java
index a1c24cd48..526b7d549 100644
--- a/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/IntegrityWorkflowManager.java
+++ b/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/IntegrityWorkflowManager.java
@@ -30,13 +30,17 @@
import org.bitrepository.settings.referencesettings.WorkflowConfiguration;
import org.bitrepository.settings.referencesettings.WorkflowSettings;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+
/**
* Manages the workflows for the integrity service. Delegates most functionality to the
Workflow
* class, but handles som configuration specific to the integrity workflows.
*/
public class IntegrityWorkflowManager extends WorkflowManager {
- public static final long DAILY = 86400000;
- public static final long HOURLY = 360000;
+ public static final long DAILY = 86_400_000;
+ public static final long HOURLY = 3_600_000;
public IntegrityWorkflowManager(IntegrityWorkflowContext context, JobScheduler scheduler) {
super(context, getWorkflowSettings(context.getSettings()), scheduler);
@@ -63,7 +67,14 @@ protected static WorkflowSettings createDefaultWorkflowSettings() {
WorkflowConfiguration completeIntegrityWorkflowConf = new WorkflowConfiguration();
completeIntegrityWorkflowConf.setWorkflowClass(CompleteIntegrityCheck.class.getCanonicalName());
Schedule schedule = new Schedule();
- schedule.setWorkflowInterval(DAILY);
+ try {
+ Duration workflowInterval = DatatypeFactory.newInstance().newDuration(DAILY);
+ schedule.setWorkflowInterval(workflowInterval);
+ } catch (DatatypeConfigurationException e) {
+ throw new RuntimeException(
+ "Could not instantiate datatype factory for creating duration for workflow interval for settings",
+ e);
+ }
completeIntegrityWorkflowConf.setSchedules(new Schedules());
completeIntegrityWorkflowConf.getSchedules().getSchedule().add(schedule);
defaultWorkflowSettings.getWorkflow().add(completeIntegrityWorkflowConf);
diff --git a/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/step/HandleMissingFilesStep.java b/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/step/HandleMissingFilesStep.java
index adb2e93c8..35571dbc8 100644
--- a/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/step/HandleMissingFilesStep.java
+++ b/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/step/HandleMissingFilesStep.java
@@ -33,12 +33,15 @@
import org.slf4j.LoggerFactory;
import java.io.IOException;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
/**
@@ -50,14 +53,14 @@ public class HandleMissingFilesStep extends AbstractWorkFlowStep {
private final IntegrityModel store;
private final IntegrityReporter reporter;
private final StatisticsCollector sc;
- private final Long gracePeriod;
+ private final Duration gracePeriod;
public HandleMissingFilesStep(IntegrityModel store, IntegrityReporter reporter, StatisticsCollector statisticsCollector,
- Long missingFileGracePeriod) {
+ Duration missingFileGracePeriod) {
this.store = store;
this.reporter = reporter;
this.sc = statisticsCollector;
- this.gracePeriod = missingFileGracePeriod;
+ this.gracePeriod = Objects.requireNonNull(missingFileGracePeriod, "missingFileGracePeriod");
}
@Override
@@ -77,7 +80,8 @@ public synchronized void performStep() throws StepFailedException {
for (String pillar : pillars) {
missingFilesMap.put(pillar, 0L);
}
- Date missingAfterDate = new Date(System.currentTimeMillis() - gracePeriod);
+ Instant missingAfterInstant = Instant.now().minus(gracePeriod);
+ Date missingAfterDate = Date.from(missingAfterInstant);
log.info("Looking for missing files, files need to be older than {} to be considered missing.", missingAfterDate);
try (IntegrityIssueIterator issueIterator = store.findFilesWithMissingCopies(reporter.getCollectionID(), pillars.size(), 0L,
diff --git a/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/step/HandleObsoleteChecksumsStep.java b/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/step/HandleObsoleteChecksumsStep.java
index ece992875..1a7d8fca2 100644
--- a/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/step/HandleObsoleteChecksumsStep.java
+++ b/bitrepository-integrity-service/src/main/java/org/bitrepository/integrityservice/workflow/step/HandleObsoleteChecksumsStep.java
@@ -23,7 +23,6 @@
import org.bitrepository.common.settings.Settings;
import org.bitrepository.common.utils.SettingsUtils;
-import org.bitrepository.common.utils.TimeUtils;
import org.bitrepository.integrityservice.cache.IntegrityModel;
import org.bitrepository.integrityservice.cache.database.IntegrityIssueIterator;
import org.bitrepository.integrityservice.checking.MaxChecksumAgeProvider;
@@ -35,6 +34,9 @@
import org.slf4j.LoggerFactory;
import java.io.IOException;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
@@ -48,7 +50,7 @@ public class HandleObsoleteChecksumsStep extends AbstractWorkFlowStep {
private final IntegrityModel store;
private final IntegrityReporter reporter;
private final StatisticsCollector sc;
- public static final long DEFAULT_MAX_CHECKSUM_AGE = TimeUtils.MS_PER_YEAR;
+ public static final Duration DEFAULT_MAX_CHECKSUM_AGE = ChronoUnit.YEARS.getDuration();
public HandleObsoleteChecksumsStep(Settings settings, IntegrityModel store, IntegrityReporter reporter,
StatisticsCollector statisticsCollector) {
@@ -76,28 +78,28 @@ public synchronized void performStep() throws StepFailedException {
List pillars = SettingsUtils.getPillarIDsForCollection(reporter.getCollectionID());
for (String pillar : pillars) {
- Long obsolteteChecksums = 0L;
- long maxAge = maxChecksumAgeProvider.getMaxChecksumAge(pillar);
- if (maxAge == 0) {
+ long obsoleteChecksums = 0L;
+ Duration maxAge = maxChecksumAgeProvider.getMaxChecksumAge(pillar);
+ if (maxAge.isZero()) {
log.info("Skipping obsolete checksums check for pillar '" + pillar + "' as it has a " +
- "MaxChecksumAge of 0 (i.e. checksums don't expire).");
+ "MaxChecksumAge of 0 (i.e., checksums don't expire).");
continue;
} else {
- Date outDated = new Date(System.currentTimeMillis() - maxAge);
- try (IntegrityIssueIterator obsoleteChecksumsIterator = store.findChecksumsOlderThan(outDated, pillar,
+ Date outdated = Date.from(Instant.now().minus(maxAge));
+ try (IntegrityIssueIterator obsoleteChecksumsIterator = store.findChecksumsOlderThan(outdated, pillar,
reporter.getCollectionID())) {
String file;
while ((file = obsoleteChecksumsIterator.getNextIntegrityIssue()) != null) {
try {
reporter.reportObsoleteChecksum(file, pillar);
- obsolteteChecksums++;
+ obsoleteChecksums++;
} catch (IOException e) {
throw new StepFailedException("Failed to report file: " + file + " as having an obsolete checksum", e);
}
}
}
}
- sc.getPillarCollectionStat(pillar).setObsoleteChecksums(obsolteteChecksums);
+ sc.getPillarCollectionStat(pillar).setObsoleteChecksums(obsoleteChecksums);
}
}
diff --git a/bitrepository-integrity-service/src/test/conf/ReferenceSettings.xml b/bitrepository-integrity-service/src/test/conf/ReferenceSettings.xml
index eef53b083..42e1e0633 100644
--- a/bitrepository-integrity-service/src/test/conf/ReferenceSettings.xml
+++ b/bitrepository-integrity-service/src/test/conf/ReferenceSettings.xml
@@ -27,8 +27,8 @@
- 1000
- 3600000
+ PT1S
+ PT1H
@@ -37,7 +37,7 @@
org.apache.derby.jdbc.EmbeddedDriver
jdbc:derby:target/database/integritydb
- 3600000
+ PT1H
org.apache.derby.jdbc.EmbeddedDriver
jdbc:derby:target/database/auditcontributerdb
diff --git a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/IntegrityDatabaseTestCase.java b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/IntegrityDatabaseTestCase.java
index 46b19fd0f..95aa07bcf 100644
--- a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/IntegrityDatabaseTestCase.java
+++ b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/IntegrityDatabaseTestCase.java
@@ -37,6 +37,7 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import javax.xml.datatype.DatatypeConfigurationException;
import java.math.BigInteger;
import java.util.List;
@@ -105,5 +106,5 @@ protected void insertMissingFilesInChecksumDataForModel(IntegrityModel cache, Li
* Method to modify the by constructor loaded settings.
* Default implementation does nothing, so override to change behavior.
*/
- protected void customizeSettings() { }
+ protected void customizeSettings() throws DatatypeConfigurationException { }
}
diff --git a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/checking/MaxChecksumAgeProviderTest.java b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/checking/MaxChecksumAgeProviderTest.java
index 91b5ac4a1..93fd86f83 100644
--- a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/checking/MaxChecksumAgeProviderTest.java
+++ b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/checking/MaxChecksumAgeProviderTest.java
@@ -23,23 +23,33 @@
import org.bitrepository.settings.referencesettings.ObsoleteChecksumSettings;
import org.jaccept.structure.ExtendedTestCase;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.math.BigInteger;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import java.time.Duration;
import static org.testng.Assert.assertEquals;
public class MaxChecksumAgeProviderTest extends ExtendedTestCase{
+ DatatypeFactory factory;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUpFactory() throws DatatypeConfigurationException {
+ factory = DatatypeFactory.newInstance();
+ }
+
@Test(groups = {"regressiontest", "integritytest"})
public void testNoSettings() {
addDescription("Test the MaxChecksumAge when no settings are defined");
addStep("Create a MaxChecksumAgeProvider with null settings and a default MaxAge of 100",
"Test that the MaxAge for a random pillar is 100");
- long defaultMaxAge = 100;
+ Duration defaultMaxAge = Duration.ofMillis(100);
MaxChecksumAgeProvider maxChecksumAgeProvider = new MaxChecksumAgeProvider(defaultMaxAge, null);
- assertEquals(defaultMaxAge, maxChecksumAgeProvider.getMaxChecksumAge(""));
+ assertEquals(maxChecksumAgeProvider.getMaxChecksumAge(""), defaultMaxAge);
}
@Test(groups = {"regressiontest", "integritytest"})
@@ -49,11 +59,11 @@ public void testNoPillarSpecificSetting() {
addStep("Create a MaxChecksumAgeProvider with settings containing a default MaxAge of 10 and no pillar " +
"specific settings",
"Test that the MaxAge for a random pillar is 10");
- long defaultMaxAge = 100;
+ Duration defaultMaxAge = Duration.ofMillis(100);
ObsoleteChecksumSettings settings = new ObsoleteChecksumSettings();
- settings.setDefaultMaxChecksumAge(BigInteger.TEN);
+ settings.setDefaultMaxChecksumAge(factory.newDuration(10));
MaxChecksumAgeProvider maxChecksumAgeProvider = new MaxChecksumAgeProvider(defaultMaxAge, settings);
- assertEquals(10, maxChecksumAgeProvider.getMaxChecksumAge(""));
+ assertEquals(maxChecksumAgeProvider.getMaxChecksumAge(""), Duration.ofMillis(10));
}
@Test(groups = {"regressiontest", "integritytest"})
@@ -64,21 +74,21 @@ public void testPillarSpecificSetting() {
addStep("Create a MaxChecksumAgeProvider with settings containing a default MaxAge of 10, pillar1" +
"MaxChecksumAge of 1001 and pillar2 MaxChecksumAge of 1002" ,
"Test that the MaxAge for pillar1 is 1001, pillar2 is 1002 and for a random pillar is 10");
- long defaultMaxAge = 100;
- long defaultMaxAgeinSettings = 100;
+ Duration defaultMaxAge = Duration.ofMillis(100);
+ long defaultMaxAgeInSettings = 100;
final String PILLAR1 = "PILLAR1";
long pillar1MaxAge = 1000;
final String PILLAR2 = "PILLAR2";
long pillar2MaxAge = 10000;
ObsoleteChecksumSettings settings = new ObsoleteChecksumSettings();
- settings.setDefaultMaxChecksumAge(BigInteger.valueOf(defaultMaxAgeinSettings));
+ settings.setDefaultMaxChecksumAge(factory.newDuration(defaultMaxAgeInSettings));
settings.getMaxChecksumAgeForPillar().add(
MaxChecksumAgeProvider.createMaxChecksumAgeForPillar(PILLAR1, pillar1MaxAge));
settings.getMaxChecksumAgeForPillar().add(
MaxChecksumAgeProvider.createMaxChecksumAgeForPillar(PILLAR2, pillar2MaxAge));
MaxChecksumAgeProvider maxChecksumAgeProvider = new MaxChecksumAgeProvider(defaultMaxAge, settings);
- assertEquals(pillar1MaxAge, maxChecksumAgeProvider.getMaxChecksumAge(PILLAR1));
- assertEquals(pillar2MaxAge, maxChecksumAgeProvider.getMaxChecksumAge(PILLAR2));
- assertEquals(defaultMaxAgeinSettings, maxChecksumAgeProvider.getMaxChecksumAge(""));
+ assertEquals(maxChecksumAgeProvider.getMaxChecksumAge(PILLAR1), Duration.ofMillis(pillar1MaxAge));
+ assertEquals(maxChecksumAgeProvider.getMaxChecksumAge(PILLAR2), Duration.ofMillis(pillar2MaxAge));
+ assertEquals(maxChecksumAgeProvider.getMaxChecksumAge(""), Duration.ofMillis(defaultMaxAgeInSettings));
}
}
diff --git a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/integrationtest/MissingChecksumTests.java b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/integrationtest/MissingChecksumTests.java
index 5c1446937..ac9f83e44 100644
--- a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/integrationtest/MissingChecksumTests.java
+++ b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/integrationtest/MissingChecksumTests.java
@@ -58,6 +58,8 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
import java.math.BigInteger;
import java.util.ArrayList;
@@ -106,8 +108,9 @@ public void setup() throws Exception {
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().clear();
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(PILLAR_1);
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(PILLAR_2);
-
- settings.getReferenceSettings().getIntegrityServiceSettings().setTimeBeforeMissingFileCheck(0);
+
+ Duration time = DatatypeFactory.newInstance().newDuration(0);
+ settings.getReferenceSettings().getIntegrityServiceSettings().setTimeBeforeMissingFileCheck(time);
TEST_COLLECTION = settings.getRepositorySettings().getCollections().getCollection().get(0).getID();
SettingsUtils.initialize(settings);
diff --git a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/stresstest/DatabaseStressTests.java b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/stresstest/DatabaseStressTests.java
index 081175372..89f738fde 100644
--- a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/stresstest/DatabaseStressTests.java
+++ b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/stresstest/DatabaseStressTests.java
@@ -42,6 +42,8 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
import java.math.BigInteger;
import java.util.Date;
@@ -72,8 +74,9 @@ public void setup() throws Exception {
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(PILLAR_2);
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(PILLAR_3);
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(PILLAR_4);
-
- settings.getReferenceSettings().getIntegrityServiceSettings().setTimeBeforeMissingFileCheck(0);
+
+ Duration time = DatatypeFactory.newInstance().newDuration(0);
+ settings.getReferenceSettings().getIntegrityServiceSettings().setTimeBeforeMissingFileCheck(time);
}
protected void populateDatabase(IntegrityDAO cache) {
@@ -96,10 +99,10 @@ protected void populateDatabase(IntegrityDAO cache) {
}
@AfterMethod (alwaysRun = true)
- public void clearDatabase() throws Exception {
+ public void clearDatabase() {
DBConnector connector = new DBConnector(settings.getReferenceSettings().getIntegrityServiceSettings().getIntegrityDatabase());
- DatabaseUtils.executeStatement(connector, "DELETE FROM fileinfo", new Object[0]);
- DatabaseUtils.executeStatement(connector, "DELETE FROM pillar", new Object[0]);
+ DatabaseUtils.executeStatement(connector, "DELETE FROM fileinfo");
+ DatabaseUtils.executeStatement(connector, "DELETE FROM pillar");
}
@Test(groups = {"stresstest", "integritytest"})
@@ -114,8 +117,8 @@ public void testDatabasePerformance() {
startTime = System.currentTimeMillis();
String collection = settings.getRepositorySettings().getCollections().getCollection().get(0).getID();
- int numberOfpillarsInCollection = settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().size();
- cache.findFilesWithMissingCopies(collection, numberOfpillarsInCollection, 0L, Long.MAX_VALUE);
+ int numberOfPillarsInCollection = settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().size();
+ cache.findFilesWithMissingCopies(collection, numberOfPillarsInCollection, 0L, Long.MAX_VALUE);
System.err.println("Time to find missing files: " + TimeUtils.millisecondsToHuman(System.currentTimeMillis() - startTime));
startTime = System.currentTimeMillis();
diff --git a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/IntegrityWorkflowManagerTest.java b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/IntegrityWorkflowManagerTest.java
index e1e8abe2f..bddd5fb37 100644
--- a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/IntegrityWorkflowManagerTest.java
+++ b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/IntegrityWorkflowManagerTest.java
@@ -36,6 +36,9 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@@ -49,19 +52,22 @@ public class IntegrityWorkflowManagerTest extends ExtendedTestCase {
private Settings settings;
private WorkflowSettings workflowSettings;
private TimerBasedScheduler scheduler;
+ private DatatypeFactory factory;
private String collection1ID, collection2ID;
private TestWorkflow workflow1, workflow2;
@BeforeMethod(alwaysRun = true)
- public void setup() {
+ public void setup() throws DatatypeConfigurationException {
scheduler = mock(TimerBasedScheduler.class);
+ factory = DatatypeFactory.newInstance();
+
settings = TestSettingsProvider.reloadSettings(this.getClass().getSimpleName());
workflowSettings = new WorkflowSettings();
WorkflowConfiguration workflowConfiguration = new WorkflowConfiguration();
workflowConfiguration.setWorkflowClass("org.bitrepository.integrityservice.workflow.TestWorkflow");
Schedule schedule = new Schedule();
- schedule.setWorkflowInterval(IntegrityWorkflowManager.DAILY);
+ schedule.setWorkflowInterval(factory.newDuration(IntegrityWorkflowManager.DAILY));
workflowConfiguration.setSchedules(new Schedules());
workflowConfiguration.getSchedules().getSchedule().add(schedule);
workflowSettings.getWorkflow().add(workflowConfiguration);
@@ -82,7 +88,7 @@ public void normalWorkflowSettings() {
"collection system",
"Two Test workflows should be scheduled daily, one for each collection");
- createIntegrityWorkflowManager(new IntegrityWorkflowContext(settings, null, null, null, null));
+ createIntegrityWorkflowManager();
verify(scheduler).schedule(eq(workflow1), eq(IntegrityWorkflowManager.DAILY));
verify(scheduler).schedule(eq(workflow2), eq(IntegrityWorkflowManager.DAILY));
verifyNoMoreInteractions(scheduler);
@@ -91,14 +97,14 @@ public void normalWorkflowSettings() {
@Test (groups = {"regressiontest"})
public void noWorkflowPackage() {
addDescription("Verifies that the IntegrityWorkflowManager loads correctly for at workflow configuration with " +
- "a workflow class name without a package scope (located in the deafult workflow package).");
+ "a workflow class name without a package scope (located in the default workflow package).");
addStep("Create a IntegrityWorkflowManager based on a single Testworkflow with a daily schedule in a to " +
- "collection system, where the className is just the simplename",
+ "collection system, where the className is just the simpleName",
"Two Test workflows should be scheduled daily, one for each collection");
workflowSettings.getWorkflow().get(0).setWorkflowClass("TestWorkflow");
- createIntegrityWorkflowManager(new IntegrityWorkflowContext(settings, null, null, null, null));
+ createIntegrityWorkflowManager();
verify(scheduler).schedule(eq(workflow1), eq(IntegrityWorkflowManager.DAILY));
verify(scheduler).schedule(eq(workflow2), eq(IntegrityWorkflowManager.DAILY));
verifyNoMoreInteractions(scheduler);
@@ -119,7 +125,7 @@ public void noWorkflowSettings() {
defaultWorkflow2.initialise(null, collection2ID);
- createIntegrityWorkflowManager(new IntegrityWorkflowContext(settings, null, null, null, null));
+ createIntegrityWorkflowManager();
verify(scheduler).schedule(eq(defaultWorkflow1), eq(IntegrityWorkflowManager.DAILY));
verify(scheduler).schedule(eq(defaultWorkflow2), eq(IntegrityWorkflowManager.DAILY));
verifyNoMoreInteractions(scheduler);
@@ -137,17 +143,17 @@ public void collectionSpecificWorkflows() {
settings.getReferenceSettings().getIntegrityServiceSettings().getWorkflows().getWorkflow().get(0);
workflowConfiguration.getSchedules().getSchedule().clear();
Schedule schedule1 = new Schedule();
- schedule1.setWorkflowInterval(IntegrityWorkflowManager.DAILY);
+ schedule1.setWorkflowInterval(factory.newDuration(IntegrityWorkflowManager.DAILY));
schedule1.setCollections(new Collections());
schedule1.getCollections().getCollectionID().add(collection1ID);
workflowConfiguration.getSchedules().getSchedule().add(schedule1);
Schedule schedule2 = new Schedule();
- schedule2.setWorkflowInterval(IntegrityWorkflowManager.HOURLY);
+ schedule2.setWorkflowInterval(factory.newDuration(IntegrityWorkflowManager.HOURLY));
schedule2.setCollections(new Collections());
schedule2.getCollections().getCollectionID().add(collection2ID);
workflowConfiguration.getSchedules().getSchedule().add(schedule2);
- createIntegrityWorkflowManager(new IntegrityWorkflowContext(settings, null, null, null, null));
+ createIntegrityWorkflowManager();
verify(scheduler).schedule(eq(workflow1), eq(IntegrityWorkflowManager.DAILY));
verify(scheduler).schedule(eq(workflow2), eq(IntegrityWorkflowManager.HOURLY));
verifyNoMoreInteractions(scheduler);
@@ -162,8 +168,7 @@ public void unscheduledWorkflow() {
"Two Test workflows should be create with a -1 interval between runs.");
workflowSettings.getWorkflow().get(0).setSchedules(null);
- IntegrityWorkflowManager manager = createIntegrityWorkflowManager(
- new IntegrityWorkflowContext(settings, null, null, null, null));
+ IntegrityWorkflowManager manager = createIntegrityWorkflowManager();
when(manager.getNextScheduledRun(workflow1.getJobID())).thenReturn(null);
when(manager.getRunInterval(workflow1.getJobID())).thenReturn(-1L);
assertNull(manager.getNextScheduledRun(workflow1.getJobID()));
@@ -182,7 +187,7 @@ public void startWorkflow() {
verify(scheduler).startJob(workflow1);
}
- private IntegrityWorkflowManager createIntegrityWorkflowManager(IntegrityWorkflowContext context) {
+ private IntegrityWorkflowManager createIntegrityWorkflowManager() {
IntegrityWorkflowManager manager =
new IntegrityWorkflowManager(new IntegrityWorkflowContext(settings, null, null, null, null),
scheduler);
diff --git a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/RepairMissingFilesWorkflowTest.java b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/RepairMissingFilesWorkflowTest.java
index 07ba6c040..acca352b1 100644
--- a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/RepairMissingFilesWorkflowTest.java
+++ b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/RepairMissingFilesWorkflowTest.java
@@ -42,6 +42,8 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
import java.math.BigInteger;
import java.net.URL;
import java.util.ArrayList;
@@ -83,7 +85,8 @@ public void setup() throws Exception {
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().clear();
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(PILLAR_1);
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(PILLAR_2);
- settings.getReferenceSettings().getIntegrityServiceSettings().setTimeBeforeMissingFileCheck(0);
+ Duration time = DatatypeFactory.newInstance().newDuration(0);
+ settings.getReferenceSettings().getIntegrityServiceSettings().setTimeBeforeMissingFileCheck(time);
settings.getReferenceSettings().getFileExchangeSettings().setProtocolType(ProtocolType.HTTP);
settings.getReferenceSettings().getFileExchangeSettings().setPath("dav");
@@ -100,7 +103,7 @@ public void setup() throws Exception {
}
@Test(groups = {"regressiontest", "integritytest"})
- public void testNoMissingFiles() throws Exception {
+ public void testNoMissingFiles() {
addDescription("Test that the workflow does nothing, when it has no missing files.");
addStep("Prepare for calls to mocks", "");
when(model.findFilesWithMissingCopies(anyString(), anyInt(), anyLong(), anyLong()))
@@ -123,7 +126,7 @@ public void testNoMissingFiles() throws Exception {
}
@Test(groups = {"regressiontest", "integritytest"})
- public void testSuccessRepair() throws Exception {
+ public void testSuccessRepair() {
addDescription("Test that the workflow makes calls to the collector, when a file is missing");
addStep("Prepare for calls to mocks to handle a repair", "");
when(model.findFilesWithMissingCopies(eq(TEST_COLLECTION), anyInt(), anyLong(), anyLong()))
@@ -171,7 +174,7 @@ public Void answer(InvocationOnMock invocation) {
}
@Test(groups = {"regressiontest", "integritytest"})
- public void testFailedGetFile() throws Exception {
+ public void testFailedGetFile() {
addDescription("Test that the workflow does not try to put a file, if it fails to get it.");
addStep("Prepare for calls to mocks to fail when performing get-file", "");
when(model.findFilesWithMissingCopies(eq(TEST_COLLECTION), anyInt(), anyLong(), anyLong()))
@@ -211,7 +214,7 @@ public Void answer(InvocationOnMock invocation) {
}
@Test(groups = {"regressiontest", "integritytest"})
- public void testFailedPutFile() throws Exception {
+ public void testFailedPutFile() {
addDescription("Test that the workflow makes calls to the collector for get and put file, even when put file fails.");
addStep("Prepare for calls to mocks", "");
when(model.findFilesWithMissingCopies(eq(TEST_COLLECTION), anyInt(), anyLong(), anyLong()))
diff --git a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/GetChecksumForFileStepTest.java b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/GetChecksumForFileStepTest.java
index 05b93027e..b9f40d0ca 100644
--- a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/GetChecksumForFileStepTest.java
+++ b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/GetChecksumForFileStepTest.java
@@ -41,6 +41,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.xml.datatype.DatatypeConfigurationException;
import java.util.Arrays;
import static org.mockito.ArgumentMatchers.any;
@@ -63,11 +64,10 @@ public class GetChecksumForFileStepTest extends WorkflowstepTest {
public static final String TEST_PILLAR_3 = "test-pillar-3";
public static final String FILE_1 = "test-file-1";
- public static final String FILE_2 = "test-file-2";
String TEST_COLLECTION = "test-collection";
@BeforeMethod(alwaysRun = true)
- public void setup() {
+ public void setup() throws DatatypeConfigurationException {
super.setup();
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().clear();
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(TEST_PILLAR_1);
diff --git a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/HandleChecksumValidationStepTest.java b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/HandleChecksumValidationStepTest.java
index 161b8dd03..d6ad4f327 100644
--- a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/HandleChecksumValidationStepTest.java
+++ b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/HandleChecksumValidationStepTest.java
@@ -39,6 +39,9 @@
import org.testng.Assert;
import org.testng.annotations.Test;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
@@ -62,12 +65,13 @@ public class HandleChecksumValidationStepTest extends IntegrityDatabaseTestCase
String TEST_COLLECTION;
@Override
- protected void customizeSettings() {
+ protected void customizeSettings() throws DatatypeConfigurationException {
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().clear();
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(TEST_PILLAR_1);
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(TEST_PILLAR_2);
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(TEST_PILLAR_3);
- settings.getReferenceSettings().getIntegrityServiceSettings().setTimeBeforeMissingFileCheck(0L);
+ Duration time = DatatypeFactory.newInstance().newDuration(0);
+ settings.getReferenceSettings().getIntegrityServiceSettings().setTimeBeforeMissingFileCheck(time);
SettingsUtils.initialize(settings);
TEST_COLLECTION = settings.getRepositorySettings().getCollections().getCollection().get(0).getID();
auditManager = mock(AuditTrailManager.class);
@@ -106,10 +110,10 @@ public void testSimilarData() throws Exception {
addStep("Validate the file ids", "Should not have integrity issues.");
Assert.assertFalse(reporter.hasIntegrityIssues(), reporter.generateSummaryOfReport());
- Assert.assertTrue(cs.getCollectionStat().getChecksumErrors() == 0);
- Assert.assertTrue(cs.getPillarCollectionStat(TEST_PILLAR_3).getChecksumErrors() == 0);
- Assert.assertTrue(cs.getPillarCollectionStat(TEST_PILLAR_2).getChecksumErrors() == 0);
- Assert.assertTrue(cs.getPillarCollectionStat(TEST_PILLAR_1).getChecksumErrors() == 0);
+ Assert.assertEquals(cs.getCollectionStat().getChecksumErrors(), Long.valueOf(0));
+ Assert.assertEquals(cs.getPillarCollectionStat(TEST_PILLAR_3).getChecksumErrors(), Long.valueOf(0));
+ Assert.assertEquals(cs.getPillarCollectionStat(TEST_PILLAR_2).getChecksumErrors(), Long.valueOf(0));
+ Assert.assertEquals(cs.getPillarCollectionStat(TEST_PILLAR_1).getChecksumErrors(), Long.valueOf(0));
for(FileInfo fi : cache.getFileInfos(FILE_1, TEST_COLLECTION)) {
Assert.assertEquals(fi.getChecksum(), "1234cccc4321");
}
@@ -154,9 +158,9 @@ public void testTwoDisagreeingChecksums() throws Exception {
addStep("Validate the file ids", "Should have integrity issues. No entry should be valid.");
Assert.assertTrue(reporter.hasIntegrityIssues(), reporter.generateSummaryOfReport());
- Assert.assertTrue(cs.getCollectionStat().getChecksumErrors() == 1);
- Assert.assertTrue(cs.getPillarCollectionStat(TEST_PILLAR_1).getChecksumErrors() == 1);
- Assert.assertTrue(cs.getPillarCollectionStat(TEST_PILLAR_2).getChecksumErrors() == 1);
+ Assert.assertEquals(cs.getCollectionStat().getChecksumErrors(), Long.valueOf(1));
+ Assert.assertEquals(cs.getPillarCollectionStat(TEST_PILLAR_1).getChecksumErrors(), Long.valueOf(1));
+ Assert.assertEquals(cs.getPillarCollectionStat(TEST_PILLAR_2).getChecksumErrors(), Long.valueOf(1));
/*for(FileInfo fi : cache.getFileInfos(FILE_1, TEST_COLLECTION)) {
Assert.assertTrue(fi.getChecksumState() != ChecksumState.VALID);
}*/
@@ -183,10 +187,10 @@ public void testThreeDisagreeingChecksums() throws Exception {
addStep("Validate the file ids", "Should have integrity issues.");
Assert.assertTrue(reporter.hasIntegrityIssues(), reporter.generateSummaryOfReport());
- Assert.assertTrue(cs.getCollectionStat().getChecksumErrors() == 1);
- Assert.assertTrue(cs.getPillarCollectionStat(TEST_PILLAR_3).getChecksumErrors() == 1);
- Assert.assertTrue(cs.getPillarCollectionStat(TEST_PILLAR_2).getChecksumErrors() == 1);
- Assert.assertTrue(cs.getPillarCollectionStat(TEST_PILLAR_1).getChecksumErrors() == 1);
+ Assert.assertEquals(cs.getCollectionStat().getChecksumErrors(), Long.valueOf(1));
+ Assert.assertEquals(cs.getPillarCollectionStat(TEST_PILLAR_3).getChecksumErrors(), Long.valueOf(1));
+ Assert.assertEquals(cs.getPillarCollectionStat(TEST_PILLAR_2).getChecksumErrors(), Long.valueOf(1));
+ Assert.assertEquals(cs.getPillarCollectionStat(TEST_PILLAR_1).getChecksumErrors(), Long.valueOf(1));
}
@Test(groups = {"regressiontest", "integritytest"})
@@ -211,10 +215,10 @@ public void testChecksumMajority() throws Exception {
addStep("Validate the file ids", "Should only have integrity issues on pillar 3.");
Assert.assertTrue(reporter.hasIntegrityIssues(), reporter.generateSummaryOfReport());
- Assert.assertEquals((long) cs.getCollectionStat().getChecksumErrors(), 1);
- Assert.assertEquals((long) cs.getPillarCollectionStat(TEST_PILLAR_3).getChecksumErrors(), 1);
- Assert.assertEquals((long) cs.getPillarCollectionStat(TEST_PILLAR_2).getChecksumErrors(), 0);
- Assert.assertEquals((long) cs.getPillarCollectionStat(TEST_PILLAR_1).getChecksumErrors(), 0);
+ Assert.assertEquals(cs.getCollectionStat().getChecksumErrors(), Long.valueOf(1));
+ Assert.assertEquals(cs.getPillarCollectionStat(TEST_PILLAR_3).getChecksumErrors(), Long.valueOf(1));
+ Assert.assertEquals(cs.getPillarCollectionStat(TEST_PILLAR_2).getChecksumErrors(), Long.valueOf(0));
+ Assert.assertEquals(cs.getPillarCollectionStat(TEST_PILLAR_1).getChecksumErrors(), Long.valueOf(0));
}
@Test(groups = {"regressiontest", "integritytest"})
diff --git a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/WorkflowstepTest.java b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/WorkflowstepTest.java
index 9f77c2161..f6740ed49 100644
--- a/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/WorkflowstepTest.java
+++ b/bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/workflow/step/WorkflowstepTest.java
@@ -33,13 +33,15 @@
import org.jaccept.structure.ExtendedTestCase;
import org.testng.annotations.BeforeMethod;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+
import static org.mockito.Mockito.mock;
public class WorkflowstepTest extends ExtendedTestCase {
protected Settings settings;
public static final String TEST_PILLAR_1 = "test-pillar-1";
- public static final String TEST_FILE_1 = "test-file-1";
protected String TEST_COLLECTION;
protected IntegrityAlerter alerter;
@@ -49,11 +51,12 @@ public class WorkflowstepTest extends ExtendedTestCase {
protected IntegrityContributors integrityContributors;
@BeforeMethod(alwaysRun = true)
- public void setup() {
+ public void setup() throws DatatypeConfigurationException {
settings = TestSettingsProvider.reloadSettings(this.getClass().getSimpleName());
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().clear();
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID().add(TEST_PILLAR_1);
- settings.getReferenceSettings().getIntegrityServiceSettings().setTimeBeforeMissingFileCheck(0L);
+ DatatypeFactory factory = DatatypeFactory.newInstance();
+ settings.getReferenceSettings().getIntegrityServiceSettings().setTimeBeforeMissingFileCheck(factory.newDuration(0));
TEST_COLLECTION = settings.getRepositorySettings().getCollections().getCollection().get(0).getID();
SettingsUtils.initialize(settings);
diff --git a/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/MonitoringService.java b/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/MonitoringService.java
index 626b3583b..e64df6a5e 100644
--- a/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/MonitoringService.java
+++ b/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/MonitoringService.java
@@ -25,6 +25,7 @@
import org.bitrepository.access.getstatus.GetStatusClient;
import org.bitrepository.common.settings.Settings;
import org.bitrepository.common.utils.SettingsUtils;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.monitoringservice.alarm.BasicMonitoringServiceAlerter;
import org.bitrepository.monitoringservice.alarm.MonitorAlerter;
import org.bitrepository.monitoringservice.collector.StatusCollector;
@@ -40,6 +41,7 @@
import org.slf4j.LoggerFactory;
import javax.jms.JMSException;
+import java.time.Duration;
import java.util.Map;
public class MonitoringService implements LifeCycledService {
@@ -80,8 +82,10 @@ public int getMaxRetries() {
/**
* @return The interval between collecting status from the components.
*/
- public long getCollectionInterval() {
- return settings.getReferenceSettings().getMonitoringServiceSettings().getCollectionInterval();
+ public Duration getCollectionInterval() {
+ javax.xml.datatype.Duration collectionInterval =
+ settings.getReferenceSettings().getMonitoringServiceSettings().getCollectionInterval();
+ return XmlUtils.xmlDurationToDuration(collectionInterval);
}
@Override
diff --git a/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/collector/StatusCollector.java b/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/collector/StatusCollector.java
index 3b5923e5b..e5c489eef 100644
--- a/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/collector/StatusCollector.java
+++ b/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/collector/StatusCollector.java
@@ -24,9 +24,11 @@
import org.bitrepository.access.getstatus.GetStatusClient;
import org.bitrepository.client.eventhandler.EventHandler;
import org.bitrepository.common.settings.Settings;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.monitoringservice.alarm.MonitorAlerter;
import org.bitrepository.monitoringservice.status.StatusStore;
+import javax.xml.datatype.Duration;
import java.util.Timer;
import java.util.TimerTask;
@@ -37,9 +39,10 @@ public class StatusCollector {
private final GetStatusClient getStatusClient;
private final StatusStore statusStore;
private final EventHandler eventHandler;
- private static final Boolean TIMER_IS_DAEMON = true;
+ private static final boolean TIMER_IS_DAEMON = true;
private static final String NAME_OF_TIMER = "GetStatus collection timer";
private static final Timer timer = new Timer(NAME_OF_TIMER, TIMER_IS_DAEMON);
+ /** Collection interval in milliseconds */
private final long collectionInterval;
/**
@@ -52,7 +55,9 @@ public StatusCollector(GetStatusClient getStatusClient, Settings settings, Statu
this.getStatusClient = getStatusClient;
eventHandler = new GetStatusEventHandler(statusStore, alerter);
this.statusStore = statusStore;
- collectionInterval = settings.getReferenceSettings().getMonitoringServiceSettings().getCollectionInterval();
+ Duration collectionIntervalXmlDuration =
+ settings.getReferenceSettings().getMonitoringServiceSettings().getCollectionInterval();
+ collectionInterval = XmlUtils.xmlDurationToMilliseconds(collectionIntervalXmlDuration);
}
/**
diff --git a/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/webservice/RestMonitoringService.java b/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/webservice/RestMonitoringService.java
index 9c8b89550..4d78f8c0a 100644
--- a/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/webservice/RestMonitoringService.java
+++ b/bitrepository-monitoring-service/src/main/java/org/bitrepository/monitoringservice/webservice/RestMonitoringService.java
@@ -47,7 +47,7 @@ public RestMonitoringService() {
public List getMonitoringServiceConfiguration() {
List options = new ArrayList<>();
- options.add(new WebConfOption("Check interval", TimeUtils.millisecondsToHuman(service.getCollectionInterval())));
+ options.add(new WebConfOption("Check interval", TimeUtils.durationToHuman(service.getCollectionInterval())));
options.add(new WebConfOption("Max retries", Long.toString(service.getMaxRetries())));
return options;
diff --git a/bitrepository-monitoring-service/src/test/java/org/bitrepository/monitoringservice/collector/StatusCollectorTest.java b/bitrepository-monitoring-service/src/test/java/org/bitrepository/monitoringservice/collector/StatusCollectorTest.java
index 5161cc1dd..1d9a3c877 100644
--- a/bitrepository-monitoring-service/src/test/java/org/bitrepository/monitoringservice/collector/StatusCollectorTest.java
+++ b/bitrepository-monitoring-service/src/test/java/org/bitrepository/monitoringservice/collector/StatusCollectorTest.java
@@ -31,6 +31,9 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+
public class StatusCollectorTest extends ExtendedTestCase {
Settings settings;
@@ -50,7 +53,8 @@ public void testStatusCollector() throws Exception {
MockAlerter alerter = new MockAlerter();
MockStatusStore store = new MockStatusStore();
MockGetStatusClient client = new MockGetStatusClient();
- settings.getReferenceSettings().getMonitoringServiceSettings().setCollectionInterval(INTERVAL);
+ Duration intervalXmlDur = DatatypeFactory.newInstance().newDuration(INTERVAL);
+ settings.getReferenceSettings().getMonitoringServiceSettings().setCollectionInterval(intervalXmlDur);
addStep("Create the collector", "");
Assert.assertEquals(store.getCallsForGetStatusMap(), 0);
diff --git a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/Pillar.java b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/Pillar.java
index 3602346a0..9734045ad 100644
--- a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/Pillar.java
+++ b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/Pillar.java
@@ -24,6 +24,7 @@
import org.bitrepository.common.ArgumentValidator;
import org.bitrepository.common.settings.Settings;
import org.bitrepository.common.utils.SettingsUtils;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.pillar.common.MessageHandlerContext;
import org.bitrepository.pillar.messagehandler.PillarMediator;
import org.bitrepository.pillar.schedulablejobs.RecalculateChecksumJob;
@@ -37,6 +38,7 @@
import org.slf4j.LoggerFactory;
import javax.jms.JMSException;
+import javax.xml.datatype.Duration;
/**
* Class for the Reference Pillar.
@@ -88,9 +90,10 @@ public Pillar(MessageBus messageBus, Settings settings, StorageModel pillarModel
*/
private void initializeWorkflows() {
Long interval = DEFAULT_RECALCULATION_WORKFLOW_TIME;
- if (settings.getReferenceSettings().getPillarSettings().getRecalculateOldChecksumsInterval() != null) {
- interval = settings.getReferenceSettings().getPillarSettings()
- .getRecalculateOldChecksumsInterval().longValue();
+ Duration recalculateOldChecksumsInterval =
+ settings.getReferenceSettings().getPillarSettings().getRecalculateOldChecksumsInterval();
+ if (recalculateOldChecksumsInterval != null) {
+ interval = XmlUtils.xmlDurationToMilliseconds(recalculateOldChecksumsInterval);
}
for (String collectionID : SettingsUtils.getCollectionIDsForPillar(
settings.getReferenceSettings().getPillarSettings().getPillarID())) {
diff --git a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForDeleteFileRequestHandler.java b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForDeleteFileRequestHandler.java
index 35e28945b..bbcbbb3ad 100644
--- a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForDeleteFileRequestHandler.java
+++ b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForDeleteFileRequestHandler.java
@@ -29,7 +29,6 @@
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForDeleteFileRequest;
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForDeleteFileResponse;
import org.bitrepository.bitrepositorymessages.MessageResponse;
-import org.bitrepository.common.utils.TimeMeasurementUtils;
import org.bitrepository.pillar.common.MessageHandlerContext;
import org.bitrepository.pillar.store.StorageModel;
import org.bitrepository.protocol.MessageContext;
@@ -77,8 +76,7 @@ protected void validateRequest(IdentifyPillarsForDeleteFileRequest request, Mess
protected void sendPositiveResponse(IdentifyPillarsForDeleteFileRequest request, MessageContext messageContext) {
IdentifyPillarsForDeleteFileResponse response = createFinalResponse(request);
- response.setTimeToDeliver(TimeMeasurementUtils.getTimeMeasurementFromMilliseconds(
- getSettings().getReferenceSettings().getPillarSettings().getTimeToStartDeliver()));
+ response.setTimeToDeliver(getTimeToStartDeliver());
ResponseInfo irInfo = new ResponseInfo();
irInfo.setResponseCode(ResponseCode.IDENTIFICATION_POSITIVE);
diff --git a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetChecksumsRequestHandler.java b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetChecksumsRequestHandler.java
index f84613658..d2e93b6bd 100644
--- a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetChecksumsRequestHandler.java
+++ b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetChecksumsRequestHandler.java
@@ -30,7 +30,6 @@
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForGetChecksumsRequest;
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForGetChecksumsResponse;
import org.bitrepository.bitrepositorymessages.MessageResponse;
-import org.bitrepository.common.utils.TimeMeasurementUtils;
import org.bitrepository.pillar.common.MessageHandlerContext;
import org.bitrepository.pillar.store.StorageModel;
import org.bitrepository.protocol.MessageContext;
@@ -79,8 +78,7 @@ protected void validateRequest(IdentifyPillarsForGetChecksumsRequest request, Me
protected void sendPositiveResponse(IdentifyPillarsForGetChecksumsRequest request, MessageContext requestContext) {
IdentifyPillarsForGetChecksumsResponse response = createFinalResponse(request);
- response.setTimeToDeliver(TimeMeasurementUtils.getTimeMeasurementFromMilliseconds(
- getSettings().getReferenceSettings().getPillarSettings().getTimeToStartDeliver()));
+ response.setTimeToDeliver(getTimeToStartDeliver());
ResponseInfo irInfo = new ResponseInfo();
irInfo.setResponseCode(ResponseCode.IDENTIFICATION_POSITIVE);
diff --git a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetFileIDsRequestHandler.java b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetFileIDsRequestHandler.java
index bf2baa53a..2eb6aefd1 100644
--- a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetFileIDsRequestHandler.java
+++ b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetFileIDsRequestHandler.java
@@ -29,7 +29,6 @@
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForGetFileIDsRequest;
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForGetFileIDsResponse;
import org.bitrepository.bitrepositorymessages.MessageResponse;
-import org.bitrepository.common.utils.TimeMeasurementUtils;
import org.bitrepository.pillar.common.MessageHandlerContext;
import org.bitrepository.pillar.store.StorageModel;
import org.bitrepository.protocol.MessageContext;
@@ -75,8 +74,7 @@ protected void validateRequest(IdentifyPillarsForGetFileIDsRequest request, Mess
@Override
protected void sendPositiveResponse(IdentifyPillarsForGetFileIDsRequest request, MessageContext requestContext) {
IdentifyPillarsForGetFileIDsResponse response = createFinalResponse(request);
- response.setTimeToDeliver(TimeMeasurementUtils.getTimeMeasurementFromMilliseconds(
- getSettings().getReferenceSettings().getPillarSettings().getTimeToStartDeliver()));
+ response.setTimeToDeliver(getTimeToStartDeliver());
ResponseInfo irInfo = new ResponseInfo();
irInfo.setResponseCode(ResponseCode.IDENTIFICATION_POSITIVE);
diff --git a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetFileRequestHandler.java b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetFileRequestHandler.java
index 870928456..37ffd15ac 100644
--- a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetFileRequestHandler.java
+++ b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForGetFileRequestHandler.java
@@ -29,7 +29,6 @@
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForGetFileRequest;
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForGetFileResponse;
import org.bitrepository.bitrepositorymessages.MessageResponse;
-import org.bitrepository.common.utils.TimeMeasurementUtils;
import org.bitrepository.pillar.common.MessageHandlerContext;
import org.bitrepository.pillar.store.StorageModel;
import org.bitrepository.protocol.MessageContext;
@@ -79,8 +78,7 @@ protected void validateRequest(IdentifyPillarsForGetFileRequest request, Message
protected void sendPositiveResponse(IdentifyPillarsForGetFileRequest request, MessageContext requestContext) {
IdentifyPillarsForGetFileResponse response = createFinalResponse(request);
- response.setTimeToDeliver(TimeMeasurementUtils.getTimeMeasurementFromMilliseconds(
- getSettings().getReferenceSettings().getPillarSettings().getTimeToStartDeliver()));
+ response.setTimeToDeliver(getTimeToStartDeliver());
ResponseInfo irInfo = new ResponseInfo();
irInfo.setResponseCode(ResponseCode.IDENTIFICATION_POSITIVE);
diff --git a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForPutFileRequestHandler.java b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForPutFileRequestHandler.java
index 83e836df1..17c21ceed 100644
--- a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForPutFileRequestHandler.java
+++ b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForPutFileRequestHandler.java
@@ -30,7 +30,6 @@
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForPutFileResponse;
import org.bitrepository.bitrepositorymessages.MessageResponse;
import org.bitrepository.common.utils.ChecksumUtils;
-import org.bitrepository.common.utils.TimeMeasurementUtils;
import org.bitrepository.pillar.common.MessageHandlerContext;
import org.bitrepository.pillar.store.StorageModel;
import org.bitrepository.protocol.MessageContext;
@@ -123,8 +122,7 @@ private void respondDuplicateFile(IdentifyPillarsForPutFileRequest message) thro
IdentifyPillarsForPutFileResponse response = createFinalResponse(message);
response.setReplyTo(getSettings().getReceiverDestinationID());
- response.setTimeToDeliver(TimeMeasurementUtils.getTimeMeasurementFromMilliseconds(
- getSettings().getReferenceSettings().getPillarSettings().getTimeToStartDeliver()));
+ response.setTimeToDeliver(getTimeToStartDeliver());
response.setChecksumDataForExistingFile(getPillarModel().getChecksumDataForFile(message.getFileID(), message.getCollectionID(),
ChecksumUtils.getDefault(getSettings())));
@@ -147,8 +145,7 @@ private void respondSuccessfulIdentification(IdentifyPillarsForPutFileRequest re
// Needs to filled in: AuditTrailInformation, PillarChecksumSpec, ReplyTo, TimeToDeliver
response.setReplyTo(getSettings().getContributorDestinationID());
- response.setTimeToDeliver(TimeMeasurementUtils.getTimeMeasurementFromMilliseconds(
- getSettings().getReferenceSettings().getPillarSettings().getTimeToStartDeliver()));
+ response.setTimeToDeliver(getTimeToStartDeliver());
ResponseInfo irInfo = new ResponseInfo();
irInfo.setResponseCode(ResponseCode.IDENTIFICATION_POSITIVE);
diff --git a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForReplaceFileRequestHandler.java b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForReplaceFileRequestHandler.java
index bea3c6e2b..94d6d6428 100644
--- a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForReplaceFileRequestHandler.java
+++ b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyPillarsForReplaceFileRequestHandler.java
@@ -29,7 +29,6 @@
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForReplaceFileRequest;
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForReplaceFileResponse;
import org.bitrepository.bitrepositorymessages.MessageResponse;
-import org.bitrepository.common.utils.TimeMeasurementUtils;
import org.bitrepository.pillar.common.MessageHandlerContext;
import org.bitrepository.pillar.store.StorageModel;
import org.bitrepository.protocol.MessageContext;
@@ -78,8 +77,7 @@ protected void validateRequest(IdentifyPillarsForReplaceFileRequest request, Mes
protected void sendPositiveResponse(IdentifyPillarsForReplaceFileRequest request, MessageContext requestContext) {
IdentifyPillarsForReplaceFileResponse response = createFinalResponse(request);
- response.setTimeToDeliver(TimeMeasurementUtils.getTimeMeasurementFromMilliseconds(
- getSettings().getReferenceSettings().getPillarSettings().getTimeToStartDeliver()));
+ response.setTimeToDeliver(getTimeToStartDeliver());
ResponseInfo irInfo = new ResponseInfo();
irInfo.setResponseCode(ResponseCode.IDENTIFICATION_POSITIVE);
diff --git a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyRequestHandler.java b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyRequestHandler.java
index e8a1e5f16..c2d8260a4 100644
--- a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyRequestHandler.java
+++ b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/messagehandler/IdentifyRequestHandler.java
@@ -21,12 +21,16 @@
*/
package org.bitrepository.pillar.messagehandler;
+import org.bitrepository.bitrepositoryelements.TimeMeasureTYPE;
import org.bitrepository.bitrepositorymessages.MessageRequest;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.pillar.common.MessageHandlerContext;
import org.bitrepository.pillar.store.StorageModel;
import org.bitrepository.protocol.MessageContext;
import org.bitrepository.service.exception.RequestHandlerException;
+import javax.xml.datatype.Duration;
+
/**
* Abstract class for the methods for handing the identify request messages.
* Contains the common methods for handling identify request messages.
@@ -69,4 +73,10 @@ protected abstract void validateRequest(T request, MessageContext requestContext
*/
protected abstract void sendPositiveResponse(T request, MessageContext requestContext)
throws RequestHandlerException;
+
+ protected TimeMeasureTYPE getTimeToStartDeliver() {
+ Duration timeToStartDeliver = getSettings().getReferenceSettings().getPillarSettings().getTimeToStartDeliver();
+ return XmlUtils.xmlDurationToTimeMeasure(timeToStartDeliver);
+ }
+
}
diff --git a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/FileStorageModel.java b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/FileStorageModel.java
index fe552c76b..a5c3b7e50 100644
--- a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/FileStorageModel.java
+++ b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/FileStorageModel.java
@@ -35,6 +35,7 @@
import org.bitrepository.common.utils.Base16Utils;
import org.bitrepository.common.utils.CalendarUtils;
import org.bitrepository.common.utils.ChecksumUtils;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.pillar.store.checksumdatabase.ChecksumEntry;
import org.bitrepository.pillar.store.checksumdatabase.ChecksumStore;
import org.bitrepository.pillar.store.checksumdatabase.ExtractedChecksumResultSet;
@@ -48,9 +49,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
import java.io.IOException;
import java.net.URL;
+import java.time.Instant;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
@@ -267,13 +270,12 @@ public void verifyFileToCacheConsistencyOfAllData(String collectionID) {
verifyArchiveToCacheConsistencyForFile(fileID, collectionID);
}
- long maxAgeForChecksums = settings.getReferenceSettings().getPillarSettings()
- .getMaxAgeForChecksums().longValue();
- Date checksumDate = new Date(System.currentTimeMillis() - maxAgeForChecksums);
+ Duration maxAgeForChecksums = settings.getReferenceSettings().getPillarSettings().getMaxAgeForChecksums();
+ Instant checksumDate = Instant.now().minus(XmlUtils.xmlDurationToDuration(maxAgeForChecksums));
for (String fileID : cache.getFileIDsWithOldChecksums(checksumDate, collectionID)) {
recalculateChecksum(fileID, collectionID);
}
- // TODO: validate the 'last modified' timestamp ?
+ // TODO: validate the 'last modified' timestamp?
}
/**
diff --git a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/checksumdatabase/ChecksumDAO.java b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/checksumdatabase/ChecksumDAO.java
index 245cbd10a..abca41817 100644
--- a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/checksumdatabase/ChecksumDAO.java
+++ b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/checksumdatabase/ChecksumDAO.java
@@ -26,6 +26,7 @@
import org.bitrepository.service.database.DatabaseManager;
import javax.xml.datatype.XMLGregorianCalendar;
+import java.time.Instant;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -152,9 +153,9 @@ public ExtractedChecksumResultSet getChecksumResult(XMLGregorianCalendar minTime
}
@Override
- public List getFileIDsWithOldChecksums(Date checksumDate, String collectionID) {
+ public List getFileIDsWithOldChecksums(Instant checksumDate, String collectionID) {
ArgumentValidator.checkNotNull(checksumDate, "Date checksumDate");
ArgumentValidator.checkNotNullOrEmpty(collectionID, "String collectionID");
- return extractor.extractFileIDsWithMaxChecksumDate(checksumDate.getTime(), collectionID);
+ return extractor.extractFileIDsWithMaxChecksumDate(checksumDate.toEpochMilli(), collectionID);
}
}
diff --git a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/checksumdatabase/ChecksumStore.java b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/checksumdatabase/ChecksumStore.java
index 1b117089b..cebeb73fa 100644
--- a/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/checksumdatabase/ChecksumStore.java
+++ b/bitrepository-reference-pillar/src/main/java/org/bitrepository/pillar/store/checksumdatabase/ChecksumStore.java
@@ -22,6 +22,7 @@
package org.bitrepository.pillar.store.checksumdatabase;
import javax.xml.datatype.XMLGregorianCalendar;
+import java.time.Instant;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -117,7 +118,7 @@ ExtractedFileIDsResultSet getFileIDs(XMLGregorianCalendar minTimeStamp, XMLGrego
* @param collectionID The id of the collection for the files.
* @return The collection of ids for the files with old checksums.
*/
- List getFileIDsWithOldChecksums(Date checksumDate, String collectionID);
+ List getFileIDsWithOldChecksums(Instant checksumDate, String collectionID);
/**
* Deletes a given entry from the cache.
diff --git a/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/schedulablejobs/RecalculateChecksumWorkflowTest.java b/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/schedulablejobs/RecalculateChecksumWorkflowTest.java
index 06688702e..c9c76bfbf 100644
--- a/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/schedulablejobs/RecalculateChecksumWorkflowTest.java
+++ b/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/schedulablejobs/RecalculateChecksumWorkflowTest.java
@@ -24,19 +24,29 @@
import org.bitrepository.pillar.DefaultPillarTest;
import org.bitrepository.service.workflow.SchedulableJob;
import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.math.BigInteger;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
import java.util.Date;
public class RecalculateChecksumWorkflowTest extends DefaultPillarTest {
+
+ DatatypeFactory factory;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUpFactory() throws DatatypeConfigurationException {
+ factory = DatatypeFactory.newInstance();
+ }
+
@Test( groups = {"regressiontest", "pillartest"})
public void testWorkflowRecalculatesChecksum() throws Exception {
addDescription("Test that the workflow recalculates the workflows, when the maximum age has been met.");
Date beforeWorkflowDate = csCache.getCalculationDate(DEFAULT_FILE_ID, collectionID);
Assert.assertEquals(csCache.getAllFileIDs(collectionID).size(), 1);
Assert.assertEquals(archives.getAllFileIds(collectionID).size(), 1);
- settingsForCUT.getReferenceSettings().getPillarSettings().setMaxAgeForChecksums(BigInteger.ZERO);
+ settingsForCUT.getReferenceSettings().getPillarSettings().setMaxAgeForChecksums(factory.newDuration(0));
synchronized(this) {
wait(100);
@@ -58,7 +68,8 @@ public void testWorkflowDoesNotRecalculateWhenNotNeeded() throws Exception {
Date beforeWorkflowDate = csCache.getCalculationDate(DEFAULT_FILE_ID, collectionID);
Assert.assertEquals(csCache.getAllFileIDs(collectionID).size(), 1);
Assert.assertEquals(archives.getAllFileIds(collectionID).size(), 1);
- settingsForCUT.getReferenceSettings().getPillarSettings().setMaxAgeForChecksums(BigInteger.valueOf(Long.MAX_VALUE));
+ settingsForCUT.getReferenceSettings().getPillarSettings()
+ .setMaxAgeForChecksums(factory.newDuration(Long.MAX_VALUE));
synchronized(this) {
wait(100);
diff --git a/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/store/checksumcache/ChecksumDatabaseTest.java b/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/store/checksumcache/ChecksumDatabaseTest.java
index 48934e014..fba4c1698 100644
--- a/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/store/checksumcache/ChecksumDatabaseTest.java
+++ b/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/store/checksumcache/ChecksumDatabaseTest.java
@@ -40,6 +40,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.time.Instant;
import java.util.Date;
import java.util.List;
@@ -330,17 +331,17 @@ public void testGetFileIDsWithOldChecksums() {
cache.insertChecksumCalculation(FILE_ID_2, collectionID, DEFAULT_CHECKSUM, FILE_2_DATE);
addStep("Extract all entries with checksum date older than now", "Returns both file ids");
- List extractedFileIDs = cache.getFileIDsWithOldChecksums(new Date(), collectionID);
+ List extractedFileIDs = cache.getFileIDsWithOldChecksums(Instant.now(), collectionID);
Assert.assertEquals(extractedFileIDs.size(), 2);
Assert.assertTrue(extractedFileIDs.contains(FILE_ID_1));
Assert.assertTrue(extractedFileIDs.contains(FILE_ID_2));
addStep("Extract all entries with checksum date older than epoch", "Returns no file ids");
- extractedFileIDs = cache.getFileIDsWithOldChecksums(new Date(0), collectionID);
+ extractedFileIDs = cache.getFileIDsWithOldChecksums(Instant.EPOCH, collectionID);
Assert.assertEquals(extractedFileIDs.size(), 0);
addStep("Extract all entries with checksum date older than middle date", "Returns the first file id");
- extractedFileIDs = cache.getFileIDsWithOldChecksums(MIDDLE_DATE, collectionID);
+ extractedFileIDs = cache.getFileIDsWithOldChecksums(MIDDLE_DATE.toInstant(), collectionID);
Assert.assertEquals(extractedFileIDs.size(), 1);
Assert.assertTrue(extractedFileIDs.contains(FILE_ID_1));
}
diff --git a/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/store/checksumcache/MemoryCacheMock.java b/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/store/checksumcache/MemoryCacheMock.java
index 3025fe18c..dfcd43209 100644
--- a/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/store/checksumcache/MemoryCacheMock.java
+++ b/bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/store/checksumcache/MemoryCacheMock.java
@@ -27,6 +27,7 @@
import org.bitrepository.pillar.store.checksumdatabase.ExtractedFileIDsResultSet;
import javax.xml.datatype.XMLGregorianCalendar;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -130,14 +131,13 @@ public ExtractedChecksumResultSet getChecksumResult(XMLGregorianCalendar minTime
}
@Override
- public List getFileIDsWithOldChecksums(Date checksumDate, String collectionID) {
+ public List getFileIDsWithOldChecksums(Instant checksumDate, String collectionID) {
List res = new ArrayList<>();
for(ChecksumEntry ce : checksumMap.values()) {
- if(ce.getCalculationDate().getTime() < checksumDate.getTime()) {
+ if(ce.getCalculationDate().toInstant().isBefore(checksumDate)) {
res.add(ce.getFileId());
}
}
return res;
-
}
}
diff --git a/bitrepository-reference-pillar/src/test/resources/conf/ReferenceSettings.xml b/bitrepository-reference-pillar/src/test/resources/conf/ReferenceSettings.xml
index abd3e9117..c828809f9 100644
--- a/bitrepository-reference-pillar/src/test/resources/conf/ReferenceSettings.xml
+++ b/bitrepository-reference-pillar/src/test/resources/conf/ReferenceSettings.xml
@@ -30,8 +30,8 @@
org.bitrepository.protocol.messagebus.destination.UserSpecificReceiverDestinationIDFactory
- 10000
- 3600000
+ PT10S
+ PT1H
EmbeddedReferencePillar
@@ -40,9 +40,9 @@
target/reference1pillar/test-archive
1000000000
- 1000
- 86400000
- 3600000
+ PT1S
+ P1D
+ PT1H
org.apache.derby.jdbc.EmbeddedDriver
jdbc:derby:target/reference1pillar/auditcontributerdb
diff --git a/bitrepository-reference-settings/src/main/resources/xsd/ReferenceSettings.xsd b/bitrepository-reference-settings/src/main/resources/xsd/ReferenceSettings.xsd
index 8ac748b28..0f312af84 100644
--- a/bitrepository-reference-settings/src/main/resources/xsd/ReferenceSettings.xsd
+++ b/bitrepository-reference-settings/src/main/resources/xsd/ReferenceSettings.xsd
@@ -73,13 +73,13 @@
Defines the thread pools to handle message.
- A received message is check against the different message thread pools in the
+ A received message is checked against the different message thread pools in the
following order:
1. Is there defined pools specific to collection for the received message.
2. Specific message type pools
2. Category pools
- 3. Default pool (no message filters defined). Note that this poolwill always be create. If undefined a pool
- with ondemand creation of processing threads is created (using CachedThreadPool).
+ 3. Default pool (no message filters defined). Note that this pool will always be created. If undefined a pool
+ with on-demand creation of processing threads is created (using CachedThreadPool).
@@ -163,27 +163,41 @@
General settings for a client
-
+
- The amount of milliseconds between the cleanups in the
- ConversationMediator.
+ The duration between the cleanups in the ConversationMediator.
+ Non-negative XML schema durations consisting of hours, minutes and/or seconds are accepted.
+ The hours may be more than 24. The seconds may have up to 9 decimals of fraction.
+ For example PT2H (2 hours), PT3M (3 minutes), PT1H22M22.5S (1 hour 22 minutes 22.5 seconds).
+
+
+
+
+
-
+
- The timeout for a conversation in milliseconds.
+ The timeout for a conversation.
+ Non-negative XML schema durations consisting of hours, minutes and/or seconds are accepted.
+ The hours may be more than 24. The seconds may have up to 9 decimals of fraction.
+
+
+
+
+
Number of allowed automatic retries for the performing part of an operation.
This relates to operations which can fail due to file transfer errors.
- 0 denotes that a operation should not be retried (only the initial operation attempt).
+ 0 denotes that an operation should not be retried (only the initial operation attempt).
1 or higher denotes the number of additional attempts of file transfer. I.e. if 2 up to 3
attempts is allowed before the operation fails.
@@ -248,27 +262,54 @@
-
+
- The time to use as timeToStartDeliver in identification responses in milliseconds.
-
-
+ The time to use as timeToStartDeliver in identification responses.
+ Non-negative XML schema durations consisting of days, hours, minutes and/or seconds are accepted.
+ The seconds may have up to 9 decimals of fraction.
+ For example P2D (2 days), PT3M (3 minutes), P1DT1H22M22.5S (1 day 1 hour 22 minutes 22.5 seconds).
+ A day will be understood as 24 hours always.
+
+
+
+
+
+
+
-
+
- The number of milliseconds a checksum can be before it has to be recalculated.
-
-
+ The age a checksum can have before it has to be recalculated.
+ Non-negative XML schema durations are accepted. The seconds may have up to 9 decimals of fraction.
+ For example P1Y (1 year), P2M (2 months), PT3M (3 minutes),
+ P1DT1H22M22.5S (1 day 1 hour 22 minutes 22.5 seconds).
+ Years, months and days will be converted to time using heuristic average lengths
+ (24 hours for a day; between 30 and 31 days for a month).
+
+
+
+
+
+
+
-
+
- The number of milliseconds between running the workflow for ensuring the checksums integrity.
- Default is once per hour, or 3600000.
-
-
+ The interval between running the workflow for ensuring the checksums' integrity.
+ Non-negative XML schema durations are accepted. The seconds may have up to 9 decimals of fraction.
+ Years, months and days will be converted to time using heuristic average lengths
+ (24 hours for a day; between 30 and 31 days for a month).
+ Default is once per hour or PT1H.
+
+
+
+
+
+
+
@@ -312,9 +353,9 @@
- Whether or not verify the consistency between files and the data in the checksum database, when handling
+ Whether or not to verify the consistency between files and the data in the checksum database when handling
messages for operations involving the given files.
- The consistency is already being checked by the scheduled job, so it setting is only for further
+ The consistency is already being checked by the scheduled job, so this setting is only for further
verifying the consistency when handling messages.
Default value is false.
This setting is only relevant for the FilePillar (since ChecksumPillars do not have the actual files).
@@ -371,7 +412,7 @@
The list of collection ids to have its data archived with the following list of directories.
- Each collection will have its files archived in its own sub-directory with the collection name.
+ Each collection will have its files archived in its own subdirectory with the collection name.
A collection is only able to be used in one 'CollectionDir'.
If no collection ids are defined, then it will be used as default directory for the collections, which
@@ -605,12 +646,19 @@
-
+
- Interval at which statuses is to be collected from components. Value in milliseconds.
+ Interval at which statuses are to be collected from components.
+ Non-negative XML schema durations consisting of hours, minutes and/or seconds are accepted.
+ The hours may be more than 24. The seconds may have up to 9 decimals of fraction.
+
+
+
+
+
@@ -656,7 +704,7 @@
- Specifies whether the audit trail services should send alarms when contributers defined to be part of
+ Specifies whether the audit trail services should send alarms when contributors defined to be part of
the collection, doesn't reply to identify requests. Default is false.
@@ -668,32 +716,47 @@
-
+
- The amount of milliseconds to between each collecting of audit trail data from the contributors.
+ The interval between each collecting of audit trail data from the contributors.
+ Non-negative XML schema durations consisting of hours, minutes and/or seconds are accepted.
+ The hours may be more than 24. The seconds may have up to 9 decimals of fraction.
+
+
+
+
+
- The amount of milliseconds for the timertask to check whether it is time to run the collector.
+ The amount of milliseconds for the timer task to check whether it is time to run the collector.
+ Not used.
-
+
- Initial grace period in milliseconds after startup to allow the system to finish startup. The default is
- 0 ms.
+ Initial grace period after startup to allow the system to finish startup.
+ The default is 0.
+ Non-negative XML schema durations consisting of hours, minutes and/or seconds are accepted.
+ The hours may be more than 24. The seconds may have up to 9 decimals of fraction.
+
+
+
+
+
- The settings to use for audit trail preservation, eg. backup of audit trails..
+ The settings to use for audit trail preservation, e.g., backup of audit trails.
@@ -703,12 +766,22 @@
-
+
- The amount of milliseconds between each preservation of audit trails.
+ The interval between each preservation of audit trails.
+ Non-negative XML schema durations consisting of months, days, hours, minutes and/or seconds are accepted.
+ The seconds may have up to 9 decimals of fraction.
+ For example P2M (2 months), PT3M (3 minutes), P1DT1H22M22.5S (1 day 1 hour 22 minutes 22.5 seconds).
+ Months and days will be converted to time using heuristic average lengths
+ (24 hours for a day; between 30 and 31 days for a month).
+
+
+
+
+
@@ -744,21 +817,29 @@
-
+
- Initial grace period in milliseconds after startup to allow the system to finish startup.
- The default is 0 ms.
-
-
+ Not used (only the like-named setting in AuditTrailServiceSettings is).
+ Initial grace period after startup to allow the system to finish startup.
+ The default is 0.
+ Non-negative XML schema durations consisting of hours, minutes and/or seconds are accepted.
+ The hours may be more than 24. The seconds may have up to 9 decimals of fraction.
+
+
+
+
+
+
+
Control how the integrity service should behave in case of a contributor failing to deliver
FileIDs or Checksum data.
- If set to true, stop the integrity check and send an alarm, if false, continue the check on
- a incomplete set of data, and alert by sending an alarm.
+ If set to true, stop the integrity check and send an alarm. If false, continue the check on
+ an incomplete set of data, and alert by sending an alarm.
The service defaults to true.
@@ -778,12 +859,19 @@
-
+
- The number of milliseconds a file has to be known by the system before it is set to missing.
+ The time a file has to be known by the system before it is set to missing.
+ Non-negative XML schema durations consisting of hours, minutes and/or seconds are accepted.
+ The hours may be more than 24. The seconds may have up to 9 decimals of fraction.
+
+
+
+
+
@@ -803,8 +891,9 @@
- The directory where to write and store integrity reports. Directory must exists, and be read- and writable
- E.g. /home/webservices/var/integrity-reports/
+ The directory where to write and store integrity reports.
+ The directory must exist and be readable and writable.
+ E.g., /home/webservices/var/integrity-reports/
@@ -867,14 +956,23 @@
Defines a specific workflow.
-
+
- The time in milliseconds between the workflow is run.
- If it is a non-positive number, then the workflow will not be scheduled, but it will be possible to run manually from the UI.
- Also workflows with a positive interval will be run at start-up, whereas workflows with a non-positive interval will not.
-
-
+ The time between the workflow is run.
+ A duration longer than 0 will cause the workflow to run at startup and then at the specified interval.
+ If the duration is effectively zero or negative (e.g., P0D, PT0S or -PT1S),
+ then the workflow will not be scheduled, but it will be possible to run it manually from the UI.
+ The seconds of the duration may have up to 9 decimals of fraction.
+ Years, months and days will be converted to time using heuristic average lengths
+ (24 hours for a day; between 30 and 31 days for a month).
+
+
+
+
+
+
+
@@ -906,13 +1004,21 @@
-
+
- The default MaxChecksumAge to use for pillars. Can be overridden by pillar specific settings. If undefined
- 1 year is used.
+ The default MaxChecksumAge to use for pillars. Can be overridden by pillar specific settings.
+ Non-negative XML schema durations are accepted. The seconds may have up to 9 decimals of fraction.
+ Years, months and days will be converted to time using heuristic average lengths
+ (24 hours for a day; between 30 and 31 days for a month).
+ If undefined, 1 year is used, P1Y.
+
+
+
+
+
@@ -933,14 +1039,22 @@
-
+
- The max checksum age for the pillar.
- If set to 0, then the pillar is ignored for obsolete checksums check, e.g. for ChecksumPillars
- who cannot recalculate the checksum.
+ The maximum checksum age for the pillar.
+ If set to 0 (e.g., P0Y or PT0S), then the pillar is ignored for obsolete checksums check effectively
+ causing checksums not to expire; e.g., for ChecksumPillars, which cannot recalculate the checksum.
+ Non-negative XML schema durations are accepted. The seconds may have up to 9 decimals of fraction.
+ Years, months and days will be converted to time using heuristic average lengths
+ (24 hours for a day; between 30 and 31 days for a month).
+
+
+
+
+
@@ -1014,7 +1128,7 @@
- OPTIONAL. Setting for disallowing/allowing automigration of supported databases.
+ OPTIONAL. Setting for disallowing/allowing auto-migration of supported databases.
Defaults to true.
@@ -1022,7 +1136,7 @@
- OPTIONAL. Setting for disallowing/allowing auto creation of supported databases.
+ OPTIONAL. Setting for disallowing/allowing auto-creation of supported databases.
Defaults to true.
diff --git a/bitrepository-service/src/main/java/org/bitrepository/service/scheduler/JobScheduler.java b/bitrepository-service/src/main/java/org/bitrepository/service/scheduler/JobScheduler.java
index 80f807e91..e1936f411 100644
--- a/bitrepository-service/src/main/java/org/bitrepository/service/scheduler/JobScheduler.java
+++ b/bitrepository-service/src/main/java/org/bitrepository/service/scheduler/JobScheduler.java
@@ -35,10 +35,10 @@
*/
public interface JobScheduler {
/**
- * Adds a job for the scheduler to schedule.
+ * If interval is > 0, adds a job for the scheduler to schedule.
*
* @param job The job to schedule.
- * @param interval The interval for how often the job should be triggered.
+ * @param interval The interval in milliseconds for how often the job should be triggered; 0 or negative if never.
*/
void schedule(SchedulableJob job, Long interval);
diff --git a/bitrepository-service/src/main/java/org/bitrepository/service/workflow/WorkflowManager.java b/bitrepository-service/src/main/java/org/bitrepository/service/workflow/WorkflowManager.java
index cd36c0188..ac0b688d6 100644
--- a/bitrepository-service/src/main/java/org/bitrepository/service/workflow/WorkflowManager.java
+++ b/bitrepository-service/src/main/java/org/bitrepository/service/workflow/WorkflowManager.java
@@ -23,6 +23,7 @@
package org.bitrepository.service.workflow;
import org.bitrepository.common.utils.SettingsUtils;
+import org.bitrepository.common.utils.XmlUtils;
import org.bitrepository.service.scheduler.JobEventListener;
import org.bitrepository.service.scheduler.JobScheduler;
import org.bitrepository.settings.referencesettings.Schedule;
@@ -31,6 +32,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.xml.datatype.Duration;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
@@ -101,7 +103,7 @@ public Date getNextScheduledRun(JobID jobID) {
public long getRunInterval(JobID jobID) {
long interval = scheduler.getRunInterval(jobID);
- if (interval == -1) {
+ if (interval < 0) {
if (workflows.containsKey(jobID)) { // Unscheduled job
return -1;
} else {
@@ -124,17 +126,19 @@ private void loadWorkFlows(WorkflowSettings configuration) {
} else {
collectionsToScheduleWorkflowFor = SettingsUtils.getAllCollectionsIDs();
}
+ Duration workflowInterval = schedule.getWorkflowInterval();
+ long workflowIntervalMillis = XmlUtils.xmlDurationToMilliseconds(workflowInterval);
for (String collectionID : collectionsToScheduleWorkflowFor) {
Workflow workflow =
(Workflow) lookupClass(workflowConf.getWorkflowClass()).getDeclaredConstructor().newInstance();
workflow.initialise(context, collectionID);
- scheduler.schedule(workflow, schedule.getWorkflowInterval());
+ scheduler.schedule(workflow, workflowIntervalMillis);
addWorkflow(collectionID, workflow);
unscheduledCollections.remove(collectionID);
}
}
}
- // Create a instance of all workflows not explicitly scheduled.
+ // Create an instance of all workflows not explicitly scheduled.
for (String collectionID : unscheduledCollections) {
Workflow workflow =
(Workflow) Class.forName(workflowConf.getWorkflowClass()).getDeclaredConstructor().newInstance();