mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add Arc MIAA delete action back (#11901)
* Add Arc MIAA delete action back * fix
This commit is contained in:
@@ -148,12 +148,11 @@ async function promptInputBox(title: string, options: vscode.InputBoxOptions): P
|
||||
|
||||
/**
|
||||
* Opens an input box prompting the user to enter in the name of a resource to delete
|
||||
* @param namespace The namespace of the resource to delete
|
||||
* @param name The name of the resource to delete
|
||||
* @returns Promise resolving to true if the user confirmed the name, false if the input box was closed for any other reason
|
||||
*/
|
||||
export async function promptForResourceDeletion(namespace: string, name: string): Promise<boolean> {
|
||||
const title = loc.resourceDeletionWarning(namespace, name);
|
||||
export async function promptForResourceDeletion(name: string): Promise<boolean> {
|
||||
const title = loc.resourceDeletionWarning(name);
|
||||
const options: vscode.InputBoxOptions = {
|
||||
placeHolder: name,
|
||||
validateInput: input => input !== name ? loc.invalidResourceDeletionName(name) : ''
|
||||
|
||||
@@ -149,7 +149,7 @@ export function fetchEndpointsFailed(name: string, error: any): string { return
|
||||
export function fetchRegistrationsFailed(name: string, error: any): string { return localize('arc.fetchRegistrationsFailed', "An unexpected error occurred retrieving the registrations for '{0}'. {1}", name, getErrorMessage(error)); }
|
||||
export function fetchDatabasesFailed(name: string, error: any): string { return localize('arc.fetchDatabasesFailed', "An unexpected error occurred retrieving the databases for '{0}'. {1}", name, getErrorMessage(error)); }
|
||||
export function couldNotFindRegistration(namespace: string, name: string) { return localize('arc.couldNotFindRegistration', "Could not find controller registration for {0} ({1})", name, namespace); }
|
||||
export function resourceDeletionWarning(namespace: string, name: string): string { return localize('arc.resourceDeletionWarning', "Warning! Deleting a resource is permanent and cannot be undone. To delete the resource '{0}.{1}' type the name '{1}' below to proceed.", namespace, name); }
|
||||
export function resourceDeletionWarning(name: string): string { return localize('arc.resourceDeletionWarning', "Warning! Deleting a resource is permanent and cannot be undone. To delete the resource '{0}' type the name '{0}' below to proceed.", name); }
|
||||
export function invalidResourceDeletionName(name: string): string { return localize('arc.invalidResourceDeletionName', "The value '{0}' does not match the instance name. Try again or press escape to exit", name); }
|
||||
export function couldNotFindAzureResource(name: string): string { return localize('arc.couldNotFindAzureResource', "Could not find Azure resource for {0}", name); }
|
||||
export function passwordResetFailed(error: any): string { return localize('arc.passwordResetFailed', "Failed to reset password. {0}", getErrorMessage(error)); }
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdataExt from 'azdata-ext';
|
||||
import * as vscode from 'vscode';
|
||||
import { parseInstanceName, UserCancelledError } from '../common/utils';
|
||||
import { ResourceType } from '../constants';
|
||||
import { AzureArcTreeDataProvider } from '../ui/tree/azureArcTreeDataProvider';
|
||||
import * as loc from '../localizedConstants';
|
||||
import * as azdataExt from '../../../azdata/src/typings/azdata-ext';
|
||||
import { ConnectToControllerDialog } from '../ui/dialogs/connectControllerDialog';
|
||||
|
||||
export type ControllerInfo = {
|
||||
@@ -22,7 +22,6 @@ export type ControllerInfo = {
|
||||
export type ResourceInfo = {
|
||||
name: string,
|
||||
resourceType: ResourceType | string,
|
||||
namespace?: string,
|
||||
connectionId?: string
|
||||
};
|
||||
|
||||
@@ -55,7 +54,11 @@ export class ControllerModel {
|
||||
this._azdataApi = <azdataExt.IExtension>vscode.extensions.getExtension(azdataExt.extension.name)?.exports;
|
||||
}
|
||||
|
||||
public async refresh(showErrors: boolean = true, promptReconnect: boolean = false): Promise<void> {
|
||||
/**
|
||||
* Calls azdata login to set the context to this controller
|
||||
* @param promptReconnect
|
||||
*/
|
||||
public async azdataLogin(promptReconnect: boolean = false): Promise<void> {
|
||||
// We haven't gotten our password yet or we want to prompt for a reconnect
|
||||
if (!this._password || promptReconnect) {
|
||||
this._password = '';
|
||||
@@ -70,6 +73,7 @@ export class ControllerModel {
|
||||
const model = await dialog.waitForClose();
|
||||
if (model) {
|
||||
this.treeDataProvider.addOrUpdateController(model.controllerModel, model.password, false);
|
||||
this._password = model.password;
|
||||
} else {
|
||||
throw new UserCancelledError();
|
||||
}
|
||||
@@ -77,7 +81,21 @@ export class ControllerModel {
|
||||
}
|
||||
|
||||
await this._azdataApi.login(this.info.url, this.info.username, this._password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the Tree Node for this model. This will also result in the model being refreshed.
|
||||
*/
|
||||
public async refreshTreeNode(): Promise<void> {
|
||||
const node = this.treeDataProvider.getControllerNode(this);
|
||||
if (node) {
|
||||
this.treeDataProvider.refreshNode(node);
|
||||
} else {
|
||||
await this.refresh(false);
|
||||
}
|
||||
}
|
||||
public async refresh(showErrors: boolean = true, promptReconnect: boolean = false): Promise<void> {
|
||||
await this.azdataLogin(promptReconnect);
|
||||
this._registrations = [];
|
||||
await Promise.all([
|
||||
this._azdataApi.dc.config.show().then(result => {
|
||||
@@ -156,8 +174,7 @@ export class ControllerModel {
|
||||
|
||||
public getRegistration(type: ResourceType, name: string): Registration | undefined {
|
||||
return this._registrations.find(r => {
|
||||
// TODO chgagnon namespace
|
||||
return r.instanceType === type && /* r.instanceNamespace === namespace && */ parseInstanceName(r.instanceName) === name;
|
||||
return r.instanceType === type && parseInstanceName(r.instanceName) === name;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -170,17 +187,6 @@ export class ControllerModel {
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the specified MIAA resource from the controller
|
||||
* @param namespace The namespace of the resource
|
||||
* @param name The name of the resource
|
||||
*/
|
||||
public async miaaDelete(name: string): Promise<void> {
|
||||
// TODO chgagnon Fix delete
|
||||
//await this._sqlInstanceRouter.apiV1HybridSqlNsNameDelete(namespace, name);
|
||||
await this.deleteRegistration(ResourceType.sqlManagedInstances, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this model is for the same controller as another
|
||||
* @param other The other instance to test
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as azdataExt from 'azdata-ext';
|
||||
import * as vscode from 'vscode';
|
||||
import { ResourceModel } from './resourceModel';
|
||||
import { ResourceInfo, Registration } from './controllerModel';
|
||||
import { ResourceInfo, Registration, ControllerModel } from './controllerModel';
|
||||
import { AzureArcTreeDataProvider } from '../ui/tree/azureArcTreeDataProvider';
|
||||
import { Deferred } from '../common/promise';
|
||||
import * as loc from '../localizedConstants';
|
||||
import { UserCancelledError } from '../common/utils';
|
||||
import * as azdataExt from '../../../azdata/src/typings/azdata-ext';
|
||||
|
||||
export type DatabaseModel = { name: string, status: string };
|
||||
|
||||
@@ -34,7 +34,7 @@ export class MiaaModel extends ResourceModel {
|
||||
|
||||
private _refreshPromise: Deferred<void> | undefined = undefined;
|
||||
|
||||
constructor(info: ResourceInfo, registration: Registration, private _treeDataProvider: AzureArcTreeDataProvider) {
|
||||
constructor(private _controllerModel: ControllerModel, info: ResourceInfo, registration: Registration, private _treeDataProvider: AzureArcTreeDataProvider) {
|
||||
super(info, registration);
|
||||
this._azdataApi = <azdataExt.IExtension>vscode.extensions.getExtension(azdataExt.extension.name)?.exports;
|
||||
}
|
||||
@@ -73,6 +73,7 @@ export class MiaaModel extends ResourceModel {
|
||||
}
|
||||
this._refreshPromise = new Deferred();
|
||||
try {
|
||||
await this._controllerModel.azdataLogin();
|
||||
const instanceRefresh = this._azdataApi.sql.mi.show(this.info.name).then(result => {
|
||||
this._config = result.result;
|
||||
this.configLastUpdated = new Date();
|
||||
|
||||
@@ -93,7 +93,7 @@ export class PostgresModel extends ResourceModel {
|
||||
|
||||
/** Returns the service's Kubernetes namespace */
|
||||
public get namespace(): string | undefined {
|
||||
return this.info.namespace;
|
||||
return ''; // TODO chgagnon return this.info.namespace;
|
||||
}
|
||||
|
||||
/** Returns the service's name */
|
||||
@@ -103,7 +103,7 @@ export class PostgresModel extends ResourceModel {
|
||||
|
||||
/** Returns the service's fully qualified name in the format namespace.name */
|
||||
public get fullName(): string {
|
||||
return `${this.info.namespace}.${this.info.name}`;
|
||||
return `${this.namespace}.${this.name}`;
|
||||
}
|
||||
|
||||
/** Returns the service's spec */
|
||||
|
||||
@@ -139,7 +139,7 @@ describe('promptForResourceDeletion Method Tests', function (): void {
|
||||
});
|
||||
|
||||
it('Resolves as true when value entered is correct', function (done): void {
|
||||
promptForResourceDeletion('mynamespace', 'myname').then((value: boolean) => {
|
||||
promptForResourceDeletion('myname').then((value: boolean) => {
|
||||
value ? done() : done(new Error('Expected return value to be true'));
|
||||
});
|
||||
mockInputBox.value = 'myname';
|
||||
@@ -147,14 +147,14 @@ describe('promptForResourceDeletion Method Tests', function (): void {
|
||||
});
|
||||
|
||||
it('Resolves as false when input box is closed early', function (done): void {
|
||||
promptForResourceDeletion('mynamespace', 'myname').then((value: boolean) => {
|
||||
promptForResourceDeletion('myname').then((value: boolean) => {
|
||||
!value ? done() : done(new Error('Expected return value to be false'));
|
||||
});
|
||||
mockInputBox.hide();
|
||||
});
|
||||
|
||||
it('Validation message is set when value entered is incorrect', async function (): Promise<void> {
|
||||
promptForResourceDeletion('mynamespace', 'myname');
|
||||
promptForResourceDeletion('myname');
|
||||
mockInputBox.value = 'wrong value';
|
||||
await mockInputBox.triggerAccept();
|
||||
should(mockInputBox.validationMessage).not.be.equal('', 'Validation message should not be empty after incorrect value entered');
|
||||
|
||||
1
extensions/arc/src/typings/refs.d.ts
vendored
1
extensions/arc/src/typings/refs.d.ts
vendored
@@ -7,3 +7,4 @@
|
||||
/// <reference path='../../../../src/sql/azdata.proposed.d.ts'/>
|
||||
/// <reference path='../../../azurecore/src/azurecore.d.ts'/>
|
||||
/// <reference path='../../../../src/vs/vscode.d.ts'/>
|
||||
/// <reference path='../../../azdata/src/typings/azdata-ext.d.ts'/>
|
||||
|
||||
@@ -162,7 +162,8 @@ export class ControllerDashboardOverviewPage extends DashboardPage {
|
||||
|
||||
const openInAzurePortalButton = this.modelView.modelBuilder.button().withProperties<azdata.ButtonProperties>({
|
||||
label: loc.openInAzurePortal,
|
||||
iconPath: IconPathHelper.openInTab
|
||||
iconPath: IconPathHelper.openInTab,
|
||||
enabled: false
|
||||
}).component();
|
||||
|
||||
this.disposables.push(
|
||||
@@ -215,8 +216,7 @@ export class ControllerDashboardOverviewPage extends DashboardPage {
|
||||
url: ''
|
||||
}).component();
|
||||
nameLink.onDidClick(async () => {
|
||||
// TODO chgagnon
|
||||
await this._controllerModel.treeDataProvider.openResourceDashboard(this._controllerModel, r.instanceType || '', /* r.instanceNamespace || */ '', parseInstanceName(r.instanceName));
|
||||
await this._controllerModel.treeDataProvider.openResourceDashboard(this._controllerModel, r.instanceType || '', parseInstanceName(r.instanceName));
|
||||
});
|
||||
// TODO chgagnon
|
||||
return [imageComponent, nameLink, resourceTypeToDisplayName(r.instanceType), '-'/* loc.numVCores(r.vCores) */];
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as azdataExt from 'azdata-ext';
|
||||
import * as vscode from 'vscode';
|
||||
import * as loc from '../../../localizedConstants';
|
||||
import { DashboardPage } from '../../components/dashboardPage';
|
||||
import { IconPathHelper, cssStyles, Endpoints } from '../../../constants';
|
||||
import { ControllerModel } from '../../../models/controllerModel';
|
||||
import { getDatabaseStateDisplayText } from '../../../common/utils';
|
||||
import { getDatabaseStateDisplayText, promptForResourceDeletion } from '../../../common/utils';
|
||||
import { MiaaModel } from '../../../models/miaaModel';
|
||||
|
||||
export class MiaaDashboardOverviewPage extends DashboardPage {
|
||||
@@ -24,6 +25,8 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
|
||||
private _grafanaLink!: azdata.HyperlinkComponent;
|
||||
private _databasesTable!: azdata.DeclarativeTableComponent;
|
||||
|
||||
private readonly _azdataApi: azdataExt.IExtension;
|
||||
|
||||
private _instanceProperties = {
|
||||
resourceGroup: '-',
|
||||
status: '-',
|
||||
@@ -37,6 +40,8 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
|
||||
|
||||
constructor(modelView: azdata.ModelView, private _controllerModel: ControllerModel, private _miaaModel: MiaaModel) {
|
||||
super(modelView);
|
||||
this._azdataApi = vscode.extensions.getExtension(azdataExt.extension.name)?.exports;
|
||||
|
||||
this._instanceProperties.miaaAdmin = this._miaaModel.username || this._instanceProperties.miaaAdmin;
|
||||
this.disposables.push(
|
||||
this._controllerModel.onRegistrationsUpdated(() => this.handleRegistrationsUpdated()),
|
||||
@@ -182,12 +187,11 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
|
||||
deleteButton.onDidClick(async () => {
|
||||
deleteButton.enabled = false;
|
||||
try {
|
||||
/* TODO chgagnon enable delete
|
||||
if (await promptForResourceDeletion(this._miaaModel.info.namespace, this._miaaModel.info.name)) {
|
||||
await this._controllerModel.miaaDelete(this._miaaModel.info.namespace, this._miaaModel.info.name);
|
||||
if (await promptForResourceDeletion(this._miaaModel.info.name)) {
|
||||
await this._azdataApi.sql.mi.delete(this._miaaModel.info.name);
|
||||
await this._controllerModel.refreshTreeNode();
|
||||
vscode.window.showInformationMessage(loc.resourceDeleted(this._miaaModel.info.name));
|
||||
}
|
||||
*/
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage(loc.resourceDeletionFailed(this._miaaModel.info.name, error));
|
||||
} finally {
|
||||
@@ -266,7 +270,7 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
|
||||
|
||||
private handleEndpointsUpdated(): void {
|
||||
const kibanaEndpoint = this._controllerModel.getEndpoint(Endpoints.logsui);
|
||||
const kibanaQuery = `kubernetes_namespace:"${this._miaaModel.info.namespace}" and instance_name :"${this._miaaModel.info.name}"`;
|
||||
const kibanaQuery = `kubernetes_namespace:"${this._miaaModel.config?.metadata.namespace}" and instance_name :"${this._miaaModel.config?.metadata.name}"`;
|
||||
const kibanaUrl = kibanaEndpoint ? `${kibanaEndpoint.endpoint}/app/kibana#/discover?_a=(query:(language:kuery,query:'${kibanaQuery}'))` : '';
|
||||
this._kibanaLink.label = kibanaUrl;
|
||||
this._kibanaLink.url = kibanaUrl;
|
||||
|
||||
@@ -51,7 +51,7 @@ export class AzureArcTreeDataProvider implements vscode.TreeDataProvider<TreeNod
|
||||
}
|
||||
|
||||
public async addOrUpdateController(model: ControllerModel, password: string, refreshTree = true): Promise<void> {
|
||||
const controllerNode = this._controllerNodes.find(node => model.equals(node.model));
|
||||
const controllerNode = this.getControllerNode(model);
|
||||
if (controllerNode) {
|
||||
controllerNode.model.info = model.info;
|
||||
} else {
|
||||
@@ -64,6 +64,10 @@ export class AzureArcTreeDataProvider implements vscode.TreeDataProvider<TreeNod
|
||||
await this.saveControllers();
|
||||
}
|
||||
|
||||
public getControllerNode(model: ControllerModel): ControllerTreeNode | undefined {
|
||||
return this._controllerNodes.find(node => model.equals(node.model));
|
||||
}
|
||||
|
||||
public async removeController(controllerNode: ControllerTreeNode): Promise<void> {
|
||||
this._controllerNodes = this._controllerNodes.filter(node => node !== controllerNode);
|
||||
this._onDidChangeTreeData.fire(undefined);
|
||||
@@ -115,17 +119,16 @@ export class AzureArcTreeDataProvider implements vscode.TreeDataProvider<TreeNod
|
||||
* Opens the dashboard for the specified resource
|
||||
* @param controllerModel The model for the controller containing the resource we want to open the dashboard for
|
||||
* @param resourceType The resourceType for the resource
|
||||
* @param namespace The namespace of the resource
|
||||
* @param name The name of the resource
|
||||
*/
|
||||
public async openResourceDashboard(controllerModel: ControllerModel, resourceType: string, namespace: string, name: string): Promise<void> {
|
||||
public async openResourceDashboard(controllerModel: ControllerModel, resourceType: string, name: string): Promise<void> {
|
||||
const controllerNode = this._controllerNodes.find(n => n.model === controllerModel);
|
||||
if (controllerNode) {
|
||||
const resourceNode = controllerNode.getResourceNode(resourceType, namespace, name);
|
||||
const resourceNode = controllerNode.getResourceNode(resourceType, name);
|
||||
if (resourceNode) {
|
||||
|
||||
} else {
|
||||
console.log(`Couldn't find resource node for ${namespace}.${name} (${resourceType})`);
|
||||
console.log(`Couldn't find resource node for ${name} (${resourceType})`);
|
||||
}
|
||||
await resourceNode?.openDashboard();
|
||||
} else {
|
||||
|
||||
@@ -13,7 +13,6 @@ import { ControllerDashboard } from '../dashboards/controller/controllerDashboar
|
||||
import { PostgresModel } from '../../models/postgresModel';
|
||||
import { parseInstanceName, UserCancelledError } from '../../common/utils';
|
||||
import { MiaaModel } from '../../models/miaaModel';
|
||||
import { Deferred } from '../../common/promise';
|
||||
import { RefreshTreeNode } from './refreshTreeNode';
|
||||
import { ResourceTreeNode } from './resourceTreeNode';
|
||||
import { AzureArcTreeDataProvider } from './azureArcTreeDataProvider';
|
||||
@@ -25,24 +24,20 @@ import * as loc from '../../localizedConstants';
|
||||
export class ControllerTreeNode extends TreeNode {
|
||||
|
||||
private _children: ResourceTreeNode[] = [];
|
||||
private _childrenRefreshPromise = new Deferred();
|
||||
|
||||
constructor(public model: ControllerModel, private _context: vscode.ExtensionContext, private _treeDataProvider: AzureArcTreeDataProvider) {
|
||||
super(model.label, vscode.TreeItemCollapsibleState.Collapsed, ResourceType.dataControllers);
|
||||
model.onRegistrationsUpdated(registrations => this.refreshChildren(registrations));
|
||||
}
|
||||
|
||||
public async getChildren(): Promise<TreeNode[]> {
|
||||
// First reset our deferred promise so we're sure we'll get the refreshed children
|
||||
this._childrenRefreshPromise = new Deferred();
|
||||
try {
|
||||
await this.model.refresh(false);
|
||||
await this._childrenRefreshPromise.promise;
|
||||
this.updateChildren(this.model.registrations);
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(loc.errorConnectingToController(err));
|
||||
try {
|
||||
await this.model.refresh(false, true);
|
||||
await this._childrenRefreshPromise.promise;
|
||||
this.updateChildren(this.model.registrations);
|
||||
} catch (err) {
|
||||
if (!(err instanceof UserCancelledError)) {
|
||||
vscode.window.showErrorMessage(loc.errorConnectingToController(err));
|
||||
@@ -65,17 +60,15 @@ export class ControllerTreeNode extends TreeNode {
|
||||
/**
|
||||
* Finds and returns the ResourceTreeNode specified if it exists, otherwise undefined
|
||||
* @param resourceType The resourceType of the node
|
||||
* @param namespace The namespace of the node
|
||||
* @param name The name of the node
|
||||
*/
|
||||
public getResourceNode(resourceType: string, namespace: string, name: string): ResourceTreeNode | undefined {
|
||||
public getResourceNode(resourceType: string, name: string): ResourceTreeNode | undefined {
|
||||
return this._children.find(c =>
|
||||
c.model?.info.resourceType === resourceType &&
|
||||
c.model?.info.namespace === namespace &&
|
||||
c.model.info.name === name);
|
||||
}
|
||||
|
||||
private refreshChildren(registrations: Registration[]): void {
|
||||
private updateChildren(registrations: Registration[]): void {
|
||||
const newChildren: ResourceTreeNode[] = [];
|
||||
registrations.forEach(registration => {
|
||||
if (!registration.instanceName) {
|
||||
@@ -105,7 +98,7 @@ export class ControllerTreeNode extends TreeNode {
|
||||
node = new PostgresTreeNode(postgresModel, this.model, this._context);
|
||||
break;
|
||||
case ResourceType.sqlManagedInstances:
|
||||
const miaaModel = new MiaaModel(resourceInfo, registration, this._treeDataProvider);
|
||||
const miaaModel = new MiaaModel(this.model, resourceInfo, registration, this._treeDataProvider);
|
||||
node = new MiaaTreeNode(miaaModel, this.model);
|
||||
break;
|
||||
}
|
||||
@@ -119,6 +112,5 @@ export class ControllerTreeNode extends TreeNode {
|
||||
// Update our model info too
|
||||
this.model.info.resources = <ResourceInfo[]>this._children.map(c => c.model?.info).filter(c => c);
|
||||
this._treeDataProvider.saveControllers();
|
||||
this._childrenRefreshPromise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user