api.cat.tasks.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. )
  26. func newCatTasksFunc(t Transport) CatTasks {
  27. return func(o ...func(*CatTasksRequest)) (*Response, error) {
  28. var r = CatTasksRequest{}
  29. for _, f := range o {
  30. f(&r)
  31. }
  32. return r.Do(r.ctx, t)
  33. }
  34. }
  35. // ----- API Definition -------------------------------------------------------
  36. // CatTasks returns information about the tasks currently executing on one or more nodes in the cluster.
  37. //
  38. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html.
  39. type CatTasks func(o ...func(*CatTasksRequest)) (*Response, error)
  40. // CatTasksRequest configures the Cat Tasks API request.
  41. type CatTasksRequest struct {
  42. Actions []string
  43. Detailed *bool
  44. Format string
  45. H []string
  46. Help *bool
  47. Nodes []string
  48. ParentTaskID string
  49. S []string
  50. Time string
  51. V *bool
  52. Pretty bool
  53. Human bool
  54. ErrorTrace bool
  55. FilterPath []string
  56. Header http.Header
  57. ctx context.Context
  58. }
  59. // Do executes the request and returns response or error.
  60. func (r CatTasksRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  61. var (
  62. method string
  63. path strings.Builder
  64. params map[string]string
  65. )
  66. method = "GET"
  67. path.Grow(len("/_cat/tasks"))
  68. path.WriteString("/_cat/tasks")
  69. params = make(map[string]string)
  70. if len(r.Actions) > 0 {
  71. params["actions"] = strings.Join(r.Actions, ",")
  72. }
  73. if r.Detailed != nil {
  74. params["detailed"] = strconv.FormatBool(*r.Detailed)
  75. }
  76. if r.Format != "" {
  77. params["format"] = r.Format
  78. }
  79. if len(r.H) > 0 {
  80. params["h"] = strings.Join(r.H, ",")
  81. }
  82. if r.Help != nil {
  83. params["help"] = strconv.FormatBool(*r.Help)
  84. }
  85. if len(r.Nodes) > 0 {
  86. params["nodes"] = strings.Join(r.Nodes, ",")
  87. }
  88. if r.ParentTaskID != "" {
  89. params["parent_task_id"] = r.ParentTaskID
  90. }
  91. if len(r.S) > 0 {
  92. params["s"] = strings.Join(r.S, ",")
  93. }
  94. if r.Time != "" {
  95. params["time"] = r.Time
  96. }
  97. if r.V != nil {
  98. params["v"] = strconv.FormatBool(*r.V)
  99. }
  100. if r.Pretty {
  101. params["pretty"] = "true"
  102. }
  103. if r.Human {
  104. params["human"] = "true"
  105. }
  106. if r.ErrorTrace {
  107. params["error_trace"] = "true"
  108. }
  109. if len(r.FilterPath) > 0 {
  110. params["filter_path"] = strings.Join(r.FilterPath, ",")
  111. }
  112. req, err := newRequest(method, path.String(), nil)
  113. if err != nil {
  114. return nil, err
  115. }
  116. if len(params) > 0 {
  117. q := req.URL.Query()
  118. for k, v := range params {
  119. q.Set(k, v)
  120. }
  121. req.URL.RawQuery = q.Encode()
  122. }
  123. if len(r.Header) > 0 {
  124. if len(req.Header) == 0 {
  125. req.Header = r.Header
  126. } else {
  127. for k, vv := range r.Header {
  128. for _, v := range vv {
  129. req.Header.Add(k, v)
  130. }
  131. }
  132. }
  133. }
  134. if ctx != nil {
  135. req = req.WithContext(ctx)
  136. }
  137. res, err := transport.Perform(req)
  138. if err != nil {
  139. return nil, err
  140. }
  141. response := Response{
  142. StatusCode: res.StatusCode,
  143. Body: res.Body,
  144. Header: res.Header,
  145. }
  146. return &response, nil
  147. }
  148. // WithContext sets the request context.
  149. func (f CatTasks) WithContext(v context.Context) func(*CatTasksRequest) {
  150. return func(r *CatTasksRequest) {
  151. r.ctx = v
  152. }
  153. }
  154. // WithActions - a list of actions that should be returned. leave empty to return all..
  155. func (f CatTasks) WithActions(v ...string) func(*CatTasksRequest) {
  156. return func(r *CatTasksRequest) {
  157. r.Actions = v
  158. }
  159. }
  160. // WithDetailed - return detailed task information (default: false).
  161. func (f CatTasks) WithDetailed(v bool) func(*CatTasksRequest) {
  162. return func(r *CatTasksRequest) {
  163. r.Detailed = &v
  164. }
  165. }
  166. // WithFormat - a short version of the accept header, e.g. json, yaml.
  167. func (f CatTasks) WithFormat(v string) func(*CatTasksRequest) {
  168. return func(r *CatTasksRequest) {
  169. r.Format = v
  170. }
  171. }
  172. // WithH - comma-separated list of column names to display.
  173. func (f CatTasks) WithH(v ...string) func(*CatTasksRequest) {
  174. return func(r *CatTasksRequest) {
  175. r.H = v
  176. }
  177. }
  178. // WithHelp - return help information.
  179. func (f CatTasks) WithHelp(v bool) func(*CatTasksRequest) {
  180. return func(r *CatTasksRequest) {
  181. r.Help = &v
  182. }
  183. }
  184. // WithNodes - a list of node ids or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes.
  185. func (f CatTasks) WithNodes(v ...string) func(*CatTasksRequest) {
  186. return func(r *CatTasksRequest) {
  187. r.Nodes = v
  188. }
  189. }
  190. // WithParentTaskID - return tasks with specified parent task ID (node_id:task_number). set to -1 to return all..
  191. func (f CatTasks) WithParentTaskID(v string) func(*CatTasksRequest) {
  192. return func(r *CatTasksRequest) {
  193. r.ParentTaskID = v
  194. }
  195. }
  196. // WithS - comma-separated list of column names or column aliases to sort by.
  197. func (f CatTasks) WithS(v ...string) func(*CatTasksRequest) {
  198. return func(r *CatTasksRequest) {
  199. r.S = v
  200. }
  201. }
  202. // WithTime - the unit in which to display time values.
  203. func (f CatTasks) WithTime(v string) func(*CatTasksRequest) {
  204. return func(r *CatTasksRequest) {
  205. r.Time = v
  206. }
  207. }
  208. // WithV - verbose mode. display column headers.
  209. func (f CatTasks) WithV(v bool) func(*CatTasksRequest) {
  210. return func(r *CatTasksRequest) {
  211. r.V = &v
  212. }
  213. }
  214. // WithPretty makes the response body pretty-printed.
  215. func (f CatTasks) WithPretty() func(*CatTasksRequest) {
  216. return func(r *CatTasksRequest) {
  217. r.Pretty = true
  218. }
  219. }
  220. // WithHuman makes statistical values human-readable.
  221. func (f CatTasks) WithHuman() func(*CatTasksRequest) {
  222. return func(r *CatTasksRequest) {
  223. r.Human = true
  224. }
  225. }
  226. // WithErrorTrace includes the stack trace for errors in the response body.
  227. func (f CatTasks) WithErrorTrace() func(*CatTasksRequest) {
  228. return func(r *CatTasksRequest) {
  229. r.ErrorTrace = true
  230. }
  231. }
  232. // WithFilterPath filters the properties of the response body.
  233. func (f CatTasks) WithFilterPath(v ...string) func(*CatTasksRequest) {
  234. return func(r *CatTasksRequest) {
  235. r.FilterPath = v
  236. }
  237. }
  238. // WithHeader adds the headers to the HTTP request.
  239. func (f CatTasks) WithHeader(h map[string]string) func(*CatTasksRequest) {
  240. return func(r *CatTasksRequest) {
  241. if r.Header == nil {
  242. r.Header = make(http.Header)
  243. }
  244. for k, v := range h {
  245. r.Header.Add(k, v)
  246. }
  247. }
  248. }
  249. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  250. func (f CatTasks) WithOpaqueID(s string) func(*CatTasksRequest) {
  251. return func(r *CatTasksRequest) {
  252. if r.Header == nil {
  253. r.Header = make(http.Header)
  254. }
  255. r.Header.Set("X-Opaque-Id", s)
  256. }
  257. }