diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/IndexLifecycleExplainResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/IndexLifecycleExplainResponse.java index f79639e244304..8bdc3b195acd0 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/IndexLifecycleExplainResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/IndexLifecycleExplainResponse.java @@ -124,15 +124,12 @@ private IndexLifecycleExplainResponse(String index, boolean managedByILM, String throw new IllegalArgumentException("[" + POLICY_NAME_FIELD.getPreferredName() + "] cannot be null for managed index"); } // check to make sure that step details are either all null or all set. - long numNull = Stream.of(phase, action, step, phaseTime, actionTime, stepTime).filter(Objects::isNull).count(); - if (numNull > 0 && numNull < 6) { + long numNull = Stream.of(phase, action, step).filter(Objects::isNull).count(); + if (numNull > 0 && numNull < 3) { throw new IllegalArgumentException("managed index response must have complete step details [" + PHASE_FIELD.getPreferredName() + "=" + phase + ", " + - PHASE_TIME_FIELD.getPreferredName() + "=" + phaseTime + ", " + ACTION_FIELD.getPreferredName() + "=" + action + ", " + - ACTION_TIME_FIELD.getPreferredName() + "=" + actionTime + ", " + - STEP_FIELD.getPreferredName() + "=" + step + ", " + - STEP_TIME_FIELD.getPreferredName() + "=" + stepTime + "]"); + STEP_FIELD.getPreferredName() + "=" + step + "]"); } } else { if (policyName != null || lifecycleDate != null || phase != null || action != null || step != null || failedStep != null diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/IndexLifecycleExplainResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/IndexLifecycleExplainResponseTests.java index 40d9f7e194a5f..29f7a8db89f57 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/IndexLifecycleExplainResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/IndexLifecycleExplainResponseTests.java @@ -69,7 +69,7 @@ private static IndexLifecycleExplainResponse randomManagedIndexExplainResponse() } public void testInvalidStepDetails() { - final int numNull = randomIntBetween(1, 6); + final int numNull = randomIntBetween(1, 3); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> IndexLifecycleExplainResponse.newManagedIndexResponse(randomAlphaOfLength(10), randomAlphaOfLength(10), @@ -78,9 +78,9 @@ public void testInvalidStepDetails() { (numNull == 2) ? null : randomAlphaOfLength(10), (numNull == 3) ? null : randomAlphaOfLength(10), randomBoolean() ? null : randomAlphaOfLength(10), - (numNull == 4) ? null : randomNonNegativeLong(), - (numNull == 5) ? null : randomNonNegativeLong(), - (numNull == 6) ? null : randomNonNegativeLong(), + randomBoolean() ? null : randomNonNegativeLong(), + randomBoolean() ? null : randomNonNegativeLong(), + randomBoolean() ? null : randomNonNegativeLong(), randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()), randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo(""))); assertThat(exception.getMessage(), startsWith("managed index response must have complete step details")); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleExplainResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleExplainResponse.java index 7880703d8baa5..fd171c88539c3 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleExplainResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleExplainResponse.java @@ -113,15 +113,12 @@ private IndexLifecycleExplainResponse(String index, boolean managedByILM, String throw new IllegalArgumentException("[" + POLICY_NAME_FIELD.getPreferredName() + "] cannot be null for managed index"); } // check to make sure that step details are either all null or all set. - long numNull = Stream.of(phase, action, step, phaseTime, actionTime, stepTime).filter(Objects::isNull).count(); - if (numNull > 0 && numNull < 6) { + long numNull = Stream.of(phase, action, step).filter(Objects::isNull).count(); + if (numNull > 0 && numNull < 3) { throw new IllegalArgumentException("managed index response must have complete step details [" + PHASE_FIELD.getPreferredName() + "=" + phase + ", " + - PHASE_TIME_FIELD.getPreferredName() + "=" + phaseTime + ", " + ACTION_FIELD.getPreferredName() + "=" + action + ", " + - ACTION_TIME_FIELD.getPreferredName() + "=" + actionTime + ", " + - STEP_FIELD.getPreferredName() + "=" + step + ", " + - STEP_TIME_FIELD.getPreferredName() + "=" + stepTime + "]"); + STEP_FIELD.getPreferredName() + "=" + step + "]"); } } else { if (policyName != null || lifecycleDate != null || phase != null || action != null || step != null || failedStep != null diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleExplainResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleExplainResponseTests.java index 6381dd1ae4177..4b483dcf03945 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleExplainResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleExplainResponseTests.java @@ -60,7 +60,7 @@ private static IndexLifecycleExplainResponse randomManagedIndexExplainResponse() } public void testInvalidStepDetails() { - final int numNull = randomIntBetween(1, 6); + final int numNull = randomIntBetween(1, 3); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> IndexLifecycleExplainResponse.newManagedIndexResponse(randomAlphaOfLength(10), randomAlphaOfLength(10), @@ -69,9 +69,9 @@ public void testInvalidStepDetails() { (numNull == 2) ? null : randomAlphaOfLength(10), (numNull == 3) ? null : randomAlphaOfLength(10), randomBoolean() ? null : randomAlphaOfLength(10), - (numNull == 4) ? null : randomNonNegativeLong(), - (numNull == 5) ? null : randomNonNegativeLong(), - (numNull == 6) ? null : randomNonNegativeLong(), + randomBoolean() ? null : randomNonNegativeLong(), + randomBoolean() ? null : randomNonNegativeLong(), + randomBoolean() ? null : randomNonNegativeLong(), randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()), randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo(""))); assertThat(exception.getMessage(), startsWith("managed index response must have complete step details")); @@ -109,7 +109,7 @@ protected IndexLifecycleExplainResponse mutateInstance(IndexLifecycleExplainResp BytesReference stepInfo = instance.getStepInfo(); PhaseExecutionInfo phaseExecutionInfo = instance.getPhaseExecutionInfo(); if (managed) { - switch (between(0, 7)) { + switch (between(0, 10)) { case 0: index = index + randomAlphaOfLengthBetween(1, 5); break; @@ -120,11 +120,17 @@ protected IndexLifecycleExplainResponse mutateInstance(IndexLifecycleExplainResp phase = randomAlphaOfLengthBetween(1, 5); action = randomAlphaOfLengthBetween(1, 5); step = randomAlphaOfLengthBetween(1, 5); + break; + case 3: phaseTime = randomValueOtherThan(phaseTime, () -> randomLongBetween(0, 100000)); + break; + case 4: actionTime = randomValueOtherThan(actionTime, () -> randomLongBetween(0, 100000)); + break; + case 5: stepTime = randomValueOtherThan(stepTime, () -> randomLongBetween(0, 100000)); break; - case 3: + case 6: if (Strings.hasLength(failedStep) == false) { failedStep = randomAlphaOfLength(10); } else if (randomBoolean()) { @@ -133,10 +139,10 @@ protected IndexLifecycleExplainResponse mutateInstance(IndexLifecycleExplainResp failedStep = null; } break; - case 4: + case 7: policyTime = randomValueOtherThan(policyTime, () -> randomLongBetween(0, 100000)); break; - case 5: + case 8: if (Strings.hasLength(stepInfo) == false) { stepInfo = new BytesArray(randomByteArrayOfLength(100)); } else if (randomBoolean()) { @@ -146,10 +152,10 @@ protected IndexLifecycleExplainResponse mutateInstance(IndexLifecycleExplainResp stepInfo = null; } break; - case 6: + case 9: phaseExecutionInfo = randomValueOtherThan(phaseExecutionInfo, () -> PhaseExecutionInfoTests.randomPhaseExecutionInfo("")); break; - case 7: + case 10: return IndexLifecycleExplainResponse.newUnmanagedIndexResponse(index); default: throw new AssertionError("Illegal randomisation branch");