diff options
Diffstat (limited to 'src/sagas')
| -rw-r--r-- | src/sagas/experiments.js | 14 | ||||
| -rw-r--r-- | src/sagas/index.js | 18 | ||||
| -rw-r--r-- | src/sagas/simulations.js | 3 | ||||
| -rw-r--r-- | src/sagas/topology.js | 25 |
4 files changed, 50 insertions, 10 deletions
diff --git a/src/sagas/experiments.js b/src/sagas/experiments.js index d1334759..cf92e97f 100644 --- a/src/sagas/experiments.js +++ b/src/sagas/experiments.js @@ -1,8 +1,20 @@ import {call, put, select} from "redux-saga/effects"; import {addPropToStoreObject, addToStore} from "../actions/objects"; -import {deleteExperiment} from "../api/routes/experiments"; +import {deleteExperiment, getExperiment} from "../api/routes/experiments"; import {addExperiment, getExperimentsOfSimulation} from "../api/routes/simulations"; import {fetchAndStoreAllSchedulers, fetchAndStoreAllTraces, fetchAndStorePathsOfSimulation} from "./objects"; +import {fetchAllDatacentersOfExperiment} from "./topology"; + +export function* onOpenExperimentSucceeded(action) { + try { + const experiment = yield call(getExperiment, action.experimentId); + yield put(addToStore("experiment", experiment)); + + yield fetchAllDatacentersOfExperiment(experiment); + } catch (error) { + console.error(error); + } +} export function* onFetchExperimentsOfSimulation() { try { diff --git a/src/sagas/index.js b/src/sagas/index.js index 30ca2f89..b10d6a1c 100644 --- a/src/sagas/index.js +++ b/src/sagas/index.js @@ -1,19 +1,28 @@ 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_EXPERIMENT, + DELETE_EXPERIMENT, + FETCH_EXPERIMENTS_OF_SIMULATION, + OPEN_EXPERIMENT_SUCCEEDED +} from "../actions/experiments"; import {ADD_SIMULATION, DELETE_SIMULATION, OPEN_SIMULATION_SUCCEEDED} from "../actions/simulations"; import { ADD_TILE, CANCEL_NEW_ROOM_CONSTRUCTION, DELETE_TILE, - FETCH_LATEST_DATACENTER, START_NEW_ROOM_CONSTRUCTION } from "../actions/topology/building"; 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 { + onAddExperiment, + onDeleteExperiment, + onFetchExperimentsOfSimulation, + onOpenExperimentSucceeded +} from "./experiments"; import {onDeleteCurrentUser} from "./profile"; import {onOpenSimulationSucceeded, onSimulationAdd, onSimulationDelete} from "./simulations"; import { @@ -29,7 +38,6 @@ import { onDeleteUnit, onEditRackName, onEditRoomName, - onFetchLatestDatacenter, onStartNewRoomConstruction } from "./topology"; import {onFetchAuthorizationsOfCurrentUser, onFetchLoggedInUser} from "./users"; @@ -44,8 +52,8 @@ export default function* rootSaga() { yield takeEvery(DELETE_CURRENT_USER, onDeleteCurrentUser); yield takeEvery(OPEN_SIMULATION_SUCCEEDED, onOpenSimulationSucceeded); + yield takeEvery(OPEN_EXPERIMENT_SUCCEEDED, onOpenExperimentSucceeded); - yield takeEvery(FETCH_LATEST_DATACENTER, onFetchLatestDatacenter); yield takeEvery(START_NEW_ROOM_CONSTRUCTION, onStartNewRoomConstruction); yield takeEvery(CANCEL_NEW_ROOM_CONSTRUCTION, onCancelNewRoomConstruction); yield takeEvery(ADD_TILE, onAddTile); diff --git a/src/sagas/simulations.js b/src/sagas/simulations.js index 57eb6bad..cf0358f9 100644 --- a/src/sagas/simulations.js +++ b/src/sagas/simulations.js @@ -2,11 +2,14 @@ import {call, put} from "redux-saga/effects"; import {addToStore} from "../actions/objects"; import {addSimulationSucceeded, deleteSimulationSucceeded} from "../actions/simulations"; import {addSimulation, deleteSimulation, getSimulation} from "../api/routes/simulations"; +import {fetchLatestDatacenter} from "./topology"; export function* onOpenSimulationSucceeded(action) { try { const simulation = yield call(getSimulation, action.id); yield put(addToStore("simulation", simulation)); + + yield fetchLatestDatacenter(action.id); } catch (error) { console.error(error); } diff --git a/src/sagas/topology.js b/src/sagas/topology.js index 763d4569..6a3e03af 100644 --- a/src/sagas/topology.js +++ b/src/sagas/topology.js @@ -8,7 +8,7 @@ import { } from "../actions/objects"; import { cancelNewRoomConstructionSucceeded, - fetchLatestDatacenterSucceeded, + setCurrentDatacenter, startNewRoomConstructionSucceeded } from "../actions/topology/building"; import {addRoomToDatacenter} from "../api/routes/datacenters"; @@ -38,6 +38,7 @@ import { fetchAndStoreGPU, fetchAndStoreMachinesOfTile, fetchAndStoreMemory, + fetchAndStorePath, fetchAndStorePathsOfSimulation, fetchAndStorePSU, fetchAndStoreRackOnTile, @@ -47,15 +48,31 @@ import { fetchAndStoreTilesOfRoom } from "./objects"; -export function* onFetchLatestDatacenter(action) { +export function* fetchLatestDatacenter(simulationId) { try { - const paths = yield fetchAndStorePathsOfSimulation(action.currentSimulationId); + const paths = yield fetchAndStorePathsOfSimulation(simulationId); const latestPath = paths[paths.length - 1]; const sections = yield fetchAndStoreSectionsOfPath(latestPath.id); const latestSection = sections[sections.length - 1]; yield fetchAllUnitSpecifications(); yield fetchDatacenter(latestSection.datacenterId); - yield put(fetchLatestDatacenterSucceeded(latestSection.datacenterId)); + yield put(setCurrentDatacenter(latestSection.datacenterId)); + } catch (error) { + console.error(error); + } +} + +export function* fetchAllDatacentersOfExperiment(experiment) { + try { + const path = yield fetchAndStorePath(experiment.pathId); + const sections = yield fetchAndStoreSectionsOfPath(path.id); + path.sectionIds = sections.map(section => section.id); + yield fetchAllUnitSpecifications(); + + for (let i in sections) { + yield fetchDatacenter(sections[i].datacenterId); + } + yield put(setCurrentDatacenter(sections[0].datacenterId)); } catch (error) { console.error(error); } |
