summaryrefslogtreecommitdiff
path: root/src/sagas/topology.js
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-08-25 17:48:12 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:44 +0200
commitc47a27b826f7d76410308a4151611a366f9eaf46 (patch)
treec1ca374204714cedabcacb8620848b903a0bf8d6 /src/sagas/topology.js
parent1ddbbd3563af77a218020021ea50a8832900b4db (diff)
Fetch and display datacenter topology
Diffstat (limited to 'src/sagas/topology.js')
-rw-r--r--src/sagas/topology.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/sagas/topology.js b/src/sagas/topology.js
new file mode 100644
index 00000000..6d359534
--- /dev/null
+++ b/src/sagas/topology.js
@@ -0,0 +1,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;
+ }
+ console.log(tile);
+ 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");
+ }
+}