From fb959d188c74ae42614131457a8e13886613389e Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 8 Aug 2019 08:15:09 +0200 Subject: [PATCH] Backport: Add description to force-merge tasks (#41365) (#45191) * Add description to force-merge tasks (#41365) This is static information that is part of the force merge request. Relates to #15975 --- .../elasticsearch/client/IndicesClientIT.java | 4 ++ .../indices/forcemerge/ForceMergeRequest.java | 9 +++++ .../forcemerge/ForceMergeRequestTests.java | 38 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 17b3121cd0b62..c880c859dccdc 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -1045,6 +1045,8 @@ public void testForceMerge() throws IOException { assertThat(forceMergeResponse.getSuccessfulShards(), equalTo(1)); assertThat(forceMergeResponse.getFailedShards(), equalTo(0)); assertThat(forceMergeResponse.getShardFailures(), equalTo(BroadcastResponse.EMPTY)); + + assertThat(forceMergeRequest.getDescription(), containsString(index)); } { String nonExistentIndex = "non_existent_index"; @@ -1053,6 +1055,8 @@ public void testForceMerge() throws IOException { ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(forceMergeRequest, highLevelClient().indices()::forcemerge, highLevelClient().indices()::forcemergeAsync)); assertEquals(RestStatus.NOT_FOUND, exception.status()); + + assertThat(forceMergeRequest.getDescription(), containsString(nonExistentIndex)); } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequest.java index b7fa9094540a7..20480c45f10a5 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequest.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; +import java.util.Arrays; /** * A request to force merging the segments of one or more indices. In order to @@ -114,6 +115,14 @@ public ForceMergeRequest flush(boolean flush) { return this; } + @Override + public String getDescription() { + return "Force-merge indices " + Arrays.toString(indices()) + + ", maxSegments[" + maxNumSegments + + "], onlyExpungeDeletes[" + onlyExpungeDeletes + + "], flush[" + flush + "]"; + } + @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java new file mode 100644 index 0000000000000..1054f814105bb --- /dev/null +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java @@ -0,0 +1,38 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.action.admin.indices.forcemerge; + +import org.elasticsearch.test.ESTestCase; + +public class ForceMergeRequestTests extends ESTestCase { + + public void testDescription() { + ForceMergeRequest request = new ForceMergeRequest(); + assertEquals("Force-merge indices [], maxSegments[-1], onlyExpungeDeletes[false], flush[true]", request.getDescription()); + + request = new ForceMergeRequest("shop", "blog"); + assertEquals("Force-merge indices [shop, blog], maxSegments[-1], onlyExpungeDeletes[false], flush[true]", request.getDescription()); + + request = new ForceMergeRequest(); + request.maxNumSegments(12); + request.onlyExpungeDeletes(true); + request.flush(false); + assertEquals("Force-merge indices [], maxSegments[12], onlyExpungeDeletes[true], flush[false]", request.getDescription()); + } +}