1 parent
d616e6b1a8
commit
6a06a12455
14 files changed
+388
-20
No files matched your search
@@ -16,7 +16,7 @@ import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";
|
|||||||
import EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";
|
import EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";
|
||||||
import NacosConfigDiffDialog from "@/components/nacos/NacosConfigDiffDialog.vue";
|
import NacosConfigDiffDialog from "@/components/nacos/NacosConfigDiffDialog.vue";
|
||||||
import NacosConfigHistoryDialog from "@/components/nacos/NacosConfigHistoryDialog.vue";
|
import NacosConfigHistoryDialog from "@/components/nacos/NacosConfigHistoryDialog.vue";
|
||||||
import NacosConfigBatchDialog, { type NacosBatchDialogMode, type NacosConfigTransferTarget } from "@/components/nacos/NacosConfigBatchDialog.vue";
|
import NacosConfigBatchDialog, { type NacosBatchDialogMode, type NacosConfigTransferDialogPayload, type NacosConfigTransferTarget } from "@/components/nacos/NacosConfigBatchDialog.vue";
|
||||||
import NacosContentSearchDialog from "@/components/nacos/NacosContentSearchDialog.vue";
|
import NacosContentSearchDialog from "@/components/nacos/NacosContentSearchDialog.vue";
|
||||||
import { useToast } from "@/composables/useToast";
|
import { useToast } from "@/composables/useToast";
|
||||||
import { useNacosConfigListColumnResize, type ToggleableNacosConfigListColumnKey } from "@/composables/useNacosConfigListColumnResize";
|
import { useNacosConfigListColumnResize, type ToggleableNacosConfigListColumnKey } from "@/composables/useNacosConfigListColumnResize";
|
||||||
@@ -67,7 +67,6 @@ import type {
|
|||||||
NacosConnectionInfo,
|
NacosConnectionInfo,
|
||||||
NacosContentMatch,
|
NacosContentMatch,
|
||||||
NacosContentSearchResult,
|
NacosContentSearchResult,
|
||||||
NacosConflictPolicy,
|
|
||||||
NacosInstanceInfo,
|
NacosInstanceInfo,
|
||||||
NacosInstancePatch,
|
NacosInstancePatch,
|
||||||
NacosInstanceRef,
|
NacosInstanceRef,
|
||||||
@@ -435,6 +434,8 @@ function selectedKeys(): NacosConfigKey[] {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectedConfigTransferKeys = computed(() => selectedKeys());
|
||||||
|
|
||||||
function isBatchDeleteSnapshotInScope(snapshot: NacosBatchDeleteSnapshot) {
|
function isBatchDeleteSnapshotInScope(snapshot: NacosBatchDeleteSnapshot) {
|
||||||
return snapshot.connectionId === props.connectionId && snapshot.namespace === namespace.value;
|
return snapshot.connectionId === props.connectionId && snapshot.namespace === namespace.value;
|
||||||
}
|
}
|
||||||
@@ -1245,7 +1246,7 @@ async function exportConfigArchive(scope: NacosConfigSelectionScope) {
|
|||||||
|
|
||||||
const batchTransferRequest = shallowRef<NacosConfigTransferRequest | null>(null);
|
const batchTransferRequest = shallowRef<NacosConfigTransferRequest | null>(null);
|
||||||
|
|
||||||
async function previewBatch(payload: { scope: NacosConfigSelectionScope; targetConnectionId: string; targetNamespace: string; targetGroup: string; policy: NacosConflictPolicy }) {
|
async function previewBatch(payload: NacosConfigTransferDialogPayload) {
|
||||||
batchLoading.value = true;
|
batchLoading.value = true;
|
||||||
batchError.value = "";
|
batchError.value = "";
|
||||||
batchPreview.value = null;
|
batchPreview.value = null;
|
||||||
@@ -1262,6 +1263,7 @@ async function previewBatch(payload: { scope: NacosConfigSelectionScope; targetC
|
|||||||
source: buildConfigSelector(payload.scope),
|
source: buildConfigSelector(payload.scope),
|
||||||
targetNamespace: payload.targetNamespace,
|
targetNamespace: payload.targetNamespace,
|
||||||
targetGroup: payload.targetGroup || undefined,
|
targetGroup: payload.targetGroup || undefined,
|
||||||
|
dataIdMappings: payload.dataIdMappings,
|
||||||
conflictPolicy: payload.policy,
|
conflictPolicy: payload.policy,
|
||||||
};
|
};
|
||||||
batchTransferRequest.value = req;
|
batchTransferRequest.value = req;
|
||||||
@@ -1274,7 +1276,7 @@ async function previewBatch(payload: { scope: NacosConfigSelectionScope; targetC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function applyBatch(payload: { scope: NacosConfigSelectionScope; targetConnectionId: string; targetNamespace: string; targetGroup: string; policy: NacosConflictPolicy }) {
|
async function applyBatch(payload: NacosConfigTransferDialogPayload) {
|
||||||
if (batchLoading.value || batchReport.value || !batchPreview.value) return;
|
if (batchLoading.value || batchReport.value || !batchPreview.value) return;
|
||||||
if (payload.policy === "OVERWRITE" && !window.confirm(t("nacos.overwriteConfirm"))) return;
|
if (payload.policy === "OVERWRITE" && !window.confirm(t("nacos.overwriteConfirm"))) return;
|
||||||
const targetConnectionId = batchMode.value === "import" ? props.connectionId : payload.targetConnectionId;
|
const targetConnectionId = batchMode.value === "import" ? props.connectionId : payload.targetConnectionId;
|
||||||
@@ -3030,6 +3032,7 @@ onBeforeUnmount(() => {
|
|||||||
:mode="batchMode"
|
:mode="batchMode"
|
||||||
:loading="batchLoading"
|
:loading="batchLoading"
|
||||||
:selected-count="selectedConfigCount"
|
:selected-count="selectedConfigCount"
|
||||||
|
:selected-keys="selectedConfigTransferKeys"
|
||||||
:filtered-count="configTotal"
|
:filtered-count="configTotal"
|
||||||
:target-connections="batchTargetConnections"
|
:target-connections="batchTargetConnections"
|
||||||
:target-connection-id="batchTargetConnectionId"
|
:target-connection-id="batchTargetConnectionId"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useI18n } from "vue-i18n";
|
|||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||||
import type { NacosBatchPreview, NacosBatchReport, NacosConfigSelectionScope, NacosConflictPolicy, NacosNamespaceInfo } from "@/types/nacos";
|
import type { NacosBatchPreview, NacosBatchReport, NacosConfigDataIdMapping, NacosConfigKey, NacosConfigSelectionScope, NacosConflictPolicy, NacosNamespaceInfo } from "@/types/nacos";
|
||||||
import { nacosNamespaceIdentity } from "@/lib/nacos/nacosNamespaceVisibility";
|
import { nacosNamespaceIdentity } from "@/lib/nacos/nacosNamespaceVisibility";
|
||||||
|
|
||||||
export type NacosBatchDialogMode = "export" | "import" | "copy";
|
export type NacosBatchDialogMode = "export" | "import" | "copy";
|
||||||
@@ -15,11 +15,21 @@ export interface NacosConfigTransferTarget {
|
|||||||
label: string;
|
label: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface NacosConfigTransferDialogPayload {
|
||||||
|
scope: NacosConfigSelectionScope;
|
||||||
|
targetConnectionId: string;
|
||||||
|
targetNamespace: string;
|
||||||
|
targetGroup: string;
|
||||||
|
dataIdMappings?: NacosConfigDataIdMapping[];
|
||||||
|
policy: NacosConflictPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
open: boolean;
|
open: boolean;
|
||||||
mode: NacosBatchDialogMode;
|
mode: NacosBatchDialogMode;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
selectedCount: number;
|
selectedCount: number;
|
||||||
|
selectedKeys: NacosConfigKey[];
|
||||||
filteredCount: number;
|
filteredCount: number;
|
||||||
targetConnections: NacosConfigTransferTarget[];
|
targetConnections: NacosConfigTransferTarget[];
|
||||||
targetConnectionId: string;
|
targetConnectionId: string;
|
||||||
@@ -37,8 +47,8 @@ const emit = defineEmits<{
|
|||||||
chooseFile: [];
|
chooseFile: [];
|
||||||
reset: [];
|
reset: [];
|
||||||
targetConnectionChange: [connectionId: string];
|
targetConnectionChange: [connectionId: string];
|
||||||
preview: [payload: { scope: NacosConfigSelectionScope; targetConnectionId: string; targetNamespace: string; targetGroup: string; policy: NacosConflictPolicy }];
|
preview: [payload: NacosConfigTransferDialogPayload];
|
||||||
apply: [payload: { scope: NacosConfigSelectionScope; targetConnectionId: string; targetNamespace: string; targetGroup: string; policy: NacosConflictPolicy }];
|
apply: [payload: NacosConfigTransferDialogPayload];
|
||||||
export: [scope: NacosConfigSelectionScope];
|
export: [scope: NacosConfigSelectionScope];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
@@ -47,6 +57,7 @@ const scope = ref<NacosConfigSelectionScope>("selected");
|
|||||||
const policy = ref<NacosConflictPolicy>("ABORT");
|
const policy = ref<NacosConflictPolicy>("ABORT");
|
||||||
const targetNamespace = ref("");
|
const targetNamespace = ref("");
|
||||||
const targetGroup = ref("");
|
const targetGroup = ref("");
|
||||||
|
const targetDataIdDrafts = ref<NacosConfigDataIdMapping[]>([]);
|
||||||
|
|
||||||
const titleKey = computed(() => `nacos.batch${props.mode[0].toUpperCase()}${props.mode.slice(1)}Title`);
|
const titleKey = computed(() => `nacos.batch${props.mode[0].toUpperCase()}${props.mode.slice(1)}Title`);
|
||||||
const descriptionKey = computed(() => `nacos.batch${props.mode[0].toUpperCase()}${props.mode.slice(1)}Description`);
|
const descriptionKey = computed(() => `nacos.batch${props.mode[0].toUpperCase()}${props.mode.slice(1)}Description`);
|
||||||
@@ -111,6 +122,32 @@ function resetTargetNamespace() {
|
|||||||
targetNamespace.value = targetNamespaces.value[0] ? JSON.stringify(targetNamespaces.value[0].namespace) : "";
|
targetNamespace.value = targetNamespaces.value[0] ? JSON.stringify(targetNamespaces.value[0].namespace) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetTargetDataIdDrafts() {
|
||||||
|
targetDataIdDrafts.value = props.selectedKeys.map((key) => ({
|
||||||
|
sourceGroup: key.group,
|
||||||
|
sourceDataId: key.dataId,
|
||||||
|
targetDataId: "",
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function transferPayload(): NacosConfigTransferDialogPayload {
|
||||||
|
const dataIdMappings =
|
||||||
|
scope.value === "selected"
|
||||||
|
? targetDataIdDrafts.value.flatMap((mapping) => {
|
||||||
|
const targetDataId = mapping.targetDataId.trim();
|
||||||
|
return targetDataId && targetDataId !== mapping.sourceDataId ? [{ ...mapping, targetDataId }] : [];
|
||||||
|
})
|
||||||
|
: [];
|
||||||
|
return {
|
||||||
|
scope: scope.value,
|
||||||
|
targetConnectionId: props.targetConnectionId,
|
||||||
|
targetNamespace: selectedTargetNamespace.value,
|
||||||
|
targetGroup: targetGroup.value.trim(),
|
||||||
|
...(dataIdMappings.length ? { dataIdMappings } : {}),
|
||||||
|
policy: policy.value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.open,
|
() => props.open,
|
||||||
(open) => {
|
(open) => {
|
||||||
@@ -118,6 +155,7 @@ watch(
|
|||||||
scope.value = props.selectedCount ? "selected" : "filtered";
|
scope.value = props.selectedCount ? "selected" : "filtered";
|
||||||
policy.value = "ABORT";
|
policy.value = "ABORT";
|
||||||
targetGroup.value = "";
|
targetGroup.value = "";
|
||||||
|
resetTargetDataIdDrafts();
|
||||||
resetTargetNamespace();
|
resetTargetNamespace();
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
@@ -206,7 +244,29 @@ watch(targetNamespaces, () => {
|
|||||||
</div>
|
</div>
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<div class="text-sm font-medium">{{ t("nacos.targetGroup") }}</div>
|
<div class="text-sm font-medium">{{ t("nacos.targetGroup") }}</div>
|
||||||
<input v-model="targetGroup" type="text" class="h-10 w-full rounded-md border border-input bg-background px-3 text-sm" :disabled="loading" :placeholder="t('nacos.targetGroupPlaceholder')" @change="emit('reset')" />
|
<input v-model="targetGroup" data-testid="nacos-target-group" type="text" class="h-10 w-full rounded-md border border-input bg-background px-3 text-sm" :disabled="loading" :placeholder="t('nacos.targetGroupPlaceholder')" @change="emit('reset')" />
|
||||||
|
</div>
|
||||||
|
<div v-if="scope === 'selected' && targetDataIdDrafts.length" class="space-y-2">
|
||||||
|
<div class="text-sm font-medium">{{ t("nacos.targetDataIds") }}</div>
|
||||||
|
<p class="text-xs text-muted-foreground">{{ t("nacos.targetDataIdsHint") }}</p>
|
||||||
|
<div class="max-h-52 space-y-2 overflow-auto rounded-md border p-2">
|
||||||
|
<label v-for="(mapping, index) in targetDataIdDrafts" :key="`${mapping.sourceGroup}\u0000${mapping.sourceDataId}`" :for="`nacos-target-data-id-${index}`" class="grid gap-2 rounded-md bg-muted/30 p-2 text-xs sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)] sm:items-center">
|
||||||
|
<span class="min-w-0">
|
||||||
|
<span class="block truncate font-medium text-foreground" :title="mapping.sourceDataId">{{ mapping.sourceDataId }}</span>
|
||||||
|
<span class="block truncate text-muted-foreground" :title="mapping.sourceGroup">{{ mapping.sourceGroup }}</span>
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
:id="`nacos-target-data-id-${index}`"
|
||||||
|
v-model="mapping.targetDataId"
|
||||||
|
data-testid="nacos-target-data-id"
|
||||||
|
type="text"
|
||||||
|
class="h-9 w-full rounded-md border border-input bg-background px-3 text-sm text-foreground"
|
||||||
|
:disabled="loading"
|
||||||
|
:placeholder="mapping.sourceDataId"
|
||||||
|
@input="emit('reset')"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-xs text-muted-foreground">{{ t("nacos.copyKeepsSource") }}</p>
|
<p class="text-xs text-muted-foreground">{{ t("nacos.copyKeepsSource") }}</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -285,11 +345,11 @@ watch(targetNamespaces, () => {
|
|||||||
{{ t("nacos.exportZip") }}
|
{{ t("nacos.exportZip") }}
|
||||||
</Button>
|
</Button>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<Button v-if="!preview" :disabled="loading || !canContinue" @click="emit('preview', { scope, targetConnectionId, targetNamespace: selectedTargetNamespace, targetGroup: targetGroup.trim(), policy })">
|
<Button v-if="!preview" :disabled="loading || !canContinue" @click="emit('preview', transferPayload())">
|
||||||
<Loader2 v-if="loading" class="mr-2 h-4 w-4 animate-spin" />
|
<Loader2 v-if="loading" class="mr-2 h-4 w-4 animate-spin" />
|
||||||
{{ t("nacos.preview") }}
|
{{ t("nacos.preview") }}
|
||||||
</Button>
|
</Button>
|
||||||
<Button v-else :variant="policy === 'OVERWRITE' ? 'destructive' : 'default'" :disabled="loading || hasPreviewBlockingErrors" @click="emit('apply', { scope, targetConnectionId, targetNamespace: selectedTargetNamespace, targetGroup: targetGroup.trim(), policy })">
|
<Button v-else :variant="policy === 'OVERWRITE' ? 'destructive' : 'default'" :disabled="loading || hasPreviewBlockingErrors" @click="emit('apply', transferPayload())">
|
||||||
<Loader2 v-if="loading" class="mr-2 h-4 w-4 animate-spin" />
|
<Loader2 v-if="loading" class="mr-2 h-4 w-4 animate-spin" />
|
||||||
{{ t("nacos.apply") }}
|
{{ t("nacos.apply") }}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
+84
-3
@@ -4,7 +4,7 @@ import { createApp, defineComponent, h, nextTick, type App } from "vue";
|
|||||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
import i18n from "@/i18n";
|
import i18n from "@/i18n";
|
||||||
import NacosConfigBatchDialog from "@/components/nacos/NacosConfigBatchDialog.vue";
|
import NacosConfigBatchDialog from "@/components/nacos/NacosConfigBatchDialog.vue";
|
||||||
import type { NacosBatchReport } from "@/types/nacos";
|
import type { NacosBatchReport, NacosConfigKey } from "@/types/nacos";
|
||||||
|
|
||||||
const mountedApps: App[] = [];
|
const mountedApps: App[] = [];
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ async function mountDialog(
|
|||||||
{ namespace: "remote-only", namespaceShowName: "Remote only" },
|
{ namespace: "remote-only", namespaceShowName: "Remote only" },
|
||||||
],
|
],
|
||||||
report: NacosBatchReport | null = null,
|
report: NacosBatchReport | null = null,
|
||||||
|
selectedKeys: NacosConfigKey[] = [{ namespace: "shared", group: "DEFAULT_GROUP", dataId: "app.yaml" }],
|
||||||
) {
|
) {
|
||||||
const onTargetConnectionChange = vi.fn();
|
const onTargetConnectionChange = vi.fn();
|
||||||
const onPreview = vi.fn();
|
const onPreview = vi.fn();
|
||||||
@@ -27,7 +28,8 @@ async function mountDialog(
|
|||||||
open: true,
|
open: true,
|
||||||
mode: "copy",
|
mode: "copy",
|
||||||
loading: false,
|
loading: false,
|
||||||
selectedCount: 1,
|
selectedCount: selectedKeys.length,
|
||||||
|
selectedKeys,
|
||||||
filteredCount: 1,
|
filteredCount: 1,
|
||||||
targetConnections: [
|
targetConnections: [
|
||||||
{ id: "source", label: "Source" },
|
{ id: "source", label: "Source" },
|
||||||
@@ -80,7 +82,7 @@ describe("NacosConfigBatchDialog cross-connection sync", () => {
|
|||||||
|
|
||||||
it("includes a trimmed target group override in the preview payload when provided", async () => {
|
it("includes a trimmed target group override in the preview payload when provided", async () => {
|
||||||
const { onPreview } = await mountDialog("remote");
|
const { onPreview } = await mountDialog("remote");
|
||||||
const groupInput = document.body.querySelector("input[type=text]") as HTMLInputElement;
|
const groupInput = document.body.querySelector("[data-testid=nacos-target-group]") as HTMLInputElement;
|
||||||
groupInput.value = " TARGET_GROUP ";
|
groupInput.value = " TARGET_GROUP ";
|
||||||
groupInput.dispatchEvent(new Event("input"));
|
groupInput.dispatchEvent(new Event("input"));
|
||||||
await nextTick();
|
await nextTick();
|
||||||
@@ -98,6 +100,85 @@ describe("NacosConfigBatchDialog cross-connection sync", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("emits a trimmed target Data ID mapping for one selected config", async () => {
|
||||||
|
const { onPreview } = await mountDialog("remote");
|
||||||
|
const dataIdInput = document.body.querySelector("[data-testid=nacos-target-data-id]") as HTMLInputElement;
|
||||||
|
dataIdInput.value = " app-prod.yaml ";
|
||||||
|
dataIdInput.dispatchEvent(new Event("input"));
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
Array.from(document.body.querySelectorAll("button"))
|
||||||
|
.find((button) => button.textContent?.includes("Preview"))
|
||||||
|
?.click();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
expect(onPreview).toHaveBeenCalledWith({
|
||||||
|
scope: "selected",
|
||||||
|
targetConnectionId: "remote",
|
||||||
|
targetNamespace: "shared",
|
||||||
|
targetGroup: "",
|
||||||
|
dataIdMappings: [{ sourceGroup: "DEFAULT_GROUP", sourceDataId: "app.yaml", targetDataId: "app-prod.yaml" }],
|
||||||
|
policy: "ABORT",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("lets multiple selected configs independently retain or edit their target Data IDs", async () => {
|
||||||
|
const selectedKeys = [
|
||||||
|
{ namespace: "shared", group: "DEFAULT_GROUP", dataId: "app.yaml" },
|
||||||
|
{ namespace: "shared", group: "WORKER_GROUP", dataId: "worker.yaml" },
|
||||||
|
];
|
||||||
|
const { onPreview } = await mountDialog("remote", undefined, null, selectedKeys);
|
||||||
|
const dataIdInputs = Array.from(document.body.querySelectorAll("[data-testid=nacos-target-data-id]")) as HTMLInputElement[];
|
||||||
|
expect(dataIdInputs).toHaveLength(2);
|
||||||
|
dataIdInputs[1].value = "worker-prod.yaml";
|
||||||
|
dataIdInputs[1].dispatchEvent(new Event("input"));
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
Array.from(document.body.querySelectorAll("button"))
|
||||||
|
.find((button) => button.textContent?.includes("Preview"))
|
||||||
|
?.click();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
expect(onPreview).toHaveBeenCalledWith({
|
||||||
|
scope: "selected",
|
||||||
|
targetConnectionId: "remote",
|
||||||
|
targetNamespace: "shared",
|
||||||
|
targetGroup: "",
|
||||||
|
dataIdMappings: [{ sourceGroup: "WORKER_GROUP", sourceDataId: "worker.yaml", targetDataId: "worker-prod.yaml" }],
|
||||||
|
policy: "ABORT",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("treats blank or unchanged target Data IDs as source-preserving defaults", async () => {
|
||||||
|
const { onPreview } = await mountDialog("remote");
|
||||||
|
const dataIdInput = document.body.querySelector("[data-testid=nacos-target-data-id]") as HTMLInputElement;
|
||||||
|
dataIdInput.value = " app.yaml ";
|
||||||
|
dataIdInput.dispatchEvent(new Event("input"));
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
Array.from(document.body.querySelectorAll("button"))
|
||||||
|
.find((button) => button.textContent?.includes("Preview"))
|
||||||
|
?.click();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
expect(onPreview.mock.calls[0][0]).not.toHaveProperty("dataIdMappings");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("hides target Data ID editing and omits mappings for non-selected scopes", async () => {
|
||||||
|
const { onPreview } = await mountDialog("remote");
|
||||||
|
const filteredScope = document.body.querySelector("input[value=filtered]") as HTMLInputElement;
|
||||||
|
filteredScope.click();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
expect(document.body.querySelector("[data-testid=nacos-target-data-id]")).toBeNull();
|
||||||
|
Array.from(document.body.querySelectorAll("button"))
|
||||||
|
.find((button) => button.textContent?.includes("Preview"))
|
||||||
|
?.click();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
expect(onPreview.mock.calls[0][0]).not.toHaveProperty("dataIdMappings");
|
||||||
|
});
|
||||||
|
|
||||||
it("excludes the source namespace only for same-connection sync and emits connection changes", async () => {
|
it("excludes the source namespace only for same-connection sync and emits connection changes", async () => {
|
||||||
const { onTargetConnectionChange } = await mountDialog("source");
|
const { onTargetConnectionChange } = await mountDialog("source");
|
||||||
const selects = Array.from(document.body.querySelectorAll("select")) as HTMLSelectElement[];
|
const selects = Array.from(document.body.querySelectorAll("select")) as HTMLSelectElement[];
|
||||||
|
|||||||
@@ -8353,6 +8353,8 @@ export default {
|
|||||||
chooseTargetNamespace: "Choose another namespace",
|
chooseTargetNamespace: "Choose another namespace",
|
||||||
targetGroup: "Target group (optional)",
|
targetGroup: "Target group (optional)",
|
||||||
targetGroupPlaceholder: "Same as source group",
|
targetGroupPlaceholder: "Same as source group",
|
||||||
|
targetDataIds: "Target Data IDs (optional)",
|
||||||
|
targetDataIdsHint: "Selected configs can be renamed individually. Leave a field blank to keep its source Data ID.",
|
||||||
copyKeepsSource: "Sync uses one-way copy semantics. Source namespace configs stay unchanged.",
|
copyKeepsSource: "Sync uses one-way copy semantics. Source namespace configs stay unchanged.",
|
||||||
conflictPolicy: "Conflict policy",
|
conflictPolicy: "Conflict policy",
|
||||||
policyABORT: "Abort on conflict",
|
policyABORT: "Abort on conflict",
|
||||||
|
|||||||
@@ -6809,6 +6809,8 @@ export default withEnglishFallback({
|
|||||||
chooseTargetNamespace: "Seleccione otro namespace",
|
chooseTargetNamespace: "Seleccione otro namespace",
|
||||||
targetGroup: "Group de destino (opcional)",
|
targetGroup: "Group de destino (opcional)",
|
||||||
targetGroupPlaceholder: "Igual que el group de origen",
|
targetGroupPlaceholder: "Igual que el group de origen",
|
||||||
|
targetDataIds: "Data ID de destino (opcional)",
|
||||||
|
targetDataIdsHint: "Las configuraciones seleccionadas se pueden renombrar individualmente. Deja un campo vacío para conservar el Data ID de origen.",
|
||||||
copyKeepsSource: "La sincronización usa una copia unidireccional. Las configuraciones del namespace de origen no cambian.",
|
copyKeepsSource: "La sincronización usa una copia unidireccional. Las configuraciones del namespace de origen no cambian.",
|
||||||
conflictPolicy: "Política de conflictos",
|
conflictPolicy: "Política de conflictos",
|
||||||
policyABORT: "Abortar al encontrar conflictos",
|
policyABORT: "Abortar al encontrar conflictos",
|
||||||
|
|||||||
@@ -6810,6 +6810,8 @@ export default withEnglishFallback({
|
|||||||
chooseTargetNamespace: "Scegli un altro namespace",
|
chooseTargetNamespace: "Scegli un altro namespace",
|
||||||
targetGroup: "Group di destinazione (facoltativo)",
|
targetGroup: "Group di destinazione (facoltativo)",
|
||||||
targetGroupPlaceholder: "Uguale al group di origine",
|
targetGroupPlaceholder: "Uguale al group di origine",
|
||||||
|
targetDataIds: "Data ID di destinazione (facoltativi)",
|
||||||
|
targetDataIdsHint: "Le configurazioni selezionate possono essere rinominate singolarmente. Lascia un campo vuoto per mantenere il Data ID di origine.",
|
||||||
copyKeepsSource: "La sincronizzazione usa una copia unidirezionale. Le configurazioni del namespace di origine restano invariate.",
|
copyKeepsSource: "La sincronizzazione usa una copia unidirezionale. Le configurazioni del namespace di origine restano invariate.",
|
||||||
conflictPolicy: "Strategia conflitti",
|
conflictPolicy: "Strategia conflitti",
|
||||||
policyABORT: "Interrompi in caso di conflitto",
|
policyABORT: "Interrompi in caso di conflitto",
|
||||||
|
|||||||
@@ -6849,6 +6849,8 @@ export default withEnglishFallback({
|
|||||||
chooseTargetNamespace: "別の名前空間を選択",
|
chooseTargetNamespace: "別の名前空間を選択",
|
||||||
targetGroup: "宛先グループ(任意)",
|
targetGroup: "宛先グループ(任意)",
|
||||||
targetGroupPlaceholder: "元のグループと同じ",
|
targetGroupPlaceholder: "元のグループと同じ",
|
||||||
|
targetDataIds: "宛先 Data ID(任意)",
|
||||||
|
targetDataIdsHint: "選択した設定ごとに Data ID を変更できます。空欄の場合は元の Data ID を保持します。",
|
||||||
copyKeepsSource: "同期は一方向コピーです。元の名前空間の設定は変更されません。",
|
copyKeepsSource: "同期は一方向コピーです。元の名前空間の設定は変更されません。",
|
||||||
conflictPolicy: "競合ポリシー",
|
conflictPolicy: "競合ポリシー",
|
||||||
policyABORT: "競合時に中止",
|
policyABORT: "競合時に中止",
|
||||||
|
|||||||
@@ -7549,6 +7549,8 @@ export default withEnglishFallback({
|
|||||||
chooseTargetNamespace: "다른 네임스페이스 선택",
|
chooseTargetNamespace: "다른 네임스페이스 선택",
|
||||||
targetGroup: "대상 그룹(선택 사항)",
|
targetGroup: "대상 그룹(선택 사항)",
|
||||||
targetGroupPlaceholder: "원본 그룹과 동일",
|
targetGroupPlaceholder: "원본 그룹과 동일",
|
||||||
|
targetDataIds: "대상 Data ID(선택 사항)",
|
||||||
|
targetDataIdsHint: "선택한 구성을 개별적으로 이름 변경할 수 있습니다. 비워 두면 원본 Data ID를 유지합니다.",
|
||||||
copyKeepsSource: "동기화는 단방향 복사 의미를 사용합니다. 소스 네임스페이스 구성은 변경되지 않습니다.",
|
copyKeepsSource: "동기화는 단방향 복사 의미를 사용합니다. 소스 네임스페이스 구성은 변경되지 않습니다.",
|
||||||
conflictPolicy: "충돌 정책",
|
conflictPolicy: "충돌 정책",
|
||||||
policyABORT: "충돌 시 중단",
|
policyABORT: "충돌 시 중단",
|
||||||
|
|||||||
@@ -6811,6 +6811,8 @@ export default withEnglishFallback({
|
|||||||
chooseTargetNamespace: "Escolha outro namespace",
|
chooseTargetNamespace: "Escolha outro namespace",
|
||||||
targetGroup: "Group de destino (opcional)",
|
targetGroup: "Group de destino (opcional)",
|
||||||
targetGroupPlaceholder: "Igual ao group de origem",
|
targetGroupPlaceholder: "Igual ao group de origem",
|
||||||
|
targetDataIds: "Data IDs de destino (opcional)",
|
||||||
|
targetDataIdsHint: "As configurações selecionadas podem ser renomeadas individualmente. Deixe um campo vazio para manter o Data ID de origem.",
|
||||||
copyKeepsSource: "A sincronização usa cópia unidirecional. As configurações do namespace de origem permanecem inalteradas.",
|
copyKeepsSource: "A sincronização usa cópia unidirecional. As configurações do namespace de origem permanecem inalteradas.",
|
||||||
conflictPolicy: "Política de conflitos",
|
conflictPolicy: "Política de conflitos",
|
||||||
policyABORT: "Abortar ao encontrar conflito",
|
policyABORT: "Abortar ao encontrar conflito",
|
||||||
|
|||||||
@@ -8334,6 +8334,8 @@ export default withEnglishFallback({
|
|||||||
chooseTargetNamespace: "请选择其他命名空间",
|
chooseTargetNamespace: "请选择其他命名空间",
|
||||||
targetGroup: "目标 Group(可选)",
|
targetGroup: "目标 Group(可选)",
|
||||||
targetGroupPlaceholder: "与源 Group 相同",
|
targetGroupPlaceholder: "与源 Group 相同",
|
||||||
|
targetDataIds: "目标 Data ID(可选)",
|
||||||
|
targetDataIdsHint: "可逐项修改已选配置的 Data ID;留空则保留源 Data ID。",
|
||||||
copyKeepsSource: "同步采用单向复制语义,源命名空间中的配置保持不变。",
|
copyKeepsSource: "同步采用单向复制语义,源命名空间中的配置保持不变。",
|
||||||
conflictPolicy: "冲突策略",
|
conflictPolicy: "冲突策略",
|
||||||
policyABORT: "遇冲突终止",
|
policyABORT: "遇冲突终止",
|
||||||
|
|||||||
@@ -6119,6 +6119,8 @@ export default withEnglishFallback({
|
|||||||
chooseTargetNamespace: "請選擇其他命名空間",
|
chooseTargetNamespace: "請選擇其他命名空間",
|
||||||
targetGroup: "目標 Group(選填)",
|
targetGroup: "目標 Group(選填)",
|
||||||
targetGroupPlaceholder: "與來源 Group 相同",
|
targetGroupPlaceholder: "與來源 Group 相同",
|
||||||
|
targetDataIds: "目標 Data ID(選填)",
|
||||||
|
targetDataIdsHint: "可逐項修改已選設定的 Data ID;留空則保留來源 Data ID。",
|
||||||
copyKeepsSource: "同步採用單向複製,來源命名空間中的設定保持不變。",
|
copyKeepsSource: "同步採用單向複製,來源命名空間中的設定保持不變。",
|
||||||
conflictPolicy: "衝突策略",
|
conflictPolicy: "衝突策略",
|
||||||
policyABORT: "遇到衝突時終止",
|
policyABORT: "遇到衝突時終止",
|
||||||
|
|||||||
@@ -397,6 +397,12 @@ export interface NacosBatchReport {
|
|||||||
items: NacosBatchItemResult[];
|
items: NacosBatchItemResult[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface NacosConfigDataIdMapping {
|
||||||
|
sourceGroup: string;
|
||||||
|
sourceDataId: string;
|
||||||
|
targetDataId: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface NacosConfigTransferRequest {
|
export interface NacosConfigTransferRequest {
|
||||||
operationId: string;
|
operationId: string;
|
||||||
sourceConnectionId: string;
|
sourceConnectionId: string;
|
||||||
@@ -404,6 +410,7 @@ export interface NacosConfigTransferRequest {
|
|||||||
source: NacosConfigSelector;
|
source: NacosConfigSelector;
|
||||||
targetNamespace: string;
|
targetNamespace: string;
|
||||||
targetGroup?: string;
|
targetGroup?: string;
|
||||||
|
dataIdMappings?: NacosConfigDataIdMapping[];
|
||||||
conflictPolicy: NacosConflictPolicy;
|
conflictPolicy: NacosConflictPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -158,17 +159,20 @@ async fn transfer_configs(
|
|||||||
request: &NacosConfigTransferRequest,
|
request: &NacosConfigTransferRequest,
|
||||||
) -> Result<Vec<NacosConfigUpsert>, String> {
|
) -> Result<Vec<NacosConfigUpsert>, String> {
|
||||||
let target_group = request.target_group.as_deref().map(str::trim).filter(|group| !group.is_empty());
|
let target_group = request.target_group.as_deref().map(str::trim).filter(|group| !group.is_empty());
|
||||||
|
let mut data_id_mappings = validated_data_id_mappings(request)?;
|
||||||
let source = resolve_selector(source_admin, &request.source).await?;
|
let source = resolve_selector(source_admin, &request.source).await?;
|
||||||
let configs = source
|
let configs = source
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|config| {
|
.map(|config| {
|
||||||
|
let source_key = (config.group.clone(), config.data_id.clone());
|
||||||
let content = config
|
let content = config
|
||||||
.content
|
.content
|
||||||
.ok_or_else(|| format!("Nacos configuration {}/{} has no content", config.group, config.data_id))?;
|
.ok_or_else(|| format!("Nacos configuration {}/{} has no content", config.group, config.data_id))?;
|
||||||
let group = target_group.map(str::to_string).unwrap_or(config.group);
|
let group = target_group.map(str::to_string).unwrap_or(config.group);
|
||||||
|
let data_id = data_id_mappings.remove(&source_key).unwrap_or(config.data_id);
|
||||||
Ok(NacosConfigUpsert {
|
Ok(NacosConfigUpsert {
|
||||||
namespace: Some(request.target_namespace.clone()),
|
namespace: Some(request.target_namespace.clone()),
|
||||||
data_id: config.data_id,
|
data_id,
|
||||||
group,
|
group,
|
||||||
content,
|
content,
|
||||||
config_type: config.config_type,
|
config_type: config.config_type,
|
||||||
@@ -178,7 +182,12 @@ async fn transfer_configs(
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, String>>()?;
|
.collect::<Result<Vec<_>, String>>()?;
|
||||||
let mut target_keys = std::collections::HashSet::new();
|
if let Some(((group, data_id), _)) = data_id_mappings.into_iter().next() {
|
||||||
|
return Err(format!(
|
||||||
|
"Nacos configuration {group}/{data_id} no longer exists in the selected source configurations"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let mut target_keys = HashSet::new();
|
||||||
for config in &configs {
|
for config in &configs {
|
||||||
let namespace = config.namespace.as_deref().unwrap_or_default();
|
let namespace = config.namespace.as_deref().unwrap_or_default();
|
||||||
let key = (namespace, config.group.as_str(), config.data_id.as_str());
|
let key = (namespace, config.group.as_str(), config.data_id.as_str());
|
||||||
@@ -192,6 +201,47 @@ async fn transfer_configs(
|
|||||||
Ok(configs)
|
Ok(configs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn validated_data_id_mappings(
|
||||||
|
request: &NacosConfigTransferRequest,
|
||||||
|
) -> Result<HashMap<(String, String), String>, String> {
|
||||||
|
if request.data_id_mappings.is_empty() {
|
||||||
|
return Ok(HashMap::new());
|
||||||
|
}
|
||||||
|
if !matches!(request.source.scope, NacosConfigSelectionScope::Selected) {
|
||||||
|
return Err("Nacos Data ID mappings are only supported for selected configurations".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
let selected_keys: HashSet<_> =
|
||||||
|
request.source.keys.iter().map(|key| (key.group.as_str(), key.data_id.as_str())).collect();
|
||||||
|
let mut mappings = HashMap::with_capacity(request.data_id_mappings.len());
|
||||||
|
for mapping in &request.data_id_mappings {
|
||||||
|
let source_key = (mapping.source_group.as_str(), mapping.source_data_id.as_str());
|
||||||
|
if !selected_keys.contains(&source_key) {
|
||||||
|
return Err(format!(
|
||||||
|
"Nacos configuration {}/{} is not selected for Data ID mapping",
|
||||||
|
mapping.source_group, mapping.source_data_id
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let target_data_id = mapping.target_data_id.trim();
|
||||||
|
if target_data_id.is_empty() {
|
||||||
|
return Err(format!(
|
||||||
|
"Nacos configuration {}/{} target Data ID cannot be blank",
|
||||||
|
mapping.source_group, mapping.source_data_id
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if mappings
|
||||||
|
.insert((mapping.source_group.clone(), mapping.source_data_id.clone()), target_data_id.to_string())
|
||||||
|
.is_some()
|
||||||
|
{
|
||||||
|
return Err(format!(
|
||||||
|
"Nacos configuration {}/{} has multiple target Data ID mappings",
|
||||||
|
mapping.source_group, mapping.source_data_id
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(mappings)
|
||||||
|
}
|
||||||
|
|
||||||
async fn resolve_selector(
|
async fn resolve_selector(
|
||||||
admin: Arc<dyn NacosAdmin>,
|
admin: Arc<dyn NacosAdmin>,
|
||||||
selector: &NacosConfigSelector,
|
selector: &NacosConfigSelector,
|
||||||
@@ -842,15 +892,23 @@ mod tests {
|
|||||||
},
|
},
|
||||||
target_namespace: "target-ns".to_string(),
|
target_namespace: "target-ns".to_string(),
|
||||||
target_group: target_group.map(str::to_string),
|
target_group: target_group.map(str::to_string),
|
||||||
|
data_id_mappings: Vec::new(),
|
||||||
conflict_policy: NacosConflictPolicy::default(),
|
conflict_policy: NacosConflictPolicy::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn source_admin_with_config() -> Arc<MockAdmin> {
|
fn data_id_mapping(source_group: &str, source_data_id: &str, target_data_id: &str) -> NacosConfigDataIdMapping {
|
||||||
let admin = Arc::new(MockAdmin::default());
|
NacosConfigDataIdMapping {
|
||||||
|
source_group: source_group.to_string(),
|
||||||
|
source_data_id: source_data_id.to_string(),
|
||||||
|
target_data_id: target_data_id.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert_source_config(admin: &MockAdmin, data_id: &str, group: &str, content: &str) {
|
||||||
admin.insert(NacosConfigItem {
|
admin.insert(NacosConfigItem {
|
||||||
data_id: "app".to_string(),
|
data_id: data_id.to_string(),
|
||||||
group: "SOURCE_GROUP".to_string(),
|
group: group.to_string(),
|
||||||
namespace: "source-ns".to_string(),
|
namespace: "source-ns".to_string(),
|
||||||
app_name: None,
|
app_name: None,
|
||||||
desc: None,
|
desc: None,
|
||||||
@@ -858,8 +916,13 @@ mod tests {
|
|||||||
config_type: Some("text".to_string()),
|
config_type: Some("text".to_string()),
|
||||||
md5: None,
|
md5: None,
|
||||||
encrypted_data_key: None,
|
encrypted_data_key: None,
|
||||||
content: Some("value".to_string()),
|
content: Some(content.to_string()),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn source_admin_with_config() -> Arc<MockAdmin> {
|
||||||
|
let admin = Arc::new(MockAdmin::default());
|
||||||
|
insert_source_config(&admin, "app", "SOURCE_GROUP", "value");
|
||||||
admin
|
admin
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -916,4 +979,132 @@ mod tests {
|
|||||||
assert_eq!(configs.len(), 1);
|
assert_eq!(configs.len(), 1);
|
||||||
assert_eq!(configs[0].group, "SOURCE_GROUP");
|
assert_eq!(configs[0].group, "SOURCE_GROUP");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn transfer_with_data_id_mapping_uses_the_trimmed_target_data_id() {
|
||||||
|
let source_admin = source_admin_with_config();
|
||||||
|
let mut request = transfer_request(None);
|
||||||
|
request.data_id_mappings = vec![data_id_mapping("SOURCE_GROUP", "app", " renamed.yaml ")];
|
||||||
|
|
||||||
|
let configs = transfer_configs(source_admin, &request).await.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(configs.len(), 1);
|
||||||
|
assert_eq!(configs[0].data_id, "renamed.yaml");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn transfer_with_multiple_selected_configs_maps_only_the_edited_data_id() {
|
||||||
|
let source_admin = source_admin_with_config();
|
||||||
|
insert_source_config(&source_admin, "worker", "OTHER_GROUP", "worker value");
|
||||||
|
let mut request = transfer_request(None);
|
||||||
|
request.source.keys.push(NacosConfigKey {
|
||||||
|
namespace: Some("source-ns".to_string()),
|
||||||
|
data_id: "worker".to_string(),
|
||||||
|
group: "OTHER_GROUP".to_string(),
|
||||||
|
});
|
||||||
|
request.data_id_mappings = vec![data_id_mapping("OTHER_GROUP", "worker", "worker-prod")];
|
||||||
|
|
||||||
|
let configs = transfer_configs(source_admin, &request).await.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(configs.len(), 2);
|
||||||
|
assert!(configs.iter().any(|config| config.group == "SOURCE_GROUP" && config.data_id == "app"));
|
||||||
|
assert!(configs.iter().any(|config| config.group == "OTHER_GROUP" && config.data_id == "worker-prod"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn transfer_rejects_blank_data_id_mapping() {
|
||||||
|
let source_admin = source_admin_with_config();
|
||||||
|
let mut request = transfer_request(None);
|
||||||
|
request.data_id_mappings = vec![data_id_mapping("SOURCE_GROUP", "app", " ")];
|
||||||
|
|
||||||
|
let error = transfer_configs(source_admin, &request).await.unwrap_err();
|
||||||
|
|
||||||
|
assert!(error.contains("target Data ID cannot be blank"), "unexpected error: {error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn transfer_rejects_duplicate_mappings_for_the_same_source_key() {
|
||||||
|
let source_admin = source_admin_with_config();
|
||||||
|
let mut request = transfer_request(None);
|
||||||
|
request.data_id_mappings =
|
||||||
|
vec![data_id_mapping("SOURCE_GROUP", "app", "first"), data_id_mapping("SOURCE_GROUP", "app", "second")];
|
||||||
|
|
||||||
|
let error = transfer_configs(source_admin, &request).await.unwrap_err();
|
||||||
|
|
||||||
|
assert!(error.contains("multiple target Data ID mappings"), "unexpected error: {error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn transfer_rejects_data_id_mapping_outside_selected_scope() {
|
||||||
|
let source_admin = source_admin_with_config();
|
||||||
|
let mut request = transfer_request(None);
|
||||||
|
request.source.scope = NacosConfigSelectionScope::Filtered;
|
||||||
|
request.data_id_mappings = vec![data_id_mapping("SOURCE_GROUP", "app", "renamed")];
|
||||||
|
|
||||||
|
let error = transfer_configs(source_admin, &request).await.unwrap_err();
|
||||||
|
|
||||||
|
assert!(error.contains("only supported for selected"), "unexpected error: {error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn transfer_rejects_data_id_mapping_for_an_unselected_source_key() {
|
||||||
|
let source_admin = source_admin_with_config();
|
||||||
|
let mut request = transfer_request(None);
|
||||||
|
request.data_id_mappings = vec![data_id_mapping("SOURCE_GROUP", "not-selected", "renamed")];
|
||||||
|
|
||||||
|
let error = transfer_configs(source_admin, &request).await.unwrap_err();
|
||||||
|
|
||||||
|
assert!(error.contains("SOURCE_GROUP/not-selected is not selected"), "unexpected error: {error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn transfer_rejects_a_stale_selected_source_mapping() {
|
||||||
|
let source_admin = source_admin_with_config();
|
||||||
|
let mut request = transfer_request(None);
|
||||||
|
request.source.keys[0].data_id = "deleted".to_string();
|
||||||
|
request.data_id_mappings = vec![data_id_mapping("SOURCE_GROUP", "deleted", "renamed")];
|
||||||
|
|
||||||
|
let error = transfer_configs(source_admin, &request).await.unwrap_err();
|
||||||
|
|
||||||
|
assert_eq!(error, "not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn transfer_rejects_target_key_collisions_after_data_id_mapping() {
|
||||||
|
let source_admin = source_admin_with_config();
|
||||||
|
insert_source_config(&source_admin, "worker", "SOURCE_GROUP", "worker value");
|
||||||
|
let mut request = transfer_request(Some("TARGET_GROUP"));
|
||||||
|
request.source.keys.push(NacosConfigKey {
|
||||||
|
namespace: Some("source-ns".to_string()),
|
||||||
|
data_id: "worker".to_string(),
|
||||||
|
group: "SOURCE_GROUP".to_string(),
|
||||||
|
});
|
||||||
|
request.data_id_mappings = vec![data_id_mapping("SOURCE_GROUP", "worker", "app")];
|
||||||
|
|
||||||
|
let error = transfer_configs(source_admin, &request).await.unwrap_err();
|
||||||
|
|
||||||
|
assert!(error.contains("target-ns/TARGET_GROUP/app"), "unexpected error: {error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn preview_and_apply_share_the_same_mapped_data_id_plan() {
|
||||||
|
let source_admin = source_admin_with_config();
|
||||||
|
let target_admin = Arc::new(MockAdmin::default());
|
||||||
|
let mut request = transfer_request(None);
|
||||||
|
request.data_id_mappings = vec![data_id_mapping("SOURCE_GROUP", "app", "app-prod")];
|
||||||
|
|
||||||
|
let preview = preview_transfer(source_admin.clone(), target_admin.clone(), &request).await.unwrap();
|
||||||
|
let report = apply_transfer(source_admin, target_admin.clone(), &request, &preview.plan_hash).await.unwrap();
|
||||||
|
|
||||||
|
assert_eq!((preview.created, report.created), (1, 1));
|
||||||
|
let published = target_admin
|
||||||
|
.get_config(NacosConfigKey {
|
||||||
|
namespace: Some("target-ns".to_string()),
|
||||||
|
data_id: "app-prod".to_string(),
|
||||||
|
group: "SOURCE_GROUP".to_string(),
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(published.content.as_deref(), Some("value"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -816,6 +816,14 @@ pub struct NacosBatchReport {
|
|||||||
pub items: Vec<NacosBatchItemResult>,
|
pub items: Vec<NacosBatchItemResult>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct NacosConfigDataIdMapping {
|
||||||
|
pub source_group: String,
|
||||||
|
pub source_data_id: String,
|
||||||
|
pub target_data_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct NacosConfigTransferRequest {
|
pub struct NacosConfigTransferRequest {
|
||||||
@@ -827,6 +835,8 @@ pub struct NacosConfigTransferRequest {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub target_group: Option<String>,
|
pub target_group: Option<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
pub data_id_mappings: Vec<NacosConfigDataIdMapping>,
|
||||||
|
#[serde(default)]
|
||||||
pub conflict_policy: NacosConflictPolicy,
|
pub conflict_policy: NacosConflictPolicy,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user