From fbd850da531e277f296d8869eeb31301bf08de00 Mon Sep 17 00:00:00 2001 From: Yury Fridlyand Date: Wed, 8 Jun 2022 17:01:45 -0700 Subject: [PATCH] Rename `master` node role to `cluster_manager` as it was done in OpenSearch. Ref: https://github.com/opensearch-project/OpenSearch/issues/2480 Signed-off-by: Yury Fridlyand --- .../Core/cat.cluster_manager.json | 69 ++++++++++++++++++ .../CatClusterManagerRecord.cs | 44 +++++++++++ .../CatClusterManagerRequest.cs | 36 +++++++++ .../Cat/CatNodes/CatNodesRecord.cs | 7 ++ .../Cluster/ClusterStats/ClusterNodesStats.cs | 3 + .../Cluster/NodesInfo/NodeRole.cs | 3 + src/OpenSearch.Client/Descriptors.Cat.cs | 31 +++++++- src/OpenSearch.Client/OpenSearchClient.Cat.cs | 28 +++++++ src/OpenSearch.Client/Requests.Cat.cs | 73 ++++++++++++++++++- .../_Generated/ApiUrlsLookup.generated.cs | 1 + .../RequestParameters.Cat.cs | 68 ++++++++++++++++- .../OpenSearchLowLevelClient.Cat.cs | 9 +++ .../CatClusterManagerApiTests.cs | 59 +++++++++++++++ .../CatClusterManagerUrlTests.cs | 44 +++++++++++ .../Tests/Cat/CatMaster/CatMasterApiTests.cs | 2 + .../ClusterStats/ClusterStatsApiTests.cs | 1 + 16 files changed, 475 insertions(+), 3 deletions(-) create mode 100644 src/ApiGenerator/RestSpecification/Core/cat.cluster_manager.json create mode 100644 src/OpenSearch.Client/Cat/CatClusterManager/CatClusterManagerRecord.cs create mode 100644 src/OpenSearch.Client/Cat/CatClusterManager/CatClusterManagerRequest.cs create mode 100644 tests/Tests/Cat/CatClusterManager/CatClusterManagerApiTests.cs create mode 100644 tests/Tests/Cat/CatClusterManager/CatClusterManagerUrlTests.cs diff --git a/src/ApiGenerator/RestSpecification/Core/cat.cluster_manager.json b/src/ApiGenerator/RestSpecification/Core/cat.cluster_manager.json new file mode 100644 index 0000000000..cd96038ad0 --- /dev/null +++ b/src/ApiGenerator/RestSpecification/Core/cat.cluster_manager.json @@ -0,0 +1,69 @@ +{ + "cat.cluster_manager":{ + "documentation":{ + "url":"https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-master/", + "description":"Returns information about the cluster-manager node." + }, + "stability":"stable", + "url":{ + "paths":[ + { + "path":"/_cat/cluster_manager", + "methods":[ + "GET" + ] + }, + { + "path":"/_cat/master", + "methods":[ + "GET" + ], + "deprecated":{ + "version":"2.0.0", + "description":"To promote inclusive language, please use '/_cat/cluster_manager' instead." + } + } + ] + }, + "params":{ + "format":{ + "type":"string", + "description":"a short version of the Accept header, e.g. json, yaml" + }, + "local":{ + "type":"boolean", + "description":"Return local information, do not retrieve the state from cluster-manager node (default: false)" + }, + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node", + "deprecated":{ + "version":"2.0.0", + "description":"To promote inclusive language, use 'cluster_manager_timeout' instead." + } + }, + "cluster_manager_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to cluster-manager node" + }, + "h":{ + "type":"list", + "description":"Comma-separated list of column names to display" + }, + "help":{ + "type":"boolean", + "description":"Return help information", + "default":false + }, + "s":{ + "type":"list", + "description":"Comma-separated list of column names or column aliases to sort by" + }, + "v":{ + "type":"boolean", + "description":"Verbose mode. Display column headers", + "default":false + } + } + } +} diff --git a/src/OpenSearch.Client/Cat/CatClusterManager/CatClusterManagerRecord.cs b/src/OpenSearch.Client/Cat/CatClusterManager/CatClusterManagerRecord.cs new file mode 100644 index 0000000000..1f1717190b --- /dev/null +++ b/src/OpenSearch.Client/Cat/CatClusterManager/CatClusterManagerRecord.cs @@ -0,0 +1,44 @@ +/* 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. +*/ + +using System.Runtime.Serialization; + +namespace OpenSearch.Client +{ + [DataContract] + public class CatClusterManagerRecord : ICatRecord + { + [DataMember(Name ="id")] + public string Id { get; set; } + + [DataMember(Name ="ip")] + public string Ip { get; set; } + + [DataMember(Name ="node")] + public string Node { get; set; } + } +} diff --git a/src/OpenSearch.Client/Cat/CatClusterManager/CatClusterManagerRequest.cs b/src/OpenSearch.Client/Cat/CatClusterManager/CatClusterManagerRequest.cs new file mode 100644 index 0000000000..9b253256fd --- /dev/null +++ b/src/OpenSearch.Client/Cat/CatClusterManager/CatClusterManagerRequest.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. +* +* 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. +*/ + +namespace OpenSearch.Client +{ + [MapsApi("cat.cluster_manager.json")] + public partial interface ICatClusterManagerRequest { } + + public partial class CatClusterManagerRequest { } + + public partial class CatClusterManagerDescriptor { } +} diff --git a/src/OpenSearch.Client/Cat/CatNodes/CatNodesRecord.cs b/src/OpenSearch.Client/Cat/CatNodes/CatNodesRecord.cs index 95011ee750..71a3cb84d2 100644 --- a/src/OpenSearch.Client/Cat/CatNodes/CatNodesRecord.cs +++ b/src/OpenSearch.Client/Cat/CatNodes/CatNodesRecord.cs @@ -33,6 +33,7 @@ namespace OpenSearch.Client public class CatNodesRecord : ICatRecord { public string Build => _b ?? _build; + public string ClusterManager => _cm ?? _cluster_manager; public string CompletionSize => _completionSize ?? _cs ?? _completion_size; [DataMember(Name ="cpu")] @@ -125,6 +126,12 @@ public class CatNodesRecord : ICatRecord [DataMember(Name ="build")] internal string _build { get; set; } + [DataMember(Name ="cm")] + internal string _cm { get; set; } + + [DataMember(Name ="cluster_manager")] + internal string _cluster_manager { get; set; } + [DataMember(Name ="completion.size")] internal string _completion_size { get; set; } diff --git a/src/OpenSearch.Client/Cluster/ClusterStats/ClusterNodesStats.cs b/src/OpenSearch.Client/Cluster/ClusterStats/ClusterNodesStats.cs index 5cefeb7ddf..749580b1f2 100644 --- a/src/OpenSearch.Client/Cluster/ClusterStats/ClusterNodesStats.cs +++ b/src/OpenSearch.Client/Cluster/ClusterStats/ClusterNodesStats.cs @@ -237,6 +237,9 @@ public class ClusterOperatingSystemName [DataContract] public class ClusterNodeCount { + [DataMember(Name = "cluster_manager")] + public int ClusterManager { get; internal set; } + [DataMember(Name = "coordinating_only")] public int CoordinatingOnly { get; internal set; } diff --git a/src/OpenSearch.Client/Cluster/NodesInfo/NodeRole.cs b/src/OpenSearch.Client/Cluster/NodesInfo/NodeRole.cs index c240f4cd86..5c4cf6ecf5 100644 --- a/src/OpenSearch.Client/Cluster/NodesInfo/NodeRole.cs +++ b/src/OpenSearch.Client/Cluster/NodesInfo/NodeRole.cs @@ -36,6 +36,9 @@ public enum NodeRole [EnumMember(Value = "master")] Master, + [EnumMember(Value = "cluster_manager")] + ClusterManager, + [EnumMember(Value = "data")] Data, diff --git a/src/OpenSearch.Client/Descriptors.Cat.cs b/src/OpenSearch.Client/Descriptors.Cat.cs index b515cb7789..296e346c5e 100644 --- a/src/OpenSearch.Client/Descriptors.Cat.cs +++ b/src/OpenSearch.Client/Descriptors.Cat.cs @@ -286,7 +286,11 @@ public CatIndicesDescriptor Index() public CatIndicesDescriptor Verbose(bool? verbose = true) => Qs("v", verbose); } - ///Descriptor for Master https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-master/ + /// + /// Descriptor for Master + /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-master/ + /// Replaced by in OpenSearch 2.0 + /// public partial class CatMasterDescriptor : RequestDescriptorBase, ICatMasterRequest { internal override ApiUrls ApiUrls => ApiUrlsLookups.CatMaster; @@ -308,6 +312,31 @@ public partial class CatMasterDescriptor : RequestDescriptorBase Qs("v", verbose); } + /// + /// Descriptor for cluster_manager + /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-cluster_manager/ + /// + public partial class CatClusterManagerDescriptor : RequestDescriptorBase, ICatClusterManagerRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.CatClusterManager; + // values part of the url path + // Request parameters + ///a short version of the Accept header, e.g. json, yaml + public CatClusterManagerDescriptor Format(string format) => Qs("format", format); + ///Comma-separated list of column names to display + public CatClusterManagerDescriptor Headers(params string[] headers) => Qs("h", headers); + ///Return help information + public CatClusterManagerDescriptor Help(bool? help = true) => Qs("help", help); + ///Return local information, do not retrieve the state from master node (default: false) + public CatClusterManagerDescriptor Local(bool? local = true) => Qs("local", local); + ///Explicit operation timeout for connection to master node + public CatClusterManagerDescriptor ClusterManagerTimeout(Time mastertimeout) => Qs("cluster_manager_timeout", mastertimeout); + ///Comma-separated list of column names or column aliases to sort by + public CatClusterManagerDescriptor SortByColumns(params string[] sortbycolumns) => Qs("s", sortbycolumns); + ///Verbose mode. Display column headers + public CatClusterManagerDescriptor Verbose(bool? verbose = true) => Qs("v", verbose); + } + ///Descriptor for NodeAttributes https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-nodeattrs/ public partial class CatNodeAttributesDescriptor : RequestDescriptorBase, ICatNodeAttributesRequest { diff --git a/src/OpenSearch.Client/OpenSearchClient.Cat.cs b/src/OpenSearch.Client/OpenSearchClient.Cat.cs index b2a797a361..94578e0816 100644 --- a/src/OpenSearch.Client/OpenSearchClient.Cat.cs +++ b/src/OpenSearch.Client/OpenSearchClient.Cat.cs @@ -234,27 +234,55 @@ internal CatNamespace(OpenSearchClient client): base(client) /// GET request to the cat.master API, read more about this API online: /// /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-master/ + /// Replaced by in OpenSearch 2.0 /// public CatResponse Master(Func selector = null) => Master(selector.InvokeOrDefault(new CatMasterDescriptor())); /// /// GET request to the cat.master API, read more about this API online: /// /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-master/ + /// Replaced by in OpenSearch 2.0 /// public Task> MasterAsync(Func selector = null, CancellationToken ct = default) => MasterAsync(selector.InvokeOrDefault(new CatMasterDescriptor()), ct); /// /// GET request to the cat.master API, read more about this API online: /// /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-master/ + /// Replaced by in OpenSearch 2.0 /// public CatResponse Master(ICatMasterRequest request) => DoCat(request); /// /// GET request to the cat.master API, read more about this API online: /// /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-master/ + /// Replaced by in OpenSearch 2.0 /// public Task> MasterAsync(ICatMasterRequest request, CancellationToken ct = default) => DoCatAsync(request, ct); /// + /// GET request to the cat.cluster_manager API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-cluster_manager/ + /// + public CatResponse ClusterManager(Func selector = null) => ClusterManager(selector.InvokeOrDefault(new CatClusterManagerDescriptor())); + /// + /// GET request to the cat.cluster_manager API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-cluster_manager/ + /// + public Task> ClusterManagerAsync(Func selector = null, CancellationToken ct = default) => ClusterManagerAsync(selector.InvokeOrDefault(new CatClusterManagerDescriptor()), ct); + /// + /// GET request to the cat.cluster_manager API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-cluster_manager/ + /// + public CatResponse ClusterManager(ICatClusterManagerRequest request) => DoCat(request); + /// + /// GET request to the cat.cluster_manager API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-cluster_manager/ + /// + public Task> ClusterManagerAsync(ICatClusterManagerRequest request, CancellationToken ct = default) => DoCatAsync(request, ct); + /// /// GET request to the cat.nodeattrs API, read more about this API online: /// /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-nodeattrs/ diff --git a/src/OpenSearch.Client/Requests.Cat.cs b/src/OpenSearch.Client/Requests.Cat.cs index 902b6f09f1..53ac454cb3 100644 --- a/src/OpenSearch.Client/Requests.Cat.cs +++ b/src/OpenSearch.Client/Requests.Cat.cs @@ -589,7 +589,10 @@ public partial interface ICatMasterRequest : IRequestRequest for Master https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-master/ + /// Request for Master + /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-master/ + /// Replaced by in OpenSearch 2.0 + /// public partial class CatMasterRequest : PlainRequestBase, ICatMasterRequest { protected ICatMasterRequest Self => this; @@ -650,6 +653,74 @@ public bool? Verbose } } + [InterfaceDataContract] + public partial interface ICatClusterManagerRequest : IRequest + { + } + + /// Request for ClusterManager + /// https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-cluster_manager/ + /// + public partial class CatClusterManagerRequest : PlainRequestBase, ICatClusterManagerRequest + { + protected ICatClusterManagerRequest Self => this; + internal override ApiUrls ApiUrls => ApiUrlsLookups.CatClusterManager; + // values part of the url path + // Request parameters + ///a short version of the Accept header, e.g. json, yaml + public string Format + { + get => Q("format"); + set + { + Q("format", value); + SetAcceptHeader(value); + } + } + + ///Comma-separated list of column names to display + public string[] Headers + { + get => Q("h"); + set => Q("h", value); + } + + ///Return help information + public bool? Help + { + get => Q("help"); + set => Q("help", value); + } + + ///Return local information, do not retrieve the state from cluster_manager node (default: false) + public bool? Local + { + get => Q("local"); + set => Q("local", value); + } + + ///Explicit operation timeout for connection to cluster_manager node + public Time ClusterManagerTimeout + { + get => Q