From 2c79d49487cd3854d0934eafcb51454d809f9d22 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Wed, 31 Jul 2019 10:47:12 -0700 Subject: [PATCH] Add support for cancelling BDC Add Controller request (#6546) * Add cancel support * Add comment --- .../dialog/addControllerDialog.ts | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/extensions/big-data-cluster/src/bigDataCluster/dialog/addControllerDialog.ts b/extensions/big-data-cluster/src/bigDataCluster/dialog/addControllerDialog.ts index 7bc72050de..16421ebefc 100644 --- a/extensions/big-data-cluster/src/bigDataCluster/dialog/addControllerDialog.ts +++ b/extensions/big-data-cluster/src/bigDataCluster/dialog/addControllerDialog.ts @@ -5,7 +5,6 @@ 'use strict'; -import * as vscode from 'vscode'; import * as azdata from 'azdata'; import * as nls from 'vscode-nls'; import { IEndPoint, IControllerError, getEndPoints } from '../controller/clusterControllerApi'; @@ -16,6 +15,9 @@ import { showErrorMessage } from '../utils'; const localize = nls.loadMessageBundle(); export class AddControllerDialogModel { + + private _canceled = false; + constructor( public treeDataProvider: ControllerTreeDataProvider, public node?: TreeNode, @@ -33,15 +35,27 @@ export class AddControllerDialogModel { } public async onComplete(clusterName: string, url: string, username: string, password: string, rememberPassword: boolean): Promise { - let response = await getEndPoints(clusterName, url, username, password, true); - if (response && response.endPoints) { - let masterInstance: IEndPoint = undefined; - if (response.endPoints) { - masterInstance = response.endPoints.find(e => e.name && e.name === 'sql-server-master'); + try { + // We pre-fetch the endpoints here to verify that the information entered is correct (the user is able to connect) + let response = await getEndPoints(clusterName, url, username, password, true); + if (response && response.endPoints) { + let masterInstance: IEndPoint = undefined; + if (response.endPoints) { + masterInstance = response.endPoints.find(e => e.name && e.name === 'sql-server-master'); + } + if (this._canceled) { + return; + } + this.treeDataProvider.addController(clusterName, url, username, password, rememberPassword, masterInstance); + await this.treeDataProvider.saveControllers(); + } + } catch (error) { + // Ignore the error if we cancelled the request since we can't stop the actual request from completing + if (!this._canceled) { + throw error; } - this.treeDataProvider.addController(clusterName, url, username, password, rememberPassword, masterInstance); - await this.treeDataProvider.saveControllers(); } + } public async onError(error: IControllerError): Promise { @@ -49,6 +63,7 @@ export class AddControllerDialogModel { } public async onCancel(): Promise { + this._canceled = true; if (this.node) { this.node.refresh(); }