@camunda/ccma-saas-frontend 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. Licensed under a commercial license.
4
+ * You may not use this file except in compliance with the commercial license.
5
+ */
6
+ // The Console view of the operator's `Migration` CR (camunda-operator,
7
+ // `docs/migration-api-contract.md`, ADR 0008). The UI reads only these types.
8
+ // Today `migration-workaround.ts` builds the view. The operator integration
9
+ // replaces only that adapter.
10
+ export const MIGRATION_PHASES = [
11
+ 'AwaitingPrincipal',
12
+ 'Transferring',
13
+ 'AwaitingBackup',
14
+ 'Verifying',
15
+ 'Restoring',
16
+ 'Completed',
17
+ 'VerificationFailed',
18
+ 'RestoreFailed',
19
+ ];
20
+ /** The reasons of the contract's reason catalogue, per phase. */
21
+ export const MIGRATION_REASONS_BY_PHASE = {
22
+ AwaitingPrincipal: ['WaitingForPrincipal', 'GrantingAccess'],
23
+ Transferring: ['TransferOpen', 'RemovingAccess'],
24
+ AwaitingBackup: [
25
+ 'WaitingForBackupChoice',
26
+ 'BackupNotFound',
27
+ 'PartitionCountMismatch',
28
+ ],
29
+ Verifying: ['VerifyingBackup'],
30
+ Restoring: ['RestoringBackup'],
31
+ Completed: ['MigrationCompleted'],
32
+ VerificationFailed: [
33
+ 'BackupIncomplete',
34
+ 'SnapshotsMissing',
35
+ 'BackupUnreadable',
36
+ 'ElasticsearchVersionIncompatible',
37
+ 'CamundaVersionIncompatible',
38
+ 'PartitionCountIncompatible',
39
+ 'InsufficientDiskSize',
40
+ ],
41
+ RestoreFailed: [
42
+ 'RestoreFailedBeforeDataDeletion',
43
+ 'RestoreFailedAfterDataDeletion',
44
+ ],
45
+ };
46
+ /** The ADR lock rule: a migration cluster is hidden and locked until Completed. */
47
+ export const isMigrationLocked = (view) => view !== undefined && view.phase !== 'Completed';
48
+ const MAX_BACKUP_ID = BigInt('9223372036854775807');
49
+ /** A backup ID is an integer from 1 to 2^63-1. A string keeps every digit. */
50
+ export const isValidBackupId = (value) => /^[1-9]\d{0,18}$/.test(value) && BigInt(value) <= MAX_BACKUP_ID;
51
+ /** A partition count is a whole number from 0 to 2147483647. `0`: Elasticsearch data only. */
52
+ export const isValidPartitionsCount = (value) => /^(0|[1-9]\d{0,9})$/.test(value) && Number(value) <= 2147483647;
@@ -1,43 +1,57 @@
1
1
  import { type ClusterLabels } from '@camunda/ccma-shared-types';
2
- /** The cloud identity that the customer lets Camunda use for the transfer. */
3
- export type MigrationIdentity = {
4
- provider: 'aws';
5
- roleArn: string;
6
- };
7
- export type MigrationState = 'awaitingTransfer' | 'migrating' | 'none';
8
- export interface MigrationInfo {
9
- state: MigrationState;
10
- /** AWS only for now. Set when the state is not `none`. */
11
- roleArn?: string;
12
- /** The name without the prefix. */
13
- displayName: string;
14
- }
2
+ import { type MigrationAccess, type MigrationSourceInput, type MigrationView } from './migration-view.js';
3
+ /** The prefix takes some of the characters of the cluster name. */
4
+ export declare const MIGRATION_NAME_MAX_LENGTH: number;
5
+ /** The description holds the principal, and it allows 150 characters. */
6
+ export declare const MIGRATION_ROLE_ARN_MAX_LENGTH = 150;
15
7
  /**
16
- * A cluster is in a state only if the name has the prefix AND the description
17
- * is a valid role ARN. A user who renames a cluster to "[3844 start] X" has
18
- * no ARN, so the rename does not lock the cluster.
8
+ * The access of the AWS template. The target statements need the bucket ARN
9
+ * of the cluster. The workaround knows no bucket, thus it has no statements.
19
10
  */
