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
96d4dca5
Commit
96d4dca5
authored
3 years ago
by
Jedrzej Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
stream upload
parent
c5b44a83
Branches
Branches containing commit
Tags
v0.8.2
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dags/taskflow_stream.py
+63
-0
63 additions, 0 deletions
dags/taskflow_stream.py
with
63 additions
and
0 deletions
dags/taskflow_stream.py
0 → 100644
+
63
−
0
View file @
96d4dca5
import
os
import
shutil
import
requests
from
airflow.decorators
import
dag
,
task
from
airflow.models.connection
import
Connection
from
airflow.providers.ssh.hooks.ssh
import
SSHHook
from
airflow.utils.dates
import
days_ago
from
b2shareoperator
import
(
get_file_list
,
get_object_md
,
get_objects
)
default_args
=
{
'
owner
'
:
'
airflow
'
,
}
@dag
(
default_args
=
default_args
,
schedule_interval
=
None
,
start_date
=
days_ago
(
2
),
tags
=
[
'
example
'
])
def
taskflow_stream
():
@task
(
multiple_outputs
=
True
)
def
get_flist
(
**
kwargs
):
connection
=
Connection
.
get_connection_from_secrets
(
'
default_b2share
'
)
server
=
connection
.
get_uri
()
print
(
f
"
Rereiving data from
{
server
}
"
)
params
=
kwargs
[
'
params
'
]
if
'
oid
'
not
in
params
:
# {"oid":"b38609df2b334ea296ea1857e568dbea"}
print
(
"
Missing object id in pipeline parameters
"
)
lst
=
get_objects
(
server
=
server
)
flist
=
{
o
[
'
id
'
]:
[
f
[
'
key
'
]
for
f
in
o
[
'
files
'
]]
for
o
in
lst
}
print
(
f
"
Objects on server:
{
flist
}
"
)
return
-
1
oid
=
params
[
'
oid
'
]
obj
=
get_object_md
(
server
=
server
,
oid
=
oid
)
print
(
f
"
Retrieved object
{
oid
}
:
{
obj
}
"
)
flist
=
get_file_list
(
obj
)
return
flist
@task
(
multiple_outputs
=
True
)
def
stream_upload
(
flist
:
dict
,
**
kwargs
):
params
=
kwargs
[
'
params
'
]
target
=
params
.
get
(
'
target
'
,
'
/tmp/
'
)
connection_id
=
params
.
get
(
'
connection
'
,
'
default_ssh
'
)
ssh_hook
=
SSHHook
(
ssh_conn_id
=
connection_id
)
mappings
=
dict
()
with
ssh_hook
.
get_conn
()
as
ssh_client
:
sftp_client
=
ssh_client
.
open_sftp
()
for
fname
,
url
in
flist
.
items
():
print
(
f
"
Processing:
{
url
}
-->
{
fname
}
"
)
with
requests
.
get
(
url
,
stream
=
True
)
as
r
:
with
sftp_client
.
open
(
os
.
path
.
join
(
target
,
fname
),
'
wb
'
)
as
f
:
shutil
.
copyfileobj
(
r
.
raw
,
f
)
mappings
[
url
]
=
os
.
path
.
join
(
target
,
fname
)
return
mappings
flist
=
get_flist
()
stats
=
stream_upload
(
flist
)
dag
=
taskflow_stream
()
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