Skip to content

Commit

Permalink
fix(mis): 移出用户前增加用户是否有运行中作业的判断 (#956)
Browse files Browse the repository at this point in the history
在移出用户的时候,先将用户封锁,保证用户无法提交作业,再查看用户是否有还在运行的作业。如果有的话,提示:用户还有作业在运行,请等待作业结束或手动结束作业后再移出


![image](https://github.com/PKUHPC/SCOW/assets/25954437/7e728455-eb18-4858-804a-323ebb90662f)
  • Loading branch information
tongchong authored Nov 17, 2023
1 parent f577d9d commit 3e13a35
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/angry-coats-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@scow/mis-server": patch
"@scow/mis-web": patch
---

移出用户前增加用户是否有运行中作业的判断
29 changes: 28 additions & 1 deletion apps/mis-server/src/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export const userServiceServer = plugin((server) => {
const userAccount = await em.findOne(UserAccount, {
user: { userId, tenant: { name: tenantName } },
account: { accountName, tenant: { name: tenantName } },
});
}, { populate: ["user", "account"]});

if (!userAccount) {
throw <ServiceError>{
Expand All @@ -211,6 +211,33 @@ export const userServiceServer = plugin((server) => {
};
}

// 如果要从账户中移出用户,先封锁,先将用户封锁,保证用户无法提交作业
if (userAccount.status === UserStatus.UNBLOCKED) {
await blockUserInAccount(userAccount, server.ext, logger);
await em.flush();
}

// 查询用户是否有RUNNING、PENDING的作业,如果有,抛出异常
const jobs = await server.ext.clusters.callOnAll(
logger,
async (client) => {
const fields = ["job_id", "user", "state", "account"];

return await asyncClientCall(client.job, "getJobs", {
fields,
filter: { users: [userId], accounts: [accountName], states: ["RUNNING", "PENDING"]},
});
},
);

if (jobs.filter((i) => i.result.jobs.length > 0).length > 0) {
throw <ServiceError>{
code: Status.FAILED_PRECONDITION,
message: `User ${userId} has jobs running or pending and cannot remove.
Please wait for the job to end or end the job manually before moving out.`,
};
}

await server.ext.clusters.callOnAll(logger, async (client) => {
return await asyncClientCall(client.user, "removeUserFromAccount", { userId, accountName });
});
Expand Down
2 changes: 2 additions & 0 deletions apps/mis-web/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ export default {
confirmRemoveText: "Confirm removing user from account",
removeSuccess: "User removed successfully!",
removerUser: "Remove User",
cannotRemoverUserWhoHaveRunningJobFromAccount: "The user still has a job running, "
+ " and the user has been blocked. Please wait for the job to end or end the job manually before moving out.",
},
},
},
Expand Down
1 change: 1 addition & 0 deletions apps/mis-web/src/i18n/zh_cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ export default {
confirmRemoveText:"确认要从账户",
removeSuccess:"移出用户成功!",
removerUser:"移出用户",
cannotRemoverUserWhoHaveRunningJobFromAccount:"用户还有作业在运行,已封锁该用户,请等待作业结束或手动结束作业后再移出",
},
},
},
Expand Down
8 changes: 8 additions & 0 deletions apps/mis-web/src/pageComponents/users/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ export const UserTable: React.FC<Props> = ({
identityId: r.userId,
accountName: accountName,
} })
.httpError(409, () => {
message.destroy("removeUser");
message.error({
content: t(p("cannotRemoverUserWhoHaveRunningJobFromAccount")),
duration: 4,
});
reload();
})
.then(() => {
message.destroy("removeUser");
message.success(t(p("removeSuccess")));
Expand Down
3 changes: 3 additions & 0 deletions apps/mis-web/src/pages/api/users/removeFromAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const RemoveUserFromAccountSchema = typeboxRouteSchema({
// 不能移出账户拥有者
406: Type.Null(),

// 不能移出有正在运行作业的用户,只能先封锁
409: Type.Null(),
},
});

Expand Down Expand Up @@ -81,6 +83,7 @@ export default /* #__PURE__*/route(RemoveUserFromAccountSchema, async (req, res)
.catch(handlegRPCError({
[Status.NOT_FOUND]: () => ({ 404: null }),
[Status.OUT_OF_RANGE]: () => ({ 406: null }),
[Status.FAILED_PRECONDITION]: () => ({ 409: null }),
},
async () => await callLog(logInfo, OperationResult.FAIL),
));
Expand Down

0 comments on commit 3e13a35

Please sign in to comment.