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

@@ -81,7 +81,18 @@ export class DatabaseSelectorPage extends MigrationWizardPage {
});
}
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) => {
return true;
});

View File

@@ -62,7 +62,6 @@ export class SKURecommendationPage extends MigrationWizardPage {
}
];
constructor(wizard: azdata.window.Wizard, migrationStateModel: MigrationStateModel) {
super(wizard, azdata.window.createWizardPage(constants.SKU_RECOMMENDATION_PAGE_TITLE), migrationStateModel);
}
@@ -287,7 +286,6 @@ export class SKURecommendationPage extends MigrationWizardPage {
}
}).component();
const managedInstanceSubscriptionDropdownLabel = this._view.modelBuilder.text().withProps({
value: constants.SUBSCRIPTION,
width: WIZARD_INPUT_COMPONENT_WIDTH,
@@ -407,18 +405,27 @@ export class SKURecommendationPage extends MigrationWizardPage {
}
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) {
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._azureSubscriptionText.value = constants.SELECT_AZURE_MI;
this.migrationStateModel._migrationDbs = this.migrationStateModel._miDbs;
this.migrationStateModel._migrationDbs = miDbs;
} else {
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._azureSubscriptionText.value = constants.SELECT_AZURE_VM;
this.migrationStateModel._migrationDbs = this.migrationStateModel._vmDbs;
this.migrationStateModel._migrationDbs = vmDbs;
}
this.migrationStateModel.refreshDatabaseBackupPage = true;
this._targetContainer.display = (this.migrationStateModel._migrationDbs.length === 0) ? 'none' : 'inline';
@@ -426,18 +433,38 @@ export class SKURecommendationPage extends MigrationWizardPage {
}
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;
const serverName = (await this.migrationStateModel.getSourceConnectionProfile()).serverName;
this._igComponent.value = constants.ASSESSMENT_COMPLETED(serverName);
try {
await this.migrationStateModel.getDatabaseAssessments();
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) {
console.log(e);
}
this.refreshCardText();
this._assessmentLoader.loading = false;
this._assessmentComponent.updateCssStyles({ display: 'none' });
this._formContainer.component().updateCssStyles({ display: 'block' });
}
private async populateSubscriptionDropdown(): Promise<void> {
@@ -475,13 +502,20 @@ export class SKURecommendationPage extends MigrationWizardPage {
private async populateResourceInstanceDropdown(): Promise<void> {
try {
this._resourceDropdown.loading = true;
if (this._rbg.selectedCardId === MigrationTargetType.SQLVM) {
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 {
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);
@@ -492,7 +526,6 @@ export class SKURecommendationPage extends MigrationWizardPage {
}
}
public async onPageEnter(pageChangeInfo: azdata.window.WizardPageChangeInfo): Promise<void> {
this.wizard.registerNavigationValidator((pageChangeInfo) => {
const errors: string[] = [];
@@ -538,7 +571,7 @@ export class SKURecommendationPage extends MigrationWizardPage {
return true;
});
this.wizard.nextButton.enabled = false;
if (!this.migrationStateModel._assessmentResults) {
if (this.migrationStateModel._runAssessments) {
await this.constructDetails();
}
this._assessmentComponent.updateCssStyles({
@@ -567,16 +600,16 @@ export class SKURecommendationPage extends MigrationWizardPage {
}
public refreshDatabaseCount(selectedDbs: string[]): void {
this.wizard.message = {
text: '',
level: azdata.window.MessageLevel.Error
};
this.migrationStateModel._migrationDbs = selectedDbs;
this.refreshCardText();
}
public refreshCardText(): void {
this._rbgLoader.loading = true;
this.wizard.message = {
text: '',
level: azdata.window.MessageLevel.Error
};
if (this._rbg.selectedCardId === MigrationTargetType.SQLMI) {
this.migrationStateModel._migrationDbs = this.migrationStateModel._miDbs;
} else {
@@ -586,7 +619,6 @@ export class SKURecommendationPage extends MigrationWizardPage {
this._azureResourceGroupDropdown.display = (!this._rbg.selectedCardId) ? 'none' : 'inline';
this._targetContainer.display = (this.migrationStateModel._migrationDbs.length === 0) ? 'none' : 'inline';
if (this.migrationStateModel._assessmentResults) {
const dbCount = this.migrationStateModel._assessmentResults.databaseAssessments.length;
@@ -608,6 +640,11 @@ export class SKURecommendationPage extends MigrationWizardPage {
cards: this._rbg.cards
});
}
if (this._rbg.selectedCardId) {
this.changeTargetType(this._rbg.selectedCardId);
}
this._rbgLoader.loading = false;
}