mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Initial work on Arc tree view (#11008)
* Initial work on Arc tree view * finish my thoughts
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { Authentication } from '../controller/auth';
|
||||
import { EndpointsRouterApi, EndpointModel, RegistrationRouterApi, RegistrationResponse, TokenRouterApi, SqlInstanceRouterApi } from '../controller/generated/v1/api';
|
||||
import { parseEndpoint } from '../common/utils';
|
||||
import { parseEndpoint, parseInstanceName } from '../common/utils';
|
||||
import { ResourceType } from '../constants';
|
||||
|
||||
export interface Registration extends RegistrationResponse {
|
||||
@@ -31,7 +31,7 @@ export class ControllerModel {
|
||||
public endpointsLastUpdated?: Date;
|
||||
public registrationsLastUpdated?: Date;
|
||||
|
||||
constructor(controllerUrl: string, auth: Authentication) {
|
||||
constructor(public readonly controllerUrl: string, public readonly auth: Authentication) {
|
||||
this._endpointsRouter = new EndpointsRouterApi(controllerUrl);
|
||||
this._endpointsRouter.setDefaultAuthentication(auth);
|
||||
|
||||
@@ -84,16 +84,7 @@ export class ControllerModel {
|
||||
|
||||
public getRegistration(type: string, namespace: string, name: string): Registration | undefined {
|
||||
return this._registrations.find(r => {
|
||||
// Resources deployed outside the controller's namespace are named in the format 'namespace_name'
|
||||
let instanceName = r.instanceName!;
|
||||
const parts: string[] = instanceName.split('_');
|
||||
if (parts.length === 2) {
|
||||
instanceName = parts[1];
|
||||
}
|
||||
else if (parts.length > 2) {
|
||||
throw new Error(`Cannot parse resource '${instanceName}'. Acceptable formats are 'namespace_name' or 'name'.`);
|
||||
}
|
||||
return r.instanceType === type && r.instanceNamespace === namespace && instanceName === name;
|
||||
return r.instanceType === type && r.instanceNamespace === namespace && parseInstanceName(r.instanceName) === name;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ export class MiaaModel {
|
||||
private _sqlInstanceRouter: SqlInstanceRouterApi;
|
||||
private _status: HybridSqlNsNameGetResponse | undefined;
|
||||
private _databases: DatabaseModel[] = [];
|
||||
private _connectionProfile: azdata.IConnectionProfile | undefined = undefined;
|
||||
|
||||
private readonly _onPasswordUpdated = new vscode.EventEmitter<string>();
|
||||
private readonly _onStatusUpdated = new vscode.EventEmitter<HybridSqlNsNameGetResponse>();
|
||||
private readonly _onDatabasesUpdated = new vscode.EventEmitter<DatabaseModel[]>();
|
||||
@@ -24,7 +26,7 @@ export class MiaaModel {
|
||||
public onDatabasesUpdated = this._onDatabasesUpdated.event;
|
||||
public passwordLastUpdated?: Date;
|
||||
|
||||
constructor(public connectionProfile: azdata.IConnectionProfile, controllerUrl: string, auth: Authentication, private _namespace: string, private _name: string) {
|
||||
constructor(controllerUrl: string, auth: Authentication, private _namespace: string, private _name: string) {
|
||||
this._sqlInstanceRouter = new SqlInstanceRouterApi(controllerUrl);
|
||||
this._sqlInstanceRouter.setDefaultAuthentication(auth);
|
||||
}
|
||||
@@ -43,6 +45,13 @@ export class MiaaModel {
|
||||
return this._namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* The username used to connect to this instance
|
||||
*/
|
||||
public get username(): string | undefined {
|
||||
return this._connectionProfile?.userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The status of this instance
|
||||
*/
|
||||
@@ -67,17 +76,44 @@ export class MiaaModel {
|
||||
this._status = response.body;
|
||||
this._onStatusUpdated.fire(this._status);
|
||||
});
|
||||
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);
|
||||
const promises: Thenable<any>[] = [instanceRefresh];
|
||||
await this.getConnection();
|
||||
if (this._connectionProfile) {
|
||||
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]);
|
||||
promises.push(databasesRefresh);
|
||||
}
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
private async getConnection(): Promise<void> {
|
||||
if (this._connectionProfile) {
|
||||
return;
|
||||
}
|
||||
const connection = await azdata.connection.openConnectionDialog(['MSSQL']);
|
||||
this._connectionProfile = {
|
||||
serverName: connection.options['serverName'],
|
||||
databaseName: connection.options['databaseName'],
|
||||
authenticationType: connection.options['authenticationType'],
|
||||
providerName: 'MSSQL',
|
||||
connectionName: '',
|
||||
userName: connection.options['user'],
|
||||
password: connection.options['password'],
|
||||
savePassword: false,
|
||||
groupFullName: undefined,
|
||||
saveProfile: true,
|
||||
id: connection.connectionId,
|
||||
groupId: undefined,
|
||||
options: connection.options
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user