Migrating other deployment wizards to the generic ResourceTypeWizard (#13132)

* SQL VM wizard migration to ResourceType Wizard

* Revert "SQL VM wizard migration to ResourceType Wizard"

This reverts commit e58cd47707a7e2812be20d915f1fe638b96b035f.

* migrated notebook wizard

* SQL VM wizard migration to ResourceType Wizard

* Fixed some imports on SQL VM wizard

* migrated sqldb wizard to generic ResourceTypeWizard

* Added missing import
Solving errors from the merge

* Moved some common functionality into ResourceTypeWizard

* Changed logic of start deployment

* fixed some import after changing files.
This commit is contained in:
Aasim Khan
2020-10-30 12:42:20 -07:00
committed by GitHub
parent 76625012dd
commit 4f96ac46be
28 changed files with 743 additions and 776 deletions

View File

@@ -11,10 +11,7 @@ import * as path from 'path';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import { DeploymentProvider, instanceOfAzureSQLVMDeploymentProvider, instanceOfAzureSQLDBDeploymentProvider, instanceOfCommandDeploymentProvider, instanceOfDialogDeploymentProvider, instanceOfDownloadDeploymentProvider, instanceOfNotebookBasedDialogInfo, instanceOfNotebookDeploymentProvider, instanceOfNotebookWizardDeploymentProvider, instanceOfWebPageDeploymentProvider, instanceOfWizardDeploymentProvider, NotebookInfo, NotebookPathInfo, ResourceType, ResourceTypeOption } from '../interfaces'; import { DeploymentProvider, instanceOfAzureSQLVMDeploymentProvider, instanceOfAzureSQLDBDeploymentProvider, instanceOfCommandDeploymentProvider, instanceOfDialogDeploymentProvider, instanceOfDownloadDeploymentProvider, instanceOfNotebookBasedDialogInfo, instanceOfNotebookDeploymentProvider, instanceOfNotebookWizardDeploymentProvider, instanceOfWebPageDeploymentProvider, instanceOfWizardDeploymentProvider, NotebookInfo, NotebookPathInfo, ResourceType, ResourceTypeOption } from '../interfaces';
import { DeployAzureSQLVMWizard } from '../ui/deployAzureSQLVMWizard/deployAzureSQLVMWizard';
import { DeployAzureSQLDBWizard } from '../ui/deployAzureSQLDBWizard/deployAzureSQLDBWizard';
import { DeploymentInputDialog } from '../ui/deploymentInputDialog'; import { DeploymentInputDialog } from '../ui/deploymentInputDialog';
import { NotebookWizard } from '../ui/notebookWizard/notebookWizard';
import { AzdataService } from './azdataService'; import { AzdataService } from './azdataService';
import { KubeService } from './kubeService'; import { KubeService } from './kubeService';
import { INotebookService } from './notebookService'; import { INotebookService } from './notebookService';
@@ -253,13 +250,7 @@ export class ResourceTypeService implements IResourceTypeService {
public startDeployment(resourceType: ResourceType, provider: DeploymentProvider): void { public startDeployment(resourceType: ResourceType, provider: DeploymentProvider): void {
const self = this; const self = this;
if (instanceOfWizardDeploymentProvider(provider)) { if (instanceOfDialogDeploymentProvider(provider)) {
const wizard = new ResourceTypeWizard(resourceType, provider, new KubeService(), new AzdataService(this.platformService), this.notebookService, this.toolsService, this.platformService);
wizard.open();
} else if (instanceOfNotebookWizardDeploymentProvider(provider)) {
const wizard = new NotebookWizard(provider.notebookWizard, this.notebookService, this.platformService, this.toolsService);
wizard.open();
} else if (instanceOfDialogDeploymentProvider(provider)) {
const dialog = new DeploymentInputDialog(this.notebookService, this.platformService, this.toolsService, provider.dialog); const dialog = new DeploymentInputDialog(this.notebookService, this.platformService, this.toolsService, provider.dialog);
dialog.open(); dialog.open();
} else if (instanceOfNotebookDeploymentProvider(provider)) { } else if (instanceOfNotebookDeploymentProvider(provider)) {
@@ -286,11 +277,8 @@ export class ResourceTypeService implements IResourceTypeService {
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(provider.webPageUrl)); vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(provider.webPageUrl));
} else if (instanceOfCommandDeploymentProvider(provider)) { } else if (instanceOfCommandDeploymentProvider(provider)) {
vscode.commands.executeCommand(provider.command); vscode.commands.executeCommand(provider.command);
} else if (instanceOfAzureSQLVMDeploymentProvider(provider)) { } else {
const wizard = new DeployAzureSQLVMWizard(provider.azureSQLVMWizard, this.notebookService, this.toolsService); const wizard = new ResourceTypeWizard(resourceType, provider, new KubeService(), new AzdataService(this.platformService), this.notebookService, this.toolsService, this.platformService);
wizard.open();
} else if (instanceOfAzureSQLDBDeploymentProvider(provider)) {
const wizard = new DeployAzureSQLDBWizard(provider.azureSQLDBWizard, this.notebookService, this.toolsService);
wizard.open(); wizard.open();
} }
} }

View File

@@ -1,175 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import * as constants from './constants';
import { INotebookService } from '../../services/notebookService';
import { IToolsService } from '../../services/toolsService';
import { WizardBase } from '../wizardBase';
import { WizardPageBase } from '../wizardPageBase';
import { DeployAzureSQLDBWizardModel } from './deployAzureSQLDBWizardModel';
import { AzureSQLDBWizardInfo } from '../../interfaces';
import { AzureSettingsPage } from './pages/azureSettingsPage';
import { DatabaseSettingsPage } from './pages/databaseSettingsPage';
import axios, { AxiosRequestConfig } from 'axios';
import { AzureSQLDBSummaryPage } from './pages/summaryPage';
import { EOL } from 'os';
export class DeployAzureSQLDBWizard extends WizardBase<DeployAzureSQLDBWizard, WizardPageBase<DeployAzureSQLDBWizard>, DeployAzureSQLDBWizardModel> {
constructor(private wizardInfo: AzureSQLDBWizardInfo, private _notebookService: INotebookService, private _toolsService: IToolsService) {
super(
constants.WizardTitle,
'DeployAzureSqlDBWizard',
new DeployAzureSQLDBWizardModel(),
_toolsService
);
}
private cache: Map<string, any> = new Map();
protected initialize(): void {
this.setPages(this.getPages());
this.wizardObject.generateScriptButton.hidden = true;
this.wizardObject.doneButton.label = constants.WizardDoneButtonLabel;
}
public get notebookService(): INotebookService {
return this._notebookService;
}
public get toolService(): IToolsService {
return this._toolsService;
}
protected async onOk(): Promise<void> {
await this.scriptToNotebook();
}
protected onCancel(): void {
}
private getPages(): WizardPageBase<DeployAzureSQLDBWizard>[] {
const pages: WizardPageBase<DeployAzureSQLDBWizard>[] = [];
pages.push(new AzureSettingsPage(this));
pages.push(new DatabaseSettingsPage(this));
pages.push(new AzureSQLDBSummaryPage(this));
return pages;
}
private async scriptToNotebook(): Promise<void> {
const variableValueStatements = this.model.getCodeCellContentForNotebook();
const insertionPosition = 2; // Cell number 2 is the position where the python variable setting statements need to be inserted in this.wizardInfo.notebook.
try {
await this.notebookService.openNotebookWithEdits(this.wizardInfo.notebook, variableValueStatements, insertionPosition);
} catch (error) {
vscode.window.showErrorMessage(error);
}
}
public async getRequest(url: string, useCache = false): Promise<any> {
if (useCache) {
if (this.cache.has(url)) {
return this.cache.get(url);
}
}
let token = this.model.securityToken.token;
const config: AxiosRequestConfig = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
validateStatus: () => true // Never throw
};
const response = await axios.get(url, config);
if (response.status !== 200) {
let errorMessage: string[] = [];
errorMessage.push(response.status.toString());
errorMessage.push(response.statusText);
if (response.data && response.data.error) {
errorMessage.push(`${response.data.error.code} : ${response.data.error.message}`);
}
vscode.window.showErrorMessage(errorMessage.join(EOL));
}
if (useCache) {
this.cache.set(url, response);
}
return response;
}
public createFormRowComponent(view: azdata.ModelView, title: string, description: string, component: azdata.Component, required: boolean): azdata.FlexContainer {
component.updateProperties({
required: required,
width: '480px'
});
const labelText = view.modelBuilder.text()
.withProperties<azdata.TextComponentProperties>(
{
value: title,
width: '250px',
description: description,
requiredIndicator: required,
})
.component();
labelText.updateCssStyles({
'font-weight': '400',
'font-size': '13px',
});
const flexContainer = view.modelBuilder.flexContainer()
.withLayout(
{
flexFlow: 'row',
alignItems: 'center',
})
.withItems(
[labelText, component],
{
CSSStyles: { 'margin-right': '5px' }
})
.component();
return flexContainer;
}
public changeComponentDisplay(component: azdata.Component, display: ('none' | 'block')) {
component.updateProperties({
required: display === 'block'
});
component.updateCssStyles({
display: display
});
}
public changeRowDisplay(container: azdata.FlexContainer, display: ('none' | 'block')) {
container.items.map((component) => {
component.updateProperties({
required: (display === 'block'),
});
component.updateCssStyles({
display: display,
});
});
}
public addDropdownValues(component: azdata.DropDownComponent, values: azdata.CategoryValue[], width?: number) {
component.updateProperties({
values: values,
width: '480px'
});
}
public showErrorMessage(message: string) {
this.wizardObject.message = {
text: message,
level: azdata.window.MessageLevel.Error
};
}
}

View File