20
- export declare const getMigrationInfo: (cluster: {
11
+ export declare const buildAwsAccess: (bucketArn?: string) => MigrationAccess;
12
+ export interface MigrationWorkaroundCluster {
21
13
  name: string;
22
14
  description?: string;
23
- }) => MigrationInfo;
15
+ labels?: ClusterLabels;
16
+ }
17
+ /**
18
+ * The migration of a cluster, or `undefined` for a cluster with no migration
19
+ * or a completed one. A cluster has a migration only if the name has a prefix
20
+ * AND the description is a role ARN (the contract pattern, or the older pattern
21
+ * that Create accepted first). A user who renames a cluster to
22
+ * "[3844 transfer] X" has no ARN, so the rename does not lock the cluster.
23
+ */
24
+ export declare const getMigrationView: (cluster: MigrationWorkaroundCluster) => MigrationView | undefined;
24
25
  /**
25
- * The one plan check of the details page and the list. An
26
- * unknown plan (slow or failed org request) keeps a prefixed cluster locked.
27
- * Only a known other plan unlocks it.
26
+ * The one plan check of the details page and the list. An unknown plan (slow
27
+ * or failed org request) keeps a prefixed cluster locked. Only a known other
28
+ * plan unlocks it.
28
29
  */
29
30
  export declare const isMigrationPlan: (planType: string | undefined) => boolean;
31
+ /** True for a label of the workaround. The UI shows no such label. */
32
+ export declare const isMigrationLabel: (label: string) => boolean;
33
+ /** The input of Create for a migration. A GCP service account joins later. */
34
+ export type MigrationIdentity = {
35
+ provider: 'aws';
36
+ roleArn: string;
37
+ };
38
+ /** The name of a new migration cluster. Create needs a valid principal. */
39
+ export declare const buildMigrationCreateName: (name: string) => string;
40
+ /** The body of the cluster update that writes a step of the customer. */
41
+ export interface MigrationUpdate {
42
+ name: string;
43
+ labels: Required<ClusterLabels>;
44
+ }
45
+ /** Transferring → AwaitingBackup. Keeps the source that the policy used. */
46
+ export declare const buildTransferFinishedUpdate: (view: MigrationView, labels: ClusterLabels | undefined, source: MigrationSourceInput) => MigrationUpdate;
47
+ /** AwaitingBackup → Transferring. */
48
+ export declare const buildReopenTransferUpdate: (view: MigrationView, labels: ClusterLabels | undefined) => MigrationUpdate;
30
49
  /**
31
- * The backup ID has no field in the operator yet. Ops read it from the custom
32
- * labels of the cluster. The new label replaces an older one.
50
+ * AwaitingBackup or RestoreFailed → Verifying. Each choice is a new attempt,
51
+ * also the same backup again.
33
52
  */
34
- export declare const withBackupIdLabel: (labels: ClusterLabels | undefined, backupId: string) => Required<ClusterLabels>;
35
- /** True for the label that holds the backup ID. The UI shows no such label. */
36
- export declare const isBackupIdLabel: (label: string) => boolean;
37
- export declare const buildStartName: (name: string) => string;
38
- export declare const buildMigrateName: (name: string) => string;
39
- /** The name limit while the prefix takes room in the 50 character name. */
40
- export declare const MIGRATION_NAME_MAX_LENGTH = 35;
41
- /** The description holds the role, and the description allows 150 characters. */
42
- export declare const MIGRATION_ROLE_ARN_MAX_LENGTH = 150;
53
+ export declare const buildBackupChoiceUpdate: (view: MigrationView, labels: ClusterLabels | undefined, choice: {
54
+ backupId: string;
55
+ partitionsCount: number;
56
+ }) => MigrationUpdate;
43
57
  export declare const isValidAwsRoleArn: (value: string) => boolean;
@@ -3,64 +3,228 @@
3
3
  * under one or more contributor license agreements. Licensed under a commercial license.
4
4
  * You may not use this file except in compliance with the commercial license.
5
5
  */
