Skip to content

Commit 3ce5340

Browse files
stevejgordongithub-actions[bot]
authored andcommitted
Add promote data stream API to NEST (#5636)
* Add request and response types * Generate NEST code * Add URL tests
1 parent 9f5ae03 commit 3ce5340

File tree

7 files changed

+129
-0
lines changed

7 files changed

+129
-0
lines changed

src/Nest/Descriptors.Indices.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,27 @@ public OpenIndexDescriptor Index<TOther>()
10111011
public OpenIndexDescriptor WaitForActiveShards(string waitforactiveshards) => Qs("wait_for_active_shards", waitforactiveshards);
10121012
}
10131013

1014+
///<summary>Descriptor for PromoteDataStream <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</para></summary>
1015+
public partial class PromoteDataStreamDescriptor : RequestDescriptorBase<PromoteDataStreamDescriptor, PromoteDataStreamRequestParameters, IPromoteDataStreamRequest>, IPromoteDataStreamRequest
1016+
{
1017+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream;
1018+
///<summary>/_data_stream/_promote/{name}</summary>
1019+
///<param name = "name">this parameter is required</param>
1020+
public PromoteDataStreamDescriptor(Name name): base(r => r.Required("name", name))
1021+
{
1022+
}
1023+
1024+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
1025+
[SerializationConstructor]
1026+
protected PromoteDataStreamDescriptor(): base()
1027+
{
1028+
}
1029+
1030+
// values part of the url path
1031+
Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get<Name>("name");
1032+
// Request parameters
1033+
}
1034+
10141035
///<summary>Descriptor for PutAlias <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html</para></summary>
10151036
public partial class PutAliasDescriptor : RequestDescriptorBase<PutAliasDescriptor, PutAliasRequestParameters, IPutAliasRequest>, IPutAliasRequest
10161037
{

src/Nest/ElasticClient.Indices.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,30 @@ public Task<GetMappingResponse> GetMappingAsync<TDocument>(Func<GetMappingDescri
665665
/// </summary>
666666
public Task<OpenIndexResponse> OpenAsync(IOpenIndexRequest request, CancellationToken ct = default) => DoRequestAsync<IOpenIndexRequest, OpenIndexResponse>(request, request.RequestParameters, ct);
667667
/// <summary>
668+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
669+
/// <para></para>
670+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</a>
671+
/// </summary>
672+
public PromoteDataStreamResponse PromoteDataStream(Name name, Func<PromoteDataStreamDescriptor, IPromoteDataStreamRequest> selector = null) => PromoteDataStream(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name)));
673+
/// <summary>
674+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
675+
/// <para></para>
676+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</a>
677+
/// </summary>
678+
public Task<PromoteDataStreamResponse> PromoteDataStreamAsync(Name name, Func<PromoteDataStreamDescriptor, IPromoteDataStreamRequest> selector = null, CancellationToken ct = default) => PromoteDataStreamAsync(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name)), ct);
679+
/// <summary>
680+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
681+
/// <para></para>
682+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</a>
683+
/// </summary>
684+
public PromoteDataStreamResponse PromoteDataStream(IPromoteDataStreamRequest request) => DoRequest<IPromoteDataStreamRequest, PromoteDataStreamResponse>(request, request.RequestParameters);
685+
/// <summary>
686+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
687+
/// <para></para>
688+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</a>
689+
/// </summary>
690+
public Task<PromoteDataStreamResponse> PromoteDataStreamAsync(IPromoteDataStreamRequest request, CancellationToken ct = default) => DoRequestAsync<IPromoteDataStreamRequest, PromoteDataStreamResponse>(request, request.RequestParameters, ct);
691+
/// <summary>
668692
/// <c>PUT</c> request to the <c>indices.put_alias</c> API, read more about this API online:
669693
/// <para></para>
670694
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html</a>

src/Nest/Requests.Indices.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,39 @@ public string WaitForActiveShards
17651765
}
17661766
}
17671767

