mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-15 18:46:36 -05:00
* changing the cutover icon on migration cutover page. * Fixing monitoring table and pending log backups * converting file upload times in utc to local time zones * adding autorefresh to dashboard, migration status and cutover dialogs. * Supporting blob container e2e * vbump extension * Fixing some PR comments * Fixed broken blob container dropdown onChange event * Localizing display string in refresh dialog Fixing some localized strings * Fixing var declaration * making a class readonly for 250px width * removing refresh interval dialog and replacing it with hardcoded values. * Fixing summary page IR information. * surfacing test connection error * Clearing intervals on view closed to remove auto refresh.
104 lines
4.0 KiB
TypeScript
104 lines
4.0 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
import * as vscode from 'vscode';
|
|
import { azureResource } from 'azureResource';
|
|
import { DatabaseMigration, SqlMigrationService, SqlManagedInstance, getMigrationStatus, AzureAsyncOperationResource, getMigrationAsyncOperationDetails, SqlVMServer } from '../api/azure';
|
|
import * as azdata from 'azdata';
|
|
|
|
export class MigrationLocalStorage {
|
|
private static context: vscode.ExtensionContext;
|
|
private static mementoToken: string = 'sqlmigration.databaseMigrations';
|
|
|
|
public static setExtensionContext(context: vscode.ExtensionContext): void {
|
|
MigrationLocalStorage.context = context;
|
|
}
|
|
|
|
public static async getMigrationsBySourceConnections(connectionProfile: azdata.connection.ConnectionProfile, refreshStatus?: boolean): Promise<MigrationContext[]> {
|
|
|
|
const result: MigrationContext[] = [];
|
|
const validMigrations: MigrationContext[] = [];
|
|
|
|
const migrationMementos: MigrationContext[] = this.context.globalState.get(this.mementoToken) || [];
|
|
for (let i = 0; i < migrationMementos.length; i++) {
|
|
const migration = migrationMementos[i];
|
|
if (migration.sourceConnectionProfile.serverName === connectionProfile.serverName) {
|
|
if (refreshStatus) {
|
|
try {
|
|
const backupConfiguration = migration.migrationContext.properties.backupConfiguration;
|
|
const sourceDatabase = migration.migrationContext.properties.sourceDatabaseName;
|
|
migration.migrationContext = await getMigrationStatus(
|
|
migration.azureAccount,
|
|
migration.subscription,
|
|
migration.migrationContext
|
|
);
|
|
migration.migrationContext.properties.sourceDatabaseName = sourceDatabase;
|
|
migration.migrationContext.properties.backupConfiguration = backupConfiguration;
|
|
if (migration.asyncUrl) {
|
|
migration.asyncOperationResult = await getMigrationAsyncOperationDetails(
|
|
migration.azureAccount,
|
|
migration.subscription,
|
|
migration.asyncUrl
|
|
);
|
|
}
|
|
}
|
|
catch (e) {
|
|
// Keeping only valid migrations in cache. Clearing all the migrations which return ResourceDoesNotExit error.
|
|
if (e.message === 'ResourceDoesNotExist') {
|
|
continue;
|
|
} else {
|
|
console.log(e);
|
|
}
|
|
}
|
|
}
|
|
result.push(migration);
|
|
}
|
|
validMigrations.push(migration);
|
|
}
|
|
this.context.globalState.update(this.mementoToken, validMigrations);
|
|
return result;
|
|
}
|
|
|
|
public static saveMigration(
|
|
connectionProfile: azdata.connection.ConnectionProfile,
|
|
migrationContext: DatabaseMigration,
|
|
targetMI: SqlManagedInstance | SqlVMServer,
|
|
azureAccount: azdata.Account,
|
|
subscription: azureResource.AzureResourceSubscription,
|
|
controller: SqlMigrationService,
|
|
asyncURL: string): void {
|
|
try {
|
|
let migrationMementos: MigrationContext[] = this.context.globalState.get(this.mementoToken) || [];
|
|
migrationMementos = migrationMementos.filter(m => m.migrationContext.id !== migrationContext.id);
|
|
migrationMementos.push({
|
|
sourceConnectionProfile: connectionProfile,
|
|
migrationContext: migrationContext,
|
|
targetManagedInstance: targetMI,
|
|
subscription: subscription,
|
|
azureAccount: azureAccount,
|
|
controller: controller,
|
|
asyncUrl: asyncURL
|
|
});
|
|
this.context.globalState.update(this.mementoToken, migrationMementos);
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
}
|
|
|
|
public static clearMigrations() {
|
|
this.context.globalState.update(this.mementoToken, ([] as MigrationContext[]));
|
|
}
|
|
}
|
|
|
|
export interface MigrationContext {
|
|
sourceConnectionProfile: azdata.connection.ConnectionProfile,
|
|
migrationContext: DatabaseMigration,
|
|
targetManagedInstance: SqlManagedInstance | SqlVMServer,
|
|
azureAccount: azdata.Account,
|
|
subscription: azureResource.AzureResourceSubscription,
|
|
controller: SqlMigrationService,
|
|
asyncUrl: string,
|
|
asyncOperationResult?: AzureAsyncOperationResource
|
|
}
|