summaryrefslogtreecommitdiff
path: root/opendc
diff options
context:
space:
mode:
authorleonoverweel <l.overweel@gmail.com>2017-02-27 02:33:02 +0100
committerleonoverweel <l.overweel@gmail.com>2017-02-27 02:33:02 +0100
commit855b654942d400204ea3ce952b5fe0cebf8492c2 (patch)
tree4f963b2bd11a1873d613fc78c0eda5f98e43dd75 /opendc
parentcdfce7ce038826bd99be805b7e7579c9ec5d4fc2 (diff)
Add state and last_simulated_tick to Experiments
This change brings the web server back up to date with the new database schema.
Diffstat (limited to 'opendc')
-rw-r--r--opendc/api/v1/simulations/simulationId/experiments/endpoint.py11
-rw-r--r--opendc/api/v1/simulations/simulationId/experiments/experimentId/last-simulated-tick/endpoint.py10
-rw-r--r--opendc/models/experiment.py23
3 files changed, 11 insertions, 33 deletions
diff --git a/opendc/api/v1/simulations/simulationId/experiments/endpoint.py b/opendc/api/v1/simulations/simulationId/experiments/endpoint.py
index 8cc4165f..034e82a1 100644
--- a/opendc/api/v1/simulations/simulationId/experiments/endpoint.py
+++ b/opendc/api/v1/simulations/simulationId/experiments/endpoint.py
@@ -89,6 +89,8 @@ def POST(request):
# Instantiate an Experiment
experiment = Experiment.from_JSON(request.params_body['experiment'])
+ experiment.state = 'QUEUED'
+ experiment.last_simulated_tick = 0
# Try to insert this Experiment
@@ -96,15 +98,10 @@ def POST(request):
experiment.insert()
except exceptions.ForeignKeyError as e:
- return Response(400, 'Foreign key constraint not met.')
-
- # Queue this Experiment for simulation
-
- queued_experiment = QueuedExperiment(experiment_id = experiment.id)
- queued_experiment.insert()
+ return Response(400, 'Foreign key constraint not met.' + e.message)
# Return this Experiment
-
+
experiment.read()
return Response(
diff --git a/opendc/api/v1/simulations/simulationId/experiments/experimentId/last-simulated-tick/endpoint.py b/opendc/api/v1/simulations/simulationId/experiments/experimentId/last-simulated-tick/endpoint.py
index ed33be85..d39fafe4 100644
--- a/opendc/api/v1/simulations/simulationId/experiments/experimentId/last-simulated-tick/endpoint.py
+++ b/opendc/api/v1/simulations/simulationId/experiments/experimentId/last-simulated-tick/endpoint.py
@@ -30,14 +30,10 @@ def GET(request):
# Make sure this user is authorized to view this Experiment's last simulated tick
if not experiment.google_id_has_at_least(request.google_id, 'VIEW'):
- return Response(403, 'Forbidden from viewing Room States for {}.'.format(experiment))
-
- # Get and return the last simulated tick
-
- last_simulated_tick = experiment.get_last_simulated_tick()
+ return Response(403, 'Forbidden from viewing last simulated tick for {}.'.format(experiment))
return Response(
200,
- 'Successfully retrieved Room States for {}.'.format(experiment),
- {'lastSimulatedTick': last_simulated_tick}
+ 'Successfully retrieved last simulated tick for {}.'.format(experiment),
+ {'lastSimulatedTick': experiment.last_simulated_tick}
)
diff --git a/opendc/models/experiment.py b/opendc/models/experiment.py
index 35056d0f..c7381084 100644
--- a/opendc/models/experiment.py
+++ b/opendc/models/experiment.py
@@ -11,31 +11,16 @@ class Experiment(Model):
'pathId': 'path_id',
'traceId': 'trace_id',
'schedulerName': 'scheduler_name',
- 'name': 'name'
+ 'name': 'name',
+ 'state': 'state',
+ 'lastSimulatedTick': 'last_simulated_tick'
}
}
TABLE_NAME = 'experiments'
- COLUMNS = ['id', 'simulation_id', 'path_id', 'trace_id', 'scheduler_name', 'name']
+ COLUMNS = ['id', 'simulation_id', 'path_id', 'trace_id', 'scheduler_name', 'name', 'state', 'last_simulated_tick']
COLUMNS_PRIMARY_KEY = ['id']
- def get_last_simulated_tick(self):
- """Get this Experiment's last simulated tick."""
-
- statement = '''
- SELECT tick
- FROM task_states
- WHERE experiment_id = ?
- ORDER BY tick DESC
- LIMIT 1
- '''
- result = database.fetchone(statement, (self.id,))
-
- if result is not None:
- return result[0]
-
- return -1
-
def google_id_has_at_least(self, google_id, authorization_level):
"""Return True if the user has at least the given auth level over this Experiment."""