Skip to content

Commit 6bf5167

Browse files
committed
Add promote data stream API to NEST (#5636)
* Add request and response types * Generate NEST code * Add URL tests
1 parent 0d5722d commit 6bf5167

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
@@ -1030,6 +1030,27 @@ public OpenIndexDescriptor Index<TOther>()
10301030
public OpenIndexDescriptor WaitForActiveShards(string waitforactiveshards) => Qs("wait_for_active_shards", waitforactiveshards);
10311031
}
10321032

1033+
///<summary>Descriptor for PromoteDataStream <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</para></summary>
1034+
public partial class PromoteDataStreamDescriptor : RequestDescriptorBase<PromoteDataStreamDescriptor, PromoteDataStreamRequestParameters, IPromoteDataStreamRequest>, IPromoteDataStreamRequest
1035+
{
1036+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream;
1037+
///<summary>/_data_stream/_promote/{name}</summary>
1038+
///<param name = "name">this parameter is required</param>
1039+
public PromoteDataStreamDescriptor(Name name): base(r => r.Required("name", name))
1040+
{
1041+
}
1042+
1043+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
1044+
[SerializationConstructor]
1045+
protected PromoteDataStreamDescriptor(): base()
1046+
{
1047+
}
1048+
1049+
// values part of the url path
1050+
Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get<Name>("name");
1051+
// Request parameters
1052+
}
1053+
10331054
///<summary>Descriptor for PutAlias <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html</para></summary>
10341055
public partial class PutAliasDescriptor : RequestDescriptorBase<PutAliasDescriptor, PutAliasRequestParameters, IPutAliasRequest>, IPutAliasRequest
10351056
{

src/Nest/ElasticClient.Indices.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,30 @@ public Task<GetMappingResponse> GetMappingAsync<TDocument>(Func<GetMappingDescri
684684
/// </summary>
685685
public Task<OpenIndexResponse> OpenAsync(IOpenIndexRequest request, CancellationToken ct = default) => DoRequestAsync<IOpenIndexRequest, OpenIndexResponse>(request, request.RequestParameters, ct);
686686
/// <summary>
687+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
688+
/// <para></para>
689+
/// <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>
690+
/// </summary>
691+
public PromoteDataStreamResponse PromoteDataStream(Name name, Func<PromoteDataStreamDescriptor, IPromoteDataStreamRequest> selector = null) => PromoteDataStream(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name)));
692+
/// <summary>
693+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
694+
/// <para></para>
695+
/// <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>
696+
/// </summary>
697+
public Task<PromoteDataStreamResponse> PromoteDataStreamAsync(Name name, Func<PromoteDataStreamDescriptor, IPromoteDataStreamRequest> selector = null, CancellationToken ct = default) => PromoteDataStreamAsync(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name)), ct);
698+
/// <summary>
699+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
700+
/// <para></para>
701+
/// <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>
702+
/// </summary>
703+
public PromoteDataStreamResponse PromoteDataStream(IPromoteDataStreamRequest request) => DoRequest<IPromoteDataStreamRequest, PromoteDataStreamResponse>(request, request.RequestParameters);
704+
/// <summary>
705+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
706+
/// <para></para>
707+
/// <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>
708+
/// </summary>
709+
public Task<PromoteDataStreamResponse> PromoteDataStreamAsync(IPromoteDataStreamRequest request, CancellationToken ct = default) => DoRequestAsync<IPromoteDataStreamRequest, PromoteDataStreamResponse>(request, request.RequestParameters, ct);
710+
/// <summary>
687711
/// <c>PUT</c> request to the <c>indices.put_alias</c> API, read more about this API online:
688712
/// <para></para>
689713
/// <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
@@ -1784,6 +1784,39 @@ public string WaitForActiveShards
17841784
}
17851785
}
17861786

1787+
[InterfaceDataContract]
1788+
public partial interface IPromoteDataStreamRequest : IRequest<PromoteDataStreamRequestParameters>
1789+
{
1790+
[IgnoreDataMember]
1791+
Name Name
1792+
{
1793+
get;
1794+
}
1795+
}
1796+
1797+
///<summary>Request for PromoteDataStream <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</para></summary>
1798+
public partial class PromoteDataStreamRequest : PlainRequestBase<PromoteDataStreamRequestParameters>, IPromoteDataStreamRequest
1799+
{
1800+
protected IPromoteDataStreamRequest Self => this;
1801+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream;
1802+
///<summary>/_data_stream/_promote/{name}</summary>
1803+
///<param name = "name">this parameter is required</param>
1804+
public PromoteDataStreamRequest(Name name): base(r => r.Required("name", name))
1805+
{
1806+
}
1807+
1808+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
1809+
[SerializationConstructor]
1810+
protected PromoteDataStreamRequest(): base()
1811+
{
1812+
}
1813+
1814+
// values part of the url path
1815+
[IgnoreDataMember]
1816+
Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get<Name>("name");
1817+
// Request parameters
1818+
}
1819+
17871820
[InterfaceDataContract]
17881821
public partial interface IPutAliasRequest : IRequest<PutAliasRequestParameters>
17891822
{
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
@@ -151,6 +151,7 @@ internal static class ApiUrlsLookups
151151
internal static ApiUrls IndicesGetSettings = new ApiUrls(new[]{"_settings", "{index}/_settings", "{index}/_settings/{name}", "_settings/{name}"});
152152
internal static ApiUrls IndicesGetTemplate = new ApiUrls(new[]{"_template", "_template/{name}"});
153153
internal static ApiUrls IndicesOpen = new ApiUrls(new[]{"{index}/_open"});
154+
internal static ApiUrls IndicesPromoteDataStream = new ApiUrls(new[]{"_data_stream/_promote/{name}"});
154155
internal static ApiUrls IndicesPutAlias = new ApiUrls(new[]{"{index}/_alias/{name}"});
155156
internal static ApiUrls IndicesPutMapping = new ApiUrls(new[]{"{index}/_mapping"});
156157
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)