From 51b594f7ba5eb6f2c427e81902373aca0bbcade4 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 1f3eef5419f..7019451959e 100644 --- a/src/Nest/Descriptors.Indices.cs +++ b/src/Nest/Descriptors.Indices.cs @@ -1080,6 +1080,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 5459d8a8c28..267c3d5d9d1 100644 --- a/src/Nest/ElasticClient.Indices.cs +++ b/src/Nest/ElasticClient.Indices.cs @@ -756,6 +756,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 83d2a992f52..3bd3fb38409 100644 --- a/src/Nest/Requests.Indices.cs +++ b/src/Nest/Requests.Indices.cs @@ -1929,6 +1929,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 6131b1d3180..fe9f1a6355a 100644 --- a/src/Nest/_Generated/ApiUrlsLookup.generated.cs +++ b/src/Nest/_Generated/ApiUrlsLookup.generated.cs @@ -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"}); 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 34ef46221221a7d6a9cec8edcb10f3695582c574 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 27 Apr 2021 11:54:41 +0100 Subject: [PATCH 2/3] Update license headers --- .../Promote/PromoteDataStreamResponse.cs | 21 ++++++++++++++++--- .../Promote/PromoteDataStreamUrlTests.cs | 19 +++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) 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 { 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; From f2a10c4b484d5d596a7dee757192e4b39ac85e8c Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 27 Apr 2021 11:57:46 +0100 Subject: [PATCH 3/3] Update license header --- .../Promote/PromoteDataStreamRequest.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 {