Skip to content

Commit

Permalink
perf(frontend): mongodb工具箱重构_库表备份 TencentBlueKing#8498
Browse files Browse the repository at this point in the history
  • Loading branch information
3octaves committed Dec 19, 2024
1 parent f3bf3dd commit a1dd941
Show file tree
Hide file tree
Showing 7 changed files with 451 additions and 299 deletions.
3 changes: 3 additions & 0 deletions dbm-ui/frontend/src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3924,5 +3924,8 @@
"已选 IP": "已选 IP",
"业务资源池": "业务资源池",
"冷/热节点": "冷/热节点",
"目标集群n输入格式有误": "目标集群 {n} 输入格式有误",
"目标集群n不存在": "目标集群 {n} 不存在",
"目标集群n重复": "目标集群 {n} 重复",
"这行勿动!新增翻译请在上一行添加!": ""
}
6 changes: 5 additions & 1 deletion dbm-ui/frontend/src/services/source/dbbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ export function checkClusterDatabase(params: { bk_biz_id: number; cluster_id: nu
}

// 根据用户手动输入的ip[:port]查询真实的实例
export function checkInstance<T extends InstanceInfos>(params: { instance_addresses: string[]; bk_biz_id: number }) {
export function checkInstance<T extends InstanceInfos>(params: {
instance_addresses: string[];
bk_biz_id: number;
cluster_ids?: number[];
}) {
return http.post<T[]>(`${path}/check_instances/`, params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,25 @@
v-for="(item, index) in tableData"
:key="index">
<EditClusterColumn
ref="editClusterColumn"
v-if="isShardCluster"
v-model="item.cluster[0]"
:cluster-types="[formData.cluster_type]"
field="cluster.0.master_domain"
label="目标分片集群"
:selected="selected"
@batch-edit="handleClusterBatchEdit" />
<EditClusterWithSelectorColumn
v-else
v-model="item.cluster"
:cluster-types="[formData.cluster_type]"
:label="isShardCluster ? '目标分片集群' : '副本集'"
label="副本集"
:selected="selected"
@batch-edit="handleClusterBatchEdit" />
<EditTargetHostColumn
v-if="isShowHostColumn"
v-model="item.target_host"
:cluster-id="item.cluster.id" />
:cluster-id="item.cluster[0].id"
:disabled="!Boolean(item.cluster[0].id)" />
<EditDbNameColumn
v-model="item.db_patterns"
field="db_patterns"
Expand Down Expand Up @@ -148,6 +157,7 @@
</template>

<script setup lang="ts">
import _ from 'lodash';
import type { ComponentProps } from 'vue-component-type-helpers';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
Expand All @@ -167,17 +177,19 @@
import TicketRemark from '@views/db-manage/common/TicketRemark.vue';
import OperationColumn from '@views/db-manage/common/toolbox-field/operation-column/Index.vue';
import EditClusterColumn from '@views/db-manage/mongodb/common/toolbox-field/edit-cluster/Index.vue';
import EditClusterWithSelectorColumn from '@views/db-manage/mongodb/common/toolbox-field/edit-cluster-with-selector/Index.vue';
import EditDbNameColumn from '@views/db-manage/mongodb/common/toolbox-field/edit-db-name/Index.vue';
import EditTableNameColumn from '@views/db-manage/mongodb/common/toolbox-field/edit-db-table/Index.vue';
import EditTargetHostColumn from '@views/db-manage/mongodb/common/toolbox-field/edit-host/Index.vue';

export interface IDataRow {
import EditTargetHostColumn from './components/TargetHostColumn.vue';

interface IDataRow {
cluster: {
id?: number;
master_domain?: string;
cluster_type?: string;
cluster_type_name?: string;
};
}[];
target_host: string;
db_patterns: string[];
ignore_dbs: string[];
Expand All @@ -186,7 +198,7 @@
}

const createRowData = (values?: Partial<IDataRow>) => ({
cluster: values?.cluster ? values.cluster : {},
cluster: values?.cluster ? values.cluster : [{}],
target_host: values?.target_host || '',
db_patterns: values?.db_patterns || [],
ignore_dbs: values?.ignore_dbs || [],
Expand Down Expand Up @@ -219,9 +231,9 @@
nextTick(() => {
tableData.value = infos.map((item) =>
createRowData({
cluster: {
master_domain: clusters[item.cluster_ids[0]].immute_domain,
},
cluster: item.cluster_ids.map((clusterId) => ({
master_domain: clusters[clusterId].immute_domain,
})),
target_host: item.backup_host,
db_patterns: item.ns_filter.db_patterns,
ignore_dbs: item.ns_filter.ignore_dbs,
Expand All @@ -237,12 +249,26 @@
const editableTableRef = useTemplateRef('editableTable');

const rules = {
'cluster.master_domain': [
cluster: [
{
validator: (value: string) => {
if (value) {
const nonEmptyIdList = tableData.value.filter((row) => row.cluster.master_domain === value);
return nonEmptyIdList.length === 1;
validator: (value: IDataRow['cluster']) => {
const currentRowDomainMap = value.reduce<Record<string, number>>((prevMap, item) => {
if (item.master_domain) {
return Object.assign({}, prevMap, { [item.master_domain]: 0 });
}
return prevMap;
}, {});
tableData.value.forEach((rowItem) => {
rowItem.cluster.forEach((clusterItem) => {
if (clusterItem.master_domain && currentRowDomainMap[clusterItem.master_domain] !== undefined) {
currentRowDomainMap[clusterItem.master_domain] = currentRowDomainMap[clusterItem.master_domain] + 1;
}
});
});
const unValidRowDomainMapList = Object.entries(currentRowDomainMap).filter((mapItem) => mapItem[1] > 1);
const unValidRowDomainList = unValidRowDomainMapList.map((item) => item[0]);
if (unValidRowDomainList.length > 0) {
return t('目标集群n重复', { n: unValidRowDomainList.join(',') });
}
return true;
},
Expand All @@ -262,21 +288,31 @@
const isShowHostColumn = computed(() => isShardCluster.value && formData.backup_type === 'mongos');

const selected = computed(() => {
const selectedClusters: ComponentProps<typeof EditClusterColumn>['selected'] = {
const selectedClusters: ComponentProps<typeof EditClusterWithSelectorColumn>['selected'] = {
[formData.cluster_type]: [],
};
tableData.value.forEach((tableRow) => {
const { id, cluster_type: clusterType, master_domain: masterDomain } = tableRow.cluster;
if (id && clusterType && masterDomain) {
selectedClusters[clusterType as keyof typeof selectedClusters].push({
id,
master_domain: masterDomain,
});
}
tableRow.cluster.forEach((clusterItem) => {
const { id, cluster_type: clusterType, master_domain: masterDomain } = clusterItem;
if (id && clusterType && masterDomain) {
selectedClusters[clusterType as keyof typeof selectedClusters].push({
id,
master_domain: masterDomain,
});
}
});
});
return selectedClusters;
});

const clusterMemo = computed(() =>
Object.fromEntries(
Object.values(selected.value).flatMap((clusters) =>
clusters.filter((cluster) => cluster.master_domain).map((cluster) => [cluster.master_domain, true]),
),
),
);

watch(
() => formData.cluster_type,
() => {
Expand All @@ -285,18 +321,25 @@
);

const handleClusterBatchEdit = (clusterList: MongodbModel[]) => {
const newList = clusterList.map((item) =>
createRowData({
cluster: {
id: item.id,
master_domain: item.master_domain,
cluster_type: item.cluster_type,
cluster_type_name: item.cluster_type_name,
},
}),
);
const newList: IDataRow[] = [];
clusterList.forEach((item) => {
if (!clusterMemo.value[item.master_domain]) {
newList.push(
createRowData({
cluster: [
{
id: item.id,
master_domain: item.master_domain,
cluster_type: item.cluster_type,
cluster_type_name: item.cluster_type_name,
},
],
}),
);
}
});

tableData.value = [...(tableData.value[0].cluster.master_domain ? tableData.value : []), ...newList];
tableData.value = [...(_.isEmpty(tableData.value[0].cluster) ? tableData.value : []), ...newList];
window.changeConfirm = true;
};

Expand All @@ -321,7 +364,7 @@
file_tag: formData.file_tag,
infos: tableData.value.map((tableRow) => {
const result = {
cluster_ids: [tableRow.cluster.id],
cluster_ids: tableRow.cluster.map((item) => item.id),
cluster_type: formData.cluster_type,
ns_filter: {
db_patterns: tableRow.db_patterns,
Expand Down
Loading

0 comments on commit a1dd941

Please sign in to comment.