diff options
| author | Georgios Andreadis <info@gandreadis.com> | 2020-07-22 14:07:39 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-08-24 19:48:18 +0200 |
| commit | 92ce9387f5c3ce54b4077ef6a5f604fc2cfe6ade (patch) | |
| tree | 90432dbd06a13d300f8307dea342f4639c9c57e7 /frontend/src/sagas | |
| parent | ae8f03d514ba0982a34b96f1e29e262ca6048a19 (diff) | |
| parent | 8739a156b75ba96e15d1bb19b08ca829c1eb01e8 (diff) | |
Merge pull request #12 from atlarge-research/feature/scenario-plots
Plotting of portfolio results
Diffstat (limited to 'frontend/src/sagas')
| -rw-r--r-- | frontend/src/sagas/index.js | 13 | ||||
| -rw-r--r-- | frontend/src/sagas/objects.js | 32 | ||||
| -rw-r--r-- | frontend/src/sagas/portfolios.js | 43 | ||||
| -rw-r--r-- | frontend/src/sagas/scenarios.js | 19 | ||||
| -rw-r--r-- | frontend/src/sagas/topology.js | 14 |
5 files changed, 64 insertions, 57 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..1dbc7903 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, @@ -165,21 +165,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/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..14c1ed2d 100644 --- a/frontend/src/sagas/topology.js +++ b/frontend/src/sagas/topology.js @@ -44,7 +44,7 @@ export function* onAddTopology(action) { addTopology, Object.assign({}, action.topology, { projectId: currentProjectId, - }), + }) ) yield fetchAndStoreTopology(topology._id) @@ -52,7 +52,7 @@ export function* onAddTopology(action) { yield put( addPropToStoreObject('project', currentProjectId, { topologyIds: topologyIds.concat([topology._id]), - }), + }) ) yield put(setCurrentTopology(topology._id)) } catch (error) { @@ -74,7 +74,7 @@ export function* onDeleteTopology(action) { yield put( addPropToStoreObject('project', currentProjectId, { topologyIds: topologyIds.filter((id) => id !== action.id), - }), + }) ) } catch (error) { console.error(error) @@ -258,7 +258,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 +269,7 @@ export function* onAddUnit(action) { yield put( addPropToStoreObject('machine', machine._id, { [action.unitType + 'Ids']: units, - }), + }) ) yield updateTopologyOnServer(topologyId) } catch (error) { @@ -284,7 +284,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 +292,7 @@ export function* onDeleteUnit(action) { yield put( addPropToStoreObject('machine', machine._id, { [action.unitType + 'Ids']: unitIds, - }), + }) ) yield updateTopologyOnServer(topologyId) } catch (error) { |
