-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Record most recent snapshot policy success/failure #40619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gwbrown
merged 7 commits into
elastic:snapshot-lifecycle-management
from
gwbrown:slm/results-in-cluster-state
Apr 2, 2019
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
24c435c
Record most recent snapshot policy success/failure
gwbrown 1895dc1
Review feedback
gwbrown 134bc69
Fix NOCOMMIT
gwbrown 42e12b6
Review feedback
gwbrown 1f9ebd0
Merge branch 'snapshot-lifecycle-management' into slm/results-in-clus…
gwbrown fd95ea5
Adjust integration test to account for validation
gwbrown 37ef0a7
Merge branch 'snapshot-lifecycle-management' into slm/results-in-clus…
gwbrown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
...rc/main/java/org/elasticsearch/xpack/core/snapshotlifecycle/SnapshotInvocationRecord.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.snapshotlifecycle; | ||
|
||
import org.elasticsearch.cluster.AbstractDiffable; | ||
import org.elasticsearch.cluster.Diffable; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
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 java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Holds information about Snapshots kicked off by Snapshot Lifecycle Management in the cluster state, so that this information can be | ||
* presented to the user. This class is used for both successes and failures as the structure of the data is very similar. | ||
*/ | ||
public class SnapshotInvocationRecord extends AbstractDiffable<SnapshotInvocationRecord> | ||
implements Writeable, ToXContentObject, Diffable<SnapshotInvocationRecord> { | ||
|
||
static final ParseField SNAPSHOT_NAME = new ParseField("snapshot_name"); | ||
static final ParseField TIMESTAMP = new ParseField("time"); | ||
static final ParseField DETAILS = new ParseField("details"); | ||
|
||
private String snapshotName; | ||
private long timestamp; | ||
private String details; | ||
|
||
public static final ConstructingObjectParser<SnapshotInvocationRecord, String> PARSER = | ||
new ConstructingObjectParser<>("snapshot_policy_invocation_record", true, | ||
a -> new SnapshotInvocationRecord((String) a[0], (long) a[1], (String) a[2])); | ||
|
||
static { | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), SNAPSHOT_NAME); | ||
PARSER.declareLong(ConstructingObjectParser.constructorArg(), TIMESTAMP); | ||
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), DETAILS); | ||
} | ||
|
||
public static SnapshotInvocationRecord parse(XContentParser parser, String name) { | ||
return PARSER.apply(parser, name); | ||
} | ||
|
||
public SnapshotInvocationRecord(String snapshotName, long timestamp, String details) { | ||
this.snapshotName = Objects.requireNonNull(snapshotName, "snapshot name must be provided"); | ||
this.timestamp = timestamp; | ||
this.details = details; | ||
} | ||
|
||
public SnapshotInvocationRecord(StreamInput in) throws IOException { | ||
this.snapshotName = in.readString(); | ||
this.timestamp = in.readVLong(); | ||
this.details = in.readOptionalString(); | ||
} | ||
|
||
public String getSnapshotName() { | ||
return snapshotName; | ||
} | ||
|
||
public long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public String getDetails() { | ||
return details; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(snapshotName); | ||
out.writeVLong(timestamp); | ||
out.writeOptionalString(details); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
{ | ||
builder.field(SNAPSHOT_NAME.getPreferredName(), snapshotName); | ||
builder.timeField(TIMESTAMP.getPreferredName(), "time_string", timestamp); | ||
if (Objects.nonNull(details)) { | ||
builder.field(DETAILS.getPreferredName(), details); | ||
} | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
SnapshotInvocationRecord that = (SnapshotInvocationRecord) o; | ||
return getTimestamp() == that.getTimestamp() && | ||
Objects.equals(getSnapshotName(), that.getSnapshotName()) && | ||
Objects.equals(getDetails(), that.getDetails()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getSnapshotName(), getTimestamp(), getDetails()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.