-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from coveo/featured-cluster-agent-node
Featured cluster agent node
- Loading branch information
Showing
11 changed files
with
223 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './ClusterAgent'; | ||
export * from './ClusterAgentInterfaces'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './ClusterNode'; | ||
export * from './ClusterNodeInterfaces'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/'; |