Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Jochem Bijlard
fractalis
Commits
a9e0eb8f
Commit
a9e0eb8f
authored
May 23, 2018
by
Jochem Bijlard
Browse files
Add /state/register to create a named session, which can be used to load
data to from other sessions.
parent
75b10cfc
Pipeline
#5258
failed with stages
in 27 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
fractalis/data/controller.py
View file @
a9e0eb8f
...
...
@@ -11,6 +11,7 @@ from fractalis.data.schema import create_data_schema
from
fractalis.validator
import
validate_json
,
validate_schema
from
fractalis
import
celery
,
redis
from
fractalis.sync
import
remove_data
from
fractalis.session
import
RedisSession
data_blueprint
=
Blueprint
(
'data_blueprint'
,
__name__
)
...
...
@@ -31,12 +32,34 @@ def create_data_task() -> Tuple[Response, int]:
etl_handler
=
ETLHandler
.
factory
(
handler
=
payload
[
'handler'
],
server
=
payload
[
'server'
],
auth
=
payload
[
'auth'
])
task_ids
=
etl_handler
.
handle
(
descriptors
=
payload
[
'descriptors'
],
data_tasks
=
session
[
'data_tasks'
],
use_existing
=
False
,
wait
=
wait
)
session
[
'data_tasks'
]
+=
task_ids
session
[
'data_tasks'
]
=
list
(
set
(
session
[
'data_tasks'
]))
alias
=
payload
.
get
(
'destination'
)
try
:
if
alias
is
None
:
task_ids
=
etl_handler
.
handle
(
descriptors
=
payload
[
'descriptors'
],
data_tasks
=
session
[
'data_tasks'
],
use_existing
=
False
,
wait
=
wait
)
session
[
'data_tasks'
]
+=
task_ids
session
[
'data_tasks'
]
=
list
(
set
(
session
[
'data_tasks'
]))
else
:
logger
.
info
(
"Submitting task to alias: {}"
.
format
(
alias
))
session_id
=
redis
.
get
(
'alias:{}'
.
format
(
alias
))
session_key
=
'session:{}'
.
format
(
session_id
)
destination
=
RedisSession
(
session_id
,
json
.
loads
(
redis
.
get
(
session_key
)))
task_ids
=
etl_handler
.
handle
(
descriptors
=
payload
[
'descriptors'
],
data_tasks
=
destination
[
'data_tasks'
],
use_existing
=
False
,
wait
=
wait
)
destination
[
'data_tasks'
]
=
list
(
set
(
destination
[
'data_tasks'
]
+
task_ids
))
redis
.
set
(
session_key
,
json
.
dumps
(
destination
))
except
Exception
as
e
:
logger
.
error
(
e
)
raise
e
logger
.
debug
(
"Tasks successfully submitted. Sending response."
)
return
jsonify
(
''
),
201
...
...
fractalis/state/controller.py
View file @
a9e0eb8f
...
...
@@ -137,3 +137,15 @@ def get_state_data(state_id: UUID) -> Tuple[Response, int]:
repl
=
session
[
'state_access'
][
state_id
][
i
],
string
=
state
)
return
jsonify
({
'state'
:
json
.
loads
(
state
)}),
200
@
state_blueprint
.
route
(
'/register'
,
methods
=
[
'POST'
])
def
register
():
logger
.
debug
(
"Received POST request on /state/<uuid:token>."
)
payload
=
request
.
get_json
(
force
=
True
)
alias
=
payload
.
get
(
'alias'
)
redis
.
set
(
'alias:{}'
.
format
(
alias
),
session
.
sid
)
logger
.
debug
(
"Registered alias: {}"
.
format
(
alias
))
return
jsonify
(
''
),
200
tests/functional/test_state.py
View file @
a9e0eb8f
...
...
@@ -315,3 +315,41 @@ class TestState:
body
=
flask
.
json
.
loads
(
rv
.
get_data
())
assert
403
==
rv
.
status_code
,
body
assert
'no access'
in
body
.
get
(
'error'
)
def
test_etl_through_alias
(
self
,
test_client
):
def
find_session_cookie
(
headers
):
for
head
in
headers
:
if
head
[
0
]
==
'Set-Cookie'
:
break
else
:
raise
ValueError
(
'Set-Cookie not found in header.'
)
return
head
[
1
].
split
(
';'
)[
0
].
split
(
'='
)[
1
]
uuid
=
str
(
uuid4
())
rv
=
test_client
.
post
(
'/state/register'
,
data
=
json
.
dumps
({
'alias'
:
uuid
}))
session_id_1
=
find_session_cookie
(
rv
.
headers
)
assert
redis
.
get
(
'alias:{}'
.
format
(
uuid
))
==
session_id_1
test_client
.
cookie_jar
=
None
rv
=
test_client
.
post
(
'/state/register'
,
data
=
json
.
dumps
({
'alias'
:
uuid
}))
session_id_2
=
find_session_cookie
(
rv
.
headers
)
assert
session_id_2
!=
session_id_1
rv
=
test_client
.
post
(
'/data'
,
data
=
json
.
dumps
({
'destination'
:
uuid
,
'descriptors'
:
{
'constraint'
:
''
,
'data_type'
:
'categorical'
,
'label'
:
'MOCK_LABEL'
},
'auth'
:
{
'token'
:
''
},
"handler"
:
"transmart"
,
"server"
:
''
}))
print
(
rv
)
Write
Preview
Markdown
is supported
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