Skip to content

Commit

Permalink
Merge pull request #26 from coveo/featured-cluster-agent-node
Browse files Browse the repository at this point in the history
Featured cluster agent node
  • Loading branch information
pochretien authored Oct 23, 2019
2 parents e0e4a40 + f5249a8 commit d8a40cb
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 11 deletions.
17 changes: 17 additions & 0 deletions src/resources/Clusters/Agents/ClusterAgent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import API from '../../../APICore';
import Resource from '../../Resource';
import {ClusterNodeUpgradeDataModel} from '../ClusterInterfaces';
import {ClusterNodeUpgradeModel} from '../Nodes';
import {ClusterAgentModel} from './ClusterAgentInterfaces';

export default class ClusterAgent extends Resource {
static getBaseUrl = (id: string) => `/rest/organizations/${API.orgPlaceholder}/clusters/${id}/agents`;

list(clusterId: string) {
return this.api.get<ClusterAgentModel[]>(ClusterAgent.getBaseUrl(clusterId));
}

upgrade(clusterId: string, id: string, data: ClusterNodeUpgradeDataModel) {
return this.api.put<ClusterNodeUpgradeModel[]>(`${ClusterAgent.getBaseUrl(clusterId)}/${id}/upgrades`, data);
}
}
10 changes: 10 additions & 0 deletions src/resources/Clusters/Agents/ClusterAgentInterfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {ClusterNodeStatusModel} from '../ClusterInterfaces';

export interface ClusterAgentModel {
id: string;
name: string;
description: string;
platform: string;
version: string;
status: ClusterNodeStatusModel;
}
2 changes: 2 additions & 0 deletions src/resources/Clusters/Agents/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ClusterAgent';
export * from './ClusterAgentInterfaces';
38 changes: 38 additions & 0 deletions src/resources/Clusters/Agents/tests/ClusterAgent.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import API from '../../../../APICore';
import {ClusterNodeUpgradeDataModel} from '../../ClusterInterfaces';
import ClusterAgent from '../ClusterAgent';

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

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

describe('clusterAgent', () => {
let clusterAgent: ClusterAgent;
const api = new APIMock() as jest.Mocked<API>;
const clusterId = '🦋';

beforeEach(() => {
jest.clearAllMocks();
clusterAgent = new ClusterAgent(api);
});

describe('list', () => {
it('should make a GET call to the ClusterAgent base url', () => {
clusterAgent.list(clusterId);

expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(ClusterAgent.getBaseUrl(clusterId));
});
});

describe('upgrade', () => {
it('should make a PUT call to the upgrade cluster agent url', () => {
const agentId = '👐';
const data: ClusterNodeUpgradeDataModel = {componentName: 'butterfly', version: '1.2.3'};
clusterAgent.upgrade(clusterId, agentId, data);

expect(api.put).toHaveBeenCalledTimes(1);
expect(api.put).toHaveBeenCalledWith(`${ClusterAgent.getBaseUrl(clusterId)}/${agentId}/upgrades`, data);
});
});
});
17 changes: 15 additions & 2 deletions src/resources/Clusters/Cluster.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import API from '../../APICore';
import Resource from '../Resource';
import {ClusterAgentModel, ClusterModel, ClusterStatusModel} from './ClusterInterfaces';
import ClusterAgent from './Agents/ClusterAgent';
import {ClusterModel, ClusterStatusModel} from './ClusterInterfaces';
import ClusterNode from './Nodes/ClusterNode';

