Skip to content

Commit

Permalink
feat(frontend): 补充资源操作记录 #8872
Browse files Browse the repository at this point in the history
  • Loading branch information
jinquantianxia authored and hLinx committed Jan 3, 2025
1 parent 3c9a712 commit 8ac0b44
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 778 deletions.
26 changes: 26 additions & 0 deletions dbm-ui/frontend/src/common/const/machineEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { t } from '@locales/index';

/**
* 机器事件统类型
*/
export const enum MachineEvents {
IMPORT_RESOURCE = 'import_resource',
APPLY_RESOURCE = 'apply_resource',
RETURN_RESOURCE = 'return_resource',
TO_DIRTY = 'to_dirty',
TO_RECYCLE = 'to_recycle',
TO_FAULT = 'to_fault',
UNDO_IMPORT = 'undo_import',
RECYCLED = 'recycled',
}

export const machineEventsDisplayMap = {
[MachineEvents.IMPORT_RESOURCE]: t('导入资源池'),
[MachineEvents.APPLY_RESOURCE]: t('申请资源'),
[MachineEvents.RETURN_RESOURCE]: t('退回资源'),
[MachineEvents.TO_DIRTY]: t('转入污点池'),
[MachineEvents.TO_RECYCLE]: t('转入待回收池'),
[MachineEvents.TO_FAULT]: t('转入故障池'),
[MachineEvents.UNDO_IMPORT]: t('撤销导入'),
[MachineEvents.RECYCLED]: t('回收'),
};
13 changes: 13 additions & 0 deletions dbm-ui/frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1655,5 +1655,18 @@
"Mongo分片集群": "",
"sqlserver单节点版": "",
"sqlserver主从版": "",
"操作明细": "",
"导入资源池": "",
"申请资源": "",
"退回资源": "",
"转入污点池": "",
"转入待回收池": "",
"撤销导入": "",
"回收": "",
"业务主机退回资源池": "",
"资源池主机转入待回收池": "",
"资源池主机转入故障池": "",
"业务主机转入故障池": "",
"全局资源池": "",
"这行勿动!新增翻译请在上一行添加!": ""
}
39 changes: 34 additions & 5 deletions dbm-ui/frontend/src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3897,11 +3897,9 @@
"已选择以下n台主机": "已选择以下 {0} 台主机",
"资源监控": "资源监控",
"系统管理": "系统管理",
"撤销导入": "撤销导入",
"确认后,主机将从资源池移回原有模块": "确认后,主机将从资源池移回原有模块",
"所属DB": "所属DB",
"转入故障池": "转入故障池",
"转入待回收池": "转入待回收池",
"资源归属": "资源归属",
"确认批量将 {n} 台主机转入回收池?": "确认批量将 {n} 台主机转入回收池?",
"确认批量将 {n} 台主机转入故障池?": "确认批量将 {n} 台主机转入故障池?",
Expand Down Expand Up @@ -3934,8 +3932,6 @@
"确认转入待故障池?": "确认转入待故障池?",
"跳转管理页": "跳转管理页",
"确认批量回收 {n} 台主机?": "确认批量回收 {n} 台主机?",
"回收": "回收",
"导入资源池": "导入资源池",
"确认回收该机器?": "确认回收该机器?",
"待回收池": "待回收池",
"故障池": "故障池",
Expand All @@ -3952,7 +3948,6 @@
"所有 IP": "所有 IP",
"已选 IP": "已选 IP",
"业务资源池": "业务资源池",
"冷/热节点": "冷/热节点",
"退回公共资源池": "退回公共资源池",
"确认转入业务资源池?": "确认转入业务资源池?",
"转入业务资源池": "转入业务资源池",
Expand All @@ -3965,6 +3960,40 @@
"清空主机现有的所属 DB 和标签,重新进行设置": "清空主机现有的所属 DB 和标签,重新进行设置",
"清空主机现有的所属业务、所属 DB 、标签,重新进行设置": "清空主机现有的所属业务、所属 DB 、标签,重新进行设置",
"添加属性": "添加属性",
"目标集群:": "目标集群:",
"目标 DB:": "目标 DB:",
"目标表名:": "目标表名:",
"where 条件:": "where 条件:",
"导出数据:": "导出数据:",
"脚本来源:": "脚本来源:",
"脚本执行内容:": "脚本执行内容:",
"MySQL单节点集群": "MySQL 单节点集群",
"MySQL高可用集群": "MySQL 高可用集群",
"TendisCache集群": "TendisCache集群",
"RedisCache主从版": "RedisCache主从版",
"Kafka集群": "Kafka 集群",
"Hdfs集群": "Hdfs 集群",
"Pulsar集群": "Pulsar 集群",
"Riak集群": "Riak 集群",
"Mongo分片集群": "Mongo 分片集群",
"sqlserver单节点版": "sqlserver 单节点版",
"sqlserver主从版": "sqlserver 主从版",
"操作明细": "操作明细",
"导入资源池": "导入资源池",
"申请资源": "申请资源",
"退回资源": "退回资源",
"转入污点池": "转入污点池",
"转入待回收池": "转入待回收池",
"撤销导入": "撤销导入",
"回收": "回收",
"从「n」业务 CMDB空闲机模块导入": "从「{n}」业务 CMDB空闲机模块导入",
"退回「n」业务 CMDB 空闲机模块": "退回「{n}」业务 CMDB 空闲机模块",
"退回「n」业务 CMDB 待回收模块": "退回「{n}」业务 CMDB 待回收模块",
"业务主机退回资源池": "业务主机退回资源池",
"资源池主机转入待回收池": "资源池主机转入待回收池",
"资源池主机转入故障池": "资源池主机转入故障池",
"业务主机转入故障池": "业务主机转入故障池",
"全局资源池": "全局资源池",
"这行勿动!新增翻译请在上一行添加!": ""

}
76 changes: 76 additions & 0 deletions dbm-ui/frontend/src/services/model/db-resource/machineEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { MachineEvents, machineEventsDisplayMap } from '@common/const/machineEvents';

