Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ILM] Fix misleading copy and fix serialization #81908

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,28 @@ export const POLICY_WITH_NODE_ROLE_ALLOCATION: PolicyFromES = {
},
name: POLICY_NAME,
};

export const POLICY_WITH_MIGRATE_OFF: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
policy: {
name: 'my_policy',
phases: {
hot: {
min_age: '0ms',
actions: {
rollover: {
max_age: '30d',
max_size: '50gb',
},
},
},
warm: {
actions: {
migrate: { enabled: false },
},
},
},
},
name: 'my_policy',
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
DELETE_PHASE_POLICY,
NEW_SNAPSHOT_POLICY_NAME,
SNAPSHOT_POLICY_NAME,
POLICY_WITH_MIGRATE_OFF,
POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION,
POLICY_WITH_NODE_ROLE_ALLOCATION,
} from './constants';
Expand Down Expand Up @@ -142,6 +143,40 @@ describe('<EditPolicy />', () => {
});

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

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

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

test('setting node_attr based allocation, but not selecting node attribute should leave allocation unchanged', async () => {
const { actions, find, component } = testBed;
act(() => {
find(`warm-dataTierAllocationControls.dataTierSelect`).simulate('click');
});
component.update();
await act(async () => {
find(`warm-dataTierAllocationControls.customDataAllocationOption`).simulate('click');
});
component.update();
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
const warmPhase = JSON.parse(JSON.parse(latestRequest.requestBody).body).phases.warm;

expect(warmPhase.actions.migrate).toEqual({ enabled: false });
});

describe('node roles', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([POLICY_WITH_NODE_ROLE_ALLOCATION]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const i18nTexts = {
'xpack.indexLifecycleMgmt.editPolicy.warm.nodeAttributesMissingDescription',
{
defaultMessage:
'Define custom node attributes in elasticsearch.yml to use attribute-based allocation. Warm nodes will be used instead.',
'Define custom node attributes in elasticsearch.yml to use attribute-based allocation.',
}
),
},
Expand All @@ -28,7 +28,7 @@ const i18nTexts = {
'xpack.indexLifecycleMgmt.editPolicy.cold.nodeAttributesMissingDescription',
{
defaultMessage:
'Define custom node attributes in elasticsearch.yml to use attribute-based allocation. Cold nodes will be used instead.',
'Define custom node attributes in elasticsearch.yml to use attribute-based allocation.',
}
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ export const serializePhaseWithAllocation = (
): SerializedPhase['actions'] => {
const esPhaseActions: SerializedPhase['actions'] = cloneDeep(originalPhaseActions);

if (phase.dataTierAllocationType === 'custom' && phase.selectedNodeAttrs) {
const [name, value] = phase.selectedNodeAttrs.split(':');
esPhaseActions.allocate = esPhaseActions.allocate || ({} as AllocateAction);
esPhaseActions.allocate.require = {
[name]: value,
};
if (phase.dataTierAllocationType === 'custom') {
if (phase.selectedNodeAttrs) {
const [name, value] = phase.selectedNodeAttrs.split(':');
esPhaseActions.allocate = esPhaseActions.allocate || ({} as AllocateAction);
esPhaseActions.allocate.require = {
[name]: value,
};
}
// else leave the policy configuration unchanged.
} else if (phase.dataTierAllocationType === 'none') {
esPhaseActions.migrate = { enabled: false };
if (esPhaseActions.allocate) {
Expand Down