api.cat.thread_pool.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. // Licensed to Elasticsearch B.V. under one or more contributor
  2. // license agreements. See the NOTICE file distributed with
  3. // this work for additional information regarding copyright
  4. // ownership. Elasticsearch B.V. licenses this file to you under
  5. // the Apache License, Version 2.0 (the "License"); you may
  6. // not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. //
  18. // Code generated from specification version 7.17.10: DO NOT EDIT
  19. package esapi
  20. import (
  21. "context"
  22. "net/http"
  23. "strconv"
  24. "strings"
  25. "time"
  26. )
  27. func newCatThreadPoolFunc(t Transport) CatThreadPool {
  28. return func(o ...func(*CatThreadPoolRequest)) (*Response, error) {
  29. var r = CatThreadPoolRequest{}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // CatThreadPool returns cluster-wide thread pool statistics per node.
  38. // By default the active, queue and rejected statistics are returned for all thread pools.
  39. //
  40. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-thread-pool.html.
  41. type CatThreadPool func(o ...func(*CatThreadPoolRequest)) (*Response, error)
  42. // CatThreadPoolRequest configures the Cat Thread Pool API request.
  43. type CatThreadPoolRequest struct {
  44. ThreadPoolPatterns []string
  45. Format string
  46. H []string
  47. Help *bool
  48. Local *bool
  49. MasterTimeout time.Duration
  50. S []string
  51. Size string
  52. V *bool
  53. Pretty bool
  54. Human bool
  55. ErrorTrace bool
  56. FilterPath []string
  57. Header http.Header
  58. ctx context.Context
  59. }
  60. // Do executes the request and returns response or error.
  61. func (r CatThreadPoolRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  62. var (
  63. method string
  64. path strings.Builder
  65. params map[string]string
  66. )
  67. method = "GET"
  68. path.Grow(1 + len("_cat") + 1 + len("thread_pool") + 1 + len(strings.Join(r.ThreadPoolPatterns, ",")))
  69. path.WriteString("/")
  70. path.WriteString("_cat")
  71. path.WriteString("/")
  72. path.WriteString("thread_pool")
  73. if len(r.ThreadPoolPatterns) > 0 {
  74. path.WriteString("/")
  75. path.WriteString(strings.Join(r.ThreadPoolPatterns, ","))
  76. }
  77. params = make(map[string]string)
  78. if r.Format != "" {
  79. params["format"] = r.Format
  80. }
  81. if len(r.H) > 0 {
  82. params["h"] = strings.Join(r.H, ",")
  83. }
  84. if r.Help != nil {
  85. params["help"] = strconv.FormatBool(*r.Help)
  86. }
  87. if r.Local != nil {
  88. params["local"] = strconv.FormatBool(*r.Local)
  89. }
  90. if r.MasterTimeout != 0 {
  91. params["master_timeout"] = formatDuration(r.MasterTimeout)
  92. }
  93. if len(r.S) > 0 {
  94. params["s"] = strings.Join(r.S, ",")
  95. }
  96. if r.Size != "" {
  97. params["size"] = r.Size
  98. }
  99. if r.V != nil {
  100. params["v"] = strconv.FormatBool(*r.V)
  101. }
  102. if r.Pretty {
  103. params["pretty"] = "true"
  104. }
  105. if r.Human {
  106. params["human"] = "true"
  107. }
  108. if r.ErrorTrace {
  109. params["error_trace"] = "true"
  110. }
  111. if len(r.FilterPath) > 0 {
  112. params["filter_path"] = strings.Join(r.FilterPath, ",")
  113. }
  114. req, err := newRequest(method, path.String(), nil)
  115. if err != nil {
  116. return nil, err
  117. }
  118. if len(params) > 0 {
  119. q := req.URL.Query()
  120. for k, v := range params {
  121. q.Set(k, v)
  122. }
  123. req.URL.RawQuery = q.Encode()
  124. }
  125. if len(r.Header) > 0 {
  126. if len(req.Header) == 0 {
  127. req.Header = r.Header
  128. } else {
  129. for k, vv := range r.Header {
  130. for _, v := range vv {
  131. req.Header.Add(k, v)
  132. }
  133. }
  134. }
  135. }
  136. if ctx != nil {
  137. req = req.WithContext(ctx)
  138. }
  139. res, err := transport.Perform(req)
  140. if err != nil {
  141. return nil, err
  142. }
  143. response := Response{
  144. StatusCode: res.StatusCode,
  145. Body: res.Body,
  146. Header: res.Header,
  147. }
  148. return &response, nil
  149. }
  150. // WithContext sets the request context.
  151. func (f CatThreadPool) WithContext(v context.Context) func(*CatThreadPoolRequest) {
  152. return func(r *CatThreadPoolRequest) {
  153. r.ctx = v
  154. }
  155. }
  156. // WithThreadPoolPatterns - a list of regular-expressions to filter the thread pools in the output.
  157. func (f CatThreadPool) WithThreadPoolPatterns(v ...string) func(*CatThreadPoolRequest) {
  158. return func(r *CatThreadPoolRequest) {
  159. r.ThreadPoolPatterns = v
  160. }
  161. }
  162. // WithFormat - a short version of the accept header, e.g. json, yaml.
  163. func (f CatThreadPool) WithFormat(v string) func(*CatThreadPoolRequest) {
  164. return func(r *CatThreadPoolRequest) {
  165. r.Format = v
  166. }
  167. }
  168. // WithH - comma-separated list of column names to display.
  169. func (f CatThreadPool) WithH(v ...string) func(*CatThreadPoolRequest) {
  170. return func(r *CatThreadPoolRequest) {
  171. r.H = v
  172. }
  173. }
  174. // WithHelp - return help information.
  175. func (f CatThreadPool) WithHelp(v bool) func(*CatThreadPoolRequest) {
  176. return func(r *CatThreadPoolRequest) {
  177. r.Help = &v
  178. }
  179. }
  180. // WithLocal - return local information, do not retrieve the state from master node (default: false).
  181. func (f CatThreadPool) WithLocal(v bool) func(*CatThreadPoolRequest) {
  182. return func(r *CatThreadPoolRequest) {
  183. r.Local = &v
  184. }
  185. }
  186. // WithMasterTimeout - explicit operation timeout for connection to master node.
  187. func (f CatThreadPool) WithMasterTimeout(v time.Duration) func(*CatThreadPoolRequest) {
  188. return func(r *CatThreadPoolRequest) {
  189. r.MasterTimeout = v
  190. }
  191. }
  192. // WithS - comma-separated list of column names or column aliases to sort by.
  193. func (f CatThreadPool) WithS(v ...string) func(*CatThreadPoolRequest) {
  194. return func(r *CatThreadPoolRequest) {
  195. r.S = v
  196. }
  197. }
  198. // WithSize - the multiplier in which to display values.
  199. func (f CatThreadPool) WithSize(v string) func(*CatThreadPoolRequest) {
  200. return func(r *CatThreadPoolRequest) {
  201. r.Size = v
  202. }
  203. }
  204. // WithV - verbose mode. display column headers.
  205. func (f CatThreadPool) WithV(v bool) func(*CatThreadPoolRequest) {
  206. return func(r *CatThreadPoolRequest) {
  207. r.V = &v
  208. }
  209. }
  210. // WithPretty makes the response body pretty-printed.
  211. func (f CatThreadPool) WithPretty() func(*CatThreadPoolRequest) {
  212. return func(r *CatThreadPoolRequest) {
  213. r.Pretty = true
  214. }
  215. }
  216. // WithHuman makes statistical values human-readable.
  217. func (f CatThreadPool) WithHuman() func(*CatThreadPoolRequest) {
  218. return func(r *CatThreadPoolRequest) {
  219. r.Human = true
  220. }
  221. }
  222. // WithErrorTrace includes the stack trace for errors in the response body.
  223. func (f CatThreadPool) WithErrorTrace() func(*CatThreadPoolRequest) {
  224. return func(r *CatThreadPoolRequest) {
  225. r.ErrorTrace = true
  226. }
  227. }
  228. // WithFilterPath filters the properties of the response body.
  229. func (f CatThreadPool) WithFilterPath(v ...string) func(*CatThreadPoolRequest) {
  230. return func(r *CatThreadPoolRequest) {
  231. r.FilterPath = v
  232. }
  233. }
  234. // WithHeader adds the headers to the HTTP request.
  235. func (f CatThreadPool) WithHeader(h map[string]string) func(*CatThreadPoolRequest) {
  236. return func(r *CatThreadPoolRequest) {
  237. if r.Header == nil {
  238. r.Header = make(http.Header)
  239. }
  240. for k, v := range h {
  241. r.Header.Add(k, v)
  242. }
  243. }
  244. }
  245. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  246. func (f CatThreadPool) WithOpaqueID(s string) func(*CatThreadPoolRequest) {
  247. return func(r *CatThreadPoolRequest) {
  248. if r.Header == nil {
  249. r.Header = make(http.Header)
  250. }
  251. r.Header.Set("X-Opaque-Id", s)
  252. }
  253. }