Skip to content

Commit 28444dd

Browse files
authored
Implement Snapshot Lifecycle Management APIs (#4126)
This commit implements the Snapshot Lifecycle APIs in both the high level and low level clients. Unit tests for URLs, integration tests for the SLM API flow. The slm.get_lifecycle JSON spec is patched so that policy_id is a list and the Ids type is used to model multiple ids.
1 parent 92ce48e commit 28444dd

32 files changed

+1239
-20
lines changed

src/CodeGeneration/ApiGenerator/Configuration/CodeConfiguration.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ public static class CodeConfiguration
4545
"monitoring.bulk.json",
4646
"snapshot.cleanup_repository.json",
4747
"ml.estimate_memory_usage.json",
48-
49-
"slm.delete_lifecycle.json",
50-
"slm.execute_lifecycle.json",
51-
"slm.get_lifecycle.json",
52-
"slm.put_lifecycle.json",
5348
};
5449

5550

src/CodeGeneration/ApiGenerator/Domain/Code/CsharpNames.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private static string CreateCSharpNamespace(string endpointNamespace)
8888
case "ccr": return "CrossClusterReplication";
8989
case "ml": return "MachineLearning";
9090
case "xpack": return "XPack";
91+
case "slm": return "SnapshotLifecycleManagement";
9192
default: return endpointNamespace.ToPascalCase();
9293
}
9394
}

