|
@@ -21,10 +21,12 @@ package org.elasticsearch.client.slm;
|
|
|
|
|
|
import org.elasticsearch.common.Nullable;
|
|
|
import org.elasticsearch.common.ParseField;
|
|
|
+import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
|
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
+import org.elasticsearch.snapshots.SnapshotId;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.Objects;
|
|
@@ -39,6 +41,7 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
|
|
|
static final ParseField LAST_FAILURE = new ParseField("last_failure");
|
|
|
static final ParseField NEXT_EXECUTION_MILLIS = new ParseField("next_execution_millis");
|
|
|
static final ParseField NEXT_EXECUTION = new ParseField("next_execution");
|
|
|
+ static final ParseField SNAPSHOT_IN_PROGRESS = new ParseField("in_progress");
|
|
|
|
|
|
private final SnapshotLifecyclePolicy policy;
|
|
|
private final long version;
|
|
@@ -48,6 +51,8 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
|
|
|
private final SnapshotInvocationRecord lastSuccess;
|
|
|
@Nullable
|
|
|
private final SnapshotInvocationRecord lastFailure;
|
|
|
+ @Nullable
|
|
|
+ private final SnapshotInProgress snapshotInProgress;
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public static final ConstructingObjectParser<SnapshotLifecyclePolicyMetadata, String> PARSER =
|
|
@@ -59,8 +64,9 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
|
|
|
SnapshotInvocationRecord lastSuccess = (SnapshotInvocationRecord) a[3];
|
|
|
SnapshotInvocationRecord lastFailure = (SnapshotInvocationRecord) a[4];
|
|
|
long nextExecution = (long) a[5];
|
|
|
+ SnapshotInProgress sip = (SnapshotInProgress) a[6];
|
|
|
|
|
|
- return new SnapshotLifecyclePolicyMetadata(policy, version, modifiedDate, lastSuccess, lastFailure, nextExecution);
|
|
|
+ return new SnapshotLifecyclePolicyMetadata(policy, version, modifiedDate, lastSuccess, lastFailure, nextExecution, sip);
|
|
|
});
|
|
|
|
|
|
static {
|
|
@@ -70,6 +76,7 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
|
|
|
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), SnapshotInvocationRecord::parse, LAST_SUCCESS);
|
|
|
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), SnapshotInvocationRecord::parse, LAST_FAILURE);
|
|
|
PARSER.declareLong(ConstructingObjectParser.constructorArg(), NEXT_EXECUTION_MILLIS);
|
|
|
+ PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), SnapshotInProgress::parse, SNAPSHOT_IN_PROGRESS);
|
|
|
}
|
|
|
|
|
|
public static SnapshotLifecyclePolicyMetadata parse(XContentParser parser, String id) {
|
|
@@ -78,13 +85,15 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
|
|
|
|
|
|
public SnapshotLifecyclePolicyMetadata(SnapshotLifecyclePolicy policy, long version, long modifiedDate,
|
|
|
SnapshotInvocationRecord lastSuccess, SnapshotInvocationRecord lastFailure,
|
|
|
- long nextExecution) {
|
|
|
+ long nextExecution,
|
|
|
+ @Nullable SnapshotInProgress snapshotInProgress) {
|
|
|
this.policy = policy;
|
|
|
this.version = version;
|
|
|
this.modifiedDate = modifiedDate;
|
|
|
this.lastSuccess = lastSuccess;
|
|
|
this.lastFailure = lastFailure;
|
|
|
this.nextExecution = nextExecution;
|
|
|
+ this.snapshotInProgress = snapshotInProgress;
|
|
|
}
|
|
|
|
|
|
public SnapshotLifecyclePolicy getPolicy() {
|
|
@@ -115,6 +124,11 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
|
|
|
return this.nextExecution;
|
|
|
}
|
|
|
|
|
|
+ @Nullable
|
|
|
+ public SnapshotInProgress getSnapshotInProgress() {
|
|
|
+ return this.snapshotInProgress;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
builder.startObject();
|
|
@@ -128,6 +142,9 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
|
|
|
builder.field(LAST_FAILURE.getPreferredName(), lastFailure);
|
|
|
}
|
|
|
builder.timeField(NEXT_EXECUTION_MILLIS.getPreferredName(), NEXT_EXECUTION.getPreferredName(), nextExecution);
|
|
|
+ if (snapshotInProgress != null) {
|
|
|
+ builder.field(SNAPSHOT_IN_PROGRESS.getPreferredName(), snapshotInProgress);
|
|
|
+ }
|
|
|
builder.endObject();
|
|
|
return builder;
|
|
|
}
|
|
@@ -154,4 +171,84 @@ public class SnapshotLifecyclePolicyMetadata implements ToXContentObject {
|
|
|
Objects.equals(nextExecution, other.nextExecution);
|
|
|
}
|
|
|
|
|
|
+ public static class SnapshotInProgress implements ToXContentObject {
|
|
|
+ private static final ParseField NAME = new ParseField("name");
|
|
|
+ private static final ParseField UUID = new ParseField("uuid");
|
|
|
+ private static final ParseField STATE = new ParseField("state");
|
|
|
+ private static final ParseField START_TIME = new ParseField("start_time_millis");
|
|
|
+ private static final ParseField FAILURE = new ParseField("failure");
|
|
|
+
|
|
|
+ private static final ConstructingObjectParser<SnapshotInProgress, Void> PARSER =
|
|
|
+ new ConstructingObjectParser<>("snapshot_in_progress", true, a -> {
|
|
|
+ SnapshotId id = new SnapshotId((String) a[0], (String) a[1]);
|
|
|
+ String state = (String) a[2];
|
|
|
+ long start = (long) a[3];
|
|
|
+ String failure = (String) a[4];
|
|
|
+ return new SnapshotInProgress(id, state, start, failure);
|
|
|
+ });
|
|
|
+
|
|
|
+ static {
|
|
|
+ PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME);
|
|
|
+ PARSER.declareString(ConstructingObjectParser.constructorArg(), UUID);
|
|
|
+ PARSER.declareString(ConstructingObjectParser.constructorArg(), STATE);
|
|
|
+ PARSER.declareLong(ConstructingObjectParser.constructorArg(), START_TIME);
|
|
|
+ PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), FAILURE);
|
|
|
+ }
|
|
|
+
|
|
|
+ private final SnapshotId snapshotId;
|
|
|
+ private final String state;
|
|
|
+ private final long startTime;
|
|
|
+ private final String failure;
|
|
|
+
|
|
|
+ public SnapshotInProgress(SnapshotId snapshotId, String state, long startTime, @Nullable String failure) {
|
|
|
+ this.snapshotId = snapshotId;
|
|
|
+ this.state = state;
|
|
|
+ this.startTime = startTime;
|
|
|
+ this.failure = failure;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SnapshotInProgress parse(XContentParser parser, String name) {
|
|
|
+ return PARSER.apply(parser, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
+ builder.startObject();
|
|
|
+ builder.field(NAME.getPreferredName(), snapshotId.getName());
|
|
|
+ builder.field(UUID.getPreferredName(), snapshotId.getUUID());
|
|
|
+ builder.field(STATE.getPreferredName(), state);
|
|
|
+ builder.timeField(START_TIME.getPreferredName(), "start_time", startTime);
|
|
|
+ if (failure != null) {
|
|
|
+ builder.field(FAILURE.getPreferredName(), failure);
|
|
|
+ }
|
|
|
+ builder.endObject();
|
|
|
+ return builder;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int hashCode() {
|
|
|
+ return Objects.hash(snapshotId, state, startTime, failure);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean equals(Object obj) {
|
|
|
+ if (obj == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (obj.getClass() != getClass()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ SnapshotInProgress other = (SnapshotInProgress) obj;
|
|
|
+ return Objects.equals(snapshotId, other.snapshotId) &&
|
|
|
+ Objects.equals(state, other.state) &&
|
|
|
+ startTime == other.startTime &&
|
|
|
+ Objects.equals(failure, other.failure);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return Strings.toString(this);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|