Skip to content

Commit 51b594f

Browse files
committed
Add promote data stream API to NEST (#5636)
* Add request and response types * Generate NEST code * Add URL tests
1 parent 91fc76e commit 51b594f

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
@@ -1080,6 +1080,27 @@ public OpenIndexDescriptor Index<TOther>()
10801080
public OpenIndexDescriptor WaitForActiveShards(string waitforactiveshards) => Qs("wait_for_active_shards", waitforactiveshards);
10811081
}
10821082

1083+
///<summary>Descriptor for PromoteDataStream <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</para></summary>
1084+
public partial class PromoteDataStreamDescriptor : RequestDescriptorBase<PromoteDataStreamDescriptor, PromoteDataStreamRequestParameters, IPromoteDataStreamRequest>, IPromoteDataStreamRequest
1085+
{
1086+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream;
1087+
///<summary>/_data_stream/_promote/{name}</summary>
1088+
///<param name = "name">this parameter is required</param>
1089+
public PromoteDataStreamDescriptor(Name name): base(r => r.Required("name", name))
1090+
{
1091+
}
1092+
1093+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
1094+
[SerializationConstructor]
1095+
protected PromoteDataStreamDescriptor(): base()
1096+
{
1097+
}
1098+
1099+
// values part of the url path
1100+
Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get<Name>("name");
1101+
// Request parameters
1102+
}
1103+
10831104
///<summary>Descriptor for PutAlias <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html</para></summary>
10841105
public partial class PutAliasDescriptor : RequestDescriptorBase<PutAliasDescriptor, PutAliasRequestParameters, IPutAliasRequest>, IPutAliasRequest
10851106
{

src/Nest/ElasticClient.Indices.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,30 @@ public Task<GetMappingResponse> GetMappingAsync<TDocument>(Func<GetMappingDescri
756756
/// </summary>
757757
public Task<OpenIndexResponse> OpenAsync(IOpenIndexRequest request, CancellationToken ct = default) => DoRequestAsync<IOpenIndexRequest, OpenIndexResponse>(request, request.RequestParameters, ct);
758758
/// <summary>
759+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
760+
/// <para></para>
761+
/// <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>
762+
/// </summary>
763+
public PromoteDataStreamResponse PromoteDataStream(Name name, Func<PromoteDataStreamDescriptor, IPromoteDataStreamRequest> selector = null) => PromoteDataStream(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name)));
764+
/// <summary>
765+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
766+
/// <para></para>
767+
/// <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>
768+
/// </summary>
769+
public Task<PromoteDataStreamResponse> PromoteDataStreamAsync(Name name, Func<PromoteDataStreamDescriptor, IPromoteDataStreamRequest> selector = null, CancellationToken ct = default) => PromoteDataStreamAsync(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name)), ct);
770+
/// <summary>
771+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
772+
/// <para></para>
773+
/// <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>
774+
/// </summary>
775+
public PromoteDataStreamResponse PromoteDataStream(IPromoteDataStreamRequest request) => DoRequest<IPromoteDataStreamRequest, PromoteDataStreamResponse>(request, request.RequestParameters);
776+
/// <summary>
777+
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
778+
/// <para></para>
779+
/// <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>
780+
/// </summary>
781+
public Task<PromoteDataStreamResponse> PromoteDataStreamAsync(IPromoteDataStreamRequest request, CancellationToken ct = default) => DoRequestAsync<IPromoteDataStreamRequest, PromoteDataStreamResponse>(request, request.RequestParameters, ct);
782+
/// <summary>
759783
/// <c>PUT</c> request to the <c>indices.put_alias</c> API, read more about this API online:
760784
/// <para></para>
761785
/// <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
@@ -1929,6 +1929,39 @@ public string WaitForActiveShards
19291929
}
19301930
}
19311931

1932+
[InterfaceDataContract]
1933+
public partial interface IPromoteDataStreamRequest : IRequest<PromoteDataStreamRequestParameters>
1934+
{
1935+
[IgnoreDataMember]
1936+
Name Name
1937+
{
1938+
get;
1939+
}
1940+
}
1941+
1942+
///<summary>Request for PromoteDataStream <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</para></summary>
1943+
public partial class PromoteDataStreamRequest : PlainRequestBase<PromoteDataStreamRequestParameters>, IPromoteDataStreamRequest
1944+
{
1945+
protected IPromoteDataStreamRequest Self => this;
1946+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream;
1947+
///<summary>/_data_stream/_promote/{name}</summary>
1948+
///<param name = "name">this parameter is required</param>
1949+
public PromoteDataStreamRequest(Name name): base(r => r.Required("name", name))
1950+
{
1951+
}
1952+
1953+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
1954+
[SerializationConstructor]
1955+
protected PromoteDataStreamRequest(): base()
1956+
{
1957+
}
1958+
1959+
// values part of the url path
1960+
[IgnoreDataMember]
1961+
Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get<Name>("name");
1962+
// Request parameters
1963+
}
1964+
19321965
[InterfaceDataContract]
19331966
public partial interface IPutAliasRequest : IRequest<PutAliasRequestParameters>
19341967
{
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
@@ -154,6 +154,7 @@ internal static class ApiUrlsLookups
154154
internal static ApiUrls IndicesGetTemplate = new ApiUrls(new[]{"_template", "_template/{name}"});
155155
internal static ApiUrls IndicesMigrateToDataStream = new ApiUrls(new[]{"_data_stream/_migrate/{name}"});
156156
internal static ApiUrls IndicesOpen = new ApiUrls(new[]{"{index}/_open"});
157+
internal static ApiUrls IndicesPromoteDataStream = new ApiUrls(new[]{"_data_stream/_promote/{name}"});
157158
internal static ApiUrls IndicesPutAlias = new ApiUrls(new[]{"{index}/_alias/{name}"});
158159
internal static ApiUrls IndicesPutMapping = new ApiUrls(new[]{"{index}/_mapping"});
159160
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)