HER-1901 timestamped subdirectory for each launch

* HardLinker.java
    renamed FilesystemLinkMaker.java
* FilesystemLinkMaker.java
    add support for symbolic links
* CLibrary.java
    new method symlink()
* BdbModule.java
    use new class name FilesystemLinkMaker
* CrawlJob.java
    at crawl launch, create launch directory launch-{timestamp17}, copy cxml there, symlink "current" to launch dir, inform ConfigPaths
* ConfigPath.java
    interpolate ${launch-id} in configured paths
* ConfigFile.java
    obtainReader() - snapshot config files to launch dir when they are read
* ActionDirectory.java
    default doneDir now ${launch-id}/actions-done
    actOn() - symlink from old style done dir action/done to done files
* SurtPrefixedDecideRule.java
    default surtsDumpFile now ${launch-id}/surts.dump
    pathsFixedUp() - this gets called at build time, but we don't want anything written to disk until launch time, so remove call to dumpSurtPrefixSet() here
* CrawlerLoggerModule.java
    default logs dir now ${launch-id}/logs
* StatisticsTracker.java 
    default reports dir now ${launch-id}/reports
* WriterPoolProcessor.java
    default writer base path now ${launch-id} 
* profile-crawler-beans.cxml
    update to reflect new default paths under launch dirs
* PropertyUtils.java
    fix javadoc typo
This commit is contained in:
nlevitt committed 2011-07-13 19:18:55 +00:00
1 parent a8682ff1ff
commit 4250e07de9
13 files changed
+134 -38

No files matched your search

