From 6bf5167e5219e9be508ba7f41e2f2762d6e05b38 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Mon, 26 Apr 2021 10:42:52 +0100 Subject: [PATCH 1/3] Add promote data stream API to NEST (#5636) * Add request and response types * Generate NEST code * Add URL tests --- src/Nest/Descriptors.Indices.cs | 21 ++++++++++++ src/Nest/ElasticClient.Indices.cs | 24 ++++++++++++++ src/Nest/Requests.Indices.cs | 33 +++++++++++++++++++ .../Promote/PromoteDataStreamRequest.cs | 25 ++++++++++++++ .../Promote/PromoteDataStreamResponse.cs | 8 +++++ .../_Generated/ApiUrlsLookup.generated.cs | 1 + .../Promote/PromoteDataStreamUrlTests.cs | 17 ++++++++++ 7 files changed, 129 insertions(+) create mode 100644 src/Nest/XPack/DataStreams/Promote/PromoteDataStreamRequest.cs create mode 100644 src/Nest/XPack/DataStreams/Promote/PromoteDataStreamResponse.cs create mode 100644 tests/Tests/XPack/DataStreams/Promote/PromoteDataStreamUrlTests.cs diff --git a/src/Nest/Descriptors.Indices.cs b/src/Nest/Descriptors.Indices.cs index 63047b5366f..fa43318712e 100644 --- a/src/Nest/Descriptors.Indices.cs +++ b/src/Nest/Descriptors.Indices.cs @@ -1030,6 +1030,27 @@ public OpenIndexDescriptor Index() public OpenIndexDescriptor WaitForActiveShards(string waitforactiveshards) => Qs("wait_for_active_shards", waitforactiveshards); } + ///Descriptor for PromoteDataStream https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + public partial class PromoteDataStreamDescriptor : RequestDescriptorBase, IPromoteDataStreamRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream; + ////_data_stream/_promote/{name} + ///this parameter is required + public PromoteDataStreamDescriptor(Name name): base(r => r.Required("name", name)) + { + } + + ///Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected PromoteDataStreamDescriptor(): base() + { + } + + // values part of the url path + Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get("name"); + // Request parameters + } + ///Descriptor for PutAlias https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html public partial class PutAliasDescriptor : RequestDescriptorBase, IPutAliasRequest { diff --git a/src/Nest/ElasticClient.Indices.cs b/src/Nest/ElasticClient.Indices.cs index 5987b34ca20..268019e2c1b 100644 --- a/src/Nest/ElasticClient.Indices.cs +++ b/src/Nest/ElasticClient.Indices.cs @@ -684,6 +684,30 @@ public Task GetMappingAsync(Func public Task OpenAsync(IOpenIndexRequest request, CancellationToken ct = default) => DoRequestAsync(request, request.RequestParameters, ct); /// + /// POST request to the indices.promote_data_stream API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + /// + public PromoteDataStreamResponse PromoteDataStream(Name name, Func selector = null) => PromoteDataStream(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name))); + /// + /// POST request to the indices.promote_data_stream API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + /// + public Task PromoteDataStreamAsync(Name name, Func selector = null, CancellationToken ct = default) => PromoteDataStreamAsync(selector.InvokeOrDefault(new PromoteDataStreamDescriptor(name: name)), ct); + /// + /// POST request to the indices.promote_data_stream API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + /// + public PromoteDataStreamResponse PromoteDataStream(IPromoteDataStreamRequest request) => DoRequest(request, request.RequestParameters); + /// + /// POST request to the indices.promote_data_stream API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + /// + public Task PromoteDataStreamAsync(IPromoteDataStreamRequest request, CancellationToken ct = default) => DoRequestAsync(request, request.RequestParameters, ct); + /// /// PUT request to the indices.put_alias API, read more about this API online: /// /// https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html diff --git a/src/Nest/Requests.Indices.cs b/src/Nest/Requests.Indices.cs index fba4210ba98..723ba364df2 100644 --- a/src/Nest/Requests.Indices.cs +++ b/src/Nest/Requests.Indices.cs @@ -1784,6 +1784,39 @@ public string WaitForActiveShards } } + [InterfaceDataContract] + public partial interface IPromoteDataStreamRequest : IRequest + { + [IgnoreDataMember] + Name Name + { + get; + } + } + + ///Request for PromoteDataStream https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + public partial class PromoteDataStreamRequest : PlainRequestBase, IPromoteDataStreamRequest + { + protected IPromoteDataStreamRequest Self => this; + internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream; + ////_data_stream/_promote/{name} + ///this parameter is required + public PromoteDataStreamRequest(Name name): base(r => r.Required("name", name)) + { + } + + ///Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected PromoteDataStreamRequest(): base() + { + } + + // values part of the url path + [IgnoreDataMember] + Name IPromoteDataStreamRequest.Name => Self.RouteValues.Get("name"); + // Request parameters + } + [InterfaceDataContract] public partial interface IPutAliasRequest : IRequest { diff --git a/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamRequest.cs b/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamRequest.cs new file mode 100644 index 00000000000..610a509d7c3 --- /dev/null +++ b/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamRequest.cs @@ -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 +{ + /// + /// The purpose of the promote data stream api is to turn a data stream that is replicated by CCR into a regular data stream. + /// + [MapsApi("indices.promote_data_stream.json")] + [ReadAs(typeof(PromoteDataStreamRequest))] + public partial interface IPromoteDataStreamRequest + { + } + + /// + public partial class PromoteDataStreamRequest : IPromoteDataStreamRequest + { + } + + /// + public partial class PromoteDataStreamDescriptor + { + } +} diff --git a/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamResponse.cs b/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamResponse.cs new file mode 100644 index 00000000000..15e0a55f693 --- /dev/null +++ b/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamResponse.cs @@ -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 { } +} diff --git a/src/Nest/_Generated/ApiUrlsLookup.generated.cs b/src/Nest/_Generated/ApiUrlsLookup.generated.cs index 8a322a04617..3f165e207cf 100644 --- a/src/Nest/_Generated/ApiUrlsLookup.generated.cs +++ b/src/Nest/_Generated/ApiUrlsLookup.generated.cs @@ -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"}); diff --git a/tests/Tests/XPack/DataStreams/Promote/PromoteDataStreamUrlTests.cs b/tests/Tests/XPack/DataStreams/Promote/PromoteDataStreamUrlTests.cs new file mode 100644 index 00000000000..914e228626a --- /dev/null +++ b/tests/Tests/XPack/DataStreams/Promote/PromoteDataStreamUrlTests.cs @@ -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"))); + } +} From 13e914f8e0007e34db71e3ff175b4b212a2a16f7 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 27 Apr 2021 12:02:39 +0100 Subject: [PATCH 2/3] Fixup --- src/Nest/Descriptors.Indices.cs | 2 ++ src/Nest/Requests.Indices.cs | 2 ++ .../Promote/PromoteDataStreamRequest.cs | 21 ++++++++++++++++--- .../Promote/PromoteDataStreamResponse.cs | 21 ++++++++++++++++--- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/Nest/Descriptors.Indices.cs b/src/Nest/Descriptors.Indices.cs index fa43318712e..47d98317c5a 100644 --- a/src/Nest/Descriptors.Indices.cs +++ b/src/Nest/Descriptors.Indices.cs @@ -1034,6 +1034,8 @@ public OpenIndexDescriptor Index() public partial class PromoteDataStreamDescriptor : RequestDescriptorBase, IPromoteDataStreamRequest { internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream; + protected override HttpMethod HttpMethod => HttpMethod.POST; + protected override bool SupportsBody => false; ////_data_stream/_promote/{name} ///this parameter is required public PromoteDataStreamDescriptor(Name name): base(r => r.Required("name", name)) diff --git a/src/Nest/Requests.Indices.cs b/src/Nest/Requests.Indices.cs index 723ba364df2..090d86a7df2 100644 --- a/src/Nest/Requests.Indices.cs +++ b/src/Nest/Requests.Indices.cs @@ -1799,6 +1799,8 @@ public partial class PromoteDataStreamRequest : PlainRequestBase this; internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesPromoteDataStream; + protected override HttpMethod HttpMethod => HttpMethod.POST; + protected override bool SupportsBody => false; ////_data_stream/_promote/{name} ///this parameter is required public PromoteDataStreamRequest(Name name): base(r => r.Required("name", name)) diff --git a/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamRequest.cs b/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamRequest.cs index 610a509d7c3..10bbd4c77f9 100644 --- a/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamRequest.cs +++ b/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamRequest.cs @@ -1,6 +1,21 @@ -// 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 +/* + * 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 { diff --git a/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamResponse.cs b/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamResponse.cs index 15e0a55f693..d84fc6dd5ff 100644 --- a/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamResponse.cs +++ b/src/Nest/XPack/DataStreams/Promote/PromoteDataStreamResponse.cs @@ -1,6 +1,21 @@ -// 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 +/* + * 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 { From bc3b84e04387ad94bd852aef71e5838591817c71 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 27 Apr 2021 12:04:23 +0100 Subject: [PATCH 3/3] Update license header in tests --- .../Promote/PromoteDataStreamUrlTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Tests/XPack/DataStreams/Promote/PromoteDataStreamUrlTests.cs b/tests/Tests/XPack/DataStreams/Promote/PromoteDataStreamUrlTests.cs index 914e228626a..91d94541604 100644 --- a/tests/Tests/XPack/DataStreams/Promote/PromoteDataStreamUrlTests.cs +++ b/tests/Tests/XPack/DataStreams/Promote/PromoteDataStreamUrlTests.cs @@ -1,3 +1,22 @@ +/* + * 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;