6
- import { MIGRATION_BACKUP_ID_LABEL_PREFIX, SalesPlanType, } from '@camunda/ccma-shared-types';
7
- // TODO(3844-workaround): The operator has no migration fields yet. The name
8
- // prefix holds the state and the description holds the role. Delete this file
9
- // when the operator spec is ready. Only this file knows the prefixes.
10
- const START_PREFIX = '[3844 start] ';
11
- const MIGRATE_PREFIX = '[3844 migrate] ';
6
+ import { isMigrationLabel as isSharedMigrationLabel, MAX_LENGTH_CLUSTER_NAME, migrationLabelPrefix, SalesPlanType, } from '@camunda/ccma-shared-types';
7
+ import { isValidBackupId, MIGRATION_REASONS_BY_PHASE, } from './migration-view.js';
8
+ // TODO(3844-workaround): The operator has no `Migration` CR yet. The name
9
+ // prefix holds the phase, the description holds the principal, and custom
10
+ // labels hold the rest. Only this file knows that encoding. The operator
11
+ // integration replaces this file and keeps `migration-view.ts`.
12
+ const PHASE_PREFIXES = [
13
+ ['[3844 principal] ', 'AwaitingPrincipal'],
14
+ ['[3844 transfer] ', 'Transferring'],
15
+ ['[3844 backup] ', 'AwaitingBackup'],
16
+ ['[3844 verify] ', 'Verifying'],
17
+ ['[3844 restore] ', 'Restoring'],
18
+ ['[3844 vfail] ', 'VerificationFailed'],
19
+ ['[3844 rfail] ', 'RestoreFailed'],
20
+ // The prefixes of the first workaround. Clusters with them still exist.
21
+ ['[3844 start] ', 'Transferring'],
22
+ ['[3844 migrate] ', 'Restoring'],
23
+ ];
24
+ const prefixOf = (phase) => PHASE_PREFIXES.find(([, p]) => p === phase)?.[0] ?? '';
25
+ const LONGEST_PREFIX = Math.max(...PHASE_PREFIXES.map(([prefix]) => prefix.length));
26
+ /** The prefix takes some of the characters of the cluster name. */
27
+ export const MIGRATION_NAME_MAX_LENGTH = MAX_LENGTH_CLUSTER_NAME - LONGEST_PREFIX;
28
+ /** The description holds the principal, and it allows 150 characters. */
29
+ export const MIGRATION_ROLE_ARN_MAX_LENGTH = 150;
30
+ const LABEL = {
31
+ backupId: migrationLabelPrefix('backup-id'),
32
+ partitions: migrationLabelPrefix('partitions'),
33
+ attempt: migrationLabelPrefix('attempt'),
34
+ sourceBucket: migrationLabelPrefix('source-bucket'),
35
+ sourceKmsKey: migrationLabelPrefix('source-kms-key'),
36
+ // Testers set these two to show a reason other than the default of the
37
+ // phase. A param label is `migration-reason-param:<field>=<value>`.
38
+ reason: migrationLabelPrefix('reason'),
39
+ reasonParam: migrationLabelPrefix('reason-param'),
40
+ };
41
+ const DEFAULT_REASON = {
42
+ AwaitingPrincipal: 'GrantingAccess',
43
+ Transferring: 'TransferOpen',
44
+ AwaitingBackup: 'WaitingForBackupChoice',
45
+ Verifying: 'VerifyingBackup',
46
+ Restoring: 'RestoringBackup',
47
+ Completed: 'MigrationCompleted',
48
+ // No default: a guess would tell the customer the wrong thing to fix.
49
+ VerificationFailed: undefined,
50
+ // The safe default: it tells that the next restore replaces the data.
51
+ RestoreFailed: 'RestoreFailedAfterDataDeletion',
52
+ };
53
+ const NUMBER_PARAMS = new Set([
54
+ 'backupPartitions',
55
+ 'chosenPartitions',
56
+ 'clusterPartitions',
57
+ ]);
58
+ const STRING_PARAMS = new Set([
59
+ 'backupId',
60
+ 'backupVersion',
61
+ 'clusterVersion',
62
+ ]);
63
+ // The AWS template of the operator's provider seam (contract, "Access").
64
+ const TARGET_BUCKET_ACTIONS = ['s3:ListBucket', 's3:GetBucketLocation'];
65
+ const TARGET_OBJECT_ACTIONS = [
66
+ 's3:PutObject',
67
+ 's3:PutObjectTagging',
68
+ 's3:ListMultipartUploadParts',
69
+ 's3:AbortMultipartUpload',
70
+ ];
12
71
  /**
13
- * A cluster is in a state only if the name has the prefix AND the description
14
- * is a valid role ARN. A user who renames a cluster to "[3844 start] X" has
15
- * no ARN, so the rename does not lock the cluster.
72
+ * The access of the AWS template. The target statements need the bucket ARN
73
+ * of the cluster. The workaround knows no bucket, thus it has no statements.
16
74
  */
