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
|
import {put} from "redux-saga/effects";
import {addPropToStoreObject} from "../actions/objects";
import {fetchLatestDatacenterSucceeded} from "../actions/topology";
import {
fetchAndStoreCoolingItem,
fetchAndStoreDatacenter,
fetchAndStorePathsOfSimulation,
fetchAndStorePSU,
fetchAndStoreRackOnTile,
fetchAndStoreRoomsOfDatacenter,
fetchAndStoreSectionsOfPath,
fetchAndStoreTilesOfRoom
} from "./objects";
export function* onFetchLatestDatacenter(action) {
try {
const paths = yield fetchAndStorePathsOfSimulation(action.currentSimulationId);
const latestPath = paths[paths.length - 1];
const sections = yield fetchAndStoreSectionsOfPath(latestPath.id);
const latestSection = sections[sections.length - 1];
yield fetchDatacenter(latestSection.datacenterId);
yield put(fetchLatestDatacenterSucceeded(latestSection.datacenterId));
} catch (error) {
console.log(error);
}
}
export function* fetchDatacenter(datacenterId) {
try {
const datacenter = yield fetchAndStoreDatacenter(datacenterId);
datacenter.roomIds = (yield fetchAndStoreRoomsOfDatacenter(datacenterId)).map(room => room.id);
for (let index in datacenter.roomIds) {
yield fetchRoom(datacenter.roomIds[index]);
}
} catch (error) {
console.log(error);
}
}
function* fetchRoom(roomId) {
const tiles = yield fetchAndStoreTilesOfRoom(roomId);
yield put(addPropToStoreObject("room", roomId, {tileIds: tiles.map(tile => tile.id)}));
for (let index in tiles) {
yield fetchTile(tiles[index]);
}
}
function* fetchTile(tile) {
if (!tile.objectType) {
return;
}
switch (tile.objectType) {
case "RACK":
const rack = yield fetchAndStoreRackOnTile(tile.objectId, tile.id);
yield put(addPropToStoreObject("tile", tile.id, {rackId: rack.id}));
break;
case "COOLING_ITEM":
const coolingItem = yield fetchAndStoreCoolingItem(tile.objectId);
yield put(addPropToStoreObject("tile", tile.id, {coolingItemId: coolingItem.id}));
break;
case "PSU":
const psu = yield fetchAndStorePSU(tile.objectId);
yield put(addPropToStoreObject("tile", tile.id, {psuId: psu.id}));
break;
default:
console.warn("Unknown object type encountered while fetching tile objects");
}
}
|