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
b18868b7
Commit
b18868b7
authored
3 years ago
by
Jedrzej Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
image transfer dag
parent
29f0625c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
dags/decors.py
+1
-1
1 addition, 1 deletion
dags/decors.py
dags/image_transfer.py
+45
-0
45 additions, 0 deletions
dags/image_transfer.py
dags/uploadflow.py
+1
-2
1 addition, 2 deletions
dags/uploadflow.py
with
47 additions
and
3 deletions
dags/decors.py
+
1
−
1
View file @
b18868b7
...
@@ -39,7 +39,7 @@ def get_connection(conn_id, **kwargs):
...
@@ -39,7 +39,7 @@ def get_connection(conn_id, **kwargs):
# for now SSH is hardcoded
# for now SSH is hardcoded
params
=
kwargs
[
'
params
'
]
params
=
kwargs
[
'
params
'
]
host
=
params
.
get
(
'
host
'
)
host
=
params
.
get
(
'
host
'
)
port
=
int
(
params
.
get
(
'
port
'
,
22
22
))
port
=
int
(
params
.
get
(
'
port
'
,
22
))
user
=
params
.
get
(
'
login
'
,
'
eflows
'
)
user
=
params
.
get
(
'
login
'
,
'
eflows
'
)
hook
=
SSHHook
(
remote_host
=
host
,
port
=
port
,
username
=
user
)
hook
=
SSHHook
(
remote_host
=
host
,
port
=
port
,
username
=
user
)
# key in vault should be in form of formated string:
# key in vault should be in form of formated string:
...
...
This diff is collapsed.
Click to expand it.
dags/image_transfer.py
0 → 100644
+
45
−
0
View file @
b18868b7
import
os
import
shutil
import
requests
from
airflow.decorators
import
dag
,
task
from
airflow.utils.dates
import
days_ago
from
airflow.operators.python
import
PythonOperator
from
decors
import
setup
,
get_connection
,
remove
default_args
=
{
'
owner
'
:
'
airflow
'
,
}
@dag
(
default_args
=
default_args
,
schedule_interval
=
None
,
start_date
=
days_ago
(
2
),
tags
=
[
'
example
'
])
def
transfer_image
():
@task
def
stream_upload
(
connection_id
,
**
kwargs
):
params
=
kwargs
[
'
params
'
]
target
=
params
.
get
(
'
target
'
,
'
/tmp/
'
)
image_id
=
params
.
get
(
'
image_id
'
,
'
wordcount_skylake.sif
'
)
url
=
f
"
https://bscgrid20.bsc.es/image_creation/images/download/
{
image_id
}
"
print
(
f
"
Putting
{
url
}
-->
{
target
}
connection
"
)
ssh_hook
=
get_connection
(
conn_id
=
connection_id
,
**
kwargs
)
with
ssh_hook
.
get_conn
()
as
ssh_client
:
sftp_client
=
ssh_client
.
open_sftp
()
ssh_client
.
exec_command
(
command
=
f
"
mkdir -p
{
target
}
"
)
with
requests
.
get
(
url
,
stream
=
True
,
verify
=
False
)
as
r
:
with
sftp_client
.
open
(
os
.
path
.
join
(
target
,
image_id
),
'
wb
'
)
as
f
:
shutil
.
copyfileobj
(
r
.
raw
,
f
)
setup_task
=
PythonOperator
(
python_callable
=
setup
,
task_id
=
'
setup_connection
'
)
a_id
=
setup_task
.
output
[
'
return_value
'
]
cleanup_task
=
PythonOperator
(
python_callable
=
remove
,
op_kwargs
=
{
'
conn_id
'
:
a_id
},
task_id
=
'
cleanup
'
)
setup_task
>>
stream_upload
(
connection_id
=
a_id
)
>>
cleanup_task
dag
=
transfer_image
()
This diff is collapsed.
Click to expand it.
dags/uploadflow.py
+
1
−
2
View file @
b18868b7
...
@@ -105,8 +105,7 @@ def upload_example():
...
@@ -105,8 +105,7 @@ def upload_example():
setup_task
=
PythonOperator
(
setup_task
=
PythonOperator
(
python_callable
=
setup
,
task_id
=
'
setup_connection
'
)
python_callable
=
setup
,
task_id
=
'
setup_connection
'
)
a_id
=
setup_task
.
output
[
'
return_value
'
]
a_id
=
setup_task
.
output
[
'
return_value
'
]
files
=
load
(
connection_id
=
a_id
)
files
=
load
(
connection_id
=
a_id
)
...
...
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