Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
StoragePlugin4Rosetta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Preservation
StoragePlugin4Rosetta
Commits
dc7d7a83
Commit
dc7d7a83
authored
2 years ago
by
Andreas Romeyke
Browse files
Options
Downloads
Patches
Plain Diff
- refactoring, removed relative file handling
parent
9e625213
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java
+33
-43
33 additions, 43 deletions
.../dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java
with
33 additions
and
43 deletions
java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java
+
33
−
43
View file @
dc7d7a83
...
...
@@ -108,14 +108,9 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
}
return
"(unknown) Bytes/s"
;
}
public
boolean
checkFixity
(
List
<
Fixity
>
fixities
,
String
storedEntityIdentifier
)
throws
Exception
{
log
.
info
(
"SLUBStoragePlugin.checkFixity()"
);
/* todo: only absolute paths */
return
checkFixity
(
fixities
,
storedEntityIdentifier
,
true
);
}
public
boolean
checkFixity
(
List
<
Fixity
>
fixities
,
String
storedEntityIdentifier
,
boolean
isRelativePath
)
throws
Exception
{
log
.
info
(
"SLUBStoragePlugin.checkFixity() storedEntityIdentifier='"
+
storedEntityIdentifier
+
"'
isRelativePath="
+
isRelativePath
);
public
boolean
checkFixity
(
List
<
Fixity
>
fixities
,
String
absolute_
storedEntityIdentifier
)
throws
Exception
{
log
.
info
(
"SLUBStoragePlugin.checkFixity() storedEntityIdentifier='"
+
absolute_
storedEntityIdentifier
+
"'
"
);
// log.info("SLUBStoragePlugin.checkFixity() all fixities=" + fixities);
if
(
fixities
==
null
)
{
log
.
warn
(
"No fixity list provided"
);
...
...
@@ -124,12 +119,12 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
boolean
result
=
true
;
for
(
Fixity
fixity
:
fixities
)
{
fixity
.
setResult
(
Boolean
.
FALSE
);
result
&=
checkSpecificFixity
(
storedEntityIdentifier
,
isRelativePath
,
fixity
);
result
&=
checkSpecificFixity
(
absolute_
storedEntityIdentifier
,
fixity
);
}
return
result
;
}
private
boolean
checkSpecificFixity
(
String
storedEntityIdentifier
,
boolean
isRelativePath
,
Fixity
fixity
)
throws
Exception
{
private
boolean
checkSpecificFixity
(
String
absolute_
storedEntityIdentifier
,
Fixity
fixity
)
throws
Exception
{
String
algorithm
=
fixity
.
getAlgorithm
();
/* HINT: in past versions of Rosetta was a workaround for fixity.getAlgorithm() required,
a lowercase string was returned instead of the correct fixity code table entry */
...
...
@@ -142,17 +137,16 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
(!
Fixity
.
FixityAlgorithm
.
SHA256
.
toString
().
equals
(
algorithm
))
&&
(!
Fixity
.
FixityAlgorithm
.
CRC32
.
toString
().
equals
(
algorithm
))
)
{
// log.info("SLUBStoragePlugin.checkFixity() call checkFixityByPlugin (" + fixity + "," + storedEntityIdentifier +
"," + isRelativePath +
")");
return
checkFixityByPlugin
(
fixity
,
storedEntityIdentifier
,
isRelativePath
);
// log.info("SLUBStoragePlugin.checkFixity() call checkFixityByPlugin (" + fixity + "," + storedEntityIdentifier + ")");
return
checkFixityByPlugin
(
fixity
,
absolute_
storedEntityIdentifier
);
}
else
{
log
.
info
(
"SLUBStoragePlugin.checkFixity() calcMD5|calcSHA1|calcCRC32|calcSHA256=true"
);
int
checksummerAlgorithmIndex
=
getChecksummerAlgorithmIndex
(
algorithm
);
log
.
info
(
"SLUBStoragePlugin.checkFixity() checksummerAlgorithmIndex="
+
checksummerAlgorithmIndex
);
if
(
checksummerAlgorithmIndex
!=
-
1
)
{
return
checkFixityByBuiltin
(
fixity
,
storedEntityIdentifier
,
isRelativePath
,
algorithm
);
return
checkFixityByBuiltin
(
fixity
,
absolute_
storedEntityIdentifier
,
algorithm
);
}
}
}
catch
(
IOException
e
)
{
log
.
error
(
"SLUBStoragePlugin.checkFixity(), I/O error, "
+
e
.
getMessage
());
throw
e
;
// let Rosetta know something broke, creates technical issue in workbench
...
...
@@ -169,19 +163,18 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
/** uses a checksummer object and check if fixity of given builtin algorithm is correct
*
* @param fixity concrete fixity object
* @param storedEntityIdentifier ROsetta identifier
* @param isRelativePath RelativePath
* @param absolute_storedEntityIdentifier ROsetta identifier
* @param algorithm which algorithm should be used
* @return result
* @throws NoSuchAlgorithmException if algorithm is unknown
* @throws IOException if I/O error
*/
private
boolean
checkFixityByBuiltin
(
Fixity
fixity
,
String
storedEntityIdentifier
,
boolean
isRelativePath
,
String
algorithm
)
throws
NoSuchAlgorithmException
,
IOException
{
private
boolean
checkFixityByBuiltin
(
Fixity
fixity
,
String
absolute_
storedEntityIdentifier
,
String
algorithm
)
throws
NoSuchAlgorithmException
,
IOException
{
String
oldValue
=
fixity
.
getValue
();
log
.
info
(
"SLUBStoragePlugin.checkFixity() getAlgorithm (2)="
+
algorithm
);
log
.
info
(
"SLUBStoragePlugin.checkFixity() oldvalue="
+
oldValue
);
long
starttime
=
System
.
currentTimeMillis
();
InputStream
is
=
retrieveEntity
(
storedEntityIdentifier
,
isRelativePath
);
InputStream
is
=
retrieveEntity
(
absolute_
storedEntityIdentifier
);
Checksummer
checksummer
=
new
Checksummer
(
is
,
true
,
true
,
true
,
true
);
fixity
.
setValue
(
checksummer
.
getChecksum
(
algorithm
));
log
.
info
(
"SLUBStoragePlugin.checkFixity() newvalue="
+
fixity
.
getValue
());
...
...
@@ -189,7 +182,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
boolean
result
=
fixity
.
getResult
();
is
.
close
();
long
endtime
=
System
.
currentTimeMillis
();
var
pathname
=
(
isRelativePath
?
getDirRoot
()
:
""
)
+
storedEntityIdentifier
;
var
pathname
=
absolute_
storedEntityIdentifier
;
log
.
info
(
"SLUBStoragePlugin.checkFixity() pathname='"
+
pathname
+
"' result="
+
result
+
" (builtin "
+
throughput
(
starttime
,
endtime
,
pathname
)+
")"
);
return
result
;
}
...
...
@@ -197,12 +190,11 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
/** check fixity by calling its registered plugin
*
* @param fixity concrete fixity object
* @param storedEntityIdentifier path to file which should be checked
* @param isRelativePath indicates if path is relative
* @param absolute_storedEntityIdentifier path to file which should be checked
* @return result
* @throws Exception to inform rosetta
*/
private
boolean
checkFixityByPlugin
(
Fixity
fixity
,
String
storedEntityIdentifier
,
boolean
isRelativePath
)
throws
Exception
{
private
boolean
checkFixityByPlugin
(
Fixity
fixity
,
String
absolute_
storedEntityIdentifier
)
throws
Exception
{
log
.
info
(
"SLUBStoragePlugin.checkFixityByPlugin() another fixity"
);
String
pluginname
=
fixity
.
getPluginName
();
log
.
info
(
"SLUBStoragePlugin.checkFixityByPlugin() pluginname="
+
pluginname
);
...
...
@@ -222,7 +214,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
String
oldValue
=
fixity
.
getValue
();
log
.
info
(
"SLUBStoragePlugin.checkFixityByPlugin() oldvalue="
+
oldValue
);
long
starttime
=
System
.
currentTimeMillis
();
fixity
.
setValue
(
getChecksumUsingPlugin
(
isRelativePath
?
getLocalFilePath
(
storedEntityIdentifier
)
:
storedEntityIdentifier
,
pluginname
,
oldValue
));
fixity
.
setValue
(
getChecksumUsingPlugin
(
absolute_
storedEntityIdentifier
,
pluginname
,
oldValue
));
/* 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)
*/
...
...
@@ -230,15 +222,16 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
log
.
info
(
"SLUBStoragePlugin.checkFixityByPlugin() newvalue="
+
fixity
.
getValue
());
boolean
result
=
fixity
.
getResult
();
long
endtime
=
System
.
currentTimeMillis
();
var
pathname
=
(
isRelativePath
?
getDirRoot
()
:
""
)
+
storedEntityIdentifier
;
var
pathname
=
absolute_
storedEntityIdentifier
;
log
.
info
(
"SLUBStoragePlugin.checkFixityByPlugin() pathname='"
+
pathname
+
"' result="
+
result
+
" (plugins "
+
throughput
(
starttime
,
endtime
,
pathname
)+
")"
);
return
result
;
}
public
boolean
deleteEntity
(
String
storedEntityIdentifier
)
public
boolean
deleteEntity
(
String
relative_
storedEntityIdentifier
)
{
log
.
info
(
"SLUBStoragePlugin.deleteEntity() storedEntityIdentifier='"
+
storedEntityIdentifier
+
"'"
);
File
file
=
new
File
(
getDirRoot
()
+
storedEntityIdentifier
);
log
.
info
(
"SLUBStoragePlugin.deleteEntity() storedEntityIdentifier='"
+
relative_storedEntityIdentifier
+
"'"
);
var
absolute_filename
=
getFullFilePath
(
relative_storedEntityIdentifier
);
File
file
=
new
File
(
absolute_filename
);
try
{
return
file
.
delete
();
...
...
@@ -266,22 +259,19 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
throws
IOException
{
log
.
info
(
"SLUBStoragePlugin.retrieveEntity() with '"
+
storedEntityIdentifier
+
"'"
);
return
retrieveEntity
(
storedEntityIdentifier
,
true
);
}
public
InputStream
retrieveEntity
(
String
storedEntityIdentifier
,
boolean
isRelative
)
throws
IOException
{
log
.
info
(
"SLUBStoragePlugin.retrieveEntity() with '"
+
storedEntityIdentifier
+
"' isrelative="
+
isRelative
);
var
pathname
=
(
isRelative
?
getDirRoot
()
:
""
)
+
storedEntityIdentifier
;
// TODO: 64k (1MB) buffer set
// 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
)),
getBlockSize
());
var
absolute_filename
=
getFullFilePath
(
storedEntityIdentifier
);
var
absolute_path
=
Paths
.
get
(
absolute_filename
);
var
is
=
java
.
nio
.
file
.
Files
.
newInputStream
(
absolute_path
);
return
new
BufferedInputStream
(
is
,
getBlockSize
());
}
public
byte
[]
retrieveEntityByRange
(
String
storedEntityIdentifier
,
long
start
,
long
end
)
throws
Exception
{
log
.
info
(
"SLUBStoragePlugin.retrieveEntitybyRange() with '"
+
storedEntityIdentifier
+
"' start="
+
start
+
" end="
+
end
);
/* try-with-ressource block, no close if failed needed */
try
(
RandomAccessFile
file
=
new
RandomAccessFile
(
getDirRoot
()
+
storedEntityIdentifier
,
"r"
))
var
absolute_filename
=
getFullFilePath
(
storedEntityIdentifier
);
try
(
RandomAccessFile
file
=
new
RandomAccessFile
(
absolute_filename
,
"r"
))
{
long
starttime
=
System
.
currentTimeMillis
();
file
.
seek
(
start
);
...
...
@@ -317,24 +307,25 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
if
(
existsDescPath
!=
null
)
{
destFilePath
=
existsDescPath
;
isCopyFileNeeded
=
!
checkFixity
(
storedEntityMetadata
.
getFixities
(),
destFilePath
,
false
);
/* destFilePath is relative, checkfixity expects absolute */
isCopyFileNeeded
=
!
checkFixity
(
storedEntityMetadata
.
getFixities
(),
getFullFilePath
(
destFilePath
));
}
log
.
debug
(
"SLUBStoragePlugin.storeEntity() destFilePath='"
+
destFilePath
+
"'"
);
Map
<
String
,
String
>
paths
=
getStoreEntityIdentifier
(
storedEntityMetadata
,
destFilePath
);
String
storedEntityIdentifier
=
paths
.
get
(
"relativeDirectoryPath"
);
log
.
debug
(
"SLUBStoragePlugin.storeEntity() storedEntityIdentifier='"
+
storedEntityIdentifier
+
"'"
);
destFilePath
=
paths
.
get
(
"destFilePath"
);
log
.
debug
(
"SLUBStoragePlugin.storeEntity() destFilePath (2)='"
+
destFilePath
+
"'"
);
String
absolute_
destFilePath
=
paths
.
get
(
"destFilePath"
);
log
.
debug
(
"SLUBStoragePlugin.storeEntity() destFilePath (2)='"
+
absolute_
destFilePath
+
"'"
);
log
.
debug
(
"SLUBStoragePlugin.storeEntity() isCopyFileNeeded='"
+
isCopyFileNeeded
+
"'"
);
if
(
isCopyFileNeeded
)
{
if
(
canHandleSourcePath
(
storedEntityMetadata
.
getCurrentFilePath
()))
{
log
.
debug
(
"SLUBStoragePlugin.storeEntity() destFilePath canhandle sourcepath"
);
log
.
debug
(
"SLUBStoragePlugin.storeEntity()
absolute_
destFilePath canhandle sourcepath"
);
if
(
is
!=
null
)
{
is
.
close
();
}
copyStream
(
storedEntityMetadata
,
destFilePath
);
copyStream
(
storedEntityMetadata
,
absolute_
destFilePath
);
log
.
info
(
"SLUBStoragePlugin.storeEntity() try copy (copyStream) was successfull"
);
}
else
...
...
@@ -345,12 +336,12 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
log
.
warn
(
"SLUBStoragePlugin.storeEntity() InputStream is null"
);
return
null
;
}
try
(
OutputStream
output
=
java
.
nio
.
file
.
Files
.
newOutputStream
(
Paths
.
get
(
destFilePath
)))
try
(
OutputStream
output
=
java
.
nio
.
file
.
Files
.
newOutputStream
(
Paths
.
get
(
absolute_
destFilePath
)))
{
long
starttime
=
System
.
currentTimeMillis
();
IOUtil
.
copy
(
is
,
output
,
getBlockSize
());
long
endtime
=
System
.
currentTimeMillis
();
log
.
info
(
"SLUBStoragePlugin.storeEntity() try copy (IOUtil.copy) was successfull ("
+
throughput
(
starttime
,
endtime
,
destFilePath
)+
")"
);
log
.
info
(
"SLUBStoragePlugin.storeEntity() try copy (IOUtil.copy) was successfull ("
+
throughput
(
starttime
,
endtime
,
absolute_
destFilePath
)+
")"
);
}
}
if
(!
checkFixity
(
storedEntityMetadata
.
getFixities
(),
storedEntityIdentifier
))
{
...
...
@@ -483,7 +474,6 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
// paths.put("relativeDirectoryPath", (relativeDirectoryPath + getNextDir(destFilePath) + File.separator + fileName));
paths
.
put
(
"relativeDirectoryPath"
,
(
relativeDirectoryPath
+
File
.
separator
+
fileName
));
return
paths
;
}
/** copied from NFS Storage Plugin, enhanced with debugging info,
* this combines full file path and creates parent directories if needed {@inheritDoc}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment