[ILM] Fix frozen phase min_age (de)serialization (#96544)

This commit is contained in:
Sébastien Loix 2021-04-08 16:41:27 +01:00 committed by GitHub
parent 0d62e11736
commit c9d19fd43b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 92 additions and 14 deletions

View file

@ -481,21 +481,84 @@ describe('<EditPolicy /> serialization', () => {
});
});
test('delete phase', async () => {
const { actions } = testBed;
await actions.delete.enable(true);
await actions.setWaitForSnapshotPolicy('test');
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const entirePolicy = JSON.parse(JSON.parse(latestRequest.requestBody).body);
expect(entirePolicy.phases.delete).toEqual({
min_age: '365d',
actions: {
delete: {},
wait_for_snapshot: {
policy: 'test',
describe('frozen phase', () => {
test('default value', async () => {
const { actions } = testBed;
await actions.frozen.enable(true);
await actions.frozen.setSearchableSnapshot('myRepo');
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const entirePolicy = JSON.parse(JSON.parse(latestRequest.requestBody).body);
expect(entirePolicy.phases.frozen).toEqual({
min_age: '0d',
actions: {
searchable_snapshot: { snapshot_repository: 'myRepo' },
},
},
});
});
describe('deserialization', () => {
beforeEach(async () => {
const policyToEdit = getDefaultHotPhasePolicy('my_policy');
policyToEdit.policy.phases.frozen = {
min_age: '1234m',
actions: { searchable_snapshot: { snapshot_repository: 'myRepo' } },
};
httpRequestsMockHelpers.setLoadPolicies([policyToEdit]);
httpRequestsMockHelpers.setLoadSnapshotPolicies([]);
httpRequestsMockHelpers.setListNodes({
nodesByRoles: {},
nodesByAttributes: { test: ['123'] },
isUsingDeprecatedDataRoleConfig: false,
});
await act(async () => {
testBed = await setup();
});
const { component } = testBed;
component.update();
});
test('default value', async () => {
const { actions } = testBed;
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const entirePolicy = JSON.parse(JSON.parse(latestRequest.requestBody).body);
expect(entirePolicy.phases.frozen).toEqual({
min_age: '1234m',
actions: {
searchable_snapshot: {
snapshot_repository: 'myRepo',
},
},
});
});
});
});
describe('delete phase', () => {
test('default value', async () => {
const { actions } = testBed;
await actions.delete.enable(true);
await actions.setWaitForSnapshotPolicy('test');
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const entirePolicy = JSON.parse(JSON.parse(latestRequest.requestBody).body);
expect(entirePolicy.phases.delete).toEqual({
min_age: '365d',
actions: {
delete: {},
wait_for_snapshot: {
policy: 'test',
},
},
});
});
});
});

View file

@ -114,6 +114,14 @@ export const createDeserializer = (isCloudEnabled: boolean) => (
}
}
if (draft.phases.frozen) {
if (draft.phases.frozen.min_age) {
const minAge = splitSizeAndUnits(draft.phases.frozen.min_age);
draft.phases.frozen.min_age = minAge.size;
draft._meta.frozen.minAgeUnit = minAge.units;
}
}
if (draft.phases.delete) {
if (draft.phases.delete.min_age) {
const minAge = splitSizeAndUnits(draft.phases.delete.min_age);

View file

@ -267,6 +267,13 @@ export const createSerializer = (originalPolicy?: SerializedPolicy) => (
draft.phases.frozen!.actions = draft.phases.frozen?.actions ?? {};
const frozenPhase = draft.phases.frozen!;
/**
* FROZEN PHASE MIN AGE
*/
if (updatedPolicy.phases.frozen?.min_age) {
frozenPhase.min_age = `${updatedPolicy.phases.frozen!.min_age}${_meta.frozen.minAgeUnit}`;
}
/**
* FROZEN PHASE SEARCHABLE SNAPSHOT
*/