@@ -5,9 +5,22 @@
import { EOL } from 'os'; import { EOL } from 'os';
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import { Model } from '../model'; import * as vscode from 'vscode';
import * as constants from './constants';
import axios, { AxiosRequestConfig } from 'axios';
import { ResourceTypeModel } from '../resourceTypeModel';
import { INotebookService } from '../../services/notebookService';
import { IToolsService } from '../../services/toolsService';
import { AzureSQLDBDeploymentProvider } from '../../interfaces';
import { ResourceTypeWizard } from '../resourceTypeWizard';
import { ResourceTypePage } from '../resourceTypePage';
import { DatabaseSettingsPage } from './pages/databaseSettingsPage';
import { AzureSQLDBSummaryPage } from './pages/summaryPage';
import { AzureSettingsPage } from './pages/azureSettingsPage';
export class DeployAzureSQLDBWizardModel extends ResourceTypeModel {
private cache: Map<string, any> = new Map();
export class DeployAzureSQLDBWizardModel extends Model {
public azureAccount!: azdata.Account; public azureAccount!: azdata.Account;
public securityToken!: any; public securityToken!: any;
public azureSubscription!: string; public azureSubscription!: string;
@@ -29,9 +42,142 @@ export class DeployAzureSQLDBWizardModel extends Model {
public databaseCollation!: string; public databaseCollation!: string;
public newFirewallRule!: boolean; public newFirewallRule!: boolean;
public get notebookService(): INotebookService {
return this.wizard.notebookService;
}
constructor() { public get toolService(): IToolsService {
super(); return this.wizard.toolsService;
}
constructor(public sqldbProvider: AzureSQLDBDeploymentProvider, wizard: ResourceTypeWizard) {
super(sqldbProvider, wizard);
this.wizard.wizardObject.title = constants.WizardTitle;
}
initialize(): void {
this.wizard.setPages(this.getPages());
this.wizard.wizardObject.generateScriptButton.hidden = true;
this.wizard.wizardObject.doneButton.label = constants.WizardDoneButtonLabel;
}
async onOk(): Promise<void> {
await this.scriptToNotebook();
}
onCancel(): void {
}
private getPages(): ResourceTypePage[] {
const pages: ResourceTypePage[] = [];
pages.push(new AzureSettingsPage(this));
pages.push(new DatabaseSettingsPage(this));
pages.push(new AzureSQLDBSummaryPage(this));
return pages;
}
public async getRequest(url: string, useCache = false): Promise<any> {
if (useCache) {
if (this.cache.has(url)) {
return this.cache.get(url);
}
}
let token = this.securityToken.token;
const config: AxiosRequestConfig = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
validateStatus: () => true // Never throw
};
const response = await axios.get(url, config);
if (response.status !== 200) {
let errorMessage: string[] = [];
errorMessage.push(response.status.toString());
errorMessage.push(response.statusText);
if (response.data && response.data.error) {
errorMessage.push(`${response.data.error.code} : ${response.data.error.message}`);
}
vscode.window.showErrorMessage(errorMessage.join(EOL));
}
if (useCache) {
this.cache.set(url, response);
}
return response;
}
public createFormRowComponent(view: azdata.ModelView, title: string, description: string, component: azdata.Component, required: boolean): azdata.FlexContainer {
component.updateProperties({
required: required,
width: '480px'
});
const labelText = view.modelBuilder.text()
.withProperties<azdata.TextComponentProperties>(
{
value: title,
width: '250px',
description: description,
requiredIndicator: required,
})
.component();
labelText.updateCssStyles({
'font-weight': '400',
'font-size': '13px',
});
const flexContainer = view.modelBuilder.flexContainer()
.withLayout(
{
flexFlow: 'row',
alignItems: 'center',
})
.withItems(
[labelText, component],
{
CSSStyles: { 'margin-right': '5px' }
})
.component();
return flexContainer;
}
public changeComponentDisplay(component: azdata.Component, display: ('none' | 'block')) {
component.updateProperties({
required: display === 'block'
});
component.updateCssStyles({
display: display
});
}
public changeRowDisplay(container: azdata.FlexContainer, display: ('none' | 'block')) {
container.items.map((component) => {
component.updateProperties({
required: (display === 'block'),
});
component.updateCssStyles({
display: display,
});
});
}
public addDropdownValues(component: azdata.DropDownComponent, values: azdata.CategoryValue[], width?: number) {
component.updateProperties({
values: values,
width: '480px'
});
}
private async scriptToNotebook(): Promise<void> {
const variableValueStatements = this.getCodeCellContentForNotebook();
const insertionPosition = 2; // Cell number 2 is the position where the python variable setting statements need to be inserted in this.wizardInfo.notebook.
try {
await this.notebookService.openNotebookWithEdits(this.sqldbProvider.azureSQLDBWizard.notebook, variableValueStatements, insertionPosition);
} catch (error) {
vscode.window.showErrorMessage(error);
}
} }
public getCodeCellContentForNotebook(): string[] { public getCodeCellContentForNotebook(): string[] {

View File

@@ -6,12 +6,12 @@
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import { EOL } from 'os'; import { EOL } from 'os';
import * as constants from '../constants'; import * as constants from '../constants';
import { DeployAzureSQLDBWizard } from '../deployAzureSQLDBWizard';
import { apiService } from '../../../services/apiService'; import { apiService } from '../../../services/apiService';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { BasePage } from './basePage'; import { BasePage } from './basePage';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import { DeployAzureSQLDBWizardModel } from '../deployAzureSQLDBWizardModel';
import * as localizedConstants from '../../../localizedConstants'; import * as localizedConstants from '../../../localizedConstants';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -59,11 +59,11 @@ export class AzureSettingsPage extends BasePage {
private _accountsMap!: Map<string, azdata.Account>; private _accountsMap!: Map<string, azdata.Account>;
private _subscriptionsMap!: Map<string, azureResource.AzureResourceSubscription>; private _subscriptionsMap!: Map<string, azureResource.AzureResourceSubscription>;
constructor(wizard: DeployAzureSQLDBWizard) { constructor(private _model: DeployAzureSQLDBWizardModel) {
super( super(
constants.AzureSettingsPageTitle, constants.AzureSettingsPageTitle,
'', '',
wizard _model.wizard
); );
this._accountsMap = new Map(); this._accountsMap = new Map();
this._subscriptionsMap = new Map(); this._subscriptionsMap = new Map();
@@ -91,19 +91,19 @@ export class AzureSettingsPage extends BasePage {
.withFormItems( .withFormItems(
[ [
{ {
component: this.wizard.createFormRowComponent(view, constants.AzureAccountDropdownLabel, '', this._azureAccountsDropdown, true) component: this._model.createFormRowComponent(view, constants.AzureAccountDropdownLabel, '', this._azureAccountsDropdown, true)
}, },
{ {
component: this.buttonFlexContainer component: this.buttonFlexContainer
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.AzureAccountSubscriptionDropdownLabel, '', this._azureSubscriptionsDropdown, true) component: this._model.createFormRowComponent(view, constants.AzureAccountSubscriptionDropdownLabel, '', this._azureSubscriptionsDropdown, true)
}, },
// { //@todo alma1 9/9/2020 Used for upcoming server creation feature. // { //@todo alma1 9/9/2020 Used for upcoming server creation feature.
// component: this.wizard.createFormRowComponent(view, constants.AzureAccountResourceGroupDropdownLabel, '', this._resourceGroupDropdown, true) // component: this.wizard.createFormRowComponent(view, constants.AzureAccountResourceGroupDropdownLabel, '', this._resourceGroupDropdown, true)
// }, // },
{ {
component: this.wizard.createFormRowComponent(view, constants.AzureAccountDatabaseServersDropdownLabel, '', this._serverGroupDropdown, true) component: this._model.createFormRowComponent(view, constants.AzureAccountDatabaseServersDropdownLabel, '', this._serverGroupDropdown, true)
}, },
// { //@todo alma1 9/8/2020 Used for upcoming server creation feature. // { //@todo alma1 9/8/2020 Used for upcoming server creation feature.
// component: this.wizard.createFormRowComponent(view, constants.AzureAccountRegionDropdownLabel, '', this._azureRegionsDropdown, true) // component: this.wizard.createFormRowComponent(view, constants.AzureAccountRegionDropdownLabel, '', this._azureRegionsDropdown, true)
@@ -162,7 +162,7 @@ export class AzureSettingsPage extends BasePage {
this._azureAccountsDropdown = view.modelBuilder.dropDown().withProperties({}).component(); this._azureAccountsDropdown = view.modelBuilder.dropDown().withProperties({}).component();
this._azureAccountsDropdown.onValueChanged(async (value) => { this._azureAccountsDropdown.onValueChanged(async (value) => {
this.wizard.model.azureAccount = this._accountsMap.get(value.selected)!; this._model.azureAccount = this._accountsMap.get(value.selected)!;
this.populateAzureSubscriptionsDropdown(); this.populateAzureSubscriptionsDropdown();
}); });
@@ -193,13 +193,13 @@ export class AzureSettingsPage extends BasePage {
let accounts = await azdata.accounts.getAllAccounts(); let accounts = await azdata.accounts.getAllAccounts();
if (accounts.length === 0) { if (accounts.length === 0) {
this.wizard.showErrorMessage(localize('deployAzureSQLDB.azureSignInError', "Sign in to an Azure account first")); this._model.wizard.showErrorMessage(localize('deployAzureSQLDB.azureSignInError', "Sign in to an Azure account first"));
return; return;
} else { } else {
this.wizard.showErrorMessage(''); this._model.wizard.showErrorMessage('');
} }
this.wizard.addDropdownValues( this._model.addDropdownValues(
this._azureAccountsDropdown, this._azureAccountsDropdown,
accounts.map((account): azdata.CategoryValue => { accounts.map((account): azdata.CategoryValue => {
let accountCategoryValue = { let accountCategoryValue = {
@@ -211,7 +211,7 @@ export class AzureSettingsPage extends BasePage {
}), }),
); );
this.wizard.model.azureAccount = accounts[0]; this._model.azureAccount = accounts[0];
this._azureAccountsDropdown.loading = false; this._azureAccountsDropdown.loading = false;
await this.populateAzureSubscriptionsDropdown(); await this.populateAzureSubscriptionsDropdown();
@@ -223,11 +223,11 @@ export class AzureSettingsPage extends BasePage {
this._azureSubscriptionsDropdown.onValueChanged(async (value) => { this._azureSubscriptionsDropdown.onValueChanged(async (value) => {
let currentSubscriptionValue = this._azureSubscriptionsDropdown.value as azdata.CategoryValue; let currentSubscriptionValue = this._azureSubscriptionsDropdown.value as azdata.CategoryValue;
this.wizard.model.azureSubscription = currentSubscriptionValue.name; this._model.azureSubscription = currentSubscriptionValue.name;
this.wizard.model.azureSubscriptionDisplayName = currentSubscriptionValue.displayName; this._model.azureSubscriptionDisplayName = currentSubscriptionValue.displayName;
this.wizard.model.securityToken = await azdata.accounts.getAccountSecurityToken( this._model.securityToken = await azdata.accounts.getAccountSecurityToken(
this.wizard.model.azureAccount, this._model.azureAccount,
this._subscriptionsMap.get(currentSubscriptionValue.name)?.tenant!, this._subscriptionsMap.get(currentSubscriptionValue.name)?.tenant!,
azdata.AzureResource.ResourceManagement azdata.AzureResource.ResourceManagement
); );
@@ -266,7 +266,7 @@ export class AzureSettingsPage extends BasePage {
} }
subscriptions.sort((a: any, b: any) => a.name.toLocaleLowerCase().localeCompare(b.name.toLocaleLowerCase())); subscriptions.sort((a: any, b: any) => a.name.toLocaleLowerCase().localeCompare(b.name.toLocaleLowerCase()));
this.wizard.addDropdownValues( this._model.addDropdownValues(
this._azureSubscriptionsDropdown, this._azureSubscriptionsDropdown,
subscriptions.map((subscription: any): azdata.CategoryValue => { subscriptions.map((subscription: any): azdata.CategoryValue => {
let subscriptionCategoryValue = { let subscriptionCategoryValue = {
@@ -278,11 +278,11 @@ export class AzureSettingsPage extends BasePage {
}) })
); );
this.wizard.model.azureSubscription = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).name; this._model.azureSubscription = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).name;
this.wizard.model.azureSubscriptionDisplayName = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).displayName; this._model.azureSubscriptionDisplayName = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).displayName;
this.wizard.model.securityToken = await azdata.accounts.getAccountSecurityToken( this._model.securityToken = await azdata.accounts.getAccountSecurityToken(
this.wizard.model.azureAccount, this._model.azureAccount,
this._subscriptionsMap.get((this._azureSubscriptionsDropdown.value as azdata.CategoryValue).name)?.tenant!, this._subscriptionsMap.get((this._azureSubscriptionsDropdown.value as azdata.CategoryValue).name)?.tenant!,
azdata.AzureResource.ResourceManagement azdata.AzureResource.ResourceManagement
); );
@@ -299,9 +299,9 @@ export class AzureSettingsPage extends BasePage {
}).component(); }).component();
this._serverGroupDropdown.onValueChanged(async (value) => { this._serverGroupDropdown.onValueChanged(async (value) => {
if (value.selected === ((this._serverGroupDropdown.value as azdata.CategoryValue).displayName)) { if (value.selected === ((this._serverGroupDropdown.value as azdata.CategoryValue).displayName)) {
this.wizard.model.azureServerName = value.selected; this._model.azureServerName = value.selected;
this.wizard.model.azureResouceGroup = (this._serverGroupDropdown.value as azdata.CategoryValue).name.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), ''); this._model.azureResouceGroup = (this._serverGroupDropdown.value as azdata.CategoryValue).name.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
this.wizard.model.azureRegion = (this._serverGroupDropdown.value as azdata.CategoryValue).name.replace(RegExp('^(.*?)/location/'), ''); this._model.azureRegion = (this._serverGroupDropdown.value as azdata.CategoryValue).name.replace(RegExp('^(.*?)/location/'), '');
//this.populateManagedInstanceDropdown(); //@todo alma1 9/8/2020 functions below are used for upcoming database hardware creation feature. //this.populateManagedInstanceDropdown(); //@todo alma1 9/8/2020 functions below are used for upcoming database hardware creation feature.
} }
}); });
@@ -318,8 +318,8 @@ export class AzureSettingsPage extends BasePage {
// await this.populateManagedInstanceDropdown(); //@todo alma1 9/8/2020 functions below are used for upcoming database hardware creation feature. // await this.populateManagedInstanceDropdown(); //@todo alma1 9/8/2020 functions below are used for upcoming database hardware creation feature.
return; return;
} }
let url = `https://management.azure.com/subscriptions/${this.wizard.model.azureSubscription}/providers/Microsoft.Sql/servers?api-version=2019-06-01-preview`; let url = `https://management.azure.com/subscriptions/${this._model.azureSubscription}/providers/Microsoft.Sql/servers?api-version=2019-06-01-preview`;
let response = await this.wizard.getRequest(url); let response = await this._model.getRequest(url);
if (response.data.value.length === 0) { if (response.data.value.length === 0) {
this._serverGroupDropdown.updateProperties({ this._serverGroupDropdown.updateProperties({
values: [ values: [
@@ -335,7 +335,7 @@ export class AzureSettingsPage extends BasePage {
} else { } else {
response.data.value.sort((a: azdata.CategoryValue, b: azdata.CategoryValue) => (a!.name > b!.name) ? 1 : -1); response.data.value.sort((a: azdata.CategoryValue, b: azdata.CategoryValue) => (a!.name > b!.name) ? 1 : -1);
} }
this.wizard.addDropdownValues( this._model.addDropdownValues(
this._serverGroupDropdown, this._serverGroupDropdown,
response.data.value.map((value: any) => { response.data.value.map((value: any) => {
return { return {
@@ -346,9 +346,9 @@ export class AzureSettingsPage extends BasePage {
}) })
); );
if (this._serverGroupDropdown.value) { if (this._serverGroupDropdown.value) {
this.wizard.model.azureServerName = (this._serverGroupDropdown.value as azdata.CategoryValue).displayName; this._model.azureServerName = (this._serverGroupDropdown.value as azdata.CategoryValue).displayName;
this.wizard.model.azureResouceGroup = (this._serverGroupDropdown.value as azdata.CategoryValue).name.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), ''); this._model.azureResouceGroup = (this._serverGroupDropdown.value as azdata.CategoryValue).name.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
this.wizard.model.azureRegion = (this._serverGroupDropdown.value as azdata.CategoryValue).name.replace(RegExp('^(.*?)/location/'), ''); this._model.azureRegion = (this._serverGroupDropdown.value as azdata.CategoryValue).name.replace(RegExp('^(.*?)/location/'), '');
} }
this._serverGroupDropdown.loading = false; this._serverGroupDropdown.loading = false;
// await this.populateManagedInstanceDropdown(); //@todo alma1 9/8/2020 functions below are used for upcoming database hardware creation feature. // await this.populateManagedInstanceDropdown(); //@todo alma1 9/8/2020 functions below are used for upcoming database hardware creation feature.
@@ -760,7 +760,7 @@ export class AzureSettingsPage extends BasePage {
// errorMessages.push(localize('deployAzureSQLDB.SupportedFamiliesError', "No Supported Family found in current DB edition.\nSelect a different edition")); // errorMessages.push(localize('deployAzureSQLDB.SupportedFamiliesError', "No Supported Family found in current DB edition.\nSelect a different edition"));
// } // }
this.wizard.showErrorMessage(errorMessages.join(EOL)); this._model.wizard.showErrorMessage(errorMessages.join(EOL));
return errorMessages.join(EOL); return errorMessages.join(EOL);
} }
} }

View File

@@ -3,9 +3,8 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { WizardPageBase } from '../../wizardPageBase'; import { ResourceTypePage } from '../../resourceTypePage';
import { DeployAzureSQLDBWizard } from '../deployAzureSQLDBWizard';
export abstract class BasePage extends WizardPageBase<DeployAzureSQLDBWizard> { export abstract class BasePage extends ResourceTypePage {
public abstract initialize(): void; public abstract initialize(): void;
} }

View File

@@ -5,10 +5,10 @@
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import { EOL } from 'os'; import { EOL } from 'os';
import { DeployAzureSQLDBWizard } from '../deployAzureSQLDBWizard';
import * as constants from '../constants'; import * as constants from '../constants';
import { BasePage } from './basePage'; import { BasePage } from './basePage';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import { DeployAzureSQLDBWizardModel } from '../deployAzureSQLDBWizardModel';
import { createCheckbox, createFlexContainer, createLabel } from '../../modelViewUtils'; import { createCheckbox, createFlexContainer, createLabel } from '../../modelViewUtils';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -32,11 +32,11 @@ export class DatabaseSettingsPage extends BasePage {
private _form!: azdata.FormContainer; private _form!: azdata.FormContainer;
constructor(wizard: DeployAzureSQLDBWizard) { constructor(private _model: DeployAzureSQLDBWizardModel) {
super( super(
constants.DatabaseSettingsPageTitle, constants.DatabaseSettingsPageTitle,
'', '',
wizard _model.wizard
); );
} }
@@ -119,10 +119,10 @@ export class DatabaseSettingsPage extends BasePage {
}).component(); }).component();
this._startIpAddressTextbox.onTextChanged((value) => { this._startIpAddressTextbox.onTextChanged((value) => {
this.wizard.model.startIpAddress = value; this._model.startIpAddress = value;
}); });
this._startIpAddressTextRow = this.wizard.createFormRowComponent(view, constants.StartIpAddressLabel, '', this._startIpAddressTextbox, true); this._startIpAddressTextRow = this._model.createFormRowComponent(view, constants.StartIpAddressLabel, '', this._startIpAddressTextbox, true);
//End IP Address Section: //End IP Address Section:
@@ -131,10 +131,10 @@ export class DatabaseSettingsPage extends BasePage {
}).component(); }).component();
this._endIpAddressTextbox.onTextChanged((value) => { this._endIpAddressTextbox.onTextChanged((value) => {
this.wizard.model.endIpAddress = value; this._model.endIpAddress = value;
}); });
this._endIpAddressTextRow = this.wizard.createFormRowComponent(view, constants.EndIpAddressLabel, '', this._endIpAddressTextbox, true); this._endIpAddressTextRow = this._model.createFormRowComponent(view, constants.EndIpAddressLabel, '', this._endIpAddressTextbox, true);
} }
private createFirewallToggle(view: azdata.ModelView) { private createFirewallToggle(view: azdata.ModelView) {
@@ -156,15 +156,15 @@ export class DatabaseSettingsPage extends BasePage {
} }
}); });
this.wizard.model.newFirewallRule = true; this._model.newFirewallRule = true;
this._firewallToggleDropdown.onChanged((value) => { this._firewallToggleDropdown.onChanged((value) => {
let displayValue: 'block' | 'none' = (value) ? 'block' : 'none'; let displayValue: 'block' | 'none' = (value) ? 'block' : 'none';
this.wizard.changeRowDisplay(this._firewallRuleNameTextRow, displayValue); this._model.changeRowDisplay(this._firewallRuleNameTextRow, displayValue);
this.wizard.changeRowDisplay(this._endIpAddressTextRow, displayValue); this._model.changeRowDisplay(this._endIpAddressTextRow, displayValue);
this.wizard.changeRowDisplay(this._startIpAddressTextRow, displayValue); this._model.changeRowDisplay(this._startIpAddressTextRow, displayValue);
this.wizard.changeComponentDisplay(this._IpInfoText, displayValue); this._model.changeComponentDisplay(this._IpInfoText, displayValue);
this.wizard.model.newFirewallRule = value; this._model.newFirewallRule = value;
}); });
} }
@@ -172,10 +172,10 @@ export class DatabaseSettingsPage extends BasePage {
this._firewallRuleNameTextbox = view.modelBuilder.inputBox().component(); this._firewallRuleNameTextbox = view.modelBuilder.inputBox().component();
this._firewallRuleNameTextRow = this.wizard.createFormRowComponent(view, constants.FirewallRuleNameLabel, '', this._firewallRuleNameTextbox, true); this._firewallRuleNameTextRow = this._model.createFormRowComponent(view, constants.FirewallRuleNameLabel, '', this._firewallRuleNameTextbox, true);
this._firewallRuleNameTextbox.onTextChanged((value) => { this._firewallRuleNameTextbox.onTextChanged((value) => {
this.wizard.model.firewallRuleName = value; this._model.firewallRuleName = value;
}); });
} }
@@ -183,10 +183,10 @@ export class DatabaseSettingsPage extends BasePage {
this._databaseNameTextbox = view.modelBuilder.inputBox().component(); this._databaseNameTextbox = view.modelBuilder.inputBox().component();
this._databaseNameTextRow = this.wizard.createFormRowComponent(view, constants.DatabaseNameLabel, '', this._databaseNameTextbox, true); this._databaseNameTextRow = this._model.createFormRowComponent(view, constants.DatabaseNameLabel, '', this._databaseNameTextbox, true);
this._databaseNameTextbox.onTextChanged((value) => { this._databaseNameTextbox.onTextChanged((value) => {
this.wizard.model.databaseName = value; this._model.databaseName = value;
}); });
} }
@@ -197,10 +197,10 @@ export class DatabaseSettingsPage extends BasePage {
}).component(); }).component();
this._collationTextbox.onTextChanged((value) => { this._collationTextbox.onTextChanged((value) => {
this.wizard.model.databaseCollation = value; this._model.databaseCollation = value;
}); });
this._collationTextRow = this.wizard.createFormRowComponent(view, constants.CollationNameLabel, '', this._collationTextbox, true); this._collationTextRow = this._model.createFormRowComponent(view, constants.CollationNameLabel, '', this._collationTextbox, true);
} }
@@ -213,7 +213,7 @@ export class DatabaseSettingsPage extends BasePage {
let databasename = this._databaseNameTextbox.value!; let databasename = this._databaseNameTextbox.value!;
let collationname = this._collationTextbox.value!; let collationname = this._collationTextbox.value!;
if (this.wizard.model.newFirewallRule) { if (this._model.newFirewallRule) {
if (!(ipRegex.test(startipvalue))) { if (!(ipRegex.test(startipvalue))) {
errorMessages.push(localize('deployAzureSQLDB.DBMinIpInvalidError', "Min Ip address is invalid")); errorMessages.push(localize('deployAzureSQLDB.DBMinIpInvalidError', "Min Ip address is invalid"));
} }
@@ -260,19 +260,19 @@ export class DatabaseSettingsPage extends BasePage {
errorMessages.push(localize('deployAzureSQLDB.DBCollationSpecialCharError', "Collation name cannot contain special characters \/\"\"[]:|<>+=;,?*@&, .")); errorMessages.push(localize('deployAzureSQLDB.DBCollationSpecialCharError', "Collation name cannot contain special characters \/\"\"[]:|<>+=;,?*@&, ."));
} }
this.wizard.showErrorMessage(errorMessages.join(EOL)); this._model.wizard.showErrorMessage(errorMessages.join(EOL));
return errorMessages.join(EOL); return errorMessages.join(EOL);
} }
protected async databaseNameExists(dbName: string): Promise<boolean> { protected async databaseNameExists(dbName: string): Promise<boolean> {
const url = `https://management.azure.com` + const url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` + `/subscriptions/${this._model.azureSubscription}` +
`/resourceGroups/${this.wizard.model.azureResouceGroup}` + `/resourceGroups/${this._model.azureResouceGroup}` +
`/providers/Microsoft.Sql` + `/providers/Microsoft.Sql` +
`/servers/${this.wizard.model.azureServerName}` + `/servers/${this._model.azureServerName}` +
`/databases?api-version=2017-10-01-preview`; `/databases?api-version=2017-10-01-preview`;
let response = await this.wizard.getRequest(url, true); let response = await this._model.getRequest(url, true);
let nameArray = response.data.value.map((v: any) => { return v.name; }); let nameArray = response.data.value.map((v: any) => { return v.name; });
return (nameArray.includes(dbName)); return (nameArray.includes(dbName));

View File

@@ -4,24 +4,24 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import { WizardPageBase } from '../../wizardPageBase';
import { DeployAzureSQLDBWizard } from '../deployAzureSQLDBWizard';
import * as constants from '../constants'; import * as constants from '../constants';
import * as localizedConstants from '../../../localizedConstants'; import * as localizedConstants from '../../../localizedConstants';
import { SectionInfo, LabelPosition, FontWeight, FieldType } from '../../../interfaces'; import { SectionInfo, LabelPosition, FontWeight, FieldType } from '../../../interfaces';
import { createSection } from '../../modelViewUtils'; import { createSection } from '../../modelViewUtils';
import { BasePage } from '../../deployAzureSQLVMWizard/pages/basePage';
import { DeployAzureSQLDBWizardModel } from '../deployAzureSQLDBWizardModel';
export class AzureSQLDBSummaryPage extends WizardPageBase<DeployAzureSQLDBWizard> { export class AzureSQLDBSummaryPage extends BasePage {
private formItems: azdata.FormComponent[] = []; private formItems: azdata.FormComponent[] = [];
private _form!: azdata.FormBuilder; private _form!: azdata.FormBuilder;
private _view!: azdata.ModelView; private _view!: azdata.ModelView;
constructor(wizard: DeployAzureSQLDBWizard) { constructor(private _model: DeployAzureSQLDBWizardModel) {
super( super(
'Summary', 'Summary',
'', '',
wizard _model.wizard
); );
} }
@@ -42,7 +42,7 @@ export class AzureSQLDBSummaryPage extends WizardPageBase<DeployAzureSQLDBWizard
this.formItems = []; this.formItems = [];
let model = this.wizard.model; let model = this._model;
const labelWidth = '150px'; const labelWidth = '150px';
const inputWidth = '400px'; const inputWidth = '400px';

View File

@@ -1,224 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import * as constants from './constants';
import { INotebookService } from '../../services/notebookService';
import { IToolsService } from '../../services/toolsService';
import { WizardBase } from '../wizardBase';
import { WizardPageBase } from '../wizardPageBase';
import { DeployAzureSQLVMWizardModel } from './deployAzureSQLVMWizardModel';
import { AzureSQLVMWizardInfo } from '../../interfaces';
import { AzureSettingsPage } from './pages/azureSettingsPage';
import { VmSettingsPage } from './pages/vmSettingsPage';
import axios, { AxiosRequestConfig } from 'axios';
import { NetworkSettingsPage } from './pages/networkSettingsPage';
import { SqlServerSettingsPage } from './pages/sqlServerSettingsPage';
import { AzureSQLVMSummaryPage } from './pages/summaryPage';
import { EOL } from 'os';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
export class DeployAzureSQLVMWizard extends WizardBase<DeployAzureSQLVMWizard, WizardPageBase<DeployAzureSQLVMWizard>, DeployAzureSQLVMWizardModel> {
private cache: Map<string, any> = new Map();
constructor(private wizardInfo: AzureSQLVMWizardInfo, private _notebookService: INotebookService, private _toolsService: IToolsService) {
super(
constants.WizardTitle,
'DeployAzureSqlVMWizard',
new DeployAzureSQLVMWizardModel(),
_toolsService
);
}
protected initialize(): void {
this.setPages(this.getPages());
this.wizardObject.generateScriptButton.hidden = true;
this.wizardObject.doneButton.label = constants.WizardDoneButtonLabel;
}
public get notebookService(): INotebookService {
return this._notebookService;
}
public get toolService(): IToolsService {
return this._toolsService;
}
protected async onOk(): Promise<void> {
await this.scriptToNotebook();
}
protected onCancel(): void {
}
private getPages(): WizardPageBase<DeployAzureSQLVMWizard>[] {
const pages: WizardPageBase<DeployAzureSQLVMWizard>[] = [];
pages.push(new AzureSettingsPage(this));
pages.push(new VmSettingsPage(this));
pages.push(new NetworkSettingsPage(this));
pages.push(new SqlServerSettingsPage(this));
pages.push(new AzureSQLVMSummaryPage(this));
return pages;
}
private async scriptToNotebook(): Promise<void> {
this.setEnvironmentVariables(process.env);
const variableValueStatements = this.model.getCodeCellContentForNotebook();
const insertionPosition = 2; // Cell number 5 is the position where the python variable setting statements need to be inserted in this.wizardInfo.notebook.
try {
await this.notebookService.openNotebookWithEdits(this.wizardInfo.notebook, variableValueStatements, insertionPosition);
} catch (error) {
vscode.window.showErrorMessage(error);
}
}
private setEnvironmentVariables(env: NodeJS.ProcessEnv): void {
env['AZDATA_NB_VAR_AZURE_SQLVM_PASSWORD'] = this.model.vmPassword;
env['AZDATA_NB_VAR_AZURE_SQLVM_SQL_PASSWORD'] = this.model.sqlAuthenticationPassword;
}
public async getRequest(url: string, useCache = false): Promise<any> {
if (useCache) {
if (this.cache.has(url)) {
return this.cache.get(url);
}
}
let token = this.model.securityToken.token;
const config: AxiosRequestConfig = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
validateStatus: () => true // Never throw
};
const response = await axios.get(url, config);
if (response.status !== 200) {
let errorMessage: string[] = [];
errorMessage.push(response.status.toString());
errorMessage.push(response.statusText);
if (response.data && response.data.error) {
errorMessage.push(`${response.data.error.code} : ${response.data.error.message}`);
}
vscode.window.showErrorMessage(errorMessage.join(EOL));
}
if (useCache) {
this.cache.set(url, response);
}
return response;
}
public createFormRowComponent(view: azdata.ModelView, title: string, description: string, component: azdata.Component, required: boolean): azdata.FlexContainer {
component.updateProperties({
required: required,
width: '480px'
});
const labelText = view.modelBuilder.text()
.withProperties<azdata.TextComponentProperties>(
{
value: title,
width: '250px',
description: description,
requiredIndicator: required,
})
.component();
labelText.updateCssStyles({
'font-weight': '400',
'font-size': '13px',
});
const flexContainer = view.modelBuilder.flexContainer()
.withLayout(
{
flexFlow: 'row',
alignItems: 'center',
})
.withItems(
[labelText, component],
{
CSSStyles: { 'margin-right': '5px' }
})
.component();
return flexContainer;
}
public changeComponentDisplay(component: azdata.Component, display: ('none' | 'block')) {
component.updateProperties({
required: display === 'block'
});
component.updateCssStyles({
display: display
});
}
public changeRowDisplay(container: azdata.FlexContainer, display: ('none' | 'block')) {
container.items.map((component) => {
component.updateProperties({
required: (display === 'block'),
});
component.updateCssStyles({
display: display,
});
});
}
public addDropdownValues(component: azdata.DropDownComponent, values: azdata.CategoryValue[], width?: number) {
component.updateProperties({
values: values,
width: '480px'
});
}
public showErrorMessage(message: string) {
this.wizardObject.message = {
text: message,
level: azdata.window.MessageLevel.Error
};
}
public validatePassword(password: string): string[] {
/**
* 1. Password length should be between 12 and 123.
* 2. Password must have 3 of the following: 1 lower case character, 1 upper case character, 1 number, and 1 special character.
*/
let errorMessages = [];
if (password.length < 12 || password.length > 123) {
errorMessages.push(localize('sqlVMDeploymentWizard.PasswordLengthError', "Password must be between 12 and 123 characters long."));
}
let charTypeCounter = 0;
if (new RegExp('.*[a-z].*').test(password)) {
charTypeCounter++;
}
if (new RegExp('.*[A-Z].*').test(password)) {
charTypeCounter++;
}
if (new RegExp('.*[0-9].*').test(password)) {
charTypeCounter++;
}
if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/.test(password)) {
charTypeCounter++;
}
if (charTypeCounter < 3) {
errorMessages.push(localize('sqlVMDeploymentWizard.PasswordSpecialCharRequirementError', "Password must have 3 of the following: 1 lower case character, 1 upper case character, 1 number, and 1 special character."));
}
return errorMessages;
}
}

View File

@@ -5,9 +5,27 @@
import { EOL } from 'os'; import { EOL } from 'os';
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import { Model } from '../model'; import { ResourceTypeWizard } from '../resourceTypeWizard';
import { AzureSQLVMDeploymentProvider } from '../../interfaces';
import * as constants from './constants';
import { IToolsService } from '../../services/toolsService';
import { INotebookService } from '../../services/notebookService';
import axios, { AxiosRequestConfig } from 'axios';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { AzureSettingsPage } from './pages/azureSettingsPage';
import { VmSettingsPage } from './pages/vmSettingsPage';
import { NetworkSettingsPage } from './pages/networkSettingsPage';
import { SqlServerSettingsPage } from './pages/sqlServerSettingsPage';
import { AzureSQLVMSummaryPage } from './pages/summaryPage';
import { ResourceTypeModel } from '../resourceTypeModel';
import { ResourceTypePage } from '../resourceTypePage';
const localize = nls.loadMessageBundle();
export class DeployAzureSQLVMWizardModel extends ResourceTypeModel {
private cache: Map<string, any> = new Map();
export class DeployAzureSQLVMWizardModel extends Model {
public azureAccount!: azdata.Account; public azureAccount!: azdata.Account;
public securityToken!: any; public securityToken!: any;
public azureSubscription!: string; public azureSubscription!: string;
@@ -38,15 +56,197 @@ export class DeployAzureSQLVMWizardModel extends Model {
public sqlAuthenticationPassword!: string; public sqlAuthenticationPassword!: string;
public sqlOptimizationDropdown!: string; public sqlOptimizationDropdown!: string;
public get notebookService(): INotebookService {
constructor() { return this.wizard.notebookService;
super();
} }
public get toolService(): IToolsService {
return this.wizard.toolsService;
}
constructor(public sqlvmProvider: AzureSQLVMDeploymentProvider, wizard: ResourceTypeWizard) {
super(sqlvmProvider, wizard);
this.wizard.wizardObject.title = constants.WizardTitle;
}
initialize(): void {
this.wizard.setPages(this.getPages());
this.wizard.wizardObject.generateScriptButton.hidden = true;
this.wizard.wizardObject.doneButton.label = constants.WizardDoneButtonLabel;
}
async onOk(): Promise<void> {
await this.scriptToNotebook();
}
onCancel(): void {
throw new Error('Method not implemented.');
}
private getPages(): ResourceTypePage[] {
const pages: ResourceTypePage[] = [];
pages.push(new AzureSettingsPage(this));
pages.push(new VmSettingsPage(this));
pages.push(new NetworkSettingsPage(this));
pages.push(new SqlServerSettingsPage(this));
pages.push(new AzureSQLVMSummaryPage(this));
return pages;
}
private async scriptToNotebook(): Promise<void> {
this.setNotebookEnvironmentVariables(process.env);
const variableValueStatements = this.getCodeCellContentForNotebook();
const insertionPosition = 2; // Cell number 5 is the position where the python variable setting statements need to be inserted in this.wizardInfo.notebook.
try {
await this.notebookService.openNotebookWithEdits(this.sqlvmProvider.azureSQLVMWizard.notebook, variableValueStatements, insertionPosition);
} catch (error) {
vscode.window.showErrorMessage(error);
}
}
private setNotebookEnvironmentVariables(env: NodeJS.ProcessEnv): void {
env['AZDATA_NB_VAR_AZURE_SQLVM_PASSWORD'] = this.vmPassword;
env['AZDATA_NB_VAR_AZURE_SQLVM_SQL_PASSWORD'] = this.sqlAuthenticationPassword;
}
public async getRequest(url: string, useCache = false): Promise<any> {
if (useCache) {
if (this.cache.has(url)) {
return this.cache.get(url);
}
}
let token = this.securityToken.token;
const config: AxiosRequestConfig = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
validateStatus: () => true // Never throw
};
const response = await axios.get(url, config);
if (response.status !== 200) {
let errorMessage: string[] = [];
errorMessage.push(response.status.toString());
errorMessage.push(response.statusText);
if (response.data && response.data.error) {
errorMessage.push(`${response.data.error.code} : ${response.data.error.message}`);
}
vscode.window.showErrorMessage(errorMessage.join(EOL));
}
if (useCache) {
this.cache.set(url, response);
}
return response;
}
public createFormRowComponent(view: azdata.ModelView, title: string, description: string, component: azdata.Component, required: boolean): azdata.FlexContainer {
component.updateProperties({
required: required,
width: '480px'
});
const labelText = view.modelBuilder.text()
.withProperties<azdata.TextComponentProperties>(
{
value: title,
width: '250px',
description: description,
requiredIndicator: required,
})
.component();
labelText.updateCssStyles({
'font-weight': '400',
'font-size': '13px',
});
const flexContainer = view.modelBuilder.flexContainer()
.withLayout(
{
flexFlow: 'row',
alignItems: 'center',
})
.withItems(
[labelText, component],
{
CSSStyles: { 'margin-right': '5px' }
})
.component();
return flexContainer;
}
public changeComponentDisplay(component: azdata.Component, display: ('none' | 'block')) {
component.updateProperties({
required: display === 'block'
});
component.updateCssStyles({
display: display
});
}
public changeRowDisplay(container: azdata.FlexContainer, display: ('none' | 'block')) {
container.items.map((component) => {
component.updateProperties({
required: (display === 'block'),
});
component.updateCssStyles({
display: display,
});
});
}
public addDropdownValues(component: azdata.DropDownComponent, values: azdata.CategoryValue[], width?: number) {
component.updateProperties({
values: values,
width: '480px'
});
}
public validatePassword(password: string): string[] {
/**
* 1. Password length should be between 12 and 123.
* 2. Password must have 3 of the following: 1 lower case character, 1 upper case character, 1 number, and 1 special character.
*/
let errorMessages = [];
if (password.length < 12 || password.length > 123) {
errorMessages.push(localize('sqlVMDeploymentWizard.PasswordLengthError', "Password must be between 12 and 123 characters long."));
}
let charTypeCounter = 0;
if (new RegExp('.*[a-z].*').test(password)) {
charTypeCounter++;
}
if (new RegExp('.*[A-Z].*').test(password)) {
charTypeCounter++;
}
if (new RegExp('.*[0-9].*').test(password)) {
charTypeCounter++;
}
if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/.test(password)) {
charTypeCounter++;
}
if (charTypeCounter < 3) {
errorMessages.push(localize('sqlVMDeploymentWizard.PasswordSpecialCharRequirementError', "Password must have 3 of the following: 1 lower case character, 1 upper case character, 1 number, and 1 special character."));
}
return errorMessages;
}
public getCodeCellContentForNotebook(): string[] { public getCodeCellContentForNotebook(): string[] {
const statements: string[] = []; const statements: string[] = [];
statements.push('import os'); statements.push('import os');
statements.push(`azure_sqlvm_nb_var_subscription = '${this.azureSubscription}'`); statements.push(`azure_sqlvm_nb_var_subscription = '${this.azureSubscription}'`);
statements.push(`azure_sqlvm_nb_var_resource_group_name = '${this.azureResouceGroup}'`); statements.push(`azure_sqlvm_nb_var_resource_group_name = '${this.azureResouceGroup}'`);

View File

@@ -5,14 +5,14 @@
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import * as constants from '../constants'; import * as constants from '../constants';
import { WizardPageBase } from '../../wizardPageBase';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
import { apiService } from '../../../services/apiService'; import { apiService } from '../../../services/apiService';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as localizedConstants from '../../../localizedConstants'; import * as localizedConstants from '../../../localizedConstants';
import { BasePage } from './basePage';
import { DeployAzureSQLVMWizardModel } from '../deployAzureSQLVMWizardModel';
export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> { export class AzureSettingsPage extends BasePage {
// <- means depends on // <- means depends on
//dropdown for azure accounts //dropdown for azure accounts
private _azureAccountsDropdown!: azdata.DropDownComponent; private _azureAccountsDropdown!: azdata.DropDownComponent;
@@ -34,11 +34,11 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
private _accountsMap!: Map<string, azdata.Account>; private _accountsMap!: Map<string, azdata.Account>;
private _subscriptionsMap!: Map<string, azureResource.AzureResourceSubscription>; private _subscriptionsMap!: Map<string, azureResource.AzureResourceSubscription>;
constructor(wizard: DeployAzureSQLVMWizard) { constructor(private _model: DeployAzureSQLVMWizardModel) {
super( super(
constants.AzureSettingsPageTitle, constants.AzureSettingsPageTitle,
'', '',
wizard _model.wizard
); );
this._accountsMap = new Map(); this._accountsMap = new Map();
this._subscriptionsMap = new Map(); this._subscriptionsMap = new Map();
@@ -59,19 +59,19 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
.withFormItems( .withFormItems(
[ [
{ {
component: this.wizard.createFormRowComponent(view, constants.AzureAccountDropdownLabel, '', this._azureAccountsDropdown, true) component: this._model.createFormRowComponent(view, constants.AzureAccountDropdownLabel, '', this._azureAccountsDropdown, true)
}, },
{ {
component: this.buttonFlexContainer component: this.buttonFlexContainer
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.AzureAccountSubscriptionDropdownLabel, '', this._azureSubscriptionsDropdown, true) component: this._model.createFormRowComponent(view, constants.AzureAccountSubscriptionDropdownLabel, '', this._azureSubscriptionsDropdown, true)
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.AzureAccountResourceGroupDropdownLabel, '', this._resourceGroupDropdown, true) component: this._model.createFormRowComponent(view, constants.AzureAccountResourceGroupDropdownLabel, '', this._resourceGroupDropdown, true)
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.AzureAccountRegionDropdownLabel, '', this._azureRegionsDropdown, true) component: this._model.createFormRowComponent(view, constants.AzureAccountRegionDropdownLabel, '', this._azureRegionsDropdown, true)
} }
], ],
{ {
@@ -85,13 +85,13 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
} }
public async onEnter(): Promise<void> { public async onEnter(): Promise<void> {
this.wizard.wizardObject.registerNavigationValidator((pcInfo) => { this._model.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
return true; return true;
}); });
} }
public async onLeave(): Promise<void> { public async onLeave(): Promise<void> {
this.wizard.wizardObject.registerNavigationValidator((pcInfo) => { this._model.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
return true; return true;
}); });
} }
@@ -101,7 +101,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
this._azureAccountsDropdown = view.modelBuilder.dropDown().withProperties({}).component(); this._azureAccountsDropdown = view.modelBuilder.dropDown().withProperties({}).component();
this._azureAccountsDropdown.onValueChanged(async (value) => { this._azureAccountsDropdown.onValueChanged(async (value) => {
this.wizard.model.azureAccount = this._accountsMap.get(value.selected)!; this._model.azureAccount = this._accountsMap.get(value.selected)!;
this.populateAzureSubscriptionsDropdown(); this.populateAzureSubscriptionsDropdown();
}); });
@@ -132,13 +132,13 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
let accounts = await azdata.accounts.getAllAccounts(); let accounts = await azdata.accounts.getAllAccounts();
if (accounts.length === 0) { if (accounts.length === 0) {
this.wizard.showErrorMessage('Sign in to an Azure account first'); this._model.wizard.showErrorMessage('Sign in to an Azure account first');
return; return;
} else { } else {
this.wizard.showErrorMessage(''); this._model.wizard.showErrorMessage('');
} }
this.wizard.addDropdownValues( this._model.addDropdownValues(
this._azureAccountsDropdown, this._azureAccountsDropdown,
accounts.map((account): azdata.CategoryValue => { accounts.map((account): azdata.CategoryValue => {
let accountCategoryValue = { let accountCategoryValue = {
@@ -150,7 +150,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
}), }),
); );
this.wizard.model.azureAccount = accounts[0]; this._model.azureAccount = accounts[0];
this._azureAccountsDropdown.loading = false; this._azureAccountsDropdown.loading = false;
await this.populateAzureSubscriptionsDropdown(); await this.populateAzureSubscriptionsDropdown();
@@ -162,11 +162,11 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
this._azureSubscriptionsDropdown.onValueChanged(async (value) => { this._azureSubscriptionsDropdown.onValueChanged(async (value) => {
let currentSubscriptionValue = this._azureSubscriptionsDropdown.value as azdata.CategoryValue; let currentSubscriptionValue = this._azureSubscriptionsDropdown.value as azdata.CategoryValue;
this.wizard.model.azureSubscription = currentSubscriptionValue.name; this._model.azureSubscription = currentSubscriptionValue.name;
this.wizard.model.azureSubscriptionDisplayName = currentSubscriptionValue.displayName; this._model.azureSubscriptionDisplayName = currentSubscriptionValue.displayName;
this.wizard.model.securityToken = await azdata.accounts.getAccountSecurityToken( this._model.securityToken = await azdata.accounts.getAccountSecurityToken(
this.wizard.model.azureAccount, this._model.azureAccount,
this._subscriptionsMap.get(currentSubscriptionValue.name)?.tenant!, this._subscriptionsMap.get(currentSubscriptionValue.name)?.tenant!,
azdata.AzureResource.ResourceManagement azdata.AzureResource.ResourceManagement
); );
@@ -199,7 +199,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
} }
subscriptions.sort((a: any, b: any) => a.name.toLocaleLowerCase().localeCompare(b.name.toLocaleLowerCase())); subscriptions.sort((a: any, b: any) => a.name.toLocaleLowerCase().localeCompare(b.name.toLocaleLowerCase()));
this.wizard.addDropdownValues( this._model.addDropdownValues(
this._azureSubscriptionsDropdown, this._azureSubscriptionsDropdown,
subscriptions.map((subscription: any): azdata.CategoryValue => { subscriptions.map((subscription: any): azdata.CategoryValue => {
let subscriptionCategoryValue = { let subscriptionCategoryValue = {
@@ -211,11 +211,11 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
}) })
); );
this.wizard.model.azureSubscription = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).name; this._model.azureSubscription = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).name;
this.wizard.model.azureSubscriptionDisplayName = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).displayName; this._model.azureSubscriptionDisplayName = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).displayName;
this.wizard.model.securityToken = await azdata.accounts.getAccountSecurityToken( this._model.securityToken = await azdata.accounts.getAccountSecurityToken(
this.wizard.model.azureAccount, this._model.azureAccount,
this._subscriptionsMap.get((this._azureSubscriptionsDropdown.value as azdata.CategoryValue).name)?.tenant!, this._subscriptionsMap.get((this._azureSubscriptionsDropdown.value as azdata.CategoryValue).name)?.tenant!,
azdata.AzureResource.ResourceManagement azdata.AzureResource.ResourceManagement
); );
@@ -229,7 +229,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
required: true required: true
}).component(); }).component();
this._resourceGroupDropdown.onValueChanged(async (value) => { this._resourceGroupDropdown.onValueChanged(async (value) => {
this.wizard.model.azureResouceGroup = value.selected; this._model.azureResouceGroup = value.selected;
}); });
} }
@@ -246,7 +246,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
return; return;
} }
let currentSubscription = this._subscriptionsMap.get(currentSubscriptionValue.name); let currentSubscription = this._subscriptionsMap.get(currentSubscriptionValue.name);
let resourceGroups = (await subService.getResourceGroups(this.wizard.model.azureAccount, currentSubscription, true)).resourceGroups; let resourceGroups = (await subService.getResourceGroups(this._model.azureAccount, currentSubscription, true)).resourceGroups;
if (resourceGroups === undefined || resourceGroups.length === 0) { if (resourceGroups === undefined || resourceGroups.length === 0) {
this._resourceGroupDropdown.loading = false; this._resourceGroupDropdown.loading = false;
this._resourceGroupDropdown.updateProperties({ this._resourceGroupDropdown.updateProperties({
@@ -264,7 +264,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
}; };
}) })
}); });
this.wizard.model.azureResouceGroup = (this._resourceGroupDropdown.value as azdata.CategoryValue).name; this._model.azureResouceGroup = (this._resourceGroupDropdown.value as azdata.CategoryValue).name;
this._resourceGroupDropdown.loading = false; this._resourceGroupDropdown.loading = false;
} }
@@ -274,7 +274,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
}).component(); }).component();
this._azureRegionsDropdown.onValueChanged((value) => { this._azureRegionsDropdown.onValueChanged((value) => {
this.wizard.model.azureRegion = (this._azureRegionsDropdown.value as azdata.CategoryValue).name; this._model.azureRegion = (this._azureRegionsDropdown.value as azdata.CategoryValue).name;
}); });
} }
@@ -283,10 +283,10 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
let supportedRegions = 'eastus, eastus2, westus, centralus, northcentralus, southcentralus, northeurope, westeurope, eastasia, southeastasia, japaneast, japanwest, australiaeast, australiasoutheast, australiacentral, brazilsouth, southindia, centralindia, westindia, canadacentral, canadaeast, westus2, westcentralus, uksouth, ukwest, koreacentral, koreasouth, francecentral, southafricanorth, uaenorth, switzerlandnorth, germanywestcentral, norwayeast'; let supportedRegions = 'eastus, eastus2, westus, centralus, northcentralus, southcentralus, northeurope, westeurope, eastasia, southeastasia, japaneast, japanwest, australiaeast, australiasoutheast, australiacentral, brazilsouth, southindia, centralindia, westindia, canadacentral, canadaeast, westus2, westcentralus, uksouth, ukwest, koreacentral, koreasouth, francecentral, southafricanorth, uaenorth, switzerlandnorth, germanywestcentral, norwayeast';
let supportedRegionsArray = supportedRegions.split(', '); let supportedRegionsArray = supportedRegions.split(', ');
let url = `https://management.azure.com/subscriptions/${this.wizard.model.azureSubscription}/locations?api-version=2020-01-01`; let url = `https://management.azure.com/subscriptions/${this._model.azureSubscription}/locations?api-version=2020-01-01`;
const response = await this.wizard.getRequest(url, false); const response = await this._model.getRequest(url, false);
response.data.value = response.data.value.sort((a: any, b: any) => (a.displayName > b.displayName) ? 1 : -1); response.data.value = response.data.value.sort((a: any, b: any) => (a.displayName > b.displayName) ? 1 : -1);
this.wizard.addDropdownValues( this._model.addDropdownValues(
this._azureRegionsDropdown, this._azureRegionsDropdown,
response.data.value.filter((value: any) => { response.data.value.filter((value: any) => {
return supportedRegionsArray.includes(value.name); return supportedRegionsArray.includes(value.name);
@@ -297,7 +297,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
}; };
}) })
); );
this.wizard.model.azureRegion = (this._azureRegionsDropdown.value as azdata.CategoryValue).name; this._model.azureRegion = (this._azureRegionsDropdown.value as azdata.CategoryValue).name;
this._azureRegionsDropdown.loading = false; this._azureRegionsDropdown.loading = false;
} }
} }

