-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclusters.go
67 lines (62 loc) · 2.47 KB
/
clusters.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
package remy
import (
"bytes"
"encoding/json"
"fmt"
)
// Cluster is the underlying struct for a single Cluster in a domain. Each domain may have multiple Cluster instances,
// each having their own ClusterMaster, deployed state, etc.
type Cluster struct {
Name string
Servers []struct {
Name string
State string
Health string
IsClusterMaster bool `json:"clusterMaster,omitempty"`
DropOutFrequency string `json:",omitempty"`
ResendRequestsCount int `json:",omitempty"`
FragmentsSentCount int `json:",omitempty"`
FragmentsReceivedCount int `json:",omitempty"`
} `json:"servers,omitempty"`
}
// GoString creates a GoString of the Cluster type for use in command-line applications.
func (c *Cluster) GoString() string {
var buffer bytes.Buffer
buffer.WriteString(fmt.Sprintf("Name: %v\n", c.Name))
for i := range c.Servers {
buffer.WriteString(fmt.Sprintf("State: %-14v| Health: %-14v| Cluster Master? %-14v| Drop Out Freq: %-14v\n",
c.Servers[i].State, c.Servers[i].Health, c.Servers[i].IsClusterMaster, c.Servers[i].DropOutFrequency))
buffer.WriteString(fmt.Sprintf("Resend Req. Count: %-14v| Fragments Sent Count: %-14v| Fragments Recv Count: %-14v\n",
c.Servers[i].ResendRequestsCount, c.Servers[i].FragmentsSentCount, c.Servers[i].FragmentsReceivedCount))
}
return buffer.String()
}
// Clusters returns all clusters configured in a domain and provides run-time information for each cluster and for each cluster's member servers, including all the member servers' state and health.
func (a *AdminServer) Clusters(fullFormat bool) ([]Cluster, error) {
url := fmt.Sprintf("%v%v/clusters", a.AdminURL, MonitorPath)
if fullFormat {
url = url + "?format=full"
}
w, err := requestAndUnmarshal(url, a)
if err != nil {
return nil, err
}
var clusters []Cluster
if err := json.Unmarshal(w.Body.Items, &clusters); err != nil {
return nil, err
}
return clusters, nil
}
// Cluster returns run-time information for the specified cluster and its member servers, including the member servers' state and health.
func (a *AdminServer) Cluster(clusterName string) (*Cluster, error) {
url := fmt.Sprintf("%v%v/clusters/%v", a.AdminURL, MonitorPath, clusterName)
w, err := requestAndUnmarshal(url, a)
if err != nil {
return nil, err
}
var cluster Cluster
if err := json.Unmarshal(w.Body.Item, &cluster); err != nil {
return nil, err
}
return &cluster, nil
}