src/CodeGeneration/ApiGenerator/Domain/Specification/UrlPart.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,37 +53,39 @@ public string HighLevelTypeName
5353
case "timestamp": return "Timestamp";
5454
case "index_metric": return "IndexMetrics";
5555
case "metric": return "Metrics";
56-
57-
case "node_id" when Type == "list":
56+
57+
case "node_id" when Type == "list":
5858
return "NodeIds";
59-
60-
case "fields" when Type == "list":
59+
60+
case "fields" when Type == "list":
6161
return "Fields";
62-
62+
6363
case "parent_task_id":
64-
case "task_id":
64+
case "task_id":
6565
return "TaskId";
66-
66+
6767
case "forecast_id":
6868
case "action_id":
6969
return "Ids";
70-
70+
7171
case "index":
7272
case "new_index":
73-
case "target":
73+
case "target":
7474
return Type == "string" ? "IndexName" : "Indices";
75-
75+
7676
case "watch_id":
7777
case "job_id":
7878
case "calendar_id":
7979
case "event_id":
8080
case "datafeed_id":
8181
case "snapshot_id":
8282
case "filter_id":
83-
case "policy_id":
84-
case "id":
83+
case "id":
8584
return "Id";
86-
85+
86+
case "policy_id":
87+
return Type == "string" ? "Id" : "Ids";
88+
8789
case "application":
8890
case "repository":
8991
case "snapshot":
@@ -96,8 +98,8 @@ public string HighLevelTypeName
9698
case "thread_pool_patterns":
9799
case "type":
98100
return Type == "string" ? "Name" : "Names";
99-
100-
101+
102+
101103
//This forces a compilation error post code generation as intended
102104
default: return Type + "_";
103105
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"slm.get_lifecycle":{
3+
"url":{
4+
"parts":{
5+
"policy_id":{
6+
"type":"list",
7+
"description":"Comma-separated list of snapshot lifecycle policies to retrieve"
8+
}
9+
}
10+
}
11+
}
12+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
2+
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
3+
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
4+
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
5+
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
6+
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
7+
// -----------------------------------------------
8+
//
9+
// This file is automatically generated
10+
// Please do not edit these files manually
11+
// Run the following in the root of the repos:
12+
//
13+
// *NIX : ./build.sh codegen
14+
// Windows : build.bat codegen
15+
//
16+
// -----------------------------------------------
17+
// ReSharper disable RedundantUsingDirective
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
21+
using System.Text;
22+
using System.Linq.Expressions;
23+
24+
// ReSharper disable once CheckNamespace
25+
namespace Elasticsearch.Net.Specification.SlmApi
26+
{
27+
///<summary>Request options for DeleteSnapshotLifecycle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-delete.html</para></summary>
28+
public class DeleteSnapshotLifecycleRequestParameters : RequestParameters<DeleteSnapshotLifecycleRequestParameters>
29+
{
30+
public override HttpMethod DefaultHttpMethod => HttpMethod.DELETE;
31+
}
32+
33+
///<summary>Request options for ExecuteSnapshotLifecycle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-execute.html</para></summary>
34+
public class ExecuteSnapshotLifecycleRequestParameters : RequestParameters<ExecuteSnapshotLifecycleRequestParameters>
35+
{
36+
public override HttpMethod DefaultHttpMethod => HttpMethod.PUT;
37+
}
38+
39+
///<summary>Request options for GetSnapshotLifecycle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-get.html</para></summary>
40+
public class GetSnapshotLifecycleRequestParameters : RequestParameters<GetSnapshotLifecycleRequestParameters>
41+
{
42+
public override HttpMethod DefaultHttpMethod => HttpMethod.GET;
43+
}
44+
45+
///<summary>Request options for PutSnapshotLifecycle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-put.html</para></summary>
46+
public class PutSnapshotLifecycleRequestParameters : RequestParameters<PutSnapshotLifecycleRequestParameters>
47+
{
48+
public override HttpMethod DefaultHttpMethod => HttpMethod.PUT;
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
2+
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
3+
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
4+
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
5+
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
6+
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
7+
// -----------------------------------------------
8+
//
9+
// This file is automatically generated
10+
// Please do not edit these files manually
11+
// Run the following in the root of the repos:
12+
//
13+
// *NIX : ./build.sh codegen
14+
// Windows : build.bat codegen
15+
//
16+
// -----------------------------------------------
17+
// ReSharper disable RedundantUsingDirective
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
21+
using System.Text;
22+
using System.Linq.Expressions;
23+
24+
// ReSharper disable once CheckNamespace
25+
namespace Elasticsearch.Net.Specification.SnapshotLifecycleManagementApi
26+
{
27+
///<summary>Request options for DeleteSnapshotLifecycle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-delete.html</para></summary>
28+
public class DeleteSnapshotLifecycleRequestParameters : RequestParameters<DeleteSnapshotLifecycleRequestParameters>
29+
{
30+
public override HttpMethod DefaultHttpMethod => HttpMethod.DELETE;
31+
}
32+
33+
///<summary>Request options for ExecuteSnapshotLifecycle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-execute.html</para></summary>
34+
public class ExecuteSnapshotLifecycleRequestParameters : RequestParameters<ExecuteSnapshotLifecycleRequestParameters>
35+
{
36+
public override HttpMethod DefaultHttpMethod => HttpMethod.PUT;
37+
}
38+
39+
///<summary>Request options for GetSnapshotLifecycle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-get.html</para></summary>
40+
public class GetSnapshotLifecycleRequestParameters : RequestParameters<GetSnapshotLifecycleRequestParameters>
41+
{
42+
public override HttpMethod DefaultHttpMethod => HttpMethod.GET;
43+
}
44+
45+
///<summary>Request options for PutSnapshotLifecycle <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-put.html</para></summary>
46+
public class PutSnapshotLifecycleRequestParameters : RequestParameters<PutSnapshotLifecycleRequestParameters>
47+
{
48+
public override HttpMethod DefaultHttpMethod => HttpMethod.PUT;
49+
}
50+
}

src/Elasticsearch.Net/ElasticLowLevelClient.NoNamespace.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
using Elasticsearch.Net.Specification.RollupApi;
3838
using Elasticsearch.Net.Specification.SecurityApi;
3939
using Elasticsearch.Net.Specification.SnapshotApi;
40+
using Elasticsearch.Net.Specification.SnapshotLifecycleManagementApi;
4041
using Elasticsearch.Net.Specification.SqlApi;
4142
using Elasticsearch.Net.Specification.TasksApi;
4243
using Elasticsearch.Net.Specification.WatcherApi;
@@ -136,6 +137,12 @@ public LowLevelSnapshotNamespace Snapshot
136137
private set;
137138
}
138139

140+
public LowLevelSnapshotLifecycleManagementNamespace SnapshotLifecycleManagement
141+
{
142+
get;
143+
private set;
144+
}
145+
139146
public LowLevelSqlNamespace Sql
140147
{
141148
get;
@@ -176,6 +183,7 @@ partial void SetupNamespaces()
176183
Rollup = new LowLevelRollupNamespace(this);
177184
Security = new LowLevelSecurityNamespace(this);
178185
Snapshot = new LowLevelSnapshotNamespace(this);
186+
SnapshotLifecycleManagement = new LowLevelSnapshotLifecycleManagementNamespace(this);
179187
Sql = new LowLevelSqlNamespace(this);
180188
Tasks = new LowLevelTasksNamespace(this);
181189
Watcher = new LowLevelWatcherNamespace(this);
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
2+
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
3+
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
4+
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
5+
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
6+
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
7+
// -----------------------------------------------
8+
//
9+
// This file is automatically generated
10+
// Please do not edit these files manually
11+
// Run the following in the root of the repos:
12+
//
13+
// *NIX : ./build.sh codegen
14+
// Windows : build.bat codegen
15+
//
16+
// -----------------------------------------------
17+
// ReSharper disable RedundantUsingDirective
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Collections.Specialized;
21+
using System.Linq;
22+
using System.Text;
23+
using System.Threading;
24+
using System.Threading.Tasks;
25+
using Elasticsearch.Net;
26+
using static Elasticsearch.Net.HttpMethod;
27+
28+
// ReSharper disable InterpolatedStringExpressionIsNotIFormattable
29+
// ReSharper disable once CheckNamespace
30+
// ReSharper disable InterpolatedStringExpressionIsNotIFormattable
31+
// ReSharper disable RedundantExtendsListEntry
32+
namespace Elasticsearch.Net.Specification.SnapshotLifecycleManagementApi
33+
{
34+
///<summary>
35+
/// Snapshot Lifecycle Management APIs.
36+
/// <para>Not intended to be instantiated directly. Use the <see cref = "IElasticLowLevelClient.SnapshotLifecycleManagement"/> property
37+
/// on <see cref = "IElasticLowLevelClient"/>.
38+
///</para>
39+
///</summary>
40+
public class LowLevelSnapshotLifecycleManagementNamespace : NamespacedClientProxy
41+
{
42+
internal LowLevelSnapshotLifecycleManagementNamespace(ElasticLowLevelClient client): base(client)
43+
{
44+
}
45+
46+
///<summary>DELETE on /_slm/policy/{policy_id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-delete.html</para></summary>
47+
///<param name = "policyId">The id of the snapshot lifecycle policy to remove</param>
48+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
49+
public TResponse DeleteSnapshotLifecycle<TResponse>(string policyId, DeleteSnapshotLifecycleRequestParameters requestParameters = null)
50+
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(DELETE, Url($"_slm/policy/{policyId:policyId}"), null, RequestParams(requestParameters));
51+
///<summary>DELETE on /_slm/policy/{policy_id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-delete.html</para></summary>
52+
///<param name = "policyId">The id of the snapshot lifecycle policy to remove</param>
53+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
54+
public Task<TResponse> DeleteSnapshotLifecycleAsync<TResponse>(string policyId, DeleteSnapshotLifecycleRequestParameters requestParameters = null, CancellationToken ctx = default)
55+
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(DELETE, Url($"_slm/policy/{policyId:policyId}"), ctx, null, RequestParams(requestParameters));
56+
///<summary>PUT on /_slm/policy/{policy_id}/_execute <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-execute.html</para></summary>
57+
///<param name = "policyId">The id of the snapshot lifecycle policy to be executed</param>
58+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
59+
public TResponse ExecuteSnapshotLifecycle<TResponse>(string policyId, ExecuteSnapshotLifecycleRequestParameters requestParameters = null)
60+
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(PUT, Url($"_slm/policy/{policyId:policyId}/_execute"), null, RequestParams(requestParameters));
61+
///<summary>PUT on /_slm/policy/{policy_id}/_execute <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-execute.html</para></summary>
62+
///<param name = "policyId">The id of the snapshot lifecycle policy to be executed</param>
63+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
64+
public Task<TResponse> ExecuteSnapshotLifecycleAsync<TResponse>(string policyId, ExecuteSnapshotLifecycleRequestParameters requestParameters = null, CancellationToken ctx = default)
65+
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(PUT, Url($"_slm/policy/{policyId:policyId}/_execute"), ctx, null, RequestParams(requestParameters));
66+
///<summary>GET on /_slm/policy/{policy_id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-get.html</para></summary>
67+
///<param name = "policyId">Comma-separated list of snapshot lifecycle policies to retrieve</param>
68+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
69+
public TResponse GetSnapshotLifecycle<TResponse>(string policyId, GetSnapshotLifecycleRequestParameters requestParameters = null)
70+
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(GET, Url($"_slm/policy/{policyId:policyId}"), null, RequestParams(requestParameters));
71+
///<summary>GET on /_slm/policy/{policy_id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-get.html</para></summary>
72+
///<param name = "policyId">Comma-separated list of snapshot lifecycle policies to retrieve</param>
73+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
74+
public Task<TResponse> GetSnapshotLifecycleAsync<TResponse>(string policyId, GetSnapshotLifecycleRequestParameters requestParameters = null, CancellationToken ctx = default)
75+
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(GET, Url($"_slm/policy/{policyId:policyId}"), ctx, null, RequestParams(requestParameters));
76+
///<summary>GET on /_slm/policy <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-get.html</para></summary>
77+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
78+
public TResponse GetSnapshotLifecycle<TResponse>(GetSnapshotLifecycleRequestParameters requestParameters = null)
79+
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(GET, "_slm/policy", null, RequestParams(requestParameters));
80+
///<summary>GET on /_slm/policy <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-get.html</para></summary>
81+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
82+
public Task<TResponse> GetSnapshotLifecycleAsync<TResponse>(GetSnapshotLifecycleRequestParameters requestParameters = null, CancellationToken ctx = default)
83+
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(GET, "_slm/policy", ctx, null, RequestParams(requestParameters));
84+
///<summary>PUT on /_slm/policy/{policy_id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-put.html</para></summary>
85+
///<param name = "policyId">The id of the snapshot lifecycle policy</param>
86+
///<param name = "body">The snapshot lifecycle policy definition to register</param>
87+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
88+
public TResponse PutSnapshotLifecycle<TResponse>(string policyId, PostData body, PutSnapshotLifecycleRequestParameters requestParameters = null)
89+
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(PUT, Url($"_slm/policy/{policyId:policyId}"), body, RequestParams(requestParameters));
90+
///<summary>PUT on /_slm/policy/{policy_id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-put.html</para></summary>
91+
///<param name = "policyId">The id of the snapshot lifecycle policy</param>
92+
///<param name = "body">The snapshot lifecycle policy definition to register</param>
93+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
94+
public Task<TResponse> PutSnapshotLifecycleAsync<TResponse>(string policyId, PostData body, PutSnapshotLifecycleRequestParameters requestParameters = null, CancellationToken ctx = default)
95+
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(PUT, Url($"_slm/policy/{policyId:policyId}"), ctx, body, RequestParams(requestParameters));
96+
}
97+
}

src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
using Elasticsearch.Net.Specification.RollupApi;
3838
using Elasticsearch.Net.Specification.SecurityApi;
3939
using Elasticsearch.Net.Specification.SnapshotApi;
40+
using Elasticsearch.Net.Specification.SnapshotLifecycleManagementApi;
4041
using Elasticsearch.Net.Specification.SqlApi;
4142
using Elasticsearch.Net.Specification.TasksApi;
4243
using Elasticsearch.Net.Specification.WatcherApi;
@@ -1069,6 +1070,12 @@ LowLevelSnapshotNamespace Snapshot
10691070
get;
10701071
}
10711072

1073+
///<summary>Snapshot Lifecycle Management APIs</summary>
1074+
LowLevelSnapshotLifecycleManagementNamespace SnapshotLifecycleManagement
1075+
{
1076+
get;
1077+
}
1078+
10721079
///<summary>Sql APIs</summary>
10731080
LowLevelSqlNamespace Sql
10741081
{

0 commit comments

Comments
 (0)