Kusto Notebook Kernel Changes (#11760)

* Able to get Kernel Alias using extension registery

* Get Kernel Alias through Capability Services

* Notebook Action feature to add kusto to dropdown based on extension - complete

* Fixed indexing issue when Kusto is in kernels Dropdown

* Kusto Kernel listed properly and selected when kernel changes

* Added kernel change when user Attaches To Kusto connection

* Deleted unnecessary code/refactored

* Fix Merge Issues

* Resolving Compile issues - test file error

* Capabilities Provider Changes

* Fixed Notebook Tests

* Rearchitect kernel changes to Notebook Model

* Address minor changes
This commit is contained in:
Vasu Bhog
2020-08-18 14:52:25 -05:00
committed by GitHub
parent 6153b7ad06
commit 2bfba53e21
7 changed files with 63 additions and 14 deletions

View File

@@ -29,6 +29,7 @@ import { startsWith } from 'vs/base/common/strings';
import { notebookConstants } from 'sql/workbench/services/notebook/browser/interfaces';
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
import { Deferred } from 'sql/base/common/promise';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
/*
* Used to control whether a message in a dialog/wizard is displayed as an error,
@@ -81,6 +82,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
private _connectionUrisToDispose: string[] = [];
private _textCellsLoading: number = 0;
private _standardKernels: notebookUtils.IStandardKernelWithProvider[];
private _kernelAliases: string[] = [];
public requestConnectionHandler: () => Promise<boolean>;
@@ -89,7 +91,9 @@ export class NotebookModel extends Disposable implements INotebookModel {
public connectionProfile: IConnectionProfile | undefined,
@ILogService private readonly logService: ILogService,
@INotificationService private readonly notificationService: INotificationService,
@IAdsTelemetryService private readonly adstelemetryService: IAdsTelemetryService
@IAdsTelemetryService private readonly adstelemetryService: IAdsTelemetryService,
@ICapabilitiesService private _capabilitiesService?: ICapabilitiesService
) {
super();
if (!_notebookOptions || !_notebookOptions.notebookUri || !_notebookOptions.notebookManagers) {
@@ -232,6 +236,10 @@ export class NotebookModel extends Disposable implements INotebookModel {
return this._providerId;
}
public get kernelAliases(): string[] {
return this._kernelAliases;
}
public set trustedMode(isTrusted: boolean) {
this._trustedMode = isTrusted;
@@ -514,7 +522,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
this._onErrorEmitter.fire({ message: error, severity: Severity.Error });
}
public async startSession(manager: INotebookManager, displayName?: string, setErrorStateOnFail?: boolean): Promise<void> {
public async startSession(manager: INotebookManager, displayName?: string, setErrorStateOnFail?: boolean, kernelAlias?: string): Promise<void> {
if (displayName && this._standardKernels) {
let standardKernel = find(this._standardKernels, kernel => kernel.displayName === displayName);
if (standardKernel) {
@@ -552,7 +560,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
await clientSession.ready;
if (clientSession.kernel) {
await clientSession.kernel.ready;
await this.updateKernelInfoOnKernelChange(clientSession.kernel);
await this.updateKernelInfoOnKernelChange(clientSession.kernel, kernelAlias);
}
if (clientSession.isInErrorState) {
if (setErrorStateOnFail) {
@@ -571,6 +579,15 @@ export class NotebookModel extends Disposable implements INotebookModel {
}
public setDefaultKernelAndProviderId() {
if (this._capabilitiesService?.providers) {
let providers = this._capabilitiesService.providers;
for (const server in providers) {
let alias = providers[server].connection.notebookKernelAlias;
if (alias && this._kernelAliases.indexOf(alias) === -1) {
this._kernelAliases.push(providers[server].connection.notebookKernelAlias);
}
}
}
if (this._savedKernelInfo) {
this.sanitizeSavedKernelInfo();
let provider = this._kernelDisplayNameToNotebookProviderIds.get(this._savedKernelInfo.display_name);
@@ -699,10 +716,15 @@ export class NotebookModel extends Disposable implements INotebookModel {
return;
}
let oldDisplayName = this._activeClientSession && this._activeClientSession.kernel ? this._activeClientSession.kernel.name : undefined;
let nbKernelAlias: string;
if (this.kernelAliases.includes(displayName)) {
displayName = 'SQL';
nbKernelAlias = 'Kusto';
}
try {
let changeKernelNeeded = true;
if (mustSetProvider) {
let providerChanged = await this.tryStartSessionByChangingProviders(displayName);
let providerChanged = await this.tryStartSessionByChangingProviders(displayName, nbKernelAlias);
// If provider was changed, a new session with new kernel is already created. We can skip calling changeKernel.
changeKernelNeeded = !providerChanged;
}
@@ -712,7 +734,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
let kernel = await this._activeClientSession.changeKernel(spec, this._oldKernel);
try {
await kernel.ready;
await this.updateKernelInfoOnKernelChange(kernel);
await this.updateKernelInfoOnKernelChange(kernel, nbKernelAlias);
} catch (err2) {
// TODO should we handle this in any way?
this.logService.error(`doChangeKernel: ignoring error ${getErrorMessage(err2)}`);
@@ -742,14 +764,15 @@ export class NotebookModel extends Disposable implements INotebookModel {
// Else no need to do anything
}
private async updateKernelInfoOnKernelChange(kernel: nb.IKernel) {
private async updateKernelInfoOnKernelChange(kernel: nb.IKernel, kernelAlias?: string) {
await this.updateKernelInfo(kernel);
if (kernel.info) {
this.updateLanguageInfo(kernel.info.language_info);
}
this._kernelChangedEmitter.fire({
newValue: kernel,
oldValue: undefined
oldValue: undefined,
nbKernelAlias: kernelAlias
});
}
@@ -928,7 +951,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
* Set _providerId and start session if it is new provider
* @param displayName Kernel dispay name
*/
private async tryStartSessionByChangingProviders(displayName: string): Promise<boolean> {
private async tryStartSessionByChangingProviders(displayName: string, kernelAlias?: string): Promise<boolean> {
if (displayName) {
if (this._activeClientSession && this._activeClientSession.isReady) {
this._oldKernel = this._activeClientSession.kernel;
@@ -942,7 +965,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
await this.shutdownActiveSession();
let manager = this.getNotebookManager(providerId);
if (manager) {
await this.startSession(manager, displayName, false);
await this.startSession(manager, displayName, false, kernelAlias);
} else {
throw new Error(localize('ProviderNoManager', "Can't find notebook manager for provider {0}", providerId));
}