Skip to content

Commit

Permalink
Merge pull request #24 from coveo/feature-clusters-resource
Browse files Browse the repository at this point in the history
feat(clusters): add cluster resource
  • Loading branch information
GermainBergeron authored Oct 22, 2019
2 parents e1baf70 + 7113b38 commit a648513
Show file tree
Hide file tree
Showing 6 changed files with 200 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<ClusterModel[]>(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`, {});
}
}
108 changes: 108 additions & 0 deletions src/resources/Clusters/ClusterInterfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
export interface ClusterResource {
id: string;
name: string;
createdDate?: number;
status: 'QUEUED_TO_CREATE' | 'CREATING' | 'REMOVING' | 'UPGRADING' | 'PAUSED' | 'COMPLETED' | 'ERROR';
type: string;
numberOfRetries: number;
}

export interface ClusterStatusModel {
orgReadOnlyStatus: boolean;
currentProvisioningProgress: number;
initialProvisioningDone: boolean;
lastProvisioningCompletedDate?: number;
ongoing: boolean;
resources: ClusterResource[];
retryScheduled: boolean;
status: 'ERROR' | 'HEALTHY';
}

export interface ClusterTopologyModel {
agents: ClusterTopologyAgentModel[];
crawlerDbConnectionString: string;
dpmDocUri: string;
indexDocUri: string;
indexers: ClusterIndexerModel[];
rabbitServerId: string;
secCacheJobUri: string;
secClusterSyncUri: string;
securityCaches: ClusterSecurityCacheModel[];
securityProviderDbConnectionString: string;
securityProviders: ClusterSecurityProviderModel[];
topologyId: string;
}

export interface ClusterTopologyAgentModel {
id: string;
machineSpec: ClusterMachineSpecModel;
storages: ClusterStorageSpecModel[];
}

export interface ClusterStorageSpecModel {
numberOfIops: number;
sizeInGibibytes: number;
sizeInGigabytes: number;
storageType: 'STANDARD' | 'SSD' | 'PROVISIONED_SSD';
}

export interface ClusterMachineSpecModel {
architecture: string;
storageSpec: ClusterStorageSpecModel;
}

export interface ClusterComponentModel {
adminPort: number;
adminUri: string;
agentId: string;
componentName: string;
componentPlatform: string;
componentVersion: string;
id: string;
name: string;
}

export interface ClusterIndexerModel extends ClusterComponentModel {
indexerDocUri: string;
searchPort: number;
searchServerUri: string;
}

export interface ClusterSecurityCacheModel extends ClusterComponentModel {
secCacheSyncUri: string;
}

export interface ClusterSecurityProviderModel extends ClusterComponentModel {
type: string;
useDefaultConfiguration: boolean;
}

export interface ClusterModel {
id: string;
identityTargetMode: string;
liveCluster: boolean;
organizationId: string;
componentVersions: {
connectorsVersion: string;
indexerVersion: string;
securityCacheVersion: string;
securityProviderVersion: string;
};
clusterTopology: ClusterTopologyModel;
}

export interface ClusterAgentModel {
id: string;
name: string;
description: string;
platform: string;
version: string;
status: ClusterNodeStatusModel;
}

export interface ClusterNodeStatusModel {
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,13 +1,15 @@
import API from '../APICore';
import ApiKey from './ApiKeys/ApiKeys';
import Catalog from './Catalogs/Catalog';
import Cluster from './Clusters/Cluster';
import Group from './Groups/Groups';
import Organization from './Organizations/Organization';
import Resource from './Resource';
import SecurityCache from './SecurityCache/SecurityCache';

const resourcesMap: Array<{key: string; resource: typeof Resource}> = [
{key: 'catalog', resource: Catalog},
{key: 'cluster', resource: Cluster},
{key: 'group', resource: Group},
{key: 'organization', resource: Organization},
{key: 'securityCache', resource: SecurityCache},
Expand All @@ -18,6 +20,7 @@ class PlatformResources {
protected API: API;

catalog: Catalog;
cluster: Cluster;
group: Group;
organization: Organization;
apiKey: ApiKey;
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';
Expand Down

0 comments on commit a648513

Please sign in to comment.