Feat: batch restart

This commit is contained in:
Lazy 2024-06-19 14:59:57 +08:00
parent 069f6d078d
commit e0a4b9a9f4
3 changed files with 47 additions and 4 deletions

View File

@ -377,6 +377,19 @@ export const batchKill = useDefineApi<
url: "/api/instance/multi_kill"
});
export const batchRestart = useDefineApi<
{
data: {
instanceUuid: string;
daemonId: string;
}[];
},
boolean
>({
method: "POST",
url: "/api/instance/multi_restart"
});
export const batchDelete = useDefineApi<
{
params: {

View File

@ -17,12 +17,19 @@ import {
DeleteOutlined,
WarningOutlined,
InfoCircleOutlined,
FrownOutlined
FrownOutlined,
RedoOutlined
} from "@ant-design/icons-vue";
import BetweenMenus from "@/components/BetweenMenus.vue";
import { router } from "@/config/router";
import { remoteInstances, remoteNodeList } from "@/services/apis";
import { batchStart, batchStop, batchKill, batchDelete } from "@/services/apis/instance";
import {
batchStart,
batchStop,
batchKill,
batchDelete,
batchRestart
} from "@/services/apis/instance";
import type { NodeStatus } from "../types/index";
import { notification, Modal } from "ant-design-vue";
import { computeNodeName } from "../tools/nodes";
@ -190,6 +197,11 @@ const instanceOperations = [
icon: PauseCircleOutlined,
click: () => batchOperation("stop")
},
{
title: t("TXT_CODE_47dcfa5"),
icon: RedoOutlined,
click: () => batchOperation("restart")
},
{
title: t("TXT_CODE_7b67813a"),
icon: CloseOutlined,
@ -209,12 +221,13 @@ const instanceOperations = [
}
];
const batchOperation = async (actName: "start" | "stop" | "kill") => {
const batchOperation = async (actName: "start" | "stop" | "kill" | "restart") => {
if (selectedInstance.value.length === 0) return reportErrorMsg(t("TXT_CODE_a0a77be5"));
const operationMap = {
start: async () => exec(batchStart().execute, t("TXT_CODE_2b5fd76e")),
stop: async () => exec(batchStop().execute, t("TXT_CODE_4822a21")),
kill: async () => exec(batchKill().execute, t("TXT_CODE_effefaab"))
kill: async () => exec(batchKill().execute, t("TXT_CODE_effefaab")),
restart: async () => exec(batchRestart().execute, t("TXT_CODE_effefaab"))
};
const exec = async (fn: Function, msg: string) => {

View File

@ -197,6 +197,23 @@ router.post("/multi_kill", permission({ level: ROLE.ADMIN }), async (ctx) => {
}
});
// [Top-level Permission]
// restart instance routing in batches
router.post("/multi_restart", permission({ level: ROLE.ADMIN }), async (ctx) => {
try {
const instances = ctx.request.body;
multiOperationForwarding(instances, async (daemonId: string, instanceUuids: string[]) => {
const remoteService = RemoteServiceSubsystem.getInstance(daemonId);
new RemoteRequest(remoteService)
.request("instance/restart", { instanceUuids })
.catch((err) => {});
});
ctx.body = true;
} catch (err) {
ctx.body = err;
}
});
// [Top-level Permission]
// Get quick install list
router.get("/quick_install_list", permission({ level: ROLE.USER }), async (ctx) => {