Skip to content

Commit

Permalink
feat(clusters): add cluster resource
Browse files Browse the repository at this point in the history
  • Loading branch information
GermainBergeron committed Oct 18, 2019
1 parent e3a7123 commit 44d7a7a
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/resources/Clusters/Cluster.ts
Original file line number Diff line number Diff line change
@@ -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<ClusterStatusModel[]>(Cluster.baseUrl);
}

listAgents(id: string) {
return this.api.get<ClusterAgentModel[]>(`${Cluster.baseUrl}/${id}/agents`);
}

live() {
return this.api.get<ClusterModel>(`${Cluster.baseUrl}/live`);
}

status(id: string) {
return this.api.get<ClusterStatusModel>(`${Cluster.baseUrl}/${id}/status`);
}

synchronize(id: string) {
return this.api.post<{}>(`${Cluster.baseUrl}/${id}/synchronize`, {});
}
}
44 changes: 44 additions & 0 deletions src/resources/Clusters/ClusterInterfaces.ts
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions src/resources/Clusters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Cluster';
export * from './ClusterInterfaces';
59 changes: 59 additions & 0 deletions src/resources/Clusters/tests/Clusters.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import API from '../../../APICore';
import Cluster from '../Cluster';

jest.mock('../../../APICore');

const APIMock: jest.Mock<API> = API as any;

describe('Cluster', () => {
let cluster: Cluster;
const api = new APIMock() as jest.Mocked<API>;

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`, {});
});
});
});
3 changes: 3 additions & 0 deletions src/resources/PlatformResources.ts
Original file line number Diff line number Diff line change
@@ -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},
];
Expand All @@ -14,6 +16,7 @@ class PlatformResources {
protected API: API;

catalog: Catalog;
cluster: Clusters;
group: Group;
organization: Organization;

Expand Down
1 change: 1 addition & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
@@ -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';

0 comments on commit 44d7a7a

Please sign in to comment.