Skip to content

render non-ElasticsearchException in ILM #31284

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

Merged
merged 9 commits into from
Jun 15, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static ClusterState moveClusterStateToErrorStep(Index index, ClusterState cluste
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,15 @@ public void testMoveClusterStateToErrorStep() throws IOException {
.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() {
Expand Down Expand Up @@ -950,13 +957,8 @@ public static void assertClusterStateOnNextStep(ClusterState oldClusterState, In
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testExecuteSuccessfullyMoved() throws IOException {

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()),
Expand Down