|
@@ -31,15 +31,12 @@ import org.elasticsearch.common.joda.FormatDateTimeFormatter;
|
|
|
import org.elasticsearch.common.joda.Joda;
|
|
|
import org.elasticsearch.common.unit.TimeValue;
|
|
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
|
|
-import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
|
|
import org.elasticsearch.common.xcontent.ToXContent;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
-import org.elasticsearch.common.xcontent.XContentParser.Token;
|
|
|
import org.elasticsearch.rest.RestStatus;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.io.UncheckedIOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
@@ -84,7 +81,7 @@ public final class SnapshotInfo implements Comparable<SnapshotInfo>, ToXContent,
|
|
|
private static final Comparator<SnapshotInfo> COMPARATOR =
|
|
|
Comparator.comparing(SnapshotInfo::startTime).thenComparing(SnapshotInfo::snapshotId);
|
|
|
|
|
|
- private static final class SnapshotInfoBuilder {
|
|
|
+ public static final class SnapshotInfoBuilder {
|
|
|
private String snapshotName = null;
|
|
|
private String snapshotUUID = null;
|
|
|
private String state = null;
|
|
@@ -137,23 +134,8 @@ public final class SnapshotInfo implements Comparable<SnapshotInfo>, ToXContent,
|
|
|
this.version = version;
|
|
|
}
|
|
|
|
|
|
- private void setShardFailures(XContentParser parser) {
|
|
|
- if (shardFailures == null) {
|
|
|
- shardFailures = new ArrayList<>();
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- if (parser.currentToken() == Token.START_ARRAY) {
|
|
|
- parser.nextToken();
|
|
|
- }
|
|
|
-
|
|
|
- while (parser.currentToken() != Token.END_ARRAY) {
|
|
|
- shardFailures.add(SnapshotShardFailure.fromXContent(parser));
|
|
|
- parser.nextToken();
|
|
|
- }
|
|
|
- } catch (IOException exception) {
|
|
|
- throw new UncheckedIOException(exception);
|
|
|
- }
|
|
|
+ private void setShardFailures(List<SnapshotShardFailure> shardFailures) {
|
|
|
+ this.shardFailures = shardFailures;
|
|
|
}
|
|
|
|
|
|
private void ignoreVersion(String version) {
|
|
@@ -172,7 +154,7 @@ public final class SnapshotInfo implements Comparable<SnapshotInfo>, ToXContent,
|
|
|
// ignore extra field
|
|
|
}
|
|
|
|
|
|
- private SnapshotInfo build() {
|
|
|
+ public SnapshotInfo build() {
|
|
|
SnapshotId snapshotId = new SnapshotId(snapshotName, snapshotUUID);
|
|
|
|
|
|
if (indices == null) {
|
|
@@ -219,11 +201,11 @@ public final class SnapshotInfo implements Comparable<SnapshotInfo>, ToXContent,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static final ObjectParser<SnapshotInfoBuilder, Void> SNAPSHOT_INFO_PARSER =
|
|
|
- new ObjectParser<>(SnapshotInfoBuilder.class.getName(), SnapshotInfoBuilder::new);
|
|
|
+ public static final ObjectParser<SnapshotInfoBuilder, Void> SNAPSHOT_INFO_PARSER =
|
|
|
+ new ObjectParser<>(SnapshotInfoBuilder.class.getName(), true, SnapshotInfoBuilder::new);
|
|
|
|
|
|
private static final ObjectParser<ShardStatsBuilder, Void> SHARD_STATS_PARSER =
|
|
|
- new ObjectParser<>(ShardStatsBuilder.class.getName(), ShardStatsBuilder::new);
|
|
|
+ new ObjectParser<>(ShardStatsBuilder.class.getName(), true, ShardStatsBuilder::new);
|
|
|
|
|
|
static {
|
|
|
SNAPSHOT_INFO_PARSER.declareString(SnapshotInfoBuilder::setSnapshotName, new ParseField(SNAPSHOT));
|
|
@@ -236,8 +218,8 @@ public final class SnapshotInfo implements Comparable<SnapshotInfo>, ToXContent,
|
|
|
SNAPSHOT_INFO_PARSER.declareObject(SnapshotInfoBuilder::setShardStatsBuilder, SHARD_STATS_PARSER, new ParseField(SHARDS));
|
|
|
SNAPSHOT_INFO_PARSER.declareBoolean(SnapshotInfoBuilder::setIncludeGlobalState, new ParseField(INCLUDE_GLOBAL_STATE));
|
|
|
SNAPSHOT_INFO_PARSER.declareInt(SnapshotInfoBuilder::setVersion, new ParseField(VERSION_ID));
|
|
|
- SNAPSHOT_INFO_PARSER.declareField(
|
|
|
- SnapshotInfoBuilder::setShardFailures, parser -> parser, new ParseField(FAILURES), ValueType.OBJECT_ARRAY_OR_STRING);
|
|
|
+ SNAPSHOT_INFO_PARSER.declareObjectArray(SnapshotInfoBuilder::setShardFailures, SnapshotShardFailure.SNAPSHOT_SHARD_FAILURE_PARSER,
|
|
|
+ new ParseField(FAILURES));
|
|
|
SNAPSHOT_INFO_PARSER.declareString(SnapshotInfoBuilder::ignoreVersion, new ParseField(VERSION));
|
|
|
SNAPSHOT_INFO_PARSER.declareString(SnapshotInfoBuilder::ignoreStartTime, new ParseField(START_TIME));
|
|
|
SNAPSHOT_INFO_PARSER.declareString(SnapshotInfoBuilder::ignoreEndTime, new ParseField(END_TIME));
|
|
@@ -521,7 +503,7 @@ public final class SnapshotInfo implements Comparable<SnapshotInfo>, ToXContent,
|
|
|
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
|
|
|
// write snapshot info to repository snapshot blob format
|
|
|
if (CONTEXT_MODE_SNAPSHOT.equals(params.param(CONTEXT_MODE_PARAM))) {
|
|
|
- return toXContentSnapshot(builder, params);
|
|
|
+ return toXContentInternal(builder, params);
|
|
|
}
|
|
|
|
|
|
final boolean verbose = params.paramAsBoolean("verbose", GetSnapshotsRequest.DEFAULT_VERBOSE_MODE);
|
|
@@ -576,7 +558,7 @@ public final class SnapshotInfo implements Comparable<SnapshotInfo>, ToXContent,
|
|
|
return builder;
|
|
|
}
|
|
|
|
|
|
- private XContentBuilder toXContentSnapshot(final XContentBuilder builder, final ToXContent.Params params) throws IOException {
|
|
|
+ private XContentBuilder toXContentInternal(final XContentBuilder builder, final ToXContent.Params params) throws IOException {
|
|
|
builder.startObject(SNAPSHOT);
|
|
|
builder.field(NAME, snapshotId.getName());
|
|
|
builder.field(UUID, snapshotId.getUUID());
|
|
@@ -609,22 +591,12 @@ public final class SnapshotInfo implements Comparable<SnapshotInfo>, ToXContent,
|
|
|
return builder;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * This method creates a SnapshotInfo from external x-content. It does not
|
|
|
+ * handle x-content written with the internal version.
|
|
|
+ */
|
|
|
public static SnapshotInfo fromXContent(final XContentParser parser) throws IOException {
|
|
|
- parser.nextToken(); // // move to '{'
|
|
|
-
|
|
|
- if (parser.currentToken() != Token.START_OBJECT) {
|
|
|
- throw new IllegalArgumentException("unexpected token [" + parser.currentToken() + "], expected ['{']");
|
|
|
- }
|
|
|
-
|
|
|
- SnapshotInfo snapshotInfo = SNAPSHOT_INFO_PARSER.apply(parser, null).build();
|
|
|
-
|
|
|
- if (parser.currentToken() != Token.END_OBJECT) {
|
|
|
- throw new IllegalArgumentException("unexpected token [" + parser.currentToken() + "], expected ['}']");
|
|
|
- }
|
|
|
-
|
|
|
- parser.nextToken(); // move past '}'
|
|
|
-
|
|
|
- return snapshotInfo;
|
|
|
+ return SNAPSHOT_INFO_PARSER.parse(parser, null).build();
|
|
|
}
|
|
|
|
|
|
/**
|