api.snapshot.status.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 newSnapshotStatusFunc(t Transport) SnapshotStatus {
  28. return func(o ...func(*SnapshotStatusRequest)) (*Response, error) {
  29. var r = SnapshotStatusRequest{}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // SnapshotStatus returns information about the status of a snapshot.
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html.
  40. type SnapshotStatus func(o ...func(*SnapshotStatusRequest)) (*Response, error)
  41. // SnapshotStatusRequest configures the Snapshot Status API request.
  42. type SnapshotStatusRequest struct {
  43. Repository string
  44. Snapshot []string
  45. IgnoreUnavailable *bool
  46. MasterTimeout time.Duration
  47. Pretty bool
  48. Human bool
  49. ErrorTrace bool
  50. FilterPath []string
  51. Header http.Header
  52. ctx context.Context
  53. }
  54. // Do executes the request and returns response or error.
  55. func (r SnapshotStatusRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  56. var (
  57. method string
  58. path strings.Builder
  59. params map[string]string
  60. )
  61. method = "GET"
  62. path.Grow(1 + len("_snapshot") + 1 + len(r.Repository) + 1 + len(strings.Join(r.Snapshot, ",")) + 1 + len("_status"))
  63. path.WriteString("/")
  64. path.WriteString("_snapshot")
  65. if r.Repository != "" {
  66. path.WriteString("/")
  67. path.WriteString(r.Repository)
  68. }
  69. if len(r.Snapshot) > 0 {
  70. path.WriteString("/")
  71. path.WriteString(strings.Join(r.Snapshot, ","))
  72. }
  73. path.WriteString("/")
  74. path.WriteString("_status")
  75. params = make(map[string]string)
  76. if r.IgnoreUnavailable != nil {
  77. params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
  78. }
  79. if r.MasterTimeout != 0 {
  80. params["master_timeout"] = formatDuration(r.MasterTimeout)
  81. }
  82. if r.Pretty {
  83. params["pretty"] = "true"
  84. }
  85. if r.Human {
  86. params["human"] = "true"
  87. }
  88. if r.ErrorTrace {
  89. params["error_trace"] = "true"
  90. }
  91. if len(r.FilterPath) > 0 {
  92. params["filter_path"] = strings.Join(r.FilterPath, ",")
  93. }
  94. req, err := newRequest(method, path.String(), nil)
  95. if err != nil {
  96. return nil, err
  97. }
  98. if len(params) > 0 {
  99. q := req.URL.Query()
  100. for k, v := range params {
  101. q.Set(k, v)
  102. }
  103. req.URL.RawQuery = q.Encode()
  104. }
  105. if len(r.Header) > 0 {
  106. if len(req.Header) == 0 {
  107. req.Header = r.Header
  108. } else {
  109. for k, vv := range r.Header {
  110. for _, v := range vv {
  111. req.Header.Add(k, v)
  112. }
  113. }
  114. }
  115. }
  116. if ctx != nil {
  117. req = req.WithContext(ctx)
  118. }
  119. res, err := transport.Perform(req)
  120. if err != nil {
  121. return nil, err
  122. }
  123. response := Response{
  124. StatusCode: res.StatusCode,
  125. Body: res.Body,
  126. Header: res.Header,
  127. }
  128. return &response, nil
  129. }
  130. // WithContext sets the request context.
  131. func (f SnapshotStatus) WithContext(v context.Context) func(*SnapshotStatusRequest) {
  132. return func(r *SnapshotStatusRequest) {
  133. r.ctx = v
  134. }
  135. }
  136. // WithRepository - a repository name.
  137. func (f SnapshotStatus) WithRepository(v string) func(*SnapshotStatusRequest) {
  138. return func(r *SnapshotStatusRequest) {
  139. r.Repository = v
  140. }
  141. }
  142. // WithSnapshot - a list of snapshot names.
  143. func (f SnapshotStatus) WithSnapshot(v ...string) func(*SnapshotStatusRequest) {
  144. return func(r *SnapshotStatusRequest) {
  145. r.Snapshot = v
  146. }
  147. }
  148. // WithIgnoreUnavailable - whether to ignore unavailable snapshots, defaults to false which means a snapshotmissingexception is thrown.
  149. func (f SnapshotStatus) WithIgnoreUnavailable(v bool) func(*SnapshotStatusRequest) {
  150. return func(r *SnapshotStatusRequest) {
  151. r.IgnoreUnavailable = &v
  152. }
  153. }
  154. // WithMasterTimeout - explicit operation timeout for connection to master node.
  155. func (f SnapshotStatus) WithMasterTimeout(v time.Duration) func(*SnapshotStatusRequest) {
  156. return func(r *SnapshotStatusRequest) {
  157. r.MasterTimeout = v
  158. }
  159. }
  160. // WithPretty makes the response body pretty-printed.
  161. func (f SnapshotStatus) WithPretty() func(*SnapshotStatusRequest) {
  162. return func(r *SnapshotStatusRequest) {
  163. r.Pretty = true
  164. }
  165. }
  166. // WithHuman makes statistical values human-readable.
  167. func (f SnapshotStatus) WithHuman() func(*SnapshotStatusRequest) {
  168. return func(r *SnapshotStatusRequest) {
  169. r.Human = true
  170. }
  171. }
  172. // WithErrorTrace includes the stack trace for errors in the response body.
  173. func (f SnapshotStatus) WithErrorTrace() func(*SnapshotStatusRequest) {
  174. return func(r *SnapshotStatusRequest) {
  175. r.ErrorTrace = true
  176. }
  177. }
  178. // WithFilterPath filters the properties of the response body.
  179. func (f SnapshotStatus) WithFilterPath(v ...string) func(*SnapshotStatusRequest) {
  180. return func(r *SnapshotStatusRequest) {
  181. r.FilterPath = v
  182. }
  183. }
  184. // WithHeader adds the headers to the HTTP request.
  185. func (f SnapshotStatus) WithHeader(h map[string]string) func(*SnapshotStatusRequest) {
  186. return func(r *SnapshotStatusRequest) {
  187. if r.Header == nil {
  188. r.Header = make(http.Header)
  189. }
  190. for k, v := range h {
  191. r.Header.Add(k, v)
  192. }
  193. }
  194. }
  195. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  196. func (f SnapshotStatus) WithOpaqueID(s string) func(*SnapshotStatusRequest) {
  197. return func(r *SnapshotStatusRequest) {
  198. if r.Header == nil {
  199. r.Header = make(http.Header)
  200. }
  201. r.Header.Set("X-Opaque-Id", s)
  202. }
  203. }