Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Data Logistics Service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
eFlows4HPC WP2
Data Logistics Service
Commits
25367313
Commit
25367313
authored
2 years ago
by
Maria Petrova-El Sayed
Browse files
Options
Downloads
Patches
Plain Diff
Stage out docker execution results into b2share
parent
67208e62
No related branches found
Branches containing commit
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
dags/docker_in_ssh_op.py
+76
-9
76 additions, 9 deletions
dags/docker_in_ssh_op.py
with
76 additions
and
9 deletions
dags/docker_in_ssh_op.py
+
76
−
9
View file @
25367313
...
...
@@ -5,8 +5,8 @@ from airflow.models.connection import Connection
from
airflow.models
import
Variable
from
airflow.operators.python
import
get_current_context
from
b2shareoperator
import
(
download_file
,
get_file_list
,
get_object_md
,
get_objects
)
from
decors
import
get_connection
,
remove
,
setup
get_objects
,
get_record_template
,
create_draft_record
,
add_file
,
submit_draft
)
from
decors
import
get_connection
import
docker_cmd
as
doc
import
os
...
...
@@ -113,10 +113,10 @@ def docker_with_ssh():
# return loaded_files
@task
def
run_container
(
**
kwargs
):
def
run_container
(
data_locations
,
**
kwargs
):
params
=
kwargs
[
'
params
'
]
stageout_
arg
s
=
params
.
get
(
'
stageout_args
'
,
[])
stageout_
fname
s
=
params
.
get
(
'
stageout_args
'
,
[])
cmd
=
doc
.
get_dockercmd
(
params
,
DATA_LOCATION
)
print
(
f
"
Executing docker command
{
cmd
}
"
)
...
...
@@ -133,15 +133,15 @@ def docker_with_ssh():
context
=
get_current_context
()
task_calculate
.
execute
(
context
)
return
stageout_
arg
s
return
stageout_
fname
s
@task
def
postproces
s_results
(
output_files
:
list
):
def
l
s_results
(
output_files
:
list
):
if
not
output_files
:
return
"
No output to stage out. Nothing more to do.
"
hook
=
get_connection
(
conn_id
=
DW_CONNECTION_ID
)
sp
=
"
"
cmd
=
f
"
cd
{
DATA_LOCATION
}
;
cat
{
sp
.
join
(
output_files
)
}
"
cmd
=
f
"
cd
{
DATA_LOCATION
}
;
ls -al
{
sp
.
join
(
output_files
)
}
"
process
=
SSHOperator
(
task_id
=
"
print_results
"
,
ssh_hook
=
hook
,
...
...
@@ -150,14 +150,81 @@ def docker_with_ssh():
context
=
get_current_context
()
process
.
execute
(
context
)
@task
()
def
retrieve_res
(
output_fnames
:
list
,
**
kwargs
):
"""
This task copies the data from the remote location back to the host
Args:
output_fnames (list): the files that will be stored on another system
Returns:
files (list): the locations of the newly retrieved result files
"""
local_tmp_dir
=
Variable
.
get
(
"
working_dir
"
,
default_var
=
'
/tmp/
'
)
files
=
[]
print
(
f
"
Using
{
DW_CONNECTION_ID
}
connection
"
)
ssh_hook
=
get_connection
(
conn_id
=
DW_CONNECTION_ID
)
with
ssh_hook
.
get_conn
()
as
ssh_client
:
sftp_client
=
ssh_client
.
open_sftp
()
for
fname
in
output_fnames
:
local
=
os
.
path
.
join
(
local_tmp_dir
,
fname
)
print
(
f
"
Copying
{
os
.
path
.
join
(
DATA_LOCATION
,
fname
)
}
to
{
local
}
"
)
sftp_client
.
get
(
os
.
path
.
join
(
DATA_LOCATION
,
fname
),
local
)
files
.
append
(
local
)
return
files
@task
def
stageout_results
(
output_files
:
list
):
if
not
output_files
:
print
(
"
No output to stage out. Nothing more to do.
"
)
return
-
1
connection
=
Connection
.
get_connection_from_secrets
(
'
default_b2share
'
)
server
=
"
https://
"
+
connection
.
host
token
=
''
if
'
access_token
'
in
connection
.
extra_dejson
.
keys
():
token
=
connection
.
extra_dejson
[
'
access_token
'
]
print
(
f
"
Registering data to
{
server
}
"
)
template
=
get_record_template
()
r
=
create_draft_record
(
server
=
server
,
token
=
token
,
record
=
template
)
print
(
f
"
record
{
r
}
"
)
if
'
id
'
in
r
:
print
(
f
"
Draft record created
{
r
[
'
id
'
]
}
-->
{
r
[
'
links
'
][
'
self
'
]
}
"
)
else
:
print
(
'
Something went wrong with registration
'
,
r
,
r
.
text
)
return
-
1
for
f
in
output_files
:
print
(
f
"
Uploading
{
f
}
"
)
_
=
add_file
(
record
=
r
,
fname
=
f
.
name
,
token
=
token
,
remote
=
f
)
# delete local
# os.unlink(local)
print
(
"
Submitting record for pubication
"
)
submitted
=
submit_draft
(
record
=
r
,
token
=
token
)
print
(
f
"
Record created
{
submitted
}
"
)
return
submitted
[
'
links
'
][
'
publication
'
]
# context = get_current_context()
# process.execute(context)
#TODO a cleanup job
@task
def
cleanup
(
errorcode
):
print
(
"
TODO: Clean up
"
)
data
=
extract
()
files
=
transform
(
data
)
data_locations
=
load
(
files
)
output_files
=
run_container
()
output_fnames
=
run_container
(
data_locations
)
ls_results
(
output_fnames
)
files
=
retrieve_res
(
output_fnames
)
errcode
=
stageout_results
(
files
)
cleanup
(
errcode
)
data
>>
files
>>
data_locations
>>
output_f
il
es
>>
postproces
s_results
(
output_f
iles
)
#
data >> files >> data_locations >> output_f
nam
es >>
l
s_results(output_f
names) >> files >> stageout_results(files) >> cleanup(
)
dag
=
docker_with_ssh
()
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