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
/**
44
55
* Override in subclass to add custom fields following the common `_shards` field
45
56
*/
46
57
@ Override
47
58
protected void addCustomXContentFields (XContentBuilder builder , Params params ) throws IOException {
48
- builder .startArray ("reloaded_nodes" );
49
- for (Entry <String , List < String >> indexNodesReloaded : reloadedIndicesNodes .entrySet ()) {
59
+ builder .startArray (RELOAD_DETAILS_FIELD . getPreferredName () );
60
+ for (Entry <String , ReloadDetails > indexDetails : reloadDetails .entrySet ()) {
50
61
builder .startObject ();
51
- builder .field ("index" , indexNodesReloaded .getKey ());
52
- builder .field ("reloaded_node_ids" , indexNodesReloaded .getValue ());
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 ());
53
66
builder .endObject ();
54
67
}
55
68
builder .endArray ();
@@ -59,31 +72,61 @@ protected void addCustomXContentFields(XContentBuilder builder, Params params) t
59
72
private static final ConstructingObjectParser <ReloadAnalyzersResponse , Void > PARSER = new ConstructingObjectParser <>("reload_analyzer" ,
60
73
true , arg -> {
61
74
BroadcastResponse response = (BroadcastResponse ) arg [0 ];
62
- List <Tuple < String , List < String >>> results = (List <Tuple < String , List < String >> >) arg [1 ];
63
- Map <String , List < String > > reloadedNodeIds = new HashMap <>();
64
- for (Tuple < String , List < String >> result : results ) {
65
- reloadedNodeIds .put (result .v1 (), result . v2 () );
75
+ List <ReloadDetails > results = (List <ReloadDetails >) arg [1 ];
76
+ Map <String , ReloadDetails > reloadedNodeIds = new HashMap <>();
77
+ for (ReloadDetails result : results ) {
78
+ reloadedNodeIds .put (result .getIndexName (), result );
66
79
}
67
80
return new ReloadAnalyzersResponse (response .getTotalShards (), response .getSuccessfulShards (), response .getFailedShards (),
68
81
Arrays .asList (response .getShardFailures ()), reloadedNodeIds );
69
82
});
70
83
71
84
@ SuppressWarnings ({ "unchecked" })
72
- private static final ConstructingObjectParser <Tuple < String , List < String >> , Void > ENTRY_PARSER = new ConstructingObjectParser <>(
85
+ private static final ConstructingObjectParser <ReloadDetails , Void > ENTRY_PARSER = new ConstructingObjectParser <>(
73
86
"reload_analyzer.entry" , true , arg -> {
74
- String index = (String ) arg [0 ];
75
- List <String > nodeIds = (List <String >) arg [1 ];
76
- return new Tuple <>(index , nodeIds );
87
+ return new ReloadDetails ((String ) arg [0 ], new HashSet <>((List <String >) arg [1 ]), new HashSet <>((List <String >) arg [2 ]));
77
88
});
78
89
79
90
static {
80
91
declareBroadcastFields (PARSER );
81
- PARSER .declareObjectArray (constructorArg (), ENTRY_PARSER , new ParseField ("reloaded_nodes" ));
82
- ENTRY_PARSER .declareString (constructorArg (), new ParseField ("index" ));
83
- 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 );
84
96
}
85
97
86
98
public static ReloadAnalyzersResponse fromXContent (XContentParser parser ) {
87
99
return PARSER .apply (parser , null );
88
100
}
101
+
102
+ public static class ReloadDetails {
103
+
104
+ private final String indexName ;
105
+ private final Set <String > reloadedIndicesNodes ;
106
+ private final Set <String > reloadedAnalyzers ;
107
+
108
+ ReloadDetails (String name , Set <String > reloadedIndicesNodes , Set <String > reloadedAnalyzers ) {
109
+ this .indexName = name ;
110
+ this .reloadedIndicesNodes = reloadedIndicesNodes ;
111
+ this .reloadedAnalyzers = reloadedAnalyzers ;
112
+ }
113
+
114
+ public String getIndexName () {
115
+ return indexName ;
116
+ }
117
+
118
+ public Set <String > getReloadedIndicesNodes () {
119
+ return reloadedIndicesNodes ;
120
+ }
121
+
122
+ public Set <String > getReloadedAnalyzers () {
123
+ return reloadedAnalyzers ;
124
+ }
125
+
126
+ void merge (ReloadResult other ) {
127
+ assert this .indexName == other .index ;
128
+ this .reloadedAnalyzers .addAll (other .reloadedSearchAnalyzers );
129
+ this .reloadedIndicesNodes .add (other .nodeId );
130
+ }
131
+ }
89
132
}
0 commit comments