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
bd6dfca2
Commit
bd6dfca2
authored
3 years ago
by
Jedrzej Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
stage-in compatbile with datacat ids
parent
d6889f39
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#99736
failed
3 years ago
Stage: test
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
dags/taskflow.py
+27
-13
27 additions, 13 deletions
dags/taskflow.py
dags/taskflow_stream.py
+27
-12
27 additions, 12 deletions
dags/taskflow_stream.py
with
54 additions
and
25 deletions
dags/taskflow.py
+
27
−
13
View file @
bd6dfca2
...
...
@@ -5,10 +5,12 @@ from airflow.models.connection import Connection
from
airflow.models
import
Variable
from
airflow.utils.dates
import
days_ago
import
os
from
datacat_integration.hooks
import
DataCatalogHook
import
json
from
decors
import
get_connection
,
remove
,
setup
from
b2shareoperator
import
(
download_file
,
get_file_list
,
get_object_md
,
get_objects
)
from
b2shareoperator
import
(
download_file
,
get_file_list
,
get_object_md
)
default_args
=
{
'
owner
'
:
'
airflow
'
,
...
...
@@ -20,22 +22,34 @@ def taskflow_example():
@task
(
multiple_outputs
=
True
)
def
extract
(
conn_id
,
**
kwargs
):
params
=
kwargs
[
'
params
'
]
if
'
oid
'
not
in
params
:
print
(
"
Missing object id in pipeline parameters. Please provide an id for b2share or data cat id
"
)
return
-
1
oid
=
params
[
'
oid
'
]
hook
=
DataCatalogHook
()
try
:
entry
=
json
.
loads
(
hook
.
get_entry
(
'
dataset
'
,
oid
))
if
entry
and
'
b2share
'
in
entry
[
'
url
'
]:
print
(
f
"
Got data cat b2share entry:
{
entry
}
\n
with url:
{
entry
[
'
url
'
]
}
"
)
oid
=
entry
[
'
url
'
].
split
(
'
/
'
)[
-
1
]
print
(
f
"
Extracted oid
{
oid
}
"
)
else
:
print
(
'
No entry in data cat or not a b2share entry
'
)
except
:
# falling back to b2share
print
(
"
No entry found. Probably a b2share object
"
)
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
# non zero exit code is a task failure
oid
=
params
[
'
oid
'
]
obj
=
get_object_md
(
server
=
server
,
oid
=
oid
)
print
(
f
"
Retrieved object
{
oid
}
:
{
obj
}
"
)
# check status?
flist
=
get_file_list
(
obj
)
return
flist
...
...
This diff is collapsed.
Click to expand it.
dags/taskflow_stream.py
+
27
−
12
View file @
bd6dfca2
from
importlib.metadata
import
metadata
import
os
import
shutil
import
requests
...
...
@@ -6,10 +7,12 @@ 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
datacat_integration.hooks
import
DataCatalogHook
import
json
from
b2shareoperator
import
(
get_file_list
,
get_object_md
,
get_object
s
)
from
b2shareoperator
import
(
get_file_list
,
get_object
_md
)
default_args
=
{
'
owner
'
:
'
airflow
'
,
...
...
@@ -20,19 +23,31 @@ default_args = {
def
taskflow_stream
():
@task
(
multiple_outputs
=
True
)
def
get_flist
(
**
kwargs
):
params
=
kwargs
[
'
params
'
]
if
'
oid
'
not
in
params
:
print
(
"
Missing object id in pipeline parameters. Please provide an id for b2share or data cat id
"
)
return
-
1
oid
=
params
[
'
oid
'
]
hook
=
DataCatalogHook
()
try
:
entry
=
json
.
loads
(
hook
.
get_entry
(
'
dataset
'
,
oid
))
if
entry
and
'
b2share
'
in
entry
[
'
url
'
]:
print
(
f
"
Got data cat b2share entry:
{
entry
}
\n
with url:
{
entry
[
'
url
'
]
}
"
)
oid
=
entry
[
'
url
'
].
split
(
'
/
'
)[
-
1
]
print
(
f
"
Extracted oid
{
oid
}
"
)
else
:
print
(
'
No entry in data cat or not a b2share entry
'
)
except
:
# falling back to b2share
print
(
"
No entry found. Probably a b2share object
"
)
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
}
"
)
...
...
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