Skip to content

Commit

Permalink
the batch method moves the file it gets to the tempdir allocated by s…
Browse files Browse the repository at this point in the history
…ettings
  • Loading branch information
svcarlsen committed Sep 18, 2015
1 parent ee14ebf commit 2dc044a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Expand Up @@ -108,6 +108,9 @@ public BitmagArcRepositoryClient() {
this.tempdir = Settings.getFile(BITREPOSITORY_TEMPDIR);
this.maxStoreFailures = Settings.getInt(BITREPOSITORY_STORE_MAX_PILLAR_FAILURES);
this.usepillar = Settings.get(BITREPOSITORY_USEPILLAR);
tempdir.mkdirs();
log.info("Storing tempfiles in folder {}", tempdir);

// Initialize connection to the bitrepository
this.bitrep = new Bitrepository(configDir, keyfilename, maxStoreFailures, usepillar);
}
Expand Down Expand Up @@ -234,7 +237,7 @@ public BatchStatus batch(final FileBatchJob job, String replicaId, String... arg
// Deduce the remote file to run the batchjob on from the job.getFilenamePattern()
// e.g. "22-metadata-[0-9]+.(w)?arc" => 22-metadata-1.warc
log.info("Trying to deducing requested file to run batch on from pattern {}", job.getFilenamePattern().pattern());

String patternAsString = job.getFilenamePattern().pattern();
if (!patternAsString.contains("metadata-")) {
log.warn("deducing requested file to run batch on from pattern {} failed. Is not a metadata file", job.getFilenamePattern().pattern());
Expand All @@ -244,13 +247,14 @@ public BatchStatus batch(final FileBatchJob job, String replicaId, String... arg
// nameparts will be ["22", "metadata", "[0", "9]+.(w)?arc"]
String nameParts[] = patternAsString.split("-");
String nameToFetch = nameParts[0] + "-metadata-1.warc";
List<File> files = new ArrayList<File>();

List<File> files = new ArrayList<File>();
if (!bitrep.existsInCollection(nameToFetch, collectionId)) {
log.warn("The file '{}' is not in collection '{}'.", nameToFetch, collectionId);
} else {
File workFile = bitrep.getFile(nameToFetch, this.collectionId, null);
files.add(workFile);
File tmpFile = bitrep.getFile(nameToFetch, this.collectionId, null);
File workFile = new File(tempdir, nameToFetch);
FileUtils.moveFile(tmpFile, workFile);
files.add(workFile);
}

OutputStream os = null;
Expand Down
Expand Up @@ -32,15 +32,19 @@ public static void runnerTwo(){
System.out.println("pillar " + i + ": " + pillar);
}

if (bitrep.existsInCollection("47-metadata-1.warc", "books")){
System.out.println("47-metadata-1.warc found in collection books");
if (bitrep.existsInCollection("70-metadata-1.warc", "books")){
System.out.println("70-metadata-1.warc found in collection books");
File f = bitrep.getFile("70-metadata-1.warc", "books", null);
System.out.println("file fetched = " + f.getAbsolutePath());
} else {
System.out.println("47-metadata-1.warc NOT found in collection books");
System.out.println("70-metadata-1.warc NOT found in collection books");
}
/*
System.out.println("books-ids:");
for (String id: bitrep.getFileIds("books")) {
System.out.println(id);
}
*/



Expand Down

0 comments on commit 2dc044a

Please sign in to comment.