21
21
22
22
import org .elasticsearch .common .Nullable ;
23
23
import org .elasticsearch .common .ParseField ;
24
+ import org .elasticsearch .common .Strings ;
24
25
import org .elasticsearch .common .xcontent .ConstructingObjectParser ;
25
26
import org .elasticsearch .common .xcontent .ToXContentObject ;
26
27
import org .elasticsearch .common .xcontent .XContentBuilder ;
27
28
import org .elasticsearch .common .xcontent .XContentParser ;
29
+ import org .elasticsearch .snapshots .SnapshotId ;
28
30
29
31
import java .io .IOException ;
30
32
import java .util .Objects ;
@@ -39,6 +41,7 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
39
41
static final ParseField LAST_FAILURE = new ParseField ("last_failure" );
40
42
static final ParseField NEXT_EXECUTION_MILLIS = new ParseField ("next_execution_millis" );
41
43
static final ParseField NEXT_EXECUTION = new ParseField ("next_execution" );
44
+ static final ParseField SNAPSHOT_IN_PROGRESS = new ParseField ("in_progress" );
42
45
43
46
private final SnapshotLifecyclePolicy policy ;
44
47
private final long version ;
@@ -48,6 +51,8 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
48
51
private final SnapshotInvocationRecord lastSuccess ;
49
52
@ Nullable
50
53
private final SnapshotInvocationRecord lastFailure ;
54
+ @ Nullable
55
+ private final SnapshotInProgress snapshotInProgress ;
51
56
52
57
@ SuppressWarnings ("unchecked" )
53
58
public static final ConstructingObjectParser <SnapshotLifecyclePolicyMetadata , String > PARSER =
@@ -59,8 +64,9 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
59
64
SnapshotInvocationRecord lastSuccess = (SnapshotInvocationRecord ) a [3 ];
60
65
SnapshotInvocationRecord lastFailure = (SnapshotInvocationRecord ) a [4 ];
61
66
long nextExecution = (long ) a [5 ];
67
+ SnapshotInProgress sip = (SnapshotInProgress ) a [6 ];
62
68
63
- return new SnapshotLifecyclePolicyMetadata (policy , version , modifiedDate , lastSuccess , lastFailure , nextExecution );
69
+ return new SnapshotLifecyclePolicyMetadata (policy , version , modifiedDate , lastSuccess , lastFailure , nextExecution , sip );
64
70
});
65
71
66
72
static {
@@ -70,6 +76,7 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
70
76
PARSER .declareObject (ConstructingObjectParser .optionalConstructorArg (), SnapshotInvocationRecord ::parse , LAST_SUCCESS );
71
77
PARSER .declareObject (ConstructingObjectParser .optionalConstructorArg (), SnapshotInvocationRecord ::parse , LAST_FAILURE );
72
78
PARSER .declareLong (ConstructingObjectParser .constructorArg (), NEXT_EXECUTION_MILLIS );
79
+ PARSER .declareObject (ConstructingObjectParser .optionalConstructorArg (), SnapshotInProgress ::parse , SNAPSHOT_IN_PROGRESS );
73
80
}
74
81
75
82
public static SnapshotLifecyclePolicyMetadata parse (XContentParser parser , String id ) {
@@ -78,13 +85,15 @@ public static SnapshotLifecyclePolicyMetadata parse(XContentParser parser, Strin
78
85
79
86
public SnapshotLifecyclePolicyMetadata (SnapshotLifecyclePolicy policy , long version , long modifiedDate ,
80
87
SnapshotInvocationRecord lastSuccess , SnapshotInvocationRecord lastFailure ,
81
- long nextExecution ) {
88
+ long nextExecution ,
89
+ @ Nullable SnapshotInProgress snapshotInProgress ) {
82
90
this .policy = policy ;
83
91
this .version = version ;
84
92
this .modifiedDate = modifiedDate ;
85
93
this .lastSuccess = lastSuccess ;
86
94
this .lastFailure = lastFailure ;
87
95
this .nextExecution = nextExecution ;
96
+ this .snapshotInProgress = snapshotInProgress ;
88
97
}
89
98
90
99
public SnapshotLifecyclePolicy getPolicy () {
@@ -115,6 +124,11 @@ public long getNextExecution() {
115
124
return this .nextExecution ;
116
125
}
117
126
127
+ @ Nullable
128
+ public SnapshotInProgress getSnapshotInProgress () {
129
+ return this .snapshotInProgress ;
130
+ }
131
+
118
132
@ Override
119
133
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
120
134
builder .startObject ();
@@ -128,6 +142,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
128
142
builder .field (LAST_FAILURE .getPreferredName (), lastFailure );
129
143
}
130
144
builder .timeField (NEXT_EXECUTION_MILLIS .getPreferredName (), NEXT_EXECUTION .getPreferredName (), nextExecution );
145
+ if (snapshotInProgress != null ) {
146
+ builder .field (SNAPSHOT_IN_PROGRESS .getPreferredName (), snapshotInProgress );
147
+ }
131
148
builder .endObject ();
132
149
return builder ;
133
150
}
@@ -154,4 +171,84 @@ public boolean equals(Object obj) {
154
171
Objects .equals (nextExecution , other .nextExecution );
155
172
}
156
173
174
+ public static class SnapshotInProgress implements ToXContentObject {
175
+ private static final ParseField NAME = new ParseField ("name" );
176
+ private static final ParseField UUID = new ParseField ("uuid" );
177
+ private static final ParseField STATE = new ParseField ("state" );
178
+ private static final ParseField START_TIME = new ParseField ("start_time_millis" );
179
+ private static final ParseField FAILURE = new ParseField ("failure" );
180
+
181
+ private static final ConstructingObjectParser <SnapshotInProgress , Void > PARSER =
182
+ new ConstructingObjectParser <>("snapshot_in_progress" , true , a -> {
183
+ SnapshotId id = new SnapshotId ((String ) a [0 ], (String ) a [1 ]);
184
+ String state = (String ) a [2 ];
185
+ long start = (long ) a [3 ];
186
+ String failure = (String ) a [4 ];
187
+ return new SnapshotInProgress (id , state , start , failure );
188
+ });
189
+
190
+ static {
191
+ PARSER .declareString (ConstructingObjectParser .constructorArg (), NAME );
192
+ PARSER .declareString (ConstructingObjectParser .constructorArg (), UUID );
193
+ PARSER .declareString (ConstructingObjectParser .constructorArg (), STATE );
194
+ PARSER .declareLong (ConstructingObjectParser .constructorArg (), START_TIME );
195
+ PARSER .declareString (ConstructingObjectParser .optionalConstructorArg (), FAILURE );
196
+ }
197
+
198
+ private final SnapshotId snapshotId ;
199
+ private final String state ;
200
+ private final long startTime ;
201
+ private final String failure ;
202
+
203
+ public SnapshotInProgress (SnapshotId snapshotId , String state , long startTime , @ Nullable String failure ) {
204
+ this .snapshotId = snapshotId ;
205
+ this .state = state ;
206
+ this .startTime = startTime ;
207
+ this .failure = failure ;
208
+ }
209
+
210
+ private static SnapshotInProgress parse (XContentParser parser , String name ) {
211
+ return PARSER .apply (parser , null );
212
+ }
213
+
214
+ @ Override
215
+ public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
216
+ builder .startObject ();
217
+ builder .field (NAME .getPreferredName (), snapshotId .getName ());
218
+ builder .field (UUID .getPreferredName (), snapshotId .getUUID ());
219
+ builder .field (STATE .getPreferredName (), state );
220
+ builder .timeField (START_TIME .getPreferredName (), "start_time" , startTime );
221
+ if (failure != null ) {
222
+ builder .field (FAILURE .getPreferredName (), failure );
223
+ }
224
+ builder .endObject ();
225
+ return builder ;
226
+ }
227
+
228
+ @ Override
229
+ public int hashCode () {
230
+ return Objects .hash (snapshotId , state , startTime , failure );
231
+ }
232
+
233
+ @ Override
234
+ public boolean equals (Object obj ) {
235
+ if (obj == null ) {
236
+ return false ;
237
+ }
238
+
239
+ if (obj .getClass () != getClass ()) {
240
+ return false ;
241
+ }
242
+ SnapshotInProgress other = (SnapshotInProgress ) obj ;
243
+ return Objects .equals (snapshotId , other .snapshotId ) &&
244
+ Objects .equals (state , other .state ) &&
245
+ startTime == other .startTime &&
246
+ Objects .equals (failure , other .failure );
247
+ }
248
+
249
+ @ Override
250
+ public String toString () {
251
+ return Strings .toString (this );
252
+ }
253
+ }
157
254
}
0 commit comments