Skip to content

Commit 2ef4eee

Browse files
committed
Add WaitForSnapshot ILM lifecycle action (#4375)
Relates: #4341 This commit adds a wait_for_snapshot ILM lifecycle action (cherry picked from commit 9b024e2)
1 parent e6c6d93 commit 2ef4eee

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Nest
4+
{
5+
/// <summary>
6+
/// The Wait For Snapshot Action waits for defined SLM policy to be executed to ensure that snapshot of index exists before deletion.
7+
/// <para></para>
8+
/// Available in Elasticsearch 7.6.0+
9+
/// </summary>
10+
public interface IWaitForSnapshotLifecycleAction : ILifecycleAction
11+
{
12+
/// <summary>
13+
/// The Snapshot Lifecycle Management (SLM) policy name that this action should wait for
14+
/// </summary>
15+
[DataMember(Name = "policy")]
16+
string Policy { get; set; }
17+
}
18+
19+
/// <inheritdoc />
20+
public class WaitForSnapshotLifecycleAction : IWaitForSnapshotLifecycleAction
21+
{
22+
/// <inheritdoc />
23+
public string Policy { get; set; }
24+
}
25+
26+
/// <inheritdoc cref="IWaitForSnapshotLifecycleAction"/>
27+
public class WaitForSnapshotLifecycleActionDescriptor
28+
: DescriptorBase<WaitForSnapshotLifecycleActionDescriptor, IWaitForSnapshotLifecycleAction>, IWaitForSnapshotLifecycleAction
29+
{
30+
string IWaitForSnapshotLifecycleAction.Policy { get; set; }
31+
32+
/// <inheritdoc cref="IWaitForSnapshotLifecycleAction.Policy"/>
33+
public WaitForSnapshotLifecycleActionDescriptor Policy(string policy) => Assign(policy, (a, v) => a.Policy = policy);
34+
}
35+
}

src/Nest/XPack/Ilm/LifecycleActions.cs

+33
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,35 @@ public LifecycleActions() { }
1515

1616
public LifecycleActions(IDictionary<string, ILifecycleAction> container) : base(container) { }
1717

18+
/// <inheritdoc cref="IAllocateLifecycleAction"/>
1819
public void Add(IAllocateLifecycleAction action) => BackingDictionary.Add("allocate", action);
1920

21+
/// <inheritdoc cref="IDeleteLifecycleAction"/>
2022
public void Add(IDeleteLifecycleAction action) => BackingDictionary.Add("delete", action);
2123

24+
/// <inheritdoc cref="IForceMergeLifecycleAction"/>
2225
public void Add(IForceMergeLifecycleAction action) => BackingDictionary.Add("forcemerge", action);
2326

27+
/// <inheritdoc cref="IFreezeLifecycleAction"/>
2428
public void Add(IFreezeLifecycleAction action) => BackingDictionary.Add("freeze", action);
2529

30+
/// <inheritdoc cref="IReadOnlyLifecycleAction"/>
2631
public void Add(IReadOnlyLifecycleAction action) => BackingDictionary.Add("readonly", action);
2732

33+
/// <inheritdoc cref="IRolloverLifecycleAction"/>
2834
public void Add(IRolloverLifecycleAction action) => BackingDictionary.Add("rollover", action);
2935

36+
/// <inheritdoc cref="ISetPriorityLifecycleAction"/>
3037
public void Add(ISetPriorityLifecycleAction action) => BackingDictionary.Add("set_priority", action);
3138

39+
/// <inheritdoc cref="IShrinkLifecycleAction"/>
3240
public void Add(IShrinkLifecycleAction action) => BackingDictionary.Add("shrink", action);
3341

42+
/// <inheritdoc cref="IUnfollowLifecycleAction"/>
3443
public void Add(IUnfollowLifecycleAction action) => BackingDictionary.Add("unfollow", action);
44+
45+
/// <inheritdoc cref="IWaitForSnapshotLifecycleAction"/>
46+
public void Add(IWaitForSnapshotLifecycleAction action) => BackingDictionary.Add("wait_for_snapshot", action);
3547
}
3648

3749
internal class LifecycleActionsJsonFormatter : IJsonFormatter<ILifecycleActions>
@@ -47,6 +59,7 @@ internal class LifecycleActionsJsonFormatter : IJsonFormatter<ILifecycleActions>
4759
{ "set_priority", 6 },
4860
{ "shrink", 7 },
4961
{ "unfollow", 8 },
62+
{ "wait_for_snapshot", 9 },
5063
};
5164

5265
public ILifecycleActions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
@@ -104,6 +117,10 @@ public ILifecycleActions Deserialize(ref JsonReader reader, IJsonFormatterResolv
104117
lifecycleAction = formatterResolver.GetFormatter<UnfollowLifecycleAction>()
105118
.Deserialize(ref reader, formatterResolver);
106119
break;
120+
case 9:
121+
lifecycleAction = formatterResolver.GetFormatter<WaitForSnapshotLifecycleAction>()
122+
.Deserialize(ref reader, formatterResolver);
123+
break;
107124
}
108125

