19
19
20
20
package org .elasticsearch .index .reindex ;
21
21
22
- import org .elasticsearch .ElasticsearchException ;
23
- import org .elasticsearch .common .Nullable ;
24
22
import org .elasticsearch .common .ParseField ;
25
23
import org .elasticsearch .common .io .stream .StreamInput ;
26
24
import org .elasticsearch .common .io .stream .StreamOutput ;
@@ -39,41 +37,32 @@ public class ReindexJobState implements Task.Status, PersistentTaskState {
39
37
public static final String NAME = ReindexTask .NAME ;
40
38
41
39
public static final ConstructingObjectParser <ReindexJobState , Void > PARSER =
42
- new ConstructingObjectParser <>(NAME , a -> new ReindexJobState ((String ) a [0 ], (BulkByScrollResponse ) a [1 ],
43
- (ElasticsearchException ) a [2 ]));
40
+ new ConstructingObjectParser <>(NAME , a -> new ReindexJobState ((String ) a [0 ], (String ) a [1 ]));
44
41
45
42
private static String EPHEMERAL_TASK_ID = "ephemeral_task_id" ;
46
- private static String REINDEX_RESPONSE = "reindex_response" ;
47
- private static String REINDEX_EXCEPTION = "reindex_exception" ;
43
+ private static String STATUS = "status" ;
48
44
49
45
static {
50
46
PARSER .declareString (ConstructingObjectParser .constructorArg (), new ParseField (EPHEMERAL_TASK_ID ));
51
- PARSER .declareObject (ConstructingObjectParser .optionalConstructorArg (), (p , c ) -> BulkByScrollResponse .fromXContent (p ),
52
- new ParseField (REINDEX_RESPONSE ));
53
- PARSER .declareObject (ConstructingObjectParser .optionalConstructorArg (), (p , c ) -> ElasticsearchException .fromXContent (p ),
54
- new ParseField (REINDEX_EXCEPTION ));
47
+ PARSER .declareString (ConstructingObjectParser .constructorArg (), new ParseField (STATUS ));
55
48
}
56
49
57
50
private final TaskId ephemeralTaskId ;
58
- private final BulkByScrollResponse reindexResponse ;
59
- private final ElasticsearchException jobException ;
51
+ private final Status status ;
60
52
61
- private ReindexJobState (String ephemeralTaskId , BulkByScrollResponse reindexResponse , ElasticsearchException jobException ) {
62
- this (new TaskId (ephemeralTaskId ), reindexResponse , jobException );
53
+ private ReindexJobState (String ephemeralTaskId , String status ) {
54
+ this (new TaskId (ephemeralTaskId ), Status . valueOf ( status ) );
63
55
}
64
56
65
- ReindexJobState (TaskId ephemeralTaskId , @ Nullable BulkByScrollResponse reindexResponse ,
66
- @ Nullable ElasticsearchException jobException ) {
57
+ ReindexJobState (TaskId ephemeralTaskId , Status status ) {
58
+ assert status != null : "Status cannot be null" ;
67
59
this .ephemeralTaskId = ephemeralTaskId ;
68
- assert (reindexResponse == null ) || (jobException == null ) : "Either response or exception must be null" ;
69
- this .reindexResponse = reindexResponse ;
70
- this .jobException = jobException ;
60
+ this .status = status ;
71
61
}
72
62
73
63
public ReindexJobState (StreamInput in ) throws IOException {
74
64
ephemeralTaskId = TaskId .readFromStream (in );
75
- reindexResponse = in .readOptionalWriteable (BulkByScrollResponse ::new );
76
- jobException = in .readException ();
65
+ status = in .readEnum (Status .class );
77
66
}
78
67
79
68
@ Override
@@ -84,35 +73,23 @@ public String getWriteableName() {
84
73
@ Override
85
74
public void writeTo (StreamOutput out ) throws IOException {
86
75
ephemeralTaskId .writeTo (out );
87
- out .writeOptionalWriteable (reindexResponse );
88
- out .writeException (jobException );
76
+ out .writeEnum (status );
89
77
}
90
78
91
79
@ Override
92
80
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
93
81
builder .startObject ();
94
82
builder .field (EPHEMERAL_TASK_ID , ephemeralTaskId .toString ());
95
- if (reindexResponse != null ) {
96
- builder .field (REINDEX_RESPONSE );
97
- builder .startObject ();
98
- reindexResponse .toXContent (builder , params );
99
- builder .endObject ();
100
- }
101
- if (jobException != null ) {
102
- builder .field (REINDEX_EXCEPTION );
103
- builder .startObject ();
104
- jobException .toXContent (builder , params );
105
- builder .endObject ();
106
- }
83
+ builder .field (STATUS , status );
107
84
return builder .endObject ();
108
85
}
109
86
110
- public BulkByScrollResponse getReindexResponse () {
111
- return reindexResponse ;
87
+ public boolean isDone () {
88
+ return status != Status . STARTED ;
112
89
}
113
90
114
- public ElasticsearchException getJobException () {
115
- return jobException ;
91
+ public Status getStatus () {
92
+ return status ;
116
93
}
117
94
118
95
public TaskId getEphemeralTaskId () {
@@ -122,4 +99,11 @@ public TaskId getEphemeralTaskId() {
122
99
public static ReindexJobState fromXContent (XContentParser parser ) {
123
100
return PARSER .apply (parser , null );
124
101
}
102
+
103
+ public enum Status {
104
+ STARTED ,
105
+ FAILED_TO_READ_FROM_REINDEX_INDEX ,
106
+ FAILED_TO_WRITE_TO_REINDEX_INDEX ,
107
+ DONE
108
+ }
125
109
}
0 commit comments