Skip to content

Commit

Permalink
fix ILM hot phase serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Jan 4, 2021
1 parent 9c092d5 commit 1af213c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ describe('deserializer and serializer', () => {
expect(result.phases.warm!.actions.readonly).toBeUndefined();
});

it('allows force merge and readonly actions to be configured in hot with default rollover enabled', () => {
formInternal._meta.hot.isUsingDefaultRollover = true;
formInternal._meta.hot.bestCompression = false;
formInternal.phases.hot!.actions.forcemerge = undefined;
formInternal._meta.hot.readonlyEnabled = false;

const result = serializer(formInternal);

expect(result.phases.hot!.actions.readonly).toBeUndefined();
expect(result.phases.hot!.actions.forcemerge).toBeUndefined();
});

it('removes set priority if it is disabled in the form', () => {
delete formInternal.phases.hot!.actions.set_priority;
delete formInternal.phases.warm!.actions.set_priority;
Expand Down Expand Up @@ -220,13 +232,14 @@ describe('deserializer and serializer', () => {
expect(result.phases.cold!.actions.allocate!.exclude).toBeUndefined();
});

it('removes forcemerge and rollover config when rollover is disabled in hot phase', () => {
it('removes forcemerge, readonly, and rollover config when rollover is disabled in hot phase', () => {
formInternal._meta.hot.useRollover = false;

const result = serializer(formInternal);

expect(result.phases.hot!.actions.rollover).toBeUndefined();
expect(result.phases.hot!.actions.forcemerge).toBeUndefined();
expect(result.phases.hot!.actions.readonly).toBeUndefined();
});

it('removes min_age from warm when rollover is enabled', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,26 @@ export const createSerializer = (originalPolicy?: SerializedPolicy) => (

if (draft.phases.hot?.actions) {
const hotPhaseActions = draft.phases.hot.actions;
if (_meta.hot.isUsingDefaultRollover) {
hotPhaseActions.rollover = cloneDeep(defaultRolloverAction);
} else if (hotPhaseActions.rollover && _meta.hot.useRollover) {
if (updatedPolicy.phases.hot!.actions.rollover?.max_age) {
hotPhaseActions.rollover.max_age = `${hotPhaseActions.rollover.max_age}${_meta.hot.maxAgeUnit}`;
} else {
delete hotPhaseActions.rollover.max_age;
}

if (typeof updatedPolicy.phases.hot!.actions.rollover?.max_docs !== 'number') {
delete hotPhaseActions.rollover.max_docs;
}

if (updatedPolicy.phases.hot!.actions.rollover?.max_size) {
hotPhaseActions.rollover.max_size = `${hotPhaseActions.rollover.max_size}${_meta.hot.maxStorageSizeUnit}`;
if (hotPhaseActions.rollover && _meta.hot.useRollover) {
if (_meta.hot.isUsingDefaultRollover) {
hotPhaseActions.rollover = cloneDeep(defaultRolloverAction);
} else {
delete hotPhaseActions.rollover.max_size;
if (updatedPolicy.phases.hot!.actions.rollover?.max_age) {
hotPhaseActions.rollover.max_age = `${hotPhaseActions.rollover.max_age}${_meta.hot.maxAgeUnit}`;
} else {
delete hotPhaseActions.rollover.max_age;
}

if (typeof updatedPolicy.phases.hot!.actions.rollover?.max_docs !== 'number') {
delete hotPhaseActions.rollover.max_docs;
}

if (updatedPolicy.phases.hot!.actions.rollover?.max_size) {
hotPhaseActions.rollover.max_size = `${hotPhaseActions.rollover.max_size}${_meta.hot.maxStorageSizeUnit}`;
} else {
delete hotPhaseActions.rollover.max_size;
}
}

if (!updatedPolicy.phases.hot!.actions?.forcemerge) {
Expand Down

0 comments on commit 1af213c

Please sign in to comment.