diff options
| author | Matthijs Bijman <matthijs@bijman.org> | 2017-02-16 22:06:09 +0100 |
|---|---|---|
| committer | Matthijs Bijman <matthijs@bijman.org> | 2017-02-16 22:06:09 +0100 |
| commit | e0b305fd1d845cba1b11578722f88adb193f756e (patch) | |
| tree | 90440eafff0f2b72571eee8a9b9c644d39ae4b75 /Simulator/include | |
| parent | 6fa9f879a5dab29cdf481e70b6f303caf69bd76f (diff) | |
Update simulator to work with new db schema
The new schema removes the queued_simulation_section table and
introduces the state and last_simulated_tick columns to the experiments
table.
Diffstat (limited to 'Simulator/include')
| -rw-r--r-- | Simulator/include/Simulator.h | 1 | ||||
| -rw-r--r-- | Simulator/include/database/Database.h | 4 | ||||
| -rw-r--r-- | Simulator/include/database/Queries.h | 15 |
3 files changed, 16 insertions, 4 deletions
diff --git a/Simulator/include/Simulator.h b/Simulator/include/Simulator.h index 381639af..1e0aaeb6 100644 --- a/Simulator/include/Simulator.h +++ b/Simulator/include/Simulator.h @@ -72,6 +72,7 @@ namespace Simulation if ((*it).second.isFinished()) { std::cout << "Finished simulation." << std::endl; + database.finishExperiment((*it).first); it = experiments.erase(it); } else diff --git a/Simulator/include/database/Database.h b/Simulator/include/database/Database.h index 6e8bfeef..7f867d6c 100644 --- a/Simulator/include/database/Database.h +++ b/Simulator/include/database/Database.h @@ -49,6 +49,10 @@ namespace Database */ void dequeueExperiment(int id) const; + /* + Marks the given experiment as finished in the database. + */ + void finishExperiment(int id) const; /* Creates a simulation object from a simulation in the database. diff --git a/Simulator/include/database/Queries.h b/Simulator/include/database/Queries.h index 73afc1a1..33e8cdb9 100644 --- a/Simulator/include/database/Queries.h +++ b/Simulator/include/database/Queries.h @@ -6,11 +6,15 @@ namespace Database namespace Queries { Query<int> GET_QUEUED_EXPERIMENTS(std::string(R"query( - SELECT experiment_id FROM queued_experiments; + SELECT id FROM experiments WHERE state LIKE 'QUEUED'; )query")); - Query<> REMOVE_QUEUED_EXPERIMENT(std::string(R"query( - DELETE FROM queued_experiments WHERE experiment_id = $id; + Query<> SET_EXPERIMENT_STATE_SIMULATING(std::string(R"query( + UPDATE experiments SET state='SIMULATING' WHERE id=$id; + )query")); + + Query<> SET_EXPERIMENT_STATE_FINISHED(std::string(R"query( + UPDATE experiments SET state='FINISHED' WHERE id=$id; )query")); Query<int, int, int, int, std::string, std::string> GET_EXPERIMENT_BY_ID(std::string(R"query( @@ -25,7 +29,10 @@ namespace Database SELECT id, path_id, datacenter_id, start_tick FROM sections WHERE path_id = $id; )query")); - + Query<> WRITE_EXPERIMENT_LAST_SIMULATED_TICK(std::string(R"query( + UPDATE experiments SET last_simulated_tick = $val WHERE id = $id; + )query")); + /* Returns the type of the scheduler of the given simulation section. Returns: <std::string : scheduler_name> |
