summaryrefslogtreecommitdiff
path: root/frontend/src/sagas
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/sagas')
-rw-r--r--frontend/src/sagas/experiments.js98
-rw-r--r--frontend/src/sagas/index.js15
-rw-r--r--frontend/src/sagas/objects.js251
-rw-r--r--frontend/src/sagas/simulations.js8
-rw-r--r--frontend/src/sagas/topology.js370
-rw-r--r--frontend/src/sagas/users.js10
6 files changed, 306 insertions, 446 deletions
diff --git a/frontend/src/sagas/experiments.js b/frontend/src/sagas/experiments.js
index a361759b..b9106fdc 100644
--- a/frontend/src/sagas/experiments.js
+++ b/frontend/src/sagas/experiments.js
@@ -7,15 +7,11 @@ import {
getAllMachineStates,
getAllRackStates,
getAllRoomStates,
- getAllTaskStates,
getExperiment,
- getLastSimulatedTick,
} from '../api/routes/experiments'
-import { getTasksOfJob } from '../api/routes/jobs'
-import { addExperiment, getExperimentsOfSimulation, getSimulation } from '../api/routes/simulations'
-import { getJobsOfTrace } from '../api/routes/traces'
-import { fetchAndStoreAllSchedulers, fetchAndStoreAllTraces, fetchAndStorePathsOfSimulation } from './objects'
-import { fetchAllDatacentersOfExperiment } from './topology'
+import { addExperiment, getSimulation } from '../api/routes/simulations'
+import { fetchAndStoreAllSchedulers, fetchAndStoreAllTraces } from './objects'
+import { fetchAndStoreAllTopologiesOfSimulation, fetchTopologyOfExperiment } from './topology'
export function* onOpenExperimentSucceeded(action) {
try {
@@ -26,9 +22,8 @@ export function* onOpenExperimentSucceeded(action) {
yield put(addToStore('experiment', experiment))
yield fetchExperimentSpecifications()
- yield fetchWorkloadOfTrace(experiment.traceId)
- yield fetchAllDatacentersOfExperiment(experiment)
+ yield fetchTopologyOfExperiment(experiment)
yield startStateFetchLoop(action.experimentId)
} catch (error) {
console.error(error)
@@ -37,20 +32,15 @@ export function* onOpenExperimentSucceeded(action) {
function* startStateFetchLoop(experimentId) {
try {
- while ((yield select(state => state.currentExperimentId)) !== -1) {
- const lastSimulatedTick = (yield call(getLastSimulatedTick, experimentId))
- .lastSimulatedTick
- if (
- lastSimulatedTick !== (yield select(state => state.lastSimulatedTick))
- ) {
+ while ((yield select((state) => state.currentExperimentId)) !== -1) {
+ const lastSimulatedTick = (yield call(getExperiment, experimentId)).lastSimulatedTick
+ if (lastSimulatedTick !== (yield select((state) => state.lastSimulatedTick))) {
yield put(setLastSimulatedTick(lastSimulatedTick))
- const taskStates = yield call(getAllTaskStates, experimentId)
const machineStates = yield call(getAllMachineStates, experimentId)
const rackStates = yield call(getAllRackStates, experimentId)
const roomStates = yield call(getAllRoomStates, experimentId)
- yield put(addBatchToStates('task', taskStates))
yield put(addBatchToStates('machine', machineStates))
yield put(addBatchToStates('rack', rackStates))
yield put(addBatchToStates('room', roomStates))
@@ -67,23 +57,15 @@ function* startStateFetchLoop(experimentId) {
export function* onFetchExperimentsOfSimulation() {
try {
- const currentSimulationId = yield select(
- state => state.currentSimulationId,
- )
+ const currentSimulationId = yield select((state) => state.currentSimulationId)
+ const currentSimulation = yield select((state) => state.object.simulation[currentSimulationId])
yield fetchExperimentSpecifications()
- const experiments = yield call(
- getExperimentsOfSimulation,
- currentSimulationId,
- )
- for (let i in experiments) {
- yield put(addToStore('experiment', experiments[i]))
+
+ for (let i in currentSimulation.experimentIds) {
+ const experiment = yield call(getExperiment, currentSimulation.experimentIds[i])
+ yield put(addToStore('experiment', experiment))
}
- yield put(
- addPropToStoreObject('simulation', currentSimulationId, {
- experimentIds: experiments.map(experiment => experiment.id),
- }),
- )
} catch (error) {
console.error(error)
}
@@ -91,10 +73,8 @@ export function* onFetchExperimentsOfSimulation() {
function* fetchExperimentSpecifications() {
try {
- const currentSimulationId = yield select(
- state => state.currentSimulationId,
- )
- yield fetchAndStorePathsOfSimulation(currentSimulationId)
+ const currentSimulationId = yield select((state) => state.currentSimulationId)
+ yield fetchAndStoreAllTopologiesOfSimulation(currentSimulationId)
yield fetchAndStoreAllTraces()
yield fetchAndStoreAllSchedulers()
} catch (error) {
@@ -102,33 +82,9 @@ function* fetchExperimentSpecifications() {
}
}
-function* fetchWorkloadOfTrace(traceId) {
- try {
- const jobs = yield call(getJobsOfTrace, traceId)
- for (let i in jobs) {
- const job = jobs[i]
- const tasks = yield call(getTasksOfJob, job.id)
- job.taskIds = tasks.map(task => task.id)
- for (let j in tasks) {
- yield put(addToStore('task', tasks[j]))
- }
- yield put(addToStore('job', job))
- }
- yield put(
- addPropToStoreObject('trace', traceId, {
- jobIds: jobs.map(job => job.id),
- }),
- )
- } catch (error) {
- console.error(error)
- }
-}
-
export function* onAddExperiment(action) {
try {
- const currentSimulationId = yield select(
- state => state.currentSimulationId,
- )
+ const currentSimulationId = yield select((state) => state.currentSimulationId)
const experiment = yield call(
addExperiment,
@@ -136,17 +92,15 @@ export function* onAddExperiment(action) {
Object.assign({}, action.experiment, {
id: -1,
simulationId: currentSimulationId,
- }),
+ })
)
yield put(addToStore('experiment', experiment))
- const experimentIds = yield select(
- state => state.objects.simulation[currentSimulationId].experimentIds,
- )
+ const experimentIds = yield select((state) => state.objects.simulation[currentSimulationId].experimentIds)
yield put(
addPropToStoreObject('simulation', currentSimulationId, {
- experimentIds: experimentIds.concat([experiment.id]),
- }),
+ experimentIds: experimentIds.concat([experiment._id]),
+ })
)
} catch (error) {
console.error(error)
@@ -157,17 +111,13 @@ 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].experimentIds,
- )
+ const currentSimulationId = yield select((state) => state.currentSimulationId)
+ const experimentIds = yield select((state) => state.objects.simulation[currentSimulationId].experimentIds)
yield put(
addPropToStoreObject('simulation', currentSimulationId, {
- experimentIds: experimentIds.filter(id => id !== action.id),
- }),
+ experimentIds: experimentIds.filter((id) => id !== action.id),
+ })
)
} catch (error) {
console.error(error)
diff --git a/frontend/src/sagas/index.js b/frontend/src/sagas/index.js
index d1de906f..0947befc 100644
--- a/frontend/src/sagas/index.js
+++ b/frontend/src/sagas/index.js
@@ -29,26 +29,26 @@ import {
onAddMachine,
onAddRackToTile,
onAddTile,
+ onAddTopology,
onAddUnit,
onCancelNewRoomConstruction,
onDeleteMachine,
onDeleteRack,
onDeleteRoom,
onDeleteTile,
+ onDeleteTopology,
onDeleteUnit,
onEditRackName,
onEditRoomName,
onStartNewRoomConstruction,
} from './topology'
import { onFetchAuthorizationsOfCurrentUser, onFetchLoggedInUser } from './users'
+import { ADD_TOPOLOGY, DELETE_TOPOLOGY } from '../actions/topologies'
export default function* rootSaga() {
yield takeEvery(LOG_IN, onFetchLoggedInUser)
- yield takeEvery(
- FETCH_AUTHORIZATIONS_OF_CURRENT_USER,
- onFetchAuthorizationsOfCurrentUser,
- )
+ yield takeEvery(FETCH_AUTHORIZATIONS_OF_CURRENT_USER, onFetchAuthorizationsOfCurrentUser)
yield takeEvery(ADD_SIMULATION, onSimulationAdd)
yield takeEvery(DELETE_SIMULATION, onSimulationDelete)
@@ -57,6 +57,8 @@ export default function* rootSaga() {
yield takeEvery(OPEN_SIMULATION_SUCCEEDED, onOpenSimulationSucceeded)
yield takeEvery(OPEN_EXPERIMENT_SUCCEEDED, onOpenExperimentSucceeded)
+ yield takeEvery(ADD_TOPOLOGY, onAddTopology)
+ yield takeEvery(DELETE_TOPOLOGY, onDeleteTopology)
yield takeEvery(START_NEW_ROOM_CONSTRUCTION, onStartNewRoomConstruction)
yield takeEvery(CANCEL_NEW_ROOM_CONSTRUCTION, onCancelNewRoomConstruction)
yield takeEvery(ADD_TILE, onAddTile)
@@ -71,10 +73,7 @@ export default function* rootSaga() {
yield takeEvery(ADD_UNIT, onAddUnit)
yield takeEvery(DELETE_UNIT, onDeleteUnit)
- yield takeEvery(
- FETCH_EXPERIMENTS_OF_SIMULATION,
- onFetchExperimentsOfSimulation,
- )
+ yield takeEvery(FETCH_EXPERIMENTS_OF_SIMULATION, onFetchExperimentsOfSimulation)
yield takeEvery(ADD_EXPERIMENT, onAddExperiment)
yield takeEvery(DELETE_EXPERIMENT, onDeleteExperiment)
}
diff --git a/frontend/src/sagas/objects.js b/frontend/src/sagas/objects.js
index faa75be2..174f9c3e 100644
--- a/frontend/src/sagas/objects.js
+++ b/frontend/src/sagas/objects.js
@@ -1,46 +1,25 @@
import { call, put, select } from 'redux-saga/effects'
import { addToStore } from '../actions/objects'
-import { getDatacenter, getRoomsOfDatacenter } from '../api/routes/datacenters'
-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 {
- getAllCPUs,
- getAllGPUs,
- getAllMemories,
- getAllStorages,
- getCoolingItem,
- getCPU,
- getFailureModel,
- getGPU,
- getMemory,
- getPSU,
- getStorage,
-} from '../api/routes/specifications'
-import { getMachinesOfRackByTile, getRackByTile } from '../api/routes/tiles'
+import { getSimulation } from '../api/routes/simulations'
import { getAllTraces } from '../api/routes/traces'
import { getUser } from '../api/routes/users'
+import { getTopology, updateTopology } from '../api/routes/topologies'
+import { uuid } from 'uuidv4'
export const OBJECT_SELECTORS = {
- simulation: state => state.objects.simulation,
- user: state => state.objects.user,
- authorization: state => state.objects.authorization,
- failureModel: state => state.objects.failureModel,
- cpu: state => state.objects.cpu,
- gpu: state => state.objects.gpu,
- memory: state => state.objects.memory,
- storage: state => state.objects.storage,
- machine: state => state.objects.machine,
- rack: state => state.objects.rack,
- coolingItem: state => state.objects.coolingItem,
- psu: state => state.objects.psu,
- tile: state => state.objects.tile,
- room: state => state.objects.room,
- datacenter: state => state.objects.datacenter,
- section: state => state.objects.section,
- path: state => state.objects.path,
+ simulation: (state) => state.objects.simulation,
+ user: (state) => state.objects.user,
+ authorization: (state) => state.objects.authorization,
+ cpu: (state) => state.objects.cpu,
+ gpu: (state) => state.objects.gpu,
+ memory: (state) => state.objects.memory,
+ storage: (state) => state.objects.storage,
+ machine: (state) => state.objects.machine,
+ rack: (state) => state.objects.rack,
+ tile: (state) => state.objects.tile,
+ room: (state) => state.objects.room,
+ topology: (state) => state.objects.topology,
}
function* fetchAndStoreObject(objectType, id, apiCall) {
@@ -61,79 +40,151 @@ function* fetchAndStoreObjects(objectType, apiCall) {
return objects
}
-export const fetchAndStoreSimulation = id =>
- fetchAndStoreObject('simulation', id, call(getSimulation, id))
-
-export const fetchAndStoreUser = id =>
- fetchAndStoreObject('user', id, call(getUser, id))
-
-export const fetchAndStoreFailureModel = id =>
- fetchAndStoreObject('failureModel', id, call(getFailureModel, id))
-
-export const fetchAndStoreAllCPUs = () =>
- fetchAndStoreObjects('cpu', call(getAllCPUs))
-
-export const fetchAndStoreCPU = id =>
- fetchAndStoreObject('cpu', id, call(getCPU, id))
-
-export const fetchAndStoreAllGPUs = () =>
- fetchAndStoreObjects('gpu', call(getAllGPUs))
-
-export const fetchAndStoreGPU = id =>
- fetchAndStoreObject('gpu', id, call(getGPU, id))
-
-export const fetchAndStoreAllMemories = () =>
- fetchAndStoreObjects('memory', call(getAllMemories))
-
-export const fetchAndStoreMemory = id =>
- fetchAndStoreObject('memory', id, call(getMemory, id))
-
-export const fetchAndStoreAllStorages = () =>
- fetchAndStoreObjects('storage', call(getAllStorages))
-
-export const fetchAndStoreStorage = id =>
- fetchAndStoreObject('storage', id, call(getStorage, id))
-
-export const fetchAndStoreMachinesOfTile = tileId =>
- fetchAndStoreObjects('machine', call(getMachinesOfRackByTile, tileId))
-
-export const fetchAndStoreRackOnTile = (id, tileId) =>
- fetchAndStoreObject('rack', id, call(getRackByTile, tileId))
-
-export const fetchAndStoreCoolingItem = id =>
- fetchAndStoreObject('coolingItem', id, call(getCoolingItem, id))
-
-export const fetchAndStorePSU = id =>
- fetchAndStoreObject('psu', id, call(getPSU, id))
-
-export const fetchAndStoreTilesOfRoom = roomId =>
- fetchAndStoreObjects('tile', call(getTilesOfRoom, roomId))
-
-export const fetchAndStoreRoomsOfDatacenter = datacenterId =>
- fetchAndStoreObjects('room', call(getRoomsOfDatacenter, datacenterId))
-
-export const fetchAndStoreDatacenter = id =>
- fetchAndStoreObject('datacenter', id, call(getDatacenter, id))
+export const fetchAndStoreSimulation = (id) => fetchAndStoreObject('simulation', id, call(getSimulation, id))
+
+export const fetchAndStoreUser = (id) => fetchAndStoreObject('user', id, call(getUser, id))
+
+export const fetchAndStoreTopology = function* (id) {
+ const topologyStore = yield select(OBJECT_SELECTORS['topology'])
+ const roomStore = yield select(OBJECT_SELECTORS['room'])
+ const tileStore = yield select(OBJECT_SELECTORS['tile'])
+ const rackStore = yield select(OBJECT_SELECTORS['rack'])
+ const machineStore = yield select(OBJECT_SELECTORS['machine'])
+
+ let topology = topologyStore[id]
+ if (!topology) {
+ const fullTopology = yield call(getTopology, id)
+
+ for (let roomIdx in fullTopology.rooms) {
+ const fullRoom = fullTopology.rooms[roomIdx]
+
+ generateIdIfNotPresent(fullRoom)
+
+ if (!roomStore[fullRoom._id]) {
+ for (let tileIdx in fullRoom.tiles) {
+ const fullTile = fullRoom.tiles[tileIdx]
+
+ generateIdIfNotPresent(fullTile)
+
+ if (!tileStore[fullTile._id]) {
+ if (fullTile.rack) {
+ const fullRack = fullTile.rack
+
+ generateIdIfNotPresent(fullTile)
+
+ if (!rackStore[fullRack._id]) {
+ for (let machineIdx in fullRack.machines) {
+ const fullMachine = fullRoom.machines[machineIdx]
+
+ generateIdIfNotPresent(fullMachine)
+
+ if (!machineStore[fullMachine._id]) {
+ let machine = (({ _id, position, cpuIds, gpuIds, memoryIds, storageIds }) => ({
+ _id,
+ rackId: fullRack._id,
+ position,
+ cpuIds,
+ gpuIds,
+ memoryIds,
+ storageIds,
+ }))(fullMachine)
+ yield put(addToStore('machine', machine))
+ }
+ }
+
+ const filledSlots = new Array(fullRack.capacity).fill(null)
+ fullRack.machines.forEach(
+ (machine) => (filledSlots[machine.position - 1] = machine._id)
+ )
+ let rack = (({ _id, capacity, powerCapacityW }) => ({
+ _id,
+ capacity,
+ powerCapacityW,
+ machineIds: filledSlots,
+ }))(fullRack)
+ yield put(addToStore('rack', rack))
+ }
+ }
+
+ let tile = (({ _id, positionX, positionY, rack }) => ({
+ _id,
+ roomId: fullRoom._id,
+ positionX,
+ positionY,
+ rackId: rack ? rack._id : undefined,
+ }))(fullTile)
+ yield put(addToStore('tile', tile))
+ }
+ }
+
+ let room = (({ _id, name, tiles }) => ({ _id, name, tileIds: tiles.map((t) => t._id) }))(fullRoom)
+ yield put(addToStore('room', room))
+ }
+ }
+
+ topology = (({ _id, name, rooms }) => ({ _id, name, roomIds: rooms.map((r) => r._id) }))(fullTopology)
+ yield put(addToStore('topology', topology))
+
+ console.log('Full topology after insertion', fullTopology)
+ // TODO consider pushing the IDs
+ }
-export const fetchAndStoreSection = id =>
- fetchAndStoreObject('section', id, call(getSection, id))
+ return topology
+}
-export const fetchAndStoreSectionsOfPath = pathId =>
- fetchAndStoreObjects('section', call(getSectionsOfPath, pathId))
+const generateIdIfNotPresent = (obj) => {
+ if (!obj._id) {
+ obj._id = uuid()
+ }
+}
-export const fetchAndStorePath = id =>
- fetchAndStoreObject('path', id, call(getPath, id))
+export const updateTopologyOnServer = function* (id) {
+ const topologyStore = yield select(OBJECT_SELECTORS['topology'])
+ const roomStore = yield select(OBJECT_SELECTORS['room'])
+ const tileStore = yield select(OBJECT_SELECTORS['tile'])
+ const rackStore = yield select(OBJECT_SELECTORS['rack'])
+ const machineStore = yield select(OBJECT_SELECTORS['machine'])
+
+ const topology = {
+ _id: id,
+ name: topologyStore[id].name,
+ rooms: topologyStore[id].roomIds.map((roomId) => ({
+ _id: roomId,
+ name: roomStore[roomId].name,
+ tiles: roomStore[roomId].tileIds.map((tileId) => ({
+ _id: tileId,
+ positionX: tileStore[tileId].positionX,
+ positionY: tileStore[tileId].positionY,
+ rack: !tileStore[tileId].rackId
+ ? undefined
+ : {
+ _id: rackStore[tileStore[tileId].rackId]._id,
+ capacity: rackStore[tileStore[tileId].rackId].capacity,
+ powerCapacityW: rackStore[tileStore[tileId].rackId].powerCapacityW,
+ machines: rackStore[tileStore[tileId].rackId].machineIds
+ .filter((m) => m !== null)
+ .map((machineId) => ({
+ _id: machineId,
+ position: machineStore[machineId].position,
+ cpuIds: machineStore[machineId].cpuIds,
+ gpuIds: machineStore[machineId].gpuIds,
+ memoryIds: machineStore[machineId].memoryIds,
+ storageIds: machineStore[machineId].storageIds,
+ })),
+ },
+ })),
+ })),
+ }
-export const fetchAndStorePathsOfSimulation = simulationId =>
- fetchAndStoreObjects('path', call(getPathsOfSimulation, simulationId))
+ yield call(updateTopology, topology)
+}
-export const fetchAndStoreAllTraces = () =>
- fetchAndStoreObjects('trace', call(getAllTraces))
+export const fetchAndStoreAllTraces = () => fetchAndStoreObjects('trace', call(getAllTraces))
export const fetchAndStoreAllSchedulers = function* () {
const objects = yield call(getAllSchedulers)
for (let index in objects) {
- objects[index].id = objects[index].name
+ objects[index]._id = objects[index].name
yield put(addToStore('scheduler', objects[index]))
}
return objects
diff --git a/frontend/src/sagas/simulations.js b/frontend/src/sagas/simulations.js
index b57fac95..be69fedd 100644
--- a/frontend/src/sagas/simulations.js
+++ b/frontend/src/sagas/simulations.js
@@ -2,14 +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'
+import { fetchAndStoreAllTopologiesOfSimulation } from './topology'
export function* onOpenSimulationSucceeded(action) {
try {
const simulation = yield call(getSimulation, action.id)
yield put(addToStore('simulation', simulation))
- yield fetchLatestDatacenter(action.id)
+ yield fetchAndStoreAllTopologiesOfSimulation(action.id)
} catch (error) {
console.error(error)
}
@@ -27,9 +27,7 @@ export function* onSimulationAdd(action) {
simulation,
}
yield put(addToStore('authorization', authorization))
- yield put(
- addSimulationSucceeded([authorization.userId, authorization.simulationId]),
- )
+ yield put(addSimulationSucceeded([authorization.userId, authorization.simulationId]))
} catch (error) {
console.error(error)
}
diff --git a/frontend/src/sagas/topology.js b/frontend/src/sagas/topology.js
index b38358a4..0be619a9 100644
--- a/frontend/src/sagas/topology.js
+++ b/frontend/src/sagas/topology.js
@@ -8,181 +8,95 @@ import {
} from '../actions/objects'
import {
cancelNewRoomConstructionSucceeded,
- setCurrentDatacenter,
+ setCurrentTopology,
startNewRoomConstructionSucceeded,
} from '../actions/topology/building'
-import { addRoomToDatacenter } from '../api/routes/datacenters'
-import { addTileToRoom, deleteRoom, updateRoom } from '../api/routes/rooms'
-import {
- addMachineToRackOnTile,
- addRackToTile,
- deleteMachineInRackOnTile,
- deleteRackFromTile,
- deleteTile,
- updateMachineInRackOnTile,
- updateRackOnTile,
-} from '../api/routes/tiles'
import {
DEFAULT_RACK_POWER_CAPACITY,
DEFAULT_RACK_SLOT_CAPACITY,
MAX_NUM_UNITS_PER_MACHINE,
} from '../components/app/map/MapConstants'
-import {
- fetchAndStoreAllCPUs,
- fetchAndStoreAllGPUs,
- fetchAndStoreAllMemories,
- fetchAndStoreAllStorages,
- fetchAndStoreCoolingItem,
- fetchAndStoreCPU,
- fetchAndStoreDatacenter,
- fetchAndStoreGPU,
- fetchAndStoreMachinesOfTile,
- fetchAndStoreMemory,
- fetchAndStorePath,
- fetchAndStorePathsOfSimulation,
- fetchAndStorePSU,
- fetchAndStoreRackOnTile,
- fetchAndStoreRoomsOfDatacenter,
- fetchAndStoreSectionsOfPath,
- fetchAndStoreStorage,
- fetchAndStoreTilesOfRoom,
-} from './objects'
+import { fetchAndStoreTopology, updateTopologyOnServer } from './objects'
+import { uuid } from 'uuidv4'
+import { addTopology, deleteTopology } from '../api/routes/topologies'
-export function* fetchLatestDatacenter(simulationId) {
+export function* fetchTopologyOfExperiment(experiment) {
try {
- 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(setCurrentDatacenter(latestSection.datacenterId))
+ yield fetchAndStoreTopology(experiment.topologyId)
+ yield put(setCurrentTopology(experiment.topologyId))
} catch (error) {
console.error(error)
}
}
-export function* fetchAllDatacentersOfExperiment(experiment) {
+export function* fetchAndStoreAllTopologiesOfSimulation(simulationId) {
try {
- const path = yield fetchAndStorePath(experiment.pathId)
- const sections = yield fetchAndStoreSectionsOfPath(path.id)
- path.sectionIds = sections.map(section => section.id)
- yield fetchAllUnitSpecifications()
+ const simulation = yield select((state) => state.objects.simulation[simulationId])
- for (let i in sections) {
- yield fetchDatacenter(sections[i].datacenterId)
+ for (let i in simulation.topologyIds) {
+ yield fetchAndStoreTopology(simulation.topologyIds[i])
}
- yield put(setCurrentDatacenter(sections[0].datacenterId))
+
+ yield put(setCurrentTopology(simulation.topologyIds[0]))
} catch (error) {
console.error(error)
}
}
-function* fetchDatacenter(datacenterId) {
+export function* onAddTopology(action) {
try {
- yield fetchAndStoreDatacenter(datacenterId)
- const rooms = yield fetchAndStoreRoomsOfDatacenter(datacenterId)
- yield put(
- addPropToStoreObject('datacenter', datacenterId, {
- roomIds: rooms.map(room => room.id),
- }),
+ const currentSimulationId = yield select((state) => state.currentSimulationId)
+
+ const topology = yield call(
+ addTopology,
+ Object.assign({}, action.topology, {
+ _id: -1,
+ simulationId: currentSimulationId,
+ })
)
+ yield put(addToStore('topology', topology))
- for (let index in rooms) {
- yield fetchRoom(rooms[index].id)
- }
+ const topologyIds = yield select((state) => state.objects.simulation[currentSimulationId].topologyIds)
+ yield put(
+ addPropToStoreObject('simulation', currentSimulationId, {
+ topologyIds: topologyIds.concat([topology._id]),
+ })
+ )
} catch (error) {
console.error(error)
}
}
-function* fetchAllUnitSpecifications() {
+export function* onDeleteTopology(action) {
try {
- yield fetchAndStoreAllCPUs()
- yield fetchAndStoreAllGPUs()
- yield fetchAndStoreAllMemories()
- yield fetchAndStoreAllStorages()
- } catch (error) {
- console.error(error)
- }
-}
-
-function* fetchRoom(roomId) {
- const tiles = yield fetchAndStoreTilesOfRoom(roomId)
- yield put(
- addPropToStoreObject('room', roomId, {
- tileIds: tiles.map(tile => tile.id),
- }),
- )
-
- for (let index in tiles) {
- yield fetchTile(tiles[index])
- }
-}
-
-function* fetchTile(tile) {
- if (!tile.objectType) {
- return
- }
-
- switch (tile.objectType) {
- 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)
- yield put(
- addPropToStoreObject('tile', tile.id, { coolingItemId: coolingItem.id }),
- )
- break
- case 'PSU':
- const psu = yield fetchAndStorePSU(tile.objectId)
- yield put(addPropToStoreObject('tile', tile.id, { psuId: psu.id }))
- break
- default:
- 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 - 1] = machine.id))
+ yield call(deleteTopology, action.id)
- yield put(addPropToStoreObject('rack', rack.id, { machineIds }))
+ const currentSimulationId = yield select((state) => state.currentSimulationId)
+ const topologyIds = yield select((state) => state.objects.simulation[currentSimulationId].topologyIds)
- 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])
- }
+ yield put(
+ addPropToStoreObject('simulation', currentSimulationId, {
+ topologyIds: topologyIds.filter((id) => id !== action.id),
+ })
+ )
+ } catch (error) {
+ console.error(error)
}
}
export function* onStartNewRoomConstruction() {
try {
- const datacenterId = yield select(state => state.currentDatacenterId)
- const room = yield call(addRoomToDatacenter, {
- id: -1,
- datacenterId,
- roomType: 'SERVER',
- })
- const roomWithEmptyTileList = Object.assign({}, room, { tileIds: [] })
- yield put(addToStore('room', roomWithEmptyTileList))
- yield put(
- addIdToStoreObjectListProp('datacenter', datacenterId, 'roomIds', room.id),
- )
- yield put(startNewRoomConstructionSucceeded(room.id))
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const room = {
+ _id: uuid(),
+ name: 'Room',
+ topologyId,
+ tileIds: [],
+ }
+ yield put(addToStore('room', room))
+ yield put(addIdToStoreObjectListProp('topology', topologyId, 'roomIds', room._id))
+ yield updateTopologyOnServer(topologyId)
+ yield put(startNewRoomConstructionSucceeded(room._id))
} catch (error) {
console.error(error)
}
@@ -190,19 +104,11 @@ export function* onStartNewRoomConstruction() {
export function* onCancelNewRoomConstruction() {
try {
- const datacenterId = yield select(state => state.currentDatacenterId)
- const roomId = yield select(
- state => state.construction.currentRoomInConstruction,
- )
- yield call(deleteRoom, roomId)
- yield put(
- removeIdFromStoreObjectListProp(
- 'datacenter',
- datacenterId,
- 'roomIds',
- roomId,
- ),
- )
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const roomId = yield select((state) => state.construction.currentRoomInConstruction)
+ yield put(removeIdFromStoreObjectListProp('topology', topologyId, 'roomIds', roomId))
+ // TODO remove room from store, too
+ yield updateTopologyOnServer(topologyId)
yield put(cancelNewRoomConstructionSucceeded())
} catch (error) {
console.error(error)
@@ -211,16 +117,17 @@ export function* onCancelNewRoomConstruction() {
export function* onAddTile(action) {
try {
- const roomId = yield select(
- state => state.construction.currentRoomInConstruction,
- )
- const tile = yield call(addTileToRoom, {
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const roomId = yield select((state) => state.construction.currentRoomInConstruction)
+ const tile = {
+ _id: uuid(),
roomId,
positionX: action.positionX,
positionY: action.positionY,
- })
+ }
yield put(addToStore('tile', tile))
- yield put(addIdToStoreObjectListProp('room', roomId, 'tileIds', tile.id))
+ yield put(addIdToStoreObjectListProp('room', roomId, 'tileIds', tile._id))
+ yield updateTopologyOnServer(topologyId)
} catch (error) {
console.error(error)
}
@@ -228,13 +135,10 @@ export function* onAddTile(action) {
export function* onDeleteTile(action) {
try {
- const roomId = yield select(
- state => state.construction.currentRoomInConstruction,
- )
- yield call(deleteTile, action.tileId)
- yield put(
- removeIdFromStoreObjectListProp('room', roomId, 'tileIds', action.tileId),
- )
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const roomId = yield select((state) => state.construction.currentRoomInConstruction)
+ yield put(removeIdFromStoreObjectListProp('room', roomId, 'tileIds', action.tileId))
+ yield updateTopologyOnServer(topologyId)
} catch (error) {
console.error(error)
}
@@ -242,14 +146,12 @@ export function* onDeleteTile(action) {
export function* onEditRoomName(action) {
try {
- const roomId = yield select(state => state.interactionLevel.roomId)
- const room = Object.assign(
- {},
- yield select(state => state.objects.room[roomId]),
- )
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const roomId = yield select((state) => state.interactionLevel.roomId)
+ const room = Object.assign({}, yield select((state) => state.objects.room[roomId]))
room.name = action.name
- yield call(updateRoom, room)
yield put(addPropToStoreObject('room', roomId, { name: action.name }))
+ yield updateTopologyOnServer(topologyId)
} catch (error) {
console.error(error)
}
@@ -257,18 +159,11 @@ export function* onEditRoomName(action) {
export function* onDeleteRoom() {
try {
- const datacenterId = yield select(state => state.currentDatacenterId)
- const roomId = yield select(state => state.interactionLevel.roomId)
- yield call(deleteRoom, roomId)
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const roomId = yield select((state) => state.interactionLevel.roomId)
yield put(goDownOneInteractionLevel())
- yield put(
- removeIdFromStoreObjectListProp(
- 'datacenter',
- datacenterId,
- 'roomIds',
- roomId,
- ),
- )
+ yield put(removeIdFromStoreObjectListProp('topology', topologyId, 'roomIds', roomId))
+ yield updateTopologyOnServer(topologyId)
} catch (error) {
console.error(error)
}
@@ -276,17 +171,12 @@ 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]),
- )
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const rackId = yield select((state) => state.objects.tile[state.interactionLevel.tileId].rackId)
+ const rack = Object.assign({}, yield select((state) => state.objects.rack[rackId]))
rack.name = action.name
- yield call(updateRackOnTile, tileId, rack)
yield put(addPropToStoreObject('rack', rackId, { name: action.name }))
+ yield updateTopologyOnServer(topologyId)
} catch (error) {
console.error(error)
}
@@ -294,11 +184,11 @@ export function* onEditRackName(action) {
export function* onDeleteRack() {
try {
- const tileId = yield select(state => state.interactionLevel.tileId)
- yield call(deleteRackFromTile, tileId)
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const tileId = yield select((state) => state.interactionLevel.tileId)
yield put(goDownOneInteractionLevel())
- yield put(addPropToStoreObject('tile', tileId, { objectType: undefined }))
- yield put(addPropToStoreObject('tile', tileId, { objectId: undefined }))
+ yield put(addPropToStoreObject('tile', tileId, { rackId: undefined }))
+ yield updateTopologyOnServer(topologyId)
} catch (error) {
console.error(error)
}
@@ -306,20 +196,16 @@ export function* onDeleteRack() {
export function* onAddRackToTile(action) {
try {
- const rack = yield call(addRackToTile, action.tileId, {
- id: -1,
- name: 'Rack',
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const rack = {
+ _id: uuid(),
capacity: DEFAULT_RACK_SLOT_CAPACITY,
powerCapacityW: DEFAULT_RACK_POWER_CAPACITY,
- })
+ }
rack.machineIds = new Array(rack.capacity).fill(null)
yield put(addToStore('rack', rack))
- yield put(
- addPropToStoreObject('tile', action.tileId, { objectId: rack.id }),
- )
- yield put(
- addPropToStoreObject('tile', action.tileId, { objectType: 'RACK' }),
- )
+ yield put(addPropToStoreObject('tile', action.tileId, { rackId: rack._id }))
+ yield updateTopologyOnServer(topologyId)
} catch (error) {
console.error(error)
}
@@ -327,27 +213,24 @@ export function* onAddRackToTile(action) {
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 rack = yield select(state => state.objects.rack[rackId])
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const rackId = yield select((state) => state.objects.tile[state.interactionLevel.tileId].rackId)
+ const rack = yield select((state) => state.objects.rack[rackId])
- const machine = yield call(addMachineToRackOnTile, tileId, {
- id: -1,
- rackId,
+ const machine = {
+ _id: -1,
position: action.position,
- tags: [],
cpuIds: [],
gpuIds: [],
memoryIds: [],
storageIds: [],
- })
+ }
yield put(addToStore('machine', machine))
const machineIds = [...rack.machineIds]
- machineIds[machine.position - 1] = machine.id
+ machineIds[machine.position - 1] = machine._id
yield put(addPropToStoreObject('rack', rackId, { machineIds }))
+ yield updateTopologyOnServer(topologyId)
} catch (error) {
console.error(error)
}
@@ -355,16 +238,15 @@ export function* onAddMachine(action) {
export function* onDeleteMachine() {
try {
- const tileId = yield select(state => state.interactionLevel.tileId)
- const position = yield select(state => state.interactionLevel.position)
- const rack = yield select(
- state => state.objects.rack[state.objects.tile[tileId].objectId],
- )
- yield call(deleteMachineInRackOnTile, tileId, position)
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const tileId = yield select((state) => state.interactionLevel.tileId)
+ const position = yield select((state) => state.interactionLevel.position)
+ const rack = yield select((state) => state.objects.rack[state.objects.tile[tileId].rackId])
const machineIds = [...rack.machineIds]
machineIds[position - 1] = null
yield put(goDownOneInteractionLevel())
- yield put(addPropToStoreObject('rack', rack.id, { machineIds }))
+ yield put(addPropToStoreObject('rack', rack._id, { machineIds }))
+ yield updateTopologyOnServer(topologyId)
} catch (error) {
console.error(error)
}
@@ -372,15 +254,12 @@ export function* onDeleteMachine() {
export function* onAddUnit(action) {
try {
- const tileId = yield select(state => state.interactionLevel.tileId)
- const position = yield select(state => state.interactionLevel.position)
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const tileId = yield select((state) => state.interactionLevel.tileId)
+ const position = yield select((state) => state.interactionLevel.position)
const machine = yield select(
- state =>
- state.objects.machine[
- state.objects.rack[state.objects.tile[tileId].objectId].machineIds[
- position - 1
- ]
- ],
+ (state) =>
+ state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]]
)
if (machine[action.unitType + 'Ids'].length >= MAX_NUM_UNITS_PER_MACHINE) {
@@ -388,17 +267,12 @@ export function* onAddUnit(action) {
}
const units = [...machine[action.unitType + 'Ids'], action.id]
- const updatedMachine = Object.assign({}, machine, {
- [action.unitType + 'Ids']: units,
- })
-
- yield call(updateMachineInRackOnTile, tileId, position, updatedMachine)
-
yield put(
- addPropToStoreObject('machine', machine.id, {
+ addPropToStoreObject('machine', machine._id, {
[action.unitType + 'Ids']: units,
- }),
+ })
)
+ yield updateTopologyOnServer(topologyId)
} catch (error) {
console.error(error)
}
@@ -406,28 +280,22 @@ export function* onAddUnit(action) {
export function* onDeleteUnit(action) {
try {
- const tileId = yield select(state => state.interactionLevel.tileId)
- const position = yield select(state => state.interactionLevel.position)
+ const topologyId = yield select((state) => state.currentTopologyId)
+ const tileId = yield select((state) => state.interactionLevel.tileId)
+ const position = yield select((state) => state.interactionLevel.position)
const machine = yield select(
- state =>
- state.objects.machine[
- state.objects.rack[state.objects.tile[tileId].objectId].machineIds[
- position - 1
- ]
- ],
+ (state) =>
+ state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]]
)
const unitIds = machine[action.unitType + 'Ids'].slice()
unitIds.splice(action.index, 1)
- const updatedMachine = Object.assign({}, machine, {
- [action.unitType + 'Ids']: unitIds,
- })
- yield call(updateMachineInRackOnTile, tileId, position, updatedMachine)
yield put(
- addPropToStoreObject('machine', machine.id, {
+ addPropToStoreObject('machine', machine._id, {
[action.unitType + 'Ids']: unitIds,
- }),
+ })
)
+ yield updateTopologyOnServer(topologyId)
} catch (error) {
console.error(error)
}
diff --git a/frontend/src/sagas/users.js b/frontend/src/sagas/users.js
index a10887a0..a95893d2 100644
--- a/frontend/src/sagas/users.js
+++ b/frontend/src/sagas/users.js
@@ -9,10 +9,7 @@ import { fetchAndStoreSimulation, fetchAndStoreUser } from './objects'
export function* onFetchLoggedInUser(action) {
try {
- const tokenResponse = yield call(
- performTokenSignIn,
- action.payload.authToken,
- )
+ const tokenResponse = yield call(performTokenSignIn, action.payload.authToken)
let userId = tokenResponse.userId
@@ -38,10 +35,7 @@ export function* onFetchAuthorizationsOfCurrentUser(action) {
yield fetchAndStoreSimulation(authorization.simulationId)
}
- const authorizationIds = user.authorizations.map(authorization => [
- action.userId,
- authorization.simulationId,
- ])
+ const authorizationIds = user.authorizations.map((authorization) => [action.userId, authorization.simulationId])
yield put(fetchAuthorizationsOfCurrentUserSucceeded(authorizationIds))
} catch (error) {