summaryrefslogtreecommitdiff
path: root/src/sagas/experiments.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/sagas/experiments.js')
-rw-r--r--src/sagas/experiments.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/sagas/experiments.js b/src/sagas/experiments.js
new file mode 100644
index 00000000..0ac919f4
--- /dev/null
+++ b/src/sagas/experiments.js
@@ -0,0 +1,73 @@
+import {call, put, select} from "redux-saga/effects";
+import {addPropToStoreObject, addToStore} from "../actions/objects";
+import {deleteExperiment} from "../api/routes/experiments";
+import {addExperiment, getExperimentsOfSimulation} from "../api/routes/simulations";
+import {
+ fetchAndStoreAllJobs,
+ fetchAndStoreAllSchedulers,
+ fetchAndStoreAllTasks,
+ fetchAndStoreAllTraces,
+ fetchAndStorePathsOfSimulation
+} from "./objects";
+
+export function* onFetchExperimentsOfSimulation() {
+ try {
+ const currentSimulationId = yield select(state => state.currentSimulationId);
+
+ yield fetchExperimentSpecifications();
+ const experiments = yield call(getExperimentsOfSimulation, currentSimulationId);
+ for (let i in experiments) {
+ yield put(addToStore("experiment", experiments[i]));
+ }
+ yield put(addPropToStoreObject("simulation", currentSimulationId,
+ {experimentIds: experiments.map(experiment => experiment.id)}));
+ } catch (error) {
+ console.log(error);
+ }
+}
+
+function* fetchExperimentSpecifications() {
+ try {
+ const currentSimulationId = yield select(state => state.currentSimulationId);
+
+ yield fetchAndStorePathsOfSimulation(currentSimulationId);
+ yield fetchAndStoreAllTasks();
+ yield fetchAndStoreAllJobs();
+ yield fetchAndStoreAllTraces();
+ yield fetchAndStoreAllSchedulers();
+ } catch (error) {
+ console.log(error);
+ }
+}
+
+export function* onAddExperiment(action) {
+ try {
+ const currentSimulationId = yield select(state => state.currentSimulationId);
+
+ const experiment = yield call(addExperiment, currentSimulationId, Object.assign({}, action.experiment, {
+ id: -1,
+ simulationId: currentSimulationId
+ }));
+ yield put(addToStore("experiment", experiment));
+
+ const experimentIds = yield select(state => state.objects.simulation[currentSimulationId]);
+ yield put(addPropToStoreObject("simulation", currentSimulationId,
+ {experimentIds: experimentIds.concat([experiment.id])}));
+ } catch (error) {
+ console.log(error);
+ }
+}
+
+export function* onDeleteExperiment(action) {
+ try {
+ yield call(deleteExperiment, action.id);
+
+ const currentSimulationId = yield select(state => state.currentSimulationId);
+ const experimentIds = yield select(state => state.objects.simulation[currentSimulationId]);
+
+ yield put(addPropToStoreObject("simulation", currentSimulationId,
+ {experimentIds: experimentIds.filter(id => id !== action.id)}));
+ } catch (error) {
+ console.log(error);
+ }
+}