Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Kontr 2.0
Portal API Backend
Commits
da8f1fc4
Unverified
Commit
da8f1fc4
authored
Sep 23, 2018
by
Peter Stanko
Browse files
Better workers selection
parent
9035e55e
Changes
5
Hide whitespace changes
Inline
Side-by-side
portal/async_celery/submission_processor.py
View file @
da8f1fc4
...
...
@@ -6,6 +6,7 @@ from storage import UploadedEntity
import
portal.tools.worker_client
from
portal
import
logger
,
tools
from
portal.database
import
Project
,
Submission
,
SubmissionState
,
Worker
from
portal.database.models
import
WorkerState
log
=
logger
.
get_logger
(
__name__
)
...
...
@@ -105,6 +106,12 @@ class SubmissionProcessor:
self
.
reset_task_id
(
state
=
SubmissionState
.
CANCELLED
)
# TODO: Storage clean up
def
_get_avail_workers
(
self
):
course
=
self
.
submission
.
course
workers
=
self
.
_rest
.
workers
.
find_all
()
return
[
worker
for
worker
in
workers
if
worker
.
state
==
WorkerState
.
READY
and
course
in
worker
.
courses
]
# TODO implement - @mdujava
# STUB: Select initialized worker
def
schedule_submission_to_worker
(
self
)
->
Worker
:
...
...
@@ -113,7 +120,7 @@ class SubmissionProcessor:
Returns(Worker): Worker instance on which the submission will be executed
"""
workers
=
Worker
.
query
.
filter
(
Worker
.
is_initialized
).
all
()
workers
=
self
.
_get_avail_workers
()
if
not
workers
:
self
.
_worker_not_available
()
worker
=
random
.
choice
(
workers
)
# randomly select a worker
...
...
portal/logger.py
View file @
da8f1fc4
...
...
@@ -44,7 +44,7 @@ LOGGERS = {
'app'
:
{
'handlers'
:
[
'console'
],
'level'
:
'DEBUG'
,
'propagate'
:
True
},
'flask'
:
{
'handlers'
:
[
'console'
],
'level'
:
'DEBUG'
,
'propagate'
:
True
},
'werkzeug'
:
{
'handlers'
:
[
'console'
],
'level'
:
'DEBUG'
,
'propagate'
:
True
},
'storage'
:
{
'handlers'
:
[
'console'
],
'level'
:
'
DEBUG
'
,
'propagate'
:
True
},
'storage'
:
{
'handlers'
:
[
'console'
],
'level'
:
'
INFO
'
,
'propagate'
:
True
},
}
LOGGING_CONF
=
{
...
...
portal/rest/schemas.py
View file @
da8f1fc4
...
...
@@ -295,7 +295,7 @@ class WorkerSchema(BaseSchema, Schema):
url
=
fields
.
Str
(
allow_none
=
True
)
tags
=
fields
.
Str
(
allow_none
=
True
)
portal_secret
=
fields
.
Str
(
allow_none
=
True
)
state
=
EnumField
(
WorkerState
)
state
=
EnumField
(
WorkerState
,
by_value
=
True
)
class
SecretSchema
(
BaseSchema
,
Schema
):
...
...
portal/service/permissions.py
View file @
da8f1fc4
...
...
@@ -37,7 +37,7 @@ class PermissionServiceCheck:
def
permissions
(
self
,
permissions
)
->
bool
:
client
=
self
.
service
.
client
log
.
debug
(
f
"[PERM] Client
{
client
.
log_name
}
in course "
log
.
trace
(
f
"[PERM] Client
{
client
.
log_name
}
in course "
f
"
\"
{
self
.
service
.
course
.
log_name
}
\"
:
{
permissions
}
"
)
if
self
.
sysadmin
():
return
True
...
...
@@ -263,9 +263,8 @@ class PermissionsService(GeneralService):
for
key
,
value
in
vars
(
permission
).
items
():
if
not
key
.
startswith
(
"_"
)
and
key
not
in
FILTER_PERMISSION_ATTRS
:
result
[
key
]
=
result
.
get
(
key
)
or
value
log
.
debug
(
f
"[PERM] Effective permissions:
{
self
.
client
.
log_name
}
"
f
"in course
{
course
.
log_name
}
:
{
result
}
"
)
log
.
debug
(
f
"[PERM] Effective permissions:
{
self
.
client
.
log_name
}
"
f
"in course
{
course
.
log_name
}
:
{
result
}
"
)
return
result
def
submission_access_group
(
self
,
submission
,
perm
):
...
...
portal/service/workers.py
View file @
da8f1fc4
...
...
@@ -19,7 +19,7 @@ class WorkerService(GeneralService):
return
self
.
_entity
def
_set_data
(
self
,
entity
:
Worker
,
**
data
)
->
Worker
:
allowed
=
[
'name'
,
'url'
,
'tags'
,
'portal_secret'
]
allowed
=
[
'name'
,
'url'
,
'tags'
,
'portal_secret'
,
'state'
]
return
self
.
update_entity
(
entity
,
data
,
allowed
=
allowed
)
def
create
(
self
,
**
data
):
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment