|
14 | 14 | import org.elasticsearch.common.io.stream.StreamOutput; |
15 | 15 | import org.elasticsearch.common.io.stream.Writeable; |
16 | 16 | import org.elasticsearch.common.unit.ByteSizeValue; |
17 | | -import org.elasticsearch.common.xcontent.XContentParserUtils; |
18 | 17 | import org.elasticsearch.core.TimeValue; |
19 | 18 | import org.elasticsearch.xcontent.ToXContent; |
20 | 19 | import org.elasticsearch.xcontent.ToXContentObject; |
21 | 20 | import org.elasticsearch.xcontent.XContentBuilder; |
22 | | -import org.elasticsearch.xcontent.XContentParser; |
23 | 21 |
|
24 | 22 | import java.io.IOException; |
25 | 23 |
|
@@ -192,114 +190,6 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par |
192 | 190 | return builder.endObject(); |
193 | 191 | } |
194 | 192 |
|
195 | | - public static SnapshotStats fromXContent(XContentParser parser) throws IOException { |
196 | | - // Parse this old school style instead of using the ObjectParser since there's an impedance mismatch between how the |
197 | | - // object has historically been written as JSON versus how it is structured in Java. |
198 | | - XContentParser.Token token = parser.currentToken(); |
199 | | - if (token == null) { |
200 | | - token = parser.nextToken(); |
201 | | - } |
202 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); |
203 | | - long startTime = 0; |
204 | | - long time = 0; |
205 | | - int incrementalFileCount = 0; |
206 | | - int totalFileCount = 0; |
207 | | - int processedFileCount = Integer.MIN_VALUE; |
208 | | - long incrementalSize = 0; |
209 | | - long totalSize = 0; |
210 | | - long processedSize = Long.MIN_VALUE; |
211 | | - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { |
212 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); |
213 | | - String currentName = parser.currentName(); |
214 | | - token = parser.nextToken(); |
215 | | - if (currentName.equals(Fields.INCREMENTAL)) { |
216 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); |
217 | | - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { |
218 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); |
219 | | - String innerName = parser.currentName(); |
220 | | - token = parser.nextToken(); |
221 | | - if (innerName.equals(Fields.FILE_COUNT)) { |
222 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_NUMBER, token, parser); |
223 | | - incrementalFileCount = parser.intValue(); |
224 | | - } else if (innerName.equals(Fields.SIZE_IN_BYTES)) { |
225 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_NUMBER, token, parser); |
226 | | - incrementalSize = parser.longValue(); |
227 | | - } else { |
228 | | - // Unknown sub field, skip |
229 | | - if (token == XContentParser.Token.START_OBJECT || token == XContentParser.Token.START_ARRAY) { |
230 | | - parser.skipChildren(); |
231 | | - } |
232 | | - } |
233 | | - } |
234 | | - } else if (currentName.equals(Fields.PROCESSED)) { |
235 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); |
236 | | - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { |
237 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); |
238 | | - String innerName = parser.currentName(); |
239 | | - token = parser.nextToken(); |
240 | | - if (innerName.equals(Fields.FILE_COUNT)) { |
241 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_NUMBER, token, parser); |
242 | | - processedFileCount = parser.intValue(); |
243 | | - } else if (innerName.equals(Fields.SIZE_IN_BYTES)) { |
244 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_NUMBER, token, parser); |
245 | | - processedSize = parser.longValue(); |
246 | | - } else { |
247 | | - // Unknown sub field, skip |
248 | | - if (token == XContentParser.Token.START_OBJECT || token == XContentParser.Token.START_ARRAY) { |
249 | | - parser.skipChildren(); |
250 | | - } |
251 | | - } |
252 | | - } |
253 | | - } else if (currentName.equals(Fields.TOTAL)) { |
254 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); |
255 | | - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { |
256 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); |
257 | | - String innerName = parser.currentName(); |
258 | | - token = parser.nextToken(); |
259 | | - if (innerName.equals(Fields.FILE_COUNT)) { |
260 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_NUMBER, token, parser); |
261 | | - totalFileCount = parser.intValue(); |
262 | | - } else if (innerName.equals(Fields.SIZE_IN_BYTES)) { |
263 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_NUMBER, token, parser); |
264 | | - totalSize = parser.longValue(); |
265 | | - } else { |
266 | | - // Unknown sub field, skip |
267 | | - if (token == XContentParser.Token.START_OBJECT || token == XContentParser.Token.START_ARRAY) { |
268 | | - parser.skipChildren(); |
269 | | - } |
270 | | - } |
271 | | - } |
272 | | - } else if (currentName.equals(Fields.START_TIME_IN_MILLIS)) { |
273 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_NUMBER, token, parser); |
274 | | - startTime = parser.longValue(); |
275 | | - } else if (currentName.equals(Fields.TIME_IN_MILLIS)) { |
276 | | - XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_NUMBER, token, parser); |
277 | | - time = parser.longValue(); |
278 | | - } else { |
279 | | - // Unknown field, skip |
280 | | - if (token == XContentParser.Token.START_OBJECT || token == XContentParser.Token.START_ARRAY) { |
281 | | - parser.skipChildren(); |
282 | | - } |
283 | | - } |
284 | | - } |
285 | | - // Handle the case where the "processed" sub-object is omitted in toXContent() when processedFileCount == incrementalFileCount. |
286 | | - if (processedFileCount == Integer.MIN_VALUE) { |
287 | | - assert processedSize == Long.MIN_VALUE; |
288 | | - processedFileCount = incrementalFileCount; |
289 | | - processedSize = incrementalSize; |
290 | | - } |
291 | | - return new SnapshotStats( |
292 | | - startTime, |
293 | | - time, |
294 | | - incrementalFileCount, |
295 | | - totalFileCount, |
296 | | - processedFileCount, |
297 | | - incrementalSize, |
298 | | - totalSize, |
299 | | - processedSize |
300 | | - ); |
301 | | - } |
302 | | - |
303 | 193 | /** |
304 | 194 | * Add stats instance to the total |
305 | 195 | * @param stats Stats instance to add |
|
0 commit comments