-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mis): 增加定时同步scow与适配器中用户封锁状态及账户封锁/解封状态的功能 (#913)
做了什么: 增加同步 scow 与适配器中用户封锁、账户封锁/解封状态的功能 1、增加同步 scow 与适配器中用户封锁、账户封锁/解封状态的接口,如果有部分账户/用户同步失败,跳过继续执行,接口返回失败账户/用户的信息 2、增加获取同步 scow 与适配器中用户封锁状态、账户封锁/解封状态的配置信息的接口 3、增加设置同步 scow 与适配器中用户封锁状态、账户封锁/解封状态的配置启动/关闭的接口 将原有接口updateBlockStatus置为deprecated 页面如下: ![image](https://github.com/PKUHPC/SCOW/assets/25954437/990dddbb-1786-4f4f-8403-47ee82f65e6b) 操作验证如下:先修改数据库,使一个账户在scow状态变为封锁,但用户仍旧能通过他它来提交作业。同步封锁状态后,提交的作业就无法运行了 ![12](https://github.com/PKUHPC/SCOW/assets/25954437/335c8ee4-c277-4a9e-ae88-fc778ac660b1) 同理,只修改scow数据库中的账户的状态为解封,该作业未运行,同步后,即可运行: ![13](https://github.com/PKUHPC/SCOW/assets/25954437/ca399e0d-f19d-4440-80e6-bf51a97f1698)
- Loading branch information
Showing
24 changed files
with
585 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@scow/config": minor | ||
--- | ||
|
||
增加scow定时同步调度器用户封锁、账户封锁/解封状态的配置,可配置同步周期、是否启动 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@scow/mis-server": minor | ||
"@scow/mis-web": minor | ||
--- | ||
|
||
增加scow定时同步调度器用户封锁、账户封锁/解封状态的功能 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@scow/grpc-api": minor | ||
--- | ||
增加scow定时同步调度器用户封锁、账户封锁/解封状态的接口,返回失败的账户、用户的信息 | ||
增加获取scow定时同步调度器用户封锁、账户封锁/解封状态配置信息的接口 | ||
增加设置scow定时同步调度器用户封锁、账户封锁/解封状态配置启动/关闭的接口 | ||
后续版本版本将会删除updateBlockStatus接口 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy | ||
* SCOW is licensed under Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
import { plugin } from "@ddadaal/tsgrpc-server"; | ||
import { SyncBlockStatusResponse } from "@scow/protos/build/server/admin"; | ||
import cron from "node-cron"; | ||
import { misConfig } from "src/config/mis"; | ||
import { lastSyncTime, synchronizeBlockStatus } from "src/tasks/syncBlockStatus"; | ||
|
||
export interface SyncBlockStatusPlugin { | ||
syncBlockStatus: { | ||
started: () => boolean; | ||
start: () => void; | ||
stop: () => void; | ||
schedule: string; | ||
lastSyncTime: () => Date | null; | ||
sync: () => Promise<SyncBlockStatusResponse>; | ||
} | ||
} | ||
|
||
export const syncBlockStatusPlugin = plugin(async (f) => { | ||
const synchronizeCron = misConfig.periodicSyncUserAccountBlockStatus?.cron ?? "0 4 * * *"; | ||
let synchronizeStarted = !!misConfig.periodicSyncUserAccountBlockStatus?.enabled; | ||
let synchronizeIsRunning = false; | ||
|
||
const logger = f.logger.child({ plugin: "syncBlockStatus" }); | ||
logger.info("misConfig.periodicSyncStatus?.cron: %s", misConfig.periodicSyncUserAccountBlockStatus?.cron); | ||
|
||
const trigger = () => { | ||
if (synchronizeIsRunning) return; | ||
|
||
synchronizeIsRunning = true; | ||
return synchronizeBlockStatus(f.ext.orm.em.fork(), logger, f.ext).finally(() => { synchronizeIsRunning = false; }); | ||
}; | ||
|
||
const task = cron.schedule( | ||
synchronizeCron, | ||
trigger, | ||
{ | ||
timezone: "Asia/Shanghai", | ||
scheduled: misConfig.periodicSyncUserAccountBlockStatus?.enabled, | ||
}, | ||
); | ||
|
||
logger.info("Sync block status started."); | ||
|
||
f.addCloseHook(() => { | ||
task.stop(); | ||
logger.info("Sync block status stopped."); | ||
}); | ||
|
||
f.addExtension("syncBlockStatus", <SyncBlockStatusPlugin["syncBlockStatus"]>{ | ||
started: () => synchronizeStarted, | ||
start: () => { | ||
if (synchronizeStarted) { | ||
logger.info("Sync is requested to start but already started"); | ||
} else { | ||
task.start(); | ||
synchronizeStarted = true; | ||
logger.info("Sync started"); | ||
} | ||
}, | ||
stop: () => { | ||
if (!synchronizeStarted) { | ||
logger.info("Sync is requested to stop but already stopped"); | ||
} else { | ||
task.stop(); | ||
synchronizeStarted = false; | ||
logger.info("Sync stopped"); | ||
} | ||
}, | ||
schedule: synchronizeCron, | ||
lastSyncTime: () => lastSyncTime, | ||
sync: trigger, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy | ||
* SCOW is licensed under Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
import { Logger } from "@ddadaal/tsgrpc-server"; | ||
import { MySqlDriver, SqlEntityManager } from "@mikro-orm/mysql"; | ||
import { updateBlockStatusInSlurm, updateUnblockStatusInSlurm } from "src/bl/block"; | ||
import { SystemState } from "src/entities/SystemState"; | ||
import { ClusterPlugin } from "src/plugins/clusters"; | ||
|
||
export let lastSyncTime: Date | null = null; | ||
|
||
export async function synchronizeBlockStatus( | ||
em: SqlEntityManager<MySqlDriver>, | ||
logger: Logger, | ||
clusterPlugin: ClusterPlugin, | ||
) { | ||
const { blockedFailedAccounts, blockedFailedUserAccounts } = | ||
await updateBlockStatusInSlurm(em, clusterPlugin.clusters, logger); | ||
const { unblockedFailedAccounts } = await updateUnblockStatusInSlurm(em, clusterPlugin.clusters, logger); | ||
|
||
lastSyncTime = new Date(); | ||
|
||
const updateBlockTime = await em.upsert(SystemState, { | ||
key: SystemState.KEYS.UPDATE_SLURM_BLOCK_STATUS, | ||
value: new Date().toISOString(), | ||
}); | ||
await em.persistAndFlush(updateBlockTime); | ||
return { blockedFailedAccounts, blockedFailedUserAccounts, unblockedFailedAccounts }; | ||
} |
Oops, something went wrong.