Skip to content

Commit 9aab60d

Browse files
authored
Add promote data stream API to NEST (#5636)
* Add request and response types * Generate NEST code * Add URL tests
1 parent 145a500 commit 9aab60d

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
@@ -1061,6 +1061,27 @@ public OpenIndexDescriptor Index<TOther>()
10611061
public OpenIndexDescriptor WaitForActiveShards(string waitforactiveshards) => Qs("wait_for_active_shards", waitforactiveshards);
10621062
}
10631063

1064+
///<summary>Descriptor for PromoteDataStream <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</para></summary>
1065+
public partial class PromoteDataStreamDescriptor : RequestDescriptorBase<PromoteDataStreamDescriptor, PromoteDataStreamRequestParameters, IPromoteDataStreamRequest>, IPromoteDataStreamRequest
1066+
{
1067+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream;
1068+
///<summary>/_data_stream/_promote/{name}</summary>
1069+
///<param name = "name">this parameter is required</param>
1070+
public PromoteDataStreamDescriptor(Name name): base(r => r.Required("name", name))
1071+
{
1072+
}
1073+
1074+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
1075+
[SerializationConstructor]
1076+
protected PromoteDataStreamDescriptor(): base()
1077+
{
1078+
}
1079+
1080+
// values part of the url path
1081+
Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get<Name>("name");
1082+
// Request parameters
1083+
}
1084+
10641085
///<summary>Descriptor for PutAlias <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html</para></summary>
10651086
public partial class PutAliasDescriptor : RequestDescriptorBase<PutAliasDescriptor, PutAliasRequestParameters, IPutAliasRequest>, IPutAliasRequest
10661087
{

src/Nest/ElasticClient.Indices.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,30 @@ public Task<GetMappingResponse> GetMappingAsync<TDocument>(Func<GetMappingDescri
737737
/// </summary>
738738
public Task<OpenIndexResponse> OpenAsync(IOpenIndexRequest request, CancellationToken ct = default) => DoRequestAsync<IOpenIndexRequest, OpenIndexResponse>(request, request.RequestParameters, ct);
739739
/// <summary>
740+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
741+
/// <para></para>
742+
/// <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>
743+
/// </summary>
744+
public PromoteDataStreamResponse PromoteDataStream(Name name, Func<PromoteDataStreamDescriptor, IPromoteDataStreamRequest> selector = null) => PromoteDataStream(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name)));
745+
/// <summary>
746+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
747+
/// <para></para>
748+
/// <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>
749+
/// </summary>
750+
public Task<PromoteDataStreamResponse> PromoteDataStreamAsync(Name name, Func<PromoteDataStreamDescriptor, IPromoteDataStreamRequest> selector = null, CancellationToken ct = default) => PromoteDataStreamAsync(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name)), ct);
751+
/// <summary>
752+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
753+
/// <para></para>
754+
/// <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>
755+
/// </summary>
756+
public PromoteDataStreamResponse PromoteDataStream(IPromoteDataStreamRequest request) => DoRequest<IPromoteDataStreamRequest, PromoteDataStreamResponse>(request, request.RequestParameters);
757+
/// <summary>
758+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
759+
/// <para></para>
760+
/// <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>
761+
/// </summary>
762+
public Task<PromoteDataStreamResponse> PromoteDataStreamAsync(IPromoteDataStreamRequest request, CancellationToken ct = default) => DoRequestAsync<IPromoteDataStreamRequest, PromoteDataStreamResponse>(request, request.RequestParameters, ct);
763+
/// <summary>
740764
/// <c>PUT</c> request to the <c>indices.put_alias</c> API, read more about this API online:
741765
/// <para></para>
742766
/// <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
@@ -1910,6 +1910,39 @@ public string WaitForActiveShards
19101910
}
19111911
}
19121912

1913+
[InterfaceDataContract]
1914+
public partial interface IPromoteDataStreamRequest : IRequest<PromoteDataStreamRequestParameters>
1915+
{
1916+
[IgnoreDataMember]
1917+
Name Name
1918+
{
1919+
get;
1920+
}
1921+
}
1922+
1923+
///<summary>Request for PromoteDataStream <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</para></summary>
1924+
public partial class PromoteDataStreamRequest : PlainRequestBase<PromoteDataStreamRequestParameters>, IPromoteDataStreamRequest
1925+
{
1926+
protected IPromoteDataStreamRequest Self => this;
1927+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream;
1928+
///<summary>/_data_stream/_promote/{name}</summary>
1929+
///<param name = "name">this parameter is required</param>
1930+
public PromoteDataStreamRequest(Name name): base(r => r.Required("name", name))
1931+
{
1932+
}
1933+
1934+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
1935+
[SerializationConstructor]
1936+
protected PromoteDataStreamRequest(): base()
1937+
{
1938+
}
1939+
1940+
// values part of the url path
1941+
[IgnoreDataMember]
1942+
Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get<Name>("name");
1943+
// Request parameters
1944+
}
1945+
19131946
[InterfaceDataContract]
19141947
public partial interface IPutAliasRequest : IRequest<PutAliasRequestParameters>
19151948
{
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
@@ -136,6 +136,7 @@ internal static class ApiUrlsLookups
136136
internal static ApiUrls IndicesGetTemplate = new ApiUrls(new[]{"_template", "_template/{name}"});
137137
internal static ApiUrls IndicesMigrateToDataStream = new ApiUrls(new[]{"_data_stream/_migrate/{name}"});
138138
internal static ApiUrls IndicesOpen = new ApiUrls(new[]{"{index}/_open"});
139+
internal static ApiUrls IndicesPromoteDataStream = new ApiUrls(new[]{"_data_stream/_promote/{name}"});
139140
internal static ApiUrls IndicesPutAlias = new ApiUrls(new[]{"{index}/_alias/{name}"});
140141
internal static ApiUrls IndicesPutMapping = new ApiUrls(new[]{"{index}/_mapping"});
141142
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)