From 40923b48fa1cf932b9f3aa791baac4d0ff8b046d Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Tue, 21 Nov 2023 13:27:13 +1300 Subject: [PATCH] Add support for component template APIs (#411) (#436) * Generate `cluster.put_component_template` Signed-off-by: Thomas Farr * Implement high-level DeleteComponentTemplate Signed-off-by: Thomas Farr * Implement high-level ComponentTemplateExists Signed-off-by: Thomas Farr * Fix license Signed-off-by: Thomas Farr * Remove old put_component_template Signed-off-by: Thomas Farr * Implement high-level GetComponentTemplate Signed-off-by: Thomas Farr * Add tests for ComponentTemplateExists Signed-off-by: Thomas Farr * Add tests for DeleteComponentTemplate Signed-off-by: Thomas Farr * Add tests for GetComponentTemplate Signed-off-by: Thomas Farr * Implement high-level PutComponentTemplate Signed-off-by: Thomas Farr * Add component template CRUD tests Signed-off-by: Thomas Farr * Add naming convention exception for ComponentTemplateExists Signed-off-by: Thomas Farr * Update guide Signed-off-by: Thomas Farr * Formatting Signed-off-by: Thomas Farr * Add changelog entry Signed-off-by: Thomas Farr * Fix license header Signed-off-by: Thomas Farr * Fix namespaces Signed-off-by: Thomas Farr * Fix license header Signed-off-by: Thomas Farr --------- Signed-off-by: Thomas Farr (cherry picked from commit 7eedc009e05c706f2554a1a27a92fc382bac5126) --- CHANGELOG.md | 1 + guides/index-template.md | 205 ++++++++++++ .../ComponentTemplate/ComponentTemplate.cs | 73 +++++ .../ComponentTemplateExistsRequest.cs | 15 + .../DeleteComponentTemplateRequest.cs | 15 + .../DeleteComponentTemplateResponse.cs | 13 + .../GetComponentTemplateRequest.cs | 15 + .../GetComponentTemplateResponse.cs | 28 ++ .../PutComponentTemplateRequest.cs | 38 +++ .../PutComponentTemplateResponse.cs | 13 + .../IndicesExists/ExistsResponse.cs | 11 +- .../OpenSearchClient.Cluster.cs | 6 +- .../_Generated/ApiUrlsLookup.cs | 12 + .../_Generated/Descriptors.Cluster.cs | 232 ++++++++++++++ .../_Generated/OpenSearchClient.Cluster.cs | 289 +++++++++++++++++ .../_Generated/Requests.Cluster.cs | 294 ++++++++++++++++++ .../RequestParameters.Cluster.cs | 123 -------- .../OpenSearchLowLevelClient.Cluster.cs | 59 ---- .../RequestParameters.Cluster.cs | 193 ++++++++++++ .../OpenSearchLowLevelClient.Cluster.cs | 237 ++++++++++++++ .../ComponentTemplateCrudTests.cs | 139 +++++++++ .../ComponentTemplateExistsApiTests.cs | 37 +++ .../ComponentTemplateExistsUrlTests.cs | 28 ++ .../DeleteComponentTemplateApiTests.cs | 36 +++ .../DeleteComponentTemplateUrlTests.cs | 28 ++ .../GetComponentTemplateApiTests.cs | 74 +++++ .../GetComponentTemplateUrlTests.cs | 35 +++ .../PutComponentTemplateApiTests.cs | 115 +++++++ .../PutComponentTemplateUrlTests.cs | 28 ++ .../CodeStandards/NamingConventions.doc.cs | 1 + tests/Tests/Tests.csproj | 1 + 31 files changed, 2201 insertions(+), 193 deletions(-) create mode 100644 guides/index-template.md create mode 100644 src/OpenSearch.Client/Cluster/ComponentTemplate/ComponentTemplate.cs create mode 100644 src/OpenSearch.Client/Cluster/ComponentTemplate/ComponentTemplateExistsRequest.cs create mode 100644 src/OpenSearch.Client/Cluster/ComponentTemplate/DeleteComponentTemplateRequest.cs create mode 100644 src/OpenSearch.Client/Cluster/ComponentTemplate/DeleteComponentTemplateResponse.cs create mode 100644 src/OpenSearch.Client/Cluster/ComponentTemplate/GetComponentTemplateRequest.cs create mode 100644 src/OpenSearch.Client/Cluster/ComponentTemplate/GetComponentTemplateResponse.cs create mode 100644 src/OpenSearch.Client/Cluster/ComponentTemplate/PutComponentTemplateRequest.cs create mode 100644 src/OpenSearch.Client/Cluster/ComponentTemplate/PutComponentTemplateResponse.cs create mode 100644 src/OpenSearch.Client/_Generated/Descriptors.Cluster.cs create mode 100644 src/OpenSearch.Client/_Generated/OpenSearchClient.Cluster.cs create mode 100644 src/OpenSearch.Client/_Generated/Requests.Cluster.cs create mode 100644 src/OpenSearch.Net/_Generated/Api/RequestParameters/RequestParameters.Cluster.cs create mode 100644 src/OpenSearch.Net/_Generated/OpenSearchLowLevelClient.Cluster.cs create mode 100644 tests/Tests/Cluster/ComponentTemplate/ComponentTemplateCrudTests.cs create mode 100644 tests/Tests/Cluster/ComponentTemplate/ComponentTemplateExistsApiTests.cs create mode 100644 tests/Tests/Cluster/ComponentTemplate/ComponentTemplateExistsUrlTests.cs create mode 100644 tests/Tests/Cluster/ComponentTemplate/DeleteComponentTemplateApiTests.cs create mode 100644 tests/Tests/Cluster/ComponentTemplate/DeleteComponentTemplateUrlTests.cs create mode 100644 tests/Tests/Cluster/ComponentTemplate/GetComponentTemplateApiTests.cs create mode 100644 tests/Tests/Cluster/ComponentTemplate/GetComponentTemplateUrlTests.cs create mode 100644 tests/Tests/Cluster/ComponentTemplate/PutComponentTemplateApiTests.cs create mode 100644 tests/Tests/Cluster/ComponentTemplate/PutComponentTemplateUrlTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 443dadbc1f..3f778c5381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Added - Added support for point-in-time search and associated APIs ([#405](https://github.com/opensearch-project/opensearch-net/pull/405)) +- Added support for the component template APIs ([#411](https://github.com/opensearch-project/opensearch-net/pull/411)) ### Dependencies - Bumps `FSharp.Data` from 6.2.0 to 6.3.0 diff --git a/guides/index-template.md b/guides/index-template.md new file mode 100644 index 0000000000..ffda5e59d6 --- /dev/null +++ b/guides/index-template.md @@ -0,0 +1,205 @@ +# Index Template +Index templates allow you to define default settings, mappings, and aliases for one or more indices during their creation. This guide will teach you how to create index templates and apply them to indices using the OpenSearch .NET client. + +## Setup +**At the time of writing the API methods related to composable templates do not yet exist in the high-level client, as such this guide makes use of their low-level counterparts.** + + +Assuming you have OpenSearch running locally on port 9200, you can create a client instance with the following code: + +```csharp +using OpenSearch.Client; +using OpenSearch.Net; + +var node = new Uri("https://localhost:9200"); +var config = new ConnectionSettings(node) + .ServerCertificateValidationCallback(CertificateValidations.AllowAll) + .BasicAuthentication("admin", "admin"); + +var client = new OpenSearchClient(config);; +``` + + +## Index Template API Actions + + +### Create an Index Template +You can create an index template to define default settings and mappings for indices of certain patterns. The following example creates an index template named `books` with default settings and mappings for indices of the `books-*` pattern: + +```csharp +client.LowLevel.Indices.PutTemplateV2ForAll("books", PostData.Serializable(new +{ + index_patterns = new[] { "books-*" }, + priority = 0, + template = new + { + settings = new + { + index = new + { + number_of_shards = 3, + number_of_replicas = 0 + } + }, + mappings = new + { + properties = new + { + title = new { type = "text" }, + author = new { type = "text" }, + published_on = new { type = "date" }, + pages = new { type = "integer" } + } + } + } +})); +``` + +Now, when you create an index that matches the `books-*` pattern, OpenSearch will automatically apply the template's settings and mappings to the index. Let's create an index named `books-nonfiction` and verify that its settings and mappings match those of the template: + +```csharp +client.Indices.Create("books-nonfiction"); +var getResponse = client.Indices.Get("books-nonfiction"); +Console.WriteLine(getResponse.Indices["books-nonfiction"].Mappings.Properties["pages"].Type); // integer +``` + + +### Multiple Index Templates + +```csharp +var createResponseOne = client.LowLevel.Indices.PutTemplateV2ForAll("books", PostData.Serializable(new +{ + index_patterns = new[] { "books-*" }, + priority = 0, + template = new + { + settings = new + { + index = new + { + number_of_shards = 3, + number_of_replicas = 0 + } + } + } +})); + +client.LowLevel.Indices.PutTemplateV2ForAll("books-fiction", PostData.Serializable(new +{ + index_patterns = new[] { "books-fiction-*" }, + priority = 1, // higher priority than the `books` template + template = new + { + settings = new + { + index = new + { + number_of_shards = 1, + number_of_replicas = 1 + } + } + } +})); +``` + +When we create an index named `books-fiction-romance`, OpenSearch will apply the `books-fiction-*` template's settings to the index: + +```csharp +client.Indices.Create("books-fiction-romance"); +var getResponse = client.Indices.Get("books-fiction-romance"); +Console.WriteLine(getResponse.Indices["books-fiction-romance"].Settings.NumberOfShards); // 1 +``` + + +### Composable Index Templates +Composable index templates are a new type of index template that allow you to define multiple component templates and compose them into a final template. The following example creates a component template named `books_mappings` with default mappings for indices of the `books-*` and `books-fiction-*` patterns: + +```csharp +// Create a component template +client.Cluster.PutComponentTemplate("books_mappings", ct => ct + .Template(t => t + .Map(m => m + .Properties(p => p + .Text(tp => tp + .Name("title")) + .Text(tp => tp + .Name("author")) + .Date(d => d + .Name("published_on")) + .Number(n => n + .Name("pages") + .Type(NumberType.Integer)))))); + +// Create an index template for "books" +var createBooksTemplateResponse = client.LowLevel.Indices.PutTemplateV2ForAll("books", PostData.Serializable(new +{ + index_patterns = new[] { "books-*" }, + composed_of = new[] { "books_mappings" }, + priority = 0, + template = new + { + settings = new + { + index = new + { + number_of_shards = 3, + number_of_replicas = 0 + } + } + } +})); + +// Create an index template for "books-fiction" +var createBooksFictionTemplateResponse = client.LowLevel.Indices.PutTemplateV2ForAll("books-fiction", PostData.Serializable(new +{ + index_patterns = new[] { "books-fiction-*" }, + composed_of = new[] { "books_mappings" }, + priority = 1, + template = new + { + settings = new + { + index = new + { + number_of_shards = 1, + number_of_replicas = 1 + } + } + } +})); +``` + +When we create an index named `books-fiction-horror`, OpenSearch will apply the `books-fiction-*` template's settings, and `books_mappings` template mappings to the index: + +```csharp +client.Indices.Create("books-fiction-horror"); +var getResponse = client.Indices.Get("books-fiction-horror"); +Console.WriteLine(getResponse.Indices["books-fiction-horror"].Settings.NumberOfShards); // 1 +Console.WriteLine(getResponse.Indices["books-fiction-horror"].Mappings.Properties["pages"].Type); // integer +``` + +### Get an Index Template +You can get an index template with the `GetTemplateV2ForAll` API action. The following example gets the `books` index template: + +```csharp +var getResponse = client.LowLevel.Indices.GetTemplateV2ForAll("books").Body; +Console.WriteLine($"Get response: {getResponse}"); // Get response: {"books":{"order":0,"index_patterns":["books-*"],"settings":{"index":{"number_of_shards":"3","number_of_replicas":"0"}},"mappings":{},"aliases":{}}} +``` + +### Delete an Index Template +You can delete an index template with the `DeleteTemplateV2ForAll` API action. The following example deletes the `books` index template: + +```csharp +var deleteResponse = client.LowLevel.Indices.DeleteTemplateV2ForAll("books"); +Console.WriteLine($"Delete response: {deleteResponse}"); // Delete response: {"acknowledged":true} +``` + + +## Cleanup +Let's delete all resources created in this guide: + +```csharp +client.Indices.Delete("books-"); +client.LowLevel.Indices.DeleteTemplateV2ForAll("books-fiction"); +client.Cluster.DeleteComponentTemplate("books_mappings"); +``` diff --git a/src/OpenSearch.Client/Cluster/ComponentTemplate/ComponentTemplate.cs b/src/OpenSearch.Client/Cluster/ComponentTemplate/ComponentTemplate.cs new file mode 100644 index 0000000000..9cb9ee41ab --- /dev/null +++ b/src/OpenSearch.Client/Cluster/ComponentTemplate/ComponentTemplate.cs @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using OpenSearch.Net.Utf8Json; + +namespace OpenSearch.Client; + +[ReadAs(typeof(ComponentTemplate))] +public interface IComponentTemplate +{ + [DataMember(Name = "template")] + ITemplate Template { get; set; } + + [DataMember(Name = "version")] + long? Version { get; set; } + + [DataMember(Name = "_meta")] + [JsonFormatter(typeof(VerbatimDictionaryInterfaceKeysFormatter))] + IDictionary Meta { get; set; } +} + +public class ComponentTemplate : IComponentTemplate +{ + public ITemplate Template { get; set; } + public long? Version { get; set; } + public IDictionary Meta { get; set; } +} + +[ReadAs(typeof(Template))] +public interface ITemplate +{ + [DataMember(Name = "aliases")] + IAliases Aliases { get; set; } + + [DataMember(Name = "mappings")] + ITypeMapping Mappings { get; set; } + + [DataMember(Name = "settings")] + IIndexSettings Settings { get; set; } +} + +public class Template : ITemplate +{ + public IAliases Aliases { get; set; } + public ITypeMapping Mappings { get; set; } + public IIndexSettings Settings { get; set; } +} + +public class TemplateDescriptor : DescriptorBase, ITemplate +{ + IAliases ITemplate.Aliases { get; set; } + ITypeMapping ITemplate.Mappings { get; set; } + IIndexSettings ITemplate.Settings { get; set; } + + public TemplateDescriptor Aliases(Func> aliasDescriptor) => + Assign(aliasDescriptor, (a, v) => a.Aliases = v?.Invoke(new AliasesDescriptor())?.Value); + + public TemplateDescriptor Map(Func, ITypeMapping> selector) where T : class => + Assign(selector, (a, v) => a.Mappings = v?.Invoke(new TypeMappingDescriptor())); + + public TemplateDescriptor Map(Func, ITypeMapping> selector) => + Assign(selector, (a, v) => a.Mappings = v?.Invoke(new TypeMappingDescriptor())); + + public TemplateDescriptor Settings(Func> settingsSelector) => + Assign(settingsSelector, (a, v) => a.Settings = v?.Invoke(new IndexSettingsDescriptor())?.Value); +} diff --git a/src/OpenSearch.Client/Cluster/ComponentTemplate/ComponentTemplateExistsRequest.cs b/src/OpenSearch.Client/Cluster/ComponentTemplate/ComponentTemplateExistsRequest.cs new file mode 100644 index 0000000000..1a6874e27b --- /dev/null +++ b/src/OpenSearch.Client/Cluster/ComponentTemplate/ComponentTemplateExistsRequest.cs @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +namespace OpenSearch.Client; + +[MapsApi("cluster.exists_component_template")] +public partial interface IComponentTemplateExistsRequest { } + +public partial class ComponentTemplateExistsRequest { } + +public partial class ComponentTemplateExistsDescriptor { } diff --git a/src/OpenSearch.Client/Cluster/ComponentTemplate/DeleteComponentTemplateRequest.cs b/src/OpenSearch.Client/Cluster/ComponentTemplate/DeleteComponentTemplateRequest.cs new file mode 100644 index 0000000000..68b627b0ba --- /dev/null +++ b/src/OpenSearch.Client/Cluster/ComponentTemplate/DeleteComponentTemplateRequest.cs @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +namespace OpenSearch.Client; + +[MapsApi("cluster.delete_component_template")] +public partial interface IDeleteComponentTemplateRequest { } + +public partial class DeleteComponentTemplateRequest { } + +public partial class DeleteComponentTemplateDescriptor { } diff --git a/src/OpenSearch.Client/Cluster/ComponentTemplate/DeleteComponentTemplateResponse.cs b/src/OpenSearch.Client/Cluster/ComponentTemplate/DeleteComponentTemplateResponse.cs new file mode 100644 index 0000000000..a232cc759e --- /dev/null +++ b/src/OpenSearch.Client/Cluster/ComponentTemplate/DeleteComponentTemplateResponse.cs @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System.Runtime.Serialization; + +namespace OpenSearch.Client; + +[DataContract] +public class DeleteComponentTemplateResponse : AcknowledgedResponseBase { } diff --git a/src/OpenSearch.Client/Cluster/ComponentTemplate/GetComponentTemplateRequest.cs b/src/OpenSearch.Client/Cluster/ComponentTemplate/GetComponentTemplateRequest.cs new file mode 100644 index 0000000000..48c4d3b4e5 --- /dev/null +++ b/src/OpenSearch.Client/Cluster/ComponentTemplate/GetComponentTemplateRequest.cs @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +namespace OpenSearch.Client; + +[MapsApi("cluster.get_component_template")] +public partial interface IGetComponentTemplateRequest { } + +public partial class GetComponentTemplateRequest { } + +public partial class GetComponentTemplateDescriptor { } diff --git a/src/OpenSearch.Client/Cluster/ComponentTemplate/GetComponentTemplateResponse.cs b/src/OpenSearch.Client/Cluster/ComponentTemplate/GetComponentTemplateResponse.cs new file mode 100644 index 0000000000..07a3be9fd1 --- /dev/null +++ b/src/OpenSearch.Client/Cluster/ComponentTemplate/GetComponentTemplateResponse.cs @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace OpenSearch.Client; + +[DataContract] +public class GetComponentTemplateResponse : ResponseBase +{ + [DataMember(Name = "component_templates")] + public IReadOnlyCollection ComponentTemplates { get; internal set; } +} + +[DataContract] +public class NamedComponentTemplate +{ + [DataMember(Name = "name")] + public string Name { get; internal set; } + + [DataMember(Name = "component_template")] + public ComponentTemplate ComponentTemplate { get; internal set; } +} diff --git a/src/OpenSearch.Client/Cluster/ComponentTemplate/PutComponentTemplateRequest.cs b/src/OpenSearch.Client/Cluster/ComponentTemplate/PutComponentTemplateRequest.cs new file mode 100644 index 0000000000..09da0006b6 --- /dev/null +++ b/src/OpenSearch.Client/Cluster/ComponentTemplate/PutComponentTemplateRequest.cs @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System; +using System.Collections.Generic; + +namespace OpenSearch.Client; + +[MapsApi("cluster.put_component_template")] +public partial interface IPutComponentTemplateRequest : IComponentTemplate { } + +public partial class PutComponentTemplateRequest +{ + public ITemplate Template { get; set; } + public long? Version { get; set; } + public IDictionary Meta { get; set; } +} + +public partial class PutComponentTemplateDescriptor +{ + ITemplate IComponentTemplate.Template { get; set; } + long? IComponentTemplate.Version { get; set; } + IDictionary IComponentTemplate.Meta { get; set; } + + public PutComponentTemplateDescriptor Version(long? version) => Assign(version, (a, v) => a.Version = v); + + public PutComponentTemplateDescriptor Meta(Func, FluentDictionary> metaSelector) => + Assign(metaSelector(new FluentDictionary()), (a, v) => a.Meta = v); + + public PutComponentTemplateDescriptor Meta(Dictionary metaDictionary) => Assign(metaDictionary, (a, v) => a.Meta = v); + + public PutComponentTemplateDescriptor Template(Func selector) => + Assign(selector, (a, v) => a.Template = v?.Invoke(new TemplateDescriptor())); +} diff --git a/src/OpenSearch.Client/Cluster/ComponentTemplate/PutComponentTemplateResponse.cs b/src/OpenSearch.Client/Cluster/ComponentTemplate/PutComponentTemplateResponse.cs new file mode 100644 index 0000000000..1786a1f449 --- /dev/null +++ b/src/OpenSearch.Client/Cluster/ComponentTemplate/PutComponentTemplateResponse.cs @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System.Runtime.Serialization; + +namespace OpenSearch.Client; + +[DataContract] +public class PutComponentTemplateResponse : AcknowledgedResponseBase { } diff --git a/src/OpenSearch.Client/Indices/IndexManagement/IndicesExists/ExistsResponse.cs b/src/OpenSearch.Client/Indices/IndexManagement/IndicesExists/ExistsResponse.cs index ceb8b37e7f..fff77c92df 100644 --- a/src/OpenSearch.Client/Indices/IndexManagement/IndicesExists/ExistsResponse.cs +++ b/src/OpenSearch.Client/Indices/IndexManagement/IndicesExists/ExistsResponse.cs @@ -28,11 +28,10 @@ using System.Runtime.Serialization; -namespace OpenSearch.Client +namespace OpenSearch.Client; + +[DataContract] +public class ExistsResponse : ResponseBase { - [DataContract] - public class ExistsResponse : ResponseBase - { - public bool Exists => ApiCall != null && ApiCall.Success && ApiCall.HttpStatusCode == 200; - } + public bool Exists => ApiCall is { Success: true, HttpStatusCode: 200 }; } diff --git a/src/OpenSearch.Client/OpenSearchClient.Cluster.cs b/src/OpenSearch.Client/OpenSearchClient.Cluster.cs index 61a88a1101..568c21ff4b 100644 --- a/src/OpenSearch.Client/OpenSearchClient.Cluster.cs +++ b/src/OpenSearch.Client/OpenSearchClient.Cluster.cs @@ -42,12 +42,8 @@ namespace OpenSearch.Client.Specification.ClusterApi /// on . /// /// - public class ClusterNamespace : NamespacedClientProxy + public partial class ClusterNamespace : NamespacedClientProxy { - internal ClusterNamespace(OpenSearchClient client): base(client) - { - } - /// /// POST request to the cluster.allocation_explain API, read more about this API online: /// diff --git a/src/OpenSearch.Client/_Generated/ApiUrlsLookup.cs b/src/OpenSearch.Client/_Generated/ApiUrlsLookup.cs index da842e9799..1bb9a629e6 100644 --- a/src/OpenSearch.Client/_Generated/ApiUrlsLookup.cs +++ b/src/OpenSearch.Client/_Generated/ApiUrlsLookup.cs @@ -45,6 +45,18 @@ namespace OpenSearch.Client { internal static partial class ApiUrlsLookups { + internal static readonly ApiUrls ClusterDeleteComponentTemplate = + new(new[] { "_component_template/{name}" }); + + internal static readonly ApiUrls ClusterComponentTemplateExists = + new(new[] { "_component_template/{name}" }); + + internal static readonly ApiUrls ClusterGetComponentTemplate = + new(new[] { "_component_template", "_component_template/{name}" }); + + internal static readonly ApiUrls ClusterPutComponentTemplate = + new(new[] { "_component_template/{name}" }); + internal static readonly ApiUrls NoNamespaceCreatePit = new(new[] { "{index}/_search/point_in_time" }); diff --git a/src/OpenSearch.Client/_Generated/Descriptors.Cluster.cs b/src/OpenSearch.Client/_Generated/Descriptors.Cluster.cs new file mode 100644 index 0000000000..954f636824 --- /dev/null +++ b/src/OpenSearch.Client/_Generated/Descriptors.Cluster.cs @@ -0,0 +1,232 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ +/* +* Modifications Copyright OpenSearch Contributors. See +* GitHub history for details. +* +* 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. +*/ +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ----------------------------------------------- +// +// This file is automatically generated +// Please do not edit these files manually +// Run the following in the root of the repos: +// +// *NIX : ./build.sh codegen +// Windows : build.bat codegen +// +// ----------------------------------------------- +// ReSharper disable RedundantUsingDirective +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Linq.Expressions; + +using OpenSearch.Net; +using OpenSearch.Net.Utf8Json; +using OpenSearch.Net.Specification.ClusterApi; + +// ReSharper disable RedundantBaseConstructorCall +// ReSharper disable UnusedTypeParameter +// ReSharper disable PartialMethodWithSinglePart +// ReSharper disable RedundantNameQualifier +namespace OpenSearch.Client +{ + /// Descriptor for DeleteComponentTemplate https://opensearch.org/docs/latest + public partial class DeleteComponentTemplateDescriptor + : RequestDescriptorBase< + DeleteComponentTemplateDescriptor, + DeleteComponentTemplateRequestParameters, + IDeleteComponentTemplateRequest + >, + IDeleteComponentTemplateRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterDeleteComponentTemplate; + + /// /_component_template/{name} + /// this parameter is required + public DeleteComponentTemplateDescriptor(Name name) + : base(r => r.Required("name", name)) { } + + /// Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected DeleteComponentTemplateDescriptor() + : base() { } + + // values part of the url path + Name IDeleteComponentTemplateRequest.Name => Self.RouteValues.Get("name"); + + // Request parameters + /// Operation timeout for connection to cluster-manager node. + /// Supported by OpenSearch servers of version 2.0.0 or greater. + public DeleteComponentTemplateDescriptor ClusterManagerTimeout( + Time clustermanagertimeout + ) => Qs("cluster_manager_timeout", clustermanagertimeout); + + /// Operation timeout for connection to master node. + [Obsolete( + "Deprecated as of: 2.0.0, reason: To promote inclusive language, use 'cluster_manager_timeout' instead." + )] + public DeleteComponentTemplateDescriptor MasterTimeout(Time mastertimeout) => + Qs("master_timeout", mastertimeout); + + /// Operation timeout. + public DeleteComponentTemplateDescriptor Timeout(Time timeout) => Qs("timeout", timeout); + } + + /// Descriptor for ComponentTemplateExists https://opensearch.org/docs/latest + public partial class ComponentTemplateExistsDescriptor + : RequestDescriptorBase< + ComponentTemplateExistsDescriptor, + ComponentTemplateExistsRequestParameters, + IComponentTemplateExistsRequest + >, + IComponentTemplateExistsRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterComponentTemplateExists; + + /// /_component_template/{name} + /// this parameter is required + public ComponentTemplateExistsDescriptor(Name name) + : base(r => r.Required("name", name)) { } + + /// Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected ComponentTemplateExistsDescriptor() + : base() { } + + // values part of the url path + Name IComponentTemplateExistsRequest.Name => Self.RouteValues.Get("name"); + + // Request parameters + /// Operation timeout for connection to cluster-manager node. + /// Supported by OpenSearch servers of version 2.0.0 or greater. + public ComponentTemplateExistsDescriptor ClusterManagerTimeout( + Time clustermanagertimeout + ) => Qs("cluster_manager_timeout", clustermanagertimeout); + + /// Return local information, do not retrieve the state from cluster-manager node. + public ComponentTemplateExistsDescriptor Local(bool? local = true) => Qs("local", local); + + /// Operation timeout for connection to master node. + [Obsolete( + "Deprecated as of: 2.0.0, reason: To promote inclusive language, use 'cluster_manager_timeout' instead." + )] + public ComponentTemplateExistsDescriptor MasterTimeout(Time mastertimeout) => + Qs("master_timeout", mastertimeout); + } + + /// Descriptor for GetComponentTemplate https://opensearch.org/docs/latest + public partial class GetComponentTemplateDescriptor + : RequestDescriptorBase< + GetComponentTemplateDescriptor, + GetComponentTemplateRequestParameters, + IGetComponentTemplateRequest + >, + IGetComponentTemplateRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterGetComponentTemplate; + + /// /_component_template + public GetComponentTemplateDescriptor() + : base() { } + + /// /_component_template/{name} + /// Optional, accepts null + public GetComponentTemplateDescriptor(Names name) + : base(r => r.Optional("name", name)) { } + + // values part of the url path + Names IGetComponentTemplateRequest.Name => Self.RouteValues.Get("name"); + + /// The Comma-separated names of the component templates. + public GetComponentTemplateDescriptor Name(Names name) => + Assign(name, (a, v) => a.RouteValues.Optional("name", v)); + + // Request parameters + /// Operation timeout for connection to cluster-manager node. + /// Supported by OpenSearch servers of version 2.0.0 or greater. + public GetComponentTemplateDescriptor ClusterManagerTimeout(Time clustermanagertimeout) => + Qs("cluster_manager_timeout", clustermanagertimeout); + + /// Return local information, do not retrieve the state from cluster-manager node. + public GetComponentTemplateDescriptor Local(bool? local = true) => Qs("local", local); + + /// Operation timeout for connection to master node. + [Obsolete( + "Deprecated as of: 2.0.0, reason: To promote inclusive language, use 'cluster_manager_timeout' instead." + )] + public GetComponentTemplateDescriptor MasterTimeout(Time mastertimeout) => + Qs("master_timeout", mastertimeout); + } + + /// Descriptor for PutComponentTemplate + public partial class PutComponentTemplateDescriptor + : RequestDescriptorBase< + PutComponentTemplateDescriptor, + PutComponentTemplateRequestParameters, + IPutComponentTemplateRequest + >, + IPutComponentTemplateRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterPutComponentTemplate; + + /// /_component_template/{name} + /// this parameter is required + public PutComponentTemplateDescriptor(Name name) + : base(r => r.Required("name", name)) { } + + /// Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected PutComponentTemplateDescriptor() + : base() { } + + // values part of the url path + Name IPutComponentTemplateRequest.Name => Self.RouteValues.Get("name"); + + // Request parameters + /// Operation timeout for connection to cluster-manager node. + /// Supported by OpenSearch servers of version 2.0.0 or greater. + public PutComponentTemplateDescriptor ClusterManagerTimeout(Time clustermanagertimeout) => + Qs("cluster_manager_timeout", clustermanagertimeout); + + /// Whether the index template should only be added if new or can also replace an existing one. + public PutComponentTemplateDescriptor Create(bool? create = true) => Qs("create", create); + + /// Operation timeout for connection to master node. + [Obsolete( + "Deprecated as of: 2.0.0, reason: To promote inclusive language, use 'cluster_manager_timeout' instead." + )] + public PutComponentTemplateDescriptor MasterTimeout(Time mastertimeout) => + Qs("master_timeout", mastertimeout); + + /// Operation timeout. + public PutComponentTemplateDescriptor Timeout(Time timeout) => Qs("timeout", timeout); + } +} diff --git a/src/OpenSearch.Client/_Generated/OpenSearchClient.Cluster.cs b/src/OpenSearch.Client/_Generated/OpenSearchClient.Cluster.cs new file mode 100644 index 0000000000..5264bb21b5 --- /dev/null +++ b/src/OpenSearch.Client/_Generated/OpenSearchClient.Cluster.cs @@ -0,0 +1,289 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ +/* +* Modifications Copyright OpenSearch Contributors. See +* GitHub history for details. +* +* 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. +*/ +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ----------------------------------------------- +// +// This file is automatically generated +// Please do not edit these files manually +// Run the following in the root of the repos: +// +// *NIX : ./build.sh codegen +// Windows : build.bat codegen +// +// ----------------------------------------------- +// ReSharper disable RedundantUsingDirective +using System; +using System.Threading; +using System.Threading.Tasks; +using OpenSearch.Net.Specification.ClusterApi; + +// ReSharper disable once CheckNamespace +// ReSharper disable RedundantTypeArgumentsOfMethod +namespace OpenSearch.Client.Specification.ClusterApi +{ + /// + /// Cluster APIs. + /// Not intended to be instantiated directly. Use the property + /// on . + /// + /// + public partial class ClusterNamespace : NamespacedClientProxy + { + internal ClusterNamespace(OpenSearchClient client) + : base(client) { } + + /// + /// DELETE request to the cluster.delete_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public DeleteComponentTemplateResponse DeleteComponentTemplate( + Name name, + Func selector = null + ) => + DeleteComponentTemplate( + selector.InvokeOrDefault(new DeleteComponentTemplateDescriptor(name: name)) + ); + + /// + /// DELETE request to the cluster.delete_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public Task DeleteComponentTemplateAsync( + Name name, + Func selector = + null, + CancellationToken ct = default + ) => + DeleteComponentTemplateAsync( + selector.InvokeOrDefault(new DeleteComponentTemplateDescriptor(name: name)), + ct + ); + + /// + /// DELETE request to the cluster.delete_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public DeleteComponentTemplateResponse DeleteComponentTemplate( + IDeleteComponentTemplateRequest request + ) => + DoRequest( + request, + request.RequestParameters + ); + + /// + /// DELETE request to the cluster.delete_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public Task DeleteComponentTemplateAsync( + IDeleteComponentTemplateRequest request, + CancellationToken ct = default + ) => + DoRequestAsync( + request, + request.RequestParameters, + ct + ); + + /// + /// HEAD request to the cluster.exists_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public ExistsResponse ComponentTemplateExists( + Name name, + Func selector = null + ) => + ComponentTemplateExists( + selector.InvokeOrDefault(new ComponentTemplateExistsDescriptor(name: name)) + ); + + /// + /// HEAD request to the cluster.exists_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public Task ComponentTemplateExistsAsync( + Name name, + Func selector = + null, + CancellationToken ct = default + ) => + ComponentTemplateExistsAsync( + selector.InvokeOrDefault(new ComponentTemplateExistsDescriptor(name: name)), + ct + ); + + /// + /// HEAD request to the cluster.exists_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public ExistsResponse ComponentTemplateExists(IComponentTemplateExistsRequest request) => + DoRequest( + request, + request.RequestParameters + ); + + /// + /// HEAD request to the cluster.exists_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public Task ComponentTemplateExistsAsync( + IComponentTemplateExistsRequest request, + CancellationToken ct = default + ) => + DoRequestAsync( + request, + request.RequestParameters, + ct + ); + + /// + /// GET request to the cluster.get_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public GetComponentTemplateResponse GetComponentTemplate( + Names name = null, + Func selector = null + ) => + GetComponentTemplate( + selector.InvokeOrDefault(new GetComponentTemplateDescriptor().Name(name: name)) + ); + + /// + /// GET request to the cluster.get_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public Task GetComponentTemplateAsync( + Names name = null, + Func selector = null, + CancellationToken ct = default + ) => + GetComponentTemplateAsync( + selector.InvokeOrDefault(new GetComponentTemplateDescriptor().Name(name: name)), + ct + ); + + /// + /// GET request to the cluster.get_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public GetComponentTemplateResponse GetComponentTemplate( + IGetComponentTemplateRequest request + ) => + DoRequest( + request, + request.RequestParameters + ); + + /// + /// GET request to the cluster.get_component_template API, read more about this API online: + /// + /// https://opensearch.org/docs/latest + /// + public Task GetComponentTemplateAsync( + IGetComponentTemplateRequest request, + CancellationToken ct = default + ) => + DoRequestAsync( + request, + request.RequestParameters, + ct + ); + + /// + /// PUT request to the cluster.put_component_template API, read more about this API online: + /// + /// + /// + public PutComponentTemplateResponse PutComponentTemplate( + Name name, + Func selector + ) => + PutComponentTemplate( + selector.InvokeOrDefault(new PutComponentTemplateDescriptor(name: name)) + ); + + /// + /// PUT request to the cluster.put_component_template API, read more about this API online: + /// + /// + /// + public Task PutComponentTemplateAsync( + Name name, + Func selector, + CancellationToken ct = default + ) => + PutComponentTemplateAsync( + selector.InvokeOrDefault(new PutComponentTemplateDescriptor(name: name)), + ct + ); + + /// + /// PUT request to the cluster.put_component_template API, read more about this API online: + /// + /// + /// + public PutComponentTemplateResponse PutComponentTemplate( + IPutComponentTemplateRequest request + ) => + DoRequest( + request, + request.RequestParameters + ); + + /// + /// PUT request to the cluster.put_component_template API, read more about this API online: + /// + /// + /// + public Task PutComponentTemplateAsync( + IPutComponentTemplateRequest request, + CancellationToken ct = default + ) => + DoRequestAsync( + request, + request.RequestParameters, + ct + ); + } +} diff --git a/src/OpenSearch.Client/_Generated/Requests.Cluster.cs b/src/OpenSearch.Client/_Generated/Requests.Cluster.cs new file mode 100644 index 0000000000..2ccc425320 --- /dev/null +++ b/src/OpenSearch.Client/_Generated/Requests.Cluster.cs @@ -0,0 +1,294 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ +/* +* Modifications Copyright OpenSearch Contributors. See +* GitHub history for details. +* +* 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. +*/ +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ----------------------------------------------- +// +// This file is automatically generated +// Please do not edit these files manually +// Run the following in the root of the repos: +// +// *NIX : ./build.sh codegen +// Windows : build.bat codegen +// +// ----------------------------------------------- +// ReSharper disable RedundantUsingDirective +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Linq.Expressions; +using System.Runtime.Serialization; +using OpenSearch.Net; +using OpenSearch.Net.Utf8Json; +using OpenSearch.Net.Specification.ClusterApi; + +// ReSharper disable RedundantBaseConstructorCall +// ReSharper disable UnusedTypeParameter +// ReSharper disable PartialMethodWithSinglePart +// ReSharper disable RedundantNameQualifier +namespace OpenSearch.Client +{ + [InterfaceDataContract] + public partial interface IDeleteComponentTemplateRequest + : IRequest + { + [IgnoreDataMember] + Name Name { get; } + } + + /// Request for DeleteComponentTemplate https://opensearch.org/docs/latest + public partial class DeleteComponentTemplateRequest + : PlainRequestBase, + IDeleteComponentTemplateRequest + { + protected IDeleteComponentTemplateRequest Self => this; + internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterDeleteComponentTemplate; + + /// /_component_template/{name} + /// this parameter is required + public DeleteComponentTemplateRequest(Name name) + : base(r => r.Required("name", name)) { } + + /// Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected DeleteComponentTemplateRequest() + : base() { } + + // values part of the url path + [IgnoreDataMember] + Name IDeleteComponentTemplateRequest.Name => Self.RouteValues.Get("name"); + + // Request parameters + /// Operation timeout for connection to cluster-manager node. + /// Supported by OpenSearch servers of version 2.0.0 or greater. + public Time ClusterManagerTimeout + { + get => Q public partial class LowLevelClusterNamespace : NamespacedClientProxy { - internal LowLevelClusterNamespace(OpenSearchLowLevelClient client): base(client) - { - } - ///POST on /_cluster/allocation/explain https://opensearch.org/docs/latest/opensearch/rest-api/cluster-allocation/ ///The index, shard, and primary flag to explain. Empty means 'explain the first unassigned shard' ///Request specific configuration such as querystring parameters & request specific connection settings. @@ -66,17 +62,6 @@ public TResponse AllocationExplain(PostData body, ClusterAllocationEx [MapsApi("cluster.allocation_explain", "body")] public Task AllocationExplainAsync(PostData body, ClusterAllocationExplainRequestParameters requestParameters = null, CancellationToken ctx = default) where TResponse : class, IOpenSearchResponse, new() => DoRequestAsync(POST, "_cluster/allocation/explain", ctx, body, RequestParams(requestParameters)); - ///DELETE on /_component_template/{name} https://opensearch.org/docs/latest/opensearch/index-templates/ - ///The name of the template - ///Request specific configuration such as querystring parameters & request specific connection settings. - public TResponse DeleteComponentTemplate(string name, DeleteComponentTemplateRequestParameters requestParameters = null) - where TResponse : class, IOpenSearchResponse, new() => DoRequest(DELETE, Url($"_component_template/{name:name}"), null, RequestParams(requestParameters)); - ///DELETE on /_component_template/{name} https://opensearch.org/docs/latest/opensearch/index-templates/ - ///The name of the template - ///Request specific configuration such as querystring parameters & request specific connection settings. - [MapsApi("cluster.delete_component_template", "name")] - public Task DeleteComponentTemplateAsync(string name, DeleteComponentTemplateRequestParameters requestParameters = null, CancellationToken ctx = default) - where TResponse : class, IOpenSearchResponse, new() => DoRequestAsync(DELETE, Url($"_component_template/{name:name}"), ctx, null, RequestParams(requestParameters)); ///DELETE on /_cluster/voting_config_exclusions ///Request specific configuration such as querystring parameters & request specific connection settings. public TResponse DeleteVotingConfigExclusions(DeleteVotingConfigExclusionsRequestParameters requestParameters = null) @@ -86,37 +71,6 @@ public TResponse DeleteVotingConfigExclusions(DeleteVotingConfigExclu [MapsApi("cluster.delete_voting_config_exclusions", "")] public Task DeleteVotingConfigExclusionsAsync(DeleteVotingConfigExclusionsRequestParameters requestParameters = null, CancellationToken ctx = default) where TResponse : class, IOpenSearchResponse, new() => DoRequestAsync(DELETE, "_cluster/voting_config_exclusions", ctx, null, RequestParams(requestParameters)); - ///HEAD on /_component_template/{name} https://opensearch.org/docs/latest/opensearch/index-templates/ - ///The name of the template - ///Request specific configuration such as querystring parameters & request specific connection settings. - public TResponse ExistsComponentTemplate(string name, ExistsComponentTemplateRequestParameters requestParameters = null) - where TResponse : class, IOpenSearchResponse, new() => DoRequest(HEAD, Url($"_component_template/{name:name}"), null, RequestParams(requestParameters)); - ///HEAD on /_component_template/{name} https://opensearch.org/docs/latest/opensearch/index-templates/ - ///The name of the template - ///Request specific configuration such as querystring parameters & request specific connection settings. - [MapsApi("cluster.exists_component_template", "name")] - public Task ExistsComponentTemplateAsync(string name, ExistsComponentTemplateRequestParameters requestParameters = null, CancellationToken ctx = default) - where TResponse : class, IOpenSearchResponse, new() => DoRequestAsync(HEAD, Url($"_component_template/{name:name}"), ctx, null, RequestParams(requestParameters)); - ///GET on /_component_template https://opensearch.org/docs/latest/opensearch/index-templates/ - ///Request specific configuration such as querystring parameters & request specific connection settings. - public TResponse GetComponentTemplate(GetComponentTemplateRequestParameters requestParameters = null) - where TResponse : class, IOpenSearchResponse, new() => DoRequest(GET, "_component_template", null, RequestParams(requestParameters)); - ///GET on /_component_template https://opensearch.org/docs/latest/opensearch/index-templates/ - ///Request specific configuration such as querystring parameters & request specific connection settings. - [MapsApi("cluster.get_component_template", "")] - public Task GetComponentTemplateAsync(GetComponentTemplateRequestParameters requestParameters = null, CancellationToken ctx = default) - where TResponse : class, IOpenSearchResponse, new() => DoRequestAsync(GET, "_component_template", ctx, null, RequestParams(requestParameters)); - ///GET on /_component_template/{name} https://opensearch.org/docs/latest/opensearch/index-templates/ - ///The comma separated names of the component templates - ///Request specific configuration such as querystring parameters & request specific connection settings. - public TResponse GetComponentTemplate(string name, GetComponentTemplateRequestParameters requestParameters = null) - where TResponse : class, IOpenSearchResponse, new() => DoRequest(GET, Url($"_component_template/{name:name}"), null, RequestParams(requestParameters)); - ///GET on /_component_template/{name} https://opensearch.org/docs/latest/opensearch/index-templates/ - ///The comma separated names of the component templates - ///Request specific configuration such as querystring parameters & request specific connection settings. - [MapsApi("cluster.get_component_template", "name")] - public Task GetComponentTemplateAsync(string name, GetComponentTemplateRequestParameters requestParameters = null, CancellationToken ctx = default) - where TResponse : class, IOpenSearchResponse, new() => DoRequestAsync(GET, Url($"_component_template/{name:name}"), ctx, null, RequestParams(requestParameters)); ///GET on /_cluster/settings https://opensearch.org/docs/latest/opensearch/rest-api/cluster-settings/ ///Request specific configuration such as querystring parameters & request specific connection settings. public TResponse GetSettings(ClusterGetSettingsRequestParameters requestParameters = null) @@ -164,19 +118,6 @@ public TResponse PostVotingConfigExclusions(PostVotingConfigExclusion [MapsApi("cluster.post_voting_config_exclusions", "")] public Task PostVotingConfigExclusionsAsync(PostVotingConfigExclusionsRequestParameters requestParameters = null, CancellationToken ctx = default) where TResponse : class, IOpenSearchResponse, new() => DoRequestAsync(POST, "_cluster/voting_config_exclusions", ctx, null, RequestParams(requestParameters)); - ///PUT on /_component_template/{name} https://opensearch.org/docs/latest/opensearch/index-templates/ - ///The name of the template - ///The template definition - ///Request specific configuration such as querystring parameters & request specific connection settings. - public TResponse PutComponentTemplate(string name, PostData body, PutComponentTemplateRequestParameters requestParameters = null) - where TResponse : class, IOpenSearchResponse, new() => DoRequest(PUT, Url($"_component_template/{name:name}"), body, RequestParams(requestParameters)); - ///PUT on /_component_template/{name} https://opensearch.org/docs/latest/opensearch/index-templates/ - ///The name of the template - ///The template definition - ///Request specific configuration such as querystring parameters & request specific connection settings. - [MapsApi("cluster.put_component_template", "name, body")] - public Task PutComponentTemplateAsync(string name, PostData body, PutComponentTemplateRequestParameters requestParameters = null, CancellationToken ctx = default) - where TResponse : class, IOpenSearchResponse, new() => DoRequestAsync(PUT, Url($"_component_template/{name:name}"), ctx, body, RequestParams(requestParameters)); ///PUT on /_cluster/settings https://opensearch.org/docs/latest/opensearch/rest-api/cluster-settings/ ///The settings to be updated. Can be either `transient` or `persistent` (survives cluster restart). ///Request specific configuration such as querystring parameters & request specific connection settings. diff --git a/src/OpenSearch.Net/_Generated/Api/RequestParameters/RequestParameters.Cluster.cs b/src/OpenSearch.Net/_Generated/Api/RequestParameters/RequestParameters.Cluster.cs new file mode 100644 index 0000000000..4b6176a712 --- /dev/null +++ b/src/OpenSearch.Net/_Generated/Api/RequestParameters/RequestParameters.Cluster.cs @@ -0,0 +1,193 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ +/* +* Modifications Copyright OpenSearch Contributors. See +* GitHub history for details. +* +* 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. +*/ +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ----------------------------------------------- +// +// This file is automatically generated +// Please do not edit these files manually +// Run the following in the root of the repos: +// +// *NIX : ./build.sh codegen +// Windows : build.bat codegen +// +// ----------------------------------------------- + +// ReSharper disable RedundantUsingDirective +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Linq.Expressions; + +// ReSharper disable once CheckNamespace +namespace OpenSearch.Net.Specification.ClusterApi +{ + /// Request options for DeleteComponentTemplate https://opensearch.org/docs/latest + public partial class DeleteComponentTemplateRequestParameters + : RequestParameters + { + public override HttpMethod DefaultHttpMethod => HttpMethod.DELETE; + public override bool SupportsBody => false; + + /// Operation timeout for connection to cluster-manager node. + /// Supported by OpenSearch servers of version 2.0.0 or greater. + public TimeSpan ClusterManagerTimeout + { + get => Q("cluster_manager_timeout"); + set => Q("cluster_manager_timeout", value); + } + + /// Operation timeout for connection to master node. + [Obsolete( + "Deprecated as of: 2.0.0, reason: To promote inclusive language, use 'cluster_manager_timeout' instead." + )] + public TimeSpan MasterTimeout + { + get => Q("master_timeout"); + set => Q("master_timeout", value); + } + + /// Operation timeout. + public TimeSpan Timeout + { + get => Q("timeout"); + set => Q("timeout", value); + } + } + + /// Request options for ComponentTemplateExists https://opensearch.org/docs/latest + public partial class ComponentTemplateExistsRequestParameters + : RequestParameters + { + public override HttpMethod DefaultHttpMethod => HttpMethod.HEAD; + public override bool SupportsBody => false; + + /// Operation timeout for connection to cluster-manager node. + /// Supported by OpenSearch servers of version 2.0.0 or greater. + public TimeSpan ClusterManagerTimeout + { + get => Q("cluster_manager_timeout"); + set => Q("cluster_manager_timeout", value); + } + + /// Return local information, do not retrieve the state from cluster-manager node. + public bool? Local + { + get => Q("local"); + set => Q("local", value); + } + + /// Operation timeout for connection to master node. + [Obsolete( + "Deprecated as of: 2.0.0, reason: To promote inclusive language, use 'cluster_manager_timeout' instead." + )] + public TimeSpan MasterTimeout + { + get => Q("master_timeout"); + set => Q("master_timeout", value); + } + } + + /// Request options for GetComponentTemplate https://opensearch.org/docs/latest + public partial class GetComponentTemplateRequestParameters + : RequestParameters + { + public override HttpMethod DefaultHttpMethod => HttpMethod.GET; + public override bool SupportsBody => false; + + /// Operation timeout for connection to cluster-manager node. + /// Supported by OpenSearch servers of version 2.0.0 or greater. + public TimeSpan ClusterManagerTimeout + { + get => Q("cluster_manager_timeout"); + set => Q("cluster_manager_timeout", value); + } + + /// Return local information, do not retrieve the state from cluster-manager node. + public bool? Local + { + get => Q("local"); + set => Q("local", value); + } + + /// Operation timeout for connection to master node. + [Obsolete( + "Deprecated as of: 2.0.0, reason: To promote inclusive language, use 'cluster_manager_timeout' instead." + )] + public TimeSpan MasterTimeout + { + get => Q("master_timeout"); + set => Q("master_timeout", value); + } + } + + /// Request options for PutComponentTemplate + public partial class PutComponentTemplateRequestParameters + : RequestParameters + { + public override HttpMethod DefaultHttpMethod => HttpMethod.PUT; + public override bool SupportsBody => true; + + /// Operation timeout for connection to cluster-manager node. + /// Supported by OpenSearch servers of version 2.0.0 or greater. + public TimeSpan ClusterManagerTimeout + { + get => Q("cluster_manager_timeout"); + set => Q("cluster_manager_timeout", value); + } + + /// Whether the index template should only be added if new or can also replace an existing one. + public bool? Create + { + get => Q("create"); + set => Q("create", value); + } + + /// Operation timeout for connection to master node. + [Obsolete( + "Deprecated as of: 2.0.0, reason: To promote inclusive language, use 'cluster_manager_timeout' instead." + )] + public TimeSpan MasterTimeout + { + get => Q("master_timeout"); + set => Q("master_timeout", value); + } + + /// Operation timeout. + public TimeSpan Timeout + { + get => Q("timeout"); + set => Q("timeout", value); + } + } +} diff --git a/src/OpenSearch.Net/_Generated/OpenSearchLowLevelClient.Cluster.cs b/src/OpenSearch.Net/_Generated/OpenSearchLowLevelClient.Cluster.cs new file mode 100644 index 0000000000..74c7396fbf --- /dev/null +++ b/src/OpenSearch.Net/_Generated/OpenSearchLowLevelClient.Cluster.cs @@ -0,0 +1,237 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ +/* +* Modifications Copyright OpenSearch Contributors. See +* GitHub history for details. +* +* 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. +*/ +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ----------------------------------------------- +// +// This file is automatically generated +// Please do not edit these files manually +// Run the following in the root of the repos: +// +// *NIX : ./build.sh codegen +// Windows : build.bat codegen +// +// ----------------------------------------------- +// ReSharper disable RedundantUsingDirective +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using OpenSearch.Net; +using static OpenSearch.Net.HttpMethod; + +// ReSharper disable InterpolatedStringExpressionIsNotIFormattable +// ReSharper disable once CheckNamespace +// ReSharper disable InterpolatedStringExpressionIsNotIFormattable +// ReSharper disable RedundantExtendsListEntry +namespace OpenSearch.Net.Specification.ClusterApi +{ + /// + /// Cluster APIs. + /// Not intended to be instantiated directly. Use the property + /// on . + /// + /// + public partial class LowLevelClusterNamespace : NamespacedClientProxy + { + internal LowLevelClusterNamespace(OpenSearchLowLevelClient client) + : base(client) { } + + /// DELETE on /_component_template/{name} https://opensearch.org/docs/latest + /// The name of the template. + /// Request specific configuration such as querystring parameters & request specific connection settings. + public TResponse DeleteComponentTemplate( + string name, + DeleteComponentTemplateRequestParameters requestParameters = null + ) + where TResponse : class, IOpenSearchResponse, new() => + DoRequest( + DELETE, + Url($"_component_template/{name:name}"), + null, + RequestParams(requestParameters) + ); + + /// DELETE on /_component_template/{name} https://opensearch.org/docs/latest + /// The name of the template. + /// Request specific configuration such as querystring parameters & request specific connection settings. + [MapsApi("cluster.delete_component_template", "name")] + public Task DeleteComponentTemplateAsync( + string name, + DeleteComponentTemplateRequestParameters requestParameters = null, + CancellationToken ctx = default + ) + where TResponse : class, IOpenSearchResponse, new() => + DoRequestAsync( + DELETE, + Url($"_component_template/{name:name}"), + ctx, + null, + RequestParams(requestParameters) + ); + + /// HEAD on /_component_template/{name} https://opensearch.org/docs/latest + /// The name of the template. + /// Request specific configuration such as querystring parameters & request specific connection settings. + public TResponse ComponentTemplateExists( + string name, + ComponentTemplateExistsRequestParameters requestParameters = null + ) + where TResponse : class, IOpenSearchResponse, new() => + DoRequest( + HEAD, + Url($"_component_template/{name:name}"), + null, + RequestParams(requestParameters) + ); + + /// HEAD on /_component_template/{name} https://opensearch.org/docs/latest + /// The name of the template. + /// Request specific configuration such as querystring parameters & request specific connection settings. + [MapsApi("cluster.exists_component_template", "name")] + public Task ComponentTemplateExistsAsync( + string name, + ComponentTemplateExistsRequestParameters requestParameters = null, + CancellationToken ctx = default + ) + where TResponse : class, IOpenSearchResponse, new() => + DoRequestAsync( + HEAD, + Url($"_component_template/{name:name}"), + ctx, + null, + RequestParams(requestParameters) + ); + + /// GET on /_component_template https://opensearch.org/docs/latest + /// Request specific configuration such as querystring parameters & request specific connection settings. + public TResponse GetComponentTemplate( + GetComponentTemplateRequestParameters requestParameters = null + ) + where TResponse : class, IOpenSearchResponse, new() => + DoRequest( + GET, + "_component_template", + null, + RequestParams(requestParameters) + ); + + /// GET on /_component_template https://opensearch.org/docs/latest + /// Request specific configuration such as querystring parameters & request specific connection settings. + [MapsApi("cluster.get_component_template", "")] + public Task GetComponentTemplateAsync( + GetComponentTemplateRequestParameters requestParameters = null, + CancellationToken ctx = default + ) + where TResponse : class, IOpenSearchResponse, new() => + DoRequestAsync( + GET, + "_component_template", + ctx, + null, + RequestParams(requestParameters) + ); + + /// GET on /_component_template/{name} https://opensearch.org/docs/latest + /// The Comma-separated names of the component templates. + /// Request specific configuration such as querystring parameters & request specific connection settings. + public TResponse GetComponentTemplate( + string name, + GetComponentTemplateRequestParameters requestParameters = null + ) + where TResponse : class, IOpenSearchResponse, new() => + DoRequest( + GET, + Url($"_component_template/{name:name}"), + null, + RequestParams(requestParameters) + ); + + /// GET on /_component_template/{name} https://opensearch.org/docs/latest + /// The Comma-separated names of the component templates. + /// Request specific configuration such as querystring parameters & request specific connection settings. + [MapsApi("cluster.get_component_template", "name")] + public Task GetComponentTemplateAsync( + string name, + GetComponentTemplateRequestParameters requestParameters = null, + CancellationToken ctx = default + ) + where TResponse : class, IOpenSearchResponse, new() => + DoRequestAsync( + GET, + Url($"_component_template/{name:name}"), + ctx, + null, + RequestParams(requestParameters) + ); + + /// PUT on /_component_template/{name} + /// The name of the template. + /// The template definition + /// Request specific configuration such as querystring parameters & request specific connection settings. + public TResponse PutComponentTemplate( + string name, + PostData body, + PutComponentTemplateRequestParameters requestParameters = null + ) + where TResponse : class, IOpenSearchResponse, new() => + DoRequest( + PUT, + Url($"_component_template/{name:name}"), + body, + RequestParams(requestParameters) + ); + + /// PUT on /_component_template/{name} + /// The name of the template. + /// The template definition + /// Request specific configuration such as querystring parameters & request specific connection settings. + [MapsApi("cluster.put_component_template", "name, body")] + public Task PutComponentTemplateAsync( + string name, + PostData body, + PutComponentTemplateRequestParameters requestParameters = null, + CancellationToken ctx = default + ) + where TResponse : class, IOpenSearchResponse, new() => + DoRequestAsync( + PUT, + Url($"_component_template/{name:name}"), + ctx, + body, + RequestParams(requestParameters) + ); + } +} diff --git a/tests/Tests/Cluster/ComponentTemplate/ComponentTemplateCrudTests.cs b/tests/Tests/Cluster/ComponentTemplate/ComponentTemplateCrudTests.cs new file mode 100644 index 0000000000..c02c0f3c56 --- /dev/null +++ b/tests/Tests/Cluster/ComponentTemplate/ComponentTemplateCrudTests.cs @@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using OpenSearch.Client; +using Tests.Core.Extensions; +using Tests.Core.ManagedOpenSearch.Clusters; +using Tests.Framework.EndpointTests; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.Cluster.ComponentTemplate; + +public class ComponentTemplateCrudTests + : CrudTestBase +{ + public ComponentTemplateCrudTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override LazyResponses Exists() => + Calls( + id => new ComponentTemplateExistsRequest(id), + (id, d) => d, + (s, c, f) => c.Cluster.ComponentTemplateExists(s, f), + (s, c, f) => c.Cluster.ComponentTemplateExistsAsync(s, f), + (s, c, r) => c.Cluster.ComponentTemplateExists(r), + (s, c, r) => c.Cluster.ComponentTemplateExistsAsync(r) + ); + + protected override LazyResponses Create() => + Calls( + CreateInitializer, + CreateFluent, + (s, c, f) => c.Cluster.PutComponentTemplate(s, f), + (s, c, f) => c.Cluster.PutComponentTemplateAsync(s, f), + (s, c, r) => c.Cluster.PutComponentTemplate(r), + (s, c, r) => c.Cluster.PutComponentTemplateAsync(r) + ); + + private PutComponentTemplateRequest CreateInitializer(string name) => new(name) + { + Version = 42, + Template = new Template + { + Settings = new IndexSettings + { + NumberOfShards = 2 + } + } + }; + + private IPutComponentTemplateRequest CreateFluent(string name, PutComponentTemplateDescriptor d) => d + .Version(42) + .Template(t => t + .Settings(s => s + .NumberOfShards(2))); + + protected override LazyResponses Read() => + Calls( + name => new GetComponentTemplateRequest(name), + (name, d) => d.Name(name), + (s, c, f) => c.Cluster.GetComponentTemplate(s, f), + (s, c, f) => c.Cluster.GetComponentTemplateAsync(s, f), + (s, c, r) => c.Cluster.GetComponentTemplate(r), + (s, c, r) => c.Cluster.GetComponentTemplateAsync(r) + ); + + protected override void ExpectAfterCreate(GetComponentTemplateResponse response) + { + response.ComponentTemplates.Should().NotBeNull().And.HaveCount(1); + var template = response.ComponentTemplates.First().ComponentTemplate; + template.Version.Should().Be(42); + template.Template.Should().NotBeNull(); + template.Template.Settings.Should().NotBeNull().And.NotBeEmpty(); + template.Template.Settings.NumberOfShards.Should().Be(2); + } + + protected override LazyResponses Update() => + Calls( + PutInitializer, + PutFluent, + (s, c, f) => c.Cluster.PutComponentTemplate(s, f), + (s, c, f) => c.Cluster.PutComponentTemplateAsync(s, f), + (s, c, r) => c.Cluster.PutComponentTemplate(r), + (s, c, r) => c.Cluster.PutComponentTemplateAsync(r) + ); + + private PutComponentTemplateRequest PutInitializer(string name) => new(name) + { + Version = 84, + Template = new Template + { + Settings = new IndexSettings + { + NumberOfShards = 1 + } + } + }; + + private IPutComponentTemplateRequest PutFluent(string name, PutComponentTemplateDescriptor d) => d + .Version(84) + .Template(t => t + .Settings(s => s + .NumberOfShards(1))); + + protected override void ExpectAfterUpdate(GetComponentTemplateResponse response) + { + response.ComponentTemplates.Should().NotBeNull().And.HaveCount(1); + var template = response.ComponentTemplates.First().ComponentTemplate; + template.Version.Should().Be(84); + template.Template.Should().NotBeNull(); + template.Template.Settings.Should().NotBeNull().And.NotBeEmpty(); + template.Template.Settings.NumberOfShards.Should().Be(1); + } + + protected override LazyResponses Delete() => + Calls( + name => new DeleteComponentTemplateRequest(name), + (name, d) => d, + (s, c, f) => c.Cluster.DeleteComponentTemplate(s, f), + (s, c, f) => c.Cluster.DeleteComponentTemplateAsync(s, f), + (s, c, r) => c.Cluster.DeleteComponentTemplate(r), + (s, c, r) => c.Cluster.DeleteComponentTemplateAsync(r) + ); + + protected override async Task GetAfterDeleteIsValid() => await AssertOnGetAfterDelete(r => r.ShouldNotBeValid()); + + protected override void ExpectDeleteNotFoundResponse(DeleteComponentTemplateResponse response) + { + response.ServerError.Should().NotBeNull(); + response.ServerError.Status.Should().Be(404); + response.ServerError.Error.Reason.Should().Contain("missing"); + } +} diff --git a/tests/Tests/Cluster/ComponentTemplate/ComponentTemplateExistsApiTests.cs b/tests/Tests/Cluster/ComponentTemplate/ComponentTemplateExistsApiTests.cs new file mode 100644 index 0000000000..4c868c11c4 --- /dev/null +++ b/tests/Tests/Cluster/ComponentTemplate/ComponentTemplateExistsApiTests.cs @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System; +using OpenSearch.Client; +using OpenSearch.Net; +using Tests.Core.ManagedOpenSearch.Clusters; +using Tests.Framework.EndpointTests; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.Cluster.ComponentTemplate; + +public class ComponentTemplateExistsApiTests + : ApiTestBase +{ + public ComponentTemplateExistsApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override Func Fluent => d => d; + + protected override HttpMethod HttpMethod => HttpMethod.HEAD; + + protected override ComponentTemplateExistsRequest Initializer => new(CallIsolatedValue); + protected override string UrlPath => $"/_component_template/{CallIsolatedValue}"; + + protected override LazyResponses ClientUsage() => Calls( + (client, f) => client.Cluster.ComponentTemplateExists(CallIsolatedValue, f), + (client, f) => client.Cluster.ComponentTemplateExistsAsync(CallIsolatedValue, f), + (client, r) => client.Cluster.ComponentTemplateExists(r), + (client, r) => client.Cluster.ComponentTemplateExistsAsync(r) + ); + + protected override ComponentTemplateExistsDescriptor NewDescriptor() => new(CallIsolatedValue); +} diff --git a/tests/Tests/Cluster/ComponentTemplate/ComponentTemplateExistsUrlTests.cs b/tests/Tests/Cluster/ComponentTemplate/ComponentTemplateExistsUrlTests.cs new file mode 100644 index 0000000000..5d267ee1c3 --- /dev/null +++ b/tests/Tests/Cluster/ComponentTemplate/ComponentTemplateExistsUrlTests.cs @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System.Threading.Tasks; +using OpenSearch.Client; +using OpenSearch.OpenSearch.Xunit.XunitPlumbing; +using Tests.Framework.EndpointTests; +using static Tests.Framework.EndpointTests.UrlTester; + +namespace Tests.Cluster.ComponentTemplate; + +public class ComponentTemplateExistsUrlTests +{ + [U] public async Task Urls() + { + var name = "temp"; + await HEAD($"/_component_template/{name}") + .Fluent(c => c.Cluster.ComponentTemplateExists(name)) + .Request(c => c.Cluster.ComponentTemplateExists(new ComponentTemplateExistsRequest(name))) + .FluentAsync(c => c.Cluster.ComponentTemplateExistsAsync(name)) + .RequestAsync(c => c.Cluster.ComponentTemplateExistsAsync(new ComponentTemplateExistsRequest(name))) + ; + } +} diff --git a/tests/Tests/Cluster/ComponentTemplate/DeleteComponentTemplateApiTests.cs b/tests/Tests/Cluster/ComponentTemplate/DeleteComponentTemplateApiTests.cs new file mode 100644 index 0000000000..7a855d10de --- /dev/null +++ b/tests/Tests/Cluster/ComponentTemplate/DeleteComponentTemplateApiTests.cs @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System; +using OpenSearch.Client; +using OpenSearch.Net; +using Tests.Core.ManagedOpenSearch.Clusters; +using Tests.Framework.EndpointTests; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.Cluster.ComponentTemplate; + +public class DeleteComponentTemplateApiTests + : ApiTestBase +{ + public DeleteComponentTemplateApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override Func Fluent => d => d; + protected override HttpMethod HttpMethod => HttpMethod.DELETE; + protected override DeleteComponentTemplateRequest Initializer => new(CallIsolatedValue); + protected override string UrlPath => $"/_component_template/{CallIsolatedValue}"; + + protected override LazyResponses ClientUsage() => Calls( + (client, f) => client.Cluster.DeleteComponentTemplate(CallIsolatedValue, f), + (client, f) => client.Cluster.DeleteComponentTemplateAsync(CallIsolatedValue, f), + (client, r) => client.Cluster.DeleteComponentTemplate(r), + (client, r) => client.Cluster.DeleteComponentTemplateAsync(r) + ); + + protected override DeleteComponentTemplateDescriptor NewDescriptor() => new(CallIsolatedValue); +} diff --git a/tests/Tests/Cluster/ComponentTemplate/DeleteComponentTemplateUrlTests.cs b/tests/Tests/Cluster/ComponentTemplate/DeleteComponentTemplateUrlTests.cs new file mode 100644 index 0000000000..fc1d67d33c --- /dev/null +++ b/tests/Tests/Cluster/ComponentTemplate/DeleteComponentTemplateUrlTests.cs @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System.Threading.Tasks; +using OpenSearch.Client; +using OpenSearch.OpenSearch.Xunit.XunitPlumbing; +using Tests.Framework.EndpointTests; +using static Tests.Framework.EndpointTests.UrlTester; + +namespace Tests.Cluster.ComponentTemplate; + +public class DeleteComponentTemplateUrlTests +{ + [U] public async Task Urls() + { + var name = "temp"; + await DELETE($"/_component_template/{name}") + .Fluent(c => c.Cluster.DeleteComponentTemplate(name)) + .Request(c => c.Cluster.DeleteComponentTemplate(new DeleteComponentTemplateRequest(name))) + .FluentAsync(c => c.Cluster.DeleteComponentTemplateAsync(name)) + .RequestAsync(c => c.Cluster.DeleteComponentTemplateAsync(new DeleteComponentTemplateRequest(name))) + ; + } +} diff --git a/tests/Tests/Cluster/ComponentTemplate/GetComponentTemplateApiTests.cs b/tests/Tests/Cluster/ComponentTemplate/GetComponentTemplateApiTests.cs new file mode 100644 index 0000000000..f7b1c05d42 --- /dev/null +++ b/tests/Tests/Cluster/ComponentTemplate/GetComponentTemplateApiTests.cs @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System; +using System.Linq; +using FluentAssertions; +using OpenSearch.Client; +using OpenSearch.Net; +using Tests.Core.Extensions; +using Tests.Core.ManagedOpenSearch.Clusters; +using Tests.Framework.EndpointTests; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.Cluster.ComponentTemplate; + +public class GetComponentTemplateApiTests + : ApiIntegrationTestBase +{ + public GetComponentTemplateApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override bool ExpectIsValid => true; + protected override object ExpectJson => null; + protected override int ExpectStatusCode => 200; + protected override HttpMethod HttpMethod => HttpMethod.GET; + protected override string UrlPath => $"/_component_template/{CallIsolatedValue}"; + + protected override GetComponentTemplateRequest Initializer => new(CallIsolatedValue); + + protected override LazyResponses ClientUsage() => Calls( + (client, f) => client.Cluster.GetComponentTemplate(CallIsolatedValue, f), + (client, f) => client.Cluster.GetComponentTemplateAsync(CallIsolatedValue, f), + (client, r) => client.Cluster.GetComponentTemplate(r), + (client, r) => client.Cluster.GetComponentTemplateAsync(r) + ); + + protected override void IntegrationSetup(IOpenSearchClient client, CallUniqueValues values) + { + foreach (var callUniqueValue in values) + { + var putTemplateResponse = client.Cluster.PutComponentTemplate(callUniqueValue.Value, d => d + .Template(t => t + .Settings(s => s.NumberOfShards(2))) + .Version(1) + ); + + if (!putTemplateResponse.IsValid) + throw new Exception($"Problem putting index template for integration test: {putTemplateResponse.DebugInformation}"); + } + } + + protected override void ExpectResponse(GetComponentTemplateResponse response) + { + response.ShouldBeValid(); + + response.ComponentTemplates.Should().NotBeNull().And.HaveCount(1); + + var componentTemplate = response.ComponentTemplates.First(); + + componentTemplate.Name.Should().Be(CallIsolatedValue); + + componentTemplate.ComponentTemplate.Should().NotBeNull(); + + componentTemplate.ComponentTemplate.Version.Should().Be(1); + + componentTemplate.ComponentTemplate.Template.Should().NotBeNull(); + componentTemplate.ComponentTemplate.Template.Settings.Should().NotBeNull(); + componentTemplate.ComponentTemplate.Template.Settings.NumberOfShards.Should().Be(2); + } +} diff --git a/tests/Tests/Cluster/ComponentTemplate/GetComponentTemplateUrlTests.cs b/tests/Tests/Cluster/ComponentTemplate/GetComponentTemplateUrlTests.cs new file mode 100644 index 0000000000..4eeb11d198 --- /dev/null +++ b/tests/Tests/Cluster/ComponentTemplate/GetComponentTemplateUrlTests.cs @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System.Threading.Tasks; +using OpenSearch.Client; +using OpenSearch.OpenSearch.Xunit.XunitPlumbing; +using Tests.Framework.EndpointTests; +using static Tests.Framework.EndpointTests.UrlTester; + +namespace Tests.Cluster.ComponentTemplate; + +public class GetComponentTemplateUrlTests +{ + [U] public async Task Urls() + { + var name = "temp"; + await GET($"/_component_template/{name}") + .Fluent(c => c.Cluster.GetComponentTemplate(name)) + .Request(c => c.Cluster.GetComponentTemplate(new GetComponentTemplateRequest(name))) + .FluentAsync(c => c.Cluster.GetComponentTemplateAsync(name)) + .RequestAsync(c => c.Cluster.GetComponentTemplateAsync(new GetComponentTemplateRequest(name))) + ; + + await GET($"/_component_template") + .Fluent(c => c.Cluster.GetComponentTemplate()) + .Request(c => c.Cluster.GetComponentTemplate(new GetComponentTemplateRequest())) + .FluentAsync(c => c.Cluster.GetComponentTemplateAsync()) + .RequestAsync(c => c.Cluster.GetComponentTemplateAsync(new GetComponentTemplateRequest())) + ; + } +} diff --git a/tests/Tests/Cluster/ComponentTemplate/PutComponentTemplateApiTests.cs b/tests/Tests/Cluster/ComponentTemplate/PutComponentTemplateApiTests.cs new file mode 100644 index 0000000000..f125ba72b6 --- /dev/null +++ b/tests/Tests/Cluster/ComponentTemplate/PutComponentTemplateApiTests.cs @@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System; +using System.Collections.Generic; +using FluentAssertions; +using OpenSearch.Client; +using OpenSearch.Net; +using Tests.Core.Extensions; +using Tests.Core.ManagedOpenSearch.Clusters; +using Tests.Framework.EndpointTests; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.Cluster.ComponentTemplate; + +public class PutComponentTemplateApiTests + : ApiIntegrationTestBase +{ + public PutComponentTemplateApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override bool ExpectIsValid => true; + + protected override object ExpectJson { get; } = new + { + version = 2, + template = new + { + settings = new Dictionary { { "index.number_of_shards", 1 } }, + mappings = new + { + dynamic_templates = new object[] + { + new + { + @base = new + { + match = "*", + match_mapping_type = "*", + mapping = new + { + index = false + } + } + } + } + } + } + }; + + protected override int ExpectStatusCode => 200; + + protected override Func Fluent => d => d + .Version(2) + .Create(false) + .Template(t => t + .Settings(p => p.NumberOfShards(1)) + .Map(tm => tm + .DynamicTemplates(dts => dts + .DynamicTemplate("base", dt => dt + .Match("*") + .MatchMappingType("*") + .Mapping(mm => mm + .Generic(g => g + .Index(false))))))); + + protected override HttpMethod HttpMethod => HttpMethod.PUT; + + protected override PutComponentTemplateRequest Initializer => new(CallIsolatedValue) + { + Version = 2, + Create = false, + Template = new Template + { + Settings = new IndexSettings + { + NumberOfShards = 1 + }, + Mappings = new TypeMapping + { + DynamicTemplates = new DynamicTemplateContainer + { + { "base", new DynamicTemplate + { + Match = "*", + MatchMappingType = "*", + Mapping = new GenericProperty { Index = false } + } } + } + } + } + }; + + protected override bool SupportsDeserialization => false; + protected override string UrlPath => $"/_component_template/{CallIsolatedValue}?create=false"; + + protected override LazyResponses ClientUsage() => Calls( + (client, f) => client.Cluster.PutComponentTemplate(CallIsolatedValue, f), + (client, f) => client.Cluster.PutComponentTemplateAsync(CallIsolatedValue, f), + (client, r) => client.Cluster.PutComponentTemplate(r), + (client, r) => client.Cluster.PutComponentTemplateAsync(r) + ); + + protected override PutComponentTemplateDescriptor NewDescriptor() => new(CallIsolatedValue); + + protected override void ExpectResponse(PutComponentTemplateResponse response) + { + response.ShouldBeValid(); + response.Acknowledged.Should().BeTrue(); + } +} diff --git a/tests/Tests/Cluster/ComponentTemplate/PutComponentTemplateUrlTests.cs b/tests/Tests/Cluster/ComponentTemplate/PutComponentTemplateUrlTests.cs new file mode 100644 index 0000000000..465a698ca3 --- /dev/null +++ b/tests/Tests/Cluster/ComponentTemplate/PutComponentTemplateUrlTests.cs @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +using System.Threading.Tasks; +using OpenSearch.Client; +using OpenSearch.OpenSearch.Xunit.XunitPlumbing; +using Tests.Framework.EndpointTests; +using static Tests.Framework.EndpointTests.UrlTester; + +namespace Tests.Cluster.ComponentTemplate; + +public class PutComponentTemplateUrlTests +{ + [U] public async Task Urls() + { + var name = "temp"; + await PUT($"/_component_template/{name}") + .Fluent(c => c.Cluster.PutComponentTemplate(name, p => p)) + .Request(c => c.Cluster.PutComponentTemplate(new PutComponentTemplateRequest(name))) + .FluentAsync(c => c.Cluster.PutComponentTemplateAsync(name, p => p)) + .RequestAsync(c => c.Cluster.PutComponentTemplateAsync(new PutComponentTemplateRequest(name))) + ; + } +} diff --git a/tests/Tests/CodeStandards/NamingConventions.doc.cs b/tests/Tests/CodeStandards/NamingConventions.doc.cs index 0bde174e53..ab357fa340 100644 --- a/tests/Tests/CodeStandards/NamingConventions.doc.cs +++ b/tests/Tests/CodeStandards/NamingConventions.doc.cs @@ -141,6 +141,7 @@ public void ParityBetweenRequestsAndResponses() typeof(IndexExistsRequest), typeof(TypeExistsRequest), typeof(IndexTemplateExistsRequest), + typeof(ComponentTemplateExistsRequest), typeof(SearchTemplateRequest), typeof(SearchTemplateRequest<>), typeof(ScrollRequest), diff --git a/tests/Tests/Tests.csproj b/tests/Tests/Tests.csproj index ee1d103e08..50a9911226 100644 --- a/tests/Tests/Tests.csproj +++ b/tests/Tests/Tests.csproj @@ -5,6 +5,7 @@ $(NoWarn);xUnit1013 True True + latest