|
@@ -21,14 +21,16 @@ package org.elasticsearch.action.admin.cluster.snapshots.create;
|
|
|
|
|
|
import org.elasticsearch.action.ActionResponse;
|
|
|
import org.elasticsearch.common.Nullable;
|
|
|
+import org.elasticsearch.common.ParseField;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
+import org.elasticsearch.common.xcontent.ObjectParser;
|
|
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
|
|
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 org.elasticsearch.snapshots.SnapshotInfo;
|
|
|
+import org.elasticsearch.snapshots.SnapshotInfo.SnapshotInfoBuilder;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.Objects;
|
|
@@ -38,6 +40,14 @@ import java.util.Objects;
|
|
|
*/
|
|
|
public class CreateSnapshotResponse extends ActionResponse implements ToXContentObject {
|
|
|
|
|
|
+ private static final ObjectParser<CreateSnapshotResponse, Void> PARSER =
|
|
|
+ new ObjectParser<>(CreateSnapshotResponse.class.getName(), true, CreateSnapshotResponse::new);
|
|
|
+
|
|
|
+ static {
|
|
|
+ PARSER.declareObject(CreateSnapshotResponse::setSnapshotInfoFromBuilder,
|
|
|
+ SnapshotInfo.SNAPSHOT_INFO_PARSER, new ParseField("snapshot"));
|
|
|
+ }
|
|
|
+
|
|
|
@Nullable
|
|
|
private SnapshotInfo snapshotInfo;
|
|
|
|
|
@@ -48,8 +58,8 @@ public class CreateSnapshotResponse extends ActionResponse implements ToXContent
|
|
|
CreateSnapshotResponse() {
|
|
|
}
|
|
|
|
|
|
- void setSnapshotInfo(SnapshotInfo snapshotInfo) {
|
|
|
- this.snapshotInfo = snapshotInfo;
|
|
|
+ private void setSnapshotInfoFromBuilder(SnapshotInfoBuilder snapshotInfoBuilder) {
|
|
|
+ this.snapshotInfo = snapshotInfoBuilder.build();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -101,38 +111,8 @@ public class CreateSnapshotResponse extends ActionResponse implements ToXContent
|
|
|
return builder;
|
|
|
}
|
|
|
|
|
|
- public static CreateSnapshotResponse fromXContent(XContentParser parser) throws IOException {
|
|
|
- CreateSnapshotResponse createSnapshotResponse = new CreateSnapshotResponse();
|
|
|
-
|
|
|
- parser.nextToken(); // move to '{'
|
|
|
-
|
|
|
- if (parser.currentToken() != Token.START_OBJECT) {
|
|
|
- throw new IllegalArgumentException("unexpected token [" + parser.currentToken() + "], expected ['{']");
|
|
|
- }
|
|
|
-
|
|
|
- parser.nextToken(); // move to 'snapshot' || 'accepted'
|
|
|
-
|
|
|
- if ("snapshot".equals(parser.currentName())) {
|
|
|
- createSnapshotResponse.snapshotInfo = SnapshotInfo.fromXContent(parser);
|
|
|
- } else if ("accepted".equals(parser.currentName())) {
|
|
|
- parser.nextToken(); // move to 'accepted' field value
|
|
|
-
|
|
|
- if (parser.booleanValue()) {
|
|
|
- // ensure accepted is a boolean value
|
|
|
- }
|
|
|
-
|
|
|
- parser.nextToken(); // move past 'true'/'false'
|
|
|
- } else {
|
|
|
- throw new IllegalArgumentException("unexpected token [" + parser.currentToken() + "] expected ['snapshot', 'accepted']");
|
|
|
- }
|
|
|
-
|
|
|
- if (parser.currentToken() != Token.END_OBJECT) {
|
|
|
- throw new IllegalArgumentException("unexpected token [" + parser.currentToken() + "], expected ['}']");
|
|
|
- }
|
|
|
-
|
|
|
- parser.nextToken(); // move past '}'
|
|
|
-
|
|
|
- return createSnapshotResponse;
|
|
|
+ public static CreateSnapshotResponse fromXContent(XContentParser parser) {
|
|
|
+ return PARSER.apply(parser, null);
|
|
|
}
|
|
|
|
|
|
@Override
|