SQL Kernel Improvements/Removing Spark Code from Core/Attach to Changes (#3790)

* Scenarios work besides loading saved kernel

* Fix compilation issue

* Save and load functional

* Fix loading kernesl issue when sql kernel is not enabled

* Fix language mapping to not be hardcoded any longer

* Remove unnecessary comment

* PR Comments vol. 1

* Code cleanup, use ConnectionProfile instead of IConnectionProfile when accessing serverName

* PR changes vol. 2

* One final comment for PR

* Fix linting issue
This commit is contained in:
Chris LaFreniere
2019-01-25 18:54:04 -08:00
committed by GitHub
parent ea67859de7
commit 43be88a37c
29 changed files with 768 additions and 627 deletions

View File

@@ -12,12 +12,13 @@ import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview
import { INotificationService, Severity, INotificationActions } from 'vs/platform/notification/common/notification';
import { SelectBox, ISelectBoxOptionsWithLabel } from 'sql/base/browser/ui/selectBox/selectBox';
import { INotebookModel, notebookConstants } from 'sql/parts/notebook/models/modelInterfaces';
import { INotebookModel } from 'sql/parts/notebook/models/modelInterfaces';
import { CellType } from 'sql/parts/notebook/models/contracts';
import { NotebookComponent } from 'sql/parts/notebook/notebook.component';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { IConnectionManagementService, IConnectionDialogService } from 'sql/platform/connection/common/connectionManagement';
import { getErrorMessage } from 'sql/parts/notebook/notebookUtils';
import { IConnectionManagementService, IConnectionDialogService } from 'sql/platform/connection/common/connectionManagement';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { noKernel } from 'sql/workbench/services/notebook/common/sessionManager';
const msgLoading = localize('loading', 'Loading kernels...');
@@ -26,7 +27,7 @@ const attachToLabel: string = localize('AttachTo', 'Attach to: ');
const msgLoadingContexts = localize('loadingContexts', 'Loading contexts...');
const msgAddNewConnection = localize('addNewConnection', 'Add new connection');
const msgSelectConnection = localize('selectConnection', 'Select connection');
const msgLocalHost = localize('localhost', 'Localhost');
const msgLocalHost = localize('localhost', 'localhost');
// Action to add a cell to notebook based on cell type(code/markdown).
export class AddCellAction extends Action {
@@ -209,7 +210,8 @@ export class AttachToDropdown extends SelectBox {
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, modelRegistered: Promise<INotebookModel>,
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IConnectionDialogService private _connectionDialogService: IConnectionDialogService,
@INotificationService private _notificationService: INotificationService) {
@INotificationService private _notificationService: INotificationService,
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService) {
super([msgLoadingContexts], msgLoadingContexts, contextViewProvider, container, { labelText: attachToLabel, labelOnTop: false } as ISelectBoxOptionsWithLabel);
if (modelRegistered) {
modelRegistered
@@ -219,8 +221,8 @@ export class AttachToDropdown extends SelectBox {
});
}
this.onDidSelect(e => {
let connection = this.model.contexts.otherConnections.find((c) => c.options.host === e.selected);
this.doChangeContext(connection);
let connection = this.model.contexts.otherConnections.find((c) => c.serverName === e.selected);
this.doChangeContext(new ConnectionProfile(this._capabilitiesService, connection));
});
}
@@ -228,54 +230,55 @@ export class AttachToDropdown extends SelectBox {
this.model = model;
model.contextsChanged(() => {
if (this.model.clientSession.kernel && this.model.clientSession.kernel.name) {
let currentKernel = this.model.clientSession.kernel.name;
this.loadAttachToDropdown(this.model, currentKernel);
let currentKernelSpec = this.model.specs.kernels.find(kernel => kernel.name === this.model.clientSession.kernel.name);
this.loadAttachToDropdown(this.model, currentKernelSpec.display_name);
}
});
}
// Load "Attach To" dropdown with the values corresponding to Kernel dropdown
public async loadAttachToDropdown(model: INotebookModel, currentKernel: string): Promise<void> {
if (currentKernel === notebookConstants.python3 || currentKernel === noKernel) {
let connProviderIds = this.model.getApplicableConnectionProviderIds(currentKernel);
if ((connProviderIds && connProviderIds.length === 0) || currentKernel === noKernel) {
this.setOptions([msgLocalHost]);
}
else {
let hadoopConnections = this.getHadoopConnections(model);
let connections = this.getConnections(model);
this.enable();
if (hadoopConnections.length === 1 && hadoopConnections[0] === msgAddNewConnection) {
hadoopConnections.unshift(msgSelectConnection);
if (connections.length === 1 && connections[0] === msgAddNewConnection) {
connections.unshift(msgSelectConnection);
this.selectWithOptionName(msgSelectConnection);
}
else {
hadoopConnections.push(msgAddNewConnection);
connections.push(msgAddNewConnection);
}
this.setOptions(hadoopConnections);
this.setOptions(connections);
}
}
//Get hadoop connections from context
public getHadoopConnections(model: INotebookModel): string[] {
let otherHadoopConnections: IConnectionProfile[] = [];
model.contexts.otherConnections.forEach((conn) => { otherHadoopConnections.push(conn); });
this.selectWithOptionName(model.contexts.defaultConnection.options.host);
otherHadoopConnections = this.setHadoopConnectionsList(model.contexts.defaultConnection, model.contexts.otherConnections);
let hadoopConnections = otherHadoopConnections.map((context) => context.options.host);
return hadoopConnections;
//Get connections from context
public getConnections(model: INotebookModel): string[] {
let otherConnections: ConnectionProfile[] = [];
model.contexts.otherConnections.forEach((conn) => { otherConnections.push(conn); });
this.selectWithOptionName(model.contexts.defaultConnection.serverName);
otherConnections = this.setConnectionsList(model.contexts.defaultConnection, model.contexts.otherConnections);
let connections = otherConnections.map((context) => context.serverName);
return connections;
}
private setHadoopConnectionsList(defaultHadoopConnection: IConnectionProfile, otherHadoopConnections: IConnectionProfile[]) {
if (defaultHadoopConnection.options.host !== msgSelectConnection) {
otherHadoopConnections = otherHadoopConnections.filter(conn => conn.options.host !== defaultHadoopConnection.options.host);
otherHadoopConnections.unshift(defaultHadoopConnection);
if (otherHadoopConnections.length > 1) {
otherHadoopConnections = otherHadoopConnections.filter(val => val.options.host !== msgSelectConnection);
private setConnectionsList(defaultConnection: ConnectionProfile, otherConnections: ConnectionProfile[]) {
if (defaultConnection.serverName !== msgSelectConnection) {
otherConnections = otherConnections.filter(conn => conn.serverName !== defaultConnection.serverName);
otherConnections.unshift(defaultConnection);
if (otherConnections.length > 1) {
otherConnections = otherConnections.filter(val => val.serverName !== msgSelectConnection);
}
}
return otherHadoopConnections;
return otherConnections;
}
public doChangeContext(connection?: IConnectionProfile): void {
public doChangeContext(connection?: ConnectionProfile): void {
if (this.value === msgAddNewConnection) {
this.openConnectionDialog();
} else {
@@ -291,15 +294,15 @@ export class AttachToDropdown extends SelectBox {
**/
public async openConnectionDialog(): Promise<void> {
try {
//TODO: Figure out how to plumb through the correct provider here
await this._connectionDialogService.openDialogAndWait(this._connectionManagementService, { connectionType: 1, providers: [notebookConstants.hadoopKnoxProviderName] }).then(connection => {
await this._connectionDialogService.openDialogAndWait(this._connectionManagementService, { connectionType: 1, providers: this.model.getApplicableConnectionProviderIds(this.model.clientSession.kernel.name) }).then(connection => {
let attachToConnections = this.values;
if (!connection) {
this.loadAttachToDropdown(this.model, this.model.clientSession.kernel.name);
return;
}
let connectedServer = connection.options[notebookConstants.hostPropName];
//Check to see if the same host is already there in dropdown. We only have host names in dropdown
let connectionProfile = new ConnectionProfile(this._capabilitiesService, connection);
let connectedServer = connectionProfile.serverName;
//Check to see if the same server is already there in dropdown. We only have server names in dropdown
if (attachToConnections.some(val => val === connectedServer)) {
this.loadAttachToDropdown(this.model, this.model.clientSession.kernel.name);
this.doChangeContext();
@@ -320,7 +323,7 @@ export class AttachToDropdown extends SelectBox {
this.select(index);
// Call doChangeContext to set the newly chosen connection in the model
this.doChangeContext(connection);
this.doChangeContext(connectionProfile);
});
}
catch (error) {