import { utcDisplayTime } from '@utils';

import { t } from '@locales/index';

export default class MachineEvent {
bk_biz_id: number | undefined;
bk_biz_name: string | undefined;
bk_host_id: number;
clusters: string[];
creator: string;
create_at: string;
db_app_abbr: string;
event: MachineEvents;
id: number;
ip: string;
ticket: number | null;
ticket_type_display: string;
to: string;
updater: string;
update_at: string;

constructor(payload = {} as MachineEvent) {
this.bk_biz_id = payload.bk_biz_id;
this.bk_biz_name = payload.bk_biz_name;
this.bk_host_id = payload.bk_host_id;
this.clusters = payload.clusters;
this.creator = payload.creator;
this.create_at = payload.create_at;
this.db_app_abbr = payload.db_app_abbr;
this.event = payload.event;
this.id = payload.id;
this.ip = payload.ip;
this.ticket = payload.ticket;
this.ticket_type_display = payload.ticket_type_display;
this.to = payload.to;
this.updater = payload.updater;
this.update_at = payload.update_at;
}

get bizDisplay() {
return this.bk_biz_id ? `${this.bk_biz_name}(#${this.bk_biz_id}${this.db_app_abbr})` : '--';
}

get eventDisplay() {
return machineEventsDisplayMap[this.event];
}

get updateAtDisplay() {
return utcDisplayTime(this.update_at);
}

get operationDetail() {
switch (this.event) {
case MachineEvents.IMPORT_RESOURCE:
return `${this.eventDisplay}${t('从「n」业务 CMDB空闲机模块导入', { n: this.bk_biz_name })})`;
case MachineEvents.APPLY_RESOURCE:
return this.eventDisplay;
case MachineEvents.RETURN_RESOURCE:
return t('业务主机退回资源池');
case MachineEvents.TO_DIRTY:
return this.eventDisplay;
case MachineEvents.TO_RECYCLE:
return t('资源池主机转入待回收池');
case MachineEvents.TO_FAULT:
return this.bk_biz_id ? t('资源池主机转入故障池') : t('业务主机转入故障池');
case MachineEvents.UNDO_IMPORT:
return `${this.eventDisplay}${t('退回「n」业务 CMDB 空闲机模块', { n: this.bk_biz_name })})`;
case MachineEvents.RECYCLED:
return `${this.eventDisplay}${t('退回「n」业务 CMDB 待回收模块', { n: this.bk_biz_name })})`;
default:
return this.event;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default class FunctionController {
'resourceManage.faultPool': ControllerItem<string>;
'resourceManage.toRecyclePool': ControllerItem<string>;
'resourceManage.dirtyHostManage': ControllerItem<string>;
'resourceManage.resourceTagsManagement': ControllerItem<string>;
'resourceManage.resourceOperationRecord': ControllerItem<string>;
bizConfigManage: ControllerItem<string>;
'bizConfigManage.monitorStrategy': ControllerItem<string>;
Expand Down
21 changes: 21 additions & 0 deletions dbm-ui/frontend/src/services/source/dbdirty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import DirtyMachinesModel from '@services/model/db-resource/dirtyMachines';
import FaultOrRecycleMachineModel from '@services/model/db-resource/FaultOrRecycleMachine';
import MachineEventModel from '@services/model/db-resource/machineEvent';
import type { ListBase } from '@services/types';

import http from '../http';
Expand Down Expand Up @@ -40,6 +41,26 @@ export function getDirtyMachines(params: { limit: number; offset: number }) {
}));
}

/**
* 机器事件列表
*/
export function getMachineEvents(params: {
operator?: string;
bk_biz_id?: number;
events?: string;
ips?: string;
create_at__lte?: string;
create_at__gte?: string;
domain?: string;
limit?: number;
offset?: number;
}) {
return http.get<ListBase<MachineEventModel[]>>(`${path}/list_machine_events/`, params).then((data) => ({
...data,
results: data.results.map((item) => new MachineEventModel(item)),
}));
}

/**
* 将污点池主机转移至待回收模块
*/
Expand Down
Loading

0 comments on commit 8ac0b44

Please sign in to comment.