Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dm-docs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hammonds
dm-docs
Commits
9fa4c3d0
Commit
9fa4c3d0
authored
9 years ago
by
sveseli
Browse files
Options
Downloads
Patches
Plain Diff
added rsync plugin with checksums before/after transfer, and file deletion after transfer
parent
a7d186ee
No related branches found
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/python/dm/daq_web_service/service/impl/rsyncWithChecksumAndDeleteFileTransferPlugin.py
+64
-0
64 additions, 0 deletions
...vice/impl/rsyncWithChecksumAndDeleteFileTransferPlugin.py
with
64 additions
and
0 deletions
src/python/dm/daq_web_service/service/impl/rsyncWithChecksumAndDeleteFileTransferPlugin.py
0 → 100755
+
64
−
0
View file @
9fa4c3d0
#!/usr/bin/env python
import
os
from
dm.common.utility.loggingManager
import
LoggingManager
from
dm.common.utility.osUtility
import
OsUtility
from
dm.common.utility.fileUtility
import
FileUtility
from
dm.common.exceptions.fileProcessingError
import
FileProcessingError
from
dm.common.processing.plugins.fileTransferPlugin
import
FileTransferPlugin
from
dm.ds_web_service.api.dsRestApiFactory
import
DsRestApiFactory
class
RsyncWithChecksumAndDeleteFileTransferPlugin
(
FileTransferPlugin
):
COMMAND
=
'
rsync -arvlPR
'
def
__init__
(
self
,
src
=
None
,
dest
=
None
):
FileTransferPlugin
.
__init__
(
self
,
self
.
COMMAND
,
src
,
dest
)
self
.
dsFileApi
=
DsRestApiFactory
.
getFileRestApi
()
self
.
logger
=
LoggingManager
.
getInstance
().
getLogger
(
self
.
__class__
.
__name__
)
def
processFile
(
self
,
fileInfo
):
filePath
=
fileInfo
.
get
(
'
filePath
'
)
dataDirectory
=
fileInfo
.
get
(
'
dataDirectory
'
)
experiment
=
fileInfo
.
get
(
'
experiment
'
)
experimentName
=
experiment
.
get
(
'
name
'
)
experimentFilePath
=
fileInfo
.
get
(
'
experimentFilePath
'
)
storageHost
=
experiment
.
get
(
'
storageHost
'
)
storageDirectory
=
experiment
.
get
(
'
storageDirectory
'
)
destUrl
=
self
.
getDestUrl
(
storageHost
,
storageDirectory
)
# Use relative path with respect to data directory as a source
os
.
chdir
(
dataDirectory
)
srcUrl
=
self
.
getSrcUrl
(
filePath
,
dataDirectory
)
# Calculate checksum
FileUtility
.
statFile
(
filePath
,
fileInfo
)
FileUtility
.
getMd5Sum
(
filePath
,
fileInfo
)
self
.
logger
.
debug
(
'
File info before transfer: %s
'
%
fileInfo
)
# Transfer file
self
.
start
(
srcUrl
,
destUrl
)
# Get remote checksum
fileInfo2
=
{}
fileInfo2
[
'
experimentFilePath
'
]
=
experimentFilePath
fileInfo2
[
'
experimentName
'
]
=
experimentName
fileMetadata
=
self
.
dsFileApi
.
statFile
(
experimentFilePath
,
experimentName
,
fileInfo2
)
self
.
logger
.
debug
(
'
File stat after transfer: %s
'
%
fileMetadata
)
# Verify checksum
if
fileMetadata
.
get
(
'
md5Sum
'
)
!=
fileInfo
.
get
(
'
md5Sum
'
):
self
.
logger
.
error
(
'
Checksum mismatch for file: %s
'
%
filePath
)
raise
FileProcessingError
(
'
Checksum mismatch detected for file: %s
'
%
filePath
)
# Remove file
self
.
logger
.
debug
(
'
Checksum test passed, deleting file %s
'
%
filePath
)
OsUtility
.
removeFile
(
srcUrl
)
#######################################################################
# Testing.
if
__name__
==
'
__main__
'
:
ft
=
RsyncWithChecksumAndDeleteFileTransferPlugin
(
'
/tmp/xyz
'
,
'
/tmp/xyz2
'
)
ft
.
start
()
print
'
StdOut:
'
,
ft
.
getStdOut
()
print
'
StdErr:
'
,
ft
.
getStdErr
()
print
'
Exit Status:
'
,
ft
.
getExitStatus
()
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