-
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 #29 from coveo/add-index-resource
Add index resource
- Loading branch information
Showing
6 changed files
with
330 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,64 @@ | ||
import API from '../../APICore'; | ||
import {PageModel} from '../BaseInterfaces'; | ||
import Resource from '../Resource'; | ||
import { | ||
CreateCoveoIndexModel, | ||
IndexAttributes, | ||
IndexBackupsItems, | ||
IndexBackupsOptions, | ||
IndexStatisticsModel, | ||
} from './IndexesInterface'; | ||
|
||
export default class Indexes extends Resource { | ||
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/indexes`; | ||
static indexBackupUrl = `/rest/organizations/${API.orgPlaceholder}/indexbackups/page`; | ||
|
||
list() { | ||
return this.api.get<IndexAttributes[]>(Indexes.baseUrl); | ||
} | ||
|
||
// Same for Copy Index but making sure to pass copyFromId and machineSpec | ||
create(indexModal?: CreateCoveoIndexModel) { | ||
return this.api.post<{id: string}>(Indexes.baseUrl, indexModal); | ||
} | ||
|
||
delete(indexId: string) { | ||
return this.api.delete(`${Indexes.baseUrl}/${indexId}`); | ||
} | ||
|
||
get(indexId: string) { | ||
return this.api.get<IndexAttributes>(`${Indexes.baseUrl}/${indexId}`); | ||
} | ||
|
||
backup(indexId: string) { | ||
return this.api.post<{id: string}>(`${Indexes.baseUrl}/${indexId}/backup`, {}); | ||
} | ||
|
||
getBackups(options?: IndexBackupsOptions) { | ||
return this.api.get<PageModel<IndexBackupsItems>>(this.buildPath(`${Indexes.indexBackupUrl}`, options)); | ||
} | ||
|
||
forceCommit(indexId: string) { | ||
return this.api.post(`${Indexes.baseUrl}/${indexId}/commit`, {}); | ||
} | ||
|
||
readOnly(indexId: string, isReadOnly: boolean) { | ||
return this.api.put(this.buildPath(`${Indexes.baseUrl}/${indexId}/readonly`, {isReadOnly}), {}); | ||
} | ||
|
||
resize(indexId: string, sizeInGibibytes: number) { | ||
return this.api.post(`${Indexes.baseUrl}/${indexId}/resize`, {sizeInGibibytes}); | ||
} | ||
|
||
stats(indexId: string) { | ||
return this.api.get<IndexStatisticsModel>(`${Indexes.baseUrl}/${indexId}/stats`); | ||
} | ||
|
||
isOnline(indexId: string, isOnline: boolean) { | ||
return this.api.put(this.buildPath(`${Indexes.baseUrl}/${indexId}/online`, {isOnline}), {}); | ||
} | ||
|
||
restore(indexId: string, backupId: string) { | ||
return this.api.post(this.buildPath(`${Indexes.baseUrl}/${indexId}/restore`, {backupId}), {}); | ||
} | ||
} |
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,103 @@ | ||
export interface IndexStorageSpec { | ||
numberOfIops: number; | ||
sizeInGibibytes: number; | ||
sizeInGigabytes: number; | ||
storageType: string; | ||
} | ||
|
||
export interface IndexMachineSpec { | ||
architecture: string; | ||
storageSpec: IndexStorageSpec; | ||
} | ||
|
||
export interface IndexSourceStatistics { | ||
collectionId: number; | ||
documentCount: number; | ||
documentTotalSize: number; | ||
sourceId: number; | ||
} | ||
|
||
export interface IndexStatisticsModel { | ||
diskSpaceUsed: number; | ||
documentCount: number; | ||
documentsTotalSize: number; | ||
lastAppliedTransactionTimestamp: number; | ||
lastCommitTimestamp: number; | ||
numberOfQueries: number; | ||
numberOfSlices: number; | ||
pendingTransactions: number; | ||
realtimeDiskSpaceUsed: number; | ||
realtimeDocumentCount: number; | ||
realtimeDocumentsTotalSize: number; | ||
realtimePendingTransactions: number; | ||
remainingDiskSpace: number; | ||
sourceStatistics: IndexSourceStatistics[]; | ||
totalMemoryUsed: number; | ||
totalPhysicalMemory: number; | ||
} | ||
|
||
export interface IndexStatus { | ||
internalStatus: string; | ||
online: boolean; | ||
readOnlyStatus: string; | ||
stats: IndexStatisticsModel; | ||
} | ||
|
||
export interface IndexAttributes { | ||
adminUri: string; | ||
agentId: string; | ||
id: string; | ||
logicalIndex: string; | ||
machineSpec: IndexMachineSpec; | ||
name: string; | ||
organizationId: string; | ||
region: string; | ||
searchUri: string; | ||
status: IndexStatus; | ||
storages: IndexStorageSpec[]; | ||
type: string; | ||
} | ||
|
||
export interface CreateCoveoIndexModel { | ||
copyFromId?: string; | ||
logicalIndexId?: string; | ||
machineSpec?: MachineSpecModel; | ||
online?: boolean; | ||
region?: string; | ||
versions?: IndexVersionsModel; | ||
} | ||
|
||
export interface MachineSpecModel { | ||
architecture: string; | ||
storageSpec: IndexStorageSpecModel; | ||
} | ||
|
||
export interface IndexStorageSpecModel { | ||
numberOfIops: number; | ||
sizeInGibibytes: number; | ||
storageType: string; | ||
} | ||
|
||
export interface IndexVersionsModel { | ||
indexerVersion: string; | ||
securityCacheVersion: string; | ||
} | ||
|
||
export interface IndexBackupsItems { | ||
backupId: string; | ||
creationDate: number; | ||
indexId: string; | ||
logicalIndex: string; | ||
organizationId: string; | ||
} | ||
|
||
export interface IndexBackupsOptions { | ||
backupId?: string; | ||
from?: number; | ||
indexId?: string; | ||
order?: string; | ||
page?: number; | ||
perPage?: number; | ||
sortBy?: string; | ||
to?: number; | ||
} |
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 './Indexes'; | ||
export * from './IndexesInterface'; |
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,157 @@ | ||
import API from '../../../APICore'; | ||
import Indexes from '../Indexes'; | ||
import {CreateCoveoIndexModel} from '../IndexesInterface'; | ||
|
||
jest.mock('../../../APICore'); | ||
|
||
const APIMock: jest.Mock<API> = API as any; | ||
|
||
describe('Cluster', () => { | ||
let indexes: Indexes; | ||
const api = new APIMock() as jest.Mocked<API>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
indexes = new Indexes(api); | ||
}); | ||
|
||
describe('list', () => { | ||
it('should make a GET call to the Cluster base url', () => { | ||
indexes.list(); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(Indexes.baseUrl); | ||
}); | ||
}); | ||
|
||
describe('get', () => { | ||
it('should make a GET call for specific index', () => { | ||
const indexId = 'ABC123'; | ||
indexes.get(indexId); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Indexes.baseUrl}/${indexId}`); | ||
}); | ||
}); | ||
|
||
describe('delete', () => { | ||
it('should make a DELETE call for specific index', () => { | ||
const indexId = 'ABC123'; | ||
indexes.delete(indexId); | ||
expect(api.delete).toHaveBeenCalledTimes(1); | ||
expect(api.delete).toHaveBeenCalledWith(`${Indexes.baseUrl}/${indexId}`); | ||
}); | ||
}); | ||
|
||
describe('create', () => { | ||
it('should make a CREATE call with no arguments', () => { | ||
indexes.create({}); | ||
expect(api.post).toHaveBeenCalledTimes(1); | ||
expect(api.post).toHaveBeenCalledWith(Indexes.baseUrl, {}); | ||
}); | ||
|
||
it('should make a CREATE call to mimick COPY_INDEX', () => { | ||
const indexToBeCopied: CreateCoveoIndexModel = { | ||
copyFromId: 'originalIndexID', | ||
machineSpec: { | ||
architecture: 'T3_MEDIUM_UNLIMITED', | ||
storageSpec: { | ||
numberOfIops: 0, | ||
sizeInGibibytes: 45, | ||
storageType: 'STANDARD', | ||
}, | ||
}, | ||
}; | ||
|
||
indexes.create(indexToBeCopied); | ||
expect(api.post).toHaveBeenCalledTimes(1); | ||
expect(api.post).toHaveBeenCalledWith(Indexes.baseUrl, indexToBeCopied); | ||
}); | ||
}); | ||
|
||
describe('backup', () => { | ||
it('should make a BACKUP call for specified index', () => { | ||
const indexId = 'ABC123'; | ||
indexes.backup(indexId); | ||
expect(api.post).toHaveBeenCalledTimes(1); | ||
expect(api.post).toHaveBeenCalledWith(`${Indexes.baseUrl}/${indexId}/backup`, {}); | ||
}); | ||
}); | ||
|
||
describe('get all backups', () => { | ||
it('should make a GETBACKUPS call', () => { | ||
const options = { | ||
backupId: 'backupId', | ||
from: 0, | ||
indexId: 'indexId', | ||
order: 'asc', | ||
page: 100, | ||
perPage: 10, | ||
sortBy: 'name', | ||
to: 20, | ||
}; | ||
|
||
indexes.getBackups(options); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith( | ||
`${Indexes.indexBackupUrl}?backupId=backupId&from=0&indexId=indexId&order=asc&page=100&perPage=10&sortBy=name&to=20` | ||
); | ||
}); | ||
}); | ||
|
||
describe('forceCommit', () => { | ||
it('should make a FORCECOMMIT call for specified index', () => { | ||
const indexId = 'ABC123'; | ||
indexes.forceCommit(indexId); | ||
expect(api.post).toHaveBeenCalledTimes(1); | ||
expect(api.post).toHaveBeenCalledWith(`${Indexes.baseUrl}/${indexId}/commit`, {}); | ||
}); | ||
}); | ||
|
||
describe('readOnly', () => { | ||
it('should make a READONLY call for specified index', () => { | ||
const isReadOnly = true; | ||
const indexId = 'ABC123'; | ||
indexes.readOnly(indexId, isReadOnly); | ||
expect(api.put).toHaveBeenCalledTimes(1); | ||
expect(api.put).toHaveBeenCalledWith(`${Indexes.baseUrl}/${indexId}/readonly?isReadOnly=true`, {}); | ||
}); | ||
}); | ||
|
||
describe('resize', () => { | ||
it('should make a RESIZE call for specified index', () => { | ||
const sizeInGibibytes = 100; | ||
const indexId = 'ABC123'; | ||
indexes.resize(indexId, sizeInGibibytes); | ||
expect(api.post).toHaveBeenCalledTimes(1); | ||
expect(api.post).toHaveBeenCalledWith(`${Indexes.baseUrl}/${indexId}/resize`, {sizeInGibibytes}); | ||
}); | ||
}); | ||
|
||
describe('stats', () => { | ||
it('should make a RESIZE call for specified index', () => { | ||
const indexId = 'ABC123'; | ||
indexes.stats(indexId); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Indexes.baseUrl}/${indexId}/stats`); | ||
}); | ||
}); | ||
|
||
describe('isOnline', () => { | ||
it('should make a ISONLINE call for specified index', () => { | ||
const isOnline = true; | ||
const indexId = 'ABC123'; | ||
indexes.isOnline(indexId, isOnline); | ||
expect(api.put).toHaveBeenCalledTimes(1); | ||
expect(api.put).toHaveBeenCalledWith(`${Indexes.baseUrl}/${indexId}/online?isOnline=true`, {}); | ||
}); | ||
}); | ||
|
||
describe('restore', () => { | ||
it('should make a RESTORE call for specified index', () => { | ||
const backupId = 'backUpID'; | ||
const indexId = 'ABC123'; | ||
indexes.restore(indexId, backupId); | ||
expect(api.post).toHaveBeenCalledTimes(1); | ||
expect(api.post).toHaveBeenCalledWith(`${Indexes.baseUrl}/${indexId}/restore?backupId=backUpID`, {}); | ||
}); | ||
}); | ||
}); |
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