Skip to content

Commit

Permalink
Add promote data stream API to NEST (#5636)
Browse files Browse the repository at this point in the history
* Add request and response types

* Generate NEST code

* Add URL tests
  • Loading branch information
stevejgordon committed Apr 27, 2021
1 parent 91fc76e commit 51b594f
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Nest/Descriptors.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,27 @@ public OpenIndexDescriptor Index<TOther>()
public OpenIndexDescriptor WaitForActiveShards(string waitforactiveshards) => Qs("wait_for_active_shards", waitforactiveshards);
}

///<summary>Descriptor for PromoteDataStream <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</para></summary>
public partial class PromoteDataStreamDescriptor : RequestDescriptorBase<PromoteDataStreamDescriptor, PromoteDataStreamRequestParameters, IPromoteDataStreamRequest>, IPromoteDataStreamRequest
{
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream;
///<summary>/_data_stream/_promote/{name}</summary>
///<param name = "name">this parameter is required</param>
public PromoteDataStreamDescriptor(Name name): base(r => r.Required("name", name))
{
}

///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
[SerializationConstructor]
protected PromoteDataStreamDescriptor(): base()
{
}

// values part of the url path
Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get<Name>("name");
// Request parameters
}

///<summary>Descriptor for PutAlias <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html</para></summary>
public partial class PutAliasDescriptor : RequestDescriptorBase<PutAliasDescriptor, PutAliasRequestParameters, IPutAliasRequest>, IPutAliasRequest
{
Expand Down
24 changes: 24 additions & 0 deletions src/Nest/ElasticClient.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,30 @@ public Task<GetMappingResponse> GetMappingAsync<TDocument>(Func<GetMappingDescri
/// </summary>
public Task<OpenIndexResponse> OpenAsync(IOpenIndexRequest request, CancellationToken ct = default) => DoRequestAsync<IOpenIndexRequest, OpenIndexResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
/// <para></para>
/// <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>
/// </summary>
public PromoteDataStreamResponse PromoteDataStream(Name name, Func<PromoteDataStreamDescriptor, IPromoteDataStreamRequest> selector = null) => PromoteDataStream(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name)));
/// <summary>
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
/// <para></para>
/// <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>
/// </summary>
public Task<PromoteDataStreamResponse> PromoteDataStreamAsync(Name name, Func<PromoteDataStreamDescriptor, IPromoteDataStreamRequest> selector = null, CancellationToken ct = default) => PromoteDataStreamAsync(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name)), ct);
/// <summary>
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
/// <para></para>
/// <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>
/// </summary>
public PromoteDataStreamResponse PromoteDataStream(IPromoteDataStreamRequest request) => DoRequest<IPromoteDataStreamRequest, PromoteDataStreamResponse>(request, request.RequestParameters);
/// <summary>
/// <c>POST</c> request to the <c>indices.promote_data_stream</c> API, read more about this API online:
/// <para></para>
/// <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>
/// </summary>
public Task<PromoteDataStreamResponse> PromoteDataStreamAsync(IPromoteDataStreamRequest request, CancellationToken ct = default) => DoRequestAsync<IPromoteDataStreamRequest, PromoteDataStreamResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>PUT</c> request to the <c>indices.put_alias</c> API, read more about this API online:
/// <para></para>
/// <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>
Expand Down
33 changes: 33 additions & 0 deletions src/Nest/Requests.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,39 @@ public string WaitForActiveShards
}
}

[InterfaceDataContract]
public partial interface IPromoteDataStreamRequest : IRequest<PromoteDataStreamRequestParameters>
{
[IgnoreDataMember]
Name Name
{
get;
}
}

///<summary>Request for PromoteDataStream <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html</para></summary>
public partial class PromoteDataStreamRequest : PlainRequestBase<PromoteDataStreamRequestParameters>, IPromoteDataStreamRequest
{
protected IPromoteDataStreamRequest Self => this;
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream;
///<summary>/_data_stream/_promote/{name}</summary>
///<param name = "name">this parameter is required</param>
public PromoteDataStreamRequest(Name name): base(r => r.Required("name", name))
{
}

///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
[SerializationConstructor]
protected PromoteDataStreamRequest(): base()
{
}

// values part of the url path
[IgnoreDataMember]
Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get<Name>("name");
// Request parameters
}

[InterfaceDataContract]
public partial interface IPutAliasRequest : IRequest<PutAliasRequestParameters>
{
Expand Down
25 changes: 25 additions & 0 deletions src/Nest/XPack/DataStreams/Promote/PromoteDataStreamRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Nest
{
/// <summary>
/// The purpose of the promote data stream api is to turn a data stream that is replicated by CCR into a regular data stream.
/// </summary>
[MapsApi("indices.promote_data_stream.json")]
[ReadAs(typeof(PromoteDataStreamRequest))]
public partial interface IPromoteDataStreamRequest
{
}

/// <inheritdoc cref="IPromoteDataStreamRequest"/>
public partial class PromoteDataStreamRequest : IPromoteDataStreamRequest
{
}

/// <inheritdoc cref="IPromoteDataStreamRequest"/>
public partial class PromoteDataStreamDescriptor
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Nest
{
public class PromoteDataStreamResponse : AcknowledgedResponseBase { }
}
1 change: 1 addition & 0 deletions src/Nest/_Generated/ApiUrlsLookup.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ internal static class ApiUrlsLookups
internal static ApiUrls IndicesGetTemplate = new ApiUrls(new[]{"_template", "_template/{name}"});
internal static ApiUrls IndicesMigrateToDataStream = new ApiUrls(new[]{"_data_stream/_migrate/{name}"});
internal static ApiUrls IndicesOpen = new ApiUrls(new[]{"{index}/_open"});
internal static ApiUrls IndicesPromoteDataStream = new ApiUrls(new[]{"_data_stream/_promote/{name}"});
internal static ApiUrls IndicesPutAlias = new ApiUrls(new[]{"{index}/_alias/{name}"});
internal static ApiUrls IndicesPutMapping = new ApiUrls(new[]{"{index}/_mapping"});
internal static ApiUrls IndicesUpdateSettings = new ApiUrls(new[]{"_settings", "{index}/_settings"});
Expand Down
17 changes: 17 additions & 0 deletions tests/Tests/XPack/DataStreams/Promote/PromoteDataStreamUrlTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Threading.Tasks;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using Nest;
using Tests.Framework.EndpointTests;
using static Tests.Framework.EndpointTests.UrlTester;

namespace Tests.XPack.DataStreams.Promote
{
public class PromoteDataStreamUrlTests : UrlTestsBase
{
[U] public override async Task Urls() => await POST("/_data_stream/_promote/stream")
.Fluent(c => c.Indices.PromoteDataStream("stream", f => f))
.Request(c => c.Indices.PromoteDataStream(new PromoteDataStreamRequest("stream")))
.FluentAsync(c => c.Indices.PromoteDataStreamAsync("stream", f => f))
.RequestAsync(c => c.Indices.PromoteDataStreamAsync(new PromoteDataStreamRequest("stream")));
}
}

0 comments on commit 51b594f

Please sign in to comment.