fix clearing number of replicas from existing policy (#31905) (#31912)

This commit is contained in:
Bill McConaghy 2019-02-25 09:55:11 -05:00 committed by GitHub
parent a5d88c6381
commit c2958dc875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -123,6 +123,9 @@ export const splitSizeAndUnits = field => {
};
export const isNumber = value => typeof value === 'number';
export const isEmptyObject = (obj) => {
return Object.entries(obj).length === 0 && obj.constructor === Object;
};
export const phaseFromES = (phase, phaseName, defaultPolicy) => {
const policy = { ...defaultPolicy };
@ -259,15 +262,29 @@ export const phaseToES = (phase, originalEsPhase) => {
esPhase.actions.allocate.require = {
[name]: value
};
} else {
if (esPhase.actions.allocate) {
delete esPhase.actions.allocate.require;
}
}
if (isNumber(phase[PHASE_REPLICA_COUNT])) {
esPhase.actions.allocate = esPhase.actions.allocate || {};
esPhase.actions.allocate.number_of_replicas = phase[PHASE_REPLICA_COUNT];
} else {
if (esPhase.actions.allocate) {
delete esPhase.actions.allocate.require;
delete esPhase.actions.allocate.number_of_replicas;
}
}
if (esPhase.actions.allocate
&& !esPhase.actions.allocate.require
&& !esPhase.actions.allocate.number_of_replicas
&& isEmptyObject(esPhase.actions.allocate.include)
&& isEmptyObject(esPhase.actions.allocate.exclude)
) {
// remove allocate action if it does not define require or number of nodes
// and both include and exclude are empty objects (ES will fail to parse if we don't)
delete esPhase.actions.allocate;
}
if (phase[PHASE_FORCE_MERGE_ENABLED]) {
esPhase.actions.forcemerge = {