export default class Cluster extends Resource {
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/clusters`;

nodes: ClusterNode;
agents: ClusterAgent;

constructor(protected api: API) {
super(api);

this.nodes = new ClusterNode(api);
this.agents = new ClusterAgent(api);
}

list() {
return this.api.get<ClusterModel[]>(Cluster.baseUrl);
}

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

live() {
Expand Down
14 changes: 5 additions & 9 deletions src/resources/Clusters/ClusterInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,14 @@ export interface ClusterModel {
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;
}

export interface ClusterNodeUpgradeDataModel {
componentName: string;
version: string;
}
32 changes: 32 additions & 0 deletions src/resources/Clusters/Nodes/ClusterNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import API from '../../../APICore';
import Resource from '../../Resource';
import {ClusterNodeUpgradeDataModel} from '../ClusterInterfaces';
import {ClusterNodeModel, ClusterNodeUpgradeModel} from './ClusterNodeInterfaces';

export default class ClusterNode extends Resource {
static getBaseUrl = (id: string) => `/rest/organizations/${API.orgPlaceholder}/clusters/${id}/nodes`;

list(clusterId: string) {
return this.api.get<ClusterNodeModel[]>(ClusterNode.getBaseUrl(clusterId));
}

listUpgrades(clusterId: string, id: string) {
return this.api.get<ClusterNodeUpgradeModel[]>(`${ClusterNode.getBaseUrl(clusterId)}/${id}/upgrades`);
}

start(clusterId: string, id: string) {
return this.api.post<{}>(`${ClusterNode.getBaseUrl(clusterId)}/${id}/start`, {});
}

stop(clusterId: string, id: string) {
return this.api.post<{}>(`${ClusterNode.getBaseUrl(clusterId)}/${id}/stop`, {});
}

dump(clusterId: string, id: string) {
return this.api.post<{}>(`${ClusterNode.getBaseUrl(clusterId)}/${id}/dumps`, {});
}

upgrade(clusterId: string, id: string, data: ClusterNodeUpgradeDataModel) {
return this.api.put<ClusterNodeUpgradeModel[]>(`${ClusterNode.getBaseUrl(clusterId)}/${id}/upgrades`, data);
}
}
22 changes: 22 additions & 0 deletions src/resources/Clusters/Nodes/ClusterNodeInterfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {ClusterNodeStatusModel} from '../ClusterInterfaces';

export interface ClusterNodeModel {
adminURI: string;
agentId: string;
componentName: string;
id: string;
indexId: string;
instanceType: string;
isCustom: boolean;
latestVersion: string;
name: string;
params?: any;
status: ClusterNodeStatusModel;
version: string;
}

export interface ClusterNodeUpgradeModel {
name: string;
platform: string;
version: string;
}
2 changes: 2 additions & 0 deletions src/resources/Clusters/Nodes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ClusterNode';
export * from './ClusterNodeInterfaces';
78 changes: 78 additions & 0 deletions src/resources/Clusters/Nodes/tests/ClusterNode.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import API from '../../../../APICore';
import {ClusterNodeUpgradeDataModel} from '../../ClusterInterfaces';
import ClusterNode from '../ClusterNode';

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

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

describe('clusterNode', () => {
let clusterNode: ClusterNode;
const api = new APIMock() as jest.Mocked<API>;
const clusterId = 'cluster-id';

beforeEach(() => {
jest.clearAllMocks();
clusterNode = new ClusterNode(api);
});

describe('list', () => {
it('should make a GET call to the ClusterNode base url', () => {
clusterNode.list(clusterId);

expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(ClusterNode.getBaseUrl(clusterId));
});
});

describe('listUpgrades', () => {
it('should make a GET call to the ClusterNode upgrades url', () => {
const nodeId = 'expected-node-id';
clusterNode.listUpgrades(clusterId, nodeId);

expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${ClusterNode.getBaseUrl(clusterId)}/${nodeId}/upgrades`);
});
});

describe('start', () => {
it('should make a POST call to the ClusterNode start url', () => {
const nodeId = 'expected-node-id';
clusterNode.start(clusterId, nodeId);

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(`${ClusterNode.getBaseUrl(clusterId)}/${nodeId}/start`, {});
});
});

describe('stop', () => {
it('should make a POST call to the ClusterNode stop url', () => {
const nodeId = 'expected-node-id';
clusterNode.stop(clusterId, nodeId);

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(`${ClusterNode.getBaseUrl(clusterId)}/${nodeId}/stop`, {});
});
});

describe('dumps', () => {
it('should make a POST call to the ClusterNode dumps url', () => {
const nodeId = 'expected-node-id';
clusterNode.dump(clusterId, nodeId);

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(`${ClusterNode.getBaseUrl(clusterId)}/${nodeId}/dumps`, {});
});
});

describe('upgrade', () => {
it('should make a PUT call to the upgrade cluster agent url', () => {
const nodeId = 'expected-node-id';
const data: ClusterNodeUpgradeDataModel = {componentName: 'butterfly', version: '1.2.3'};
clusterNode.upgrade(clusterId, nodeId, data);

expect(api.put).toHaveBeenCalledTimes(1);
expect(api.put).toHaveBeenCalledWith(`${ClusterNode.getBaseUrl(clusterId)}/${nodeId}/upgrades`, data);
});
});
});
2 changes: 2 additions & 0 deletions src/resources/Clusters/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './Cluster';
export * from './ClusterInterfaces';
export * from './Agents/';
export * from './Nodes/';

0 comments on commit d8a40cb

Please sign in to comment.