diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/SelfTest.java b/datamover/source/java/ch/systemsx/cisd/datamover/SelfTest.java index 3159930379b21373499cea42f7a11b4454939c89..b3e45e1d1b92af37922210d86436eb8fc6078a7d 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/SelfTest.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/SelfTest.java @@ -34,6 +34,8 @@ import ch.systemsx.cisd.datamover.filesystem.intf.IPathCopier; */ public class SelfTest { + private static final long TIMEOUT_MILLIS = 3000L; + private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, SelfTest.class); static @@ -48,7 +50,7 @@ public class SelfTest checkPathRecordsContainEachOther(pathRecords); for (FileStore pathRecord : pathRecords) { - String errorMessage = pathRecord.tryCheckDirectoryFullyAccessible(); + String errorMessage = pathRecord.tryCheckDirectoryFullyAccessible(TIMEOUT_MILLIS); if (errorMessage != null) { throw new ConfigurationFailureException(errorMessage); diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/intf/FileStore.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/intf/FileStore.java index 2a741df2978b02dabbb7c005bedac2d8e60669f9..610bb2ee2c18b47210b2dd81e0d58afad742639c 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/intf/FileStore.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/intf/FileStore.java @@ -165,16 +165,18 @@ public abstract class FileStore /** * Checks whether this store is a directory and is fully accessible to the program. * + * @param timeOutMillis The time (in milli-seconds) to wait for the target to become available if it is not + * initially. * @return <code>null</code> if the <var>directory</var> is fully accessible and an error message describing the * problem with the <var>directory</var> otherwise. */ - public abstract String tryCheckDirectoryFullyAccessible(); + public abstract String tryCheckDirectoryFullyAccessible(final long timeOutMillis); public abstract boolean exists(StoreItem item); /** * Returns the last time when there was a write access to <var>item</var>. - * + * * @param item The {@link StoreItem} to check. * @param stopWhenFindYounger If > 0, the recursive search for younger file will be stopped when a file or * directory is found that is as young as or younger than the time specified in this parameter. @@ -183,7 +185,7 @@ public abstract class FileStore public abstract long lastChanged(StoreItem item, long stopWhenFindYounger); /** - * List files in the scanned store. Sort in order of "oldest first". + * List files in the scanned store. Sort in order of "oldest first". */ public abstract StoreItem[] tryListSortByLastModified(ISimpleLogger loggerOrNull); diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/RemotePathMover.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/RemotePathMover.java index 120daaebb78479a2efaf2428fe4488556c12fe2a..896e6fa2f0bb36f07df268e2c270aff724c98ece 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/RemotePathMover.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/RemotePathMover.java @@ -39,6 +39,8 @@ import ch.systemsx.cisd.datamover.intf.ITimingParameters; public final class RemotePathMover implements IStoreHandler { + private static final long TIMEOUT_DESTINATION_MILLIS = 3000L; + private static final String START_COPYING_PATH_TEMPLATE = "Start copying path '%s' to '%s'."; private static final String START_COPYING_PATH_RETRY_TEMPLATE = "Start copying path '%s' to '%s' [retry: %d]."; @@ -93,8 +95,8 @@ public final class RemotePathMover implements IStoreHandler assert destinationDirectory != null; assert monitor != null; assert timingParameters != null; - String errorMsg = destinationDirectory.tryCheckDirectoryFullyAccessible(); - assert errorMsg == null : errorMsg; + String errorMsg; + assert (errorMsg = destinationDirectory.tryCheckDirectoryFullyAccessible(TIMEOUT_DESTINATION_MILLIS)) == null : errorMsg; assert sourceDirectory.tryAsExtended() != null || destinationDirectory.tryAsExtended() != null; this.sourceDirectory = sourceDirectory; @@ -137,6 +139,10 @@ public final class RemotePathMover implements IStoreHandler .format(START_COPYING_PATH_TEMPLATE, getSrcPath(item), destinationDirectory)); } } + if (checkTargetAvailable() == false) + { + return; + } final long startTime = System.currentTimeMillis(); final Status copyStatus = copyAndMonitor(item); if (StatusFlag.OK.equals(copyStatus.getFlag())) @@ -191,6 +197,17 @@ public final class RemotePathMover implements IStoreHandler markAsFinished(item); } + private boolean checkTargetAvailable() + { + final String msg = destinationDirectory.tryCheckDirectoryFullyAccessible(TIMEOUT_DESTINATION_MILLIS); + if (msg != null) + { + machineLog.error(msg); + return false; + } + return true; + } + private void remove(StoreItem sourceItem) { final StoreItem removalInProgressMarkerFile = tryMarkAsDeletionInProgress(sourceItem); diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreLocal.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreLocal.java index 29a3aa290f7df636e3517b310a745566b771d848..25a28d47d0f9e6c9bce8097480d3190943dfdccb 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreLocal.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreLocal.java @@ -72,9 +72,15 @@ public class FileStoreLocal extends ExtendedFileStore } @Override - public String tryCheckDirectoryFullyAccessible() + public String tryCheckDirectoryFullyAccessible(final long timeOutMillis) { - return FileUtilities.checkDirectoryFullyAccessible(super.getPath(), super.getDescription()); + final boolean available = FileUtilities.isAvailable(getPath(), timeOutMillis); + if (available == false) + { + return String.format("Path '%s' which is supposed to be a %s directory is not available.", getPath(), + getDescription()); + } + return FileUtilities.checkDirectoryFullyAccessible(getPath(), getDescription()); } @Override diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreRemote.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreRemote.java index 493e268862e1d37ffcdc9c8590287b270f33e2e3..89c8533bcfbf0a5e1659990f7d27cdb59f9017ff 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreRemote.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreRemote.java @@ -69,7 +69,7 @@ public class FileStoreRemote extends FileStore } @Override - public String tryCheckDirectoryFullyAccessible() + public String tryCheckDirectoryFullyAccessible(final long timeOutMillis) { // TODO 2007-10-09, Tomasz Pylak: implement ssh tunneling mode. E.g. check if directory exists return null; diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreRemoteMounted.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreRemoteMounted.java index 25476145f2a4974f4a663b95028c690fccd5fb30..5cd3e48ee160da7f5704808ab030789e80e6bbdc 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreRemoteMounted.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreRemoteMounted.java @@ -83,9 +83,9 @@ public class FileStoreRemoteMounted extends FileStore } @Override - public String tryCheckDirectoryFullyAccessible() + public String tryCheckDirectoryFullyAccessible(final long timeOutMillis) { - return localImpl.tryCheckDirectoryFullyAccessible(); + return localImpl.tryCheckDirectoryFullyAccessible(timeOutMillis); } @Override diff --git a/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java b/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java index 2581be93f0a93f3aa010040635aaf3354e5ada9b..472c7701b6f8a452139f792274e29546bde22540 100644 --- a/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java +++ b/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java @@ -167,9 +167,9 @@ public class CopyActivityMonitorTest } @Override - public String tryCheckDirectoryFullyAccessible() + public String tryCheckDirectoryFullyAccessible(long timeOutMillis) { - return localImpl.tryCheckDirectoryFullyAccessible(); + return localImpl.tryCheckDirectoryFullyAccessible(timeOutMillis); } @Override @@ -341,8 +341,7 @@ public class CopyActivityMonitorTest LogMonitoringAppender appender = LogMonitoringAppender.addAppender(LogCategory.OPERATION, "got stuck, starting a new one"); final PathLastChangedCheckerDelayed checker = - new PathLastChangedCheckerDelayed(INACTIVITY_PERIOD_MILLIS, - (long) (INACTIVITY_PERIOD_MILLIS / 10 * 1.5)); + new PathLastChangedCheckerDelayed(INACTIVITY_PERIOD_MILLIS, 0L); final MockTerminable copyProcess = new MockTerminable(); final ITimingParameters parameters = new MyTimingParameters(0); final CopyActivityMonitor monitor =