fix assessment db selection (#16591)

This commit is contained in:
brian-harris
2021-08-06 11:27:24 -07:00
committed by GitHub
parent 3a4caa64d2
commit 013ce71166
4 changed files with 111 additions and 42 deletions

View File

@@ -35,6 +35,9 @@ export const SKU_RECOMMENDATION_PAGE_TITLE = localize('sql.migration.wizard.sku.
export const SKU_RECOMMENDATION_ALL_SUCCESSFUL = (databaseCount: number): string => { export const SKU_RECOMMENDATION_ALL_SUCCESSFUL = (databaseCount: number): string => {
return localize('sql.migration.wizard.sku.all', "Based on the assessment results, all {0} of your database(s) in online state can be migrated to Azure SQL.", databaseCount); return localize('sql.migration.wizard.sku.all', "Based on the assessment results, all {0} of your database(s) in online state can be migrated to Azure SQL.", databaseCount);
}; };
export const SKU_RECOMMENDATION_ASSESSMENT_ERROR = (serverName: string): string => {
return localize('sql.migration.qizard.sku.assessment.error', "An error occurred while assessing the server '{0}'.", serverName);
};
export const SKU_RECOMMENDATION_SOME_SUCCESSFUL = (migratableCount: number, databaseCount: number): string => { export const SKU_RECOMMENDATION_SOME_SUCCESSFUL = (migratableCount: number, databaseCount: number): string => {
return localize('sql.migration.wizard.sku.some', "Based on the results of our source configuration scans, {0} out of {1} of your databases can be migrated to Azure SQL.", migratableCount, databaseCount); return localize('sql.migration.wizard.sku.some', "Based on the results of our source configuration scans, {0} out of {1} of your databases can be migrated to Azure SQL.", migratableCount, databaseCount);
}; };

View File

@@ -138,6 +138,7 @@ export class MigrationStateModel implements Model, vscode.Disposable {
private _skuRecommendations: SKURecommendations | undefined; private _skuRecommendations: SKURecommendations | undefined;
public _assessmentResults!: ServerAssessement; public _assessmentResults!: ServerAssessement;
public _runAssessments: boolean = true;
private _assessmentApiResponse!: mssql.AssessmentResult; private _assessmentApiResponse!: mssql.AssessmentResult;
public _vmDbs: string[] = []; public _vmDbs: string[] = [];
@@ -186,16 +187,27 @@ export class MigrationStateModel implements Model, vscode.Disposable {
public async getDatabaseAssessments(): Promise<ServerAssessement> { public async getDatabaseAssessments(): Promise<ServerAssessement> {
const ownerUri = await azdata.connection.getUriForConnection(this.sourceConnectionId); const ownerUri = await azdata.connection.getUriForConnection(this.sourceConnectionId);
this._assessmentApiResponse = (await this.migrationService.getAssessments(ownerUri, this._databaseAssessment))!; try {
this._assessmentResults = { this._assessmentApiResponse = (await this.migrationService.getAssessments(ownerUri, this._databaseAssessment))!;
issues: this._assessmentApiResponse.assessmentResult.items, this._assessmentResults = {
databaseAssessments: this._assessmentApiResponse.assessmentResult.databases.map(d => { issues: this._assessmentApiResponse.assessmentResult.items,
return { databaseAssessments: this._assessmentApiResponse.assessmentResult.databases.map(d => {
name: d.name, return {
issues: d.items name: d.name,
}; issues: d.items,
}) errors: d.errors
}; };
}),
errors: this._assessmentApiResponse.errors
};
} catch (error) {
this._assessmentResults = {
issues: [],
databaseAssessments: [],
errors: [],
assessmentError: error
};
}
// Generating all the telemetry asynchronously as we don't need to block the user for it. // Generating all the telemetry asynchronously as we don't need to block the user for it.
this.generateAssessmentTelemetry().catch(e => console.error(e)); this.generateAssessmentTelemetry().catch(e => console.error(e));
@@ -528,7 +540,6 @@ export class MigrationStateModel implements Model, vscode.Disposable {
return this._resourceGroups[index]; return this._resourceGroups[index];
} }
public async getManagedInstanceValues(subscription: azureResource.AzureResourceSubscription, location: azureResource.AzureLocation, resourceGroup: azureResource.AzureResourceResourceGroup): Promise<azdata.CategoryValue[]> { public async getManagedInstanceValues(subscription: azureResource.AzureResourceSubscription, location: azureResource.AzureLocation, resourceGroup: azureResource.AzureResourceResourceGroup): Promise<azdata.CategoryValue[]> {
let managedInstanceValues: azdata.CategoryValue[] = []; let managedInstanceValues: azdata.CategoryValue[] = [];
if (!this._azureAccount) { if (!this._azureAccount) {
@@ -536,7 +547,7 @@ export class MigrationStateModel implements Model, vscode.Disposable {
} }
try { try {
this._targetManagedInstances = (await getAvailableManagedInstanceProducts(this._azureAccount, subscription)).filter((mi) => { this._targetManagedInstances = (await getAvailableManagedInstanceProducts(this._azureAccount, subscription)).filter((mi) => {
if (mi.location.toLowerCase() === location.name.toLowerCase() && mi.resourceGroup?.toLowerCase() === resourceGroup.name.toLowerCase()) { if (mi.location.toLowerCase() === location.name.toLowerCase() && mi.resourceGroup?.toLowerCase() === resourceGroup?.name.toLowerCase()) {
return true; return true;
} }
return false; return false;
@@ -581,21 +592,25 @@ export class MigrationStateModel implements Model, vscode.Disposable {
public async getSqlVirtualMachineValues(subscription: azureResource.AzureResourceSubscription, location: azureResource.AzureLocation, resourceGroup: azureResource.AzureResourceResourceGroup): Promise<azdata.CategoryValue[]> { public async getSqlVirtualMachineValues(subscription: azureResource.AzureResourceSubscription, location: azureResource.AzureLocation, resourceGroup: azureResource.AzureResourceResourceGroup): Promise<azdata.CategoryValue[]> {
let virtualMachineValues: azdata.CategoryValue[] = []; let virtualMachineValues: azdata.CategoryValue[] = [];
try { try {
this._targetSqlVirtualMachines = (await getAvailableSqlVMs(this._azureAccount, subscription, resourceGroup)).filter((virtualMachine) => { if (this._azureAccount && subscription && resourceGroup) {
if (virtualMachine.location === location.name) { this._targetSqlVirtualMachines = (await getAvailableSqlVMs(this._azureAccount, subscription, resourceGroup)).filter((virtualMachine) => {
if (virtualMachine.properties.sqlImageOffer) { if (virtualMachine.location === location.name) {
return virtualMachine.properties.sqlImageOffer.toLowerCase().includes('-ws'); //filtering out all non windows sql vms. if (virtualMachine.properties.sqlImageOffer) {
return virtualMachine.properties.sqlImageOffer.toLowerCase().includes('-ws'); //filtering out all non windows sql vms.
}
return true; // Returning all VMs that don't have this property as we don't want to accidentally skip valid vms.
} }
return true; // Returning all VMs that don't have this property as we don't want to accidentally skip valid vms. return false;
} });
return false; virtualMachineValues = this._targetSqlVirtualMachines.map((virtualMachine) => {
}); return {
virtualMachineValues = this._targetSqlVirtualMachines.map((virtualMachine) => { name: virtualMachine.id,
return { displayName: `${virtualMachine.name}`
name: virtualMachine.id, };
displayName: `${virtualMachine.name}` });
}; } else {
}); this._targetSqlVirtualMachines = [];
}
if (virtualMachineValues.length === 0) { if (virtualMachineValues.length === 0) {
virtualMachineValues = [ virtualMachineValues = [
@@ -944,5 +959,8 @@ export interface ServerAssessement {
databaseAssessments: { databaseAssessments: {
name: string; name: string;
issues: mssql.SqlMigrationAssessmentResultItem[]; issues: mssql.SqlMigrationAssessmentResultItem[];
errors?: mssql.ErrorModel[];
}[]; }[];
errors?: mssql.ErrorModel[];
assessmentError?: Error;
} }

View File

@@ -81,7 +81,18 @@ export class DatabaseSelectorPage extends MigrationWizardPage {
}); });
} }
public async onPageLeave(): Promise<void> { public async onPageLeave(): Promise<void> {
this.migrationStateModel._databaseAssessment = this.selectedDbs(); const assessedDatabases = this.migrationStateModel._databaseAssessment ?? [];
const selectedDatabases = this.selectedDbs();
// run assessment if
// * the prior assessment had an error or
// * the assessed databases list is different from the selected databases list
this.migrationStateModel._runAssessments = !!this.migrationStateModel._assessmentResults?.assessmentError
|| assessedDatabases.length === 0
|| assessedDatabases.length !== selectedDatabases.length
|| assessedDatabases.some(db => selectedDatabases.indexOf(db) < 0);
this.migrationStateModel._databaseAssessment = selectedDatabases;
this.wizard.registerNavigationValidator((pageChangeInfo) => { this.wizard.registerNavigationValidator((pageChangeInfo) => {
return true; return true;
}); });

View File

@@ -62,7 +62,6 @@ export class SKURecommendationPage extends MigrationWizardPage {
} }
]; ];
constructor(wizard: azdata.window.Wizard, migrationStateModel: MigrationStateModel) { constructor(wizard: azdata.window.Wizard, migrationStateModel: MigrationStateModel) {
super(wizard, azdata.window.createWizardPage(constants.SKU_RECOMMENDATION_PAGE_TITLE), migrationStateModel); super(wizard, azdata.window.createWizardPage(constants.SKU_RECOMMENDATION_PAGE_TITLE), migrationStateModel);
} }
@@ -287,7 +286,6 @@ export class SKURecommendationPage extends MigrationWizardPage {
} }
}).component(); }).component();
const managedInstanceSubscriptionDropdownLabel = this._view.modelBuilder.text().withProps({ const managedInstanceSubscriptionDropdownLabel = this._view.modelBuilder.text().withProps({
value: constants.SUBSCRIPTION, value: constants.SUBSCRIPTION,
width: WIZARD_INPUT_COMPONENT_WIDTH, width: WIZARD_INPUT_COMPONENT_WIDTH,
@@ -407,18 +405,27 @@ export class SKURecommendationPage extends MigrationWizardPage {
} }
private changeTargetType(newTargetType: string) { private changeTargetType(newTargetType: string) {
// remove assessed databases that have been removed from the source selection list
const miDbs = this.migrationStateModel._miDbs.filter(
db => this.migrationStateModel._databaseAssessment.findIndex(
dba => dba === db) >= 0);
const vmDbs = this.migrationStateModel._vmDbs.filter(
db => this.migrationStateModel._databaseAssessment.findIndex(
dba => dba === db) >= 0);
if (newTargetType === MigrationTargetType.SQLMI) { if (newTargetType === MigrationTargetType.SQLMI) {
this._viewAssessmentsHelperText.value = constants.SKU_RECOMMENDATION_VIEW_ASSESSMENT_MI; this._viewAssessmentsHelperText.value = constants.SKU_RECOMMENDATION_VIEW_ASSESSMENT_MI;
this._databaseSelectedHelperText.value = constants.TOTAL_DATABASES_SELECTED(this.migrationStateModel._miDbs.length, this.migrationStateModel._databaseAssessment.length); this._databaseSelectedHelperText.value = constants.TOTAL_DATABASES_SELECTED(miDbs.length, this.migrationStateModel._databaseAssessment.length);
this.migrationStateModel._targetType = MigrationTargetType.SQLMI; this.migrationStateModel._targetType = MigrationTargetType.SQLMI;
this._azureSubscriptionText.value = constants.SELECT_AZURE_MI; this._azureSubscriptionText.value = constants.SELECT_AZURE_MI;
this.migrationStateModel._migrationDbs = this.migrationStateModel._miDbs; this.migrationStateModel._migrationDbs = miDbs;
} else { } else {
this._viewAssessmentsHelperText.value = constants.SKU_RECOMMENDATION_VIEW_ASSESSMENT_VM; this._viewAssessmentsHelperText.value = constants.SKU_RECOMMENDATION_VIEW_ASSESSMENT_VM;
this._databaseSelectedHelperText.value = constants.TOTAL_DATABASES_SELECTED(this.migrationStateModel._vmDbs.length, this.migrationStateModel._databaseAssessment.length); this._databaseSelectedHelperText.value = constants.TOTAL_DATABASES_SELECTED(vmDbs.length, this.migrationStateModel._databaseAssessment.length);
this.migrationStateModel._targetType = MigrationTargetType.SQLVM; this.migrationStateModel._targetType = MigrationTargetType.SQLVM;
this._azureSubscriptionText.value = constants.SELECT_AZURE_VM; this._azureSubscriptionText.value = constants.SELECT_AZURE_VM;
this.migrationStateModel._migrationDbs = this.migrationStateModel._vmDbs; this.migrationStateModel._migrationDbs = vmDbs;
} }
this.migrationStateModel.refreshDatabaseBackupPage = true; this.migrationStateModel.refreshDatabaseBackupPage = true;
this._targetContainer.display = (this.migrationStateModel._migrationDbs.length === 0) ? 'none' : 'inline'; this._targetContainer.display = (this.migrationStateModel._migrationDbs.length === 0) ? 'none' : 'inline';
@@ -426,18 +433,38 @@ export class SKURecommendationPage extends MigrationWizardPage {
} }
private async constructDetails(): Promise<void> { private async constructDetails(): Promise<void> {
this.wizard.message = {
text: '',
level: azdata.window.MessageLevel.Error
};
this._assessmentComponent.updateCssStyles({ display: 'block' });
this._formContainer.component().updateCssStyles({ display: 'none' });
this._assessmentLoader.loading = true; this._assessmentLoader.loading = true;
const serverName = (await this.migrationStateModel.getSourceConnectionProfile()).serverName; const serverName = (await this.migrationStateModel.getSourceConnectionProfile()).serverName;
this._igComponent.value = constants.ASSESSMENT_COMPLETED(serverName); this._igComponent.value = constants.ASSESSMENT_COMPLETED(serverName);
try { try {
await this.migrationStateModel.getDatabaseAssessments(); await this.migrationStateModel.getDatabaseAssessments();
this._detailsComponent.value = constants.SKU_RECOMMENDATION_ALL_SUCCESSFUL(this.migrationStateModel._assessmentResults.databaseAssessments.length); this._detailsComponent.value = constants.SKU_RECOMMENDATION_ALL_SUCCESSFUL(this.migrationStateModel._assessmentResults.databaseAssessments.length);
const error = this.migrationStateModel._assessmentResults.assessmentError;
if (error) {
this.wizard.message = {
text: constants.SKU_RECOMMENDATION_ASSESSMENT_ERROR(serverName),
description: error.message + EOL + error.stack,
level: azdata.window.MessageLevel.Error
};
}
this.migrationStateModel._runAssessments = !!error;
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
this.refreshCardText(); this.refreshCardText();
this._assessmentLoader.loading = false; this._assessmentLoader.loading = false;
this._assessmentComponent.updateCssStyles({ display: 'none' });
this._formContainer.component().updateCssStyles({ display: 'block' });
} }
private async populateSubscriptionDropdown(): Promise<void> { private async populateSubscriptionDropdown(): Promise<void> {
@@ -475,13 +502,20 @@ export class SKURecommendationPage extends MigrationWizardPage {
private async populateResourceInstanceDropdown(): Promise<void> { private async populateResourceInstanceDropdown(): Promise<void> {
try { try {
this._resourceDropdown.loading = true; this._resourceDropdown.loading = true;
if (this._rbg.selectedCardId === MigrationTargetType.SQLVM) { if (this._rbg.selectedCardId === MigrationTargetType.SQLVM) {
this._resourceDropdownLabel.value = constants.AZURE_SQL_DATABASE_VIRTUAL_MACHINE; this._resourceDropdownLabel.value = constants.AZURE_SQL_DATABASE_VIRTUAL_MACHINE;
this._resourceDropdown.values = await this.migrationStateModel.getSqlVirtualMachineValues(this.migrationStateModel._targetSubscription, this.migrationStateModel._location, this.migrationStateModel._resourceGroup); this._resourceDropdown.values = await this.migrationStateModel.getSqlVirtualMachineValues(
this.migrationStateModel._targetSubscription,
this.migrationStateModel._location,
this.migrationStateModel._resourceGroup);
} else { } else {
this._resourceDropdownLabel.value = constants.AZURE_SQL_DATABASE_MANAGED_INSTANCE; this._resourceDropdownLabel.value = constants.AZURE_SQL_DATABASE_MANAGED_INSTANCE;
this._resourceDropdown.values = await this.migrationStateModel.getManagedInstanceValues(this.migrationStateModel._targetSubscription, this.migrationStateModel._location, this.migrationStateModel._resourceGroup); this._resourceDropdown.values = await this.migrationStateModel.getManagedInstanceValues(
this.migrationStateModel._targetSubscription,
this.migrationStateModel._location,
this.migrationStateModel._resourceGroup);
} }
selectDropDownIndex(this._resourceDropdown, 0); selectDropDownIndex(this._resourceDropdown, 0);
@@ -492,7 +526,6 @@ export class SKURecommendationPage extends MigrationWizardPage {
} }
} }
public async onPageEnter(pageChangeInfo: azdata.window.WizardPageChangeInfo): Promise<void> { public async onPageEnter(pageChangeInfo: azdata.window.WizardPageChangeInfo): Promise<void> {
this.wizard.registerNavigationValidator((pageChangeInfo) => { this.wizard.registerNavigationValidator((pageChangeInfo) => {
const errors: string[] = []; const errors: string[] = [];
@@ -538,7 +571,7 @@ export class SKURecommendationPage extends MigrationWizardPage {
return true; return true;
}); });
this.wizard.nextButton.enabled = false; this.wizard.nextButton.enabled = false;
if (!this.migrationStateModel._assessmentResults) { if (this.migrationStateModel._runAssessments) {
await this.constructDetails(); await this.constructDetails();
} }
this._assessmentComponent.updateCssStyles({ this._assessmentComponent.updateCssStyles({
@@ -567,16 +600,16 @@ export class SKURecommendationPage extends MigrationWizardPage {
} }
public refreshDatabaseCount(selectedDbs: string[]): void { public refreshDatabaseCount(selectedDbs: string[]): void {
this.wizard.message = {
text: '',
level: azdata.window.MessageLevel.Error
};
this.migrationStateModel._migrationDbs = selectedDbs; this.migrationStateModel._migrationDbs = selectedDbs;
this.refreshCardText(); this.refreshCardText();
} }
public refreshCardText(): void { public refreshCardText(): void {
this._rbgLoader.loading = true; this._rbgLoader.loading = true;
this.wizard.message = {
text: '',
level: azdata.window.MessageLevel.Error
};
if (this._rbg.selectedCardId === MigrationTargetType.SQLMI) { if (this._rbg.selectedCardId === MigrationTargetType.SQLMI) {
this.migrationStateModel._migrationDbs = this.migrationStateModel._miDbs; this.migrationStateModel._migrationDbs = this.migrationStateModel._miDbs;
} else { } else {
@@ -586,7 +619,6 @@ export class SKURecommendationPage extends MigrationWizardPage {
this._azureResourceGroupDropdown.display = (!this._rbg.selectedCardId) ? 'none' : 'inline'; this._azureResourceGroupDropdown.display = (!this._rbg.selectedCardId) ? 'none' : 'inline';
this._targetContainer.display = (this.migrationStateModel._migrationDbs.length === 0) ? 'none' : 'inline'; this._targetContainer.display = (this.migrationStateModel._migrationDbs.length === 0) ? 'none' : 'inline';
if (this.migrationStateModel._assessmentResults) { if (this.migrationStateModel._assessmentResults) {
const dbCount = this.migrationStateModel._assessmentResults.databaseAssessments.length; const dbCount = this.migrationStateModel._assessmentResults.databaseAssessments.length;
@@ -608,6 +640,11 @@ export class SKURecommendationPage extends MigrationWizardPage {
cards: this._rbg.cards cards: this._rbg.cards
}); });
} }
if (this._rbg.selectedCardId) {
this.changeTargetType(this._rbg.selectedCardId);
}
this._rbgLoader.loading = false; this._rbgLoader.loading = false;
} }