Skip to content

Commit 0ddb54f

Browse files
committed
Include in-progress snapshot for a policy with get SLM policy API
addresses elastic/elasticsearch#45245
1 parent 28444dd commit 0ddb54f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/Nest/XPack/Slm/SnapshotLifecyclePolicyMetadata.cs

+32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.Serialization;
3+
using Elasticsearch.Net.Utf8Json;
34

45
namespace Nest
56
{
@@ -45,5 +46,36 @@ public class SnapshotLifecyclePolicyMetadata
4546
/// </summary>
4647
[DataMember(Name = "version")]
4748
public int Version { get; internal set; }
49+
50+
/// <summary>
51+
/// If a snapshot is currently in progress this will return information about the snapshot.
52+
/// </summary>
53+
[DataMember(Name = "in_progress")]
54+
public InProgressLifecycleSnapshot InProgress { get; internal set; }
55+
}
56+
57+
/// <summary>
58+
/// If a snapshot is in progress when calling the Get Snapshot Lifecycle metadata
59+
/// this will hold some minimal information about the in flight snapshot
60+
/// </summary>
61+
public class InProgressLifecycleSnapshot
62+
{
63+
/// <summary> The name of the snapshot currently being taken </summary>
64+
[DataMember(Name = "name")]
65+
public string Name { get; internal set; }
66+
67+
/// <summary> The UUI of the snapshot currently being taken </summary>
68+
[DataMember(Name = "uuid")]
69+
public string UUID { get; internal set; }
70+
71+
/// <summary> The state of the snapshot currently being taken </summary>
72+
[DataMember(Name = "state")]
73+
public string State { get; internal set; }
74+
75+
/// <summary> The start time of the snapshot currently being taken </summary>
76+
[DataMember(Name = "start_time_millis")]
77+
[JsonFormatter(typeof(DateTimeOffsetEpochMillisecondsFormatter))]
78+
public DateTimeOffset StartTime { get; internal set; }
79+
4880
}
4981
}

src/Tests/Tests/XPack/Slm/SlmApiTests.cs

+29
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class SlmApiTests : CoordinatedIntegrationTestBase<XPackCluster>
1919
private const string ExecuteSnapshotLifecycleStep = nameof(ExecuteSnapshotLifecycleStep);
2020
private const string GetAllSnapshotLifecycleStep = nameof(GetAllSnapshotLifecycleStep);
2121
private const string GetSnapshotLifecycleStep = nameof(GetSnapshotLifecycleStep);
22+
private const string GetSnapshotLifecycleAfterExecuteStep = nameof(GetSnapshotLifecycleAfterExecuteStep);
2223
private const string PutSnapshotLifecycleStep = nameof(PutSnapshotLifecycleStep);
2324

2425

@@ -101,6 +102,20 @@ public SlmApiTests(XPackCluster cluster, EndpointUsage usage) : base(new Coordin
101102
(v, c, r) => c.SnapshotLifecycleManagement.ExecuteSnapshotLifecycleAsync(r)
102103
)
103104
},
105+
{
106+
GetSnapshotLifecycleAfterExecuteStep, u =>
107+
u.Calls<GetSnapshotLifecycleDescriptor, GetSnapshotLifecycleRequest, IGetSnapshotLifecycleRequest, GetSnapshotLifecycleResponse>(
108+
v => new GetSnapshotLifecycleRequest(v)
109+
{
110+
Human = true
111+
},
112+
(v, d) => d.PolicyId(v).Human(),
113+
(v, c, f) => c.SnapshotLifecycleManagement.GetSnapshotLifecycle(f),
114+
(v, c, f) => c.SnapshotLifecycleManagement.GetSnapshotLifecycleAsync(f),
115+
(v, c, r) => c.SnapshotLifecycleManagement.GetSnapshotLifecycle(r),
116+
(v, c, r) => c.SnapshotLifecycleManagement.GetSnapshotLifecycleAsync(r)
117+
)
118+
},
104119
{
105120
DeleteSnapshotLifecycleStep, u =>
106121
u.Calls<DeleteSnapshotLifecycleDescriptor, DeleteSnapshotLifecycleRequest, IDeleteSnapshotLifecycleRequest,
@@ -161,6 +176,20 @@ [I] public async Task ExecuteSnapshotLifecycleResponse() => await Assert<Execute
161176
r.SnapshotName.Should().NotBeNull();
162177
});
163178

179+
[I] public async Task GetSnapshotLifeCycleAfterExecuteResponse() => await Assert<GetSnapshotLifecycleResponse>(GetSnapshotLifecycleAfterExecuteStep, (v, r) =>
180+
{
181+
r.IsValid.Should().BeTrue();
182+
r.Policies.Should().NotBeNull().And.HaveCount(1).And.ContainKey(v);
183+
184+
var metadata = r.Policies[v];
185+
metadata.InProgress.Should().NotBeNull();
186+
metadata.InProgress.Name.Should().NotBeNullOrWhiteSpace();
187+
metadata.InProgress.UUID.Should().NotBeNullOrWhiteSpace();
188+
metadata.InProgress.State.Should().NotBeNullOrWhiteSpace();
189+
metadata.InProgress.StartTime.Should().BeAfter(DateTimeOffset.MinValue);
190+
191+
});
192+
164193
[I] public async Task DeleteSnapshotLifecycleResponse() => await Assert<DeleteSnapshotLifecycleResponse>(DeleteSnapshotLifecycleStep,
165194
(v, r) =>
166195
{

0 commit comments

Comments
 (0)