-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
47 lines (42 loc) · 2.31 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
""" Models of used JSON messages """
from marshmallow import Schema, fields, validate
from marshmallow.decorators import validates_schema
class ConfigurationContainerSchema(Schema):
# TODO: document defaults in documentation-repo
# there are inconsistencies between computation and computation template
# TODO: write more validators, e.g. for regex-pattern or image
command_line_arguments = fields.String(data_key="running.commandLineArguments",
missing=None)
entrypoint = fields.String(data_key="running.entrypoint", missing=None)
intermediate_files_pattern = \
fields.List(fields.String, data_key="running.intermediateFilesPattern", missing=[])
image = fields.String(data_key="resources.image", required=True)
volume = fields.String(data_key="resources.volume", missing=None)
memory = fields.String(data_key="resources.memory", missing='64mb')
num_cpus = fields.Integer(data_key="resources.numCPUs", missing=1)
output = fields.List(fields.Raw(required=False))
class PartSchema(Schema):
identifier = fields.UUID(required=True)
access = fields.String(required=True,
validate=validate.OneOf(["invisible", "visible",
"modifiable", "template"]))
content = fields.String(missing="")
# TODO: bug in websocket-api: should be removed
metadata = fields.Raw()
class FileSchema(Schema):
identifier = fields.UUID(required=True)
path = fields.String(required=True)
parts = fields.List(fields.Nested(PartSchema), required=True)
class ComputationSchema(Schema):
identifier = fields.UUID(required=True)
environment = fields.String(required=True,
validate=validate.OneOf(["Container", "C",
"C++", "Java",
"Matlab", "Octave",
"DuMuX"]))
files = fields.List(fields.Nested(FileSchema), required=True)
configuration = fields.Raw(required=True)
@validates_schema
def validate_configuration(self, data, **kwargs):
if data["environment"] == "Container":
ConfigurationContainerSchema().validate(data["configuration"])