summaryrefslogtreecommitdiff
path: root/frontend/src/sagas
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-07-07 09:55:10 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:47:25 +0200
commitb4bdf9fde013bb7ff9579693b64ff575f7b00e44 (patch)
tree5e05ceba918849391a639bbeeab37d290a86523c /frontend/src/sagas
parent7331e9baf2cfe7bdfb24effcf0a4801da1e7ea4d (diff)
Rename simulations to projects and remove experiment view
Diffstat (limited to 'frontend/src/sagas')
-rw-r--r--frontend/src/sagas/experiments.js82
-rw-r--r--frontend/src/sagas/index.js16
-rw-r--r--frontend/src/sagas/objects.js38
-rw-r--r--frontend/src/sagas/projects.js43
-rw-r--r--frontend/src/sagas/simulations.js43
-rw-r--r--frontend/src/sagas/topology.js38
-rw-r--r--frontend/src/sagas/users.js6
7 files changed, 116 insertions, 150 deletions
diff --git a/frontend/src/sagas/experiments.js b/frontend/src/sagas/experiments.js
index e5aeeb46..f2b23017 100644
--- a/frontend/src/sagas/experiments.js
+++ b/frontend/src/sagas/experiments.js
@@ -1,22 +1,14 @@
-import { call, delay, put, select } from 'redux-saga/effects'
+import { call, put, select } from 'redux-saga/effects'
import { addPropToStoreObject, addToStore } from '../actions/objects'
-import { setLastSimulatedTick } from '../actions/simulation/tick'
-import { addBatchToStates } from '../actions/states'
-import {
- deleteExperiment,
- getAllMachineStates,
- getAllRackStates,
- getAllRoomStates,
- getExperiment,
-} from '../api/routes/experiments'
-import { addExperiment, getSimulation } from '../api/routes/simulations'
+import { deleteExperiment, getExperiment } from '../api/routes/experiments'
+import { addExperiment, getProject } from '../api/routes/projects'
import { fetchAndStoreAllSchedulers, fetchAndStoreAllTraces } from './objects'
-import { fetchAndStoreAllTopologiesOfSimulation, fetchTopologyOfExperiment } from './topology'
+import { fetchAndStoreAllTopologiesOfProject, fetchTopologyOfExperiment } from './topology'
export function* onOpenExperimentSucceeded(action) {
try {
- const simulation = yield call(getSimulation, action.simulationId)
- yield put(addToStore('simulation', simulation))
+ const project = yield call(getProject, action.projectId)
+ yield put(addToStore('project', project))
const experiment = yield call(getExperiment, action.experimentId)
yield put(addToStore('experiment', experiment))
@@ -24,46 +16,20 @@ export function* onOpenExperimentSucceeded(action) {
yield fetchExperimentSpecifications()
yield fetchTopologyOfExperiment(experiment)
- yield startStateFetchLoop(action.experimentId)
} catch (error) {
console.error(error)
}
}
-function* startStateFetchLoop(experimentId) {
+export function* onFetchExperimentsOfProject() {
try {
- 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 machineStates = yield call(getAllMachineStates, experimentId)
- const rackStates = yield call(getAllRackStates, experimentId)
- const roomStates = yield call(getAllRoomStates, experimentId)
-
- yield put(addBatchToStates('machine', machineStates))
- yield put(addBatchToStates('rack', rackStates))
- yield put(addBatchToStates('room', roomStates))
-
- yield delay(5000)
- } else {
- yield delay(10000)
- }
- }
- } catch (error) {
- console.error(error)
- }
-}
-
-export function* onFetchExperimentsOfSimulation() {
- try {
- const currentSimulationId = yield select((state) => state.currentSimulationId)
- const currentSimulation = yield select((state) => state.object.simulation[currentSimulationId])
+ const currentProjectId = yield select((state) => state.currentProjectId)
+ const currentProject = yield select((state) => state.object.project[currentProjectId])
yield fetchExperimentSpecifications()
- for (let i in currentSimulation.experimentIds) {
- const experiment = yield call(getExperiment, currentSimulation.experimentIds[i])
+ for (let i in currentProject.experimentIds) {
+ const experiment = yield call(getExperiment, currentProject.experimentIds[i])
yield put(addToStore('experiment', experiment))
}
} catch (error) {
@@ -73,8 +39,8 @@ export function* onFetchExperimentsOfSimulation() {
function* fetchExperimentSpecifications() {
try {
- const currentSimulationId = yield select((state) => state.currentSimulationId)
- yield fetchAndStoreAllTopologiesOfSimulation(currentSimulationId)
+ const currentProjectId = yield select((state) => state.currentProjectId)
+ yield fetchAndStoreAllTopologiesOfProject(currentProjectId)
yield fetchAndStoreAllTraces()
yield fetchAndStoreAllSchedulers()
} catch (error) {
@@ -84,23 +50,23 @@ function* fetchExperimentSpecifications() {
export function* onAddExperiment(action) {
try {
- const currentSimulationId = yield select((state) => state.currentSimulationId)
+ const currentProjectId = yield select((state) => state.currentProjectId)
const experiment = yield call(
addExperiment,
- currentSimulationId,
+ currentProjectId,
Object.assign({}, action.experiment, {
id: '-1',
- simulationId: currentSimulationId,
- })
+ projectId: currentProjectId,
+ }),
)
yield put(addToStore('experiment', experiment))
- const experimentIds = yield select((state) => state.objects.simulation[currentSimulationId].experimentIds)
+ const experimentIds = yield select((state) => state.objects.project[currentProjectId].experimentIds)
yield put(
- addPropToStoreObject('simulation', currentSimulationId, {
+ addPropToStoreObject('project', currentProjectId, {
experimentIds: experimentIds.concat([experiment._id]),
- })
+ }),
)
} catch (error) {
console.error(error)
@@ -111,13 +77,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 currentProjectId = yield select((state) => state.currentProjectId)
+ const experimentIds = yield select((state) => state.objects.project[currentProjectId].experimentIds)
yield put(
- addPropToStoreObject('simulation', currentSimulationId, {
+ addPropToStoreObject('project', currentProjectId, {
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 0947befc..26d19d58 100644
--- a/frontend/src/sagas/index.js
+++ b/frontend/src/sagas/index.js
@@ -3,10 +3,10 @@ import { LOG_IN } from '../actions/auth'
import {
ADD_EXPERIMENT,
DELETE_EXPERIMENT,
- FETCH_EXPERIMENTS_OF_SIMULATION,
+ FETCH_EXPERIMENTS_OF_PROJECT,
OPEN_EXPERIMENT_SUCCEEDED,
} from '../actions/experiments'
-import { ADD_SIMULATION, DELETE_SIMULATION, OPEN_SIMULATION_SUCCEEDED } from '../actions/simulations'
+import { ADD_PROJECT, DELETE_PROJECT, OPEN_PROJECT_SUCCEEDED } from '../actions/projects'
import {
ADD_TILE,
CANCEL_NEW_ROOM_CONSTRUCTION,
@@ -20,11 +20,11 @@ import { DELETE_CURRENT_USER, FETCH_AUTHORIZATIONS_OF_CURRENT_USER } from '../ac
import {
onAddExperiment,
onDeleteExperiment,
- onFetchExperimentsOfSimulation,
+ onFetchExperimentsOfProject,
onOpenExperimentSucceeded,
} from './experiments'
import { onDeleteCurrentUser } from './profile'
-import { onOpenSimulationSucceeded, onSimulationAdd, onSimulationDelete } from './simulations'
+import { onOpenProjectSucceeded, onProjectAdd, onProjectDelete } from './projects'
import {
onAddMachine,
onAddRackToTile,
@@ -49,12 +49,12 @@ 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(ADD_PROJECT, onProjectAdd)
+ yield takeEvery(DELETE_PROJECT, onProjectDelete)
yield takeEvery(DELETE_CURRENT_USER, onDeleteCurrentUser)
- yield takeEvery(OPEN_SIMULATION_SUCCEEDED, onOpenSimulationSucceeded)
+ yield takeEvery(OPEN_PROJECT_SUCCEEDED, onOpenProjectSucceeded)
yield takeEvery(OPEN_EXPERIMENT_SUCCEEDED, onOpenExperimentSucceeded)
yield takeEvery(ADD_TOPOLOGY, onAddTopology)
@@ -73,7 +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_PROJECT, onFetchExperimentsOfProject)
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 1a31c195..8a12bd13 100644
--- a/frontend/src/sagas/objects.js
+++ b/frontend/src/sagas/objects.js
@@ -1,14 +1,14 @@
import { call, put, select } from 'redux-saga/effects'
import { addToStore } from '../actions/objects'
import { getAllSchedulers } from '../api/routes/schedulers'
-import { getSimulation } from '../api/routes/simulations'
+import { getProject } from '../api/routes/projects'
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,
+ project: (state) => state.objects.project,
user: (state) => state.objects.user,
authorization: (state) => state.objects.authorization,
cpu: (state) => state.objects.cpu,
@@ -40,7 +40,7 @@ function* fetchAndStoreObjects(objectType, apiCall) {
return objects
}
-export const fetchAndStoreSimulation = (id) => fetchAndStoreObject('simulation', id, call(getSimulation, id))
+export const fetchAndStoreProject = (id) => fetchAndStoreObject('project', id, call(getProject, id))
export const fetchAndStoreUser = (id) => fetchAndStoreObject('user', id, call(getUser, id))
@@ -94,7 +94,7 @@ export const fetchAndStoreTopology = function* (id) {
const filledSlots = new Array(fullRack.capacity).fill(null)
fullRack.machines.forEach(
- (machine) => (filledSlots[machine.position - 1] = machine._id)
+ (machine) => (filledSlots[machine.position - 1] = machine._id),
)
let rack = (({ _id, name, capacity, powerCapacityW }) => ({
_id,
@@ -163,21 +163,21 @@ export const updateTopologyOnServer = function* (id) {
rack: !tileStore[tileId].rackId
? undefined
: {
- _id: rackStore[tileStore[tileId].rackId]._id,
- name: rackStore[tileStore[tileId].rackId].name,
- 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,
- cpus: machineStore[machineId].cpuIds.map((id) => cpuStore[id]),
- gpus: machineStore[machineId].gpuIds.map((id) => gpuStore[id]),
- memories: machineStore[machineId].memoryIds.map((id) => memoryStore[id]),
- storages: machineStore[machineId].storageIds.map((id) => storageStore[id]),
- })),
- },
+ _id: rackStore[tileStore[tileId].rackId]._id,
+ name: rackStore[tileStore[tileId].rackId].name,
+ 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,
+ cpus: machineStore[machineId].cpuIds.map((id) => cpuStore[id]),
+ gpus: machineStore[machineId].gpuIds.map((id) => gpuStore[id]),
+ memories: machineStore[machineId].memoryIds.map((id) => memoryStore[id]),
+ storages: machineStore[machineId].storageIds.map((id) => storageStore[id]),
+ })),
+ },
})),
})),
}
diff --git a/frontend/src/sagas/projects.js b/frontend/src/sagas/projects.js
new file mode 100644
index 00000000..d1f5e7f7
--- /dev/null
+++ b/frontend/src/sagas/projects.js
@@ -0,0 +1,43 @@
+import { call, put } from 'redux-saga/effects'
+import { addToStore } from '../actions/objects'
+import { addProjectSucceeded, deleteProjectSucceeded } from '../actions/projects'
+import { addProject, deleteProject, getProject } from '../api/routes/projects'
+import { fetchAndStoreAllTopologiesOfProject } from './topology'
+
+export function* onOpenProjectSucceeded(action) {
+ try {
+ const project = yield call(getProject, action.id)
+ yield put(addToStore('project', project))
+
+ yield fetchAndStoreAllTopologiesOfProject(action.id)
+ } catch (error) {
+ console.error(error)
+ }
+}
+
+export function* onProjectAdd(action) {
+ try {
+ const project = yield call(addProject, { name: action.name })
+ yield put(addToStore('project', project))
+
+ const authorization = {
+ projectId: project._id,
+ userId: action.userId,
+ authorizationLevel: 'OWN',
+ project,
+ }
+ yield put(addToStore('authorization', authorization))
+ yield put(addProjectSucceeded([authorization.userId, authorization.projectId]))
+ } catch (error) {
+ console.error(error)
+ }
+}
+
+export function* onProjectDelete(action) {
+ try {
+ yield call(deleteProject, action.id)
+ yield put(deleteProjectSucceeded(action.id))
+ } catch (error) {
+ console.error(error)
+ }
+}
diff --git a/frontend/src/sagas/simulations.js b/frontend/src/sagas/simulations.js
deleted file mode 100644
index be69fedd..00000000
--- a/frontend/src/sagas/simulations.js
+++ /dev/null
@@ -1,43 +0,0 @@
-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 { fetchAndStoreAllTopologiesOfSimulation } from './topology'
-
-export function* onOpenSimulationSucceeded(action) {
- try {
- const simulation = yield call(getSimulation, action.id)
- yield put(addToStore('simulation', simulation))
-
- yield fetchAndStoreAllTopologiesOfSimulation(action.id)
- } catch (error) {
- console.error(error)
- }
-}
-
-export function* onSimulationAdd(action) {
- try {
- const simulation = yield call(addSimulation, { name: action.name })
- yield put(addToStore('simulation', simulation))
-
- const authorization = {
- simulationId: simulation._id,
- userId: action.userId,
- authorizationLevel: 'OWN',
- simulation,
- }
- yield put(addToStore('authorization', authorization))
- yield put(addSimulationSucceeded([authorization.userId, authorization.simulationId]))
- } catch (error) {
- console.error(error)
- }
-}
-
-export function* onSimulationDelete(action) {
- try {
- yield call(deleteSimulation, action.id)
- yield put(deleteSimulationSucceeded(action.id))
- } catch (error) {
- console.error(error)
- }
-}
diff --git a/frontend/src/sagas/topology.js b/frontend/src/sagas/topology.js
index 2e55156b..008c7b63 100644
--- a/frontend/src/sagas/topology.js
+++ b/frontend/src/sagas/topology.js
@@ -29,15 +29,15 @@ export function* fetchTopologyOfExperiment(experiment) {
}
}
-export function* fetchAndStoreAllTopologiesOfSimulation(simulationId) {
+export function* fetchAndStoreAllTopologiesOfProject(projectId) {
try {
- const simulation = yield select((state) => state.objects.simulation[simulationId])
+ const project = yield select((state) => state.objects.project[projectId])
- for (let i in simulation.topologyIds) {
- yield fetchAndStoreTopology(simulation.topologyIds[i])
+ for (let i in project.topologyIds) {
+ yield fetchAndStoreTopology(project.topologyIds[i])
}
- yield put(setCurrentTopology(simulation.topologyIds[0]))
+ yield put(setCurrentTopology(project.topologyIds[0]))
} catch (error) {
console.error(error)
}
@@ -45,21 +45,21 @@ export function* fetchAndStoreAllTopologiesOfSimulation(simulationId) {
export function* onAddTopology(action) {
try {
- const currentSimulationId = yield select((state) => state.currentSimulationId)
+ const currentProjectId = yield select((state) => state.currentProjectId)
const topology = yield call(
addTopology,
Object.assign({}, action.topology, {
- simulationId: currentSimulationId,
- })
+ projectId: currentProjectId,
+ }),
)
yield fetchAndStoreTopology(topology._id)
- const topologyIds = yield select((state) => state.objects.simulation[currentSimulationId].topologyIds)
+ const topologyIds = yield select((state) => state.objects.project[currentProjectId].topologyIds)
yield put(
- addPropToStoreObject('simulation', currentSimulationId, {
+ addPropToStoreObject('project', currentProjectId, {
topologyIds: topologyIds.concat([topology._id]),
- })
+ }),
)
yield put(setCurrentTopology(topology._id))
} catch (error) {
@@ -69,8 +69,8 @@ export function* onAddTopology(action) {
export function* onDeleteTopology(action) {
try {
- const currentSimulationId = yield select((state) => state.currentSimulationId)
- const topologyIds = yield select((state) => state.objects.simulation[currentSimulationId].topologyIds)
+ const currentProjectId = yield select((state) => state.currentProjectId)
+ const topologyIds = yield select((state) => state.objects.project[currentProjectId].topologyIds)
const currentTopologyId = yield select((state) => state.currentTopologyId)
if (currentTopologyId === action.id) {
yield put(setCurrentTopology(topologyIds.filter((t) => t !== action.id)[0]))
@@ -79,9 +79,9 @@ export function* onDeleteTopology(action) {
yield call(deleteTopology, action.id)
yield put(
- addPropToStoreObject('simulation', currentSimulationId, {
+ addPropToStoreObject('project', currentProjectId, {
topologyIds: topologyIds.filter((id) => id !== action.id),
- })
+ }),
)
} catch (error) {
console.error(error)
@@ -265,7 +265,7 @@ export function* onAddUnit(action) {
const position = yield select((state) => state.interactionLevel.position)
const machine = yield select(
(state) =>
- state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]]
+ 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) {
@@ -276,7 +276,7 @@ export function* onAddUnit(action) {
yield put(
addPropToStoreObject('machine', machine._id, {
[action.unitType + 'Ids']: units,
- })
+ }),
)
yield updateTopologyOnServer(topologyId)
} catch (error) {
@@ -291,7 +291,7 @@ export function* onDeleteUnit(action) {
const position = yield select((state) => state.interactionLevel.position)
const machine = yield select(
(state) =>
- state.objects.machine[state.objects.rack[state.objects.tile[tileId].rackId].machineIds[position - 1]]
+ 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)
@@ -299,7 +299,7 @@ export function* onDeleteUnit(action) {
yield put(
addPropToStoreObject('machine', machine._id, {
[action.unitType + 'Ids']: unitIds,
- })
+ }),
)
yield updateTopologyOnServer(topologyId)
} catch (error) {
diff --git a/frontend/src/sagas/users.js b/frontend/src/sagas/users.js
index a95893d2..74e652f6 100644
--- a/frontend/src/sagas/users.js
+++ b/frontend/src/sagas/users.js
@@ -5,7 +5,7 @@ import { fetchAuthorizationsOfCurrentUserSucceeded } from '../actions/users'
import { performTokenSignIn } from '../api/routes/token-signin'
import { addUser } from '../api/routes/users'
import { saveAuthLocalStorage } from '../auth/index'
-import { fetchAndStoreSimulation, fetchAndStoreUser } from './objects'
+import { fetchAndStoreProject, fetchAndStoreUser } from './objects'
export function* onFetchLoggedInUser(action) {
try {
@@ -32,10 +32,10 @@ export function* onFetchAuthorizationsOfCurrentUser(action) {
for (const authorization of user.authorizations) {
authorization.userId = action.userId
yield put(addToStore('authorization', authorization))
- yield fetchAndStoreSimulation(authorization.simulationId)
+ yield fetchAndStoreProject(authorization.projectId)
}
- const authorizationIds = user.authorizations.map((authorization) => [action.userId, authorization.simulationId])
+ const authorizationIds = user.authorizations.map((authorization) => [action.userId, authorization.projectId])
yield put(fetchAuthorizationsOfCurrentUserSucceeded(authorizationIds))
} catch (error) {