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
dcec1a4d
Commit
dcec1a4d
authored
3 years ago
by
Jedrzej Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
etl scaffolding
parent
e5eade13
No related branches found
No related tags found
No related merge requests found
Pipeline
#76947
passed
3 years ago
Stage: test
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+16
-1
16 additions, 1 deletion
README.md
dags/b2shareoperator.py
+25
-8
25 additions, 8 deletions
dags/b2shareoperator.py
dags/firsto.py
+1
-1
1 addition, 1 deletion
dags/firsto.py
dags/taskflow.py
+24
-7
24 additions, 7 deletions
dags/taskflow.py
with
66 additions
and
17 deletions
README.md
+
16
−
1
View file @
dcec1a4d
# Data Logistics Service
eFlows4HPC Data Logistics Service
```
mkdir ./logs ./plugins
echo -e "AIRFLOW_UID=$(id -u)\nAIRFLOW_GID=0" > .env
docker-compose -f dockers/docker-compose.yaml --project-directory . up airflow-init
```
```
docker-compose -f dockers/docker-compose.yaml --project-directory . up -d
```
## Setup connection
curl -X POST -u creds -H "Content-Type: application/json" --data '{"connection_id": "default_b2share","conn_type":"https", "host": "b2share-testing.fz-juelich.de", "schema":""}' localhost:7001/api/v1/connections
This diff is collapsed.
Click to expand it.
dags/b2shareoperator.py
+
25
−
8
View file @
dcec1a4d
...
...
@@ -2,11 +2,28 @@ from airflow.models.baseoperator import BaseOperator
from
airflow.models.connection
import
Connection
import
requests
from
urllib.parse
import
urljoin
import
tempfile
def
get_objects
(
server
):
lst
=
requests
.
get
(
urljoin
(
server
,
'
api/records
'
)).
json
()
return
lst
[
'
hits
'
][
'
hits
'
]
def
get_file_list
(
obj
):
file_url
=
obj
[
'
links
'
][
'
files
'
]
fls
=
requests
.
get
(
file_url
).
json
()
return
{
it
[
'
key
'
]:
it
[
'
links
'
][
'
self
'
]
for
it
in
fls
[
'
contents
'
]}
def
get_object_md
(
server
,
oid
):
obj
=
requests
.
get
(
urljoin
(
server
,
f
"
api/records/
{
oid
}
"
)).
json
()
return
obj
def
download_file
(
url
:
str
,
target_dir
:
str
):
_
,
fname
=
tempfile
.
mkstemp
(
dir
=
target_dir
)
urllib
.
request
.
urlretrieve
(
url
=
url
,
filename
=
fname
)
return
fname
server
=
'
https://b2share-testing.fz-juelich.de/
'
class
B2ShareOperator
(
BaseOperator
):
...
...
@@ -18,16 +35,16 @@ class B2ShareOperator(BaseOperator):
**
kwargs
)
->
None
:
super
().
__init__
(
**
kwargs
)
self
.
name
=
name
self
.
connection
=
Connection
.
get_connection_from_secrets
(
conn_id
)
self
.
conn_id
=
conn_id
print
(
kwargs
)
def
execute
(
self
,
context
):
message
=
"
Hello {}
"
.
format
(
self
.
name
)
print
(
message
)
print
(
self
.
connection
.
get_uri
())
connection
=
Connection
.
get_connection_from_secrets
(
self
.
conn_id
)
print
(
f
"
Rereiving data from
{
connection
.
get_uri
()
}
"
)
#print(f"Retrieving info from {self.
connection.
host}"
)
l
st
=
get_objects
(
server
=
server
)
print
(
f
"
GOT:
{
l
st
}
"
)
lst
=
get_objects
(
server
=
connection
.
get_uri
()
)
fli
st
=
{
o
[
'
id
'
]:
[
f
[
'
key
'
]
for
f
in
o
[
'
files
'
]]
for
o
in
lst
}
print
(
f
"
GOT:
{
fli
st
}
"
)
print
(
self
.
params
)
return
message
return
len
(
flist
)
This diff is collapsed.
Click to expand it.
dags/firsto.py
+
1
−
1
View file @
dcec1a4d
...
...
@@ -24,5 +24,5 @@ with DAG('firsto', default_args=def_args, description='first dag', schedule_inte
t3
=
B2ShareOperator
(
task_id
=
'
task_b2sh
'
,
dag
=
dag
,
name
=
'
B2Share
'
)
t1
>>
t2
t1
>>
t2
>>
t3
This diff is collapsed.
Click to expand it.
dags/taskflow.py
+
24
−
7
View file @
dcec1a4d
...
...
@@ -3,25 +3,42 @@
from
airflow.decorators
import
dag
,
task
from
airflow.utils.dates
import
days_ago
from
airflow.models.connection
import
Connection
import
requests
import
urllib.request
import
tempfile
from
b2shareoperator
import
get_file_list
,
download_file
,
get_object_md
default_args
=
{
'
owner
'
:
'
airflow
'
,
}
@dag
(
default_args
=
default_args
,
schedule_interval
=
None
,
start_date
=
days_ago
(
2
),
tags
=
[
'
example
'
])
def
taskflow_example
():
@task
()
def
extract
():
return
{
'
key
'
:
'
value
'
,
'
key2
'
:
'
value2
'
}
def
extract
(
oid
:
str
):
connection
=
Connection
.
get_connection_from_secrets
(
'
default_b2share
'
)
server
=
connection
.
get_uri
()
print
(
f
"
Rereiving data from
{
server
}
"
)
obj
=
get_object_md
(
server
=
server
,
oid
=
oid
)
print
(
f
"
Object:
{
obj
}
"
)
flist
=
get_file_list
(
obj
)
return
flist
@task
(
multiple_outputs
=
True
)
def
transform
(
inps
:
dict
):
return
{
"
keys
"
:
len
(
inps
)}
def
transform
(
flist
:
dict
):
name_mappings
=
{}
for
fname
,
url
in
flist
.
items
():
print
(
f
"
Processing:
{
fname
}
-->
{
url
}
"
)
tmpname
=
download_file
(
url
=
url
,
target_dir
=
'
/tmp/downs/
'
)
name_mappings
[
fname
]
=
tmpname
return
name_mappings
@task
()
def
load
(
lengths
:
floa
t
):
print
(
f
"
Total
length value is:
{
lengths
:
.
2
f
}
"
)
def
load
(
files
:
dic
t
):
print
(
f
"
Total
files downloaded:
{
len
(
files
)
}
"
)
data
=
extract
()
data
=
extract
(
oid
=
'
b38609df2b334ea296ea1857e568dbea
'
)
summary
=
transform
(
data
)
load
(
summary
[
"
keys
"
])
...
...
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