17
- export const getMigrationInfo = (cluster) => {
18
- const prefixes = [
19
- [START_PREFIX, 'awaitingTransfer'],
20
- [MIGRATE_PREFIX, 'migrating'],
21
- ];
22
- const roleArn = cluster.description ?? '';
23
- if (isValidAwsRoleArn(roleArn)) {
24
- for (const [prefix, state] of prefixes) {
25
- if (cluster.name.startsWith(prefix)) {
26
- return {
27
- state,
28
- roleArn,
29
- displayName: cluster.name.slice(prefix.length),
30
- };
31
- }
75
+ export const buildAwsAccess = (bucketArn) => {
76
+ const statements = bucketArn
77
+ ? [
78
+ { resource: bucketArn, actions: TARGET_BUCKET_ACTIONS },
79
+ { resource: `${bucketArn}/*`, actions: TARGET_OBJECT_ACTIONS },
80
+ ]
81
+ : [];
82
+ return {
83
+ bucket: bucketArn,
84
+ statements,
85
+ source: [
86
+ { kind: 'Bucket', actions: ['s3:ListBucket', 's3:GetBucketLocation'] },
87
+ { kind: 'Objects', actions: ['s3:GetObject', 's3:GetObjectTagging'] },
88
+ { kind: 'Key', actions: ['kms:Decrypt'] },
89
+ ],
90
+ };
91
+ };
92
+ const labelValue = (custom, prefix) => custom.find((label) => label.startsWith(prefix))?.slice(prefix.length);
93
+ const toCount = (value) => value !== undefined && /^\d{1,10}$/.test(value) ? Number(value) : undefined;
94
+ const readReasonParams = (custom) => {
95
+ const params = {};
96
+ for (const label of custom) {
97
+ if (!label.startsWith(LABEL.reasonParam))
98
+ continue;
99
+ const [key, ...rest] = label.slice(LABEL.reasonParam.length).split('=');
100
+ const value = rest.join('=');
101
+ const field = key;
102
+ if (NUMBER_PARAMS.has(field)) {
103
+ const count = toCount(value);
104
+ if (count !== undefined)
105
+ params[field] = count;
106
+ }
107
+ else if (STRING_PARAMS.has(field) && value) {
108
+ params[field] = value;
32
109
  }
33
110
  }
34
- return { state: 'none', displayName: cluster.name };
111
+ return params;
112
+ };
113
+ const readReason = (phase, custom) => {
114
+ const value = labelValue(custom, LABEL.reason);
115
+ const allowed = MIGRATION_REASONS_BY_PHASE[phase];
116
+ return value && allowed.includes(value)
117
+ ? value
118
+ : DEFAULT_REASON[phase];
35
119
  };
36
120
  /**
37
- * The one plan check of the details page and the list. An
38
- * unknown plan (slow or failed org request) keeps a prefixed cluster locked.
39
- * Only a known other plan unlocks it.
121
+ * The migration of a cluster, or `undefined` for a cluster with no migration
122
+ * or a completed one. A cluster has a migration only if the name has a prefix
123
+ * AND the description is a role ARN (the contract pattern, or the older pattern
124
+ * that Create accepted first). A user who renames a cluster to
125
+ * "[3844 transfer] X" has no ARN, so the rename does not lock the cluster.
126
+ */
127
+ export const getMigrationView = (cluster) => {
128
+ const principal = cluster.description ?? '';
129
+ if (!isKnownMigrationPrincipal(principal))
130
+ return undefined;
131
+ const match = PHASE_PREFIXES.find(([prefix]) => cluster.name.startsWith(prefix));
132
+ if (!match)
133
+ return undefined;
134
+ const [prefix, phase] = match;
135
+ const custom = cluster.labels?.custom ?? [];
136
+ const backupId = labelValue(custom, LABEL.backupId);
137
+ const partitionsCount = toCount(labelValue(custom, LABEL.partitions));
138
+ const attempt = toCount(labelValue(custom, LABEL.attempt));
139
+ const validBackupId = backupId !== undefined && isValidBackupId(backupId) ? backupId : undefined;
140
+ // A cluster of the first workaround has no partitions label. Its choice has
141
+ // no partition count, thus it is not a backup choice of the contract.
142
+ const backup = validBackupId !== undefined && partitionsCount !== undefined
143
+ ? {
144
+ backupId: validBackupId,
145
+ partitionsCount,
146
+ attempt: attempt && attempt > 0 ? attempt : 1,
147
+ }
148
+ : undefined;
149
+ return {
150
+ phase,
151
+ reason: readReason(phase, custom),
152
+ reasonParams: {
153
+ backupId: validBackupId,
154
+ chosenPartitions: backup?.partitionsCount,
155
+ ...readReasonParams(custom),
156
+ },
157
+ access: buildAwsAccess(undefined),
158
+ // The workaround has no detection. The customer enters the backup.
159
+ detection: { backups: [] },
160
+ spec: {
161
+ principal,
162
+ transferCompleted: phase !== 'AwaitingPrincipal' && phase !== 'Transferring',
163
+ backup,
164
+ },
165
+ source: {
166
+ bucket: labelValue(custom, LABEL.sourceBucket) || undefined,
167
+ kmsKeyArn: labelValue(custom, LABEL.sourceKmsKey) || undefined,
168
+ },
169
+ displayName: cluster.name.slice(prefix.length),
170
+ };
171
+ };
172
+ /**
173
+ * The one plan check of the details page and the list. An unknown plan (slow
174
+ * or failed org request) keeps a prefixed cluster locked. Only a known other
175
+ * plan unlocks it.
40
176
  */
41
177
  export const isMigrationPlan = (planType) => !planType || planType === SalesPlanType.ENTERPRISE;
178
+ /** True for a label of the workaround. The UI shows no such label. */
179
+ export const isMigrationLabel = isSharedMigrationLabel;
180
+ /** The name of a new migration cluster. Create needs a valid principal. */
181
+ export const buildMigrationCreateName = (name) => prefixOf('Transferring') + name;
182
+ // A step clears the reason labels: they belong to the phase before it.
183
+ const buildUpdate = (view, labels, phase, set) => {
184
+ const replaced = [
185
+ LABEL.reason,
186
+ LABEL.reasonParam,
187
+ ...Object.keys(set).map((key) => LABEL[key]),
188
+ ];
189
+ const kept = (labels?.custom ?? []).filter((label) => !replaced.some((prefix) => label.startsWith(prefix)));
190
+ const added = Object.entries(set).flatMap(([key, value]) => value ? [LABEL[key] + value] : []);
191
+ const prefix = prefixOf(phase);
192
+ return {
193
+ // A name of the first workaround can be too long for a longer prefix.
194
+ name: prefix +
195
+ view.displayName.slice(0, MAX_LENGTH_CLUSTER_NAME - prefix.length),
196
+ labels: {
197
+ camunda: [...(labels?.camunda ?? [])],
198
+ custom: [...kept, ...added],
199
+ },
200
+ };
201
+ };
202
+ /** Transferring → AwaitingBackup. Keeps the source that the policy used. */
203
+ export const buildTransferFinishedUpdate = (view, labels, source) => buildUpdate(view, labels, 'AwaitingBackup', {
204
+ sourceBucket: source.bucket,
205
+ sourceKmsKey: source.kmsKeyArn,
206
+ });
207
+ /** AwaitingBackup → Transferring. */
208
+ export const buildReopenTransferUpdate = (view, labels) => buildUpdate(view, labels, 'Transferring', {});
42
209
  /**
43
- * The backup ID has no field in the operator yet. Ops read it from the custom
44
- * labels of the cluster. The new label replaces an older one.
210
+ * AwaitingBackup or RestoreFailed → Verifying. Each choice is a new attempt,
211
+ * also the same backup again.
45
212
  */
46
- export const withBackupIdLabel = (labels, backupId) => ({
47
- camunda: [...(labels?.camunda ?? [])],
48
- custom: [
49
- ...(labels?.custom ?? []).filter((label) => !label.startsWith(MIGRATION_BACKUP_ID_LABEL_PREFIX)),
50
- MIGRATION_BACKUP_ID_LABEL_PREFIX + backupId,
51
- ],
213
+ export const buildBackupChoiceUpdate = (view, labels, choice) => buildUpdate(view, labels, 'Verifying', {
214
+ backupId: choice.backupId,
215
+ partitions: String(choice.partitionsCount),
216
+ attempt: String((view.spec.backup?.attempt ?? 0) + 1),
52
217
  });
53
- /** True for the label that holds the backup ID. The UI shows no such label. */
54
- export const isBackupIdLabel = (label) => label.startsWith(MIGRATION_BACKUP_ID_LABEL_PREFIX);
55
- export const buildStartName = (name) => START_PREFIX + name;
56
- export const buildMigrateName = (name) => MIGRATE_PREFIX + name;
57
- /** The name limit while the prefix takes room in the 50 character name. */
58
- export const MIGRATION_NAME_MAX_LENGTH = 35;
59
- /** The description holds the role, and the description allows 150 characters. */
60
- export const MIGRATION_ROLE_ARN_MAX_LENGTH = 150;
61
- // The IAM path takes any printable character and ends with a slash. The role
62
- // name after it takes no slash, so a trailing slash has no name and fails.
63
- // AWS allows 64 characters at most in a role name.
64
- const AWS_ROLE_ARN_PATTERN = /^arn:(?:aws|aws-cn|aws-us-gov):iam::\d{12}:role\/(?:[\x21-\x7E]+\/)?[A-Za-z0-9+=,.@_-]{1,64}$/;
218
+ // The pattern of the contract. AWS allows 64 characters in a role name. The
219
+ // contract allows 512 in the path, but the 150 characters of the description
220
+ // are less, so no path check is necessary.
221
+ const AWS_ROLE_ARN_PATTERN = /^arn:(aws|aws-cn|aws-us-gov):iam::[0-9]{12}:role\/([A-Za-z0-9_+=,.@-]+\/)*[A-Za-z0-9_+=,.@-]{1,64}$/;
65
222
  export const isValidAwsRoleArn = (value) => value.length <= MIGRATION_ROLE_ARN_MAX_LENGTH &&
66
223
  AWS_ROLE_ARN_PATTERN.test(value);
224
+ // TODO(3844-workaround): remove with the name-prefix migration workaround.
225
+ // Create accepted this pattern before the contract pattern. A cluster created
226
+ // then keeps its migration, so that its actions stay locked.
227
+ const LEGACY_AWS_ROLE_ARN_PATTERN = /^arn:(?:aws|aws-cn|aws-us-gov):iam::\d{12}:role\/(?:[\x21-\x7E]+\/)?[A-Za-z0-9+=,.@_-]{1,64}$/;
228
+ const isKnownMigrationPrincipal = (value) => isValidAwsRoleArn(value) ||
229
+ (value.length <= MIGRATION_ROLE_ARN_MAX_LENGTH &&
230
+ LEGACY_AWS_ROLE_ARN_PATTERN.test(value));
@@ -19,7 +19,8 @@ import { CLUSTER_CREATION_BLOCKED_FLAG } from '../../runtime/cluster-creation-bl
19
19
  import { SELF_MANAGED_MIGRATION_FLAG } from '../../runtime/self-managed-migration.js';
20
20
  import { toApiConfig } from '../../runtime/to-api-config.js';
21
21
  import { Modal, Stack, TextInput } from '../../ui/index.js';
22
- import { buildMigrateName, getMigrationInfo, isMigrationPlan, MIGRATION_NAME_MAX_LENGTH, withBackupIdLabel, } from '../../utils/migration-workaround.js';
22
+ import { isMigrationLocked, } from '../../utils/migration-view.js';
23
+ import { buildBackupChoiceUpdate, buildReopenTransferUpdate, buildTransferFinishedUpdate, getMigrationView, isMigrationPlan, MIGRATION_NAME_MAX_LENGTH, } from '../../utils/migration-workaround.js';
23
24
  import { safeTranslate } from '../../utils/safe-translate.js';
24
25
  import { clusterHealthOverride } from '../cluster-health-override.js';
25
26
  import { useClusterApiClients } from '../environment/use-cluster-api-clients.js';
@@ -540,7 +541,7 @@ export const C4ClusterDetailsApp = observer((props) => {
540
541
  cluster?.status?.zeebeRestUrl,
541
542
  reloadStatisticsConfig,
542
543
  ]);
543
- // TODO(3844-workaround): The state comes from the name prefix.
544
+ // TODO(3844-workaround): The view comes from the name prefix and labels.
544
545
  const migrationFlagOn = useC4FeatureFlag(SELF_MANAGED_MIGRATION_FLAG);
545
546
  const migrationOrgInfo = data.getOrgInfo(props.orgId);
546
547
  // An unknown plan (slow or failed org request) keeps a prefixed cluster
@@ -548,28 +549,35 @@ export const C4ClusterDetailsApp = observer((props) => {
548
549
  const migrationPlanType = migrationOrgInfo?.organizationToSalesPlan?.salesPlan?.salesPlanType;
549
550
  const clusterName = cluster?.name;
550
551
  const clusterDescription = cluster?.description;
551
- // Memoized, so that `onConfirmMigration` and the tabs keep their identity
552
+ const clusterLabels = cluster?.labels;
553
+ // Memoized, so that `onMigrationUpdate` and the tabs keep their identity
552
554
  // between renders.
553
- const migrationInfo = useMemo(() => migrationFlagOn &&
555
+ const migrationView = useMemo(() => migrationFlagOn &&
554
556
  isMigrationPlan(migrationPlanType) &&
555
557
  clusterName !== undefined
556
- ? getMigrationInfo({
558
+ ? getMigrationView({
557
559
  name: clusterName,
558
560
  description: clusterDescription,
561
+ labels: clusterLabels,
559
562
  })
560
- : undefined, [migrationFlagOn, migrationPlanType, clusterName, clusterDescription]);
561
- const migrationState = migrationInfo && migrationInfo.state !== 'none'
562
- ? migrationInfo.state
563
- : undefined;
564
- const migrationLocked = migrationState !== undefined;
563
+ : undefined, [
564
+ migrationFlagOn,
565
+ migrationPlanType,
566
+ clusterName,
567
+ clusterDescription,
568
+ clusterLabels,
569
+ ]);
570
+ const migrationLocked = isMigrationLocked(migrationView);
565
571
  // Only a known Enterprise plan may submit. An unknown plan keeps the lock
566
- // but never confirms.
567
- const migrationCanConfirm = migrationPlanType === SalesPlanType.ENTERPRISE &&
572
+ // but never submits.
573
+ const migrationCanEdit = migrationPlanType === SalesPlanType.ENTERPRISE &&
568
574
  Boolean(authz.visibilities.clusters?.canEdit);
569
575
  // TODO(3844-workaround): Rename stays open in a migration state, so a tester
570
576
  // can change the name prefix and with it the state.
571
577
  const canRename = Boolean(authz.visibilities.clusters?.canEdit);
572
- const canDelete = !migrationLocked && Boolean(authz.visibilities.clusters?.canDelete);
578
+ // Delete stays open in every phase: deleting the cluster cancels the
579
+ // migration (ADR 0008).
580
+ const canDelete = Boolean(authz.visibilities.clusters?.canDelete);
573
581
  const { hasIdentityIntegration, useClusterSecretsLabel } = useClusterVersionFlags(cluster);
574
582
  const [dismissedFailedRestores, setDismissedFailedRestores] = useState(loadDismissedFailedRestores);
575
583
  const dismissFailedRestore = useCallback((restoreId) => {
@@ -656,10 +664,10 @@ export const C4ClusterDetailsApp = observer((props) => {
656
664
  setClusterMutationError('');
657
665
  }
658
666
  }, [deleteOpen]);
659
- // TODO(3844-workaround): The backup ID has no field yet. The PATCH stores
660
- // it in the custom labels, where ops read it.
661
- const onConfirmMigration = useCallback(async (backupId) => {
662
- if (!migrationInfo || !migrationCanConfirm)
667
+ // TODO(3844-workaround): Each step of the customer renames the cluster
668
+ // and writes its labels. The operator integration writes the spec instead.
669
+ const onMigrationUpdate = useCallback(async (build) => {
670
+ if (!migrationView || !migrationCanEdit)
663
671
  return;
664
672
  setClusterMutationBusy(true);
665
673
  setClusterMutationError('');
@@ -667,10 +675,7 @@ export const C4ClusterDetailsApp = observer((props) => {
667
675
  await ConsoleClusterService.updateCluster({
668
676
  config: apiConfig,
669
677
  params: { orgId: props.orgId, clusterId: props.clusterId },
670
- body: {
671
- name: buildMigrateName(migrationInfo.displayName),
672
- labels: withBackupIdLabel(cluster?.labels, backupId),
673
- },
678
+ body: build(migrationView, clusterLabels),
674
679
  });
675
680
  await reloadCluster();
676
681
  }
@@ -684,22 +689,22 @@ export const C4ClusterDetailsApp = observer((props) => {
684
689
  apiConfig,
685
690
  props.orgId,
686
691
  props.clusterId,
687
- migrationInfo,
688
- migrationCanConfirm,
689
- cluster?.labels,
692
+ migrationView,
693
+ migrationCanEdit,
694
+ clusterLabels,
690
695
  reloadCluster,
691
696
  ]);
692
- // TODO(3844-workaround): A prefixed name that is too long makes the
693
- // later PATCH of `onConfirmMigration` fail, because it adds a longer prefix.
694
- const renamedMigrationInfo = migrationInfo === undefined
697
+ // TODO(3844-workaround): A later step can write a longer prefix. Then it
698
+ // cuts the name to 50 characters. This limit keeps a renamed name short
699
+ // enough, so that no step cuts it.
700
+ const renamedMigrationView = migrationView === undefined
695
701
  ? undefined
696
- : getMigrationInfo({
702
+ : getMigrationView({
697
703
  name: newClusterName,
698
704
  description: clusterDescription,
699
705
  });
700
- const renameTooLongForMigration = renamedMigrationInfo !== undefined &&
701
- renamedMigrationInfo.state !== 'none' &&
702
- renamedMigrationInfo.displayName.length > MIGRATION_NAME_MAX_LENGTH;
706
+ const renameTooLongForMigration = renamedMigrationView !== undefined &&
707
+ renamedMigrationView.displayName.length > MIGRATION_NAME_MAX_LENGTH;
703
708
  const onRename = async () => {
704
709
  setClusterMutationBusy(true);
705
710
  setClusterMutationError('');
@@ -1584,15 +1589,19 @@ export const C4ClusterDetailsApp = observer((props) => {
1584
1589
  init: () => { },
1585
1590
  },
1586
1591
  ];
1587
- // TODO(3844-workaround): A locked cluster shows only the migration panel.
1588
- if (migrationState) {
1592
+ // A locked cluster shows only the migration panel.
1593
+ if (migrationView && migrationLocked) {
1589
1594
  return [
1590
1595
  {
1591
1596
  id: 'overview',
1592
1597
  label: tabLabel('overview'),
1593
- component: (_jsx(C4ClusterMigration, { state: migrationState, roleArn: migrationInfo?.roleArn, busy: clusterMutationBusy, canConfirm: migrationCanConfirm, error: clusterMutationError, onConfirm: (backupId) => {
1594
- void onConfirmMigration(backupId);
1595
- }, translations: buildMigrationTranslations(t) })),
1598
+ component: (_jsx(C4ClusterMigration, { migration: migrationView, busy: clusterMutationBusy, canEdit: migrationCanEdit, error: clusterMutationError, onTransferFinished: (source) => {
1599
+ void onMigrationUpdate((view, labels) => buildTransferFinishedUpdate(view, labels, source));
1600
+ }, onReopenTransfer: () => {
1601
+ void onMigrationUpdate(buildReopenTransferUpdate);
1602
+ }, onChooseBackup: (choice) => {
1603
+ void onMigrationUpdate((view, labels) => buildBackupChoiceUpdate(view, labels, choice));
1604
+ }, onDelete: canDelete ? () => setDeleteOpen(true) : undefined, translations: buildMigrationTranslations(t) })),
1596
1605
  visible: true,
1597
1606
  },
1598
1607
  ];
@@ -1607,10 +1616,11 @@ export const C4ClusterDetailsApp = observer((props) => {
1607
1616
  initializeTab: tab.id === activeTabId ? tab.init : undefined,
1608
1617
  }));
1609
1618
  }, [
1610
- migrationState,
1611
- migrationCanConfirm,
1612
- migrationInfo?.roleArn,
1613
- onConfirmMigration,
1619
+ migrationView,
1620
+ migrationLocked,
1621
+ migrationCanEdit,
1622
+ onMigrationUpdate,
1623
+ canDelete,
1614
1624
  clusterMutationBusy,
1615
1625
  clusterMutationError,
1616
1626
  activeTabId,
@@ -20,7 +20,7 @@ import { CLUSTER_CREATION_BLOCKED_FLAG } from '../../../runtime/cluster-creation
20
20
  import { useC4TwoPhaseUpgradeMockup } from '../../../runtime/use-c4-two-phase-upgrade-mockup.js';
21
21
  import { Button, Checkbox, DsText, Link, Modal, Stack } from '../../../ui/index.js';
22
22
  import { RadioButton, RadioButtonGroup } from '../../../ui/families.js';
23
- import { isBackupIdLabel } from '../../../utils/migration-workaround.js';
23
+ import { isMigrationLabel } from '../../../utils/migration-workaround.js';
24
24
  import { safeTranslate } from '../../../utils/safe-translate.js';
25
25
  import { clusterHealthOverride } from '../../cluster-health-override.js';
26
26
  import { isClusterReconciliationPaused } from '../../is-cluster-reconciliation-paused.js';
@@ -1365,7 +1365,7 @@ const C4ClusterDetailsOverviewTabImpl = (props) => {
1365
1365
  const tagsValue = [
1366
1366
  ...(cluster.labels?.camunda ?? []),
1367
1367
  ...(cluster.labels?.custom ?? []),
1368
- ].filter((value) => typeof value === 'string' && value.length > 0 && !isBackupIdLabel(value));
1368
+ ].filter((value) => typeof value === 'string' && value.length > 0 && !isMigrationLabel(value));
1369
1369
  const encryptionKeyValue = cluster.primaryEncryptionKeyId && cluster.primaryEncryptionKeyId.length > 0
1370
1370
  ? cluster.primaryEncryptionKeyId
1371
1371
  : cluster.encryption && cluster.encryption !== 'Provider'