summaryrefslogtreecommitdiff
path: root/src/sagas/topology.js
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-07 11:38:42 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:58 +0200
commite9909159dc5db91eda12437e18c1474cae848af7 (patch)
treef34e0ca56b666f6a4ab1022e58a6dcd84b779725 /src/sagas/topology.js
parentd5a92d3006561fd631279b68b23a1f8075b28bb8 (diff)
Implement first machine slot listing
Diffstat (limited to 'src/sagas/topology.js')
-rw-r--r--src/sagas/topology.js86
1 files changed, 84 insertions, 2 deletions
diff --git a/src/sagas/topology.js b/src/sagas/topology.js
index ab544bbe..2ae31074 100644
--- a/src/sagas/topology.js
+++ b/src/sagas/topology.js
@@ -1,26 +1,40 @@
import {call, put, select} from "redux-saga/effects";
import {addPropToStoreObject, addToStore} from "../actions/objects";
import {
+ addMachineSucceeded,
addRackToTileSucceeded,
addTileSucceeded,
cancelNewRoomConstructionSucceeded,
+ deleteRackSucceeded,
deleteRoomSucceeded,
deleteTileSucceeded,
+ editRackNameSucceeded,
editRoomNameSucceeded,
fetchLatestDatacenterSucceeded,
startNewRoomConstructionSucceeded
} from "../actions/topology";
import {addRoomToDatacenter} from "../api/routes/datacenters";
import {addTileToRoom, deleteRoom, updateRoom} from "../api/routes/rooms";
-import {addRackToTile, deleteTile} from "../api/routes/tiles";
+import {
+ addMachineToRackOnTile,
+ addRackToTile,
+ deleteRackFromTile,
+ deleteTile,
+ updateRackOnTile
+} from "../api/routes/tiles";
import {
fetchAndStoreCoolingItem,
+ fetchAndStoreCPU,
fetchAndStoreDatacenter,
+ fetchAndStoreGPU,
+ fetchAndStoreMachinesOfTile,
+ fetchAndStoreMemory,
fetchAndStorePathsOfSimulation,
fetchAndStorePSU,
fetchAndStoreRackOnTile,
fetchAndStoreRoomsOfDatacenter,
fetchAndStoreSectionsOfPath,
+ fetchAndStoreStorage,
fetchAndStoreTilesOfRoom
} from "./objects";
@@ -69,6 +83,7 @@ function* fetchTile(tile) {
case "RACK":
const rack = yield fetchAndStoreRackOnTile(tile.objectId, tile.id);
yield put(addPropToStoreObject("tile", tile.id, {rackId: rack.id}));
+ yield fetchMachinesOfRack(tile.id, rack);
break;
case "COOLING_ITEM":
const coolingItem = yield fetchAndStoreCoolingItem(tile.objectId);
@@ -79,7 +94,30 @@ function* fetchTile(tile) {
yield put(addPropToStoreObject("tile", tile.id, {psuId: psu.id}));
break;
default:
- console.warn("Unknown object type encountered while fetching tile objects");
+ console.warn("Unknown rack type encountered while fetching tile objects");
+ }
+}
+
+function* fetchMachinesOfRack(tileId, rack) {
+ const machines = yield fetchAndStoreMachinesOfTile(tileId);
+ const machineIds = new Array(rack.capacity).fill(null);
+ machines.forEach(machine => machineIds[machine.position] = machine.id);
+
+ yield put(addPropToStoreObject("rack", rack.id, {machineIds}));
+
+ for (let index in machines) {
+ for (let i in machines[index].cpuIds) {
+ yield fetchAndStoreCPU(machines[index].cpuIds[i]);
+ }
+ for (let i in machines[index].gpuIds) {
+ yield fetchAndStoreGPU(machines[index].gpuIds[i]);
+ }
+ for (let i in machines[index].memoryIds) {
+ yield fetchAndStoreMemory(machines[index].memoryIds[i]);
+ }
+ for (let i in machines[index].storageIds) {
+ yield fetchAndStoreStorage(machines[index].storageIds[i]);
+ }
}
}
@@ -155,6 +193,29 @@ export function* onDeleteRoom() {
}
}
+export function* onEditRackName(action) {
+ try {
+ const tileId = yield select(state => state.interactionLevel.tileId);
+ const rackId = yield select(state => state.objects.tile[state.interactionLevel.tileId].objectId);
+ const rack = Object.assign({}, yield select(state => state.objects.rack[rackId]));
+ rack.name = action.name;
+ yield call(updateRackOnTile, tileId, rack);
+ yield put(editRackNameSucceeded(action.name));
+ } catch (error) {
+ console.log(error);
+ }
+}
+
+export function* onDeleteRack() {
+ try {
+ const tileId = yield select(state => state.interactionLevel.tileId);
+ yield call(deleteRackFromTile, tileId);
+ yield put(deleteRackSucceeded());
+ } catch (error) {
+ console.log(error);
+ }
+}
+
export function* onAddRackToTile(action) {
try {
const rack = yield call(addRackToTile, action.tileId, {
@@ -170,3 +231,24 @@ export function* onAddRackToTile(action) {
console.log(error);
}
}
+
+export function* onAddMachine(action) {
+ try {
+ const tileId = yield select(state => state.interactionLevel.tileId);
+ const rackId = yield select(state => state.objects.tile[state.interactionLevel.tileId].objectId);
+ const machine = yield call(addMachineToRackOnTile, tileId, {
+ id: -1,
+ rackId,
+ position: action.position,
+ tags: [],
+ cpuIds: [],
+ gpuIds: [],
+ memoryIds: [],
+ storageIds: [],
+ });
+ yield put(addToStore("machine", machine));
+ yield put(addMachineSucceeded(machine));
+ } catch (error) {
+ console.log(error);
+ }
+}