99
1010package org .elasticsearch .action .admin .cluster .state ;
1111
12- import org .elasticsearch .TransportVersions ;
13- import org .elasticsearch .action .ActionRequest ;
1412import org .elasticsearch .action .ActionRequestValidationException ;
13+ import org .elasticsearch .action .IndicesRequest ;
14+ import org .elasticsearch .action .support .IndicesOptions ;
15+ import org .elasticsearch .action .support .master .MasterNodeReadRequest ;
16+ import org .elasticsearch .common .Strings ;
1517import org .elasticsearch .common .io .stream .StreamInput ;
1618import org .elasticsearch .common .io .stream .StreamOutput ;
19+ import org .elasticsearch .core .TimeValue ;
1720import org .elasticsearch .tasks .CancellableTask ;
1821import org .elasticsearch .tasks .Task ;
1922import org .elasticsearch .tasks .TaskId ;
2023
2124import java .io .IOException ;
25+ import java .util .Arrays ;
2226import java .util .Map ;
2327
2428/**
2529 * A remote-only version of {@link ClusterStateRequest} that should be used for cross-cluster requests.
2630 * It simply exists to handle incoming remote requests and forward them to the local transport action.
2731 */
28- public class RemoteClusterStateRequest extends ActionRequest {
32+ public class RemoteClusterStateRequest extends MasterNodeReadRequest < RemoteClusterStateRequest > implements IndicesRequest . Replaceable {
2933
30- private final ClusterStateRequest clusterStateRequest ;
34+ private boolean routingTable = true ;
35+ private boolean nodes = true ;
36+ private boolean metadata = true ;
37+ private boolean blocks = true ;
38+ private boolean customs = true ;
39+ private Long waitForMetadataVersion ;
40+ private TimeValue waitForTimeout = ClusterStateRequest .DEFAULT_WAIT_FOR_NODE_TIMEOUT ;
41+ private String [] indices = Strings .EMPTY_ARRAY ;
42+ private IndicesOptions indicesOptions = IndicesOptions .lenientExpandOpen ();
3143
32- public RemoteClusterStateRequest (ClusterStateRequest clusterStateRequest ) {
33- this . clusterStateRequest = clusterStateRequest ;
44+ public RemoteClusterStateRequest (TimeValue masterNodeTimeout ) {
45+ super ( masterNodeTimeout ) ;
3446 }
3547
3648 public RemoteClusterStateRequest (StreamInput in ) throws IOException {
37- this .clusterStateRequest = new ClusterStateRequest (in );
49+ super (in );
50+ routingTable = in .readBoolean ();
51+ nodes = in .readBoolean ();
52+ metadata = in .readBoolean ();
53+ blocks = in .readBoolean ();
54+ customs = in .readBoolean ();
55+ indices = in .readStringArray ();
56+ indicesOptions = IndicesOptions .readIndicesOptions (in );
57+ waitForTimeout = in .readTimeValue ();
58+ waitForMetadataVersion = in .readOptionalLong ();
3859 }
3960
4061 @ Override
4162 public ActionRequestValidationException validate () {
42- return clusterStateRequest .validate ();
63+ // We defer validation to `ClusterStateRequest`, which will run on the local node.
64+ return null ;
65+ }
66+
67+ public RemoteClusterStateRequest all () {
68+ routingTable = true ;
69+ nodes = true ;
70+ metadata = true ;
71+ blocks = true ;
72+ customs = true ;
73+ indices = Strings .EMPTY_ARRAY ;
74+ return this ;
75+ }
76+
77+ public RemoteClusterStateRequest clear () {
78+ routingTable = false ;
79+ nodes = false ;
80+ metadata = false ;
81+ blocks = false ;
82+ customs = false ;
83+ indices = Strings .EMPTY_ARRAY ;
84+ return this ;
85+ }
86+
87+ public boolean routingTable () {
88+ return routingTable ;
89+ }
90+
91+ public RemoteClusterStateRequest routingTable (boolean routingTable ) {
92+ this .routingTable = routingTable ;
93+ return this ;
94+ }
95+
96+ public boolean nodes () {
97+ return nodes ;
98+ }
99+
100+ public RemoteClusterStateRequest nodes (boolean nodes ) {
101+ this .nodes = nodes ;
102+ return this ;
103+ }
104+
105+ public boolean metadata () {
106+ return metadata ;
107+ }
108+
109+ public RemoteClusterStateRequest metadata (boolean metadata ) {
110+ this .metadata = metadata ;
111+ return this ;
112+ }
113+
114+ public boolean blocks () {
115+ return blocks ;
116+ }
117+
118+ public RemoteClusterStateRequest blocks (boolean blocks ) {
119+ this .blocks = blocks ;
120+ return this ;
121+ }
122+
123+ @ Override
124+ public String [] indices () {
125+ return indices ;
126+ }
127+
128+ @ Override
129+ public RemoteClusterStateRequest indices (String ... indices ) {
130+ this .indices = indices ;
131+ return this ;
132+ }
133+
134+ @ Override
135+ public IndicesOptions indicesOptions () {
136+ return this .indicesOptions ;
137+ }
138+
139+ public final RemoteClusterStateRequest indicesOptions (IndicesOptions indicesOptions ) {
140+ this .indicesOptions = indicesOptions ;
141+ return this ;
142+ }
143+
144+ @ Override
145+ public boolean includeDataStreams () {
146+ return true ;
147+ }
148+
149+ public RemoteClusterStateRequest customs (boolean customs ) {
150+ this .customs = customs ;
151+ return this ;
152+ }
153+
154+ public boolean customs () {
155+ return customs ;
156+ }
157+
158+ public TimeValue waitForTimeout () {
159+ return waitForTimeout ;
160+ }
161+
162+ public RemoteClusterStateRequest waitForTimeout (TimeValue waitForTimeout ) {
163+ this .waitForTimeout = waitForTimeout ;
164+ return this ;
165+ }
166+
167+ public Long waitForMetadataVersion () {
168+ return waitForMetadataVersion ;
169+ }
170+
171+ public RemoteClusterStateRequest waitForMetadataVersion (long waitForMetadataVersion ) {
172+ if (waitForMetadataVersion < 1 ) {
173+ throw new IllegalArgumentException (
174+ "provided waitForMetadataVersion should be >= 1, but instead is [" + waitForMetadataVersion + "]"
175+ );
176+ }
177+ this .waitForMetadataVersion = waitForMetadataVersion ;
178+ return this ;
43179 }
44180
45181 @ Override
46182 public void writeTo (StreamOutput out ) throws IOException {
47- clusterStateRequest .getParentTask ().writeTo (out );
48- out .writeTimeValue (clusterStateRequest .masterTimeout ());
49- if (out .getTransportVersion ().onOrAfter (TransportVersions .V_8_15_0 )) {
50- out .writeVLong (0L ); // Master term
51- } // else no protection against routing loops in older versions
52- out .writeBoolean (true ); // Local
53- out .writeBoolean (clusterStateRequest .routingTable ());
54- out .writeBoolean (clusterStateRequest .nodes ());
55- out .writeBoolean (clusterStateRequest .metadata ());
56- out .writeBoolean (clusterStateRequest .blocks ());
57- out .writeBoolean (clusterStateRequest .customs ());
58- out .writeStringArray (clusterStateRequest .indices ());
59- clusterStateRequest .indicesOptions ().writeIndicesOptions (out );
60- out .writeTimeValue (clusterStateRequest .waitForTimeout ());
61- out .writeOptionalLong (clusterStateRequest .waitForMetadataVersion ());
183+ super .writeTo (out );
184+ out .writeBoolean (routingTable );
185+ out .writeBoolean (nodes );
186+ out .writeBoolean (metadata );
187+ out .writeBoolean (blocks );
188+ out .writeBoolean (customs );
189+ out .writeStringArray (indices );
190+ indicesOptions .writeIndicesOptions (out );
191+ out .writeTimeValue (waitForTimeout );
192+ out .writeOptionalLong (waitForMetadataVersion );
62193 }
63194
64195 @ Override
@@ -68,10 +199,34 @@ public Task createTask(long id, String type, String action, TaskId parentTaskId,
68199
69200 @ Override
70201 public String getDescription () {
71- return clusterStateRequest .getDescription ();
72- }
202+ final StringBuilder stringBuilder = new StringBuilder ("remote cluster state [" );
203+ if (routingTable ) {
204+ stringBuilder .append ("routing table, " );
205+ }
206+ if (nodes ) {
207+ stringBuilder .append ("nodes, " );
208+ }
209+ if (metadata ) {
210+ stringBuilder .append ("metadata, " );
211+ }
212+ if (blocks ) {
213+ stringBuilder .append ("blocks, " );
214+ }
215+ if (customs ) {
216+ stringBuilder .append ("customs, " );
217+ }
218+ if (waitForMetadataVersion != null ) {
219+ stringBuilder .append ("wait for metadata version [" )
220+ .append (waitForMetadataVersion )
221+ .append ("] with timeout [" )
222+ .append (waitForTimeout )
223+ .append ("], " );
224+ }
225+ if (indices .length > 0 ) {
226+ stringBuilder .append ("indices " ).append (Arrays .toString (indices )).append (", " );
227+ }
228+ stringBuilder .append ("master timeout [" ).append (masterNodeTimeout ()).append ("]]" );
229+ return stringBuilder .toString ();
73230
74- public ClusterStateRequest clusterStateRequest () {
75- return clusterStateRequest ;
76231 }
77232}
0 commit comments