29
29
import org .elasticsearch .rest .RestStatus ;
30
30
31
31
import java .io .IOException ;
32
+ import java .util .Collection ;
33
+ import java .util .List ;
34
+ import java .util .Set ;
32
35
33
36
public class ReindexTaskStateDoc implements ToXContentObject {
34
37
38
+ @ SuppressWarnings ("unchecked" )
35
39
public static final ConstructingObjectParser <ReindexTaskStateDoc , Void > PARSER =
36
- new ConstructingObjectParser <>("reindex/index_state" , a -> new ReindexTaskStateDoc ((ReindexRequest ) a [0 ], (Long ) a [1 ],
37
- (BulkByScrollResponse ) a [2 ], (ElasticsearchException ) a [3 ], (Integer ) a [4 ], (ScrollableHitSource .Checkpoint ) a [5 ]));
40
+ new ConstructingObjectParser <>("reindex/index_state" , a -> new ReindexTaskStateDoc ((ReindexRequest ) a [0 ], (List <Set <String >>) a [1 ],
41
+ (Long ) a [2 ], (BulkByScrollResponse ) a [3 ], (ElasticsearchException ) a [4 ], (Integer ) a [5 ],
42
+ (ScrollableHitSource .Checkpoint ) a [6 ]));
38
43
39
44
private static final String REINDEX_REQUEST = "request" ;
45
+ private static final String INDEX_GROUPS = "index_groups" ;
40
46
private static final String ALLOCATION = "allocation" ;
41
47
private static final String REINDEX_RESPONSE = "response" ;
42
48
private static final String REINDEX_EXCEPTION = "exception" ;
@@ -46,6 +52,7 @@ public class ReindexTaskStateDoc implements ToXContentObject {
46
52
static {
47
53
PARSER .declareObject (ConstructingObjectParser .constructorArg (), (p , c ) -> ReindexRequest .fromXContentWithParams (p ),
48
54
new ParseField (REINDEX_REQUEST ));
55
+ PARSER .declareObjectArray (ConstructingObjectParser .constructorArg (), (p , c ) -> p .list (), new ParseField (INDEX_GROUPS ));
49
56
PARSER .declareLong (ConstructingObjectParser .optionalConstructorArg (), new ParseField (ALLOCATION ));
50
57
PARSER .declareObject (ConstructingObjectParser .optionalConstructorArg (), (p , c ) -> BulkByScrollResponse .fromXContent (p ),
51
58
new ParseField (REINDEX_RESPONSE ));
@@ -57,32 +64,35 @@ public class ReindexTaskStateDoc implements ToXContentObject {
57
64
}
58
65
59
66
private final ReindexRequest reindexRequest ;
67
+ private final List <? extends Collection <String >> indexGroups ;
60
68
private final Long allocationId ;
61
69
private final BulkByScrollResponse reindexResponse ;
62
70
private final ElasticsearchException exception ;
63
71
private final RestStatus failureStatusCode ;
64
72
private final ScrollableHitSource .Checkpoint checkpoint ;
65
73
66
- public ReindexTaskStateDoc (ReindexRequest reindexRequest ) {
67
- this (reindexRequest , null , null , null , (RestStatus ) null , null );
74
+ public ReindexTaskStateDoc (ReindexRequest reindexRequest , List <? extends Collection < String >> indexGroups ) {
75
+ this (reindexRequest , indexGroups , null , null , null , (RestStatus ) null , null );
68
76
}
69
77
70
- public ReindexTaskStateDoc (ReindexRequest reindexRequest , @ Nullable Long allocationId ,
78
+ public ReindexTaskStateDoc (ReindexRequest reindexRequest , List <? extends Collection < String >> indexGroups , @ Nullable Long allocationId ,
71
79
@ Nullable BulkByScrollResponse reindexResponse , @ Nullable ElasticsearchException exception ,
72
80
@ Nullable Integer failureStatusCode , ScrollableHitSource .Checkpoint checkpoint ) {
73
- this (reindexRequest , allocationId , reindexResponse , exception ,
81
+ this (reindexRequest , indexGroups , allocationId , reindexResponse , exception ,
74
82
failureStatusCode == null ? null : RestStatus .fromCode (failureStatusCode ), checkpoint );
75
83
}
76
84
77
- public ReindexTaskStateDoc (ReindexRequest reindexRequest , @ Nullable Long allocationId ,
85
+ public ReindexTaskStateDoc (ReindexRequest reindexRequest , List <? extends Collection < String >> indexGroups , @ Nullable Long allocationId ,
78
86
@ Nullable BulkByScrollResponse reindexResponse , @ Nullable ElasticsearchException exception ,
79
87
@ Nullable ScrollableHitSource .Checkpoint checkpoint ) {
80
- this (reindexRequest , allocationId , reindexResponse , exception , exception != null ? exception .status () : null , checkpoint );
88
+ this (reindexRequest , indexGroups , allocationId , reindexResponse ,
89
+ exception , exception != null ? exception .status () : null , checkpoint );
81
90
}
82
91
83
- private ReindexTaskStateDoc (ReindexRequest reindexRequest , @ Nullable Long allocationId ,
92
+ private ReindexTaskStateDoc (ReindexRequest reindexRequest , List <? extends Collection < String >> indexGroups , @ Nullable Long allocationId ,
84
93
@ Nullable BulkByScrollResponse reindexResponse , @ Nullable ElasticsearchException exception ,
85
94
@ Nullable RestStatus failureStatusCode , @ Nullable ScrollableHitSource .Checkpoint checkpoint ) {
95
+ this .indexGroups = indexGroups ;
86
96
this .allocationId = allocationId ;
87
97
assert (reindexResponse == null ) || (exception == null ) : "Either response or exception must be null" ;
88
98
this .reindexRequest = reindexRequest ;
@@ -97,6 +107,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
97
107
builder .startObject ();
98
108
builder .field (REINDEX_REQUEST );
99
109
reindexRequest .toXContent (builder , params , true );
110
+ builder .field (INDEX_GROUPS , indexGroups );
100
111
if (allocationId != null ) {
101
112
builder .field (ALLOCATION , allocationId );
102
113
}
@@ -128,6 +139,10 @@ public ReindexRequest getReindexRequest() {
128
139
return reindexRequest ;
129
140
}
130
141
142
+ public List <? extends Collection <String >> getIndexGroups () {
143
+ return indexGroups ;
144
+ }
145
+
131
146
public BulkByScrollResponse getReindexResponse () {
132
147
return reindexResponse ;
133
148
}
@@ -150,15 +165,17 @@ public Long getAllocationId() {
150
165
151
166
public ReindexTaskStateDoc withCheckpoint (ScrollableHitSource .Checkpoint checkpoint , BulkByScrollTask .Status status ) {
152
167
// todo: also store and resume from status.
153
- return new ReindexTaskStateDoc (reindexRequest , allocationId , reindexResponse , exception , failureStatusCode , checkpoint );
168
+ return new ReindexTaskStateDoc (reindexRequest , indexGroups , allocationId , reindexResponse ,
169
+ exception , failureStatusCode , checkpoint );
154
170
}
155
171
156
172
public ReindexTaskStateDoc withNewAllocation (long newAllocationId ) {
157
- return new ReindexTaskStateDoc (reindexRequest , newAllocationId , reindexResponse , exception , failureStatusCode , checkpoint );
173
+ return new ReindexTaskStateDoc (reindexRequest , indexGroups , newAllocationId , reindexResponse ,
174
+ exception , failureStatusCode , checkpoint );
158
175
}
159
176
160
177
public ReindexTaskStateDoc withFinishedState (@ Nullable BulkByScrollResponse reindexResponse ,
161
178
@ Nullable ElasticsearchException exception ) {
162
- return new ReindexTaskStateDoc (reindexRequest , allocationId , reindexResponse , exception , checkpoint );
179
+ return new ReindexTaskStateDoc (reindexRequest , indexGroups , allocationId , reindexResponse , exception , checkpoint );
163
180
}
164
181
}
0 commit comments