Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add promote data stream API to NEST #5636

Merged
merged 3 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Nest/Descriptors.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,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 @@ -737,6 +737,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 @@ -1910,6 +1910,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 @@ -136,6 +136,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")));
}
}