8
8
import org .elasticsearch .action .support .DefaultShardOperationFailedException ;
9
9
import org .elasticsearch .action .support .broadcast .BroadcastResponse ;
10
10
import org .elasticsearch .common .ParseField ;
11
- import org .elasticsearch .common .collect .Tuple ;
12
11
import org .elasticsearch .common .xcontent .ConstructingObjectParser ;
13
12
import org .elasticsearch .common .xcontent .XContentBuilder ;
14
13
import org .elasticsearch .common .xcontent .XContentParser ;
14
+ import org .elasticsearch .xpack .core .action .TransportReloadAnalyzersAction .ReloadResult ;
15
15
16
16
import java .io .IOException ;
17
17
import java .util .Arrays ;
18
18
import java .util .Collections ;
19
19
import java .util .HashMap ;
20
+ import java .util .HashSet ;
20
21
import java .util .List ;
21
22
import java .util .Map ;
22
23
import java .util .Map .Entry ;
24
+ import java .util .Set ;
23
25
24
26
import static org .elasticsearch .common .xcontent .ConstructingObjectParser .constructorArg ;
25
27
28
30
*/
29
31
public class ReloadAnalyzersResponse extends BroadcastResponse {
30
32
31
- private final Map <String , List <String >> reloadedIndicesNodes ;
33
+ private final Map <String , ReloadDetails > reloadDetails ;
34
+ private static final ParseField RELOAD_DETAILS_FIELD = new ParseField ("reload_details" );
35
+ private static final ParseField INDEX_FIELD = new ParseField ("index" );
36
+ private static final ParseField RELOADED_ANALYZERS_FIELD = new ParseField ("reloaded_analyzers" );
37
+ private static final ParseField RELOADED_NODE_IDS_FIELD = new ParseField ("reloaded_node_ids" );
38
+
32
39
33
40
public ReloadAnalyzersResponse () {
34
- reloadedIndicesNodes = Collections .emptyMap ();
41
+ reloadDetails = Collections .emptyMap ();
35
42
}
36
43
37
44
public ReloadAnalyzersResponse (int totalShards , int successfulShards , int failedShards ,
38
- List <DefaultShardOperationFailedException > shardFailures , Map <String , List < String > > reloadedIndicesNodes ) {
45
+ List <DefaultShardOperationFailedException > shardFailures , Map <String , ReloadDetails > reloadedIndicesNodes ) {
39
46
super (totalShards , successfulShards , failedShards , shardFailures );
40
- this .reloadedIndicesNodes = reloadedIndicesNodes ;
47
+ this .reloadDetails = reloadedIndicesNodes ;
48
+ }
49
+
50
+ public final Map <String , ReloadDetails > getReloadDetails () {
51
+ return this .reloadDetails ;
41
52
}
42
53
43
54
public Map <String , List <String >> getReloadedIndicesNodes () {
@@ -49,11 +60,13 @@ public Map<String, List<String>> getReloadedIndicesNodes() {
49
60
*/
50
61
@ Override
51
62
protected void addCustomXContentFields (XContentBuilder builder , Params params ) throws IOException {
52
- builder .startArray ("reloaded_nodes" );
53
- for (Entry <String , List < String >> indexNodesReloaded : reloadedIndicesNodes .entrySet ()) {
63
+ builder .startArray (RELOAD_DETAILS_FIELD . getPreferredName () );
64
+ for (Entry <String , ReloadDetails > indexDetails : reloadDetails .entrySet ()) {
54
65
builder .startObject ();
55
- builder .field ("index" , indexNodesReloaded .getKey ());
56
- builder .field ("reloaded_node_ids" , indexNodesReloaded .getValue ());
66
+ ReloadDetails value = indexDetails .getValue ();
67
+ builder .field (INDEX_FIELD .getPreferredName (), value .getIndexName ());
68
+ builder .field (RELOADED_ANALYZERS_FIELD .getPreferredName (), value .getReloadedAnalyzers ());
69
+ builder .field (RELOADED_NODE_IDS_FIELD .getPreferredName (), value .getReloadedIndicesNodes ());
57
70
builder .endObject ();
58
71
}
59
72
builder .endArray ();
@@ -63,31 +76,61 @@ protected void addCustomXContentFields(XContentBuilder builder, Params params) t
63
76
private static final ConstructingObjectParser <ReloadAnalyzersResponse , Void > PARSER = new ConstructingObjectParser <>("reload_analyzer" ,
64
77
true , arg -> {
65
78
BroadcastResponse response = (BroadcastResponse ) arg [0 ];
66
- List <Tuple < String , List < String >>> results = (List <Tuple < String , List < String >> >) arg [1 ];
67
- Map <String , List < String > > reloadedNodeIds = new HashMap <>();
68
- for (Tuple < String , List < String >> result : results ) {
69
- reloadedNodeIds .put (result .v1 (), result . v2 () );
79
+ List <ReloadDetails > results = (List <ReloadDetails >) arg [1 ];
80
+ Map <String , ReloadDetails > reloadedNodeIds = new HashMap <>();
81
+ for (ReloadDetails result : results ) {
82
+ reloadedNodeIds .put (result .getIndexName (), result );
70
83
}
71
84
return new ReloadAnalyzersResponse (response .getTotalShards (), response .getSuccessfulShards (), response .getFailedShards (),
72
85
Arrays .asList (response .getShardFailures ()), reloadedNodeIds );
73
86
});
74
87
75
88
@ SuppressWarnings ({ "unchecked" })
76
- private static final ConstructingObjectParser <Tuple < String , List < String >> , Void > ENTRY_PARSER = new ConstructingObjectParser <>(
89
+ private static final ConstructingObjectParser <ReloadDetails , Void > ENTRY_PARSER = new ConstructingObjectParser <>(
77
90
"reload_analyzer.entry" , true , arg -> {
78
- String index = (String ) arg [0 ];
79
- List <String > nodeIds = (List <String >) arg [1 ];
80
- return new Tuple <>(index , nodeIds );
91
+ return new ReloadDetails ((String ) arg [0 ], new HashSet <>((List <String >) arg [1 ]), new HashSet <>((List <String >) arg [2 ]));
81
92
});
82
93
83
94
static {
84
95
declareBroadcastFields (PARSER );
85
- PARSER .declareObjectArray (constructorArg (), ENTRY_PARSER , new ParseField ("reloaded_nodes" ));
86
- ENTRY_PARSER .declareString (constructorArg (), new ParseField ("index" ));
87
- ENTRY_PARSER .declareStringArray (constructorArg (), new ParseField ("reloaded_node_ids" ));
96
+ PARSER .declareObjectArray (constructorArg (), ENTRY_PARSER , RELOAD_DETAILS_FIELD );
97
+ ENTRY_PARSER .declareString (constructorArg (), INDEX_FIELD );
98
+ ENTRY_PARSER .declareStringArray (constructorArg (), RELOADED_ANALYZERS_FIELD );
99
+ ENTRY_PARSER .declareStringArray (constructorArg (), RELOADED_NODE_IDS_FIELD );
88
100
}
89
101
90
102
public static ReloadAnalyzersResponse fromXContent (XContentParser parser ) {
91
103
return PARSER .apply (parser , null );
92
104
}
105
+
106
+ public static class ReloadDetails {
107
+
108
+ private final String indexName ;
109
+ private final Set <String > reloadedIndicesNodes ;
110
+ private final Set <String > reloadedAnalyzers ;
111
+
112
+ ReloadDetails (String name , Set <String > reloadedIndicesNodes , Set <String > reloadedAnalyzers ) {
113
+ this .indexName = name ;
114
+ this .reloadedIndicesNodes = reloadedIndicesNodes ;
115
+ this .reloadedAnalyzers = reloadedAnalyzers ;
116
+ }
117
+
118
+ public String getIndexName () {
119
+ return indexName ;
120
+ }
121
+
122
+ public Set <String > getReloadedIndicesNodes () {
123
+ return reloadedIndicesNodes ;
124
+ }
125
+
126
+ public Set <String > getReloadedAnalyzers () {
127
+ return reloadedAnalyzers ;
128
+ }
129
+
130
+ void merge (ReloadResult other ) {
131
+ assert this .indexName == other .index ;
132
+ this .reloadedAnalyzers .addAll (other .reloadedSearchAnalyzers );
133
+ this .reloadedIndicesNodes .add (other .nodeId );
134
+ }
135
+ }
93
136
}
0 commit comments