summaryrefslogtreecommitdiff
path: root/src/sagas
diff options
context:
space:
mode:
Diffstat (limited to 'src/sagas')
-rw-r--r--src/sagas/experiments.js73
-rw-r--r--src/sagas/index.js9
-rw-r--r--src/sagas/objects.js16
3 files changed, 98 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);
+ }
+}
diff --git a/src/sagas/index.js b/src/sagas/index.js
index 5cb25202..e86ef8a1 100644
--- a/src/sagas/index.js
+++ b/src/sagas/index.js
@@ -1,5 +1,6 @@
import {takeEvery} from "redux-saga/effects";
import {LOG_IN} from "../actions/auth";
+import {ADD_EXPERIMENT, DELETE_EXPERIMENT, FETCH_EXPERIMENTS_OF_SIMULATION} from "../actions/experiments";
import {ADD_SIMULATION, DELETE_SIMULATION} from "../actions/simulations";
import {
ADD_TILE,
@@ -12,6 +13,7 @@ import {ADD_UNIT, DELETE_MACHINE, DELETE_UNIT} from "../actions/topology/machine
import {ADD_MACHINE, DELETE_RACK, EDIT_RACK_NAME} from "../actions/topology/rack";
import {ADD_RACK_TO_TILE, DELETE_ROOM, EDIT_ROOM_NAME} from "../actions/topology/room";
import {DELETE_CURRENT_USER, FETCH_AUTHORIZATIONS_OF_CURRENT_USER} from "../actions/users";
+import {onAddExperiment, onDeleteExperiment, onFetchExperimentsOfSimulation} from "./experiments";
import {onDeleteCurrentUser} from "./profile";
import {onSimulationAdd, onSimulationDelete} from "./simulations";
import {
@@ -34,10 +36,13 @@ import {onFetchAuthorizationsOfCurrentUser, onFetchLoggedInUser} from "./users";
export default function* rootSaga() {
yield takeEvery(LOG_IN, onFetchLoggedInUser);
+
yield takeEvery(FETCH_AUTHORIZATIONS_OF_CURRENT_USER, onFetchAuthorizationsOfCurrentUser);
yield takeEvery(ADD_SIMULATION, onSimulationAdd);
yield takeEvery(DELETE_SIMULATION, onSimulationDelete);
+
yield takeEvery(DELETE_CURRENT_USER, onDeleteCurrentUser);
+
yield takeEvery(FETCH_LATEST_DATACENTER, onFetchLatestDatacenter);
yield takeEvery(START_NEW_ROOM_CONSTRUCTION, onStartNewRoomConstruction);
yield takeEvery(CANCEL_NEW_ROOM_CONSTRUCTION, onCancelNewRoomConstruction);
@@ -52,4 +57,8 @@ export default function* rootSaga() {
yield takeEvery(DELETE_MACHINE, onDeleteMachine);
yield takeEvery(ADD_UNIT, onAddUnit);
yield takeEvery(DELETE_UNIT, onDeleteUnit);
+
+ yield takeEvery(FETCH_EXPERIMENTS_OF_SIMULATION, onFetchExperimentsOfSimulation);
+ yield takeEvery(ADD_EXPERIMENT, onAddExperiment);
+ yield takeEvery(DELETE_EXPERIMENT, onDeleteExperiment);
}
diff --git a/src/sagas/objects.js b/src/sagas/objects.js
index 508f1cf5..375781be 100644
--- a/src/sagas/objects.js
+++ b/src/sagas/objects.js
@@ -1,8 +1,10 @@
import {call, put, select} from "redux-saga/effects";
import {addToStore} from "../actions/objects";
import {getDatacenter, getRoomsOfDatacenter} from "../api/routes/datacenters";
+import {getAllJobs} from "../api/routes/jobs";
import {getPath, getSectionsOfPath} from "../api/routes/paths";
import {getTilesOfRoom} from "../api/routes/rooms";
+import {getAllSchedulers} from "../api/routes/schedulers";
import {getSection} from "../api/routes/sections";
import {getPathsOfSimulation, getSimulation} from "../api/routes/simulations";
import {
@@ -18,7 +20,9 @@ import {
getPSU,
getStorage
} from "../api/routes/specifications";
+import {getAllTasks} from "../api/routes/tasks";
import {getMachinesOfRackByTile, getRackByTile} from "../api/routes/tiles";
+import {getAllTraces} from "../api/routes/traces";
import {getUser} from "../api/routes/users";
export const OBJECT_SELECTORS = {
@@ -124,3 +128,15 @@ export const fetchAndStorePath = (id) =>
export const fetchAndStorePathsOfSimulation = (simulationId) =>
fetchAndStoreObjects("path", call(getPathsOfSimulation, simulationId));
+
+export const fetchAndStoreAllTraces = () =>
+ fetchAndStoreObjects("trace", call(getAllTraces));
+
+export const fetchAndStoreAllJobs = () =>
+ fetchAndStoreObjects("job", call(getAllJobs));
+
+export const fetchAndStoreAllTasks = () =>
+ fetchAndStoreObjects("task", call(getAllTasks));
+
+export const fetchAndStoreAllSchedulers = () =>
+ fetchAndStoreObjects("scheduler", call(getAllSchedulers));