-
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.
feat(clusters): add cluster resource
- Loading branch information
1 parent
e3a7123
commit 44d7a7a
Showing
6 changed files
with
136 additions
and
0 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,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`, {}); | ||
} | ||
} |
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,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; | ||
} |
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 './Cluster'; | ||
export * from './ClusterInterfaces'; |
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,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`, {}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -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'; |