diff options
Diffstat (limited to 'src/sagas')
| -rw-r--r-- | src/sagas/index.js | 9 | ||||
| -rw-r--r-- | src/sagas/topology.js | 86 |
2 files changed, 93 insertions, 2 deletions
diff --git a/src/sagas/index.js b/src/sagas/index.js index 024e40aa..e6c48da4 100644 --- a/src/sagas/index.js +++ b/src/sagas/index.js @@ -2,11 +2,14 @@ import {takeEvery} from "redux-saga/effects"; import {LOG_IN} from "../actions/auth"; import {ADD_SIMULATION, DELETE_SIMULATION} from "../actions/simulations"; import { + ADD_MACHINE, ADD_RACK_TO_TILE, ADD_TILE, CANCEL_NEW_ROOM_CONSTRUCTION, + DELETE_RACK, DELETE_ROOM, DELETE_TILE, + EDIT_RACK_NAME, EDIT_ROOM_NAME, FETCH_LATEST_DATACENTER, START_NEW_ROOM_CONSTRUCTION @@ -15,11 +18,14 @@ import {DELETE_CURRENT_USER, FETCH_AUTHORIZATIONS_OF_CURRENT_USER} from "../acti import {onDeleteCurrentUser} from "./profile"; import {onSimulationAdd, onSimulationDelete} from "./simulations"; import { + onAddMachine, onAddRackToTile, onAddTile, onCancelNewRoomConstruction, + onDeleteRack, onDeleteRoom, onDeleteTile, + onEditRackName, onEditRoomName, onFetchLatestDatacenter, onStartNewRoomConstruction @@ -39,5 +45,8 @@ export default function* rootSaga() { yield takeEvery(DELETE_TILE, onDeleteTile); yield takeEvery(EDIT_ROOM_NAME, onEditRoomName); yield takeEvery(DELETE_ROOM, onDeleteRoom); + yield takeEvery(EDIT_RACK_NAME, onEditRackName); + yield takeEvery(DELETE_RACK, onDeleteRack); yield takeEvery(ADD_RACK_TO_TILE, onAddRackToTile); + yield takeEvery(ADD_MACHINE, onAddMachine); } diff --git a/src/sagas/topology.js b/src/sagas/topology.js index ab544bbe..2ae31074 100644 --- a/src/sagas/topology.js +++ b/src/sagas/topology.js @@ -1,26 +1,40 @@ import {call, put, select} from "redux-saga/effects"; import {addPropToStoreObject, addToStore} from "../actions/objects"; import { + addMachineSucceeded, addRackToTileSucceeded, addTileSucceeded, cancelNewRoomConstructionSucceeded, + deleteRackSucceeded, deleteRoomSucceeded, deleteTileSucceeded, + editRackNameSucceeded, editRoomNameSucceeded, fetchLatestDatacenterSucceeded, startNewRoomConstructionSucceeded } from "../actions/topology"; import {addRoomToDatacenter} from "../api/routes/datacenters"; import {addTileToRoom, deleteRoom, updateRoom} from "../api/routes/rooms"; -import {addRackToTile, deleteTile} from "../api/routes/tiles"; +import { + addMachineToRackOnTile, + addRackToTile, + deleteRackFromTile, + deleteTile, + updateRackOnTile +} from "../api/routes/tiles"; import { fetchAndStoreCoolingItem, + fetchAndStoreCPU, fetchAndStoreDatacenter, + fetchAndStoreGPU, + fetchAndStoreMachinesOfTile, + fetchAndStoreMemory, fetchAndStorePathsOfSimulation, fetchAndStorePSU, fetchAndStoreRackOnTile, fetchAndStoreRoomsOfDatacenter, fetchAndStoreSectionsOfPath, + fetchAndStoreStorage, fetchAndStoreTilesOfRoom } from "./objects"; @@ -69,6 +83,7 @@ function* fetchTile(tile) { case "RACK": const rack = yield fetchAndStoreRackOnTile(tile.objectId, tile.id); yield put(addPropToStoreObject("tile", tile.id, {rackId: rack.id})); + yield fetchMachinesOfRack(tile.id, rack); break; case "COOLING_ITEM": const coolingItem = yield fetchAndStoreCoolingItem(tile.objectId); @@ -79,7 +94,30 @@ function* fetchTile(tile) { yield put(addPropToStoreObject("tile", tile.id, {psuId: psu.id})); break; default: - console.warn("Unknown object type encountered while fetching tile objects"); + console.warn("Unknown rack type encountered while fetching tile objects"); + } +} + +function* fetchMachinesOfRack(tileId, rack) { + const machines = yield fetchAndStoreMachinesOfTile(tileId); + const machineIds = new Array(rack.capacity).fill(null); + machines.forEach(machine => machineIds[machine.position] = machine.id); + + yield put(addPropToStoreObject("rack", rack.id, {machineIds})); + + for (let index in machines) { + for (let i in machines[index].cpuIds) { + yield fetchAndStoreCPU(machines[index].cpuIds[i]); + } + for (let i in machines[index].gpuIds) { + yield fetchAndStoreGPU(machines[index].gpuIds[i]); + } + for (let i in machines[index].memoryIds) { + yield fetchAndStoreMemory(machines[index].memoryIds[i]); + } + for (let i in machines[index].storageIds) { + yield fetchAndStoreStorage(machines[index].storageIds[i]); + } } } @@ -155,6 +193,29 @@ export function* onDeleteRoom() { } } +export function* onEditRackName(action) { + try { + const tileId = yield select(state => state.interactionLevel.tileId); + const rackId = yield select(state => state.objects.tile[state.interactionLevel.tileId].objectId); + const rack = Object.assign({}, yield select(state => state.objects.rack[rackId])); + rack.name = action.name; + yield call(updateRackOnTile, tileId, rack); + yield put(editRackNameSucceeded(action.name)); + } catch (error) { + console.log(error); + } +} + +export function* onDeleteRack() { + try { + const tileId = yield select(state => state.interactionLevel.tileId); + yield call(deleteRackFromTile, tileId); + yield put(deleteRackSucceeded()); + } catch (error) { + console.log(error); + } +} + export function* onAddRackToTile(action) { try { const rack = yield call(addRackToTile, action.tileId, { @@ -170,3 +231,24 @@ export function* onAddRackToTile(action) { console.log(error); } } + +export function* onAddMachine(action) { + try { + const tileId = yield select(state => state.interactionLevel.tileId); + const rackId = yield select(state => state.objects.tile[state.interactionLevel.tileId].objectId); + const machine = yield call(addMachineToRackOnTile, tileId, { + id: -1, + rackId, + position: action.position, + tags: [], + cpuIds: [], + gpuIds: [], + memoryIds: [], + storageIds: [], + }); + yield put(addToStore("machine", machine)); + yield put(addMachineSucceeded(machine)); + } catch (error) { + console.log(error); + } +} |
