From 4ed4e5f39c7b23e87542ad0c652c43c95b2bbcb6 Mon Sep 17 00:00:00 2001 From: Rachel Kim Date: Fri, 15 Oct 2021 16:09:43 -0700 Subject: [PATCH] Add DMS values to migration extension save and close feature (#17375) --- extensions/sql-migration/src/api/azure.ts | 4 ++ .../sql-migration/src/models/stateMachine.ts | 17 +++++++- .../src/wizard/databaseBackupPage.ts | 39 +++++++++---------- .../src/wizard/integrationRuntimePage.ts | 33 +++++++++++++--- 4 files changed, 64 insertions(+), 29 deletions(-) diff --git a/extensions/sql-migration/src/api/azure.ts b/extensions/sql-migration/src/api/azure.ts index 8a0668d059..a6c8cb08d5 100644 --- a/extensions/sql-migration/src/api/azure.ts +++ b/extensions/sql-migration/src/api/azure.ts @@ -358,6 +358,10 @@ export function getResourceGroupFromId(id: string): string { return id.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '').toLowerCase(); } +export function getFullResourceGroupFromId(id: string): string { + return id.replace(RegExp('/providers/.*'), '').toLowerCase(); +} + export interface SqlMigrationServiceProperties { name: string; subscriptionId: string; diff --git a/extensions/sql-migration/src/models/stateMachine.ts b/extensions/sql-migration/src/models/stateMachine.ts index b28c574ee8..e1ff2fa30e 100644 --- a/extensions/sql-migration/src/models/stateMachine.ts +++ b/extensions/sql-migration/src/models/stateMachine.ts @@ -68,6 +68,11 @@ export enum Page { Summary } +export enum WizardEntryPoint { + Default = 'Default', + SaveAndClose = 'SaveAndClose', +} + export interface DatabaseBackupModel { migrationMode: MigrationMode; networkContainerType: NetworkContainerType; @@ -127,6 +132,7 @@ export interface SavedInfo { targetSubscription: azureResource.AzureResourceSubscription | null; blobs: Blob[]; targetDatabaseNames: string[]; + migrationServiceId: string | null; } @@ -987,6 +993,10 @@ export class MigrationStateModel implements Model, vscode.Disposable { response.databaseMigration.properties.backupConfiguration = requestBody.properties.backupConfiguration!; response.databaseMigration.properties.offlineConfiguration = requestBody.properties.offlineConfiguration!; + let wizardEntryPoint = WizardEntryPoint.Default; + if (this.resumeAssessment) { + wizardEntryPoint = WizardEntryPoint.SaveAndClose; + } if (response.status === 201 || response.status === 200) { sendSqlMigrationActionEvent( TelemetryViews.MigrationWizardSummaryPage, @@ -1005,7 +1015,8 @@ export class MigrationStateModel implements Model, vscode.Disposable { 'targetDatabaseName': this._targetDatabaseNames[i], 'serverName': this._targetServerInstance.name, 'sqlMigrationServiceId': Buffer.from(this._sqlMigrationService?.id!).toString('base64'), - 'irRegistered': (this._nodeNames.length > 0).toString() + 'irRegistered': (this._nodeNames.length > 0).toString(), + 'wizardEntryPoint': wizardEntryPoint, }, { } @@ -1054,12 +1065,14 @@ export class MigrationStateModel implements Model, vscode.Disposable { networkShare: null, targetSubscription: null, blobs: [], - targetDatabaseNames: [] + targetDatabaseNames: [], + migrationServiceId: null, }; switch (currentPage) { case Page.Summary: case Page.IntegrationRuntime: + saveInfo.migrationServiceId = this._sqlMigrationService?.id!; case Page.DatabaseBackup: saveInfo.networkContainerType = this._databaseBackup.networkContainerType; diff --git a/extensions/sql-migration/src/wizard/databaseBackupPage.ts b/extensions/sql-migration/src/wizard/databaseBackupPage.ts index 46c1df8f17..291d54094b 100644 --- a/extensions/sql-migration/src/wizard/databaseBackupPage.ts +++ b/extensions/sql-migration/src/wizard/databaseBackupPage.ts @@ -621,7 +621,6 @@ export class DatabaseBackupPage extends MigrationWizardPage { .withProps({ value: constants.SUBSCRIPTION, width: WIZARD_INPUT_COMPONENT_WIDTH, - // requiredIndicator: true, CSSStyles: { ...styles.LABEL_CSS, 'margin': '0' @@ -632,8 +631,7 @@ export class DatabaseBackupPage extends MigrationWizardPage { enabled: false, width: WIZARD_INPUT_COMPONENT_WIDTH, CSSStyles: { - // ...styles.BODY_CSS, - // 'margin-top': '-1em' + 'margin': '0' } }).component(); @@ -641,7 +639,6 @@ export class DatabaseBackupPage extends MigrationWizardPage { .withProps({ value: constants.LOCATION, width: WIZARD_INPUT_COMPONENT_WIDTH, - // requiredIndicator: true, CSSStyles: { ...styles.LABEL_CSS, 'margin': '12px 0 0' @@ -851,6 +848,8 @@ export class DatabaseBackupPage extends MigrationWizardPage { })); if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= Page.DatabaseBackup) { targetDatabaseInput.value = this.migrationStateModel.savedInfo.targetDatabaseNames[index]; + } else { + targetDatabaseInput.value = this.migrationStateModel._targetDatabaseNames[index]; } this._networkShareTargetDatabaseNames.push(targetDatabaseInput); @@ -877,6 +876,8 @@ export class DatabaseBackupPage extends MigrationWizardPage { })); if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= Page.DatabaseBackup) { blobTargetDatabaseInput.value = this.migrationStateModel.savedInfo.targetDatabaseNames[index]; + } else { + targetDatabaseInput.value = this.migrationStateModel._targetDatabaseNames[index]; } this._blobContainerTargetDatabaseNames.push(blobTargetDatabaseInput); @@ -1133,10 +1134,6 @@ export class DatabaseBackupPage extends MigrationWizardPage { if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= Page.DatabaseBackup) { this.migrationStateModel._targetDatabaseNames = this.migrationStateModel.savedInfo.targetDatabaseNames; } - this.migrationStateModel._targetDatabaseNames?.forEach((v, index) => { - this._networkShareTargetDatabaseNames[index].value = v; - this._blobContainerTargetDatabaseNames[index].value = v; - }); await this._windowsUserAccountText.updateProperties({ required: containerType === NetworkContainerType.NETWORK_SHARE @@ -1201,7 +1198,7 @@ export class DatabaseBackupPage extends MigrationWizardPage { this._networkShareStorageAccountResourceGroupDropdown.values = await this.migrationStateModel.getAzureResourceGroupDropdownValues(this.migrationStateModel._databaseBackup.subscription); if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= Page.DatabaseBackup && this._networkShareStorageAccountResourceGroupDropdown.values) { this._networkShareStorageAccountResourceGroupDropdown.values.forEach((resource, index) => { - if ((resource).name === this.migrationStateModel.savedInfo?.networkShare?.resourceGroup.id) { + if ((resource).name.toLowerCase() === this.migrationStateModel.savedInfo?.networkShare?.resourceGroup?.id?.toLowerCase()) { selectDropDownIndex(this._networkShareStorageAccountResourceGroupDropdown, index); } }); @@ -1235,9 +1232,9 @@ export class DatabaseBackupPage extends MigrationWizardPage { this._blobContainerResourceGroupDropdowns.forEach((dropDown, index) => { dropDown.values = resourceGroupValues; if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= Page.DatabaseBackup && dropDown.values) { - dropDown.values.forEach((resource, index) => { - if ((resource).name === this.migrationStateModel.savedInfo?.blobs[index]?.resourceGroup.id) { - selectDropDownIndex(dropDown, index); + dropDown.values.forEach((resource, resourceIndex) => { + if ((resource).name.toLowerCase() === this.migrationStateModel.savedInfo?.blobs[index]?.resourceGroup?.id?.toLowerCase()) { + selectDropDownIndex(dropDown, resourceIndex); } }); } else { @@ -1256,9 +1253,9 @@ export class DatabaseBackupPage extends MigrationWizardPage { try { this._blobContainerStorageAccountDropdowns[index].values = await this.migrationStateModel.getStorageAccountValues(this.migrationStateModel._databaseBackup.subscription, this.migrationStateModel._databaseBackup.blobs[index].resourceGroup); if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= Page.DatabaseBackup && this._blobContainerStorageAccountDropdowns[index].values && this.migrationStateModel.savedInfo.blobs[index].storageAccount) { - this._blobContainerStorageAccountDropdowns[index].values!.forEach((resource, index) => { - if ((resource).name === this.migrationStateModel.savedInfo?.blobs[index]?.storageAccount.id) { - selectDropDownIndex(this._blobContainerStorageAccountDropdowns[index], index); + this._blobContainerStorageAccountDropdowns[index].values!.forEach((resource, resourceIndex) => { + if ((resource).name.toLowerCase() === this.migrationStateModel.savedInfo?.blobs[index]?.storageAccount?.id?.toLowerCase()) { + selectDropDownIndex(this._blobContainerStorageAccountDropdowns[index], resourceIndex); } }); } else { @@ -1277,9 +1274,9 @@ export class DatabaseBackupPage extends MigrationWizardPage { const blobContainerValues = await this.migrationStateModel.getBlobContainerValues(this.migrationStateModel._databaseBackup.subscription, this.migrationStateModel._databaseBackup.blobs[index].storageAccount); this._blobContainerDropdowns[index].values = blobContainerValues; if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= Page.DatabaseBackup && this._blobContainerDropdowns[index].values && this.migrationStateModel.savedInfo.blobs[index].blobContainer) { - this._blobContainerDropdowns[index].values!.forEach((resource, index) => { - if ((resource).name === this.migrationStateModel.savedInfo?.blobs[index]?.blobContainer.id) { - selectDropDownIndex(this._blobContainerDropdowns[index], index); + this._blobContainerDropdowns[index].values!.forEach((resource, resourceIndex) => { + if ((resource).name.toLowerCase() === this.migrationStateModel.savedInfo?.blobs[index]?.blobContainer?.id?.toLowerCase()) { + selectDropDownIndex(this._blobContainerDropdowns[index], resourceIndex); } }); } else { @@ -1298,9 +1295,9 @@ export class DatabaseBackupPage extends MigrationWizardPage { const blobLastBackupFileValues = await this.migrationStateModel.getBlobLastBackupFileNameValues(this.migrationStateModel._databaseBackup.subscription, this.migrationStateModel._databaseBackup.blobs[index].storageAccount, this.migrationStateModel._databaseBackup.blobs[index].blobContainer); this._blobContainerLastBackupFileDropdowns[index].values = blobLastBackupFileValues; if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= Page.DatabaseBackup && this._blobContainerLastBackupFileDropdowns[index].values && this.migrationStateModel.savedInfo.blobs[index].lastBackupFile) { - this._blobContainerLastBackupFileDropdowns[index].values!.forEach((resource, index) => { - if ((resource).name === this.migrationStateModel.savedInfo?.blobs[index]?.lastBackupFile) { - selectDropDownIndex(this._blobContainerLastBackupFileDropdowns[index], index); + this._blobContainerLastBackupFileDropdowns[index].values!.forEach((resource, resourceIndex) => { + if ((resource).name.toLowerCase() === this.migrationStateModel.savedInfo?.blobs[index]?.lastBackupFile!.toLowerCase()) { + selectDropDownIndex(this._blobContainerLastBackupFileDropdowns[index], resourceIndex); } }); } else { diff --git a/extensions/sql-migration/src/wizard/integrationRuntimePage.ts b/extensions/sql-migration/src/wizard/integrationRuntimePage.ts index b9abdc435f..6c3b652928 100644 --- a/extensions/sql-migration/src/wizard/integrationRuntimePage.ts +++ b/extensions/sql-migration/src/wizard/integrationRuntimePage.ts @@ -5,14 +5,15 @@ import * as azdata from 'azdata'; import * as vscode from 'vscode'; +import { azureResource } from 'azureResource'; import { MigrationWizardPage } from '../models/migrationWizardPage'; -import { MigrationStateModel, NetworkContainerType, StateChangeEvent } from '../models/stateMachine'; +import { MigrationStateModel, NetworkContainerType, Page, StateChangeEvent } from '../models/stateMachine'; import { CreateSqlMigrationServiceDialog } from '../dialog/createSqlMigrationService/createSqlMigrationServiceDialog'; import * as constants from '../constants/strings'; import { WIZARD_INPUT_COMPONENT_WIDTH } from './wizardController'; -import { getLocationDisplayName, getSqlMigrationService, getSqlMigrationServiceAuthKeys, getSqlMigrationServiceMonitoringData, SqlManagedInstance } from '../api/azure'; +import { getFullResourceGroupFromId, getLocationDisplayName, getSqlMigrationService, getSqlMigrationServiceAuthKeys, getSqlMigrationServiceMonitoringData, SqlManagedInstance, SqlVMServer } from '../api/azure'; import { IconPathHelper } from '../constants/iconPathHelper'; -import { findDropDownItemIndex } from '../api/utils'; +import { findDropDownItemIndex, selectDropDownIndex } from '../api/utils'; import * as styles from '../constants/styles'; export class IntergrationRuntimePage extends MigrationWizardPage { @@ -85,6 +86,10 @@ export class IntergrationRuntimePage extends MigrationWizardPage { } public async onPageEnter(pageChangeInfo: azdata.window.WizardPageChangeInfo): Promise { + if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= Page.IntegrationRuntime) { + this.migrationStateModel._targetSubscription = this.migrationStateModel.savedInfo.targetSubscription; + this.migrationStateModel._targetServerInstance = this.migrationStateModel.savedInfo.targetServerInstance; + } this._subscription.value = this.migrationStateModel._targetSubscription.name; this._location.value = await getLocationDisplayName(this.migrationStateModel._targetServerInstance.location); @@ -386,6 +391,14 @@ export class IntergrationRuntimePage extends MigrationWizardPage { this._resourceGroupDropdown.loading = true; try { this._resourceGroupDropdown.values = await this.migrationStateModel.getAzureResourceGroupDropdownValues(this.migrationStateModel._targetSubscription); + if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= Page.IntegrationRuntime && this._resourceGroupDropdown.values) { + this._resourceGroupDropdown.values.forEach((resource, resourceIndex) => { + const resourceId = this.migrationStateModel.savedInfo?.migrationServiceId?.toLowerCase(); + if (resourceId && (resource).name.toLowerCase() === getFullResourceGroupFromId(resourceId)) { + selectDropDownIndex(this._resourceGroupDropdown, resourceIndex); + } + }); + } } finally { this._resourceGroupDropdown.loading = false; } @@ -395,12 +408,20 @@ export class IntergrationRuntimePage extends MigrationWizardPage { this._dmsDropdown.loading = true; try { this._dmsDropdown.values = await this.migrationStateModel.getSqlMigrationServiceValues(this.migrationStateModel._targetSubscription, this.migrationStateModel._targetServerInstance, resourceGroupName); - const selectedSqlMigrationService = this._dmsDropdown.values.find(v => v.displayName.toLowerCase() === this.migrationStateModel._sqlMigrationService?.name.toLowerCase()); - this._dmsDropdown.value = (selectedSqlMigrationService) ? selectedSqlMigrationService : this._dmsDropdown.values[0]; + const selectedSqlMigrationService = this._dmsDropdown.values.find(v => v.displayName.toLowerCase() === this.migrationStateModel._sqlMigrationService?.name?.toLowerCase()); + + if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= Page.IntegrationRuntime && this._dmsDropdown.values) { + this._dmsDropdown.values.forEach((resource, resourceIndex) => { + if ((resource).name.toLowerCase() === this.migrationStateModel.savedInfo?.migrationServiceId?.toLowerCase()) { + selectDropDownIndex(this._dmsDropdown, resourceIndex); + } + }); + } else { + this._dmsDropdown.value = (selectedSqlMigrationService) ? selectedSqlMigrationService : this._dmsDropdown.values[0]; + } } finally { this._dmsDropdown.loading = false; } - } private async loadMigrationServiceStatus(): Promise {