1768+
[InterfaceDataContract]
1769+
public partial interface IPromoteDataStreamRequest : IRequest<PromoteDataStreamRequestParameters>
1770+
{
1771+
[IgnoreDataMember]
1772+
Name Name
1773+
{
1774+
get;
1775+
}
1776+
}
1777+
1778+
///<summary>Request for PromoteDataStream <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</para></summary>
1779+
public partial class PromoteDataStreamRequest : PlainRequestBase<PromoteDataStreamRequestParameters>, IPromoteDataStreamRequest
1780+
{
1781+
protected IPromoteDataStreamRequest Self => this;
1782+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream;
1783+
///<summary>/_data_stream/_promote/{name}</summary>
1784+
///<param name = "name">this parameter is required</param>
1785+
public PromoteDataStreamRequest(Name name): base(r => r.Required("name", name))
1786+
{
1787+
}
1788+
1789+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
1790+
[SerializationConstructor]
1791+
protected PromoteDataStreamRequest(): base()
1792+
{
1793+
}
1794+
1795+
// values part of the url path
1796+
[IgnoreDataMember]
1797+
Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get<Name>("name");
1798+
// Request parameters
1799+
}
1800+
17681801
[InterfaceDataContract]
17691802
public partial interface IPutAliasRequest : IRequest<PutAliasRequestParameters>
17701803
{
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
namespace Nest
6+
{
7+
/// <summary>
8+
/// The purpose of the promote data stream api is to turn a data stream that is replicated by CCR into a regular data stream.
9+
/// </summary>
10+
[MapsApi("indices.promote_data_stream.json")]
11+
[ReadAs(typeof(PromoteDataStreamRequest))]
12+
public partial interface IPromoteDataStreamRequest
13+
{
14+
}
15+
16+
/// <inheritdoc cref="IPromoteDataStreamRequest"/>
17+
public partial class PromoteDataStreamRequest : IPromoteDataStreamRequest
18+
{
19+
}
20+
21+
/// <inheritdoc cref="IPromoteDataStreamRequest"/>
22+
public partial class PromoteDataStreamDescriptor
23+
{
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
namespace Nest
6+
{
7+
public class PromoteDataStreamResponse : AcknowledgedResponseBase { }
8+
}

src/Nest/_Generated/ApiUrlsLookup.generated.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ internal static class ApiUrlsLookups
133133
internal static ApiUrls IndicesGetSettings = new ApiUrls(new[]{"_settings", "{index}/_settings", "{index}/_settings/{name}", "_settings/{name}"});
134134
internal static ApiUrls IndicesGetTemplate = new ApiUrls(new[]{"_template", "_template/{name}"});
135135
internal static ApiUrls IndicesOpen = new ApiUrls(new[]{"{index}/_open"});
136+
internal static ApiUrls IndicesPromoteDataStream = new ApiUrls(new[]{"_data_stream/_promote/{name}"});
136137
internal static ApiUrls IndicesPutAlias = new ApiUrls(new[]{"{index}/_alias/{name}"});
137138
internal static ApiUrls IndicesPutMapping = new ApiUrls(new[]{"{index}/_mapping"});
138139
internal static ApiUrls IndicesUpdateSettings = new ApiUrls(new[]{"_settings", "{index}/_settings"});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Threading.Tasks;
2+
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
3+
using Nest;
4+
using Tests.Framework.EndpointTests;
5+
using static Tests.Framework.EndpointTests.UrlTester;
6+
7+
namespace Tests.XPack.DataStreams.Promote
8+
{
9+
public class PromoteDataStreamUrlTests : UrlTestsBase
10+
{
11+
[U] public override async Task Urls() => await POST("/_data_stream/_promote/stream")
12+
.Fluent(c => c.Indices.PromoteDataStream("stream", f => f))
13+
.Request(c => c.Indices.PromoteDataStream(new PromoteDataStreamRequest("stream")))
14+
.FluentAsync(c => c.Indices.PromoteDataStreamAsync("stream", f => f))
15+
.RequestAsync(c => c.Indices.PromoteDataStreamAsync(new PromoteDataStreamRequest("stream")));
16+
}
17+
}

0 commit comments

Comments
 (0)