forked from go-kivik/kivik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.go
53 lines (46 loc) · 1.9 KB
/
cluster.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
package kivik
import (
"context"
"net/http"
"github.com/IG-Soft/kivik/v3/driver"
)
var clusterNotImplemented = &Error{HTTPStatus: http.StatusNotImplemented, Message: "kivik: driver does not support cluster operations"}
// ClusterStatus returns the current cluster status.
//
// See http://docs.couchdb.org/en/stable/api/server/common.html#cluster-setup
func (c *Client) ClusterStatus(ctx context.Context, options ...Options) (string, error) {
cluster, ok := c.driverClient.(driver.Cluster)
if !ok {
return "", clusterNotImplemented
}
return cluster.ClusterStatus(ctx, mergeOptions(options...))
}
// ClusterSetup performs the requested cluster action. action should be
// an object understood by the driver. For the CouchDB driver, this means an
// object which is marshalable to a JSON object of the expected format.
//
// See http://docs.couchdb.org/en/stable/api/server/common.html#post--_cluster_setup
func (c *Client) ClusterSetup(ctx context.Context, action interface{}) error {
cluster, ok := c.driverClient.(driver.Cluster)
if !ok {
return clusterNotImplemented
}
return cluster.ClusterSetup(ctx, action)
}
// ClusterMembership contains the list of known nodes, and cluster nodes, as returned
// by the /_membership endpoint.
// See https://docs.couchdb.org/en/latest/api/server/common.html#get--_membership
type ClusterMembership struct {
AllNodes []string `json:"all_nodes"`
ClusterNodes []string `json:"cluster_nodes"`
}
// Membership returns a list of known CouchDB nodes.
// See https://docs.couchdb.org/en/latest/api/server/common.html#get--_membership
func (c *Client) Membership(ctx context.Context) (*ClusterMembership, error) {
cluster, ok := c.driverClient.(driver.Cluster2)
if !ok {
return nil, &Error{HTTPStatus: http.StatusNotImplemented, Message: "kivik: driver does not support the /_membership endpoint"}
}
nodes, err := cluster.Membership(ctx)
return (*ClusterMembership)(nodes), err
}