Skip to content
Snippets Groups Projects
Commit d0c8abb9 authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- added new defaults

- added init() to correct input parameters
- added throughput() functions
- use BufferedInputStream in retrieveEntity() to (hopefully) increase throughput
parent 367ff25d
No related branches found
No related tags found
No related merge requests found
...@@ -33,12 +33,14 @@ import com.exlibris.digitool.common.dnx.DnxSectionRecord; ...@@ -33,12 +33,14 @@ import com.exlibris.digitool.common.dnx.DnxSectionRecord;
import com.exlibris.digitool.common.storage.Fixity; import com.exlibris.digitool.common.storage.Fixity;
import com.exlibris.digitool.infrastructure.utils.Checksummer; import com.exlibris.digitool.infrastructure.utils.Checksummer;
import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -46,7 +48,6 @@ import java.util.ArrayList; ...@@ -46,7 +48,6 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -72,13 +73,43 @@ import java.util.Map; ...@@ -72,13 +73,43 @@ import java.util.Map;
*/ */
public class SLUBStoragePlugin extends AbstractStorageHandler { public class SLUBStoragePlugin extends AbstractStorageHandler {
private static final ExLogger log = ExLogger.getExLogger(SLUBStoragePlugin.class); private static final ExLogger log = ExLogger.getExLogger(SLUBStoragePlugin.class);
private static final String DIR_ROOT = "DIR_ROOT"; /** {@inheritDoc} */ private static String DIR_ROOT = "DIR_ROOT"; /** {@inheritDoc} */
private static final int default_buffer = 32*1024; private static String FILES_HANDLING_METHOD = "move";
private static int BLOCK_SIZE = 32*1024;
public SLUBStoragePlugin() { public SLUBStoragePlugin() {}
log.info("SLUBStoragePlugin instantiated");
@Override
public void init(Map<String, String> params) {
super.init(params);
DIR_ROOT = parameters.get("DIR_ROOT");
try {
BLOCK_SIZE = Integer.parseInt(this.parameters.get("BLOCK_SIZE"));
} catch (NumberFormatException e) {
log.error("Could not convert BLOCK_SIZE string to int, " + e);
BLOCK_SIZE = 32*1024;
}
FILES_HANDLING_METHOD = this.parameters.get("FILES_HANDLING_METHOD");
log.info("SLUBStoragePlugin instantiated (using DIR_ROOT="+DIR_ROOT+" BLOCK_SIZE="+BLOCK_SIZE);
} }
private String throughput(long start, long end, String filename) {
try {
long fsize = Files.size(Paths.get(filename));
if (fsize > 0) {
return ((end - start) / fsize) + " Bytes/s";
}
} catch (IOException e) {
/* do nothing */
}
return "(unknown) Bytes/s";
}
private String throughput(long start, long end, long fsize) {
if (fsize > 0) {
return ((end-start)/fsize) + " Bytes/s";
}
return "(unknown) Bytes/s";
}
public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier) throws Exception { public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier) throws Exception {
log.info("SLUBStoragePlugin.checkFixity()"); log.info("SLUBStoragePlugin.checkFixity()");
return checkFixity(fixities, storedEntityIdentifier, true); return checkFixity(fixities, storedEntityIdentifier, true);
...@@ -150,14 +181,17 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -150,14 +181,17 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
String oldValue = fixity.getValue(); String oldValue = fixity.getValue();
log.info("SLUBStoragePlugin.checkFixity() getAlgorithm (2)=" + algorithm); log.info("SLUBStoragePlugin.checkFixity() getAlgorithm (2)=" + algorithm);
log.info("SLUBStoragePlugin.checkFixity() oldvalue=" + oldValue); log.info("SLUBStoragePlugin.checkFixity() oldvalue=" + oldValue);
long starttime = System.currentTimeMillis();
InputStream is = retrieveEntity(storedEntityIdentifier, isRelativePath); InputStream is = retrieveEntity(storedEntityIdentifier, isRelativePath);
Checksummer checksummer = new Checksummer(is, true, true, true, true); Checksummer checksummer = new Checksummer(is, true, true, true, true);
fixity.setValue(checksummer.getChecksum(algorithm)); fixity.setValue(checksummer.getChecksum(algorithm));
log.info("SLUBStoragePlugin.checkFixity() newvalue=" + fixity.getValue()); log.info("SLUBStoragePlugin.checkFixity() newvalue=" + fixity.getValue());
fixity.setResult((oldValue == null) || (oldValue.equalsIgnoreCase(fixity.getValue()))); fixity.setResult((oldValue == null) || (oldValue.equalsIgnoreCase(fixity.getValue())));
boolean result = fixity.getResult(); boolean result = fixity.getResult();
log.info("SLUBStoragePlugin.checkFixity() result=" + result);
is.close(); is.close();
long endtime = System.currentTimeMillis();
var pathname = (isRelativePath ? DIR_ROOT : "") + storedEntityIdentifier;
log.info("SLUBStoragePlugin.checkFixity() result=" + result + " (builtin " + throughput(starttime, endtime, pathname)+ ")");
return result; return result;
} }
...@@ -188,6 +222,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -188,6 +222,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
} }
String oldValue = fixity.getValue(); String oldValue = fixity.getValue();
log.info("SLUBStoragePlugin.checkFixityByPlugin() oldvalue=" + oldValue); log.info("SLUBStoragePlugin.checkFixityByPlugin() oldvalue=" + oldValue);
long starttime = System.currentTimeMillis();
fixity.setValue(getChecksumUsingPlugin(isRelativePath ? getLocalFilePath(storedEntityIdentifier) : storedEntityIdentifier, pluginname, oldValue)); fixity.setValue(getChecksumUsingPlugin(isRelativePath ? getLocalFilePath(storedEntityIdentifier) : storedEntityIdentifier, pluginname, oldValue));
/* HINT: if plugin name is still empty a java.lang.NullPointerException gets thrown /* HINT: if plugin name is still empty a java.lang.NullPointerException gets thrown
Rosetta will handle it and let us know (creates technical issue in workbench) Rosetta will handle it and let us know (creates technical issue in workbench)
...@@ -195,14 +230,16 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -195,14 +230,16 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
fixity.setResult((oldValue == null) || (oldValue.equals(fixity.getValue()))); fixity.setResult((oldValue == null) || (oldValue.equals(fixity.getValue())));
log.info("SLUBStoragePlugin.checkFixityByPlugin() newvalue=" + fixity.getValue()); log.info("SLUBStoragePlugin.checkFixityByPlugin() newvalue=" + fixity.getValue());
boolean result = fixity.getResult(); boolean result = fixity.getResult();
log.info("SLUBStoragePlugin.checkFixityByPlugin() result=" + result); long endtime = System.currentTimeMillis();
var pathname = (isRelativePath ? DIR_ROOT : "") + storedEntityIdentifier;
log.info("SLUBStoragePlugin.checkFixityByPlugin() result=" + result + " (plugins " + throughput(starttime, endtime, pathname)+ ")");
return result; return result;
} }
public boolean deleteEntity(String storedEntityIdentifier) public boolean deleteEntity(String storedEntityIdentifier)
{ {
log.info("SLUBStoragePlugin.deleteEntity() storedEntityIdentifier='" + storedEntityIdentifier + "'"); log.info("SLUBStoragePlugin.deleteEntity() storedEntityIdentifier='" + storedEntityIdentifier + "'");
File file = new File(this.parameters.get("DIR_ROOT") + storedEntityIdentifier); File file = new File(DIR_ROOT + storedEntityIdentifier);
try try
{ {
return file.delete(); return file.delete();
...@@ -223,7 +260,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -223,7 +260,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
public String getFullFilePath(String storedEntityIdentifier) public String getFullFilePath(String storedEntityIdentifier)
{ {
log.info("SLUBStoragePlugin.getFullFilePath() with '" + storedEntityIdentifier + "'"); log.info("SLUBStoragePlugin.getFullFilePath() with '" + storedEntityIdentifier + "'");
return this.parameters.get("DIR_ROOT") + storedEntityIdentifier; return DIR_ROOT + storedEntityIdentifier;
} }
public InputStream retrieveEntity(String storedEntityIdentifier) public InputStream retrieveEntity(String storedEntityIdentifier)
...@@ -236,19 +273,23 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -236,19 +273,23 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
throws IOException throws IOException
{ {
log.info("SLUBStoragePlugin.retrieveEntity() with '" + storedEntityIdentifier + "' isrelative=" + isRelative); log.info("SLUBStoragePlugin.retrieveEntity() with '" + storedEntityIdentifier + "' isrelative=" + isRelative);
var pathname = (isRelative ? this.parameters.get("DIR_ROOT") : "") + storedEntityIdentifier; var pathname = (isRelative ? DIR_ROOT : "") + storedEntityIdentifier;
// TODO: 64k (1MB) buffer set
return java.nio.file.Files.newInputStream( Paths.get( pathname)); // OLD, without buffering, but working: InputStream foo = java.nio.file.Files.newInputStream( Paths.get( pathname));
return new BufferedInputStream( java.nio.file.Files.newInputStream(Paths.get( pathname)), BLOCK_SIZE);
} }
public byte[] retrieveEntityByRange(String storedEntityIdentifier, long start, long end) throws Exception public byte[] retrieveEntityByRange(String storedEntityIdentifier, long start, long end) throws Exception
{ {
log.info("SLUBStoragePlugin.retrieveEntitybyRange() with '" + storedEntityIdentifier + "' start=" + start + " end=" + end); log.info("SLUBStoragePlugin.retrieveEntitybyRange() with '" + storedEntityIdentifier + "' start=" + start + " end=" + end);
/* try-with-ressource block, no close if failed needed */ /* try-with-ressource block, no close if failed needed */
try (RandomAccessFile file = new RandomAccessFile(this.parameters.get("DIR_ROOT") + storedEntityIdentifier, "r")) try (RandomAccessFile file = new RandomAccessFile(DIR_ROOT + storedEntityIdentifier, "r"))
{ {
long starttime = System.currentTimeMillis();
file.seek(start); file.seek(start);
byte[] bytes = new byte[(int)(end - start + 1L)]; byte[] bytes = new byte[(int)(end - start + 1L)];
file.readFully(bytes, 0, (int)(end - start + 1L)); file.readFully(bytes, 0, (int)(end - start + 1L));
long endtime = System.currentTimeMillis();
log.info("SLUBStoragePlugin.retrieveEntitybyRange() sucessfull (" + throughput(starttime, endtime, file.length())+ ")");
return bytes; return bytes;
} }
catch (FileNotFoundException e) { catch (FileNotFoundException e) {
...@@ -307,8 +348,10 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -307,8 +348,10 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
} }
try (OutputStream output = java.nio.file.Files.newOutputStream( Paths.get( destFilePath))) try (OutputStream output = java.nio.file.Files.newOutputStream( Paths.get( destFilePath)))
{ {
IOUtil.copy(is, output, default_buffer); long starttime = System.currentTimeMillis();
log.info("SLUBStoragePlugin.storeEntity() try copy (IOUtil.copy) was successfull"); IOUtil.copy(is, output, BLOCK_SIZE);
long endtime = System.currentTimeMillis();
log.info("SLUBStoragePlugin.storeEntity() try copy (IOUtil.copy) was successfull (" + throughput(starttime, endtime, destFilePath)+ ")" );
} }
} }
if (!checkFixity(storedEntityMetadata.getFixities(), storedEntityIdentifier)) { if (!checkFixity(storedEntityMetadata.getFixities(), storedEntityIdentifier)) {
...@@ -324,7 +367,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -324,7 +367,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
throws IOException throws IOException
{ {
log.info("SLUBStoragePlugin.copyStream()"); log.info("SLUBStoragePlugin.copyStream()");
String filesHandlingMethod = this.parameters.get("FILES_HANDLING_METHOD"); String filesHandlingMethod = FILES_HANDLING_METHOD;
String srcPath = storedEntityMetadata.getCurrentFilePath(); String srcPath = storedEntityMetadata.getCurrentFilePath();
log.debug("SLUBStoragePlugin.copyStream() destPath='" + destPath + "'"); log.debug("SLUBStoragePlugin.copyStream() destPath='" + destPath + "'");
log.debug("SLUBStoragePlugin.copyStream() srcPath='" + srcPath + "'"); log.debug("SLUBStoragePlugin.copyStream() srcPath='" + srcPath + "'");
...@@ -353,9 +396,12 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -353,9 +396,12 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
} }
else else
{ {
long starttime = System.currentTimeMillis();
FileUtil.copyFile(srcPath, destPath); FileUtil.copyFile(srcPath, destPath);
saveDestPathsTmpFile(iePid, pid, destPath); saveDestPathsTmpFile(iePid, pid, destPath);
log.info("SLUBStoragePlugin.copyStream(), copyFile was successful"); long endtime = System.currentTimeMillis();
log.info("SLUBStoragePlugin.copyStream(), copyFile was successful (" + throughput(starttime, endtime, srcPath) + ")");
} }
} }
protected String getFilePathInDescIfExists(StoredEntityMetaData storedEntityMetadata) protected String getFilePathInDescIfExists(StoredEntityMetaData storedEntityMetadata)
...@@ -446,7 +492,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { ...@@ -446,7 +492,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
*/ */
File getStreamDirectory(String path, String fileName) { File getStreamDirectory(String path, String fileName) {
log.info("SLUBStoragePlugin.getStreamDirectory path='" + path + "' fileName='" + fileName + "'"); log.info("SLUBStoragePlugin.getStreamDirectory path='" + path + "' fileName='" + fileName + "'");
File newDir = new File(parameters.get(DIR_ROOT) + File.separator + path); File newDir = new File(DIR_ROOT + File.separator + path);
log.debug("SLUBStoragePlugin.getStreamDirectory newDir.getAbsolutePath()=" + newDir.getAbsolutePath()); log.debug("SLUBStoragePlugin.getStreamDirectory newDir.getAbsolutePath()=" + newDir.getAbsolutePath());
boolean arecreated = newDir.mkdirs(); boolean arecreated = newDir.mkdirs();
log.debug("SLUBStoragePlugin.getStreamDirectory newDir.mkdirs(), directories are created:" + arecreated); log.debug("SLUBStoragePlugin.getStreamDirectory newDir.mkdirs(), directories are created:" + arecreated);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment