From f119fc78dda4d1e828dde04f378a63a93e3a0a7e Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Thu, 2 Jul 2020 18:39:28 +0200 Subject: Add current progress on frontend port --- frontend/src/sagas/experiments.js | 98 ++++++++++----------------------------- 1 file changed, 24 insertions(+), 74 deletions(-) (limited to 'frontend/src/sagas/experiments.js') 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) -- cgit v1.2.3