Skip to content

Commit cf2e2ed

Browse files
[Backport 7.x] Add promote data stream API to NEST (#5637)
* Add promote data stream API to NEST (#5636) * Add request and response types * Generate NEST code * Add URL tests * Update license headers * Update license header Co-authored-by: Steve Gordon <sgordon@hotmail.co.uk>
1 parent a9a19be commit cf2e2ed

File tree

7 files changed

+178
-0
lines changed

7 files changed

+178
-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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
namespace Nest
21+
{
22+
/// <summary>
23+
/// The purpose of the promote data stream api is to turn a data stream that is replicated by CCR into a regular data stream.
24+
/// </summary>
25+
[MapsApi("indices.promote_data_stream.json")]
26+
[ReadAs(typeof(PromoteDataStreamRequest))]
27+
public partial interface IPromoteDataStreamRequest
28+
{
29+
}
30+
31+
/// <inheritdoc cref="IPromoteDataStreamRequest"/>
32+
public partial class PromoteDataStreamRequest : IPromoteDataStreamRequest
33+
{
34+
}
35+
36+
/// <inheritdoc cref="IPromoteDataStreamRequest"/>
37+
public partial class PromoteDataStreamDescriptor
38+
{
39+
}
40+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
namespace Nest
21+
{
22+
public class PromoteDataStreamResponse : AcknowledgedResponseBase { }
23+
}

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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
using System.Threading.Tasks;
21+
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
22+
using Nest;
23+
using Tests.Framework.EndpointTests;
24+
using static Tests.Framework.EndpointTests.UrlTester;
25+
26+
namespace Tests.XPack.DataStreams.Promote
27+
{
28+
public class PromoteDataStreamUrlTests : UrlTestsBase
29+
{
30+
[U] public override async Task Urls() => await POST("/_data_stream/_promote/stream")
31+
.Fluent(c => c.Indices.PromoteDataStream("stream", f => f))
32+
.Request(c => c.Indices.PromoteDataStream(new PromoteDataStreamRequest("stream")))
33+
.FluentAsync(c => c.Indices.PromoteDataStreamAsync("stream", f => f))
34+
.RequestAsync(c => c.Indices.PromoteDataStreamAsync(new PromoteDataStreamRequest("stream")));
35+
}
36+
}

0 commit comments

Comments
 (0)