Remove ApiWrapper from mssql extension (#11336)

This commit is contained in:
Charles Gagnon
2020-07-14 10:59:55 -07:00
committed by GitHub
parent cbf3cd7445
commit 1b616acfdb
13 changed files with 76 additions and 216 deletions

View File

@@ -1,116 +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 vscode from 'vscode';
import * as azdata from 'azdata';
/**
* Wrapper class to act as a facade over VSCode and Data APIs and allow us to test / mock callbacks into
* this API from our code
*
* @export
*/
export class ApiWrapper {
// Data APIs
public registerConnectionProvider(provider: azdata.ConnectionProvider): vscode.Disposable {
return azdata.dataprotocol.registerConnectionProvider(provider);
}
public registerObjectExplorerNodeProvider(provider: azdata.ObjectExplorerNodeProvider): vscode.Disposable {
return azdata.dataprotocol.registerObjectExplorerNodeProvider(provider);
}
public registerTaskServicesProvider(provider: azdata.TaskServicesProvider): vscode.Disposable {
return azdata.dataprotocol.registerTaskServicesProvider(provider);
}
public registerFileBrowserProvider(provider: azdata.FileBrowserProvider): vscode.Disposable {
return azdata.dataprotocol.registerFileBrowserProvider(provider);
}
public createDialog(title: string, dialogName?: string, isWide?: boolean): azdata.window.Dialog {
return azdata.window.createModelViewDialog(title, dialogName, isWide);
}
public openDialog(dialog: azdata.window.Dialog): void {
return azdata.window.openDialog(dialog);
}
public closeDialog(dialog: azdata.window.Dialog): void {
return azdata.window.closeDialog(dialog);
}
public registerTaskHandler(taskId: string, handler: (profile: azdata.IConnectionProfile) => void): void {
azdata.tasks.registerTask(taskId, handler);
}
public startBackgroundOperation(operationInfo: azdata.BackgroundOperationInfo): void {
azdata.tasks.startBackgroundOperation(operationInfo);
}
public getActiveConnections(): Thenable<azdata.connection.Connection[]> {
return azdata.connection.getActiveConnections();
}
// VSCode APIs
public executeCommand(command: string, ...rest: any[]): Thenable<any> {
return vscode.commands.executeCommand(command, ...rest);
}
public registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): vscode.Disposable {
return vscode.commands.registerCommand(command, callback, thisArg);
}
public showErrorMessage(message: string, ...items: string[]): Thenable<string | undefined> {
return vscode.window.showErrorMessage(message, ...items);
}
public showWarningMessage(message: string, ...items: string[]): Thenable<string | undefined> {
return vscode.window.showWarningMessage(message, ...items);
}
public showInformationMessage(message: string, ...items: string[]): Thenable<string | undefined> {
return vscode.window.showInformationMessage(message, ...items);
}
public showOpenDialog(options: vscode.OpenDialogOptions): Thenable<vscode.Uri[] | undefined> {
return vscode.window.showOpenDialog(options);
}
public showSaveDialog(options: vscode.SaveDialogOptions): Thenable<vscode.Uri> {
return vscode.window.showSaveDialog(options);
}
public openTextDocument(uri: vscode.Uri): Thenable<vscode.TextDocument>;
public openTextDocument(options: { language?: string; content?: string; }): Thenable<vscode.TextDocument>;
public openTextDocument(uriOrOptions: any): Thenable<vscode.TextDocument> {
return vscode.workspace.openTextDocument(uriOrOptions);
}
public showTextDocument(document: vscode.TextDocument, column?: vscode.ViewColumn, preserveFocus?: boolean, preview?: boolean): Thenable<vscode.TextEditor> {
let options: vscode.TextDocumentShowOptions = {
viewColumn: column,
preserveFocus: preserveFocus,
preview: preview
};
return vscode.window.showTextDocument(document, options);
}
public get workspaceFolders(): readonly vscode.WorkspaceFolder[] {
return vscode.workspace.workspaceFolders;
}
public createStatusBarItem(alignment?: vscode.StatusBarAlignment, priority?: number): vscode.StatusBarItem {
return vscode.window.createStatusBarItem(alignment, priority);
}
public createOutputChannel(name: string): vscode.OutputChannel {
return vscode.window.createOutputChannel(name);
}
public createTab(title: string): azdata.window.DialogTab {
return azdata.window.createTab(title);
}
}

