/
cluster_post_voting_config_exclusions.go
91 lines (75 loc) · 2.41 KB
/
cluster_post_voting_config_exclusions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package es
import (
"context"
"fmt"
"net/url"
elastic "github.com/olivere/elastic/v7" // Elasticsearch client.
)
// ClusterPostVotingConfigExclusion removes all voting configuration exclusions,
// allowing any node to return to the voting configuration in the future.
//
// See: https://www.elastic.co/guide/en/elasticsearch/reference/7.0/voting-config-exclusions.html
type ClusterPostVotingConfigExclusion struct {
client *elastic.Client
node string
timeout string
}
// NewClusterPostVotingConfigExclusion returns a new ClusterPostVotingConfigExclusion.
func NewClusterPostVotingConfigExclusion(c *elastic.Client) *ClusterPostVotingConfigExclusion {
return &ClusterPostVotingConfigExclusion{
client: c,
}
}
// Node sets the node(s) that should be excluded from voting configuration.
func (s *ClusterPostVotingConfigExclusion) Node(node string) *ClusterPostVotingConfigExclusion {
s.node = node
return s
}
// Timeout sets how long to wait for the system to auto-reconfigure the node out of the voting configuration.
// The default is 30 seconds.
func (s *ClusterPostVotingConfigExclusion) Timeout(timeout string) *ClusterPostVotingConfigExclusion {
s.timeout = timeout
return s
}
// Validate checks if the operation is valid.
func (s *ClusterPostVotingConfigExclusion) Validate() error {
if s.node == "" {
return fmt.Errorf("non-empty node required")
}
return nil
}
func (s *ClusterPostVotingConfigExclusion) buildURL() (string, url.Values, error) {
var err error
path := fmt.Sprintf("/_cluster/voting_config_exclusions/%s", s.node)
params := url.Values{}
if s.timeout != "" {
params.Add("timeout", s.timeout)
}
return path, params, err
}
// Do executes the operation.
func (s *ClusterPostVotingConfigExclusion) Do(ctx context.Context) (*ClusterPostVotingConfigExclusionResponse, error) {
// Check pre-conditions
if err := s.Validate(); err != nil {
return nil, err
}
// Get URL for request
path, params, err := s.buildURL()
if err != nil {
return nil, err
}
// Get HTTP response
_, err = s.client.PerformRequest(ctx, elastic.PerformRequestOptions{
Method: "POST",
Path: path,
Params: params,
})
if err != nil {
return nil, err
}
// Return operation response
ret := &ClusterPostVotingConfigExclusionResponse{}
return ret, nil
}
// ClusterPostVotingConfigExclusionResponse represents the response from ClusterPostVotingConfigExclusion.
type ClusterPostVotingConfigExclusionResponse struct{}