summaryrefslogtreecommitdiff
path: root/web-server/opendc/api/v2/experiments/experimentId/endpoint.py
blob: 103c24ac73e2768d456db4f1ccaee64fbee4243b (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from opendc.models.experiment import Experiment
from opendc.models.simulation import Simulation
from opendc.util.rest import Response


def GET(request):
    """Get this Experiment."""

    request.check_required_parameters(path={'experimentId': 'string'})

    experiment = Experiment.from_id(request.params_path['experimentId'])

    experiment.check_exists()
    experiment.check_user_access(request.google_id, False)

    return Response(200, 'Successfully retrieved Experiment.', experiment.obj)


def PUT(request):
    """Update this Experiment."""

    request.check_required_parameters(path={'experimentId': 'string'},
                                      body={
                                          'experiment': {
                                              'topologyId': 'string',
                                              'traceId': 'string',
                                              'schedulerName': 'string',
                                              'name': 'string',
                                          }
                                      })

    experiment = Experiment.from_id(request.params_path['experimentId'])

    experiment.check_exists()
    experiment.check_user_access(request.google_id, True)

    experiment.set_property('topologyId', request.params_body['experiment']['topologyId'])
    experiment.set_property('traceId', request.params_body['experiment']['traceId'])
    experiment.set_property('schedulerName', request.params_body['experiment']['schedulerName'])
    experiment.set_property('name', request.params_body['experiment']['name'])

    experiment.update()

    return Response(200, 'Successfully updated experiment', experiment.obj)


def DELETE(request):
    """Delete this Experiment."""

    request.check_required_parameters(path={'experimentId': 'string'})

    experiment = Experiment.from_id(request.params_path['experimentId'])

    experiment.check_exists()
    experiment.check_user_access(request.google_id, True)

    simulation = Simulation.from_id(experiment.obj['simulationId'])
    simulation.check_exists()
    if request.params_path['experimentId'] in simulation.obj['experimentIds']:
        simulation.obj['experimentIds'].remove(request.params_path['experimentId'])
    simulation.update()

    experiment.delete()

    return Response(200, 'Successfully deleted experiment.', experiment.obj)