@camunda/ccma-saas-frontend 0.31.1 → 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.
- package/lib/esm/components/c4-cluster-list/c4-cluster-list.js +3 -1
- package/lib/esm/components/c4-cluster-list/c4-cluster-list.types.d.ts +2 -2
- package/lib/esm/components/c4-cluster-migration/c4-cluster-migration.d.ts +2 -1
- package/lib/esm/components/c4-cluster-migration/c4-cluster-migration.js +46 -15
- package/lib/esm/components/c4-cluster-migration/c4-cluster-migration.types.d.ts +47 -12
- package/lib/esm/components/c4-cluster-migration/migration-translations.d.ts +2 -4
- package/lib/esm/components/c4-cluster-migration/migration-translations.js +90 -15
- package/lib/esm/i18n/en/pages/clusterdetails.json +63 -14
- package/lib/esm/i18n/en/pages/createcluster.json +1 -1
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/runtime/use-c4-two-phase-upgrade-mockup.d.ts +5 -1
- package/lib/esm/runtime/use-c4-two-phase-upgrade-mockup.js +4 -2
- package/lib/esm/utils/migration-aws-policy.d.ts +22 -0
- package/lib/esm/utils/migration-aws-policy.js +54 -0
- package/lib/esm/utils/migration-view.d.ts +98 -0
- package/lib/esm/utils/migration-view.js +52 -0
- package/lib/esm/utils/migration-workaround.d.ts +46 -32
- package/lib/esm/utils/migration-workaround.js +212 -48
- package/lib/esm/widgets/cluster-details/c4-cluster-details-app.js +50 -40
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-overview-tab.js +3 -2
- package/lib/esm/widgets/clusters/c4-clusters-page.js +8 -7
- package/lib/esm/widgets/create-cluster/c4-create-cluster-page.js +3 -3
- package/package.json +3 -3
- package/lib/esm/components/c4-cluster-migration/backup-id.d.ts +0 -2
- package/lib/esm/components/c4-cluster-migration/backup-id.js +0 -9
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export declare const MIGRATION_PHASES: readonly ["AwaitingPrincipal", "Transferring", "AwaitingBackup", "Verifying", "Restoring", "Completed", "VerificationFailed", "RestoreFailed"];
|
|
2
|
+
export type MigrationPhase = (typeof MIGRATION_PHASES)[number];
|
|
3
|
+
/** The reasons of the contract's reason catalogue, per phase. */
|
|
4
|
+
export declare const MIGRATION_REASONS_BY_PHASE: {
|
|
5
|
+
readonly AwaitingPrincipal: readonly ["WaitingForPrincipal", "GrantingAccess"];
|
|
6
|
+
readonly Transferring: readonly ["TransferOpen", "RemovingAccess"];
|
|
7
|
+
readonly AwaitingBackup: readonly ["WaitingForBackupChoice", "BackupNotFound", "PartitionCountMismatch"];
|
|
8
|
+
readonly Verifying: readonly ["VerifyingBackup"];
|
|
9
|
+
readonly Restoring: readonly ["RestoringBackup"];
|
|
10
|
+
readonly Completed: readonly ["MigrationCompleted"];
|
|
11
|
+
readonly VerificationFailed: readonly ["BackupIncomplete", "SnapshotsMissing", "BackupUnreadable", "ElasticsearchVersionIncompatible", "CamundaVersionIncompatible", "PartitionCountIncompatible", "InsufficientDiskSize"];
|
|
12
|
+
readonly RestoreFailed: readonly ["RestoreFailedBeforeDataDeletion", "RestoreFailedAfterDataDeletion"];
|
|
13
|
+
};
|
|
14
|
+
export type MigrationReason = (typeof MIGRATION_REASONS_BY_PHASE)[MigrationPhase][number];
|
|
15
|
+
/**
|
|
16
|
+
* The values of a reason. A backup ID is an int64 in Zeebe, thus a string here:
|
|
17
|
+
* a JavaScript number loses digits above 2^53.
|
|
18
|
+
*/
|
|
19
|
+
export interface MigrationReasonParams {
|
|
20
|
+
backupId?: string;
|
|
21
|
+
backupPartitions?: number;
|
|
22
|
+
chosenPartitions?: number;
|
|
23
|
+
clusterPartitions?: number;
|
|
24
|
+
backupVersion?: string;
|
|
25
|
+
clusterVersion?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface MigrationAccessStatement {
|
|
28
|
+
resource: string;
|
|
29
|
+
actions: string[];
|
|
30
|
+
}
|
|
31
|
+
export type MigrationSourceKind = 'Bucket' | 'Objects' | 'Key';
|
|
32
|
+
export interface MigrationSourceAccess {
|
|
33
|
+
kind: MigrationSourceKind;
|
|
34
|
+
actions: string[];
|
|
35
|
+
}
|
|
36
|
+
/** What the customer's principal needs. The contract's `status.access`. */
|
|
37
|
+
export interface MigrationAccess {
|
|
38
|
+
/** The backup bucket of the cluster. Not set while the bucket is created. */
|
|
39
|
+
bucket?: string;
|
|
40
|
+
/** The customer's KMS key. Set only for a BYOK cluster. */
|
|
41
|
+
encryptionKey?: string;
|
|
42
|
+
/** The target-side statements. Empty while `bucket` is not set. */
|
|
43
|
+
statements: MigrationAccessStatement[];
|
|
44
|
+
/** The source-side actions. Console fills in the resources. */
|
|
45
|
+
source: MigrationSourceAccess[];
|
|
46
|
+
}
|
|
47
|
+
export interface MigrationDetectedBackup {
|
|
48
|
+
backupId: string;
|
|
49
|
+
partitionsCount: number;
|
|
50
|
+
complete: boolean;
|
|
51
|
+
time: string;
|
|
52
|
+
latestComplete?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface MigrationBackupChoice {
|
|
55
|
+
/** An integer from 1 to 2^63-1, as a string. */
|
|
56
|
+
backupId: string;
|
|
57
|
+
partitionsCount: number;
|
|
58
|
+
attempt: number;
|
|
59
|
+
}
|
|
60
|
+
export interface MigrationSpec {
|
|
61
|
+
principal: string;
|
|
62
|
+
transferCompleted: boolean;
|
|
63
|
+
backup?: MigrationBackupChoice;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The source side that the customer enters. The operator never sees it. Console
|
|
67
|
+
* keeps it only to render the source statements of the policy.
|
|
68
|
+
*/
|
|
69
|
+
export interface MigrationSourceInput {
|
|
70
|
+
/** The name of the customer's Self-Managed bucket. */
|
|
71
|
+
bucket?: string;
|
|
72
|
+
/** The ARN of the KMS key of that bucket. Not set when it uses none. */
|
|
73
|
+
kmsKeyArn?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface MigrationView {
|
|
76
|
+
phase: MigrationPhase;
|
|
77
|
+
/**
|
|
78
|
+
* Not set only when the source of the view knows no reason. Then the UI
|
|
79
|
+
* shows the general text of the phase.
|
|
80
|
+
*/
|
|
81
|
+
reason?: MigrationReason;
|
|
82
|
+
reasonParams: MigrationReasonParams;
|
|
83
|
+
/** Not set while the operator prepares the backup bucket. */
|
|
84
|
+
access?: MigrationAccess;
|
|
85
|
+
detection: {
|
|
86
|
+
backups: MigrationDetectedBackup[];
|
|
87
|
+
};
|
|
88
|
+
spec: MigrationSpec;
|
|
89
|
+
source: MigrationSourceInput;
|
|
90
|
+
/** The cluster name without any state encoding. */
|
|
91
|
+
displayName: string;
|
|
92
|
+
}
|
|
93
|
+
/** The ADR lock rule: a migration cluster is hidden and locked until Completed. */
|
|
94
|
+
export declare const isMigrationLocked: (view: MigrationView | undefined) => boolean;
|
|
95
|
+
/** A backup ID is an integer from 1 to 2^63-1. A string keeps every digit. */
|
|
96
|
+
export declare const isValidBackupId: (value: string) => boolean;
|
|
97
|
+
/** A partition count is a whole number from 0 to 2147483647. `0`: Elasticsearch data only. */
|
|
98
|
+
export declare const isValidPartitionsCount: (value: string) => boolean;
|
|
@@ -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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
*
|
|
17
|
-
*
|
|
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
|
|
11
|
+
export declare const buildAwsAccess: (bucketArn?: string) => MigrationAccess;
|
|
12
|
+
export interface MigrationWorkaroundCluster {
|
|
21
13
|
name: string;
|
|
22
14
|
description?: string;
|
|
23
|
-
|
|
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
|
-
*
|
|
27
|
-
*
|
|
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
|
-
*
|
|
32
|
-
*
|
|
50
|
+
* AwaitingBackup or RestoreFailed → Verifying. Each choice is a new attempt,
|
|
51
|
+
* also the same backup again.
|
|
33
52
|
*/
|
|
34
|
-
export declare const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 {
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
*
|
|
14
|
-
*
|
|
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
|
|
18
|
-
const
|
|
19
|
-
[
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
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
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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
|
-
*
|
|
44
|
-
*
|
|
210
|
+
* AwaitingBackup or RestoreFailed → Verifying. Each choice is a new attempt,
|
|
211
|
+
* also the same backup again.
|
|
45
212
|
*/
|
|
46
|
-
export const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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));
|