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
f0e4fad9
Commit
f0e4fad9
authored
3 years ago
by
Jedrzej Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
registration with hook. testing
parent
d0f64577
No related branches found
No related tags found
No related merge requests found
Pipeline
#96994
passed
3 years ago
Stage: test
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dags/just_reg.py
+26
-25
26 additions, 25 deletions
dags/just_reg.py
with
26 additions
and
25 deletions
dags/just_reg.py
+
26
−
25
View file @
f0e4fad9
...
@@ -3,6 +3,8 @@ from airflow.models.connection import Connection
...
@@ -3,6 +3,8 @@ from airflow.models.connection import Connection
from
airflow.operators.bash
import
BashOperator
from
airflow.operators.bash
import
BashOperator
from
airflow.providers.http.hooks.http
import
HttpHook
from
airflow.providers.http.hooks.http
import
HttpHook
from
airflow.utils.dates
import
days_ago
from
airflow.utils.dates
import
days_ago
from
datacat_integration.hooks
import
DataCatalogHook
from
datacat_integration.connection
import
DataCatalogEntry
default_args
=
{
default_args
=
{
...
@@ -33,33 +35,32 @@ def datacat_registration_example():
...
@@ -33,33 +35,32 @@ def datacat_registration_example():
print
(
"
Skipping registration as
'
register
'
parameter is not set
"
)
print
(
"
Skipping registration as
'
register
'
parameter is not set
"
)
return
0
return
0
connection
=
Connection
.
get_connection_from_secrets
(
hook
=
DataCatalogHook
()
'
datacat_connection
'
)
print
(
"
Connected to datacat via hook
"
,
hook
.
list_type
(
'
dataset
'
))
server
=
connection
.
get_uri
()
print
(
f
"
Registring
\n\t
{
object_url
}
\n
with
\n\t
{
server
}
"
)
# auth_type empty to overwrite http basic auth
entry
=
DataCatalogEntry
(
name
=
f
"
DLS results
{
kwargs
[
'
run_id
'
]
}
"
,
hook
=
HttpHook
(
http_conn_id
=
'
datacat_connection
'
,
auth_type
=
lambda
x
,
y
:
None
)
url
=
object_url
,
res
=
hook
.
run
(
endpoint
=
'
token
'
,
metadata
=
{
data
=
{
'
username
'
:
connection
.
login
,
'
password
'
:
connection
.
password
}
"
author
"
:
"
DLS on behalf of eFlows
"
,
"
access
"
:
"
hook-based
"
}
)
)
try
:
if
res
.
status_code
!=
200
:
r
=
hook
.
create_entry
(
datacat_type
=
'
dataset
'
,
entry
=
entry
)
print
(
"
Unable to authenticate. Breaking. Check `datacat_conneciton` for creds
"
)
print
(
"
Hook registration returned:
"
,
r
)
return
r
except
e
:
print
(
'
Registration failed
'
,
e
)
return
-
1
return
-
1
token
=
res
.
json
()[
'
access_token
'
]
#r = hook.run(endpoint='dataset', headers=auth_header,
auth_header
=
{
'
Authorization
'
:
f
"
Bearer
{
token
}
"
}
# json=get_record(name=f"DLS results {kwargs['run_id']}", url=object_url)
# )
r
=
hook
.
run
(
endpoint
=
'
dataset
'
,
headers
=
auth_header
,
#if r.status_code==200:
json
=
get_record
(
name
=
f
"
DLS results
{
kwargs
[
'
run_id
'
]
}
"
,
url
=
object_url
)
# d_id = r.json()[0]
)
# print(f"Registered sucesfully: {hook.base_url}/dataset/{d_id}")
if
r
.
status_code
==
200
:
# return d_id
d_id
=
r
.
json
()[
0
]
#print(f"Registraton failed: {r.text}")
print
(
f
"
Registered sucesfully:
{
hook
.
base_url
}
/dataset/
{
d_id
}
"
)
#return -1
return
d_id
print
(
f
"
Registraton failed:
{
r
.
text
}
"
)
return
-
1
...
...
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