From 44d7a7a0067516c2876fc2cf858c61076930e3a9 Mon Sep 17 00:00:00 2001 From: Germain Bergeron Date: Fri, 18 Oct 2019 12:06:41 -0400 Subject: [PATCH] feat(clusters): add cluster resource --- src/resources/Clusters/Cluster.ts | 27 +++++++++ src/resources/Clusters/ClusterInterfaces.ts | 44 ++++++++++++++ src/resources/Clusters/index.ts | 2 + src/resources/Clusters/tests/Clusters.spec.ts | 59 +++++++++++++++++++ src/resources/PlatformResources.ts | 3 + src/resources/index.ts | 1 + 6 files changed, 136 insertions(+) create mode 100644 src/resources/Clusters/Cluster.ts create mode 100644 src/resources/Clusters/ClusterInterfaces.ts create mode 100644 src/resources/Clusters/index.ts create mode 100644 src/resources/Clusters/tests/Clusters.spec.ts diff --git a/src/resources/Clusters/Cluster.ts b/src/resources/Clusters/Cluster.ts new file mode 100644 index 000000000..696282e25 --- /dev/null +++ b/src/resources/Clusters/Cluster.ts @@ -0,0 +1,27 @@ +import API from '../../APICore'; +import Resource from '../Resource'; +import {ClusterAgentModel, ClusterModel, ClusterStatusModel} from './ClusterInterfaces'; + +export default class Cluster extends Resource { + static baseUrl = `/rest/organizations/${API.orgPlaceholder}/clusters`; + + list() { + return this.api.get(Cluster.baseUrl); + } + + listAgents(id: string) { + return this.api.get(`${Cluster.baseUrl}/${id}/agents`); + } + + live() { + return this.api.get(`${Cluster.baseUrl}/live`); + } + + status(id: string) { + return this.api.get(`${Cluster.baseUrl}/${id}/status`); + } + + synchronize(id: string) { + return this.api.post<{}>(`${Cluster.baseUrl}/${id}/synchronize`, {}); + } +} diff --git a/src/resources/Clusters/ClusterInterfaces.ts b/src/resources/Clusters/ClusterInterfaces.ts new file mode 100644 index 000000000..8356f5c70 --- /dev/null +++ b/src/resources/Clusters/ClusterInterfaces.ts @@ -0,0 +1,44 @@ +export interface ClusterResource { + name: string; + createdDate?: number; + status: string; + type: string; +} + +export interface ClusterStatusModel { + orgReadOnlyStatus: boolean; + currentProvisioningProgress: number; + initialProvisioningDone: boolean; + lastProvisioningCompletedDate?: number; + ongoing: boolean; + resources: ClusterResource[]; + status: string; +} + +export interface ClusterModel { + id: string; + identityTargetMode: string; + liveCluster: boolean; + organizationId: string; + componentVersions: { + connectorsVersion: string; + indexerVersion: string; + securityCacheVersion: string; + securityProviderVersion: string; + }; +} + +export interface ClusterAgentModel { + id: string; + name: string; + description: string; + platform: string; + version: string; + status: NodeStatusModel; +} +export interface NodeStatusModel { + message: string; + severity: string; + status: string; + timestamp: string; +} diff --git a/src/resources/Clusters/index.ts b/src/resources/Clusters/index.ts new file mode 100644 index 000000000..8e74421cd --- /dev/null +++ b/src/resources/Clusters/index.ts @@ -0,0 +1,2 @@ +export * from './Cluster'; +export * from './ClusterInterfaces'; diff --git a/src/resources/Clusters/tests/Clusters.spec.ts b/src/resources/Clusters/tests/Clusters.spec.ts new file mode 100644 index 000000000..274404a82 --- /dev/null +++ b/src/resources/Clusters/tests/Clusters.spec.ts @@ -0,0 +1,59 @@ +import API from '../../../APICore'; +import Cluster from '../Cluster'; + +jest.mock('../../../APICore'); + +const APIMock: jest.Mock = API as any; + +describe('Cluster', () => { + let cluster: Cluster; + const api = new APIMock() as jest.Mocked; + + beforeEach(() => { + jest.clearAllMocks(); + cluster = new Cluster(api); + }); + + describe('list', () => { + it('should make a GET call to the Cluster base url', () => { + cluster.list(); + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith(Cluster.baseUrl); + }); + }); + + describe('listAgents', () => { + it('should make a GET call to the cluster agents url', () => { + const clusterToGet = 'cluster-to-get'; + cluster.listAgents(clusterToGet); + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith(`${Cluster.baseUrl}/${clusterToGet}/agents`); + }); + }); + + describe('live', () => { + it('should make a GET call to the live cluster url', () => { + cluster.live(); + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith(`${Cluster.baseUrl}/live`); + }); + }); + + describe('status', () => { + it('should make a GET call to the status cluster url', () => { + const clusterToGet = 'cluster-to-get'; + cluster.status(clusterToGet); + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith(`${Cluster.baseUrl}/${clusterToGet}/status`); + }); + }); + + describe('synchronize', () => { + it('should make a POST call to the live cluster url', () => { + const clusterToSync = 'cluster-to-sync'; + cluster.synchronize(clusterToSync); + expect(api.post).toHaveBeenCalledTimes(1); + expect(api.post).toHaveBeenCalledWith(`${Cluster.baseUrl}/${clusterToSync}/synchronize`, {}); + }); + }); +}); diff --git a/src/resources/PlatformResources.ts b/src/resources/PlatformResources.ts index 7a1f659f5..3482267a7 100644 --- a/src/resources/PlatformResources.ts +++ b/src/resources/PlatformResources.ts @@ -1,11 +1,13 @@ import API from '../APICore'; import Catalog from './Catalogs/Catalog'; +import Clusters from './Clusters/Cluster'; import Group from './Groups/Groups'; import Organization from './Organizations/Organization'; import Resource from './Resource'; const resourcesMap: Array<{key: string; resource: typeof Resource}> = [ {key: 'catalog', resource: Catalog}, + {key: 'cluster', resource: Clusters}, {key: 'group', resource: Group}, {key: 'organization', resource: Organization}, ]; @@ -14,6 +16,7 @@ class PlatformResources { protected API: API; catalog: Catalog; + cluster: Clusters; group: Group; organization: Organization; diff --git a/src/resources/index.ts b/src/resources/index.ts index 9725d4167..fca98a83f 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -1,6 +1,7 @@ export * from './BaseInterfaces'; export * from './PlatformResources'; export * from './Catalogs'; +export * from './Clusters'; export * from './Groups'; export * from './Organizations'; export * from './License';