render non-ElasticsearchException in ILM (#31284)

ILM was rendering exceptions using the exception helper that
basically ignores simply rendering non-elasticsearch exceptions when
no details are desired. This commit updates the method used to still be
a rather simple rendering of the exception. The rendering lacks
all the causes, but does a sufficient job in rendering the top-level
message for one of our most expected exceptions... IllegalArgumentException
This commit is contained in:
Tal Levy 2018-06-15 11:39:19 -07:00 committed by GitHub
parent 01939794fe
commit aa6944a719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View File

@ -196,7 +196,7 @@ public class IndexLifecycleRunner {
IndexMetaData idxMeta = clusterState.getMetaData().index(index);
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
causeXContentBuilder.startObject();
ElasticsearchException.generateFailureXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause, false);
ElasticsearchException.generateThrowableXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause);
causeXContentBuilder.endObject();
Settings.Builder indexSettings = moveIndexSettingsToNextStep(idxMeta.getSettings(), currentStep,
new StepKey(currentStep.getPhase(), currentStep.getAction(), ErrorStep.NAME), nowSupplier)

View File

@ -693,8 +693,15 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
.put(LifecycleSettings.LIFECYCLE_ACTION, currentStep.getAction())
.put(LifecycleSettings.LIFECYCLE_STEP, currentStep.getName()));
Index index = clusterState.metaData().index(indexName).getIndex();
ClusterState newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> now);
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, cause, now);
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, now,
"{\"type\":\"exception\",\"reason\":\"THIS IS AN EXPECTED CAUSE\"}");
cause = new IllegalArgumentException("non elasticsearch-exception");
newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> now);
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, now,
"{\"type\":\"illegal_argument_exception\",\"reason\":\"non elasticsearch-exception\"}");
}
public void testMoveClusterStateToFailedStep() {
@ -966,13 +973,8 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
assertEquals("", LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(newIndexSettings));
}
private void assertClusterStateOnErrorStep(ClusterState oldClusterState, Index index, StepKey currentStep, ClusterState newClusterState,
Exception cause, long now) throws IOException {
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
causeXContentBuilder.startObject();
ElasticsearchException.generateFailureXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause, false);
causeXContentBuilder.endObject();
String expectedCauseValue = BytesReference.bytes(causeXContentBuilder).utf8ToString();
private void assertClusterStateOnErrorStep(ClusterState oldClusterState, Index index, StepKey currentStep,
ClusterState newClusterState, long now, String expectedCauseValue) throws IOException {
assertNotSame(oldClusterState, newClusterState);
MetaData newMetadata = newClusterState.metaData();
assertNotSame(oldClusterState.metaData(), newMetadata);

View File

@ -68,7 +68,7 @@ public class MoveToErrorStepUpdateTaskTests extends ESTestCase {
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
causeXContentBuilder.startObject();
ElasticsearchException.generateFailureXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause, false);
ElasticsearchException.generateThrowableXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause);
causeXContentBuilder.endObject();
String expectedCauseValue = BytesReference.bytes(causeXContentBuilder).utf8ToString();
assertThat(LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(newState.metaData().index(index).getSettings()),