Hook up MIAA dashboard overview (#10890)

* Hook up MIAA dashboard overview

* Fix merge conflicts

* Fix links

* Remove extra &
This commit is contained in:
Charles Gagnon
2020-06-15 11:25:31 -07:00
committed by GitHub
parent ff8b03aa5e
commit d9e70731f4
16 changed files with 335 additions and 126 deletions

View File

@@ -61,19 +61,19 @@ export class ControllerModel {
]);
}
public endpoints(): EndpointModel[] {
public get endpoints(): EndpointModel[] {
return this._endpoints;
}
public endpoint(name: string): EndpointModel | undefined {
public getEndpoint(name: string): EndpointModel | undefined {
return this._endpoints.find(e => e.name === name);
}
public namespace(): string {
public get namespace(): string {
return this._namespace;
}
public registrations(): Registration[] {
public get registrations(): Registration[] {
return this._registrations;
}

View File

@@ -5,24 +5,72 @@
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import { SqlInstanceRouterApi } from '../controller/generated/v1/api/sqlInstanceRouterApi';
import { HybridSqlNsNameGetResponse } from '../controller/generated/v1/model/hybridSqlNsNameGetResponse';
import { Authentication } from '../controller/generated/v1/api';
export type DatabaseModel = { name: string, status: string };
export class MiaaModel {
private _sqlInstanceRouter: SqlInstanceRouterApi;
private _status: HybridSqlNsNameGetResponse | undefined;
private readonly _onPasswordUpdated = new vscode.EventEmitter<string>();
private readonly _onStatusUpdated = new vscode.EventEmitter<HybridSqlNsNameGetResponse>();
private readonly _onDatabasesUpdated = new vscode.EventEmitter<DatabaseModel[]>();
public onPasswordUpdated = this._onPasswordUpdated.event;
public onStatusUpdated = this._onStatusUpdated.event;
public onDatabasesUpdated = this._onDatabasesUpdated.event;
public passwordLastUpdated?: Date;
constructor(public connectionProfile: azdata.IConnectionProfile, private _name: string) {
constructor(public connectionProfile: azdata.IConnectionProfile, controllerUrl: string, auth: Authentication, private _namespace: string, private _name: string) {
this._sqlInstanceRouter = new SqlInstanceRouterApi(controllerUrl);
this._sqlInstanceRouter.setDefaultAuthentication(auth);
}
/** Returns the service's name */
/**
* The name of this instance
*/
public get name(): string {
return this._name;
}
/**
* The namespace of this instance
*/
public get namespace(): string {
return this._namespace;
}
/**
* The status of this instance
*/
public get status(): string {
return this._status?.status || '';
}
/**
* The cluster endpoint of this instance
*/
public get clusterEndpoint(): string {
return this._status?.cluster_endpoint || '';
}
public get databases(): DatabaseModel[] {
return [
{ name: 'contosoMI54', status: 'online' },
{ name: 'contosoMI56', status: 'online' },
{ name: 'contosoMI58', status: 'online' },
];
}
/** Refreshes the model */
public async refresh() {
await Promise.all([
]);
public async refresh(): Promise<void> {
this._sqlInstanceRouter.apiV1HybridSqlNsNameGet(this._namespace, this._name).then(response => {
this._status = response.body;
this._onStatusUpdated.fire(this._status);
this._onDatabasesUpdated.fire(this.databases);
});
}
}

View File

@@ -35,32 +35,32 @@ export class PostgresModel {
}
/** Returns the service's Kubernetes namespace */
public namespace(): string {
public get namespace(): string {
return this._namespace;
}
/** Returns the service's name */
public name(): string {
public get name(): string {
return this._name;
}
/** Returns the service's fully qualified name in the format namespace.name */
public fullName(): string {
public get fullName(): string {
return `${this._namespace}.${this._name}`;
}
/** Returns the service's spec */
public service(): DuskyObjectModelsDatabaseService | undefined {
public get service(): DuskyObjectModelsDatabaseService | undefined {
return this._service;
}
/** Returns the service's password */
public password(): string | undefined {
public get password(): string | undefined {
return this._password;
}
/** Returns the service's pods */
public pods(): V1Pod[] | undefined {
public get pods(): V1Pod[] | undefined {
return this._pods;
}
@@ -95,7 +95,7 @@ export class PostgresModel {
service.status = undefined; // can't update the status
func(service);
return await this._databaseRouter.updateDuskyDatabaseService(this.namespace(), this.name(), service).then(r => {
return await this._databaseRouter.updateDuskyDatabaseService(this.namespace, this.name, service).then(r => {
this._service = r.body;
return this._service;
});
@@ -108,14 +108,14 @@ export class PostgresModel {
/** Creates a SQL database in the service */
public async createDatabase(db: DuskyObjectModelsDatabase): Promise<DuskyObjectModelsDatabase> {
return await (await this._databaseRouter.createDuskyDatabase(this.namespace(), this.name(), db)).body;
return await (await this._databaseRouter.createDuskyDatabase(this.namespace, this.name, db)).body;
}
/**
* Returns the IP address and port of the service, preferring external IP over
* internal IP. If either field is not available it will be set to undefined.
*/
public endpoint(): { ip?: string, port?: number } {
public get endpoint(): { ip?: string, port?: number } {
const externalIp = this._service?.status?.externalIP;
const internalIp = this._service?.status?.internalIP;
const externalPort = this._service?.status?.externalPort;
@@ -127,7 +127,7 @@ export class PostgresModel {
}
/** Returns the service's configuration e.g. '3 nodes, 1.5 vCores, 1GiB RAM, 2GiB storage per node' */
public configuration(): string {
public get configuration(): string {
// TODO: Resource requests and limits can be configured per role. Figure out how
// to display that in the UI. For now, only show the default configuration.
@@ -136,7 +136,7 @@ export class PostgresModel {
const cpuRequest = this._service?.spec?.scheduling?._default?.resources?.requests?.['cpu'];
const ramRequest = this._service?.spec?.scheduling?._default?.resources?.requests?.['memory'];
const storage = this._service?.spec?.storage?.volumeSize;
const nodes = this.pods()?.length;
const nodes = this.pods?.length;
let configuration: string[] = [];