View File

@@ -3,10 +3,9 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { WizardPageBase } from '../../wizardPageBase'; import { ResourceTypePage } from '../../resourceTypePage';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
export abstract class BasePage extends WizardPageBase<DeployAzureSQLVMWizard> { export abstract class BasePage extends ResourceTypePage {
protected liveValidation!: boolean; protected liveValidation!: boolean;

View File

@@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
import * as constants from '../constants'; import * as constants from '../constants';
import { BasePage } from './basePage'; import { BasePage } from './basePage';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import { DeployAzureSQLVMWizardModel } from '../deployAzureSQLVMWizardModel';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -37,11 +37,11 @@ export class NetworkSettingsPage extends BasePage {
private _form!: azdata.FormContainer; private _form!: azdata.FormContainer;
constructor(wizard: DeployAzureSQLVMWizard) { constructor(private _model: DeployAzureSQLVMWizardModel) {
super( super(
constants.NetworkSettingsPageTitle, constants.NetworkSettingsPageTitle,
constants.NetworkSettingsPageDescription, constants.NetworkSettingsPageDescription,
wizard _model.wizard
); );
} }
@@ -61,13 +61,13 @@ export class NetworkSettingsPage extends BasePage {
.withFormItems( .withFormItems(
[ [
{ {
component: this.wizard.createFormRowComponent(view, constants.VirtualNetworkDropdownLabel, '', this._virtualNetworkFlexContainer, true) component: this._model.createFormRowComponent(view, constants.VirtualNetworkDropdownLabel, '', this._virtualNetworkFlexContainer, true)
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.SubnetDropdownLabel, '', this._subnetFlexContainer, true) component: this._model.createFormRowComponent(view, constants.SubnetDropdownLabel, '', this._subnetFlexContainer, true)
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.PublicIPDropdownLabel, '', this._publicIpFlexContainer, true) component: this._model.createFormRowComponent(view, constants.PublicIPDropdownLabel, '', this._publicIpFlexContainer, true)
}, },
{ {
component: this._vmRDPAllowCheckbox component: this._vmRDPAllowCheckbox
@@ -88,7 +88,7 @@ export class NetworkSettingsPage extends BasePage {
this.populateVirtualNetworkDropdown(); this.populateVirtualNetworkDropdown();
this.populatePublicIpkDropdown(); this.populatePublicIpkDropdown();
this.liveValidation = false; this.liveValidation = false;
this.wizard.wizardObject.registerNavigationValidator(async (pcInfo) => { this._model.wizard.wizardObject.registerNavigationValidator(async (pcInfo) => {
if (pcInfo.newPage < pcInfo.lastPage) { if (pcInfo.newPage < pcInfo.lastPage) {
return true; return true;
} }
@@ -103,7 +103,7 @@ export class NetworkSettingsPage extends BasePage {
} }
public async onLeave(): Promise<void> { public async onLeave(): Promise<void> {
this.wizard.wizardObject.registerNavigationValidator((pcInfo) => { this._model.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
return true; return true;
}); });
} }
@@ -125,7 +125,7 @@ export class NetworkSettingsPage extends BasePage {
}).component(); }).component();
this._virtualNetworkDropdown.onValueChanged((value) => { this._virtualNetworkDropdown.onValueChanged((value) => {
this.wizard.model.virtualNetworkName = (this._virtualNetworkDropdown.value as azdata.CategoryValue).name; this._model.virtualNetworkName = (this._virtualNetworkDropdown.value as azdata.CategoryValue).name;
this.populateSubnetDropdown(); this.populateSubnetDropdown();
}); });
@@ -136,7 +136,7 @@ export class NetworkSettingsPage extends BasePage {
}).component(); }).component();
this._newVirtualNetworkText.onTextChanged((e) => { this._newVirtualNetworkText.onTextChanged((e) => {
this.wizard.model.virtualNetworkName = e; this._model.virtualNetworkName = e;
this.activateRealTimeFormValidation(); this.activateRealTimeFormValidation();
}); });
@@ -182,28 +182,28 @@ export class NetworkSettingsPage extends BasePage {
let newVirtualNetwork = this._newVirtualNetworkCheckbox.checked; let newVirtualNetwork = this._newVirtualNetworkCheckbox.checked;
this.wizard.model.newVirtualNetwork = newVirtualNetwork ? 'True' : 'False'; this._model.newVirtualNetwork = newVirtualNetwork ? 'True' : 'False';
if (newVirtualNetwork) { if (newVirtualNetwork) {
this.wizard.changeComponentDisplay(this._virtualNetworkDropdown, 'none'); this._model.changeComponentDisplay(this._virtualNetworkDropdown, 'none');
this.wizard.changeComponentDisplay(this._newVirtualNetworkText, 'block'); this._model.changeComponentDisplay(this._newVirtualNetworkText, 'block');
this._newSubnetCheckbox.enabled = false; this._newSubnetCheckbox.enabled = false;
this.wizard.changeComponentDisplay(this._subnetDropdown, 'none'); this._model.changeComponentDisplay(this._subnetDropdown, 'none');
this.wizard.changeComponentDisplay(this._newsubnetText, 'block'); this._model.changeComponentDisplay(this._newsubnetText, 'block');
this.wizard.model.virtualNetworkName = this._newVirtualNetworkText.value!; this._model.virtualNetworkName = this._newVirtualNetworkText.value!;
this.wizard.model.newSubnet = 'True'; this._model.newSubnet = 'True';
this.wizard.model.subnetName = this._newsubnetText.value!; this._model.subnetName = this._newsubnetText.value!;
} else { } else {
this.wizard.changeComponentDisplay(this._virtualNetworkDropdown, 'block'); this._model.changeComponentDisplay(this._virtualNetworkDropdown, 'block');
this.wizard.changeComponentDisplay(this._newVirtualNetworkText, 'none'); this._model.changeComponentDisplay(this._newVirtualNetworkText, 'none');
this._newSubnetCheckbox.enabled = true; this._newSubnetCheckbox.enabled = true;
this.wizard.changeComponentDisplay(this._subnetDropdown, 'block'); this._model.changeComponentDisplay(this._subnetDropdown, 'block');
this.wizard.changeComponentDisplay(this._newsubnetText, 'none'); this._model.changeComponentDisplay(this._newsubnetText, 'none');
this.wizard.model.virtualNetworkName = (this._virtualNetworkDropdown.value as azdata.CategoryValue).name; this._model.virtualNetworkName = (this._virtualNetworkDropdown.value as azdata.CategoryValue).name;
this.wizard.model.newSubnet = this._newSubnetCheckbox.checked! ? 'True' : 'False'; this._model.newSubnet = this._newSubnetCheckbox.checked! ? 'True' : 'False';
} }
} }
@@ -225,7 +225,7 @@ export class NetworkSettingsPage extends BasePage {
}).component(); }).component();
this._subnetDropdown.onValueChanged((value) => { this._subnetDropdown.onValueChanged((value) => {
this.wizard.model.subnetName = (this._subnetDropdown.value as azdata.CategoryValue).name; this._model.subnetName = (this._subnetDropdown.value as azdata.CategoryValue).name;
}); });
this._newsubnetText = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{ this._newsubnetText = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{
@@ -235,7 +235,7 @@ export class NetworkSettingsPage extends BasePage {
}).component(); }).component();
this._newsubnetText.onTextChanged((e) => { this._newsubnetText.onTextChanged((e) => {
this.wizard.model.subnetName = e; this._model.subnetName = e;
this.activateRealTimeFormValidation(); this.activateRealTimeFormValidation();
}); });
@@ -278,16 +278,16 @@ export class NetworkSettingsPage extends BasePage {
let newSubnet = this._newSubnetCheckbox.checked!; let newSubnet = this._newSubnetCheckbox.checked!;
this.wizard.model.newSubnet = newSubnet ? 'True' : 'False'; this._model.newSubnet = newSubnet ? 'True' : 'False';
if (newSubnet) { if (newSubnet) {
this.wizard.changeComponentDisplay(this._subnetDropdown, 'none'); this._model.changeComponentDisplay(this._subnetDropdown, 'none');
this.wizard.changeComponentDisplay(this._newsubnetText, 'block'); this._model.changeComponentDisplay(this._newsubnetText, 'block');
this.wizard.model.subnetName = this._newsubnetText.value!; this._model.subnetName = this._newsubnetText.value!;
} else { } else {
this.wizard.changeComponentDisplay(this._subnetDropdown, 'block'); this._model.changeComponentDisplay(this._subnetDropdown, 'block');
this.wizard.changeComponentDisplay(this._newsubnetText, 'none'); this._model.changeComponentDisplay(this._newsubnetText, 'none');
this.wizard.model.subnetName = (this._subnetDropdown.value as azdata.CategoryValue).name; this._model.subnetName = (this._subnetDropdown.value as azdata.CategoryValue).name;
} }
} }
@@ -308,7 +308,7 @@ export class NetworkSettingsPage extends BasePage {
}).component(); }).component();
this._publicIpDropdown.onValueChanged((value) => { this._publicIpDropdown.onValueChanged((value) => {
this.wizard.model.publicIpName = (this._publicIpDropdown.value as azdata.CategoryValue).name; this._model.publicIpName = (this._publicIpDropdown.value as azdata.CategoryValue).name;
}); });
this._publicIpNetworkText = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{ this._publicIpNetworkText = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{
@@ -317,11 +317,11 @@ export class NetworkSettingsPage extends BasePage {
}).component(); }).component();
this._publicIpNetworkText.onTextChanged((e) => { this._publicIpNetworkText.onTextChanged((e) => {
this.wizard.model.publicIpName = e; this._model.publicIpName = e;
this.activateRealTimeFormValidation(); this.activateRealTimeFormValidation();
}); });
this.wizard.changeComponentDisplay(this._publicIpNetworkText, 'none'); this._model.changeComponentDisplay(this._publicIpNetworkText, 'none');
this._publicIpFlexContainer = view.modelBuilder.flexContainer().withLayout({ this._publicIpFlexContainer = view.modelBuilder.flexContainer().withLayout({
flexFlow: 'column', flexFlow: 'column',
@@ -362,16 +362,16 @@ export class NetworkSettingsPage extends BasePage {
private toggleNewPublicIp() { private toggleNewPublicIp() {
let newPip = this._newPublicIpCheckbox.checked!; let newPip = this._newPublicIpCheckbox.checked!;
this.wizard.model.newPublicIp = newPip ? 'True' : 'False'; this._model.newPublicIp = newPip ? 'True' : 'False';
if (newPip) { if (newPip) {
this.wizard.changeComponentDisplay(this._publicIpDropdown, 'none'); this._model.changeComponentDisplay(this._publicIpDropdown, 'none');
this.wizard.changeComponentDisplay(this._publicIpNetworkText, 'block'); this._model.changeComponentDisplay(this._publicIpNetworkText, 'block');
this.wizard.model.publicIpName = this._publicIpNetworkText.value!; this._model.publicIpName = this._publicIpNetworkText.value!;
} else { } else {
this.wizard.changeComponentDisplay(this._publicIpDropdown, 'block'); this._model.changeComponentDisplay(this._publicIpDropdown, 'block');
this.wizard.changeComponentDisplay(this._publicIpNetworkText, 'none'); this._model.changeComponentDisplay(this._publicIpNetworkText, 'none');
this.wizard.model.publicIpName = (this._publicIpDropdown.value as azdata.CategoryValue).name; this._model.publicIpName = (this._publicIpDropdown.value as azdata.CategoryValue).name;
} }
} }
@@ -380,21 +380,21 @@ export class NetworkSettingsPage extends BasePage {
label: constants.RDPAllowCheckboxLabel, label: constants.RDPAllowCheckboxLabel,
}).component(); }).component();
this._vmRDPAllowCheckbox.onChanged((value) => { this._vmRDPAllowCheckbox.onChanged((value) => {
this.wizard.model.allowRDP = (value) ? 'True' : 'False'; this._model.allowRDP = (value) ? 'True' : 'False';
}); });
this.wizard.model.allowRDP = 'False'; this._model.allowRDP = 'False';
} }
public async getVirtualNetworks(): Promise<any> { public async getVirtualNetworks(): Promise<any> {
let url = `https://management.azure.com` + let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` + `/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Network/virtualNetworks?api-version=2020-05-01`; `/providers/Microsoft.Network/virtualNetworks?api-version=2020-05-01`;
let response = await this.wizard.getRequest(url); let response = await this._model.getRequest(url);
let dropdownValues = response.data.value.filter((value: any) => { let dropdownValues = response.data.value.filter((value: any) => {
return value.location === this.wizard.model.azureRegion; return value.location === this._model.azureRegion;
}).map((value: any) => { }).map((value: any) => {
let resourceGroupName = value.id.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), ''); let resourceGroupName = value.id.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
return { return {
@@ -406,13 +406,13 @@ export class NetworkSettingsPage extends BasePage {
} }
public async getSubnets(): Promise<any> { public async getSubnets(): Promise<any> {
if (!this.wizard.model.virtualNetworkName) { if (!this._model.virtualNetworkName) {
return; return;
} }
let url = `https://management.azure.com` + let url = `https://management.azure.com` +
`${this.wizard.model.virtualNetworkName}` + `${this._model.virtualNetworkName}` +
`/subnets?api-version=2020-05-01`; `/subnets?api-version=2020-05-01`;
let response = await this.wizard.getRequest(url); let response = await this._model.getRequest(url);
let dropdownValues = response.data.value.map((value: any) => { let dropdownValues = response.data.value.map((value: any) => {
return { return {
name: value.id, name: value.id,
@@ -424,11 +424,11 @@ export class NetworkSettingsPage extends BasePage {
public async getPips(): Promise<any> { public async getPips(): Promise<any> {
let url = `https://management.azure.com` + let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` + `/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Network/publicIPAddresses?api-version=2020-05-01`; `/providers/Microsoft.Network/publicIPAddresses?api-version=2020-05-01`;
let response = await this.wizard.getRequest(url); let response = await this._model.getRequest(url);
let dropdownValues = response.data.value.filter((value: any) => { let dropdownValues = response.data.value.filter((value: any) => {
return value.location === this.wizard.model.azureRegion; return value.location === this._model.azureRegion;
}).map((value: any) => { }).map((value: any) => {
let resourceGroupName = value.id.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), ''); let resourceGroupName = value.id.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
return { return {
@@ -441,37 +441,37 @@ export class NetworkSettingsPage extends BasePage {
protected async validatePage(): Promise<string> { protected async validatePage(): Promise<string> {
const errorMessages = []; const errorMessages = [];
if (this.wizard.model.newVirtualNetwork === 'True') { if (this._model.newVirtualNetwork === 'True') {
if (this.wizard.model.virtualNetworkName.length < 2 || this.wizard.model.virtualNetworkName.length > 64) { if (this._model.virtualNetworkName.length < 2 || this._model.virtualNetworkName.length > 64) {
errorMessages.push(localize('deployAzureSQLVM.VnetNameLengthError', "Virtual Network name must be between 2 and 64 characters long")); errorMessages.push(localize('deployAzureSQLVM.VnetNameLengthError', "Virtual Network name must be between 2 and 64 characters long"));
} }
} else { } else {
if (this.wizard.model.virtualNetworkName === 'None') { if (this._model.virtualNetworkName === 'None') {
errorMessages.push(localize('deployAzureSQLVM.NewVnetError', "Create a new virtual network")); errorMessages.push(localize('deployAzureSQLVM.NewVnetError', "Create a new virtual network"));
} }
} }
if (this.wizard.model.newSubnet === 'True') { if (this._model.newSubnet === 'True') {
if (this.wizard.model.subnetName.length < 1 || this.wizard.model.subnetName.length > 80) { if (this._model.subnetName.length < 1 || this._model.subnetName.length > 80) {
errorMessages.push(localize('deployAzureSQLVM.SubnetNameLengthError', "Subnet name must be between 1 and 80 characters long")); errorMessages.push(localize('deployAzureSQLVM.SubnetNameLengthError', "Subnet name must be between 1 and 80 characters long"));
} }
} else { } else {
if (this.wizard.model.subnetName === 'None') { if (this._model.subnetName === 'None') {
errorMessages.push(localize('deployAzureSQLVM.NewSubnetError', "Create a new sub network")); errorMessages.push(localize('deployAzureSQLVM.NewSubnetError', "Create a new sub network"));
} }
} }
if (this.wizard.model.newPublicIp === 'True') { if (this._model.newPublicIp === 'True') {
if (this.wizard.model.publicIpName.length < 1 || this.wizard.model.publicIpName.length > 80) { if (this._model.publicIpName.length < 1 || this._model.publicIpName.length > 80) {
errorMessages.push(localize('deployAzureSQLVM.PipNameError', "Public IP name must be between 1 and 80 characters long")); errorMessages.push(localize('deployAzureSQLVM.PipNameError', "Public IP name must be between 1 and 80 characters long"));
} }
} else { } else {
if (this.wizard.model.publicIpName === 'None') { if (this._model.publicIpName === 'None') {
errorMessages.push(localize('deployAzureSQLVM.NewPipError', "Create a new new public Ip")); errorMessages.push(localize('deployAzureSQLVM.NewPipError', "Create a new new public Ip"));
} }
} }
this.wizard.showErrorMessage(errorMessages.join('\n')); this._model.wizard.showErrorMessage(errorMessages.join('\n'));
return errorMessages.join('\n'); return errorMessages.join('\n');
} }

View File

@@ -6,9 +6,9 @@
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import { EOL } from 'os'; import { EOL } from 'os';
import * as constants from '../constants'; import * as constants from '../constants';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
import { BasePage } from './basePage'; import { BasePage } from './basePage';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import { DeployAzureSQLVMWizardModel } from '../deployAzureSQLVMWizardModel';
import * as localizedConstants from '../../../localizedConstants'; import * as localizedConstants from '../../../localizedConstants';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -29,11 +29,11 @@ export class SqlServerSettingsPage extends BasePage {
private _form!: azdata.FormContainer; private _form!: azdata.FormContainer;
constructor(wizard: DeployAzureSQLVMWizard) { constructor(private _model: DeployAzureSQLVMWizardModel) {
super( super(
constants.SqlServerSettingsPageTitle, constants.SqlServerSettingsPageTitle,
'', '',
wizard _model.wizard
); );
} }
@@ -51,13 +51,13 @@ export class SqlServerSettingsPage extends BasePage {
.withFormItems( .withFormItems(
[ [
{ {
component: this.wizard.createFormRowComponent(view, constants.SqlConnectivityTypeDropdownLabel, '', this._sqlConnectivityDropdown, true) component: this._model.createFormRowComponent(view, constants.SqlConnectivityTypeDropdownLabel, '', this._sqlConnectivityDropdown, true)
}, },
{ {
component: this._portTextRow component: this._portTextRow
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.SqlEnableSQLAuthenticationLabel, '', this._sqlAuthenticationDropdown, true) component: this._model.createFormRowComponent(view, constants.SqlEnableSQLAuthenticationLabel, '', this._sqlAuthenticationDropdown, true)
}, },
{ {
component: this._sqlAuthenticationTextRow component: this._sqlAuthenticationTextRow
@@ -84,7 +84,7 @@ export class SqlServerSettingsPage extends BasePage {
this.liveValidation = false; this.liveValidation = false;
this.wizard.wizardObject.registerNavigationValidator(async (pcInfo) => { this._model.wizard.wizardObject.registerNavigationValidator(async (pcInfo) => {
if (pcInfo.newPage < pcInfo.lastPage) { if (pcInfo.newPage < pcInfo.lastPage) {
return true; return true;
} }
@@ -101,7 +101,7 @@ export class SqlServerSettingsPage extends BasePage {
} }
public async onLeave(): Promise<void> { public async onLeave(): Promise<void> {
this.wizard.wizardObject.registerNavigationValidator((pcInfo) => { this._model.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
return true; return true;
}); });
} }
@@ -131,17 +131,17 @@ export class SqlServerSettingsPage extends BasePage {
} }
}).component(); }).component();
this.wizard.model.sqlConnectivityType = (this._sqlConnectivityDropdown.value as azdata.CategoryValue).name; this._model.sqlConnectivityType = (this._sqlConnectivityDropdown.value as azdata.CategoryValue).name;
this._sqlConnectivityDropdown.onValueChanged((value) => { this._sqlConnectivityDropdown.onValueChanged((value) => {
let connectivityValue = (this._sqlConnectivityDropdown.value as azdata.CategoryValue).name; let connectivityValue = (this._sqlConnectivityDropdown.value as azdata.CategoryValue).name;
this.wizard.model.sqlConnectivityType = connectivityValue; this._model.sqlConnectivityType = connectivityValue;
if (connectivityValue === 'local') { if (connectivityValue === 'local') {
this.wizard.changeRowDisplay(this._portTextRow, 'none'); this._model.changeRowDisplay(this._portTextRow, 'none');
} else { } else {
this.wizard.changeRowDisplay(this._portTextRow, 'block'); this._model.changeRowDisplay(this._portTextRow, 'block');
} }
}); });
@@ -156,11 +156,11 @@ export class SqlServerSettingsPage extends BasePage {
}).component(); }).component();
this._portTextBox.onTextChanged((value) => { this._portTextBox.onTextChanged((value) => {
this.wizard.model.port = value; this._model.port = value;
this.activateRealTimeFormValidation(); this.activateRealTimeFormValidation();
}); });
this._portTextRow = this.wizard.createFormRowComponent(view, constants.SqlPortLabel, '', this._portTextBox, true); this._portTextRow = this._model.createFormRowComponent(view, constants.SqlPortLabel, '', this._portTextBox, true);
} }
private createSqlAuthentication(view: azdata.ModelView) { private createSqlAuthentication(view: azdata.ModelView) {
@@ -181,39 +181,39 @@ export class SqlServerSettingsPage extends BasePage {
this._sqlAuthenticationDropdown.onValueChanged((value) => { this._sqlAuthenticationDropdown.onValueChanged((value) => {
let dropdownValue = (this._sqlAuthenticationDropdown.value as azdata.CategoryValue).name; let dropdownValue = (this._sqlAuthenticationDropdown.value as azdata.CategoryValue).name;
let displayValue: 'block' | 'none' = dropdownValue === 'True' ? 'block' : 'none'; let displayValue: 'block' | 'none' = dropdownValue === 'True' ? 'block' : 'none';
this.wizard.changeRowDisplay(this._sqlAuthenticationTextRow, displayValue); this._model.changeRowDisplay(this._sqlAuthenticationTextRow, displayValue);
this.wizard.changeRowDisplay(this._sqlAuthenticationPasswordTextRow, displayValue); this._model.changeRowDisplay(this._sqlAuthenticationPasswordTextRow, displayValue);
this.wizard.changeRowDisplay(this._sqlAuthenticationPasswordConfirmationTextRow, displayValue); this._model.changeRowDisplay(this._sqlAuthenticationPasswordConfirmationTextRow, displayValue);
this.wizard.model.enableSqlAuthentication = dropdownValue; this._model.enableSqlAuthentication = dropdownValue;
}); });
this.wizard.model.enableSqlAuthentication = (this._sqlAuthenticationDropdown.value as azdata.CategoryValue).name; this._model.enableSqlAuthentication = (this._sqlAuthenticationDropdown.value as azdata.CategoryValue).name;
this._sqlAuthenticationTextbox = view.modelBuilder.inputBox().component(); this._sqlAuthenticationTextbox = view.modelBuilder.inputBox().component();
this._sqlAuthenticationTextRow = this.wizard.createFormRowComponent(view, constants.SqlAuthenticationUsernameLabel, '', this._sqlAuthenticationTextbox, true); this._sqlAuthenticationTextRow = this._model.createFormRowComponent(view, constants.SqlAuthenticationUsernameLabel, '', this._sqlAuthenticationTextbox, true);
this._sqlAuthenticationPasswordTextbox = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{ this._sqlAuthenticationPasswordTextbox = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{
inputType: 'password' inputType: 'password'
}).component(); }).component();
this._sqlAuthenticationPasswordTextRow = this.wizard.createFormRowComponent(view, constants.SqlAuthenticationPasswordLabel, '', this._sqlAuthenticationPasswordTextbox, true); this._sqlAuthenticationPasswordTextRow = this._model.createFormRowComponent(view, constants.SqlAuthenticationPasswordLabel, '', this._sqlAuthenticationPasswordTextbox, true);
this._sqlAuthenticationPasswordConfirmationTextbox = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{ this._sqlAuthenticationPasswordConfirmationTextbox = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{
inputType: 'password' inputType: 'password'
}).component(); }).component();
this._sqlAuthenticationPasswordConfirmationTextRow = this.wizard.createFormRowComponent(view, constants.SqlAuthenticationConfirmPasswordLabel, '', this._sqlAuthenticationPasswordConfirmationTextbox, true); this._sqlAuthenticationPasswordConfirmationTextRow = this._model.createFormRowComponent(view, constants.SqlAuthenticationConfirmPasswordLabel, '', this._sqlAuthenticationPasswordConfirmationTextbox, true);
this._sqlAuthenticationTextbox.onTextChanged((value) => { this._sqlAuthenticationTextbox.onTextChanged((value) => {
this.wizard.model.sqlAuthenticationUsername = value; this._model.sqlAuthenticationUsername = value;
this.activateRealTimeFormValidation(); this.activateRealTimeFormValidation();
}); });
this._sqlAuthenticationPasswordTextbox.onTextChanged((value) => { this._sqlAuthenticationPasswordTextbox.onTextChanged((value) => {
this.wizard.model.sqlAuthenticationPassword = value; this._model.sqlAuthenticationPassword = value;
this.activateRealTimeFormValidation(); this.activateRealTimeFormValidation();
}); });
@@ -235,7 +235,7 @@ export class SqlServerSettingsPage extends BasePage {
errorMessages.push(localize('deployAzureSQLVM.SqlUsernameSpecialCharError', "Username cannot contain special characters \/\"\"[]:|<>+=;,?* .")); errorMessages.push(localize('deployAzureSQLVM.SqlUsernameSpecialCharError', "Username cannot contain special characters \/\"\"[]:|<>+=;,?* ."));
} }
errorMessages.push(this.wizard.validatePassword(this._sqlAuthenticationPasswordTextbox.value!)); errorMessages.push(this._model.validatePassword(this._sqlAuthenticationPasswordTextbox.value!));
if (this._sqlAuthenticationPasswordTextbox.value !== this._sqlAuthenticationPasswordConfirmationTextbox.value) { if (this._sqlAuthenticationPasswordTextbox.value !== this._sqlAuthenticationPasswordConfirmationTextbox.value) {
errorMessages.push(localize('deployAzureSQLVM.SqlConfirmPasswordError', "Password and confirm password must match.")); errorMessages.push(localize('deployAzureSQLVM.SqlConfirmPasswordError', "Password and confirm password must match."));
@@ -243,7 +243,7 @@ export class SqlServerSettingsPage extends BasePage {
} }
this.wizard.showErrorMessage(errorMessages.join(EOL)); this._model.wizard.showErrorMessage(errorMessages.join(EOL));
return errorMessages.join(EOL); return errorMessages.join(EOL);
} }

View File

@@ -4,23 +4,23 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import { WizardPageBase } from '../../wizardPageBase';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
import * as constants from '../constants'; import * as constants from '../constants';
import { SectionInfo, LabelPosition, FontWeight, FieldType } from '../../../interfaces'; import { SectionInfo, LabelPosition, FontWeight, FieldType } from '../../../interfaces';
import { createSection } from '../../modelViewUtils'; import { createSection } from '../../modelViewUtils';
import { BasePage } from './basePage';
import { DeployAzureSQLVMWizardModel } from '../deployAzureSQLVMWizardModel';
export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard> { export class AzureSQLVMSummaryPage extends BasePage {
private formItems: azdata.FormComponent[] = []; private formItems: azdata.FormComponent[] = [];
private _form!: azdata.FormBuilder; private _form!: azdata.FormBuilder;
private _view!: azdata.ModelView; private _view!: azdata.ModelView;
constructor(wizard: DeployAzureSQLVMWizard) { constructor(private _model: DeployAzureSQLVMWizardModel) {
super( super(
'Summary', 'Summary',
'', '',
wizard _model.wizard
); );
} }
@@ -41,8 +41,6 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
this.formItems = []; this.formItems = [];
let model = this.wizard.model;
const labelWidth = '150px'; const labelWidth = '150px';
const inputWidth = '400px'; const inputWidth = '400px';
const fieldHeight = '20px'; const fieldHeight = '20px';
@@ -60,7 +58,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.AzureAccountDropdownLabel, label: constants.AzureAccountDropdownLabel,
defaultValue: model.azureAccount.displayInfo.displayName, defaultValue: this._model.azureAccount.displayInfo.displayName,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
}, },
] ]
@@ -70,7 +68,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.AzureAccountSubscriptionDropdownLabel, label: constants.AzureAccountSubscriptionDropdownLabel,
defaultValue: model.azureSubscriptionDisplayName, defaultValue: this._model.azureSubscriptionDisplayName,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
} }
] ]
@@ -80,7 +78,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.AzureAccountResourceGroupDropdownLabel, label: constants.AzureAccountResourceGroupDropdownLabel,
defaultValue: model.azureResouceGroup, defaultValue: this._model.azureResouceGroup,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
} }
] ]
@@ -90,7 +88,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.AzureAccountRegionDropdownLabel, label: constants.AzureAccountRegionDropdownLabel,
defaultValue: model.azureRegion, defaultValue: this._model.azureRegion,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
} }
] ]
@@ -110,7 +108,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.VmNameTextBoxLabel, label: constants.VmNameTextBoxLabel,
defaultValue: model.vmName, defaultValue: this._model.vmName,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
} }
] ]
@@ -120,7 +118,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.SqlAuthenticationUsernameLabel, label: constants.SqlAuthenticationUsernameLabel,
defaultValue: model.vmUsername, defaultValue: this._model.vmUsername,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
}, },
] ]
@@ -130,7 +128,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.VmImageDropdownLabel, label: constants.VmImageDropdownLabel,
defaultValue: model.vmImage, defaultValue: this._model.vmImage,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
} }
] ]
@@ -140,7 +138,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.VmSkuDropdownLabel, label: constants.VmSkuDropdownLabel,
defaultValue: model.vmImageSKU, defaultValue: this._model.vmImageSKU,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
}, },
] ]
@@ -150,7 +148,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.VmVersionDropdownLabel, label: constants.VmVersionDropdownLabel,
defaultValue: model.vmImageVersion, defaultValue: this._model.vmImageVersion,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
} }
] ]
@@ -160,7 +158,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.VmSizeDropdownLabel, label: constants.VmSizeDropdownLabel,
defaultValue: model.vmSize, defaultValue: this._model.vmSize,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
} }
] ]
@@ -180,7 +178,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.VirtualNetworkDropdownLabel, label: constants.VirtualNetworkDropdownLabel,
defaultValue: ((model.newVirtualNetwork === 'True' ? '(new) ' : '') + this.processVnetName()), defaultValue: ((this._model.newVirtualNetwork === 'True' ? '(new) ' : '') + this.processVnetName()),
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
}, },
] ]
@@ -191,7 +189,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.SubnetDropdownLabel, label: constants.SubnetDropdownLabel,
defaultValue: ((model.newSubnet === 'True' ? '(new) ' : '') + this.processSubnetName()), defaultValue: ((this._model.newSubnet === 'True' ? '(new) ' : '') + this.processSubnetName()),
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
}, },
] ]
@@ -202,7 +200,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.PublicIPDropdownLabel, label: constants.PublicIPDropdownLabel,
defaultValue: ((model.newPublicIp === 'True' ? '(new) ' : '') + this.processPublicIp()), defaultValue: ((this._model.newPublicIp === 'True' ? '(new) ' : '') + this.processPublicIp()),
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
} }
] ]
@@ -225,13 +223,13 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.SqlConnectivityTypeDropdownLabel, label: constants.SqlConnectivityTypeDropdownLabel,
defaultValue: model.sqlConnectivityType, defaultValue: this._model.sqlConnectivityType,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
} }
] ]
}); });
if (model.sqlConnectivityType !== 'local') { if (this._model.sqlConnectivityType !== 'local') {
sqlServerSettingsPage.rows?.push({ sqlServerSettingsPage.rows?.push({
items: [ items: [
{ {
@@ -250,19 +248,19 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.SqlEnableSQLAuthenticationLabel, label: constants.SqlEnableSQLAuthenticationLabel,
defaultValue: (model.enableSqlAuthentication === 'True' ? 'Yes ' : 'No '), defaultValue: (this._model.enableSqlAuthentication === 'True' ? 'Yes ' : 'No '),
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
} }
] ]
}); });
if (model.enableSqlAuthentication === 'True') { if (this._model.enableSqlAuthentication === 'True') {
sqlServerSettingsPage.rows?.push({ sqlServerSettingsPage.rows?.push({
items: [ items: [
{ {
type: FieldType.ReadonlyText, type: FieldType.ReadonlyText,
label: constants.SqlAuthenticationUsernameLabel, label: constants.SqlAuthenticationUsernameLabel,
defaultValue: model.sqlAuthenticationUsername, defaultValue: this._model.sqlAuthenticationUsername,
labelCSSStyles: { fontWeight: FontWeight.Bold } labelCSSStyles: { fontWeight: FontWeight.Bold }
} }
] ]
@@ -337,31 +335,31 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
} }
public processVnetName(): string { public processVnetName(): string {
if (this.wizard.model.newVirtualNetwork === 'True') { if (this._model.newVirtualNetwork === 'True') {
return this.wizard.model.virtualNetworkName; return this._model.virtualNetworkName;
} }
let resourceGroupName = this.wizard.model.virtualNetworkName.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), ''); let resourceGroupName = this._model.virtualNetworkName.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
let vnetName = this.wizard.model.virtualNetworkName.replace(RegExp('^(.*?)/virtualNetworks/'), ''); let vnetName = this._model.virtualNetworkName.replace(RegExp('^(.*?)/virtualNetworks/'), '');
return `(${resourceGroupName}) ${vnetName}`; return `(${resourceGroupName}) ${vnetName}`;
} }
public processSubnetName(): string { public processSubnetName(): string {
if (this.wizard.model.newSubnet === 'True') { if (this._model.newSubnet === 'True') {
return this.wizard.model.subnetName; return this._model.subnetName;
} }
let subnetName = this.wizard.model.subnetName.replace(RegExp('^(.*?)/subnets/'), ''); let subnetName = this._model.subnetName.replace(RegExp('^(.*?)/subnets/'), '');
return `${subnetName}`; return `${subnetName}`;
} }
public processPublicIp(): string { public processPublicIp(): string {
if (this.wizard.model.newPublicIp === 'True') { if (this._model.newPublicIp === 'True') {
return this.wizard.model.publicIpName; return this._model.publicIpName;
} }
let resourceGroupName = this.wizard.model.publicIpName.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), ''); let resourceGroupName = this._model.publicIpName.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
let pipName = this.wizard.model.publicIpName.replace(RegExp('^(.*?)/publicIPAddresses/'), ''); let pipName = this._model.publicIpName.replace(RegExp('^(.*?)/publicIPAddresses/'), '');
return `(${resourceGroupName}) ${pipName}`; return `(${resourceGroupName}) ${pipName}`;
} }
} }

View File

@@ -6,9 +6,9 @@
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import { EOL } from 'os'; import { EOL } from 'os';
import * as constants from '../constants'; import * as constants from '../constants';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
import { BasePage } from './basePage';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import { BasePage } from './basePage';
import { DeployAzureSQLVMWizardModel } from '../deployAzureSQLVMWizardModel';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
export class VmSettingsPage extends BasePage { export class VmSettingsPage extends BasePage {
@@ -42,11 +42,11 @@ export class VmSettingsPage extends BasePage {
private _form!: azdata.FormContainer; private _form!: azdata.FormContainer;
constructor(wizard: DeployAzureSQLVMWizard) { constructor(private _model: DeployAzureSQLVMWizardModel) {
super( super(
constants.VmSettingsPageTitle, constants.VmSettingsPageTitle,
'', '',
wizard _model.wizard
); );
} }
@@ -71,28 +71,28 @@ export class VmSettingsPage extends BasePage {
.withFormItems( .withFormItems(
[ [
{ {
component: this.wizard.createFormRowComponent(view, constants.VmNameTextBoxLabel, '', this._vmNameTextBox, true) component: this._model.createFormRowComponent(view, constants.VmNameTextBoxLabel, '', this._vmNameTextBox, true)
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.VmAdminUsernameTextBoxLabel, '', this._adminUsernameTextBox, true) component: this._model.createFormRowComponent(view, constants.VmAdminUsernameTextBoxLabel, '', this._adminUsernameTextBox, true)
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.VmAdminPasswordTextBoxLabel, '', this._adminPasswordTextBox, true) component: this._model.createFormRowComponent(view, constants.VmAdminPasswordTextBoxLabel, '', this._adminPasswordTextBox, true)
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.VmAdminConfirmPasswordTextBoxLabel, '', this._adminComfirmPasswordTextBox, true) component: this._model.createFormRowComponent(view, constants.VmAdminConfirmPasswordTextBoxLabel, '', this._adminComfirmPasswordTextBox, true)
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.VmImageDropdownLabel, '', this._vmImageDropdown, true) component: this._model.createFormRowComponent(view, constants.VmImageDropdownLabel, '', this._vmImageDropdown, true)
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.VmSkuDropdownLabel, '', this._vmImageSkuDropdown, true) component: this._model.createFormRowComponent(view, constants.VmSkuDropdownLabel, '', this._vmImageSkuDropdown, true)
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.VmVersionDropdownLabel, '', this._vmImageVersionDropdown, true) component: this._model.createFormRowComponent(view, constants.VmVersionDropdownLabel, '', this._vmImageVersionDropdown, true)
}, },
{ {
component: this.wizard.createFormRowComponent(view, constants.VmSizeDropdownLabel, '', this._vmSizeDropdown, true) component: this._model.createFormRowComponent(view, constants.VmSizeDropdownLabel, '', this._vmSizeDropdown, true)
}, },
{ {
component: this._vmSizeLearnMoreLink component: this._vmSizeLearnMoreLink
@@ -144,7 +144,7 @@ export class VmSettingsPage extends BasePage {
}).component(); }).component();
this._vmNameTextBox.onTextChanged((value) => { this._vmNameTextBox.onTextChanged((value) => {
this.wizard.model.vmName = value; this._model.vmName = value;
this.activateRealTimeFormValidation(); this.activateRealTimeFormValidation();
}); });
} }
@@ -154,7 +154,7 @@ export class VmSettingsPage extends BasePage {
}).component(); }).component();
this._adminUsernameTextBox.onTextChanged((value) => { this._adminUsernameTextBox.onTextChanged((value) => {
this.wizard.model.vmUsername = value; this._model.vmUsername = value;
this.activateRealTimeFormValidation(); this.activateRealTimeFormValidation();
}); });
} }
@@ -165,7 +165,7 @@ export class VmSettingsPage extends BasePage {
}).component(); }).component();
this._adminPasswordTextBox.onTextChanged((value) => { this._adminPasswordTextBox.onTextChanged((value) => {
this.wizard.model.vmPassword = value; this._model.vmPassword = value;
this.activateRealTimeFormValidation(); this.activateRealTimeFormValidation();
}); });
} }
@@ -185,7 +185,7 @@ export class VmSettingsPage extends BasePage {
}).component(); }).component();
this._vmImageDropdown.onValueChanged((value) => { this._vmImageDropdown.onValueChanged((value) => {
this.wizard.model.vmImage = (this._vmImageDropdown.value as azdata.CategoryValue).name; this._model.vmImage = (this._vmImageDropdown.value as azdata.CategoryValue).name;
this._vmImageSkuDropdown.loading = true; this._vmImageSkuDropdown.loading = true;
this._vmImageVersionDropdown.loading = true; this._vmImageVersionDropdown.loading = true;
this.populateVmImageSkuDropdown(); this.populateVmImageSkuDropdown();
@@ -199,16 +199,16 @@ export class VmSettingsPage extends BasePage {
this._vmImageVersionDropdown.loading = true; this._vmImageVersionDropdown.loading = true;
let url = `https://management.azure.com` + let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` + `/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Compute` + `/providers/Microsoft.Compute` +
`/locations/${this.wizard.model.azureRegion}` + `/locations/${this._model.azureRegion}` +
`/publishers/MicrosoftSQLServer` + `/publishers/MicrosoftSQLServer` +
`/artifacttypes/vmimage/offers` + `/artifacttypes/vmimage/offers` +
`?api-version=2019-12-01`; `?api-version=2019-12-01`;
let response = await this.wizard.getRequest(url, true); let response = await this._model.getRequest(url, true);
response.data = response.data.reverse(); response.data = response.data.reverse();
this.wizard.addDropdownValues( this._model.addDropdownValues(
this._vmImageDropdown, this._vmImageDropdown,
response.data.filter((value: any) => { response.data.filter((value: any) => {
return !new RegExp('-byol').test(value.name.toLowerCase()); return !new RegExp('-byol').test(value.name.toLowerCase());
@@ -227,7 +227,7 @@ export class VmSettingsPage extends BasePage {
}) })
); );
this.wizard.model.vmImage = (this._vmImageDropdown.value as azdata.CategoryValue).name; this._model.vmImage = (this._vmImageDropdown.value as azdata.CategoryValue).name;
this._vmImageDropdown.loading = false; this._vmImageDropdown.loading = false;
this.populateVmImageSkuDropdown(); this.populateVmImageSkuDropdown();
} }
@@ -237,7 +237,7 @@ export class VmSettingsPage extends BasePage {
}).component(); }).component();
this._vmImageSkuDropdown.onValueChanged((value) => { this._vmImageSkuDropdown.onValueChanged((value) => {
this.wizard.model.vmImageSKU = (this._vmImageSkuDropdown.value as azdata.CategoryValue).name; this._model.vmImageSKU = (this._vmImageSkuDropdown.value as azdata.CategoryValue).name;
this.populateVmImageVersionDropdown(); this.populateVmImageVersionDropdown();
}); });
@@ -246,16 +246,16 @@ export class VmSettingsPage extends BasePage {
private async populateVmImageSkuDropdown() { private async populateVmImageSkuDropdown() {
this._vmImageSkuDropdown.loading = true; this._vmImageSkuDropdown.loading = true;
let url = `https://management.azure.com` + let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` + `/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Compute` + `/providers/Microsoft.Compute` +
`/locations/${this.wizard.model.azureRegion}` + `/locations/${this._model.azureRegion}` +
`/publishers/MicrosoftSQLServer` + `/publishers/MicrosoftSQLServer` +
`/artifacttypes/vmimage/offers/${this.wizard.model.vmImage}` + `/artifacttypes/vmimage/offers/${this._model.vmImage}` +
`/skus?api-version=2019-12-01`; `/skus?api-version=2019-12-01`;
let response = await this.wizard.getRequest(url, true); let response = await this._model.getRequest(url, true);
this.wizard.addDropdownValues( this._model.addDropdownValues(
this._vmImageSkuDropdown, this._vmImageSkuDropdown,
response.data.map((value: any) => { response.data.map((value: any) => {
return { return {
@@ -265,7 +265,7 @@ export class VmSettingsPage extends BasePage {
}) })
); );
this.wizard.model.vmImageSKU = (this._vmImageSkuDropdown.value as azdata.CategoryValue).name; this._model.vmImageSKU = (this._vmImageSkuDropdown.value as azdata.CategoryValue).name;
this._vmImageSkuDropdown.loading = false; this._vmImageSkuDropdown.loading = false;
this.populateVmImageVersionDropdown(); this.populateVmImageVersionDropdown();
} }
@@ -275,24 +275,24 @@ export class VmSettingsPage extends BasePage {
}).component(); }).component();
this._vmImageVersionDropdown.onValueChanged((value) => { this._vmImageVersionDropdown.onValueChanged((value) => {
this.wizard.model.vmImageVersion = (this._vmImageVersionDropdown.value as azdata.CategoryValue).name; this._model.vmImageVersion = (this._vmImageVersionDropdown.value as azdata.CategoryValue).name;
}); });
} }
private async populateVmImageVersionDropdown() { private async populateVmImageVersionDropdown() {
this._vmImageVersionDropdown.loading = true; this._vmImageVersionDropdown.loading = true;
let url = `https://management.azure.com` + let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` + `/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Compute` + `/providers/Microsoft.Compute` +
`/locations/${this.wizard.model.azureRegion}` + `/locations/${this._model.azureRegion}` +
`/publishers/MicrosoftSQLServer` + `/publishers/MicrosoftSQLServer` +
`/artifacttypes/vmimage/offers/${this.wizard.model.vmImage}` + `/artifacttypes/vmimage/offers/${this._model.vmImage}` +
`/skus/${this.wizard.model.vmImageSKU}` + `/skus/${this._model.vmImageSKU}` +
`/versions?api-version=2019-12-01`; `/versions?api-version=2019-12-01`;
let response = await this.wizard.getRequest(url, true); let response = await this._model.getRequest(url, true);
this.wizard.addDropdownValues( this._model.addDropdownValues(
this._vmImageVersionDropdown, this._vmImageVersionDropdown,
response.data.map((value: any) => { response.data.map((value: any) => {
return { return {
@@ -302,7 +302,7 @@ export class VmSettingsPage extends BasePage {
}) })
); );
this.wizard.model.vmImageVersion = (this._vmImageVersionDropdown.value as azdata.CategoryValue).name; this._model.vmImageVersion = (this._vmImageVersionDropdown.value as azdata.CategoryValue).name;
this._vmImageVersionDropdown.loading = false; this._vmImageVersionDropdown.loading = false;
} }
@@ -313,7 +313,7 @@ export class VmSettingsPage extends BasePage {
}).component(); }).component();
this._vmSizeDropdown.onValueChanged((value) => { this._vmSizeDropdown.onValueChanged((value) => {
this.wizard.model.vmSize = (this._vmSizeDropdown.value as azdata.CategoryValue).name; this._model.vmSize = (this._vmSizeDropdown.value as azdata.CategoryValue).name;
}); });
this._vmSizeLearnMoreLink = view.modelBuilder.hyperlink().withProperties(<azdata.HyperlinkComponent>{ this._vmSizeLearnMoreLink = view.modelBuilder.hyperlink().withProperties(<azdata.HyperlinkComponent>{
@@ -326,12 +326,12 @@ export class VmSettingsPage extends BasePage {
private async populateVmSizeDropdown() { private async populateVmSizeDropdown() {
this._vmSizeDropdown.loading = true; this._vmSizeDropdown.loading = true;
let url = `https://management.azure.com` + let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` + `/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Compute` + `/providers/Microsoft.Compute` +
`/skus?api-version=2019-04-01` + `/skus?api-version=2019-04-01` +
`&$filter=location eq '${this.wizard.model.azureRegion}'`; `&$filter=location eq '${this._model.azureRegion}'`;
let response = await this.wizard.getRequest(url, true); let response = await this._model.getRequest(url, true);
let vmResouces: any[] = []; let vmResouces: any[] = [];
response.data.value.map((res: any) => { response.data.value.map((res: any) => {
@@ -375,7 +375,7 @@ export class VmSettingsPage extends BasePage {
value: dropDownValues[0], value: dropDownValues[0],
width: '480px' width: '480px'
}); });
this.wizard.model.vmSize = (this._vmSizeDropdown.value as azdata.CategoryValue).name; this._model.vmSize = (this._vmSizeDropdown.value as azdata.CategoryValue).name;
this._vmSizeDropdown.loading = false; this._vmSizeDropdown.loading = false;
} }
@@ -389,7 +389,7 @@ export class VmSettingsPage extends BasePage {
* 3. Cannot start with underscore and end with period or hyphen * 3. Cannot start with underscore and end with period or hyphen
* 4. Virtual machine name cannot contain special characters \/""[]:|<>+=;,?* * 4. Virtual machine name cannot contain special characters \/""[]:|<>+=;,?*
*/ */
let vmname = this.wizard.model.vmName; let vmname = this._model.vmName;
if (vmname.length < 1 && vmname.length > 15) { if (vmname.length < 1 && vmname.length > 15) {
errorMessages.push(localize('deployAzureSQLVM.VnameLengthError', "Virtual machine name must be between 1 and 15 characters long.")); errorMessages.push(localize('deployAzureSQLVM.VnameLengthError', "Virtual machine name must be between 1 and 15 characters long."));
} }
@@ -418,7 +418,7 @@ export class VmSettingsPage extends BasePage {
'aspnet', 'backup', 'console', 'david', 'guest', 'john', 'owner', 'root', 'server', 'sql', 'support', 'aspnet', 'backup', 'console', 'david', 'guest', 'john', 'owner', 'root', 'server', 'sql', 'support',
'support_388945a0', 'sys', 'test2', 'test3', 'user4', 'user5' 'support_388945a0', 'sys', 'test2', 'test3', 'user4', 'user5'
]; ];
let username = this.wizard.model.vmUsername; let username = this._model.vmUsername;
if (username.length < 1 || username.length > 20) { if (username.length < 1 || username.length > 20) {
errorMessages.push(localize('deployAzureSQLVM.VMUsernameLengthError', "Username must be between 1 and 20 characters long.")); errorMessages.push(localize('deployAzureSQLVM.VMUsernameLengthError', "Username must be between 1 and 20 characters long."));
} }
@@ -433,9 +433,9 @@ export class VmSettingsPage extends BasePage {
errorMessages.push(localize('deployAzureSQLVM.VMUsernameReservedWordsError', "Username must not include reserved words.")); errorMessages.push(localize('deployAzureSQLVM.VMUsernameReservedWordsError', "Username must not include reserved words."));
} }
errorMessages.push(this.wizard.validatePassword(this.wizard.model.vmPassword)); errorMessages.push(this._model.validatePassword(this._model.vmPassword));
if (this.wizard.model.vmPassword !== this._adminComfirmPasswordTextBox.value) { if (this._model.vmPassword !== this._adminComfirmPasswordTextBox.value) {
errorMessages.push(localize('deployAzureSQLVM.VMConfirmPasswordError', "Password and confirm password must match.")); errorMessages.push(localize('deployAzureSQLVM.VMConfirmPasswordError', "Password and confirm password must match."));
} }
@@ -443,19 +443,19 @@ export class VmSettingsPage extends BasePage {
errorMessages.push(localize('deployAzureSQLVM.vmDropdownSizeError', "Select a valid virtual machine size.")); errorMessages.push(localize('deployAzureSQLVM.vmDropdownSizeError', "Select a valid virtual machine size."));
} }
this.wizard.showErrorMessage(errorMessages.join(EOL)); this._model.wizard.showErrorMessage(errorMessages.join(EOL));
return errorMessages.join(EOL); return errorMessages.join(EOL);
} }
protected async vmNameExists(vmName: string): Promise<boolean> { protected async vmNameExists(vmName: string): Promise<boolean> {
const url = `https://management.azure.com` + const url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` + `/subscriptions/${this._model.azureSubscription}` +
`/resourceGroups/${this.wizard.model.azureResouceGroup}` + `/resourceGroups/${this._model.azureResouceGroup}` +
`/providers/Microsoft.Compute` + `/providers/Microsoft.Compute` +
`/virtualMachines?api-version=2019-12-01`; `/virtualMachines?api-version=2019-12-01`;
let response = await this.wizard.getRequest(url, true); let response = await this._model.getRequest(url, true);
let nameArray = response.data.value.map((v: any) => { return v.name; }); let nameArray = response.data.value.map((v: any) => { return v.name; });
return (nameArray.includes(vmName)); return (nameArray.includes(vmName));

View File

@@ -13,7 +13,7 @@ import { KubeCtlToolName } from '../../services/tools/kubeCtlTool';
import { getErrorMessage, getRuntimeBinaryPathEnvironmentVariableName, setEnvironmentVariablesForInstallPaths } from '../../common/utils'; import { getErrorMessage, getRuntimeBinaryPathEnvironmentVariableName, setEnvironmentVariablesForInstallPaths } from '../../common/utils';
import { ToolsInstallPath } from '../../constants'; import { ToolsInstallPath } from '../../constants';
import * as VariableNames from './constants'; import * as VariableNames from './constants';
import { ResourceTypeModel, ResourceTypePage, ResourceTypeWizard } from '../resourceTypeWizard'; import { ResourceTypeWizard } from '../resourceTypeWizard';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import { InputComponents } from '../modelViewUtils'; import { InputComponents } from '../modelViewUtils';
import { INotebookService } from '../../services/notebookService'; import { INotebookService } from '../../services/notebookService';
@@ -26,6 +26,8 @@ import { ServiceSettingsPage } from './pages/serviceSettingsPage';
import { SummaryPage } from './pages/summaryPage'; import { SummaryPage } from './pages/summaryPage';
import { TargetClusterContextPage } from './pages/targetClusterPage'; import { TargetClusterContextPage } from './pages/targetClusterPage';
import { IToolsService } from '../../services/toolsService'; import { IToolsService } from '../../services/toolsService';
import { ResourceTypeModel } from '../resourceTypeModel';
import { ResourceTypePage } from '../resourceTypePage';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
export class DeployClusterWizardModel extends ResourceTypeModel { export class DeployClusterWizardModel extends ResourceTypeModel {

View File

@@ -11,7 +11,7 @@ import { createSection, getDropdownComponent, InputComponentInfo, InputComponent
import { AksName_VariableName, Location_VariableName, ResourceGroup_VariableName, SubscriptionId_VariableName, VMCount_VariableName, VMSize_VariableName } from '../constants'; import { AksName_VariableName, Location_VariableName, ResourceGroup_VariableName, SubscriptionId_VariableName, VMCount_VariableName, VMSize_VariableName } from '../constants';
import { AzureRegion } from 'azurecore'; import { AzureRegion } from 'azurecore';
import { DeployClusterWizardModel } from '../deployClusterWizardModel'; import { DeployClusterWizardModel } from '../deployClusterWizardModel';
import { ResourceTypePage } from '../../resourceTypeWizard'; import { ResourceTypePage } from '../../resourceTypePage';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
const MissingRequiredInformationErrorMessage = localize('deployCluster.MissingRequiredInfoError', "Please fill out the required fields marked with red asterisks."); const MissingRequiredInformationErrorMessage = localize('deployCluster.MissingRequiredInfoError', "Please fill out the required fields marked with red asterisks.");

View File

@@ -12,7 +12,7 @@ import { createSection, getInputBoxComponent, getInvalidSQLPasswordMessage, getP
import * as VariableNames from '../constants'; import * as VariableNames from '../constants';
import { AuthenticationMode, DeployClusterWizardModel } from '../deployClusterWizardModel'; import { AuthenticationMode, DeployClusterWizardModel } from '../deployClusterWizardModel';
import * as localizedConstants from '../../../localizedConstants'; import * as localizedConstants from '../../../localizedConstants';
import { ResourceTypePage } from '../../resourceTypeWizard'; import { ResourceTypePage } from '../../resourceTypePage';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
const ConfirmPasswordName = 'ConfirmPassword'; const ConfirmPasswordName = 'ConfirmPassword';
@@ -349,7 +349,7 @@ export class ClusterSettingsPage extends ResourceTypePage {
}); });
if (messages.length > 0) { if (messages.length > 0) {
this.wizard.wizardObject.message = { this._model.wizard.wizardObject.message = {
text: messages.length === 1 ? messages[0] : localize('deployCluster.ValidationError', "There are some errors on this page, click 'Show Details' to view the errors."), text: messages.length === 1 ? messages[0] : localize('deployCluster.ValidationError', "There are some errors on this page, click 'Show Details' to view the errors."),
description: messages.length === 1 ? undefined : messages.join(EOL), description: messages.length === 1 ? undefined : messages.join(EOL),
level: azdata.window.MessageLevel.Error level: azdata.window.MessageLevel.Error

View File

@@ -8,7 +8,7 @@ import * as nls from 'vscode-nls';
import { BdcDeploymentType } from '../../../interfaces'; import { BdcDeploymentType } from '../../../interfaces';
import { BigDataClusterDeploymentProfile } from '../../../services/bigDataClusterDeploymentProfile'; import { BigDataClusterDeploymentProfile } from '../../../services/bigDataClusterDeploymentProfile';
import { createFlexContainer, createLabel } from '../../modelViewUtils'; import { createFlexContainer, createLabel } from '../../modelViewUtils';
import { ResourceTypePage } from '../../resourceTypeWizard'; import { ResourceTypePage } from '../../resourceTypePage';
import * as VariableNames from '../constants'; import * as VariableNames from '../constants';
import { DeployClusterWizardModel } from '../deployClusterWizardModel'; import { DeployClusterWizardModel } from '../deployClusterWizardModel';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();

View File

@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import { FieldType, SectionInfo } from '../../../interfaces'; import { FieldType, SectionInfo } from '../../../interfaces';
import { createFlexContainer, createGroupContainer, createLabel, createNumberInput, createSection, createTextInput, getCheckboxComponent, getDropdownComponent, getInputBoxComponent, InputComponentInfo, InputComponents, setModelValues, Validator } from '../../modelViewUtils'; import { createFlexContainer, createGroupContainer, createLabel, createNumberInput, createSection, createTextInput, getCheckboxComponent, getDropdownComponent, getInputBoxComponent, InputComponentInfo, InputComponents, setModelValues, Validator } from '../../modelViewUtils';
import { ResourceTypePage } from '../../resourceTypeWizard'; import { ResourceTypePage } from '../../resourceTypePage';
import * as VariableNames from '../constants'; import * as VariableNames from '../constants';
import { AuthenticationMode, DeployClusterWizardModel } from '../deployClusterWizardModel'; import { AuthenticationMode, DeployClusterWizardModel } from '../deployClusterWizardModel';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();

View File

@@ -9,7 +9,7 @@ import { createSection, createGroupContainer, createFlexContainer, createLabel }
import * as VariableNames from '../constants'; import * as VariableNames from '../constants';
import { AuthenticationMode, DeployClusterWizardModel } from '../deployClusterWizardModel'; import { AuthenticationMode, DeployClusterWizardModel } from '../deployClusterWizardModel';
import * as localizedConstants from '../../../localizedConstants'; import * as localizedConstants from '../../../localizedConstants';
import { ResourceTypePage } from '../../resourceTypeWizard'; import { ResourceTypePage } from '../../resourceTypePage';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
export class SummaryPage extends ResourceTypePage { export class SummaryPage extends ResourceTypePage {

View File

@@ -8,8 +8,8 @@ import * as os from 'os';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import { KubeClusterContext } from '../../../services/kubeService'; import { KubeClusterContext } from '../../../services/kubeService';
import { ResourceTypePage } from '../../resourceTypePage';
import { ClusterContext_VariableName, KubeConfigPath_VariableName } from '../constants'; import { ClusterContext_VariableName, KubeConfigPath_VariableName } from '../constants';
import { ResourceTypePage } from '../../resourceTypeWizard';
import { DeployClusterWizardModel } from '../deployClusterWizardModel'; import { DeployClusterWizardModel } from '../deployClusterWizardModel';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();

View File

@@ -7,7 +7,7 @@ import * as nls from 'vscode-nls';
import { SubFieldInfo, FieldType, FontWeight, LabelPosition, SectionInfo } from '../../interfaces'; import { SubFieldInfo, FieldType, FontWeight, LabelPosition, SectionInfo } from '../../interfaces';
import { createSection, DefaultInputWidth, DefaultLabelWidth, DefaultFieldAlignItems, DefaultFieldWidth, DefaultFieldHeight } from '../modelViewUtils'; import { createSection, DefaultInputWidth, DefaultLabelWidth, DefaultFieldAlignItems, DefaultFieldWidth, DefaultFieldHeight } from '../modelViewUtils';
import { NotebookWizard } from './notebookWizard'; import { NotebookWizardModel } from './notebookWizardModel';
import { NotebookWizardPage } from './notebookWizardPage'; import { NotebookWizardPage } from './notebookWizardPage';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -17,11 +17,11 @@ export class NotebookWizardAutoSummaryPage extends NotebookWizardPage {
private form!: azdata.FormBuilder; private form!: azdata.FormBuilder;
private view!: azdata.ModelView; private view!: azdata.ModelView;
constructor(wizard: NotebookWizard, _pageIndex: number) { constructor(_model: NotebookWizardModel, _pageIndex: number) {
super(wizard, super(_model,
_pageIndex, _pageIndex,
wizard.wizardInfo.pages[_pageIndex].title || localize('notebookWizard.autoSummaryPageTitle', "Review your configuration"), _model.wizardInfo.pages[_pageIndex].title || localize('notebookWizard.autoSummaryPageTitle', "Review your configuration"),
wizard.wizardInfo.pages[_pageIndex].description || '' _model.wizardInfo.pages[_pageIndex].description || ''
); );
} }
@@ -43,14 +43,14 @@ export class NotebookWizardAutoSummaryPage extends NotebookWizardPage {
}); });
this.formItems = []; this.formItems = [];
const fieldWidth = this.pageInfo.fieldWidth || this.wizard.wizardInfo.fieldWidth || DefaultFieldWidth; const fieldWidth = this.pageInfo.fieldWidth || this._model.wizardInfo.fieldWidth || DefaultFieldWidth;
const fieldHeight = this.pageInfo.fieldHeight || this.wizard.wizardInfo.fieldHeight || DefaultFieldHeight; const fieldHeight = this.pageInfo.fieldHeight || this._model.wizardInfo.fieldHeight || DefaultFieldHeight;
const fieldAlignItems = this.pageInfo.fieldAlignItems || this.wizard.wizardInfo.fieldAlignItems || DefaultFieldAlignItems; const fieldAlignItems = this.pageInfo.fieldAlignItems || this._model.wizardInfo.fieldAlignItems || DefaultFieldAlignItems;
const labelWidth = this.pageInfo.labelWidth || this.wizard.wizardInfo.labelWidth || DefaultLabelWidth; const labelWidth = this.pageInfo.labelWidth || this._model.wizardInfo.labelWidth || DefaultLabelWidth;
const labelPosition = this.pageInfo.labelPosition || this.wizard.wizardInfo.labelPosition || LabelPosition.Left; const labelPosition = this.pageInfo.labelPosition || this._model.wizardInfo.labelPosition || LabelPosition.Left;
const inputWidth = this.pageInfo.inputWidth || this.wizard.wizardInfo.inputWidth || DefaultInputWidth; const inputWidth = this.pageInfo.inputWidth || this._model.wizardInfo.inputWidth || DefaultInputWidth;
const filteredPages = this.wizard.wizardInfo.pages.filter((undefined, index) => index < this._pageIndex); const filteredPages = this._model.wizardInfo.pages.filter((undefined, index) => index < this._pageIndex);
for (const pageInfo of filteredPages) { for (const pageInfo of filteredPages) {
const summarySectionInfo: SectionInfo = { const summarySectionInfo: SectionInfo = {
labelPosition: labelPosition, labelPosition: labelPosition,
@@ -80,7 +80,7 @@ export class NotebookWizardAutoSummaryPage extends NotebookWizardPage {
component: await createSection({ component: await createSection({
container: this.wizard.wizardObject, container: this.wizard.wizardObject,
toolsService: this.wizard.toolsService, toolsService: this.wizard.toolsService,
inputComponents: this.wizard.inputComponents, inputComponents: this._model.inputComponents,
sectionInfo: summarySectionInfo, sectionInfo: summarySectionInfo,
view: this.view, view: this.view,
onNewDisposableCreated: () => { }, onNewDisposableCreated: () => { },

View File

@@ -5,58 +5,63 @@
import * as loc from '../../localizedConstants'; import * as loc from '../../localizedConstants';
import { INotebookService, Notebook } from '../../services/notebookService'; import { INotebookService, Notebook } from '../../services/notebookService';
import { IToolsService } from '../../services/toolsService'; import { IToolsService } from '../../services/toolsService';
import { Model } from '../model';
import { InputComponents, setModelValues } from '../modelViewUtils'; import { InputComponents, setModelValues } from '../modelViewUtils';
import { WizardBase } from '../wizardBase'; import { ResourceTypeModel } from '../resourceTypeModel';
import { DeploymentType, NotebookWizardInfo } from './../../interfaces'; import { ResourceTypeWizard } from '../resourceTypeWizard';
import { IPlatformService } from './../../services/platformService'; import { DeploymentType, NotebookWizardDeploymentProvider, NotebookWizardInfo } from '../../interfaces';
import { IPlatformService } from '../../services/platformService';
import { NotebookWizardAutoSummaryPage } from './notebookWizardAutoSummaryPage'; import { NotebookWizardAutoSummaryPage } from './notebookWizardAutoSummaryPage';
import { NotebookWizardPage } from './notebookWizardPage'; import { NotebookWizardPage } from './notebookWizardPage';
export class NotebookWizard extends WizardBase<NotebookWizard, NotebookWizardPage, Model> { export class NotebookWizardModel extends ResourceTypeModel {
private _inputComponents: InputComponents = {}; private _inputComponents: InputComponents = {};
public get notebookService(): INotebookService { public get notebookService(): INotebookService {
return this._notebookService; return this.wizard.notebookService;
} }
public get platformService(): IPlatformService { public get platformService(): IPlatformService {
return this._platformService; return this.wizard.platformService;
}
public get toolsService(): IToolsService {
return this.wizard.toolsService;
} }
public get wizardInfo(): NotebookWizardInfo { public get wizardInfo(): NotebookWizardInfo {
return this._wizardInfo; return this.notebookProvider.notebookWizard;
} }
public get inputComponents(): InputComponents { public get inputComponents(): InputComponents {
return this._inputComponents; return this._inputComponents;
} }
constructor(private _wizardInfo: NotebookWizardInfo, private _notebookService: INotebookService, private _platformService: IPlatformService, toolsService: IToolsService) { constructor(public notebookProvider: NotebookWizardDeploymentProvider, wizard: ResourceTypeWizard) {
super(_wizardInfo.title, _wizardInfo.name || '', new Model(), toolsService); super(notebookProvider, wizard);
if (this._wizardInfo.codeCellInsertionPosition === undefined) { if (this.notebookProvider.notebookWizard.codeCellInsertionPosition === undefined) {
this._wizardInfo.codeCellInsertionPosition = 0; this.notebookProvider.notebookWizard.codeCellInsertionPosition = 0;
} }
this.wizardObject.doneButton.label = _wizardInfo.doneAction?.label || loc.deployNotebook; this.wizard.wizardObject.title = this.notebookProvider.notebookWizard.title;
this.wizardObject.generateScriptButton.label = _wizardInfo.scriptAction?.label || loc.scriptToNotebook; this.wizard.wizardObject.doneButton.label = this.notebookProvider.notebookWizard.doneAction?.label || loc.deployNotebook;
this.wizard.wizardObject.generateScriptButton.label = this.notebookProvider.notebookWizard.scriptAction?.label || loc.scriptToNotebook;
} }
public get deploymentType(): DeploymentType | undefined { public get deploymentType(): DeploymentType | undefined {
return this._wizardInfo.type; return this.notebookProvider.notebookWizard.type;
} }
protected initialize(): void { public initialize(): void {
this.setPages(this.getPages()); this.wizard.setPages(this.getPages());
} }
protected onCancel(): void { public onCancel(): void {
} }
protected async onGenerateScript(): Promise<void> { public async onGenerateScript(): Promise<void> {
const notebook = await this.prepareNotebookAndEnvironment(); const notebook = await this.prepareNotebookAndEnvironment();
await this.openNotebook(notebook); await this.openNotebook(notebook);
} }
protected async onOk(): Promise<void> { public async onOk(): Promise<void> {
const notebook = await this.prepareNotebookAndEnvironment(); const notebook = await this.prepareNotebookAndEnvironment();
const openedNotebook = await this.openNotebook(notebook); const openedNotebook = await this.openNotebook(notebook);
openedNotebook.runAllCells(); openedNotebook.runAllCells();
@@ -68,15 +73,15 @@ export class NotebookWizard extends WizardBase<NotebookWizard, NotebookWizardPag
} }
private async prepareNotebookAndEnvironment() { private async prepareNotebookAndEnvironment() {
await setModelValues(this.inputComponents, this.model); await setModelValues(this.inputComponents, this);
const env: NodeJS.ProcessEnv = process.env; const env: NodeJS.ProcessEnv = process.env;
this.model.setEnvironmentVariables(env, (varName) => { this.setEnvironmentVariables(env, (varName) => {
const isPassword = !!this.inputComponents[varName]?.isPassword; const isPassword = !!this.inputComponents[varName]?.isPassword;
return isPassword; return isPassword;
}); });
const notebook: Notebook = await this.notebookService.getNotebook(this.wizardInfo.notebook); const notebook: Notebook = await this.notebookService.getNotebook(this.wizardInfo.notebook);
// generate python code statements for all variables captured by the wizard // generate python code statements for all variables captured by the wizard
const statements = this.model.getCodeCellContentForNotebook( const statements = this.getCodeCellContentForNotebook(
this.toolsService.toolsForCurrentProvider, this.toolsService.toolsForCurrentProvider,
(varName) => { (varName) => {
const isPassword = !!this.inputComponents[varName]?.isPassword; const isPassword = !!this.inputComponents[varName]?.isPassword;

View File

@@ -8,28 +8,28 @@ import * as vscode from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import { NotebookWizardPageInfo } from '../../interfaces'; import { NotebookWizardPageInfo } from '../../interfaces';
import { initializeWizardPage, InputComponentInfo, setModelValues, Validator } from '../modelViewUtils'; import { initializeWizardPage, InputComponentInfo, setModelValues, Validator } from '../modelViewUtils';
import { WizardPageBase } from '../wizardPageBase'; import { ResourceTypePage } from '../resourceTypePage';
import { WizardPageInfo } from '../wizardPageInfo'; import { WizardPageInfo } from '../wizardPageInfo';
import { NotebookWizard } from './notebookWizard'; import { NotebookWizardModel } from './notebookWizardModel';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
export class NotebookWizardPage extends WizardPageBase<NotebookWizard> { export class NotebookWizardPage extends ResourceTypePage {
protected get pageInfo(): NotebookWizardPageInfo { protected get pageInfo(): NotebookWizardPageInfo {
return this.wizard.wizardInfo.pages[this._pageIndex]; return this._model.wizardInfo.pages[this._pageIndex];
} }
constructor( constructor(
wizard: NotebookWizard, protected _model: NotebookWizardModel,
protected _pageIndex: number, protected _pageIndex: number,
title?: string, title?: string,
description?: string description?: string
) { ) {
super( super(
wizard.wizardInfo.pages[_pageIndex].title || title || '', _model.wizardInfo.pages[_pageIndex].title || title || '',
wizard.wizardInfo.pages[_pageIndex].description || description || '', _model.wizardInfo.pages[_pageIndex].description || description || '',
wizard _model.wizard
); );
} }
@@ -37,21 +37,21 @@ export class NotebookWizardPage extends WizardPageBase<NotebookWizard> {
* If the return value is true then done button should be visible to the user * If the return value is true then done button should be visible to the user
*/ */
private get isDoneButtonVisible(): boolean { private get isDoneButtonVisible(): boolean {
return !!this.wizard.wizardInfo.doneAction; return !!this._model.wizardInfo.doneAction;
} }
/** /**
* If the return value is true then generateScript button should be visible to the user * If the return value is true then generateScript button should be visible to the user
*/ */
private get isGenerateScriptButtonVisible(): boolean { private get isGenerateScriptButtonVisible(): boolean {
return !!this.wizard.wizardInfo.scriptAction; return !!this._model.wizardInfo.scriptAction;
} }
public initialize(): void { public initialize(): void {
initializeWizardPage({ initializeWizardPage({
container: this.wizard.wizardObject, container: this.wizard.wizardObject,
inputComponents: this.wizard.inputComponents, inputComponents: this._model.inputComponents,
wizardInfo: this.wizard.wizardInfo, wizardInfo: this._model.wizardInfo,
pageInfo: this.pageInfo, pageInfo: this.pageInfo,
page: this.pageObject, page: this.pageObject,
onNewDisposableCreated: (disposable: vscode.Disposable): void => { onNewDisposableCreated: (disposable: vscode.Disposable): void => {
@@ -62,7 +62,7 @@ export class NotebookWizardPage extends WizardPageBase<NotebookWizard> {
inputComponentInfo: InputComponentInfo inputComponentInfo: InputComponentInfo
): void => { ): void => {
if (name) { if (name) {
this.wizard.inputComponents[name] = inputComponentInfo; this._model.inputComponents[name] = inputComponentInfo;
} }
}, },
onNewValidatorCreated: (validator: Validator): void => { onNewValidatorCreated: (validator: Validator): void => {
@@ -91,7 +91,7 @@ export class NotebookWizardPage extends WizardPageBase<NotebookWizard> {
} }
if (this.pageInfo.isSummaryPage) { if (this.pageInfo.isSummaryPage) {
await setModelValues(this.wizard.inputComponents, this.wizard.model); await setModelValues(this._model.inputComponents, this.wizard.model);
} }
this.wizard.wizardObject.registerNavigationValidator((pcInfo) => { this.wizard.wizardObject.registerNavigationValidator((pcInfo) => {

View File

@@ -0,0 +1,21 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { DeploymentProvider } from '../interfaces';
import { Model } from './model';
import { ResourceTypeWizard } from './resourceTypeWizard';
export abstract class ResourceTypeModel extends Model {
constructor(public provider: DeploymentProvider, public wizard: ResourceTypeWizard) {
super();
}
abstract initialize(): void;
abstract async onOk(): Promise<void>;
abstract onCancel(): void;
async onGenerateScript(): Promise<void> { }
}

View File

@@ -0,0 +1,11 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ResourceTypeWizard } from './resourceTypeWizard';
import { WizardPageBase } from './wizardPageBase';
export abstract class ResourceTypePage extends WizardPageBase<ResourceTypeWizard>{
abstract initialize(): void;
}

View File

@@ -5,16 +5,19 @@
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { DeploymentProvider, instanceOfWizardDeploymentProvider, ResourceType } from '../interfaces'; import { DeploymentProvider, instanceOfAzureSQLDBDeploymentProvider, instanceOfAzureSQLVMDeploymentProvider, instanceOfNotebookWizardDeploymentProvider, instanceOfWizardDeploymentProvider, ResourceType } from '../interfaces';
import { Model } from './model';
import { WizardPageBase } from './wizardPageBase';
import { DeployClusterWizardModel } from './deployClusterWizard/deployClusterWizardModel'; import { DeployClusterWizardModel } from './deployClusterWizard/deployClusterWizardModel';
import { DeployAzureSQLVMWizardModel } from './deployAzureSQLVMWizard/deployAzureSQLVMWizardModel';
import { WizardPageInfo } from './wizardPageInfo'; import { WizardPageInfo } from './wizardPageInfo';
import { IKubeService } from '../services/kubeService'; import { IKubeService } from '../services/kubeService';
import { IAzdataService } from '../services/azdataService'; import { IAzdataService } from '../services/azdataService';
import { INotebookService } from '../services/notebookService'; import { INotebookService } from '../services/notebookService';
import { IToolsService } from '../services/toolsService'; import { IToolsService } from '../services/toolsService';
import { IPlatformService } from '../services/platformService'; import { IPlatformService } from '../services/platformService';
import { ResourceTypeModel } from './resourceTypeModel';
import { ResourceTypePage } from './resourceTypePage';
import { NotebookWizardModel } from './notebookWizard/notebookWizardModel';
import { DeployAzureSQLDBWizardModel } from './deployAzureSQLDBWizard/deployAzureSQLDBWizardModel';
export class ResourceTypeWizard { export class ResourceTypeWizard {
private customButtons: azdata.window.Button[] = []; private customButtons: azdata.window.Button[] = [];
@@ -49,6 +52,12 @@ export class ResourceTypeWizard {
public getResourceProviderModel(): ResourceTypeModel | undefined { public getResourceProviderModel(): ResourceTypeModel | undefined {
if (instanceOfWizardDeploymentProvider(this.provider)) { if (instanceOfWizardDeploymentProvider(this.provider)) {
return new DeployClusterWizardModel(this.provider, this); return new DeployClusterWizardModel(this.provider, this);
} else if (instanceOfAzureSQLVMDeploymentProvider(this.provider)) {
return new DeployAzureSQLVMWizardModel(this.provider, this);
} else if (instanceOfNotebookWizardDeploymentProvider(this.provider)) {
return new NotebookWizardModel(this.provider, this);
} else if (instanceOfAzureSQLDBDeploymentProvider(this.provider)) {
return new DeployAzureSQLDBWizardModel(this.provider, this);
} }
// other types are undefined for now. // other types are undefined for now.
return undefined; return undefined;
@@ -118,23 +127,11 @@ export class ResourceTypeWizard {
this.toDispose.push(disposable); this.toDispose.push(disposable);
} }
} public showErrorMessage(message: string) {
this.wizardObject.message = {
text: message,
level: azdata.window.MessageLevel.Error
export abstract class ResourceTypePage extends WizardPageBase<ResourceTypeWizard>{ };
abstract initialize(): void;
}
export abstract class ResourceTypeModel extends Model {
constructor(public provider: DeploymentProvider, public wizard: ResourceTypeWizard) {
super();
} }
abstract initialize(): void;
abstract async onOk(): Promise<void>;
abstract onCancel(): void;
async onGenerateScript(): Promise<void> { }
} }