Skip to content

Commit

Permalink
MIAA Dashboard Updates (microsoft#10960)
Browse files Browse the repository at this point in the history
* Add database info to MIAA dashboard

* hook up open in azure button

* Only use plural text
  • Loading branch information
Charles-Gagnon authored Jun 17, 2020
1 parent 4296a05 commit 487bd26
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
12 changes: 10 additions & 2 deletions extensions/arc/src/localizedConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const properties = localize('arc.properties', "Properties");
export const settings = localize('arc.settings', "Settings");
export const security = localize('arc.security', "Security");
export const computeAndStorage = localize('arc.computeAndStorage', "Compute + Storage");
export const compute = localize('arc.compute', "Compute");
export const backup = localize('arc.backup', "Backup");
export const newSupportRequest = localize('arc.newSupportRequest', "New support request");
export const diagnoseAndSolveProblems = localize('arc.diagnoseAndSolveProblems', "Diagnose and solve problems");
Expand Down Expand Up @@ -96,7 +97,14 @@ export function copiedToClipboard(name: string): string { return localize('arc.c
export function refreshFailed(error: any): string { return localize('arc.refreshFailed', "Refresh failed. {0}", (error instanceof Error ? error.message : error)); }
export function failedToManagePostgres(name: string, error: any): string { return localize('arc.failedToManagePostgres', "Failed to manage Postgres {0}. {1}", name, (error instanceof Error ? error.message : error)); }
export function clickTheTroubleshootButton(resourceType: string): string { return localize('arc.clickTheTroubleshootButton', "Click the troubleshoot button to open the Azure Arc {0} troubleshooting notebook.", resourceType); }

export const couldNotFindControllerResource = localize('arc.couldNotFindControllerResource', "Could not find Azure resource for Azure Arc Data Controller", name);
export function numVCores(vCores: string): string {
const numCores = +vCores;
if (numCores && numCores > 0) {
return localize('arc.numVCores', "{0} vCores", numCores);
} else {
return '-';
}
}
export function couldNotFindRegistration(namespace: string, name: string) { return localize('arc.couldNotFindRegistration', "Could not find controller registration for {0} ({1})", name, namespace); }

export const arcResources = localize('arc.arcResources', "Azure Arc Resources");
23 changes: 15 additions & 8 deletions extensions/arc/src/models/miaaModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class MiaaModel {

private _sqlInstanceRouter: SqlInstanceRouterApi;
private _status: HybridSqlNsNameGetResponse | undefined;

private _databases: DatabaseModel[] = [];
private readonly _onPasswordUpdated = new vscode.EventEmitter<string>();
private readonly _onStatusUpdated = new vscode.EventEmitter<HybridSqlNsNameGetResponse>();
private readonly _onDatabasesUpdated = new vscode.EventEmitter<DatabaseModel[]>();
Expand Down Expand Up @@ -58,19 +58,26 @@ export class MiaaModel {
}

public get databases(): DatabaseModel[] {
return [
{ name: 'contosoMI54', status: 'online' },
{ name: 'contosoMI56', status: 'online' },
{ name: 'contosoMI58', status: 'online' },
];
return this._databases;
}

/** Refreshes the model */
public async refresh(): Promise<void> {
this._sqlInstanceRouter.apiV1HybridSqlNsNameGet(this._namespace, this._name).then(response => {
const instanceRefresh = this._sqlInstanceRouter.apiV1HybridSqlNsNameGet(this._namespace, this._name).then(response => {
this._status = response.body;
this._onStatusUpdated.fire(this._status);
this._onDatabasesUpdated.fire(this.databases);
});
const provider = azdata.dataprotocol.getProvider<azdata.MetadataProvider>(this.connectionProfile.providerName, azdata.DataProviderType.MetadataProvider);
const databasesRefresh = azdata.connection.getUriForConnection(this.connectionProfile.id).then(ownerUri => {
provider.getDatabases(ownerUri).then(databases => {
if (databases.length > 0 && typeof (databases[0]) === 'object') {
this._databases = (<azdata.DatabaseInfo[]>databases).map(db => { return { name: db.options['name'], status: db.options['state'] }; });
} else {
this._databases = (<string[]>databases).map(db => { return { name: db, status: '-' }; });
}
this._onDatabasesUpdated.fire(this._databases);
});
});
await Promise.all([instanceRefresh, databasesRefresh]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class ControllerDashboardOverviewPage extends DashboardPage {
vscode.env.openExternal(vscode.Uri.parse(
`https://portal.azure.com/#resource/subscriptions/${r.subscriptionId}/resourceGroups/${r.resourceGroupName}/providers/Microsoft.AzureData/${ResourceType.dataControllers}/${r.instanceName}`));
} else {
vscode.window.showErrorMessage(loc.couldNotFindControllerResource);
vscode.window.showErrorMessage(loc.couldNotFindRegistration(this._controllerModel.namespace, 'controller'));
}
});

Expand Down
26 changes: 18 additions & 8 deletions extensions/arc/src/ui/dashboards/miaa/miaaDashboardOverviewPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as azdata from 'azdata';
import * as vscode from 'vscode';
import * as loc from '../../../localizedConstants';
import { DashboardPage } from '../../components/dashboardPage';
import { IconPathHelper, cssStyles, ResourceType } from '../../../constants';
Expand Down Expand Up @@ -33,7 +34,7 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
subscriptionId: '-',
miaaAdmin: '-',
host: '-',
computeAndStorage: '-'
vCores: '-'
};

constructor(modelView: azdata.ModelView, private _controllerModel: ControllerModel, private _miaaModel: MiaaModel) {
Expand Down Expand Up @@ -157,7 +158,6 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
}).component();

this._databasesTableLoading = this.modelView.modelBuilder.loadingComponent().withItem(this._databasesTable).component();
this._databasesTableLoading.loading = false;
rootContainer.addItem(this._databasesTableLoading, { CSSStyles: { 'margin-bottom': '20px' } });

this.initialized = true;
Expand All @@ -166,8 +166,8 @@ export class MiaaDashboardOverviewPage extends DashboardPage {

public get toolbarContainer(): azdata.ToolbarContainer {

const createNewButton = this.modelView.modelBuilder.button().withProperties<azdata.ButtonProperties>({
label: loc.createNew,
const createDatabaseButton = this.modelView.modelBuilder.button().withProperties<azdata.ButtonProperties>({
label: loc.newDatabase,
iconPath: IconPathHelper.add
}).component();

Expand All @@ -186,9 +186,19 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
iconPath: IconPathHelper.openInTab
}).component();

openInAzurePortalButton.onDidClick(async () => {
const r = this._controllerModel.getRegistration(ResourceType.sqlManagedInstances, this._miaaModel.namespace, this._miaaModel.name);
if (r) {
vscode.env.openExternal(vscode.Uri.parse(
`https://portal.azure.com/#resource/subscriptions/${r.subscriptionId}/resourceGroups/${r.resourceGroupName}/providers/Microsoft.AzureData/${ResourceType.sqlManagedInstances}/${r.instanceName}`));
} else {
vscode.window.showErrorMessage(loc.couldNotFindRegistration(this._miaaModel.namespace, this._miaaModel.name));
}
});

return this.modelView.modelBuilder.toolbarContainer().withToolbarItems(
[
{ component: createNewButton },
{ component: createDatabaseButton },
{ component: deleteButton },
{ component: resetPasswordButton, toolbarSeparatorAfter: true },
{ component: openInAzurePortalButton }
Expand All @@ -203,7 +213,7 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
this._instanceProperties.dataController = this._controllerModel.controllerRegistration?.instanceName || '-';
this._instanceProperties.region = (await getAzurecoreApi()).getRegionDisplayName(reg.location);
this._instanceProperties.subscriptionId = reg.subscriptionId || '-';
this._instanceProperties.computeAndStorage = reg.vCores || '-';
this._instanceProperties.vCores = reg.vCores || '-';
this._instanceProperties.host = reg.externalEndpoint || '-';
this.refreshDisplayedProperties();
}
Expand Down Expand Up @@ -264,8 +274,8 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
value: this._instanceProperties.host
},
{
displayName: loc.computeAndStorage,
value: this._instanceProperties.computeAndStorage
displayName: loc.compute,
value: loc.numVCores(this._instanceProperties.vCores)
}
];

Expand Down
2 changes: 1 addition & 1 deletion src/sql/azdata.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ declare module 'azdata' {

// Admin Services interfaces -----------------------------------------------------------------------
export interface DatabaseInfo {
options: {};
options: { [key: string]: any };
}

export interface LoginInfo {
Expand Down

0 comments on commit 487bd26

Please sign in to comment.