@@ -43,7 +43,7 @@ import org.archive.checkpointing.Checkpoint;
import org.archive.checkpointing.Checkpointable;
import org.archive.spring.ConfigPath;
import org.archive.util.CLibrary;
import org.archive.util.HardLinker;
import org.archive.util.FilesystemLinkMaker;
import org.archive.util.IdentityCacheable;
import org.archive.util.ObjectIdentityBdbManualCache;
import org.archive.util.ObjectIdentityCache;
@@ -487,7 +487,7 @@ public class BdbModule implements Lifecycle, Checkpointable, Closeable {
filedata[i] += ","+f.length();
if(getUseHardLinkCheckpoints()) {
File hardLink = new File(envCpDir,filedata[i]);
if (!HardLinker.makeHardLink(f.getAbsolutePath(), hardLink.getAbsolutePath())) {
if (!FilesystemLinkMaker.makeHardLink(f.getAbsolutePath(), hardLink.getAbsolutePath())) {
LOGGER.log(Level.SEVERE, "unable to create required checkpoint link "+hardLink);
}
}
@@ -26,6 +26,7 @@ import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import org.apache.commons.io.FileUtils;
import org.archive.io.ReadSource;
/**
@@ -48,6 +49,10 @@ public class ConfigFile extends ConfigPath implements ReadSource, WriteTarget {
if(!getFile().exists()) {
getFile().createNewFile();
}
// snapshot file to launch directory
FileUtils.copyFileToDirectory(getFile(), currentLaunchDir);
return new InputStreamReader(
new FileInputStream(getFile()),
"UTF-8");
@@ -56,9 +56,10 @@ public class ConfigPath implements Serializable {
String name;
String path;
ConfigPath base;
transient File resolved;
ConfigPath base;
transient String interpolatedPath;
transient File currentLaunchDir;
public ConfigPath() {
super();
@@ -68,6 +69,7 @@ public class ConfigPath implements Serializable {
super();
this.name = name;
this.path = path;
this.interpolatedPath = path;
}
public ConfigPath getBase() {
@@ -93,12 +95,13 @@ public class ConfigPath implements Serializable {
@Required
public void setPath(String path) {
this.path = path;
this.interpolatedPath = path;
}
public File getFile() {
return (base == null || path.startsWith("/"))
? new File(path)
: new File(base.getFile(), path);
return (base == null || interpolatedPath.startsWith("/"))
? new File(interpolatedPath)
: new File(base.getFile(), interpolatedPath);
}
/**
@@ -118,4 +121,10 @@ public class ConfigPath implements Serializable {
}
return this;
}
public void informOfLaunch(String currentLaunchId, File currentLaunchDir) {
this.currentLaunchDir = currentLaunchDir;
// could use PropertyUtils.interpolateWithProperties(String, Properties...), but no real need
interpolatedPath = path.replace("${launch-id}", currentLaunchId);
}
}
@@ -35,5 +35,6 @@ public interface CLibrary extends Library {
Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"),
CLibrary.class);
int link(String fromFile, String toFile);
int link(String existingPath, String newPath);
int symlink(String existingPath, String newPath);
}
@@ -32,7 +32,7 @@ import com.sun.jna.win32.StdCallLibrary;
*
* @see http://stackoverflow.com/questions/783075/creating-a-hard-link-in-java/3023349#3023349
*/
public class HardLinker {
public class FilesystemLinkMaker {
// see https://github.com/twall/jna/blob/master/www/GettingStarted.md
public interface Kernel32Library extends StdCallLibrary {
@@ -63,6 +63,9 @@ public class HardLinker {
*/
boolean CreateHardLinkA(String newPath, String existingPath, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
// boolean CreateHardLinkW(String newPath, String existingPath, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
// http://msdn.microsoft.com/en-us/library/aa363866%28v=VS.85%29.aspx
boolean CreateSymbolicLinkA(String newPath, String existingPath, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
}
/**
@@ -70,6 +73,7 @@ public class HardLinker {
*
* @return true on success
*/
// XXX could handle errors better (examine errno, throw exception...)
public static boolean makeHardLink(String existingPath, String newPath) {
if (Platform.isWindows()) {
return Kernel32Library.INSTANCE.CreateHardLinkA(newPath, existingPath, null);
@@ -78,17 +82,42 @@ public class HardLinker {
return status == 0;
}
}
/**
* Wrapper over platform-dependent system calls to create a symboic link.
*
* @return true on success
*/
// XXX could handle errors better (examine errno, throw exception...)
public static boolean makeSymbolicLink(String existingPath, String newPath) {
if (Platform.isWindows()) {
return Kernel32Library.INSTANCE.CreateSymbolicLinkA(newPath, existingPath, null);
} else {
int status = CLibrary.INSTANCE.symlink(existingPath, newPath);
return status == 0;
}
}
public static void main(String[] args) throws IOException {
File existingPath = File.createTempFile("heritrixHardLinkTestExistingFile", ".tmp");
File newPath = File.createTempFile("heritrixHardLinkTestNewFile", ".tmp");
newPath.delete();
if (HardLinker.makeHardLink(existingPath.getAbsolutePath(), newPath.getAbsolutePath())) {
if (FilesystemLinkMaker.makeHardLink(existingPath.getAbsolutePath(), newPath.getAbsolutePath())) {
System.out.println("success - made hard link from " + newPath.getAbsolutePath() + " to " + existingPath.getAbsolutePath());
} else {
System.out.println("failed to make hard link from " + newPath.getAbsolutePath() + " to " + existingPath.getAbsolutePath());
}
existingPath = File.createTempFile("heritrixSymlinkTestExistingFile", ".tmp");
newPath = File.createTempFile("heritrixSymlinkTestNewFile", ".tmp");
newPath.delete();
if (FilesystemLinkMaker.makeSymbolicLink(existingPath.getPath(), newPath.getPath())) {
System.out.println("success - made symlink from " + newPath.getAbsolutePath() + " to " + existingPath.getAbsolutePath());
} else {
System.out.println("failed to make symlink from " + newPath.getAbsolutePath() + " to " + existingPath.getAbsolutePath());
}
}
}
@@ -83,7 +83,7 @@ public class PropertyUtils {
* the expression is replaced with the empty-string.
*
* @param original String
* @param properties Properties to try in order; first value found (if any) is used
* @param props Properties to try in order; first value found (if any) is used
* @return modified String
*/
public static String interpolateWithProperties(String original,