Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-FAIR
Commits
4f966c19
Commit
4f966c19
authored
Mar 06, 2019
by
Markus Scheidgen
Browse files
Added a test script for bravado errors.
parent
ca900aae
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/test.py
0 → 100644
View file @
4f966c19
"""
This is a brief example demonstrating the public nomad@FAIRDI API for doing operations
that might be necessary to integrate external project data.
"""
from
bravado.requests_client
import
RequestsClient
from
bravado.client
import
SwaggerClient
import
math
from
urllib.parse
import
urlparse
from
concurrent.futures
import
ThreadPoolExecutor
nomad_url
=
'http://enc-staging-nomad.esc.rzg.mpg.de/fairdi/nomad/migration/api'
# nomad_url = 'http://localhost:8000/nomad/api/'
user
=
'admin'
password
=
'password'
upload_file
=
'external_project_example.zip'
# create the bravado client
host
=
urlparse
(
nomad_url
).
netloc
.
split
(
':'
)[
0
]
http_client
=
RequestsClient
()
http_client
.
set_basic_auth
(
host
,
user
,
password
)
client
=
SwaggerClient
.
from_url
(
'%s/swagger.json'
%
nomad_url
,
http_client
=
http_client
)
# uploads = [upload.upload_id for upload in client.uploads.get_uploads().response().result]
uploads
=
[
'SJSSLPKiR1mm6a_kSJAGZQ'
,
'nfMmrzGBTjmx77g9_C59fw'
,
'pglT7PYDQ0aB69FBbgIkRg'
,
'KXaaC5RASryl0wfuiEEUMA'
,
'xRSZ4xCnQ7uRL-uhtL3cSw'
]
executor
=
ThreadPoolExecutor
(
max_workers
=
10
)
def
run
(
upload_id
):
upload
=
client
.
uploads
.
get_upload
(
upload_id
=
upload_id
).
response
().
result
upload_total_calcs
=
upload
.
calcs
.
pagination
.
total
per_page
=
200
for
page
in
range
(
1
,
math
.
ceil
(
upload_total_calcs
/
per_page
)
+
1
):
search
=
client
.
repo
.
search
(
page
=
page
,
per_page
=
per_page
,
order_by
=
'mainfile'
,
upload_id
=
upload_id
).
response
().
result
print
(
search
.
pagination
.
page
)
for
upload
in
uploads
:
executor
.
submit
(
lambda
:
run
(
upload
))
nomad/utils.py
View file @
4f966c19
...
...
@@ -259,7 +259,8 @@ def configure_logging():
# configure log levels
for
logger
in
[
'celery.app.trace'
,
'celery.worker.strategy'
,
'bagit'
,
'elasticsearch'
,
'elasticsearch'
,
# 'celery.app.trace', 'celery.worker.strategy',
'urllib3.connectionpool'
,
'bravado'
,
'bravado_core'
,
'swagger_spec_validator'
]:
logging
.
getLogger
(
logger
).
setLevel
(
logging
.
WARNING
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment