SQL-Migration: enable cross subscription service migration (#22876)

* x subscription migration support

* refresh after cutover

* fix service irregular status load behavior

* queue service status requests, fix typo

* add migationTargetServerName helper method

* save context before api call
This commit is contained in:
brian-harris
2023-04-27 16:28:32 -07:00
committed by GitHub
parent 65f8915b7e
commit fe32180c71
15 changed files with 347 additions and 240 deletions

View File

@@ -8,7 +8,7 @@ import * as azurecore from 'azurecore';
import * as vscode from 'vscode';
import * as contracts from '../service/contracts';
import * as features from '../service/features';
import { SqlMigrationService, SqlManagedInstance, startDatabaseMigration, StartDatabaseMigrationRequest, StorageAccount, SqlVMServer, getLocationDisplayName, getSqlManagedInstanceDatabases, AzureSqlDatabaseServer, VirtualMachineInstanceView } from '../api/azure';
import { SqlMigrationService, SqlManagedInstance, startDatabaseMigration, StartDatabaseMigrationRequest, StorageAccount, SqlVMServer, getSqlManagedInstanceDatabases, AzureSqlDatabaseServer, VirtualMachineInstanceView } from '../api/azure';
import * as constants from '../constants/strings';
import * as nls from 'vscode-nls';
import { v4 as uuidv4 } from 'uuid';
@@ -150,6 +150,8 @@ export interface SavedInfo {
blobs: Blob[];
targetDatabaseNames: string[];
sqlMigrationService: SqlMigrationService | undefined;
serviceSubscription: azurecore.azureResource.AzureResourceSubscription | null;
serviceResourceGroup: azurecore.azureResource.AzureResourceResourceGroup | null;
serverAssessment: ServerAssessment | null;
skuRecommendation: SkuRecommendationSavedInfo | null;
}
@@ -201,6 +203,7 @@ export class MigrationStateModel implements Model, vscode.Disposable {
public _targetPassword!: string;
public _sourceTargetMapping: Map<string, TargetDatabaseInfo | undefined> = new Map();
public _sqlMigrationServiceSubscription!: azurecore.azureResource.AzureResourceSubscription;
public _sqlMigrationServiceResourceGroup!: azurecore.azureResource.AzureResourceResourceGroup;
public _sqlMigrationService!: SqlMigrationService | undefined;
public _sqlMigrationServices!: SqlMigrationService[];
@@ -342,6 +345,19 @@ export class MigrationStateModel implements Model, vscode.Disposable {
r.state === ValidateIrState.Succeeded)
}
public get migrationTargetServerName(): string {
switch (this._targetType) {
case MigrationTargetType.SQLMI:
return (this._targetServerInstance as azurecore.azureResource.AzureSqlManagedInstance)?.name;
case MigrationTargetType.SQLVM:
return (this._targetServerInstance as SqlVMServer)?.name;
case MigrationTargetType.SQLDB:
return (this._targetServerInstance as AzureSqlDatabaseServer)?.name;
default:
return '';
}
}
public get isBackupContainerNetworkShare(): boolean {
return this._databaseBackup?.networkContainerType === NetworkContainerType.NETWORK_SHARE;
}
@@ -927,10 +943,6 @@ export class MigrationStateModel implements Model, vscode.Disposable {
return this.extensionContext.extensionPath;
}
public getLocationDisplayName(location: string): Promise<string> {
return getLocationDisplayName(location);
}
public async getManagedDatabases(): Promise<string[]> {
return (
await getSqlManagedInstanceDatabases(this._azureAccount,
@@ -1107,7 +1119,7 @@ export class MigrationStateModel implements Model, vscode.Disposable {
requestBody.properties.sourceDatabaseName = this._databasesForMigration[i];
const response = await startDatabaseMigration(
this._azureAccount,
this._targetSubscription,
this._sqlMigrationServiceSubscription,
this._sqlMigrationService?.location!,
this._targetServerInstance,
this._targetDatabaseNames[i],
@@ -1131,9 +1143,9 @@ export class MigrationStateModel implements Model, vscode.Disposable {
{
'sessionId': this._sessionId,
'tenantId': this._azureAccount.properties.tenants[0].id,
'subscriptionId': this._targetSubscription?.id,
'resourceGroup': this._resourceGroup?.name,
'location': this._targetServerInstance.location,
'subscriptionId': this._sqlMigrationServiceSubscription?.id,
'resourceGroup': this._sqlMigrationServiceResourceGroup?.name,
'location': this._location.name,
'targetType': this._targetType,
'hashedServerName': hashString(this._assessmentApiResponse?.assessmentResult?.name),
'hashedDatabaseName': hashString(this._databasesForMigration[i]),
@@ -1197,12 +1209,16 @@ export class MigrationStateModel implements Model, vscode.Disposable {
sqlMigrationService: undefined,
serverAssessment: null,
skuRecommendation: null,
serviceResourceGroup: null,
serviceSubscription: null,
};
switch (currentPage) {
case Page.Summary:
case Page.IntegrationRuntime:
saveInfo.sqlMigrationService = this._sqlMigrationService;
saveInfo.serviceSubscription = this._sqlMigrationServiceSubscription;
saveInfo.serviceResourceGroup = this._sqlMigrationServiceResourceGroup;
saveInfo.migrationMode = this._databaseBackup.migrationMode;
saveInfo.networkContainerType = this._databaseBackup.networkContainerType;
@@ -1282,6 +1298,8 @@ export class MigrationStateModel implements Model, vscode.Disposable {
this._databaseBackup.subscription = this.savedInfo.subscription || undefined!;
this._sqlMigrationService = this.savedInfo.sqlMigrationService;
this._sqlMigrationServiceSubscription = this.savedInfo.serviceSubscription || undefined!;
this._sqlMigrationServiceResourceGroup = this.savedInfo.serviceResourceGroup || undefined!;
const savedAssessmentResults = this.savedInfo.serverAssessment;
if (savedAssessmentResults) {