Skip to content

Commit b3f3de1

Browse files
author
Christoph Büscher
committed
Changing details section name in response
1 parent 0024968 commit b3f3de1

File tree

6 files changed

+42
-37
lines changed

6 files changed

+42
-37
lines changed

docs/reference/indices/apis/reload-analyzers.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ analyzers that were reloaded:
8282
"successful" : 2,
8383
"failed" : 0
8484
},
85-
"reloaded_nodes" : [
85+
"reload_details" : [
8686
{
8787
"index" : "my_index",
8888
"reloaded_analyzers" : [

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/ReloadAnalyzersResponse.java

+28-23
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,39 @@
3030
*/
3131
public class ReloadAnalyzersResponse extends BroadcastResponse {
3232

33-
private final Map<String, IndexDetails> reloadedIndicesDetails;
33+
private final Map<String, ReloadDetails> reloadDetails;
34+
private final static ParseField RELOAD_DETAILS_FIELD = new ParseField("reload_details");
35+
private final static ParseField INDEX_FIELD = new ParseField("index");
36+
private final static ParseField RELOADED_ANALYZERS_FIELD = new ParseField("reloaded_analyzers");
37+
private final static ParseField RELOADED_NODE_IDS_FIELD = new ParseField("reloaded_node_ids");
38+
3439

3540
public ReloadAnalyzersResponse() {
36-
reloadedIndicesDetails = Collections.emptyMap();
41+
reloadDetails = Collections.emptyMap();
3742
}
3843

3944
public ReloadAnalyzersResponse(int totalShards, int successfulShards, int failedShards,
40-
List<DefaultShardOperationFailedException> shardFailures, Map<String, IndexDetails> reloadedIndicesNodes) {
45+
List<DefaultShardOperationFailedException> shardFailures, Map<String, ReloadDetails> reloadedIndicesNodes) {
4146
super(totalShards, successfulShards, failedShards, shardFailures);
42-
this.reloadedIndicesDetails = reloadedIndicesNodes;
47+
this.reloadDetails = reloadedIndicesNodes;
4348
}
4449

45-
public final Map<String, IndexDetails> getReloadedIndicesDetails() {
46-
return this.reloadedIndicesDetails;
50+
public final Map<String, ReloadDetails> getReloadDetails() {
51+
return this.reloadDetails;
4752
}
4853

4954
/**
5055
* Override in subclass to add custom fields following the common `_shards` field
5156
*/
5257
@Override
5358
protected void addCustomXContentFields(XContentBuilder builder, Params params) throws IOException {
54-
builder.startArray("reloaded_nodes");
55-
for (Entry<String, IndexDetails> indexDetails : reloadedIndicesDetails.entrySet()) {
59+
builder.startArray(RELOAD_DETAILS_FIELD.getPreferredName());
60+
for (Entry<String, ReloadDetails> indexDetails : reloadDetails.entrySet()) {
5661
builder.startObject();
57-
IndexDetails value = indexDetails.getValue();
58-
builder.field("index", value.getIndexName());
59-
builder.field("reloaded_analyzers", value.getReloadedAnalyzers());
60-
builder.field("reloaded_node_ids", value.getReloadedIndicesNodes());
62+
ReloadDetails value = indexDetails.getValue();
63+
builder.field(INDEX_FIELD.getPreferredName(), value.getIndexName());
64+
builder.field(RELOADED_ANALYZERS_FIELD.getPreferredName(), value.getReloadedAnalyzers());
65+
builder.field(RELOADED_NODE_IDS_FIELD.getPreferredName(), value.getReloadedIndicesNodes());
6166
builder.endObject();
6267
}
6368
builder.endArray();
@@ -67,40 +72,40 @@ protected void addCustomXContentFields(XContentBuilder builder, Params params) t
6772
private static final ConstructingObjectParser<ReloadAnalyzersResponse, Void> PARSER = new ConstructingObjectParser<>("reload_analyzer",
6873
true, arg -> {
6974
BroadcastResponse response = (BroadcastResponse) arg[0];
70-
List<IndexDetails> results = (List<IndexDetails>) arg[1];
71-
Map<String, IndexDetails> reloadedNodeIds = new HashMap<>();
72-
for (IndexDetails result : results) {
75+
List<ReloadDetails> results = (List<ReloadDetails>) arg[1];
76+
Map<String, ReloadDetails> reloadedNodeIds = new HashMap<>();
77+
for (ReloadDetails result : results) {
7378
reloadedNodeIds.put(result.getIndexName(), result);
7479
}
7580
return new ReloadAnalyzersResponse(response.getTotalShards(), response.getSuccessfulShards(), response.getFailedShards(),
7681
Arrays.asList(response.getShardFailures()), reloadedNodeIds);
7782
});
7883

7984
@SuppressWarnings({ "unchecked" })
80-
private static final ConstructingObjectParser<IndexDetails, Void> ENTRY_PARSER = new ConstructingObjectParser<>(
85+
private static final ConstructingObjectParser<ReloadDetails, Void> ENTRY_PARSER = new ConstructingObjectParser<>(
8186
"reload_analyzer.entry", true, arg -> {
82-
return new IndexDetails((String) arg[0], new HashSet<>((List<String>) arg[1]), new HashSet<>((List<String>) arg[2]));
87+
return new ReloadDetails((String) arg[0], new HashSet<>((List<String>) arg[1]), new HashSet<>((List<String>) arg[2]));
8388
});
8489

8590
static {
8691
declareBroadcastFields(PARSER);
87-
PARSER.declareObjectArray(constructorArg(), ENTRY_PARSER, new ParseField("reloaded_nodes"));
88-
ENTRY_PARSER.declareString(constructorArg(), new ParseField("index"));
89-
ENTRY_PARSER.declareStringArray(constructorArg(), new ParseField("reloaded_analyzers"));
90-
ENTRY_PARSER.declareStringArray(constructorArg(), new ParseField("reloaded_node_ids"));
92+
PARSER.declareObjectArray(constructorArg(), ENTRY_PARSER, RELOAD_DETAILS_FIELD);
93+
ENTRY_PARSER.declareString(constructorArg(), INDEX_FIELD);
94+
ENTRY_PARSER.declareStringArray(constructorArg(), RELOADED_ANALYZERS_FIELD);
95+
ENTRY_PARSER.declareStringArray(constructorArg(), RELOADED_NODE_IDS_FIELD);
9196
}
9297

9398
public static ReloadAnalyzersResponse fromXContent(XContentParser parser) {
9499
return PARSER.apply(parser, null);
95100
}
96101

97-
public static class IndexDetails {
102+
public static class ReloadDetails {
98103

99104
private final String indexName;
100105
private final Set<String> reloadedIndicesNodes;
101106
private final Set<String> reloadedAnalyzers;
102107

103-
IndexDetails(String name, Set<String> reloadedIndicesNodes, Set<String> reloadedAnalyzers) {
108+
ReloadDetails(String name, Set<String> reloadedIndicesNodes, Set<String> reloadedAnalyzers) {
104109
this.indexName = name;
105110
this.reloadedIndicesNodes = reloadedIndicesNodes;
106111
this.reloadedAnalyzers = reloadedAnalyzers;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/TransportReloadAnalyzersAction.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.elasticsearch.indices.IndicesService;
3030
import org.elasticsearch.threadpool.ThreadPool;
3131
import org.elasticsearch.transport.TransportService;
32-
import org.elasticsearch.xpack.core.action.ReloadAnalyzersResponse.IndexDetails;
32+
import org.elasticsearch.xpack.core.action.ReloadAnalyzersResponse.ReloadDetails;
3333
import org.elasticsearch.xpack.core.action.TransportReloadAnalyzersAction.ReloadResult;
3434

3535
import java.io.IOException;
@@ -68,14 +68,14 @@ protected ReloadResult readShardResult(StreamInput in) throws IOException {
6868
@Override
6969
protected ReloadAnalyzersResponse newResponse(ReloadAnalyzersRequest request, int totalShards, int successfulShards, int failedShards,
7070
List<ReloadResult> responses, List<DefaultShardOperationFailedException> shardFailures, ClusterState clusterState) {
71-
Map<String, IndexDetails> reloadedIndicesDetails = new HashMap<String, IndexDetails>();
71+
Map<String, ReloadDetails> reloadedIndicesDetails = new HashMap<String, ReloadDetails>();
7272
for (ReloadResult result : responses) {
7373
if (reloadedIndicesDetails.containsKey(result.index)) {
7474
reloadedIndicesDetails.get(result.index).merge(result);;
7575
} else {
7676
HashSet<String> nodeIds = new HashSet<String>();
7777
nodeIds.add(result.nodeId);
78-
IndexDetails details = new IndexDetails(result.index, nodeIds, new HashSet<String>(result.reloadedSearchAnalyzers));
78+
ReloadDetails details = new ReloadDetails(result.index, nodeIds, new HashSet<String>(result.reloadedSearchAnalyzers));
7979
reloadedIndicesDetails.put(result.index, details);
8080
}
8181
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/action/ReloadAnalyzersResponseTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.elasticsearch.common.Strings;
1010
import org.elasticsearch.common.xcontent.XContentParser;
1111
import org.elasticsearch.test.AbstractBroadcastResponseTestCase;
12-
import org.elasticsearch.xpack.core.action.ReloadAnalyzersResponse.IndexDetails;
12+
import org.elasticsearch.xpack.core.action.ReloadAnalyzersResponse.ReloadDetails;
1313

1414
import java.io.IOException;
1515
import java.util.Arrays;
@@ -25,13 +25,13 @@ public class ReloadAnalyzersResponseTests extends AbstractBroadcastResponseTestC
2525
@Override
2626
protected ReloadAnalyzersResponse createTestInstance(int totalShards, int successfulShards, int failedShards,
2727
List<DefaultShardOperationFailedException> failures) {
28-
Map<String, IndexDetails> reloadedIndicesDetails = new HashMap<>();
28+
Map<String, ReloadDetails> reloadedIndicesDetails = new HashMap<>();
2929
int randomIndices = randomIntBetween(0, 5);
3030
for (int i = 0; i < randomIndices; i++) {
3131
String name = randomAlphaOfLengthBetween(5, 10);
3232
Set<String> reloadedIndicesNodes = new HashSet<>(Arrays.asList(generateRandomStringArray(5, 5, false, true)));
3333
Set<String> reloadedAnalyzers = new HashSet<>(Arrays.asList(generateRandomStringArray(5, 5, false, true)));
34-
reloadedIndicesDetails.put(name, new IndexDetails(name, reloadedIndicesNodes, reloadedAnalyzers));
34+
reloadedIndicesDetails.put(name, new ReloadDetails(name, reloadedIndicesNodes, reloadedAnalyzers));
3535
}
3636
return new ReloadAnalyzersResponse(totalShards, successfulShards, failedShards, failures, reloadedIndicesDetails);
3737
}
@@ -43,13 +43,13 @@ protected ReloadAnalyzersResponse doParseInstance(XContentParser parser) throws
4343

4444
@Override
4545
public void testToXContent() {
46-
Map<String, IndexDetails> reloadedIndicesNodes = Collections.singletonMap("index",
47-
new IndexDetails("index", Collections.singleton("nodeId"), Collections.singleton("my_analyzer")));
46+
Map<String, ReloadDetails> reloadedIndicesNodes = Collections.singletonMap("index",
47+
new ReloadDetails("index", Collections.singleton("nodeId"), Collections.singleton("my_analyzer")));
4848
ReloadAnalyzersResponse response = new ReloadAnalyzersResponse(10, 5, 5, null, reloadedIndicesNodes);
4949
String output = Strings.toString(response);
5050
assertEquals(
5151
"{\"_shards\":{\"total\":10,\"successful\":5,\"failed\":5},"
52-
+ "\"reloaded_nodes\":[{\"index\":\"index\",\"reloaded_analyzers\":[\"my_analyzer\"],\"reloaded_node_ids\":[\"nodeId\"]}]"
52+
+ "\"reload_details\":[{\"index\":\"index\",\"reloaded_analyzers\":[\"my_analyzer\"],\"reloaded_node_ids\":[\"nodeId\"]}]"
5353
+ "}",
5454
output);
5555
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/action/ReloadSynonymAnalyzerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void testSynonymsUpdateable() throws FileNotFoundException, IOException {
8787
ReloadAnalyzersResponse reloadResponse = client().execute(ReloadAnalyzerAction.INSTANCE, new ReloadAnalyzersRequest(indexName))
8888
.actionGet();
8989
assertNoFailures(reloadResponse);
90-
Set<String> reloadedAnalyzers = reloadResponse.getReloadedIndicesDetails().get(indexName).getReloadedAnalyzers();
90+
Set<String> reloadedAnalyzers = reloadResponse.getReloadDetails().get(indexName).getReloadedAnalyzers();
9191
assertEquals(1, reloadedAnalyzers.size());
9292
assertTrue(reloadedAnalyzers.contains(analyzerName));
9393

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rest/action/ReloadSynonymAnalyzerIT.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ public void testSynonymsUpdateable() throws FileNotFoundException, IOException,
103103
.actionGet();
104104
assertNoFailures(reloadResponse);
105105
assertEquals(cluster().numDataNodes(), reloadResponse.getSuccessfulShards());
106-
assertTrue(reloadResponse.getReloadedIndicesDetails().containsKey("test"));
107-
assertEquals("test", reloadResponse.getReloadedIndicesDetails().get("test").getIndexName());
106+
assertTrue(reloadResponse.getReloadDetails().containsKey("test"));
107+
assertEquals("test", reloadResponse.getReloadDetails().get("test").getIndexName());
108108
assertEquals(Collections.singleton("my_synonym_analyzer"),
109-
reloadResponse.getReloadedIndicesDetails().get("test").getReloadedAnalyzers());
109+
reloadResponse.getReloadDetails().get("test").getReloadedAnalyzers());
110110

111111
analyzeResponse = client().admin().indices().prepareAnalyze("test", "foo").setAnalyzer("my_synonym_analyzer").get();
112112
assertEquals(3, analyzeResponse.getTokens().size());

0 commit comments

Comments
 (0)