summaryrefslogtreecommitdiff
path: root/frontend/src/sagas
diff options
context:
space:
mode:
authorjc0b <j@jc0b.computer>2020-07-22 16:28:47 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:48:21 +0200
commitd7469b9ebb01cf36a78cc98aab31fa8f307c4f65 (patch)
treed0535fa0cfe95001302fbd2b0d046d51caab6ffd /frontend/src/sagas
parent67b6ec800df8e023efadb60ae5f7919030b19789 (diff)
parent9e7cb3bd367607b32e102c3a87b68b33c53dec46 (diff)
Merge branch 'master' onto working copy
Diffstat (limited to 'frontend/src/sagas')
-rw-r--r--frontend/src/sagas/index.js13
-rw-r--r--frontend/src/sagas/objects.js49
-rw-r--r--frontend/src/sagas/portfolios.js43
-rw-r--r--frontend/src/sagas/scenarios.js19
-rw-r--r--frontend/src/sagas/topology.js28
5 files changed, 86 insertions, 66 deletions
diff --git a/frontend/src/sagas/index.js b/frontend/src/sagas/index.js
index daae8d8c..9f6c4809 100644
--- a/frontend/src/sagas/index.js
+++ b/frontend/src/sagas/index.js
@@ -1,10 +1,6 @@
import { takeEvery } from 'redux-saga/effects'
import { LOG_IN } from '../actions/auth'
-import {
- ADD_PORTFOLIO,
- DELETE_PORTFOLIO,
- OPEN_PORTFOLIO_SUCCEEDED, UPDATE_PORTFOLIO,
-} from '../actions/portfolios'
+import { ADD_PORTFOLIO, DELETE_PORTFOLIO, OPEN_PORTFOLIO_SUCCEEDED, UPDATE_PORTFOLIO } from '../actions/portfolios'
import { ADD_PROJECT, DELETE_PROJECT, OPEN_PROJECT_SUCCEEDED } from '../actions/projects'
import {
ADD_TILE,
@@ -16,12 +12,7 @@ import { ADD_UNIT, DELETE_MACHINE, DELETE_UNIT } from '../actions/topology/machi
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 {
- onAddPortfolio,
- onDeletePortfolio,
- onOpenPortfolioSucceeded,
- onUpdatePortfolio,
-} from './portfolios'
+import { onAddPortfolio, onDeletePortfolio, onOpenPortfolioSucceeded, onUpdatePortfolio } from './portfolios'
import { onDeleteCurrentUser } from './profile'
import { onOpenProjectSucceeded, onProjectAdd, onProjectDelete } from './projects'
import {
diff --git a/frontend/src/sagas/objects.js b/frontend/src/sagas/objects.js
index 17b28d02..83d71a42 100644
--- a/frontend/src/sagas/objects.js
+++ b/frontend/src/sagas/objects.js
@@ -96,7 +96,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,
@@ -128,7 +128,6 @@ export const fetchAndStoreTopology = function* (id) {
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
}
@@ -142,6 +141,12 @@ const generateIdIfNotPresent = (obj) => {
}
export const updateTopologyOnServer = function* (id) {
+ const topology = yield getTopologyAsObject(id, true)
+
+ yield call(updateTopology, topology)
+}
+
+export const getTopologyAsObject = function* (id, keepIds) {
const topologyStore = yield select(OBJECT_SELECTORS['topology'])
const roomStore = yield select(OBJECT_SELECTORS['room'])
const tileStore = yield select(OBJECT_SELECTORS['tile'])
@@ -152,39 +157,37 @@ export const updateTopologyOnServer = function* (id) {
const memoryStore = yield select(OBJECT_SELECTORS['memory'])
const storageStore = yield select(OBJECT_SELECTORS['storage'])
- const topology = {
- _id: id,
+ return {
+ _id: keepIds ? id : undefined,
name: topologyStore[id].name,
rooms: topologyStore[id].roomIds.map((roomId) => ({
- _id: roomId,
+ _id: keepIds ? roomId : undefined,
name: roomStore[roomId].name,
tiles: roomStore[roomId].tileIds.map((tileId) => ({
- _id: tileId,
+ _id: keepIds ? tileId : undefined,
positionX: tileStore[tileId].positionX,
positionY: tileStore[tileId].positionY,
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: keepIds ? rackStore[tileStore[tileId].rackId]._id : undefined,
+ 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: keepIds ? machineId : undefined,
+ 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]),
+ })),
+ },
})),
})),
}
-
- yield call(updateTopology, topology)
}
export const fetchAndStoreAllTraces = () => fetchAndStoreObjects('trace', call(getAllTraces))
diff --git a/frontend/src/sagas/portfolios.js b/frontend/src/sagas/portfolios.js
index cda1be9b..ed9bfd29 100644
--- a/frontend/src/sagas/portfolios.js
+++ b/frontend/src/sagas/portfolios.js
@@ -1,4 +1,4 @@
-import { call, put, select } from 'redux-saga/effects'
+import { call, put, select, delay } from 'redux-saga/effects'
import { addPropToStoreObject, addToStore } from '../actions/objects'
import { addPortfolio, deletePortfolio, getPortfolio, updatePortfolio } from '../api/routes/portfolios'
import { getProject } from '../api/routes/projects'
@@ -15,7 +15,34 @@ export function* onOpenPortfolioSucceeded(action) {
yield fetchAndStoreAllSchedulers()
yield fetchAndStoreAllTraces()
- // TODO Fetch portfolio-specific metrics
+ yield watchForPortfolioResults()
+ } catch (error) {
+ console.error(error)
+ }
+}
+
+export function* watchForPortfolioResults() {
+ try {
+ const currentPortfolioId = yield select((state) => state.currentPortfolioId)
+ let unfinishedScenarios = yield getCurrentUnfinishedScenarios()
+
+ while (unfinishedScenarios.length > 0) {
+ yield delay(3000)
+ yield fetchPortfolioWithScenarios(currentPortfolioId)
+ unfinishedScenarios = yield getCurrentUnfinishedScenarios()
+ }
+ } catch (error) {
+ console.error(error)
+ }
+}
+
+export function* getCurrentUnfinishedScenarios() {
+ try {
+ const currentPortfolioId = yield select((state) => state.currentPortfolioId)
+ const scenarioIds = yield select((state) => state.objects.portfolio[currentPortfolioId].scenarioIds)
+ const scenarioObjects = yield select((state) => state.objects.scenario)
+ const scenarios = scenarioIds.map((s) => scenarioObjects[s])
+ return scenarios.filter((s) => !s || s.simulation.state === 'QUEUED' || s.simulation.state === 'RUNNING')
} catch (error) {
console.error(error)
}
@@ -62,7 +89,7 @@ export function* onAddPortfolio(action) {
Object.assign({}, action.portfolio, {
projectId: currentProjectId,
scenarioIds: [],
- }),
+ })
)
yield put(addToStore('portfolio', portfolio))
@@ -70,7 +97,7 @@ export function* onAddPortfolio(action) {
yield put(
addPropToStoreObject('project', currentProjectId, {
portfolioIds: portfolioIds.concat([portfolio._id]),
- }),
+ })
)
} catch (error) {
console.error(error)
@@ -79,11 +106,7 @@ export function* onAddPortfolio(action) {
export function* onUpdatePortfolio(action) {
try {
- const portfolio = yield call(
- updatePortfolio,
- action.portfolio._id,
- action.portfolio,
- )
+ const portfolio = yield call(updatePortfolio, action.portfolio._id, action.portfolio)
yield put(addToStore('portfolio', portfolio))
} catch (error) {
console.error(error)
@@ -100,7 +123,7 @@ export function* onDeletePortfolio(action) {
yield put(
addPropToStoreObject('project', currentProjectId, {
portfolioIds: portfolioIds.filter((id) => id !== action.id),
- }),
+ })
)
} catch (error) {
console.error(error)
diff --git a/frontend/src/sagas/scenarios.js b/frontend/src/sagas/scenarios.js
index 48b1e9be..720c0c97 100644
--- a/frontend/src/sagas/scenarios.js
+++ b/frontend/src/sagas/scenarios.js
@@ -4,7 +4,7 @@ import { getProject } from '../api/routes/projects'
import { fetchAndStoreAllSchedulers, fetchAndStoreAllTraces } from './objects'
import { fetchAndStoreAllTopologiesOfProject } from './topology'
import { addScenario, deleteScenario, updateScenario } from '../api/routes/scenarios'
-import { fetchPortfolioWithScenarios } from './portfolios'
+import { fetchPortfolioWithScenarios, watchForPortfolioResults } from './portfolios'
export function* onOpenScenarioSucceeded(action) {
try {
@@ -23,19 +23,16 @@ export function* onOpenScenarioSucceeded(action) {
export function* onAddScenario(action) {
try {
- const scenario = yield call(
- addScenario,
- action.scenario.portfolioId,
- action.scenario,
- )
+ const scenario = yield call(addScenario, action.scenario.portfolioId, action.scenario)
yield put(addToStore('scenario', scenario))
const scenarioIds = yield select((state) => state.objects.portfolio[action.scenario.portfolioId].scenarioIds)
yield put(
addPropToStoreObject('portfolio', action.scenario.portfolioId, {
scenarioIds: scenarioIds.concat([scenario._id]),
- }),
+ })
)
+ yield watchForPortfolioResults()
} catch (error) {
console.error(error)
}
@@ -43,11 +40,7 @@ export function* onAddScenario(action) {
export function* onUpdateScenario(action) {
try {
- const scenario = yield call(
- updateScenario,
- action.scenario._id,
- action.scenario,
- )
+ const scenario = yield call(updateScenario, action.scenario._id, action.scenario)
yield put(addToStore('scenario', scenario))
} catch (error) {
console.error(error)
@@ -64,7 +57,7 @@ export function* onDeleteScenario(action) {
yield put(
addPropToStoreObject('scenario', currentPortfolioId, {
scenarioIds: scenarioIds.filter((id) => id !== action.id),
- }),
+ })
)
} catch (error) {
console.error(error)
diff --git a/frontend/src/sagas/topology.js b/frontend/src/sagas/topology.js
index e915f9ff..bba1ebb1 100644
--- a/frontend/src/sagas/topology.js
+++ b/frontend/src/sagas/topology.js
@@ -16,7 +16,7 @@ import {
DEFAULT_RACK_SLOT_CAPACITY,
MAX_NUM_UNITS_PER_MACHINE,
} from '../components/app/map/MapConstants'
-import { fetchAndStoreTopology, updateTopologyOnServer } from './objects'
+import { fetchAndStoreTopology, getTopologyAsObject, updateTopologyOnServer } from './objects'
import { uuid } from 'uuidv4'
import { addTopology, deleteTopology } from '../api/routes/topologies'
@@ -40,11 +40,21 @@ export function* onAddTopology(action) {
try {
const currentProjectId = yield select((state) => state.currentProjectId)
+ let topologyToBeCreated
+ if (action.duplicateId) {
+ topologyToBeCreated = yield getTopologyAsObject(action.duplicateId, false)
+ topologyToBeCreated = Object.assign({}, topologyToBeCreated, {
+ name: action.name,
+ })
+ } else {
+ topologyToBeCreated = { name: action.name, rooms: [] }
+ }
+
const topology = yield call(
addTopology,
- Object.assign({}, action.topology, {
+ Object.assign({}, topologyToBeCreated, {
projectId: currentProjectId,
- }),
+ })
)
yield fetchAndStoreTopology(topology._id)
@@ -52,7 +62,7 @@ export function* onAddTopology(action) {
yield put(
addPropToStoreObject('project', currentProjectId, {
topologyIds: topologyIds.concat([topology._id]),
- }),
+ })
)
yield put(setCurrentTopology(topology._id))
} catch (error) {
@@ -74,7 +84,7 @@ export function* onDeleteTopology(action) {
yield put(
addPropToStoreObject('project', currentProjectId, {
topologyIds: topologyIds.filter((id) => id !== action.id),
- }),
+ })
)
} catch (error) {
console.error(error)
@@ -258,7 +268,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) {
@@ -269,7 +279,7 @@ export function* onAddUnit(action) {
yield put(
addPropToStoreObject('machine', machine._id, {
[action.unitType + 'Ids']: units,
- }),
+ })
)
yield updateTopologyOnServer(topologyId)
} catch (error) {
@@ -284,7 +294,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)
@@ -292,7 +302,7 @@ export function* onDeleteUnit(action) {
yield put(
addPropToStoreObject('machine', machine._id, {
[action.unitType + 'Ids']: unitIds,
- }),
+ })
)
yield updateTopologyOnServer(topologyId)
} catch (error) {