109126
lifecycles.Add(type.Utf8String(), lifecycleAction);
@@ -161,6 +178,9 @@ public void Serialize(ref JsonWriter writer, ILifecycleActions value, IJsonForma
161178
case "unfollow":
162179
Serialize<IUnfollowLifecycleAction>(ref writer, action.Value, formatterResolver);
163180
break;
181+
case "wait_for_snapshot":
182+
Serialize<IWaitForSnapshotLifecycleAction>(ref writer, action.Value, formatterResolver);
183+
break;
164184
default:
165185
DynamicObjectResolver.ExcludeNullCamelCase.GetFormatter<ILifecycleAction>()
166186
.Serialize(ref writer, action.Value, formatterResolver);
@@ -181,31 +201,44 @@ public class LifecycleActionsDescriptor : IsADictionaryDescriptorBase<LifecycleA
181201
{
182202
public LifecycleActionsDescriptor() : base(new LifecycleActions()) { }
183203

204+
/// <inheritdoc cref="IAllocateLifecycleAction"/>
184205
public LifecycleActionsDescriptor Allocate(Func<AllocateLifecycleActionDescriptor, IAllocateLifecycleAction> selector) =>
185206
Assign("allocate", selector.InvokeOrDefault(new AllocateLifecycleActionDescriptor()));
186207

208+
/// <inheritdoc cref="IDeleteLifecycleAction"/>
187209
public LifecycleActionsDescriptor Delete(Func<DeleteLifecycleActionDescriptor, IDeleteLifecycleAction> selector) =>
188210
Assign("delete", selector.InvokeOrDefault(new DeleteLifecycleActionDescriptor()));
189211

212+
/// <inheritdoc cref="IForceMergeLifecycleAction"/>
190213
public LifecycleActionsDescriptor ForceMerge(Func<ForceMergeLifecycleActionDescriptor, IForceMergeLifecycleAction> selector) =>
191214
Assign("forcemerge", selector.InvokeOrDefault(new ForceMergeLifecycleActionDescriptor()));
192215

216+
/// <inheritdoc cref="IFreezeLifecycleAction"/>
193217
public LifecycleActionsDescriptor Freeze(Func<FreezeLifecycleActionDescriptor, IFreezeLifecycleAction> selector) =>
194218
Assign("freeze", selector.InvokeOrDefault(new FreezeLifecycleActionDescriptor()));
195219

220+
/// <inheritdoc cref="IReadOnlyLifecycleAction"/>
196221
public LifecycleActionsDescriptor ReadOnly(Func<ReadOnlyLifecycleActionDescriptor, IReadOnlyLifecycleAction> selector) =>
197222
Assign("readonly", selector.InvokeOrDefault(new ReadOnlyLifecycleActionDescriptor()));
198223

224+
/// <inheritdoc cref="IRolloverLifecycleAction"/>
199225
public LifecycleActionsDescriptor Rollover(Func<RolloverLifecycleActionDescriptor, IRolloverLifecycleAction> selector) =>
200226
Assign("rollover", selector.InvokeOrDefault(new RolloverLifecycleActionDescriptor()));
201227

228+
/// <inheritdoc cref="ISetPriorityLifecycleAction"/>
202229
public LifecycleActionsDescriptor SetPriority(Func<SetPriorityLifecycleActionDescriptor, ISetPriorityLifecycleAction> selector) =>
203230
Assign("set_priority", selector.InvokeOrDefault(new SetPriorityLifecycleActionDescriptor()));
204231

232+
/// <inheritdoc cref="IShrinkLifecycleAction"/>
205233
public LifecycleActionsDescriptor Shrink(Func<ShrinkLifecycleActionDescriptor, IShrinkLifecycleAction> selector) =>
206234
Assign("shrink", selector.InvokeOrDefault(new ShrinkLifecycleActionDescriptor()));
207235

236+
/// <inheritdoc cref="IUnfollowLifecycleAction"/>
208237
public LifecycleActionsDescriptor Unfollow(Func<UnfollowLifecycleActionDescriptor, IUnfollowLifecycleAction> selector) =>
209238
Assign("unfollow", selector.InvokeOrDefault(new UnfollowLifecycleActionDescriptor()));
239+
240+
/// <inheritdoc cref="IWaitForSnapshotLifecycleAction"/>
241+
public LifecycleActionsDescriptor WaitForSnapshot(Func<WaitForSnapshotLifecycleActionDescriptor, IWaitForSnapshotLifecycleAction> selector) =>
242+
Assign("wait_for_snapshot", selector.InvokeOrDefault(new WaitForSnapshotLifecycleActionDescriptor()));
210243
}
211244
}

0 commit comments

Comments
 (0)