cluster: rename Zones to Cluster

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-09-10 19:16:36 +00:00
parent c38dd19a92
commit b4975ae5c5
12 changed files with 123 additions and 115 deletions
+3 -67
View File
@@ -2,16 +2,10 @@ package cluster
import (
"io/fs"
"darvaza.org/resolver"
"darvaza.org/slog"
"github.com/gofrs/uuid/v5"
)
var (
_ MachineIterator = (*Zone)(nil)
_ MachineIterator = (*Zones)(nil)
_ ZoneIterator = (*Zones)(nil)
)
// A ZoneIterator is a set of Zones we can iterate on
@@ -19,9 +13,10 @@ type ZoneIterator interface {
ForEachZone(func(*Zone) bool)
}
// Zone represents one zone in a cluster
// A Zone is a set of machines in close proximity and strong
// affinity.
type Zone struct {
zones *Zones
zones *Cluster
logger `json:"-" yaml:"-"`
ID int
@@ -71,62 +66,3 @@ func (z *Zone) GatewayIDs() ([]int, int) {
return out, len(out)
}
// revive:disable:line-length-limit
// Zones represents all zones in a cluster
type Zones struct {
dir fs.FS
log slog.Logger
resolver resolver.Resolver
domain string
CephFSID uuid.UUID `json:"ceph_fsid,omitempty" yaml:"ceph_fsid,omitempty"`
Zones []*Zone
}
// revive:enable:line-length-limit
// ForEachMachine calls a function for each Machine in the cluster
// until instructed to terminate the loop
func (m *Zones) ForEachMachine(fn func(*Machine) bool) {
m.ForEachZone(func(z *Zone) bool {
var term bool
z.ForEachMachine(func(p *Machine) bool {
term = fn(p)
return term
})
return term
})
}
// ForEachZone calls a function for each Zone in the cluster
// until instructed to terminate the loop
func (m *Zones) ForEachZone(fn func(*Zone) bool) {
for _, p := range m.Zones {
if fn(p) {
// terminate
return
}
}
}
// GetMachineByName looks for a machine with the specified
// name on any zone
func (m *Zones) GetMachineByName(name string) (*Machine, bool) {
var out *Machine
if name != "" {
m.ForEachMachine(func(p *Machine) bool {
if p.Name == name {
out = p
}
return out != nil
})
}
return out, out != nil
}