1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
import {delay} from "redux-saga";
import {call, put, select} from "redux-saga/effects";
import {addPropToStoreObject, addToStore} from "../actions/objects";
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";
import {fetchAndStoreAllSchedulers, fetchAndStoreAllTraces, fetchAndStorePathsOfSimulation} from "./objects";
import {fetchAllDatacentersOfExperiment} from "./topology";
export function* onOpenExperimentSucceeded(action) {
try {
const simulation = yield call(getSimulation, action.simulationId);
yield put(addToStore("simulation", simulation));
const experiment = yield call(getExperiment, action.experimentId);
yield put(addToStore("experiment", experiment));
yield fetchExperimentSpecifications();
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);
yield fetchExperimentSpecifications();
const experiments = yield call(getExperimentsOfSimulation, currentSimulationId);
for (let i in experiments) {
yield put(addToStore("experiment", experiments[i]));
}
yield put(addPropToStoreObject("simulation", currentSimulationId,
{experimentIds: experiments.map(experiment => experiment.id)}));
} catch (error) {
console.error(error);
}
}
function* fetchExperimentSpecifications() {
try {
const currentSimulationId = yield select(state => state.currentSimulationId);
yield fetchAndStorePathsOfSimulation(currentSimulationId);
yield fetchAndStoreAllTraces();
yield fetchAndStoreAllSchedulers();
} catch (error) {
console.error(error);
}
}
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 experiment = yield call(addExperiment,
currentSimulationId,
Object.assign({}, action.experiment, {
id: -1,
simulationId: currentSimulationId
})
);
yield put(addToStore("experiment", experiment));
const experimentIds = yield select(state => state.objects.simulation[currentSimulationId].experimentIds);
yield put(addPropToStoreObject("simulation", currentSimulationId,
{experimentIds: experimentIds.concat([experiment.id])}));
} catch (error) {
console.error(error);
}
}
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);
yield put(addPropToStoreObject("simulation", currentSimulationId,
{experimentIds: experimentIds.filter(id => id !== action.id)}));
} catch (error) {
console.error(error);
}
}
|