Skip to content

Commit

Permalink
fix for correctly detecting policy data tier type
Browse files Browse the repository at this point in the history
- with jest tests see origin here:
#81642
  • Loading branch information
jloleysens committed Oct 26, 2020
1 parent 750992e commit b85f492
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,58 @@ export const DELETE_PHASE_POLICY: PolicyFromES = {
},
name: POLICY_NAME,
};

export const POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
policy: {
phases: {
hot: {
min_age: '0ms',
actions: {
rollover: {
max_size: '50gb',
},
},
},
warm: {
actions: {
allocate: {
require: {},
include: { test: '123' },
exclude: {},
},
},
},
cold: {
actions: {
migrate: { enabled: false },
},
},
},
name: POLICY_NAME,
},
name: POLICY_NAME,
};

export const POLICY_WITH_NODE_ROLE_ALLOCATION: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
policy: {
phases: {
hot: {
min_age: '0ms',
actions: {
rollover: {
max_size: '50gb',
},
},
},
warm: {
actions: {},
},
},
name: POLICY_NAME,
},
name: POLICY_NAME,
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
SNAPSHOT_POLICY_NAME,
DEFAULT_POLICY,
POLICY_WITH_INCLUDE_EXCLUDE,
POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION,
POLICY_WITH_NODE_ROLE_ALLOCATION,
} from './constants';

window.scrollTo = jest.fn();
Expand Down Expand Up @@ -381,4 +383,57 @@ describe('<EditPolicy />', () => {
expect(testBed.find('policiesErrorCallout').exists()).toBeTruthy();
});
});

describe('data allocation', () => {
describe('node roles', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([POLICY_WITH_NODE_ROLE_ALLOCATION]);
httpRequestsMockHelpers.setListNodes({
isUsingDeprecatedDataRoleConfig: false,
nodesByAttributes: { test: ['123'] },
nodesByRoles: { data: ['123'] },
});

await act(async () => {
testBed = await setup();
});

const { component } = testBed;
component.update();
});
test('showing "default" type', () => {
const { find } = testBed;
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).toContain(
'recommended'
);
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).not.toContain(
'Custom'
);
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).not.toContain('Off');
});
});
describe('node attr and none', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION]);
httpRequestsMockHelpers.setListNodes({
isUsingDeprecatedDataRoleConfig: false,
nodesByAttributes: { test: ['123'] },
nodesByRoles: { data: ['123'] },
});

await act(async () => {
testBed = await setup();
});

const { component } = testBed;
component.update();
});

test('showing "custom" and "off" types', () => {
const { find } = testBed;
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).toContain('Custom');
expect(find('cold-dataTierAllocationControls.dataTierSelect').text()).toContain('Off');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const deserializer = (policy: SerializedPolicy): FormInternal => {
warmPhaseOnRollover: Boolean(policy.phases.warm?.min_age === '0ms'),
forceMergeEnabled: Boolean(policy.phases.warm?.actions?.forcemerge),
bestCompression: policy.phases.warm?.actions?.forcemerge?.index_codec === 'best_compression',
dataTierAllocationType: determineDataTierAllocationType(policy.phases.warm?.actions.allocate),
dataTierAllocationType: determineDataTierAllocationType(policy.phases.warm?.actions),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const coldPhaseFromES = (phaseSerialized?: SerializedColdPhase): ColdPhas

phase.phaseEnabled = true;

if (phaseSerialized.actions.allocate) {
if (phaseSerialized.actions) {
phase.dataTierAllocationType = determineDataTierAllocationTypeLegacy(phaseSerialized.actions);
}

Expand Down

0 comments on commit b85f492

Please sign in to comment.