Skip to content

Commit fb959d1

Browse files
authored
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
1 parent fca458f commit fb959d1

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,8 @@ public void testForceMerge() throws IOException {
10451045
assertThat(forceMergeResponse.getSuccessfulShards(), equalTo(1));
10461046
assertThat(forceMergeResponse.getFailedShards(), equalTo(0));
10471047
assertThat(forceMergeResponse.getShardFailures(), equalTo(BroadcastResponse.EMPTY));
1048+
1049+
assertThat(forceMergeRequest.getDescription(), containsString(index));
10481050
}
10491051
{
10501052
String nonExistentIndex = "non_existent_index";
@@ -1053,6 +1055,8 @@ public void testForceMerge() throws IOException {
10531055
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
10541056
() -> execute(forceMergeRequest, highLevelClient().indices()::forcemerge, highLevelClient().indices()::forcemergeAsync));
10551057
assertEquals(RestStatus.NOT_FOUND, exception.status());
1058+
1059+
assertThat(forceMergeRequest.getDescription(), containsString(nonExistentIndex));
10561060
}
10571061
}
10581062

server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.common.io.stream.StreamOutput;
2525

2626
import java.io.IOException;
27+
import java.util.Arrays;
2728

2829
/**
2930
* A request to force merging the segments of one or more indices. In order to
@@ -114,6 +115,14 @@ public ForceMergeRequest flush(boolean flush) {
114115
return this;
115116
}
116117

118+
@Override
119+
public String getDescription() {
120+
return "Force-merge indices " + Arrays.toString(indices()) +
121+
", maxSegments[" + maxNumSegments +
122+
"], onlyExpungeDeletes[" + onlyExpungeDeletes +
123+
"], flush[" + flush + "]";
124+
}
125+
117126
@Override
118127
public void writeTo(StreamOutput out) throws IOException {
119128
super.writeTo(out);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.action.admin.indices.forcemerge;
20+
21+
import org.elasticsearch.test.ESTestCase;
22+
23+
public class ForceMergeRequestTests extends ESTestCase {
24+
25+
public void testDescription() {
26+
ForceMergeRequest request = new ForceMergeRequest();
27+
assertEquals("Force-merge indices [], maxSegments[-1], onlyExpungeDeletes[false], flush[true]", request.getDescription());
28+
29+
request = new ForceMergeRequest("shop", "blog");
30+
assertEquals("Force-merge indices [shop, blog], maxSegments[-1], onlyExpungeDeletes[false], flush[true]", request.getDescription());
31+
32+
request = new ForceMergeRequest();
33+
request.maxNumSegments(12);
34+
request.onlyExpungeDeletes(true);
35+
request.flush(false);
36+
assertEquals("Force-merge indices [], maxSegments[12], onlyExpungeDeletes[true], flush[false]", request.getDescription());
37+
}
38+
}

0 commit comments

Comments
 (0)