Skip to content

Commit

Permalink
feat(frontend): mysql和tendbcluster 备份单据优化 #6731
Browse files Browse the repository at this point in the history
  • Loading branch information
3octaves authored and hLinx committed Dec 6, 2024
1 parent 1ddada1 commit bdf0aa3
Show file tree
Hide file tree
Showing 26 changed files with 442 additions and 456 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ import { random } from '@utils';
// Mysql 全库备份
export function generateMysqlDbBackupCloneData(ticketData: TicketModel<MySQLFullBackupDetails>) {
const { clusters, infos } = ticketData.details;
const tableDataList = infos.clusters.map((item) => ({
const isNewProtocol = Array.isArray(infos);
const tableDataList = (isNewProtocol ? infos : infos.clusters).map((item) => ({
rowKey: random(),
clusterData: {
id: item.cluster_id,
domain: clusters[item.cluster_id].immute_domain,
type: clusters[item.cluster_id].cluster_type,
},
backupLocal: item.backup_local,
}));
return Promise.resolve({
tableDataList,
backupType: infos.backup_type,
fileTag: infos.file_tag,
backupType: isNewProtocol ? ticketData.details.backup_type : infos.backup_type,
fileTag: isNewProtocol ? ticketData.details.file_tag : infos.file_tag,
remark: ticketData.remark,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import type { MySQLTableBackupDetails } from '@services/model/ticket/details/mysql';
import TicketModel from '@services/model/ticket/ticket';

import { ClusterTypes } from '@common/const';

import { random } from '@utils';

// Mysql 库表备份
Expand All @@ -24,6 +26,7 @@ export function generateMysqlDbTableBackupCloneData(ticketData: TicketModel<MySQ
id: item.cluster_id,
domain: clusters[item.cluster_id].immute_domain,
},
backupLocal: item.backup_on || clusters[item.cluster_id].cluster_type === ClusterTypes.TENDBHA ? 'Slave' : 'Master',
dbPatterns: item.db_patterns,
tablePatterns: item.table_patterns,
ignoreDbs: item.ignore_dbs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { random } from '@utils';
// Spider TenDBCluster 全备单据
export function generateSpiderDbBackupCloneData(ticketData: TicketModel<SpiderFullBackupDetails>) {
const { infos, clusters } = ticketData.details;
const tableDataList = infos.clusters.map((item) => {
const isNewProtocol = Array.isArray(infos);
const tableDataList = (isNewProtocol ? infos : infos.clusters).map((item) => {
const clusterItem = clusters[item.cluster_id];

return {
Expand All @@ -35,8 +36,8 @@ export function generateSpiderDbBackupCloneData(ticketData: TicketModel<SpiderFu
return Promise.resolve({
tableDataList,
form: {
backup_type: infos.backup_type,
file_tag: infos.file_tag,
backup_type: isNewProtocol ? ticketData.details.backup_type : infos.backup_type,
file_tag: isNewProtocol ? ticketData.details.file_tag : infos.file_tag,
remark: ticketData.remark,
},
});
Expand Down
29 changes: 20 additions & 9 deletions dbm-ui/frontend/src/services/model/ticket/details/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,26 @@ export interface MySQLFlashback extends DetailBase {
*/
export interface MySQLFullBackupDetails extends DetailBase {
clusters: DetailClusters;
infos: {
backup_type: string;
clusters: {
backup_local: string;
cluster_id: number;
}[];
file_tag: string;
online: boolean;
};
// 新版协议
backup_type: string;
file_tag: string;
online: boolean;
infos:
| {
// 旧版协议
backup_type: string;
clusters: {
backup_local: string;
cluster_id: number;
}[];
file_tag: string;
online: boolean;
}
| {
// 新版协议
backup_local: string;
cluster_id: number;
}[];
}

/**
Expand Down
26 changes: 18 additions & 8 deletions dbm-ui/frontend/src/services/model/ticket/details/spider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,24 @@ export interface SpiderTableBackupDetails {

// Spider TenDBCluster 全备单据
export interface SpiderFullBackupDetails {
infos: {
backup_type: 'logical' | 'physical';
file_tag: 'MYSQL_FULL_BACKUP' | 'LONGDAY_DBFILE_3Y';
clusters: {
cluster_id: number;
backup_local: string; // spider_mnt:: 127.0.0.1: 8000
}[];
};
// 新版协议
backup_type: 'logical' | 'physical';
file_tag: 'MYSQL_FULL_BACKUP' | 'LONGDAY_DBFILE_3Y';
infos:
| {
// 旧版协议
backup_type: 'logical' | 'physical';
file_tag: 'MYSQL_FULL_BACKUP' | 'LONGDAY_DBFILE_3Y';
clusters: {
cluster_id: number;
backup_local: string; // spider_mnt:: 127.0.0.1: 8000
}[];
}
| {
// 新版协议
cluster_id: number;
backup_local: string; // spider_mnt:: 127.0.0.1: 8000
}[];
clusters: DetailClusters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
:removeable="tableData.length < 2"
@add="(payload: Array<IDataRow>) => handleAppend(index, payload)"
@clone="(payload: IDataRow) => handleClone(index, payload)"
@input-cluster-finish="(item: IDataRow) => handleInputCluster(index, item)"
@cluster-input-finish="(clusterId: number) => handleChangeCluster(index, clusterId)"
@remove="handleRemove(index)" />
</RenderData>
<DbForm
Expand Down Expand Up @@ -74,7 +74,7 @@
<TicketRemark v-model="formData.remark" />
<ClusterSelector
v-model:is-show="isShowBatchSelector"
:cluster-types="[ClusterTypes.TENDBHA]"
:cluster-types="[ClusterTypes.TENDBHA, ClusterTypes.TENDBSINGLE]"
:selected="selectedClusters"
@change="handelClusterChange" />
</div>
Expand Down Expand Up @@ -105,6 +105,8 @@
import { useRouter } from 'vue-router';

import TendbhaModel from '@services/model/mysql/tendbha';
import TendbsingleModel from '@services/model/mysql/tendbsingle';
import { queryClusters } from '@services/source/mysqlCluster';
import { createTicket } from '@services/source/ticket';

import { useTicketCloneInfo } from '@hooks';
Expand Down Expand Up @@ -149,7 +151,10 @@
const formData = reactive(createDefaultData());

const tableData = ref<Array<IDataRow>>([createRowData({})]);
const selectedClusters = shallowRef<{ [key: string]: Array<TendbhaModel> }>({ [ClusterTypes.TENDBHA]: [] });
const selectedClusters = shallowRef<{ [key: string]: Array<TendbhaModel | TendbsingleModel> }>({
[ClusterTypes.TENDBHA]: [],
[ClusterTypes.TENDBSINGLE]: [],
});

// 集群域名是否已存在表格的映射表
let domainMemo: Record<string, boolean> = {};
Expand All @@ -174,28 +179,32 @@
}
tableData.value.forEach((row) => {
Object.assign(row, {
backupLocal: value,
backupLocal: !row.clusterData || row.clusterData.type === ClusterTypes.TENDBSINGLE ? 'master' : value,
});
});
};

// 批量选择
const handelClusterChange = (selected: Record<string, Array<TendbhaModel>>) => {
const handelClusterChange = (selected: Record<string, Array<TendbhaModel | TendbsingleModel>>) => {
selectedClusters.value = selected;
const newList = selected[ClusterTypes.TENDBHA].reduce((results, clusterData) => {
const domain = clusterData.master_domain;
if (!domainMemo[domain]) {
const row = createRowData({
clusterData: {
id: clusterData.id,
domain: clusterData.master_domain,
},
});
results.push(row);
domainMemo[domain] = true;
}
return results;
}, [] as IDataRow[]);
const newList = [...selected[ClusterTypes.TENDBHA], ...selected[ClusterTypes.TENDBSINGLE]].reduce(
(results, clusterData) => {
const domain = clusterData.master_domain;
if (!domainMemo[domain]) {
const row = createRowData({
clusterData: {
id: clusterData.id,
domain: clusterData.master_domain,
type: clusterData.cluster_type,
},
});
results.push(row);
domainMemo[domain] = true;
}
return results;
},
[] as IDataRow[],
);

if (checkListEmpty(tableData.value)) {
tableData.value = newList;
Expand All @@ -206,8 +215,34 @@
};

// 输入一个集群
const handleInputCluster = (index: number, item: IDataRow) => {
tableData.value[index] = item;
const handleChangeCluster = async (index: number, clusterId: number) => {
if (tableData.value[index].clusterData?.id === clusterId) {
return;
}

const resultList = await queryClusters({
cluster_filters: [
{
id: clusterId,
},
],
bk_biz_id: window.PROJECT_CONFIG.BIZ_ID,
});
if (resultList.length < 1) {
return;
}
const item = resultList[0];
const domain = item.master_domain;
const row = createRowData({
clusterData: {
id: item.id,
domain,
type: item.cluster_type,
},
});
tableData.value[index] = row;
domainMemo[domain] = true;
selectedClusters.value[item.cluster_type].push(item);
};

// 追加集群
Expand All @@ -225,8 +260,10 @@
tableData.value = dataList;
if (domain) {
delete domainMemo[domain];
const clustersArr = selectedClusters.value[ClusterTypes.TENDBHA];
selectedClusters.value[ClusterTypes.TENDBHA] = clustersArr.filter((item) => item.master_domain !== domain);
const haList = selectedClusters.value[ClusterTypes.TENDBHA];
selectedClusters.value[ClusterTypes.TENDBHA] = haList.filter((item) => item.master_domain !== domain);
const singleList = selectedClusters.value[ClusterTypes.TENDBSINGLE];
selectedClusters.value[ClusterTypes.TENDBSINGLE] = singleList.filter((item) => item.master_domain !== domain);
}
};

Expand All @@ -250,10 +287,9 @@
ticket_type: 'MYSQL_HA_FULL_BACKUP',
remark: formData.remark,
details: {
infos: {
...formData,
clusters: infos,
},
backup_type: formData.backup_type,
file_tag: formData.file_tag,
infos,
},
}).then((data) => {
window.changeConfirm = false;
Expand All @@ -276,6 +312,7 @@
tableData.value = [createRowData()];
Object.assign(formData, createDefaultData());
selectedClusters.value[ClusterTypes.TENDBHA] = [];
selectedClusters.value[ClusterTypes.TENDBSINGLE] = [];
domainMemo = {};
window.changeConfirm = false;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
const selectList = [
{
value: 'master',
label: 'master',
label: 'Master',
},
{
value: 'slave',
label: 'slave',
label: 'Slave',
},
];

Expand Down
Loading

0 comments on commit bdf0aa3

Please sign in to comment.