Skip to content

Include in-progress snapshot for a policy with get SLM policy API #4141

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
merged 2 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Nest/XPack/Slm/SnapshotLifecyclePolicyMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.Serialization;
using Elasticsearch.Net.Utf8Json;

namespace Nest
{
Expand Down Expand Up @@ -45,5 +46,36 @@ public class SnapshotLifecyclePolicyMetadata
/// </summary>
[DataMember(Name = "version")]
public int Version { get; internal set; }

/// <summary>
/// If a snapshot is currently in progress this will return information about the snapshot.
/// </summary>
[DataMember(Name = "in_progress")]
public LifecycleSnapshotInProgress InProgress { get; internal set; }
}

/// <summary>
/// If a snapshot is in progress when calling the Get Snapshot Lifecycle metadata
/// this will hold some minimal information about the in flight snapshot
/// </summary>
public class LifecycleSnapshotInProgress
{
/// <summary> The name of the snapshot currently being taken </summary>
[DataMember(Name = "name")]
public string Name { get; internal set; }

/// <summary> The UUI of the snapshot currently being taken </summary>
[DataMember(Name = "uuid")]
public string UUID { get; internal set; }

/// <summary> The state of the snapshot currently being taken </summary>
[DataMember(Name = "state")]
public string State { get; internal set; }

/// <summary> The start time of the snapshot currently being taken </summary>
[DataMember(Name = "start_time_millis")]
[JsonFormatter(typeof(DateTimeOffsetEpochMillisecondsFormatter))]
public DateTimeOffset StartTime { get; internal set; }

}
}
29 changes: 29 additions & 0 deletions src/Tests/Tests/XPack/Slm/SlmApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class SlmApiTests : CoordinatedIntegrationTestBase<XPackCluster>
private const string ExecuteSnapshotLifecycleStep = nameof(ExecuteSnapshotLifecycleStep);
private const string GetAllSnapshotLifecycleStep = nameof(GetAllSnapshotLifecycleStep);
private const string GetSnapshotLifecycleStep = nameof(GetSnapshotLifecycleStep);
private const string GetSnapshotLifecycleAfterExecuteStep = nameof(GetSnapshotLifecycleAfterExecuteStep);
private const string PutSnapshotLifecycleStep = nameof(PutSnapshotLifecycleStep);


Expand Down Expand Up @@ -101,6 +102,20 @@ public SlmApiTests(XPackCluster cluster, EndpointUsage usage) : base(new Coordin
(v, c, r) => c.SnapshotLifecycleManagement.ExecuteSnapshotLifecycleAsync(r)
)
},
{
GetSnapshotLifecycleAfterExecuteStep, u =>
u.Calls<GetSnapshotLifecycleDescriptor, GetSnapshotLifecycleRequest, IGetSnapshotLifecycleRequest, GetSnapshotLifecycleResponse>(
v => new GetSnapshotLifecycleRequest(v)
{
Human = true
},
(v, d) => d.PolicyId(v).Human(),
(v, c, f) => c.SnapshotLifecycleManagement.GetSnapshotLifecycle(f),
(v, c, f) => c.SnapshotLifecycleManagement.GetSnapshotLifecycleAsync(f),
(v, c, r) => c.SnapshotLifecycleManagement.GetSnapshotLifecycle(r),
(v, c, r) => c.SnapshotLifecycleManagement.GetSnapshotLifecycleAsync(r)
)
},
{
DeleteSnapshotLifecycleStep, u =>
u.Calls<DeleteSnapshotLifecycleDescriptor, DeleteSnapshotLifecycleRequest, IDeleteSnapshotLifecycleRequest,
Expand Down Expand Up @@ -161,6 +176,20 @@ [I] public async Task ExecuteSnapshotLifecycleResponse() => await Assert<Execute
r.SnapshotName.Should().NotBeNull();
});

[I] public async Task GetSnapshotLifeCycleAfterExecuteResponse() => await Assert<GetSnapshotLifecycleResponse>(GetSnapshotLifecycleAfterExecuteStep, (v, r) =>
{
r.IsValid.Should().BeTrue();
r.Policies.Should().NotBeNull().And.HaveCount(1).And.ContainKey(v);

var metadata = r.Policies[v];
metadata.InProgress.Should().NotBeNull();
metadata.InProgress.Name.Should().NotBeNullOrWhiteSpace();
metadata.InProgress.UUID.Should().NotBeNullOrWhiteSpace();
metadata.InProgress.State.Should().NotBeNullOrWhiteSpace();
metadata.InProgress.StartTime.Should().BeAfter(DateTimeOffset.MinValue);

});

[I] public async Task DeleteSnapshotLifecycleResponse() => await Assert<DeleteSnapshotLifecycleResponse>(DeleteSnapshotLifecycleStep,
(v, r) =>
{
Expand Down