Skip to content

Commit

Permalink
Revert "feat(mis/portal): 集群停用功能" (#1264)
Browse files Browse the repository at this point in the history
Reverts #1219
/
  • Loading branch information
ddadaal authored and OYX-1 committed Jul 4, 2024
1 parent 1ffbad1 commit 5eed030
Show file tree
Hide file tree
Showing 204 changed files with 826 additions and 4,817 deletions.
6 changes: 0 additions & 6 deletions .changeset/eleven-feet-turn.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/great-starfishes-pump.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/grumpy-months-cover.md

This file was deleted.

12 changes: 0 additions & 12 deletions .changeset/long-kids-wash.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/weak-chicken-worry.md

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"trpc"
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
"source.fixAll.eslint": true
},
"eslint.validate": [
"javascript",
Expand Down
2 changes: 0 additions & 2 deletions apps/ai/src/models/operationLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ export const OperationType: OperationTypeEnum = {
setAccountBlockThreshold: "setAccountBlockThreshold",
setAccountDefaultBlockThreshold: "setAccountDefaultBlockThreshold",
userChangeTenant: "userChangeTenant",
activateCluster: "activateCluster",
deactivateCluster: "deactivateCluster",
customEvent: "customEvent",
};

3 changes: 0 additions & 3 deletions apps/cli/src/compose/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ export const createComposeSpec = (config: InstallConfigSchema) => {
environment: {
SCOW_LAUNCH_APP: "portal-server",
PORTAL_BASE_PATH: portalBasePath,
MIS_DEPLOYED: config.mis ? "true" : "false",
MIS_SERVER_URL: config.mis ? "mis-server:5000" : "",
...serviceLogEnv,
...nodeOptions ? { NODE_OPTIONS: nodeOptions } : {},
},
Expand All @@ -271,7 +269,6 @@ export const createComposeSpec = (config: InstallConfigSchema) => {
"BASE_PATH": portalBasePath,
"MIS_URL": join(BASE_PATH, MIS_PATH),
"MIS_DEPLOYED": config.mis ? "true" : "false",
"MIS_SERVER_URL": config.mis ? "mis-server:5000" : "",
"AI_URL": join(BASE_PATH, AI_PATH),
"AI_DEPLOYED": config.ai ? "true" : "false",
"AUTH_EXTERNAL_URL": config.auth.custom?.external?.url || join(BASE_PATH, "/auth"),
Expand Down
1 change: 0 additions & 1 deletion apps/cli/tests/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ it("generate correct paths", async () => {
const composeConfig = createComposeSpec(config);

expect(composeConfig.services["portal-web"].environment).toContain("MIS_URL=/mis");
expect(composeConfig.services["portal-web"].environment).toContain("MIS_SERVER_URL=mis-server:5000");
expect(composeConfig.services["mis-web"].environment).toContain("PORTAL_URL=/");
expect(composeConfig.services["ai"].environment).toContain("MIS_URL=/mis");
});
Expand Down
1 change: 0 additions & 1 deletion apps/mis-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export async function createServer() {
for (const plugin of plugins) {
await server.register(plugin);
}

await server.register(accountServiceServer);
await server.register(userServiceServer);
await server.register(adminServiceServer);
Expand Down
8 changes: 3 additions & 5 deletions apps/mis-server/src/bl/PriceMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Logger } from "@ddadaal/tsgrpc-server";
import { MySqlDriver, SqlEntityManager } from "@mikro-orm/mysql";
import { Partition } from "@scow/scheduler-adapter-protos/build/protos/config";
import { calculateJobPrice } from "src/bl/jobPrice";
import { configClusters } from "src/config/clusters";
import { clusters } from "src/config/clusters";
import { misConfig } from "src/config/mis";
import { JobPriceInfo } from "src/entities/JobInfo";
import { AmountStrategy, JobPriceItem } from "src/entities/JobPriceItem";
Expand Down Expand Up @@ -90,10 +90,7 @@ export async function createPriceMap(

// partitions info for all clusters
const partitionsForClusters: Record<string, Partition[]> = {};

// call for all config clusters
const reply = await clusterPlugin.callOnAll(
configClusters,
logger,
async (client) => await asyncClientCall(client.config, "getClusterConfig", {}),
);
Expand All @@ -109,9 +106,10 @@ export async function createPriceMap(

const missingPaths = [] as string[];

for (const cluster in configClusters) {
for (const cluster in clusters) {
for (const partition of partitionsForClusters[cluster]) {
const path = [cluster, partition.name];

const { qos } = partition;

if (path.join(".") in defaultPrices) {
Expand Down
64 changes: 11 additions & 53 deletions apps/mis-server/src/bl/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ import { asyncClientCall } from "@ddadaal/tsgrpc-client";
import { Logger } from "@ddadaal/tsgrpc-server";
import { Loaded } from "@mikro-orm/core";
import { MySqlDriver, SqlEntityManager } from "@mikro-orm/mysql";
import { ClusterConfigSchema } from "@scow/config/build/cluster";
import { BlockedFailedUserAccount } from "@scow/protos/build/server/admin";
import { Account } from "src/entities/Account";
import { UserAccount, UserStatus } from "src/entities/UserAccount";
import { ClusterPlugin } from "src/plugins/clusters";
import { callHook } from "src/plugins/hookClient";

import { getActivatedClusters } from "./clustersUtils";


/**
* Update block status of accounts and users in the slurm.
* If it is whitelisted, it doesn't block.
Expand All @@ -35,33 +31,15 @@ export async function updateBlockStatusInSlurm(
) {
const blockedAccounts: string[] = [];
const blockedFailedAccounts: string[] = [];
const blockedUserAccounts: [string, string][] = [];
const blockedFailedUserAccounts: BlockedFailedUserAccount[] = [];

const accounts = await em.find(Account, { blockedInCluster: true });

const currentActivatedClusters = await getActivatedClusters(em, logger).catch((e) => {
logger.info(e);
return {};
});

if (Object.keys(currentActivatedClusters).length === 0) {
logger.info("No available activated clusters in SCOW.");
return {
blockedAccounts,
blockedFailedAccounts,
blockedUserAccounts,
blockedFailedUserAccounts,
};
}

for (const account of accounts) {
if (account.whitelist) {
continue;
}

try {
await clusterPlugin.callOnAll(currentActivatedClusters, logger, async (client) =>
await clusterPlugin.callOnAll(logger, async (client) =>
await asyncClientCall(client.account, "blockAccount", {
accountName: account.accountName,
}),
Expand All @@ -72,14 +50,15 @@ export async function updateBlockStatusInSlurm(
}
}


const blockedUserAccounts: [string, string][] = [];
const blockedFailedUserAccounts: BlockedFailedUserAccount[] = [];
const userAccounts = await em.find(UserAccount, {
blockedInCluster: UserStatus.BLOCKED,
}, { populate: ["user", "account"]});

for (const ua of userAccounts) {
try {
await clusterPlugin.callOnAll(currentActivatedClusters, logger, async (client) =>
await clusterPlugin.callOnAll(logger, async (client) =>
await asyncClientCall(client.user, "blockUserInAccount", {
accountName: ua.account.$.accountName,
userId: ua.user.$.userId,
Expand Down Expand Up @@ -129,22 +108,9 @@ export async function updateUnblockStatusInSlurm(
const unblockedAccounts: string[] = [];
const unblockedFailedAccounts: string[] = [];

const currentActivatedClusters = await getActivatedClusters(em, logger).catch((e) => {
logger.info(e);
return {};
});

if (Object.keys(currentActivatedClusters).length === 0) {
logger.info("No available activated clusters in SCOW.");
return {
unblockedAccounts,
unblockedFailedAccounts,
};
}

for (const account of accounts) {
try {
await clusterPlugin.callOnAll(currentActivatedClusters, logger, async (client) =>
await clusterPlugin.callOnAll(logger, async (client) =>
await asyncClientCall(client.account, "unblockAccount", {
accountName: account.accountName,
}),
Expand Down Expand Up @@ -174,10 +140,7 @@ export async function updateUnblockStatusInSlurm(
* @returns Operation result
**/
export async function blockAccount(
account: Loaded<Account, "tenant">,
currentActivatedClusters: Record<string, ClusterConfigSchema>,
clusterPlugin: ClusterPlugin["clusters"],
logger: Logger,
account: Loaded<Account, "tenant">, clusterPlugin: ClusterPlugin["clusters"], logger: Logger,
): Promise<"AlreadyBlocked" | "Whitelisted" | "OK"> {

if (account.blockedInCluster) { return "AlreadyBlocked"; }
Expand All @@ -186,7 +149,7 @@ export async function blockAccount(
return "Whitelisted";
}

await clusterPlugin.callOnAll(currentActivatedClusters, logger, async (client) => {
await clusterPlugin.callOnAll(logger, async (client) => {
await asyncClientCall(client.account, "blockAccount", {
accountName: account.accountName,
});
Expand All @@ -207,15 +170,12 @@ export async function blockAccount(
* @returns Operation result
**/
export async function unblockAccount(
account: Loaded<Account, "tenant">,
currentActivatedClusters: Record<string, ClusterConfigSchema>,
clusterPlugin: ClusterPlugin["clusters"],
logger: Logger,
account: Loaded<Account, "tenant">, clusterPlugin: ClusterPlugin["clusters"], logger: Logger,
): Promise<"OK" | "ALREADY_UNBLOCKED"> {

if (!account.blockedInCluster) { return "ALREADY_UNBLOCKED"; }

await clusterPlugin.callOnAll(currentActivatedClusters, logger, async (client) => {
await clusterPlugin.callOnAll(logger, async (client) => {
await asyncClientCall(client.account, "unblockAccount", {
accountName: account.accountName,
});
Expand All @@ -233,7 +193,6 @@ export async function unblockAccount(
* */
export async function blockUserInAccount(
ua: Loaded<UserAccount, "user" | "account">,
currentActivatedClusters: Record<string, ClusterConfigSchema>,
clusterPlugin: ClusterPlugin, logger: Logger,
) {
if (ua.blockedInCluster == UserStatus.BLOCKED) {
Expand All @@ -243,7 +202,7 @@ export async function blockUserInAccount(
const accountName = ua.account.$.accountName;
const userId = ua.user.$.userId;

await clusterPlugin.clusters.callOnAll(currentActivatedClusters, logger, async (client) =>
await clusterPlugin.clusters.callOnAll(logger, async (client) =>
await asyncClientCall(client.user, "blockUserInAccount", {
accountName,
userId,
Expand All @@ -263,7 +222,6 @@ export async function blockUserInAccount(
* */
export async function unblockUserInAccount(
ua: Loaded<UserAccount, "user" | "account">,
currentActivatedClusters: Record<string, ClusterConfigSchema>,
clusterPlugin: ClusterPlugin, logger: Logger,
) {
if (ua.blockedInCluster === UserStatus.UNBLOCKED) {
Expand All @@ -273,7 +231,7 @@ export async function unblockUserInAccount(
const accountName = ua.account.getProperty("accountName");
const userId = ua.user.getProperty("userId");

await clusterPlugin.clusters.callOnAll(currentActivatedClusters, logger, async (client) =>
await clusterPlugin.clusters.callOnAll(logger, async (client) =>
await asyncClientCall(client.user, "unblockUserInAccount", {
accountName,
userId,
Expand Down
27 changes: 9 additions & 18 deletions apps/mis-server/src/bl/charging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import { Logger } from "@ddadaal/tsgrpc-server";
import { Loaded } from "@mikro-orm/core";
import { SqlEntityManager } from "@mikro-orm/mysql";
import { ClusterConfigSchema } from "@scow/config/build/cluster";
import { Decimal, decimalToMoney } from "@scow/lib-decimal";
import { blockAccount, blockUserInAccount, unblockAccount, unblockUserInAccount } from "src/bl/block";
import { Account } from "src/entities/Account";
Expand Down Expand Up @@ -59,7 +58,6 @@ export function checkShouldUnblockAccount(account: Loaded<Account, "tenant">) {

export async function pay(
request: PayRequest, em: SqlEntityManager,
currentActivatedClusters: Record<string, ClusterConfigSchema>,
logger: Logger, clusterPlugin: ClusterPlugin,
) {
const {
Expand Down Expand Up @@ -94,15 +92,15 @@ export async function pay(
&& checkShouldUnblockAccount(target)
) {
logger.info("Unblock account %s", target.accountName);
await unblockAccount(target, currentActivatedClusters, clusterPlugin.clusters, logger);
await unblockAccount(target, clusterPlugin.clusters, logger);
}

if (
target instanceof Account
&& checkShouldBlockAccount(target)
) {
logger.info("Block account %s", target.accountName);
await blockAccount(target, currentActivatedClusters, clusterPlugin.clusters, logger);
await blockAccount(target, clusterPlugin.clusters, logger);
}

return {
Expand All @@ -122,7 +120,6 @@ type ChargeRequest = {

export async function charge(
request: ChargeRequest, em: SqlEntityManager,
currentActivatedClusters: Record<string, ClusterConfigSchema>,
logger: Logger, clusterPlugin: ClusterPlugin,
) {
const { target, amount, comment, type, userId, metadata } = request;
Expand All @@ -147,7 +144,7 @@ export async function charge(
&& checkShouldBlockAccount(target)
) {
logger.info("Block account %s due to out of balance.", target.accountName);
await blockAccount(target, currentActivatedClusters, clusterPlugin.clusters, logger);
await blockAccount(target, clusterPlugin.clusters, logger);
}

return {
Expand All @@ -158,10 +155,7 @@ export async function charge(

export async function addJobCharge(
ua: Loaded<UserAccount, "user" | "account">,
charge: Decimal,
currentActivatedClusters: Record<string, ClusterConfigSchema>,
clusterPlugin: ClusterPlugin,
logger: Logger,
charge: Decimal, clusterPlugin: ClusterPlugin, logger: Logger,
) {
if (ua.usedJobCharge && ua.jobChargeLimit) {
ua.usedJobCharge = ua.usedJobCharge.plus(charge);
Expand All @@ -173,19 +167,16 @@ export async function addJobCharge(
).shouldBlockInCluster;

if (shouldBlockUserInCluster) {
await blockUserInAccount(ua, currentActivatedClusters, clusterPlugin, logger);
await blockUserInAccount(ua, clusterPlugin, logger);
} else {
await unblockUserInAccount(ua, currentActivatedClusters, clusterPlugin, logger);
await unblockUserInAccount(ua, clusterPlugin, logger);
}
}
}

export async function setJobCharge(
ua: Loaded<UserAccount, "user" | "account">,
charge: Decimal,
currentActivatedClusters: Record<string, ClusterConfigSchema>,
clusterPlugin: ClusterPlugin,
logger: Logger,
charge: Decimal, clusterPlugin: ClusterPlugin, logger: Logger,
) {
ua.jobChargeLimit = charge;
if (!ua.usedJobCharge) {
Expand All @@ -199,9 +190,9 @@ export async function setJobCharge(
).shouldBlockInCluster;

if (shouldBlockUserInCluster) {
await blockUserInAccount(ua, currentActivatedClusters, clusterPlugin, logger);
await blockUserInAccount(ua, clusterPlugin, logger);
} else {
await unblockUserInAccount(ua, currentActivatedClusters, clusterPlugin, logger);
await unblockUserInAccount(ua, clusterPlugin, logger);
}
}
}
Loading

0 comments on commit 5eed030

Please sign in to comment.