diff --git a/.vscode/launch.json b/.vscode/launch.json index ea93a50..bef6011 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,15 +1,3 @@ { - "configurations": [ - { - "type": "node", - "name": "vscode-jest-tests", - "request": "launch", - "console": "integratedTerminal", - "internalConsoleOptions": "neverOpen", - "disableOptimisticBPs": true, - "cwd": "${workspaceFolder}", - "runtimeExecutable": "npm", - "args": ["test", "--runInBand", "--watchAll=false"] - } - ] + "configurations": [] } diff --git a/__tests__/redux/node.spec.ts b/__tests__/redux/node.spec.ts index 7171f41..84ba248 100644 --- a/__tests__/redux/node.spec.ts +++ b/__tests__/redux/node.spec.ts @@ -2,16 +2,13 @@ import { ServiceDescriptor } from "../../src/types/Service"; import { Platform } from "../../src/types/common"; import { pruneNodes } from "../../src/scheduler/nodePruner"; import { store as mainStore } from "../../src/redux/store"; -import { - removeWorkloads, - removeServices, - removeNodes, - setPlatform, -} from "../../src/redux/reducers"; - import { runWorkload } from "../common"; import { isWorkloadSchedulable } from "../../src/utils/workload"; import { MachineSet } from "../../src/types"; +import { setPlatform } from "../../src/redux/reducers/cluster"; +import { removeNodes } from "../../src/redux/reducers/node"; +import { removeServices } from "../../src/redux/reducers/service"; +import { removeWorkloads } from "../../src/redux/reducers/workload"; const testServices: ServiceDescriptor[] = [ { diff --git a/__tests__/redux/odf.spec.ts b/__tests__/redux/odf.spec.ts index 7a3df4f..51f6846 100644 --- a/__tests__/redux/odf.spec.ts +++ b/__tests__/redux/odf.spec.ts @@ -1,17 +1,13 @@ import { getODFWorkload } from "../../src/workloads"; import { MachineSet } from "../../src/types"; -import { - addMachineSet, - addServices, - addWorkload, - editServices, - editWorkload, -} from "../../src/redux/reducers"; import { store as mainStore } from "../../src/redux/store"; import { workloadScheduler } from "../../src/scheduler/workloadScheduler"; import { getWorkloadFromDescriptors } from "../../src/utils/workload"; import { DeploymentType } from "../../src/types"; import { ODF_WORKLOAD_NAME } from "../../src/constants"; +import { addMachineSet } from "../../src/redux/reducers/machineSet"; +import { addServices, editServices } from "../../src/redux/reducers/service"; +import { addWorkload, editWorkload } from "../../src/redux/reducers/workload"; const { services: odfServices, workload: odfWorkload } = getWorkloadFromDescriptors( diff --git a/__tests__/redux/scheduler.spec.ts b/__tests__/redux/scheduler.spec.ts index dd354b2..46cf921 100644 --- a/__tests__/redux/scheduler.spec.ts +++ b/__tests__/redux/scheduler.spec.ts @@ -1,13 +1,11 @@ import { defaultWorkloads } from "../../src/components/Workload/defaultWorkloads"; import { MachineSet, WorkloadDescriptor } from "../../src/types"; -import { - addMachineSet, - addServices, - addWorkload, -} from "../../src/redux/reducers"; +import { addMachineSet } from "../../src/redux/reducers/machineSet"; import { store as mainStore } from "../../src/redux/store"; import { workloadScheduler } from "../../src/scheduler/workloadScheduler"; import { getWorkloadFromDescriptors } from "../../src/utils/workload"; +import { addServices } from "../../src/redux/reducers/service"; +import { addWorkload } from "../../src/redux/reducers/workload"; const kafkaWorkloadDescriptor: WorkloadDescriptor = defaultWorkloads.find( (wl) => wl.name === "Kafka" diff --git a/src/api.ts b/src/api.ts index 3e45b72..3e44119 100644 --- a/src/api.ts +++ b/src/api.ts @@ -127,7 +127,9 @@ export const useSetupAPI = (): void => { dispatch(addMachineSet(odfMS)); } } else { - const selectedMS = machineSet.find((ms) => ms.name === dedicatedMSName); + const selectedMS: MachineSet = machineSet.find( + (ms) => ms.name === dedicatedMSName + ) as MachineSet; workload.usesMachines = [selectedMS.name]; if (selectedMS.onlyFor.length === 0) { const updatedSelectedMS = Object.assign(_.cloneDeep(selectedMS), { @@ -162,7 +164,7 @@ export const useSetupAPI = (): void => { const schedule = React.useCallback(() => { dispatch(removeAllZones()); dispatch(removeAllNodes()); - const unschedulables = []; + const unschedulables: Workload[] = []; const scheduler = workloadScheduler(store, dispatch); const checkSchedulability = isWorkloadSchedulable(services, machineSets); const workloadSchedulability: [Workload, boolean, MachineSet[]][] = @@ -208,9 +210,9 @@ export const useSetupAPI = (): void => { const instance = _.find( platformInstanceMap[platform], (item) => item.name === instanceName - ); + ) as Instance; const isCloud = isCloudPlatform(platform); - const machineSet = { + const machineSet: MachineSet = { name: machineSetName, cpu: !isCloud ? cpu : instance?.cpuUnits, memory: !isCloud ? memory : instance?.memory, @@ -219,7 +221,7 @@ export const useSetupAPI = (): void => { onlyFor: dedicateToODF ? [ODF_WORKLOAD_NAME] : [], label: "Worker Node", instanceStorage: instance?.instanceStorage, - }; + } as MachineSet; dispatch(addMachineSet(machineSet)); }, [dispatch, platform] diff --git a/src/redux/reducers/machineSet.ts b/src/redux/reducers/machineSet.ts index 1de5907..102e3fb 100644 --- a/src/redux/reducers/machineSet.ts +++ b/src/redux/reducers/machineSet.ts @@ -7,7 +7,7 @@ import { import { MachineSet } from "../../types"; import { Platform } from "../../types"; import { disableCompactMode, enableCompactMode } from "./cluster"; -import { getMachinetSetFromInstance } from "../../utils"; +import { getMachinetSetFromInstance } from "../../utils/common"; let MS_COUNTER = 2; diff --git a/src/redux/store.ts b/src/redux/store.ts index 84799a7..65562c9 100644 --- a/src/redux/store.ts +++ b/src/redux/store.ts @@ -1,14 +1,12 @@ import { configureStore } from "@reduxjs/toolkit"; -import { - uiReducer, - ocsReducer, - workloadReducer, - machineSetReducer, - clusterReducer, - nodeReducer, - zoneReducer, - serviceReducer, -} from "./reducers"; +import { uiReducer } from "./reducers/ui"; +import { ocsReducer } from "./reducers/ocs"; +import { workloadReducer } from "./reducers/workload"; +import { machineSetReducer } from "./reducers/machineSet"; +import { clusterReducer } from "./reducers/cluster"; +import { nodeReducer } from "./reducers/node"; +import { zoneReducer } from "./reducers/zone"; +import { serviceReducer } from "./reducers/service"; const store = configureStore({ reducer: { diff --git a/src/scheduler/nodePruner.ts b/src/scheduler/nodePruner.ts index a4fae21..8b84d68 100644 --- a/src/scheduler/nodePruner.ts +++ b/src/scheduler/nodePruner.ts @@ -1,6 +1,7 @@ import { Dispatch } from "@reduxjs/toolkit"; import { Node, Zone } from "../../src/types"; -import { removeNodes, removeZone } from "../redux"; +import { removeNodes } from "../redux/reducers/node"; +import { removeZone } from "../redux/reducers/zone"; export const pruneNodes = (dispatch: Dispatch) => diff --git a/src/scheduler/workloadScheduler.ts b/src/scheduler/workloadScheduler.ts index 5c6df19..f947d2d 100644 --- a/src/scheduler/workloadScheduler.ts +++ b/src/scheduler/workloadScheduler.ts @@ -10,7 +10,7 @@ import { MachineSet, Service, Workload, Zone } from "../types"; import { Node } from "../types"; import * as _ from "lodash"; import { Dispatch } from "@reduxjs/toolkit"; -import { addZone, generateZoneID } from "../redux/reducers"; +import { addZone, generateZoneID } from "../redux/reducers/zone"; import { getMaxZones, sortBestZones } from "../utils/node"; import { addServiceToZone, getCoplacedServices } from "../utils/service"; import { store as Store } from "../redux/store"; diff --git a/src/types/Zone.ts b/src/types/Zone.ts index 56d1036..272420d 100644 --- a/src/types/Zone.ts +++ b/src/types/Zone.ts @@ -1,4 +1,4 @@ export type Zone = { nodes: number[]; - id?: number; + id: number; }; diff --git a/src/utils/service.ts b/src/utils/service.ts index d5441bb..0299dd0 100644 --- a/src/utils/service.ts +++ b/src/utils/service.ts @@ -2,14 +2,27 @@ import { MachineSet, Service, Workload, Zone } from "../types"; import { Node } from "../types"; import { canNodeAddService, getTotalNodeMemoryConsumption } from "./node"; import { Dispatch } from "@reduxjs/toolkit"; -import { - addNode, - addNodesToZone, - addServicesToNode, - getNodeID, -} from "../redux/reducers"; -import { getMachineSetForWorkload } from "./workload"; +import { addNode, addServicesToNode, getNodeID } from "../redux/reducers/node"; import { getTotalResourceRequirement } from "./common"; +import { addNodesToZone } from "../redux/reducers/zone"; + +export const getMachineSetForWorkload = ( + workload: Workload, + machineSets: MachineSet[] +): MachineSet => { + const dedicatedMS = machineSets.find((ms) => + ms.onlyFor.includes(workload.name) + ); + if (dedicatedMS) { + return dedicatedMS; + } + if (workload.usesMachines.length > 0) { + return machineSets.find((ms) => + workload.usesMachines.includes(ms.name) + ) as MachineSet; + } + return machineSets[0]; +}; /** * diff --git a/src/utils/workload.ts b/src/utils/workload.ts index a836df3..4bcbf09 100644 --- a/src/utils/workload.ts +++ b/src/utils/workload.ts @@ -7,11 +7,7 @@ import { Workload, WorkloadDescriptor, } from "../types"; -import { - generateWorkloadID, - removeServicesFromNodes, - removeWorkload, -} from "../redux"; +import { generateWorkloadID, removeWorkload } from "../redux/reducers/workload"; import { generateServiceID, removeServices } from "../redux/reducers/service"; import { getTotalResourceRequirement } from "./common"; import { getAllCoplacedServices, sortServices } from "./service"; @@ -19,6 +15,7 @@ import { getNodeKubeletCPURequirements, getNodeKubeletMemoryRequirements, } from "./kubelet"; +import { removeServicesFromNodes } from "../redux/reducers/node"; type WorkloadDescriptorObjects = { services: Service[]; @@ -83,24 +80,6 @@ export const getDescriptorFromWorkload = ( return workloadDescriptor; }; -export const getMachineSetForWorkload = ( - workload: Workload, - machineSets: MachineSet[] -): MachineSet => { - const dedicatedMS = machineSets.find((ms) => - ms.onlyFor.includes(workload.name) - ); - if (dedicatedMS) { - return dedicatedMS; - } - if (workload.usesMachines.length > 0) { - return machineSets.find((ms) => - workload.usesMachines.includes(ms.name) - ) as MachineSet; - } - return machineSets[0]; -}; - export const getWorkloadResourceConsumption = ( workload: Workload, services: Service[]