defining arc api (#12153)

* defining arcApi

* pr feedback

* activate arc extension in test

* skip failing test temporarily

* remove arcService test file
This commit is contained in:
Arvind Ranasaria
2020-09-05 10:09:15 -07:00
committed by GitHub
parent 3d7d1b23cb
commit c5d0c6f623
22 changed files with 137 additions and 75 deletions

View File

@@ -3,10 +3,11 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { ResourceType } from 'arc';
import * as azurecore from 'azurecore';
import * as vscode from 'vscode';
import { ConnectionMode, IconPath, IconPathHelper } from '../constants';
import * as loc from '../localizedConstants';
import { IconPathHelper, IconPath, ResourceType, ConnectionMode } from '../constants';
export class UserCancelledError extends Error { }

View File

@@ -118,11 +118,6 @@ export class IconPathHelper {
}
}
export const enum ResourceType {
dataControllers = 'dataControllers',
postgresInstances = 'postgresInstances',
sqlManagedInstances = 'sqlManagedInstances'
}
export const enum Endpoints {
mgmtproxy = 'mgmtproxy',

View File

@@ -3,15 +3,16 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as arc from 'arc';
import * as vscode from 'vscode';
import * as loc from './localizedConstants';
import { IconPathHelper, refreshActionId } from './constants';
import * as loc from './localizedConstants';
import { ConnectToControllerDialog } from './ui/dialogs/connectControllerDialog';
import { AzureArcTreeDataProvider } from './ui/tree/azureArcTreeDataProvider';
import { ControllerTreeNode } from './ui/tree/controllerTreeNode';
import { TreeNode } from './ui/tree/treeNode';
import { ConnectToControllerDialog } from './ui/dialogs/connectControllerDialog';
export async function activate(context: vscode.ExtensionContext): Promise<void> {
export async function activate(context: vscode.ExtensionContext): Promise<arc.IExtension> {
IconPathHelper.setExtensionContext(context);
await vscode.commands.executeCommand('setContext', 'arc.loaded', false);
@@ -54,6 +55,15 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
});
await checkArcDeploymentExtension();
return {
getRegisteredDataControllers: async () => {
return (await treeDataProvider.getChildren())
.filter(node => node instanceof ControllerTreeNode)
.map(node => (node as ControllerTreeNode).model.info);
}
};
}
export function deactivate(): void {
@@ -62,7 +72,7 @@ export function deactivate(): void {
async function checkArcDeploymentExtension(): Promise<void> {
const version = vscode.extensions.getExtension('Microsoft.arcdeployment')?.packageJSON.version;
if (version && version !== '0.3.2') {
// If we have an older verison of the deployment extension installed then uninstall it now since it's replaced
// If we have an older version of the deployment extension installed then uninstall it now since it's replaced
// by this extension. (the latest version of the Arc Deployment extension will uninstall itself so don't do
// anything here if that's already updated)
await vscode.commands.executeCommand('workbench.extensions.uninstallExtension', 'Microsoft.arcdeployment');

View File

@@ -3,28 +3,13 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ControllerInfo, ResourceType } from 'arc';
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 { ConnectToControllerDialog } from '../ui/dialogs/connectControllerDialog';
export type ControllerInfo = {
id: string,
url: string,
name: string,
username: string,
rememberPassword: boolean,
resources: ResourceInfo[]
};
export type ResourceInfo = {
name: string,
resourceType: ResourceType | string,
connectionId?: string
};
import { AzureArcTreeDataProvider } from '../ui/tree/azureArcTreeDataProvider';
export type Registration = {
instanceName: string,

View File

@@ -3,15 +3,16 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ResourceInfo } from 'arc';
import * as azdata from 'azdata';
import * as azdataExt from 'azdata-ext';
import * as vscode from 'vscode';
import { ResourceModel } from './resourceModel';
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 loc from '../localizedConstants';
import { AzureArcTreeDataProvider } from '../ui/tree/azureArcTreeDataProvider';
import { ControllerModel, Registration } from './controllerModel';
import { ResourceModel } from './resourceModel';
export type DatabaseModel = { name: string, status: string };

View File

@@ -3,9 +3,10 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ResourceInfo } from 'arc';
import * as vscode from 'vscode';
import * as loc from '../localizedConstants';
import { ResourceInfo, Registration } from './controllerModel';
import { Registration } from './controllerModel';
import { ResourceModel } from './resourceModel';
export enum PodRole {

View File

@@ -3,8 +3,9 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ResourceInfo } from 'arc';
import * as vscode from 'vscode';
import { ResourceInfo, Registration } from './controllerModel';
import { Registration } from './controllerModel';
export abstract class ResourceModel {

View File

@@ -3,15 +3,16 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as should from 'should';
import { ResourceType } from 'arc';
import 'mocha';
import { resourceTypeToDisplayName, parseEndpoint, parseInstanceName, getAzurecoreApi, getResourceTypeIcon, getConnectionModeDisplayText, getDatabaseStateDisplayText, promptForResourceDeletion, promptAndConfirmPassword, getErrorMessage, parseIpAndPort } from '../../common/utils';
import * as should from 'should';
import * as vscode from 'vscode';
import { getAzurecoreApi, getConnectionModeDisplayText, getDatabaseStateDisplayText, getErrorMessage, getResourceTypeIcon, parseEndpoint, parseInstanceName, parseIpAndPort, promptAndConfirmPassword, promptForResourceDeletion, resourceTypeToDisplayName } from '../../common/utils';
import { ConnectionMode as ConnectionMode, IconPathHelper } from '../../constants';
import * as loc from '../../localizedConstants';
import { ResourceType, IconPathHelper, ConnectionMode as ConnectionMode } from '../../constants';
import { MockInputBox } from '../stubs';
describe('resourceTypeToDisplayName Method Tests', function (): void {
it('Display Name should be correct for valid ResourceType', function (): void {
should(resourceTypeToDisplayName(ResourceType.dataControllers)).equal(loc.dataControllersType);

View File

@@ -3,8 +3,9 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ControllerInfo } from 'arc';
import { v4 as uuid } from 'uuid';
import { ControllerModel, ControllerInfo } from '../../models/controllerModel';
import { ControllerModel } from '../../models/controllerModel';
import { AzureArcTreeDataProvider } from '../../ui/tree/azureArcTreeDataProvider';
export class FakeControllerModel extends ControllerModel {

View File

@@ -3,17 +3,18 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ControllerInfo } from 'arc';
import * as azdata from 'azdata';
import * as azdataExt from 'azdata-ext';
import * as should from 'should';
import * as sinon from 'sinon';
import * as TypeMoq from 'typemoq';
import * as vscode from 'vscode';
import * as should from 'should';
import { v4 as uuid } from 'uuid';
import { ConnectToControllerDialog } from '../../ui/dialogs/connectControllerDialog';
import { ControllerModel, ControllerInfo } from '../../models/controllerModel';
import { AzureArcTreeDataProvider } from '../../ui/tree/azureArcTreeDataProvider';
import * as vscode from 'vscode';
import { UserCancelledError } from '../../common/utils';
import { ControllerModel } from '../../models/controllerModel';
import { ConnectToControllerDialog } from '../../ui/dialogs/connectControllerDialog';
import { AzureArcTreeDataProvider } from '../../ui/tree/azureArcTreeDataProvider';
describe('ControllerModel', function (): void {
afterEach(function (): void {

View File

@@ -3,12 +3,13 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ControllerInfo } from 'arc';
import * as should from 'should';
import * as sinon from 'sinon';
import { ControllerInfo, ControllerModel } from '../../../models/controllerModel';
import { ConnectToControllerDialog } from '../../../ui/dialogs/connectControllerDialog';
import * as loc from '../../../localizedConstants';
import { v4 as uuid } from 'uuid';
import * as loc from '../../../localizedConstants';
import { ControllerModel } from '../../../models/controllerModel';
import { ConnectToControllerDialog } from '../../../ui/dialogs/connectControllerDialog';
describe('ConnectControllerDialog', function (): void {
afterEach(function (): void {

View File

@@ -3,12 +3,13 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ControllerInfo } from 'arc';
import 'mocha';
import * as should from 'should';
import * as TypeMoq from 'typemoq';
import { v4 as uuid } from 'uuid';
import * as vscode from 'vscode';
import { ControllerModel, ControllerInfo } from '../../../models/controllerModel';
import { ControllerModel } from '../../../models/controllerModel';
import { AzureArcTreeDataProvider } from '../../../ui/tree/azureArcTreeDataProvider';
import { ControllerTreeNode } from '../../../ui/tree/controllerTreeNode';
import { FakeControllerModel } from '../../mocks/fakeControllerModel';

41
extensions/arc/src/typings/arc.d.ts vendored Normal file
View File

@@ -0,0 +1,41 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare module 'arc' {
import * as vscode from 'vscode';
/**
* Covers defining what the arc extension exports to other extensions
*
* IMPORTANT: THIS IS NOT A HARD DEFINITION unlike vscode; therefore no enums or classes should be defined here
* (const enums get evaluated when typescript -> javascript so those are fine)
*/
export const enum extension {
name = 'Microsoft.arc'
}
export const enum ResourceType {
dataControllers = 'dataControllers',
postgresInstances = 'postgresInstances',
sqlManagedInstances = 'sqlManagedInstances'
}
export type ResourceInfo = {
name: string,
resourceType: ResourceType | string,
connectionId?: string
};
export type ControllerInfo = {
id: string,
url: string,
name: string,
username: string,
rememberPassword: boolean,
resources: ResourceInfo[]
};
export interface IExtension {
getRegisteredDataControllers(): Promise<ControllerInfo[]>;
}
}

View File

@@ -3,14 +3,15 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ResourceType } from 'arc';
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import * as azurecore from 'azurecore';
import * as vscode from 'vscode';
import { getConnectionModeDisplayText, getResourceTypeIcon, parseInstanceName, resourceTypeToDisplayName } from '../../../common/utils';
import { cssStyles, Endpoints, IconPathHelper, iconSize } from '../../../constants';
import * as loc from '../../../localizedConstants';
import { DashboardPage } from '../../components/dashboardPage';
import { IconPathHelper, cssStyles, iconSize, ResourceType, Endpoints } from '../../../constants';
import { ControllerModel } from '../../../models/controllerModel';
import { resourceTypeToDisplayName, getResourceTypeIcon, parseInstanceName, getConnectionModeDisplayText } from '../../../common/utils';
import { DashboardPage } from '../../components/dashboardPage';
export class ControllerDashboardOverviewPage extends DashboardPage {

View File

@@ -5,14 +5,15 @@
import * as azdata from 'azdata';
import * as azdataExt from 'azdata-ext';
import * as vscode from 'vscode';
import * as loc from '../../../localizedConstants';
import * as azurecore from 'azurecore';
import { DashboardPage } from '../../components/dashboardPage';
import { IconPathHelper, cssStyles, Endpoints, ResourceType } from '../../../constants';
import { ControllerModel } from '../../../models/controllerModel';
import * as vscode from 'vscode';
import { getDatabaseStateDisplayText, promptForResourceDeletion } from '../../../common/utils';
import { cssStyles, Endpoints, IconPathHelper } from '../../../constants';
import * as loc from '../../../localizedConstants';
import { ControllerModel } from '../../../models/controllerModel';
import { MiaaModel } from '../../../models/miaaModel';
import { DashboardPage } from '../../components/dashboardPage';
import { ResourceType } from 'arc';
export class MiaaDashboardOverviewPage extends DashboardPage {

View File

@@ -3,12 +3,13 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ControllerInfo } from 'arc';
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import { v4 as uuid } from 'uuid';
import * as vscode from 'vscode';
import { Deferred } from '../../common/promise';
import * as loc from '../../localizedConstants';
import { ControllerInfo, ControllerModel } from '../../models/controllerModel';
import { ControllerModel } from '../../models/controllerModel';
import { InitializingComponent } from '../components/initializingComponent';
import { AzureArcTreeDataProvider } from '../tree/azureArcTreeDataProvider';

View File

@@ -3,11 +3,12 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ControllerInfo } from 'arc';
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import { ControllerModel } from '../../models/controllerModel';
import { ControllerTreeNode } from './controllerTreeNode';
import { TreeNode } from './treeNode';
import { ControllerModel, ControllerInfo } from '../../models/controllerModel';
const mementoToken = 'arcControllers';

View File

@@ -3,20 +3,20 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ResourceInfo, ResourceType } from 'arc';
import * as vscode from 'vscode';
import { TreeNode } from './treeNode';
import { MiaaTreeNode } from './miaaTreeNode';
import { ResourceType } from '../../constants';
import { PostgresTreeNode } from './postgresTreeNode';
import { ControllerModel, Registration, ResourceInfo } from '../../models/controllerModel';
import { ControllerDashboard } from '../dashboards/controller/controllerDashboard';
import { PostgresModel } from '../../models/postgresModel';
import { parseInstanceName, UserCancelledError } from '../../common/utils';
import * as loc from '../../localizedConstants';
import { ControllerModel, Registration } from '../../models/controllerModel';
import { MiaaModel } from '../../models/miaaModel';
import { PostgresModel } from '../../models/postgresModel';
import { ControllerDashboard } from '../dashboards/controller/controllerDashboard';
import { AzureArcTreeDataProvider } from './azureArcTreeDataProvider';
import { MiaaTreeNode } from './miaaTreeNode';
import { PostgresTreeNode } from './postgresTreeNode';
import { RefreshTreeNode } from './refreshTreeNode';
import { ResourceTreeNode } from './resourceTreeNode';
import { AzureArcTreeDataProvider } from './azureArcTreeDataProvider';
import * as loc from '../../localizedConstants';
import { TreeNode } from './treeNode';
/**
* The TreeNode for displaying an Azure Arc Controller

View File

@@ -3,12 +3,12 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ResourceType } from 'arc';
import * as vscode from 'vscode';
import { ResourceType } from '../../constants';
import { TreeNode } from './treeNode';
import { MiaaModel } from '../../models/miaaModel';
import { ControllerModel } from '../../models/controllerModel';
import { MiaaModel } from '../../models/miaaModel';
import { MiaaDashboard } from '../dashboards/miaa/miaaDashboard';
import { TreeNode } from './treeNode';
/**
* The TreeNode for displaying a SQL Managed Instance on Azure Arc

View File

@@ -3,10 +3,10 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ResourceType } from 'arc';
import * as vscode from 'vscode';
import { ResourceType } from '../../constants';
import { PostgresModel } from '../../models/postgresModel';
import { ControllerModel } from '../../models/controllerModel';
import { PostgresModel } from '../../models/postgresModel';
import { PostgresDashboard } from '../dashboards/postgres/postgresDashboard';
import { ResourceTreeNode } from './resourceTreeNode';

View File

@@ -0,0 +1,17 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as arc from 'arc';
import * as vscode from 'vscode';
export class ArcService {
private _arcApi: arc.IExtension;
constructor() {
this._arcApi = vscode.extensions.getExtension(arc.extension.name)?.exports;
}
public async getRegisteredDataControllers(): Promise<arc.ControllerInfo[]> {
return await this._arcApi.getRegisteredDataControllers();
}
}

View File

@@ -6,6 +6,7 @@
/// <reference path='../../../../src/vs/vscode.d.ts'/>
/// <reference path='../../../../src/sql/azdata.d.ts'/>
/// <reference path='../../../../src/sql/azdata.proposed.d.ts'/>
/// <reference path='../../../arc/src/typings/arc.d.ts'/>
/// <reference path='../../../azurecore/src/azurecore.d.ts'/>
/// <reference path='../../../azurecore/src/azureResource/azure-resource.d.ts'/>
/// <reference types='@types/node'/>