Skip to content

Commit 07224df

Browse files
[Backport master] Add support for the migrate to data tiers API (#5825)
* Add support for the migrate to data tiers API (#5823) * Add empty request and response * Support migrate to data tiers API * Fixup Co-authored-by: Steve Gordon <sgordon@hotmail.co.uk>
1 parent 4dd78f1 commit 07224df

8 files changed

+220
-0
lines changed

src/Nest/Descriptors.IndexLifecycleManagement.cs

+12
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ public partial class GetIlmStatusDescriptor : RequestDescriptorBase<GetIlmStatus
123123
// Request parameters
124124
}
125125

126+
///<summary>Descriptor for MigrateToDataTiers <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-migrate-to-data-tiers.html</para></summary>
127+
public partial class MigrateToDataTiersDescriptor : RequestDescriptorBase<MigrateToDataTiersDescriptor, MigrateToDataTiersRequestParameters, IMigrateToDataTiersRequest>, IMigrateToDataTiersRequest
128+
{
129+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndexLifecycleManagementMigrateToDataTiers;
130+
protected override HttpMethod HttpMethod => HttpMethod.POST;
131+
protected override bool SupportsBody => true;
132+
// values part of the url path
133+
// Request parameters
134+
///<summary>If set to true it will simulate the migration, providing a way to retrieve the ILM policies and indices that need to be migrated. The default is false</summary>
135+
public MigrateToDataTiersDescriptor DryRun(bool? dryrun = true) => Qs("dry_run", dryrun);
136+
}
137+
126138
///<summary>Descriptor for MoveToStep <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html</para></summary>
127139
public partial class MoveToStepDescriptor : RequestDescriptorBase<MoveToStepDescriptor, MoveToStepRequestParameters, IMoveToStepRequest>, IMoveToStepRequest
128140
{

src/Nest/ElasticClient.IndexLifecycleManagement.cs

+24
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,30 @@ internal IndexLifecycleManagementNamespace(ElasticClient client): base(client)
136136
/// </summary>
137137
public Task<GetIlmStatusResponse> GetStatusAsync(IGetIlmStatusRequest request, CancellationToken ct = default) => DoRequestAsync<IGetIlmStatusRequest, GetIlmStatusResponse>(request, request.RequestParameters, ct);
138138
/// <summary>
139+
/// <c>POST</c> request to the <c>ilm.migrate_to_data_tiers</c> API, read more about this API online:
140+
/// <para></para>
141+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-migrate-to-data-tiers.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-migrate-to-data-tiers.html</a>
142+
/// </summary>
143+
public MigrateToDataTiersResponse MigrateToDataTiers(Func<MigrateToDataTiersDescriptor, IMigrateToDataTiersRequest> selector = null) => MigrateToDataTiers(selector.InvokeOrDefault(new MigrateToDataTiersDescriptor()));
144+
/// <summary>
145+
/// <c>POST</c> request to the <c>ilm.migrate_to_data_tiers</c> API, read more about this API online:
146+
/// <para></para>
147+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-migrate-to-data-tiers.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-migrate-to-data-tiers.html</a>
148+
/// </summary>
149+
public Task<MigrateToDataTiersResponse> MigrateToDataTiersAsync(Func<MigrateToDataTiersDescriptor, IMigrateToDataTiersRequest> selector = null, CancellationToken ct = default) => MigrateToDataTiersAsync(selector.InvokeOrDefault(new MigrateToDataTiersDescriptor()), ct);
150+
/// <summary>
151+
/// <c>POST</c> request to the <c>ilm.migrate_to_data_tiers</c> API, read more about this API online:
152+
/// <para></para>
153+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-migrate-to-data-tiers.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-migrate-to-data-tiers.html</a>
154+
/// </summary>
155+
public MigrateToDataTiersResponse MigrateToDataTiers(IMigrateToDataTiersRequest request) => DoRequest<IMigrateToDataTiersRequest, MigrateToDataTiersResponse>(request, request.RequestParameters);
156+
/// <summary>
157+
/// <c>POST</c> request to the <c>ilm.migrate_to_data_tiers</c> API, read more about this API online:
158+
/// <para></para>
159+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-migrate-to-data-tiers.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-migrate-to-data-tiers.html</a>
160+
/// </summary>
161+
public Task<MigrateToDataTiersResponse> MigrateToDataTiersAsync(IMigrateToDataTiersRequest request, CancellationToken ct = default) => DoRequestAsync<IMigrateToDataTiersRequest, MigrateToDataTiersResponse>(request, request.RequestParameters, ct);
162+
/// <summary>
139163
/// <c>POST</c> request to the <c>ilm.move_to_step</c> API, read more about this API online:
140164
/// <para></para>
141165
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html</a>

src/Nest/Requests.IndexLifecycleManagement.cs

+25
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,31 @@ public partial class GetIlmStatusRequest : PlainRequestBase<GetIlmStatusRequestP
168168
// Request parameters
169169
}
170170

171+
[InterfaceDataContract]
172+
public partial interface IMigrateToDataTiersRequest : IRequest<MigrateToDataTiersRequestParameters>
173+
{
174+
}
175+
176+
///<summary>Request for MigrateToDataTiers <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-migrate-to-data-tiers.html</para></summary>
177+
public partial class MigrateToDataTiersRequest : PlainRequestBase<MigrateToDataTiersRequestParameters>, IMigrateToDataTiersRequest
178+
{
179+
protected IMigrateToDataTiersRequest Self => this;
180+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndexLifecycleManagementMigrateToDataTiers;
181+
protected override HttpMethod HttpMethod => HttpMethod.POST;
182+
protected override bool SupportsBody => true;
183+
// values part of the url path
184+
// Request parameters
185+
///<summary>
186+
/// If set to true it will simulate the migration, providing a way to retrieve the ILM policies and indices that need to be migrated. The
187+
/// default is false
188+
///</summary>
189+
public bool? DryRun
190+
{
191+
get => Q<bool? >("dry_run");
192+
set => Q("dry_run", value);
193+
}
194+
}
195+
171196
[InterfaceDataContract]
172197
public partial interface IMoveToStepRequest : IRequest<MoveToStepRequestParameters>
173198
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Runtime.Serialization;
6+
7+
namespace Nest
8+
{
9+
[MapsApi("ilm.migrate_to_data_tiers")]
10+
[ReadAs(typeof(MigrateToDataTiersRequest))]
11+
public partial interface IMigrateToDataTiersRequest
12+
{
13+
/// <summary>
14+
/// The legacy index template name to delete. Defaults to none.
15+
/// </summary>
16+
[DataMember(Name = "legacy_template_to_delete")]
17+
string LegacyTemplateToDelete { get; set; }
18+
19+
/// <summary>
20+
/// The name of the custom node attribute used for the indices and ILM policies allocation filtering. Defaults to data.
21+
/// </summary>
22+
[DataMember(Name = "node_attribute")]
23+
string NodeAttribute { get; set; }
24+
}
25+
26+
/// <summary>
27+
/// Specifies properties for a migrate to data tiers request.
28+
/// </summary>
29+
public partial class MigrateToDataTiersRequest
30+
{
31+
/// <inheritdoc />
32+
public string LegacyTemplateToDelete { get; set; }
33+
34+
/// <inheritdoc />
35+
public string NodeAttribute { get; set; }
36+
}
37+
38+
public partial class MigrateToDataTiersDescriptor
39+
{
40+
string IMigrateToDataTiersRequest.LegacyTemplateToDelete { get; set; }
41+
string IMigrateToDataTiersRequest.NodeAttribute { get; set; }
42+
43+
/// <inheritdoc cref="IMigrateToDataTiersRequest.LegacyTemplateToDelete" />
44+
public MigrateToDataTiersDescriptor LegacyTemplateToDelete(string legacyTemplateToDelete) =>
45+
Assign(legacyTemplateToDelete, (a, v) => a.LegacyTemplateToDelete = v);
46+
47+
/// <inheritdoc cref="IMigrateToDataTiersRequest.NodeAttribute" />
48+
public MigrateToDataTiersDescriptor NodeAttribute(string nodeAttribute) => Assign(nodeAttribute, (a, v) => a.NodeAttribute = v);
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Collections.Generic;
6+
using System.Runtime.Serialization;
7+
8+
namespace Nest
9+
{
10+
/// <summary>
11+
/// The response from a migrate to data tiers request.
12+
/// </summary>
13+
public class MigrateToDataTiersResponse : ResponseBase
14+
{
15+
/// <summary>
16+
/// Whether the request was a dry run.
17+
/// </summary>
18+
[DataMember(Name = "dry_run")]
19+
public bool DryRun { get; internal set; }
20+
21+
/// <summary>
22+
/// The ILM policies that were updated.
23+
/// </summary>
24+
[DataMember(Name = "migrated_ilm_policies")]
25+
public IEnumerable<string> MigratedIlmPolicies { get; internal set; }
26+
27+
/// <summary>
28+
/// The indices that were migrated to tier preference routing.
29+
/// </summary>
30+
[DataMember(Name = "migrated_indices")]
31+
public IEnumerable<string> MigratedIndices { get; internal set; }
32+
33+
/// <summary>
34+
/// Shows the name of the legacy index template that was deleted. This will be missing if no legacy index template was
35+
/// deleted.
36+
/// </summary>
37+
[DataMember(Name = "removed_legacy_template")]
38+
public string RemovedLegacyTemplate { get; internal set; }
39+
}
40+
}

src/Nest/_Generated/ApiUrlsLookup.generated.cs

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ internal static class ApiUrlsLookups
107107
internal static ApiUrls IndexLifecycleManagementExplainLifecycle = new ApiUrls(new[]{"{index}/_ilm/explain"});
108108
internal static ApiUrls IndexLifecycleManagementGetLifecycle = new ApiUrls(new[]{"_ilm/policy/{policy_id}", "_ilm/policy"});
109109
internal static ApiUrls IndexLifecycleManagementGetStatus = new ApiUrls(new[]{"_ilm/status"});
110+
internal static ApiUrls IndexLifecycleManagementMigrateToDataTiers = new ApiUrls(new[]{"_ilm/migrate_to_data_tiers"});
110111
internal static ApiUrls IndexLifecycleManagementMoveToStep = new ApiUrls(new[]{"_ilm/move/{index}"});
111112
internal static ApiUrls IndexLifecycleManagementPutLifecycle = new ApiUrls(new[]{"_ilm/policy/{policy_id}"});
112113
internal static ApiUrls IndexLifecycleManagementRemovePolicy = new ApiUrls(new[]{"{index}/_ilm/remove"});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System;
6+
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
7+
using Elastic.Transport;
8+
using Nest;
9+
using Tests.Core.ManagedElasticsearch.Clusters;
10+
using Tests.Framework.EndpointTests;
11+
using Tests.Framework.EndpointTests.TestState;
12+
13+
namespace Tests.XPack.Ilm.MigrateToDataTiers
14+
{
15+
[SkipVersion("<7.14.0", "Migrate to data tiers added in 7.14.0")]
16+
public class MigrateToDataTiersApiTests
17+
: ApiTestBase<XPackCluster, MigrateToDataTiersResponse, IMigrateToDataTiersRequest, MigrateToDataTiersDescriptor, MigrateToDataTiersRequest>
18+
{
19+
public MigrateToDataTiersApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
20+
21+
protected override object ExpectJson =>
22+
new { legacy_template_to_delete = "template-name", node_attribute = "test-attribute" };
23+
24+
protected override Func<MigrateToDataTiersDescriptor, IMigrateToDataTiersRequest> Fluent => d => d
25+
.DryRun()
26+
.LegacyTemplateToDelete("template-name")
27+
.NodeAttribute("test-attribute");
28+
29+
protected override HttpMethod HttpMethod => HttpMethod.POST;
30+
31+
protected override MigrateToDataTiersRequest Initializer => new()
32+
{
33+
DryRun = true, LegacyTemplateToDelete = "template-name", NodeAttribute = "test-attribute"
34+
};
35+
36+
protected override string UrlPath => "/_ilm/migrate_to_data_tiers?dry_run=true";
37+
38+
protected override LazyResponses ClientUsage() => Calls(
39+
(client, f) => client.IndexLifecycleManagement.MigrateToDataTiers(f),
40+
(client, f) => client.IndexLifecycleManagement.MigrateToDataTiersAsync(f),
41+
(client, r) => client.IndexLifecycleManagement.MigrateToDataTiers(r),
42+
(client, r) => client.IndexLifecycleManagement.MigrateToDataTiersAsync(r)
43+
);
44+
45+
protected override MigrateToDataTiersDescriptor NewDescriptor() => new();
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Threading.Tasks;
6+
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
7+
using Tests.Framework.EndpointTests;
8+
using static Tests.Framework.EndpointTests.UrlTester;
9+
10+
namespace Tests.XPack.Ilm.MigrateToDataTiers
11+
{
12+
public class MigrateToDataTiersUrlRequests : UrlTestsBase
13+
{
14+
[U] public override async Task Urls() =>
15+
await POST("/_ilm/migrate_to_data_tiers")
16+
.Fluent(c => c.IndexLifecycleManagement.MigrateToDataTiers())
17+
.Request(c => c.IndexLifecycleManagement.MigrateToDataTiers())
18+
.FluentAsync(c => c.IndexLifecycleManagement.MigrateToDataTiersAsync())
19+
.RequestAsync(c => c.IndexLifecycleManagement.MigrateToDataTiersAsync());
20+
}
21+
}

0 commit comments

Comments
 (0)