From 0439ccf76f9ccf68c7572deadf38d6a157c439e7 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Thu, 21 Sep 2017 15:10:15 +0200 Subject: Implement last-simulated-tick and states fetching --- .../sidebars/simulation/TaskComponent.js | 6 +-- .../sidebars/simulation/TraceComponent.js | 13 +++--- .../timeline/TimelineControlsComponent.js | 4 +- .../topology/machine/MachineSidebarContainer.js | 3 +- .../timeline/TimelineControlsContainer.js | 4 +- src/reducers/index.js | 3 +- src/reducers/interaction-level.js | 2 + src/reducers/states.js | 2 +- src/sagas/experiments.js | 47 +++++++++++++++++++++- 9 files changed, 69 insertions(+), 15 deletions(-) diff --git a/src/components/sidebars/simulation/TaskComponent.js b/src/components/sidebars/simulation/TaskComponent.js index 9a26e720..c02d0a4b 100644 --- a/src/components/sidebars/simulation/TaskComponent.js +++ b/src/components/sidebars/simulation/TaskComponent.js @@ -5,16 +5,16 @@ const TaskComponent = ({task, flopsLeft}) => { let stateInfo; if (flopsLeft === task.totalFlopCount) { - stateInfo =

Waiting

; + stateInfo =

Waiting

; } else if (flopsLeft > 0) { stateInfo = (

- + Running ({task.totalFlopCount - flopsLeft} / {task.totalFlopCount} FLOPS)

); } else { - stateInfo =

Completed

; + stateInfo =

Completed

; } return ( diff --git a/src/components/sidebars/simulation/TraceComponent.js b/src/components/sidebars/simulation/TraceComponent.js index 498fe5bf..ffb470ba 100644 --- a/src/components/sidebars/simulation/TraceComponent.js +++ b/src/components/sidebars/simulation/TraceComponent.js @@ -5,11 +5,14 @@ const TraceComponent = ({jobs}) => (

Trace

{jobs.map(job => ( - +
+

Job: {job.name}

+
    + {job.taskIds.map(taskId => ( + + ))} +
+
))}
); diff --git a/src/components/timeline/TimelineControlsComponent.js b/src/components/timeline/TimelineControlsComponent.js index 3f37c3bc..2e093583 100644 --- a/src/components/timeline/TimelineControlsComponent.js +++ b/src/components/timeline/TimelineControlsComponent.js @@ -5,10 +5,10 @@ function getXPercentage(tick, maxTick) { if (maxTick === 0) { return "0%"; } else if (tick > maxTick) { - return "100%"; + return ((maxTick / (maxTick + 1)) * 100) + "%"; } - return (tick / maxTick) + "%"; + return ((tick / (maxTick + 1)) * 100) + "%"; } const TimelineControlsComponent = ({currentTick, lastSimulatedTick, sectionTicks}) => ( diff --git a/src/containers/sidebars/topology/machine/MachineSidebarContainer.js b/src/containers/sidebars/topology/machine/MachineSidebarContainer.js index b0d5eed9..f99fc05e 100644 --- a/src/containers/sidebars/topology/machine/MachineSidebarContainer.js +++ b/src/containers/sidebars/topology/machine/MachineSidebarContainer.js @@ -3,8 +3,9 @@ import MachineSidebarComponent from "../../../../components/sidebars/topology/ma const mapStateToProps = state => { return { - machineId: state.interactionLevel.machineId, inSimulation: state.currentExperimentId !== -1, + machineId: state.objects.rack[state.objects.tile[state.interactionLevel.tileId].objectId] + .machineIds[state.interactionLevel.position - 1], }; }; diff --git a/src/containers/timeline/TimelineControlsContainer.js b/src/containers/timeline/TimelineControlsContainer.js index 1afd336a..16d44052 100644 --- a/src/containers/timeline/TimelineControlsContainer.js +++ b/src/containers/timeline/TimelineControlsContainer.js @@ -6,7 +6,9 @@ const mapStateToProps = state => { if (state.currentExperimentId !== -1) { const sectionIds = state.objects.path[state.objects.experiment[state.currentExperimentId].pathId].sectionIds; if (sectionIds) { - sectionTicks = sectionIds.map(sectionId => state.objects.section[sectionId].startTick); + sectionTicks = sectionIds + .filter(sectionId => state.objects.section[sectionId].startTick !== 0) + .map(sectionId => state.objects.section[sectionId].startTick); } } diff --git a/src/reducers/index.js b/src/reducers/index.js index a9b6bf34..17b75182 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -7,7 +7,7 @@ import {map} from "./map"; import {modals} from "./modals"; import {objects} from "./objects"; import {simulationList} from "./simulation-list"; -import {currentExperimentId, currentTick, isPlaying, loadMetric} from "./simulation-mode"; +import {currentExperimentId, currentTick, isPlaying, lastSimulatedTick, loadMetric} from "./simulation-mode"; import {states} from "./states"; const rootReducer = combineReducers({ @@ -21,6 +21,7 @@ const rootReducer = combineReducers({ currentDatacenterId, currentExperimentId, currentTick, + lastSimulatedTick, loadMetric, isPlaying, interactionLevel, diff --git a/src/reducers/interaction-level.js b/src/reducers/interaction-level.js index 282e5096..5a45fc68 100644 --- a/src/reducers/interaction-level.js +++ b/src/reducers/interaction-level.js @@ -6,11 +6,13 @@ import { GO_FROM_ROOM_TO_RACK } from "../actions/interaction-level"; import {OPEN_SIMULATION_SUCCEEDED} from "../actions/simulations"; +import {SET_CURRENT_DATACENTER} from "../actions/topology/building"; export function interactionLevel(state = {mode: "BUILDING"}, action) { switch (action.type) { case OPEN_EXPERIMENT_SUCCEEDED: case OPEN_SIMULATION_SUCCEEDED: + case SET_CURRENT_DATACENTER: return { mode: "BUILDING" }; diff --git a/src/reducers/states.js b/src/reducers/states.js index a9eb4ce8..d74c924c 100644 --- a/src/reducers/states.js +++ b/src/reducers/states.js @@ -22,7 +22,7 @@ function objectStates(type) { [action.tick]: Object.assign( {}, state[action.tick], - {[action.object.id]: action.object} + {[action.object[action.objectType + "Id"]]: action.object} ) } ); diff --git a/src/sagas/experiments.js b/src/sagas/experiments.js index 29f9a211..5bcd6948 100644 --- a/src/sagas/experiments.js +++ b/src/sagas/experiments.js @@ -1,6 +1,17 @@ +import {delay} from "redux-saga"; import {call, put, select} from "redux-saga/effects"; import {addPropToStoreObject, addToStore} from "../actions/objects"; -import {deleteExperiment, getExperiment} from "../api/routes/experiments"; +import {setLastSimulatedTick} from "../actions/simulation/tick"; +import {addToStates} from "../actions/states"; +import { + deleteExperiment, + 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"; @@ -19,11 +30,45 @@ export function* onOpenExperimentSucceeded(action) { yield fetchWorkloadOfTrace(experiment.traceId); yield fetchAllDatacentersOfExperiment(experiment); + yield startStateFetchLoop(action.experimentId); } catch (error) { console.error(error); } } +function* startStateFetchLoop(experimentId) { + try { + while (true) { + const lastSimulatedTick = (yield call(getLastSimulatedTick, 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 addAllStates("task", taskStates); + yield addAllStates("machine", machineStates); + yield addAllStates("rack", rackStates); + yield addAllStates("room", roomStates); + + yield delay(5000); + } else { + yield delay(10000); + } + } + } catch (error) { + console.error(error); + } +} + +function* addAllStates(objectType, states) { + for (let i in states) { + yield put(addToStates(objectType, states[i].tick, states[i])); + } +} + export function* onFetchExperimentsOfSimulation() { try { const currentSimulationId = yield select(state => state.currentSimulationId); -- cgit v1.2.3