View File

@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { ApiWrapper } from './apiWrapper';
/**
* Global context for the application
@@ -13,9 +12,7 @@ export class AppContext {
private serviceMap: Map<string, any> = new Map();
constructor(public readonly extensionContext: vscode.ExtensionContext, public readonly apiWrapper: ApiWrapper) {
this.apiWrapper = apiWrapper || new ApiWrapper();
}
constructor(public readonly extensionContext: vscode.ExtensionContext) { }
public getService<T>(serviceName: string): T {
const service = this.serviceMap.get(serviceName) as T;

View File

@@ -4,16 +4,15 @@
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import { HdfsModel } from '../hdfsModel';
import { IFileSource } from '../../objectExplorerNodeProvider/fileSources';
import { PermissionStatus, AclEntry, AclType, getImageForType, AclEntryScope, AclEntryPermission, PermissionType } from '../../hdfs/aclEntry';
import { cssStyles } from './uiConstants';
import * as loc from '../../localizedConstants';
import { HdfsError } from '../webhdfs';
import { ApiWrapper } from '../../apiWrapper';
import { IconPathHelper } from '../../iconHelper';
import { HdfsFileType } from '../fileStatus';
import { EventEmitter } from 'vscode';
const permissionsTypeIconColumnWidth = 35;
const permissionsDeleteColumnWidth = 50;
@@ -50,16 +49,16 @@ export class ManageAccessDialog {
private posixPermissionCheckboxesMapping: PermissionCheckboxesMapping[] = [];
private namedSectionInheritCheckboxes: azdata.CheckBoxComponent[] = [];
private addUserOrGroupSelectedType: AclType;
private onViewInitializedEvent: EventEmitter<void> = new EventEmitter();
private onViewInitializedEvent: vscode.EventEmitter<void> = new vscode.EventEmitter();
constructor(private hdfsPath: string, private fileSource: IFileSource, private readonly apiWrapper: ApiWrapper) {
constructor(private hdfsPath: string, private fileSource: IFileSource) {
this.hdfsModel = new HdfsModel(this.fileSource, this.hdfsPath);
this.hdfsModel.onPermissionStatusUpdated(permissionStatus => this.handlePermissionStatusUpdated(permissionStatus));
}
public openDialog(): void {
if (!this.dialog) {
this.dialog = this.apiWrapper.createDialog(loc.manageAccessTitle, 'HdfsManageAccess', true);
this.dialog = azdata.window.createModelViewDialog(loc.manageAccessTitle, 'HdfsManageAccess', true);
this.dialog.okButton.label = loc.applyText;
this.applyRecursivelyButton = azdata.window.createButton(loc.applyRecursivelyText);
@@ -68,7 +67,7 @@ export class ManageAccessDialog {
azdata.window.closeDialog(this.dialog);
await this.hdfsModel.apply(true);
} catch (err) {
this.apiWrapper.showErrorMessage(loc.errorApplyingAclChanges(err instanceof HdfsError ? err.message : err));
vscode.window.showErrorMessage(loc.errorApplyingAclChanges(err instanceof HdfsError ? err.message : err));
}
});
this.dialog.customButtons = [this.applyRecursivelyButton];
@@ -77,7 +76,7 @@ export class ManageAccessDialog {
await this.hdfsModel.apply();
return true;
} catch (err) {
this.apiWrapper.showErrorMessage(loc.errorApplyingAclChanges(err instanceof HdfsError ? err.message : err));
vscode.window.showErrorMessage(loc.errorApplyingAclChanges(err instanceof HdfsError ? err.message : err));
}
return false;
});

View File

@@ -54,3 +54,4 @@ export function sparkJobSubmissionSparkHistoryLinkMessage(sparkHistoryLink: stri
export function sparkJobSubmissionGetApplicationIdFailed(err: string): string { return localize('sparkJobSubmission.GetApplicationIdFailed', "Get Application Id Failed. {0}", err); }
export function sparkJobSubmissionLocalFileNotExisted(path: string): string { return localize('sparkJobSubmission.LocalFileNotExisted', "Local file {0} does not existed. ", path); }
export const sparkJobSubmissionNoSqlBigDataClusterFound = localize('sparkJobSubmission.NoSqlBigDataClusterFound', "No SQL Server Big Data Cluster found.");
export function sparkConnectionRequired(name: string): string { return localize('sparkConnectionRequired', "Please connect to the Spark cluster before View {0} History.", name); }

View File

@@ -12,7 +12,6 @@ import * as Constants from './constants';
import ContextProvider from './contextProvider';
import * as Utils from './utils';
import { AppContext } from './appContext';
import { ApiWrapper } from './apiWrapper';
import { UploadFilesCommand, MkDirCommand, SaveFileCommand, PreviewFileCommand, CopyPathCommand, DeleteFilesCommand, ManageAccessCommand } from './objectExplorerNodeProvider/hdfsCommands';
import { IPrompter } from './prompts/question';
import CodeAdapter from './prompts/adapter';
@@ -52,7 +51,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<IExten
IconPathHelper.setExtensionContext(context);
let prompter: IPrompter = new CodeAdapter();
let appContext = new AppContext(context, new ApiWrapper());
let appContext = new AppContext(context);
let nodeProvider = new MssqlObjectExplorerNodeProvider(prompter, appContext);
azdata.dataprotocol.registerObjectExplorerNodeProvider(nodeProvider);
@@ -108,30 +107,28 @@ function registerHdfsCommands(context: vscode.ExtensionContext, prompter: IPromp
function activateSparkFeatures(appContext: AppContext): void {
let extensionContext = appContext.extensionContext;
let apiWrapper = appContext.apiWrapper;
let outputChannel: vscode.OutputChannel = mssqlOutputChannel;
extensionContext.subscriptions.push(new OpenSparkJobSubmissionDialogCommand(appContext, outputChannel));
extensionContext.subscriptions.push(new OpenSparkJobSubmissionDialogFromFileCommand(appContext, outputChannel));
apiWrapper.registerTaskHandler(Constants.mssqlClusterLivySubmitSparkJobTask, async (profile: azdata.IConnectionProfile) => {
azdata.tasks.registerTask(Constants.mssqlClusterLivySubmitSparkJobTask, async (profile: azdata.IConnectionProfile) => {
await new OpenSparkJobSubmissionDialogTask(appContext, outputChannel).execute(profile);
});
apiWrapper.registerTaskHandler(Constants.mssqlClusterLivyOpenSparkHistory, async (profile: azdata.IConnectionProfile) => {
azdata.tasks.registerTask(Constants.mssqlClusterLivyOpenSparkHistory, async (profile: azdata.IConnectionProfile) => {
await new OpenSparkYarnHistoryTask(appContext).execute(profile, true);
});
apiWrapper.registerTaskHandler(Constants.mssqlClusterLivyOpenYarnHistory, async (profile: azdata.IConnectionProfile) => {
azdata.tasks.registerTask(Constants.mssqlClusterLivyOpenYarnHistory, async (profile: azdata.IConnectionProfile) => {
await new OpenSparkYarnHistoryTask(appContext).execute(profile, false);
});
}
function activateNotebookTask(appContext: AppContext): void {
let apiWrapper = appContext.apiWrapper;
apiWrapper.registerTaskHandler(Constants.mssqlClusterNewNotebookTask, (profile: azdata.IConnectionProfile) => {
azdata.tasks.registerTask(Constants.mssqlClusterNewNotebookTask, (profile: azdata.IConnectionProfile) => {
return saveProfileAndCreateNotebook(profile);
});
apiWrapper.registerTaskHandler(Constants.mssqlClusterOpenNotebookTask, (profile: azdata.IConnectionProfile) => {
azdata.tasks.registerTask(Constants.mssqlClusterOpenNotebookTask, (profile: azdata.IConnectionProfile) => {
return handleOpenNotebookTask(profile);
});
apiWrapper.registerTaskHandler(Constants.mssqlOpenClusterDashboard, (profile: azdata.IConnectionProfile) => {
azdata.tasks.registerTask(Constants.mssqlOpenClusterDashboard, (profile: azdata.IConnectionProfile) => {
return handleOpenClusterDashboardTask(profile, appContext);
});
}
@@ -207,11 +204,11 @@ async function handleOpenClusterDashboardTask(profile: azdata.IConnectionProfile
const serverInfo = await azdata.connection.getServerInfo(profile.id);
const controller = Utils.getClusterEndpoints(serverInfo).find(e => e.serviceName === Endpoint.controller);
if (!controller) {
appContext.apiWrapper.showErrorMessage(localize('noController', "Could not find the controller endpoint for this instance"));
vscode.window.showErrorMessage(localize('noController', "Could not find the controller endpoint for this instance"));
return;
}
appContext.apiWrapper.executeCommand('bigDataClusters.command.manageController',
vscode.commands.executeCommand('bigDataClusters.command.manageController',
{
url: controller.endpoint,
auth: profile.authenticationType === 'Integrated' ? AuthType.Integrated : AuthType.Basic,

View File

@@ -8,7 +8,6 @@ import * as azdata from 'azdata';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { ApiWrapper } from '../apiWrapper';
import { TreeNode } from './treeNodes';
import { QuestionTypes, IPrompter, IQuestion } from '../prompts/question';
import * as utils from '../utils';
@@ -63,12 +62,12 @@ export abstract class Command extends vscode.Disposable {
super(() => this.dispose());
if (typeof command === 'string') {
this.disposable = this.apiWrapper.registerCommand(command, (...args: any[]) => this._execute(command, ...args), this);
this.disposable = vscode.commands.registerCommand(command, (...args: any[]) => this._execute(command, ...args), this);
return;
}
const subscriptions = command.map(cmd => this.apiWrapper.registerCommand(cmd, (...args: any[]) => this._execute(cmd, ...args), this));
const subscriptions = command.map(cmd => vscode.commands.registerCommand(cmd, (...args: any[]) => this._execute(cmd, ...args), this));
this.disposable = vscode.Disposable.from(...subscriptions);
}
@@ -78,10 +77,6 @@ export abstract class Command extends vscode.Disposable {
}
}
protected get apiWrapper(): ApiWrapper {
return this.appContext.apiWrapper;
}
protected async preExecute(...args: any[]): Promise<any> {
return this.execute(...args);
}
@@ -138,12 +133,12 @@ export abstract class ProgressCommand extends Command {
): Promise<void> {
let disposables: vscode.Disposable[] = [];
const tokenSource = new vscode.CancellationTokenSource();
const statusBarItem = this.apiWrapper.createStatusBarItem(vscode.StatusBarAlignment.Left);
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
disposables.push(vscode.Disposable.from(statusBarItem));
statusBarItem.text = localize('progress', "$(sync~spin) {0}...", label);
if (isCancelable) {
const cancelCommandId = `cancelProgress${ProgressCommand.progressId++}`;
disposables.push(this.apiWrapper.registerCommand(cancelCommandId, async () => {
disposables.push(vscode.commands.registerCommand(cancelCommandId, async () => {
if (await this.confirmCancel()) {
tokenSource.cancel();
}
@@ -177,7 +172,7 @@ export abstract class ProgressCommand extends Command {
}
export function registerSearchServerCommand(appContext: AppContext): void {
appContext.apiWrapper.registerCommand('mssql.searchServers', () => {
vscode.commands.registerCommand('mssql.searchServers', () => {
vscode.window.showInputBox({
placeHolder: localize('mssql.searchServers', "Search Server Names")
}).then((stringSearch) => {
@@ -186,7 +181,7 @@ export function registerSearchServerCommand(appContext: AppContext): void {
}
});
});
appContext.apiWrapper.registerCommand('mssql.clearSearchServerResult', () => {
vscode.commands.registerCommand('mssql.clearSearchServerResult', () => {
vscode.commands.executeCommand('registeredServers.clearSearchServerResult');
});
}

View File

@@ -10,7 +10,6 @@ import * as fspath from 'path';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { ApiWrapper } from '../apiWrapper';
import { Command, ICommandViewContext, ProgressCommand, ICommandObjectExplorerContext } from './command';
import { File, IFile, joinHdfsPath, FileType } from './fileSources';
import { FolderNode, FileNode, HdfsFileSourceNode } from './hdfsProvider';
@@ -23,9 +22,9 @@ import { TreeNode } from './treeNodes';
import { MssqlObjectExplorerNodeProvider } from './objectExplorerNodeProvider';
import { ManageAccessDialog } from '../hdfs/ui/hdfsManageAccessDialog';
async function getSaveableUri(apiWrapper: ApiWrapper, fileName: string, isPreview?: boolean): Promise<vscode.Uri> {
async function getSaveableUri(fileName: string, isPreview?: boolean): Promise<vscode.Uri> {
let root = utils.getUserHome();
let workspaceFolders = apiWrapper.workspaceFolders;
let workspaceFolders = vscode.workspace.workspaceFolders;
if (workspaceFolders && workspaceFolders.length > 0) {
root = workspaceFolders[0].uri.fsPath;
}
@@ -81,13 +80,13 @@ export class UploadFilesCommand extends ProgressCommand {
openLabel: localize('lblUploadFiles', "Upload"),
filters: filter
};
let fileUris: vscode.Uri[] = await this.apiWrapper.showOpenDialog(options);
let fileUris: vscode.Uri[] = await vscode.window.showOpenDialog(options);
if (fileUris) {
let files: IFile[] = await Promise.all(fileUris.map(uri => uri.fsPath).map(this.mapPathsToFiles()));
await this.executeWithProgress(
(cancelToken: vscode.CancellationTokenSource) => this.writeFiles(files, folderNode, cancelToken),
localize('uploading', "Uploading files to HDFS"), true,
() => this.apiWrapper.showInformationMessage(localize('uploadCanceled', "Upload operation was canceled")));
() => vscode.window.showInformationMessage(localize('uploadCanceled', "Upload operation was canceled")));
if (context.type === constants.ObjectExplorerService) {
let objectExplorerNode = await azdata.objectexplorer.getNode(context.explorerContext.connectionProfile.id, folderNode.getNodeInfo().nodePath);
await objectExplorerNode.refresh();
@@ -95,7 +94,7 @@ export class UploadFilesCommand extends ProgressCommand {
}
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('uploadError', "Error uploading files: {0}", utils.getErrorMessage(err, true)));
}
}
@@ -153,7 +152,7 @@ export class MkDirCommand extends ProgressCommand {
await this.executeWithProgress(
async (cancelToken: vscode.CancellationTokenSource) => this.mkDir(fileName, folderNode, cancelToken),
localize('makingDir', "Creating directory"), true,
() => this.apiWrapper.showInformationMessage(localize('mkdirCanceled', "Operation was canceled")));
() => vscode.window.showInformationMessage(localize('mkdirCanceled', "Operation was canceled")));
if (context.type === constants.ObjectExplorerService) {
let objectExplorerNode = await azdata.objectexplorer.getNode(context.explorerContext.connectionProfile.id, folderNode.getNodeInfo().nodePath);
await objectExplorerNode.refresh();
@@ -161,7 +160,7 @@ export class MkDirCommand extends ProgressCommand {
}
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('mkDirError', "Error on making directory: {0}", utils.getErrorMessage(err, true)));
}
}
@@ -216,10 +215,10 @@ export class DeleteFilesCommand extends Command {
await oeNodeToRefresh.refresh();
}
} else {
this.apiWrapper.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
vscode.window.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('deleteError', "Error on deleting files: {0}", utils.getErrorMessage(err, true)));
}
}
@@ -266,28 +265,28 @@ export class SaveFileCommand extends ProgressCommand {
try {
let fileNode = await getNode<FileNode>(context, this.appContext);
if (fileNode) {
let defaultUri = await getSaveableUri(this.apiWrapper, fspath.basename(fileNode.hdfsPath));
let fileUri: vscode.Uri = await this.apiWrapper.showSaveDialog({
let defaultUri = await getSaveableUri(fspath.basename(fileNode.hdfsPath));
let fileUri: vscode.Uri = await vscode.window.showSaveDialog({
defaultUri: defaultUri
});
if (fileUri) {
await this.executeWithProgress(
(cancelToken: vscode.CancellationTokenSource) => this.doSaveAndOpen(fileUri, fileNode, cancelToken),
localize('saving', "Saving HDFS Files"), true,
() => this.apiWrapper.showInformationMessage(localize('saveCanceled', "Save operation was canceled")));
() => vscode.window.showInformationMessage(localize('saveCanceled', "Save operation was canceled")));
}
} else {
this.apiWrapper.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
vscode.window.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('saveError', "Error on saving file: {0}", utils.getErrorMessage(err, true)));
}
}
private async doSaveAndOpen(fileUri: vscode.Uri, fileNode: FileNode, cancelToken: vscode.CancellationTokenSource): Promise<void> {
await fileNode.writeFileContentsToDisk(fileUri.fsPath, cancelToken);
await this.apiWrapper.executeCommand('vscode.open', fileUri);
await vscode.commands.executeCommand('vscode.open', fileUri);
}
}
@@ -311,8 +310,12 @@ export class PreviewFileCommand extends ProgressCommand {
let contents = await fileNode.getFileContentsAsString(PreviewFileCommand.DefaultMaxSize);
let fileName: string = fspath.basename(fileNode.hdfsPath);
if (fspath.extname(fileName) !== '.ipynb') {
let doc = await this.openTextDocument(fileName);
let editor = await this.apiWrapper.showTextDocument(doc, vscode.ViewColumn.Active, false);
const doc = await this.openTextDocument(fileName);
const options: vscode.TextDocumentShowOptions = {
viewColumn: vscode.ViewColumn.Active,
preserveFocus: false
};
const editor = await vscode.window.showTextDocument(doc, options);
await editor.edit(edit => {
edit.insert(new vscode.Position(0, 0), contents);
});
@@ -327,10 +330,10 @@ export class PreviewFileCommand extends ProgressCommand {
localize('previewing', "Generating preview"),
false);
} else {
this.apiWrapper.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
vscode.window.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('previewError', "Error on previewing file: {0}", utils.getErrorMessage(err, true)));
}
}
@@ -338,7 +341,7 @@ export class PreviewFileCommand extends ProgressCommand {
private async showNotebookDocument(fileName: string, connectionProfile?: azdata.IConnectionProfile,
initialContent?: string
): Promise<azdata.nb.NotebookEditor> {
let docUri: vscode.Uri = (await getSaveableUri(this.apiWrapper, fileName, true))
let docUri: vscode.Uri = (await getSaveableUri(fileName, true))
.with({ scheme: constants.UNTITLED_SCHEMA });
return await azdata.nb.showNotebookDocument(docUri, {
connectionProfile: connectionProfile,
@@ -348,10 +351,10 @@ export class PreviewFileCommand extends ProgressCommand {
}
private async openTextDocument(fileName: string): Promise<vscode.TextDocument> {
let docUri: vscode.Uri = await getSaveableUri(this.apiWrapper, fileName, true);
let docUri: vscode.Uri = await getSaveableUri(fileName, true);
if (docUri) {
docUri = docUri.with({ scheme: constants.UNTITLED_SCHEMA });
return await this.apiWrapper.openTextDocument(docUri);
return await vscode.workspace.openTextDocument(docUri);
} else {
// Can't reliably create a filename to save as so just use untitled
let language = fspath.extname(fileName);
@@ -359,7 +362,7 @@ export class PreviewFileCommand extends ProgressCommand {
// trim the '.'
language = language.substring(1);
}
return await this.apiWrapper.openTextDocument({
return await vscode.workspace.openTextDocument({
language: language
});
}
@@ -384,10 +387,10 @@ export class CopyPathCommand extends Command {
let path = node.hdfsPath;
vscode.env.clipboard.writeText(path);
} else {
this.apiWrapper.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
vscode.window.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('copyPathError', "Error on copying path: {0}", utils.getErrorMessage(err, true)));
}
}
@@ -403,12 +406,12 @@ export class ManageAccessCommand extends Command {
try {
let node = await getNode<HdfsFileSourceNode>(context, this.appContext);
if (node) {
new ManageAccessDialog(node.hdfsPath, node.fileSource, this.apiWrapper).openDialog();
new ManageAccessDialog(node.hdfsPath, node.fileSource).openDialog();
} else {
this.apiWrapper.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
vscode.window.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('manageAccessError', "An unexpected error occurred while opening the Manage Access dialog: {0}", utils.getErrorMessage(err, true)));
}
}

View File

@@ -197,7 +197,7 @@ export class MssqlObjectExplorerNodeProvider extends ProviderBase implements azd
try {
let session = this.getSqlClusterSessionForNode(node);
if (!session) {
this.appContext.apiWrapper.showErrorMessage(localize('sessionNotFound', "Session for node {0} does not exist", node.nodePathValue));
vscode.window.showErrorMessage(localize('sessionNotFound', "Session for node {0} does not exist", node.nodePathValue));
} else {
let nodeInfo = node.getNodeInfo();
let expandInfo: azdata.ExpandNodeInfo = {

View File

@@ -47,12 +47,12 @@ export class OpenSparkJobSubmissionDialogCommand extends Command {
let dialog = new SparkJobSubmissionDialog(sqlClusterConnection, this.appContext, this.outputChannel);
await dialog.openDialog();
} catch (error) {
this.appContext.apiWrapper.showErrorMessage(getErrorMessage(error));
vscode.window.showErrorMessage(getErrorMessage(error));
}
}
private async selectConnection(): Promise<SqlClusterConnection> {
let connectionList: azdata.connection.Connection[] = await this.apiWrapper.getActiveConnections();
let connectionList: azdata.connection.Connection[] = await azdata.connection.getActiveConnections();
let connectionMap: Map<string, azdata.connection.Connection> = new Map();
let selectedHost: string = undefined;
let showConnectionDialog = false;
@@ -129,11 +129,11 @@ export class OpenSparkJobSubmissionDialogFromFileCommand extends Command {
if (node && node.hdfsPath) {
path = node.hdfsPath;
} else {
this.apiWrapper.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
vscode.window.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
return;
}
} catch (err) {
this.apiWrapper.showErrorMessage(localize('sparkJobSubmission.GetFilePathFromSelectedNodeFailed', "Error Get File Path: {0}", err));
vscode.window.showErrorMessage(localize('sparkJobSubmission.GetFilePathFromSelectedNodeFailed', "Error Get File Path: {0}", err));
return;
}
@@ -148,7 +148,7 @@ export class OpenSparkJobSubmissionDialogFromFileCommand extends Command {
let dialog = new SparkJobSubmissionDialog(sqlClusterConnection, this.appContext, this.outputChannel);
await dialog.openDialog(path);
} catch (error) {
this.appContext.apiWrapper.showErrorMessage(getErrorMessage(error));
vscode.window.showErrorMessage(getErrorMessage(error));
}
}
}
@@ -166,7 +166,7 @@ export class OpenSparkJobSubmissionDialogTask {
let dialog = new SparkJobSubmissionDialog(sqlClusterConnection, this.appContext, this.outputChannel);
await dialog.openDialog();
} catch (error) {
this.appContext.apiWrapper.showErrorMessage(getErrorMessage(error));
vscode.window.showErrorMessage(getErrorMessage(error));
}
}
}

View File

@@ -7,9 +7,6 @@ import * as azdata from 'azdata';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { AppContext } from '../../../appContext';
import { ApiWrapper } from '../../../apiWrapper';
export class SparkAdvancedTab {
private _tab: azdata.window.DialogTab;
public get tab(): azdata.window.DialogTab { return this._tab; }
@@ -18,12 +15,8 @@ export class SparkAdvancedTab {
private _referenceJARFilesInputBox: azdata.InputBoxComponent;
private _referencePyFilesInputBox: azdata.InputBoxComponent;
private get apiWrapper(): ApiWrapper {
return this.appContext.apiWrapper;
}
constructor(private appContext: AppContext) {
this._tab = this.apiWrapper.createTab(localize('sparkJobSubmission.AdvancedTabName', "ADVANCED"));
constructor() {
this._tab = azdata.window.createTab(localize('sparkJobSubmission.AdvancedTabName', "ADVANCED"));
this._tab.registerContent(async (modelView) => {
let builder = modelView.modelBuilder;

View File

@@ -11,8 +11,6 @@ import * as utils from '../../../utils';
import * as LocalizedConstants from '../../../localizedConstants';
import * as constants from '../../../constants';
import { AppContext } from '../../../appContext';
import { ApiWrapper } from '../../../apiWrapper';
import { SparkJobSubmissionModel } from './sparkJobSubmissionModel';
import { SparkFileSource } from './sparkJobSubmissionService';
@@ -33,13 +31,9 @@ export class SparkConfigurationTab {
private _mainClassInputBox: azdata.InputBoxComponent;
private _argumentsInputBox: azdata.InputBoxComponent;
private get apiWrapper(): ApiWrapper {
return this.appContext.apiWrapper;
}
// If path is specified, means the default source setting for this tab is HDFS file, otherwise, it would be local file.
constructor(private _dataModel: SparkJobSubmissionModel, private appContext: AppContext, private _path?: string) {
this._tab = this.apiWrapper.createTab(localize('sparkJobSubmission.GeneralTabName', "GENERAL"));
constructor(private _dataModel: SparkJobSubmissionModel, private _path?: string) {
this._tab = azdata.window.createTab(localize('sparkJobSubmission.GeneralTabName', "GENERAL"));
this._tab.registerContent(async (modelView) => {
let builder = modelView.modelBuilder;
@@ -263,14 +257,14 @@ export class SparkConfigurationTab {
filters: filter
};
let fileUris: vscode.Uri[] = await this.apiWrapper.showOpenDialog(options);
let fileUris: vscode.Uri[] = await vscode.window.showOpenDialog(options);
if (fileUris && fileUris[0]) {
return fileUris[0].fsPath;
}
return undefined;
} catch (err) {
this.apiWrapper.showErrorMessage(localize('sparkJobSubmission.SelectFileError', "Error in locating the file due to Error: {0}", utils.getErrorMessage(err)));
vscode.window.showErrorMessage(localize('sparkJobSubmission.SelectFileError', "Error in locating the file due to Error: {0}", utils.getErrorMessage(err)));
return undefined;
}
}

View File

@@ -10,7 +10,6 @@ import * as utils from '../../../utils';
import * as LocalizedConstants from '../../../localizedConstants';
import { AppContext } from '../../../appContext';
import { ApiWrapper } from '../../../apiWrapper';
import { SparkJobSubmissionModel } from './sparkJobSubmissionModel';
import { SparkConfigurationTab } from './sparkConfigurationTab';
import { SparkJobSubmissionInput } from './sparkJobSubmissionService';
@@ -24,9 +23,6 @@ export class SparkJobSubmissionDialog {
private _dataModel: SparkJobSubmissionModel;
private _sparkConfigTab: SparkConfigurationTab;
private _sparkAdvancedTab: SparkAdvancedTab;
private get apiWrapper(): ApiWrapper {
return this.appContext.apiWrapper;
}
constructor(
private sqlClusterConnection: SqlClusterConnection,
@@ -39,12 +35,12 @@ export class SparkJobSubmissionDialog {
}
public async openDialog(path?: string): Promise<void> {
this._dialog = this.apiWrapper.createDialog(localize('sparkJobSubmission.DialogTitleNewJob', "New Job"));
this._dialog = azdata.window.createModelViewDialog(localize('sparkJobSubmission.DialogTitleNewJob', "New Job"));
this._dataModel = new SparkJobSubmissionModel(this.sqlClusterConnection, this._dialog, this.appContext);
this._sparkConfigTab = new SparkConfigurationTab(this._dataModel, this.appContext, path);
this._sparkAdvancedTab = new SparkAdvancedTab(this.appContext);
this._sparkConfigTab = new SparkConfigurationTab(this._dataModel, path);
this._sparkAdvancedTab = new SparkAdvancedTab();
this._dialog.content = [this._sparkConfigTab.tab, this._sparkAdvancedTab.tab];
@@ -55,13 +51,13 @@ export class SparkJobSubmissionDialog {
this._dialog.registerCloseValidator(() => this.handleValidate());
await this.apiWrapper.openDialog(this._dialog);
azdata.window.openDialog(this._dialog);
}
private onClickOk(): void {
let jobName = localize('sparkJobSubmission.SubmitSparkJob', "{0} Spark Job Submission:",
this._sparkConfigTab.getInputValues()[0]);
this.apiWrapper.startBackgroundOperation(
azdata.tasks.startBackgroundOperation(
{
connection: this.sqlClusterConnection.connection,
displayName: jobName,

View File

@@ -8,6 +8,7 @@ import * as vscode from 'vscode';
import { AppContext } from '../appContext';
import { getErrorMessage } from '../utils';
import * as SqlClusterLookUp from '../sqlClusterLookUp';
import * as loc from '../localizedConstants';
export class OpenSparkYarnHistoryTask {
constructor(private appContext: AppContext) {
@@ -18,7 +19,7 @@ export class OpenSparkYarnHistoryTask {
let sqlClusterConnection = SqlClusterLookUp.findSqlClusterConnection(sqlConnProfile, this.appContext);
if (!sqlClusterConnection) {
let name = isSpark ? 'Spark' : 'Yarn';
this.appContext.apiWrapper.showErrorMessage(`Please connect to the Spark cluster before View ${name} History.`);
vscode.window.showErrorMessage(loc.sparkConnectionRequired(name));
return;
}
if (isSpark) {
@@ -28,7 +29,7 @@ export class OpenSparkYarnHistoryTask {
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(this.generateYarnHistoryUrl(sqlClusterConnection.host, sqlClusterConnection.port)));
}
} catch (error) {
this.appContext.apiWrapper.showErrorMessage(getErrorMessage(error));
vscode.window.showErrorMessage(getErrorMessage(error));
}
}