support multiple flavor of notebooks (#12159)

* support multiple flavor of notebooks

* update resource

* comments
This commit is contained in:
Alan Ren
2020-09-08 16:07:55 -07:00
committed by GitHub
parent f6c63f2dcb
commit e2b5e9bd66
5 changed files with 49 additions and 20 deletions

View File

@@ -125,7 +125,7 @@ export interface NotebookWizardPageInfo extends PageInfoBase {
description?: string;
}
export interface NotebookBasedDialogInfo extends DialogInfoBase {
notebook: string | NotebookPathInfo;
notebook: string | NotebookPathInfo | NotebookInfo[];
runNotebook?: boolean;
taskName?: string;
}
@@ -298,6 +298,14 @@ export interface NotebookPathInfo {
linux: string;
}
export interface NotebookInfo {
/**
* Type of the notebook, for example: powershell, python...
*/
type: string;
path: string;
}
export enum OsDistribution {
win32 = 'win32',
darwin = 'darwin',

View File

@@ -13,7 +13,7 @@ import * as nls from 'vscode-nls';
import { INotebookService } from './notebookService';
import { IPlatformService } from './platformService';
import { IToolsService } from './toolsService';
import { ResourceType, ResourceTypeOption, NotebookPathInfo, DeploymentProvider, instanceOfWizardDeploymentProvider, instanceOfDialogDeploymentProvider, instanceOfNotebookDeploymentProvider, instanceOfDownloadDeploymentProvider, instanceOfWebPageDeploymentProvider, instanceOfCommandDeploymentProvider, instanceOfNotebookBasedDialogInfo, instanceOfNotebookWizardDeploymentProvider } from '../interfaces';
import { ResourceType, ResourceTypeOption, NotebookPathInfo, DeploymentProvider, instanceOfWizardDeploymentProvider, instanceOfDialogDeploymentProvider, instanceOfNotebookDeploymentProvider, instanceOfDownloadDeploymentProvider, instanceOfWebPageDeploymentProvider, instanceOfCommandDeploymentProvider, instanceOfNotebookBasedDialogInfo, instanceOfNotebookWizardDeploymentProvider, NotebookInfo } from '../interfaces';
import { DeployClusterWizard } from '../ui/deployClusterWizard/deployClusterWizard';
import { DeploymentInputDialog } from '../ui/deploymentInputDialog';
@@ -77,10 +77,14 @@ export class ResourceTypeService implements IResourceTypeService {
});
}
private updateNotebookPath(objWithNotebookProperty: { notebook: string | NotebookPathInfo } | undefined, extensionPath: string): void {
private updateNotebookPath(objWithNotebookProperty: { notebook: string | NotebookPathInfo | NotebookInfo[] } | undefined, extensionPath: string): void {
if (objWithNotebookProperty && objWithNotebookProperty.notebook) {
if (typeof objWithNotebookProperty.notebook === 'string') {
objWithNotebookProperty.notebook = path.join(extensionPath, objWithNotebookProperty.notebook);
} else if (Array.isArray(objWithNotebookProperty.notebook)) {
objWithNotebookProperty.notebook.forEach(nb => {
nb.path = path.join(extensionPath, nb.path);
});
} else {
if (objWithNotebookProperty.notebook.darwin) {
objWithNotebookProperty.notebook.darwin = path.join(extensionPath, objWithNotebookProperty.notebook.darwin);

View File

@@ -7,7 +7,7 @@ import * as azdata from 'azdata';
import { EOL } from 'os';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { DialogInfo, instanceOfNotebookBasedDialogInfo, NotebookBasedDialogInfo } from '../interfaces';
import { DialogInfo, instanceOfNotebookBasedDialogInfo, NotebookBasedDialogInfo, FieldType, NotebookPathInfo } from '../interfaces';
import { INotebookService } from '../services/notebookService';
import { IPlatformService } from '../services/platformService';
import { DialogBase } from './dialogBase';
@@ -17,6 +17,8 @@ import { IToolsService } from '../services/toolsService';
const localize = nls.loadMessageBundle();
const NotebookTypeVariableName: string = 'SYS_NotebookType';
export class DeploymentInputDialog extends DialogBase {
private inputComponents: InputComponents = {};
@@ -41,6 +43,25 @@ export class DeploymentInputDialog extends DialogBase {
protected initialize() {
const self = this;
const validators: Validator[] = [];
if (this.dialogInfo.tabs.length > 0
&& instanceOfNotebookBasedDialogInfo(this.dialogInfo)
&& Array.isArray(this.dialogInfo.notebook)) {
// Add the notebook type field to the dialog
this.dialogInfo.tabs[0].sections.push(
{
fields: [
{
type: FieldType.Options,
label: localize('notebookType', 'Notebook type'),
options: this.dialogInfo.notebook.map(nb => nb.type),
variableName: NotebookTypeVariableName
}
]
}
);
}
initializeDialog({
dialogInfo: this.dialogInfo,
container: this._dialogObject,
@@ -81,7 +102,10 @@ export class DeploymentInputDialog extends DialogBase {
if (this.dialogInfo.runNotebook) {
this.executeNotebook(this.dialogInfo);
} else {
this.notebookService.launchNotebook(this.dialogInfo.notebook).then(() => { }, (error) => {
const notebook = Array.isArray(this.dialogInfo.notebook) ?
this.dialogInfo.notebook.find(nb => nb.type === model.getStringValue(NotebookTypeVariableName))?.path :
this.dialogInfo.notebook;
this.notebookService.launchNotebook(notebook!).catch(error => {
vscode.window.showErrorMessage(error);
});
}
@@ -91,6 +115,6 @@ export class DeploymentInputDialog extends DialogBase {
}
private executeNotebook(notebookDialogInfo: NotebookBasedDialogInfo): void {
this.notebookService.backgroundExecuteNotebook(notebookDialogInfo.taskName, notebookDialogInfo.notebook, 'deploy', this.platformService);
this.notebookService.backgroundExecuteNotebook(notebookDialogInfo.taskName, notebookDialogInfo.notebook as string | NotebookPathInfo, 'deploy', this.platformService);
}
}