Skip to content

[Backport master] Add promote data stream API to NEST #5638

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

Merged
merged 3 commits into from
Apr 27, 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
23 changes: 23 additions & 0 deletions src/Nest/Descriptors.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,29 @@ 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;
protected override HttpMethod HttpMethod => HttpMethod.POST;
protected override bool SupportsBody => false;
///<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 @@ -684,6 +684,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
35 changes: 35 additions & 0 deletions src/Nest/Requests.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,41 @@ 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;
protected override HttpMethod HttpMethod => HttpMethod.POST;
protected override bool SupportsBody => false;
///<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
40 changes: 40 additions & 0 deletions src/Nest/XPack/DataStreams/Promote/PromoteDataStreamRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

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
{
}
}
23 changes: 23 additions & 0 deletions src/Nest/XPack/DataStreams/Promote/PromoteDataStreamResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

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 @@ -151,6 +151,7 @@ internal static class ApiUrlsLookups
internal static ApiUrls IndicesGetSettings = new ApiUrls(new[]{"_settings", "{index}/_settings", "{index}/_settings/{name}", "_settings/{name}"});
internal static ApiUrls IndicesGetTemplate = new ApiUrls(new[]{"_template", "_template/{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
36 changes: 36 additions & 0 deletions tests/Tests/XPack/DataStreams/Promote/PromoteDataStreamUrlTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

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")));
}
}