Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xpack_watcher_stop.go 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2012-2018 Oliver Eilhard. All rights reserved.
  2. // Use of this source code is governed by a MIT-license.
  3. // See http://olivere.mit-license.org/license.txt for details.
  4. package elastic
  5. import (
  6. "context"
  7. "encoding/json"
  8. "net/url"
  9. )
  10. // XPackWatcherStopService stops the watcher service if it is running.
  11. // See https://www.elastic.co/guide/en/elasticsearch/reference/6.4/watcher-api-stop.html.
  12. type XPackWatcherStopService struct {
  13. client *Client
  14. pretty bool
  15. }
  16. // NewXPackWatcherStopService creates a new XPackWatcherStopService.
  17. func NewXPackWatcherStopService(client *Client) *XPackWatcherStopService {
  18. return &XPackWatcherStopService{
  19. client: client,
  20. }
  21. }
  22. // Pretty indicates that the JSON response be indented and human readable.
  23. func (s *XPackWatcherStopService) Pretty(pretty bool) *XPackWatcherStopService {
  24. s.pretty = pretty
  25. return s
  26. }
  27. // buildURL builds the URL for the operation.
  28. func (s *XPackWatcherStopService) buildURL() (string, url.Values, error) {
  29. // Build URL path
  30. path := "/_xpack/watcher/_stop"
  31. // Add query string parameters
  32. params := url.Values{}
  33. if s.pretty {
  34. params.Set("pretty", "true")
  35. }
  36. return path, params, nil
  37. }
  38. // Validate checks if the operation is valid.
  39. func (s *XPackWatcherStopService) Validate() error {
  40. return nil
  41. }
  42. // Do executes the operation.
  43. func (s *XPackWatcherStopService) Do(ctx context.Context) (*XPackWatcherStopResponse, error) {
  44. // Check pre-conditions
  45. if err := s.Validate(); err != nil {
  46. return nil, err
  47. }
  48. // Get URL for request
  49. path, params, err := s.buildURL()
  50. if err != nil {
  51. return nil, err
  52. }
  53. // Get HTTP response
  54. res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
  55. Method: "POST",
  56. Path: path,
  57. Params: params,
  58. })
  59. if err != nil {
  60. return nil, err
  61. }
  62. // Return operation response
  63. ret := new(XPackWatcherStopResponse)
  64. if err := json.Unmarshal(res.Body, ret); err != nil {
  65. return nil, err
  66. }
  67. return ret, nil
  68. }
  69. // XPackWatcherStopResponse is the response of XPackWatcherStopService.Do.
  70. type XPackWatcherStopResponse struct {
  71. Acknowledged bool `json:"acknowledged"`
  72. }