This repository has been archived by the owner on Feb 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
node.go
55 lines (43 loc) · 1.48 KB
/
node.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
package cluster
import "fmt"
// Node is exported
type Node interface {
ID() string
Name() string
IP() string //to inject the actual IP of the machine in docker ps (hostname:port or ip:port)
Addr() string //to know where to connect with the proxy
Images() []*Image //used by the API
Image(IDOrName string) *Image //used by the filters
Containers() []*Container //used by the filters
Container(IDOrName string) *Container //used by the filters
TotalCpus() int64 //used by the strategy
UsedCpus() int64 //used by the strategy
TotalMemory() int64 //used by the strategy
UsedMemory() int64 //used by the strategy
Labels() map[string]string //used by the filters
IsHealthy() bool
}
// SerializeNode is exported
func SerializeNode(node Node) string {
return fmt.Sprintf("{%q:%q,%q:%q,%q:%q,%q:%q}",
"Name", node.Name(),
"Id", node.ID(),
"Addr", node.Addr(),
"Ip", node.IP())
}
// NodeSorter implements the Sort interface to sort Cluster.Node.
// It is not guaranteed to be a stable sort.
type NodeSorter []Node
// Len returns the number of nodes to be sorted.
func (s NodeSorter) Len() int {
return len(s)
}
// Swap exchanges the node elements with indices i and j.
func (s NodeSorter) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
// Less reports whether the node with index i should sort before the node with index j.
// Nodes are sorted chronologically by name.
func (s NodeSorter) Less(i, j int) bool {
return s[i].Name() < s[j].Name()
}