add initial files

This commit is contained in:
David Allen 2024-11-17 13:47:37 -07:00
commit 6233590bb4
Signed by: towk
GPG key ID: 793B2924A49B3A3F
8 changed files with 307 additions and 0 deletions

39
internal/groups/groups.go Normal file
View file

@ -0,0 +1,39 @@
package groups
import (
"slices"
"github.com/davidallendj/partitions/internal/partitions"
)
type Group struct {
Name string
Labels []string
}
func (g *Group) GetNodeIDs(pm *partitions.DefaultManager) []string {
foundNodes := []string{}
for _, label := range g.Labels {
nodeID := pm.LookupMember(label)
if nodeID != nil {
// check and make sure we're not duplicating node IDs
if !slices.Contains(foundNodes, *nodeID) {
foundNodes = append(foundNodes, *nodeID)
}
}
}
return foundNodes
}
func (g *Group) GetPartitions(pm *partitions.DefaultManager) []string {
foundPartitions := []string{}
for _, label := range g.Labels {
partition := pm.LookupPartitionByMemberID(label)
if partition != nil {
if !slices.Contains(foundPartitions, partition.ID) {
foundPartitions = append(foundPartitions, partition.ID)
}
}
}
return foundPartitions
}