Skip to content

Commit

Permalink
Removes circular dependencies
Browse files Browse the repository at this point in the history
Fixes unit tests errors

Signed-off-by: Bipul Adhikari <[email protected]>
  • Loading branch information
bipuladh committed Nov 14, 2023
1 parent 6e86e82 commit 74755f7
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 81 deletions.
14 changes: 1 addition & 13 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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": []
}
11 changes: 4 additions & 7 deletions __tests__/redux/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
{
Expand Down
10 changes: 3 additions & 7 deletions __tests__/redux/odf.spec.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
8 changes: 3 additions & 5 deletions __tests__/redux/scheduler.spec.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
12 changes: 7 additions & 5 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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), {
Expand Down Expand Up @@ -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[]][] =
Expand Down Expand Up @@ -208,9 +210,9 @@ export const useSetupAPI = (): void => {
const instance = _.find<Instance>(
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,
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/redux/reducers/machineSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
18 changes: 8 additions & 10 deletions src/redux/store.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion src/scheduler/nodePruner.ts
Original file line number Diff line number Diff line change
@@ -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) =>
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/workloadScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/types/Zone.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Zone = {
nodes: number[];
id?: number;
id: number;
};
27 changes: 20 additions & 7 deletions src/utils/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};

/**
*
Expand Down
25 changes: 2 additions & 23 deletions src/utils/workload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ 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";
import {
getNodeKubeletCPURequirements,
getNodeKubeletMemoryRequirements,
} from "./kubelet";
import { removeServicesFromNodes } from "../redux/reducers/node";

type WorkloadDescriptorObjects = {
services: Service[];
Expand Down Expand Up @@ -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[]
Expand Down

0 comments on commit 74755f7

Please sign in to comment.