-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicker.go
34 lines (30 loc) · 948 Bytes
/
picker.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
package april
import (
"github.com/barbosaigor/april/util"
"github.com/barbosaigor/graphdeppicker"
"github.com/barbosaigor/graphll"
)
// Pick picks random nodes described in a yaml file as a slice of byte
func Pick(data []byte, quantity uint32) ([]string, error) {
conf, err := ReadConf(data)
if err != nil {
return nil, err
}
return PickFromConf(conf, quantity)
}
// PickFromConf picks random nodes from ConfData datastructure
func PickFromConf(conf *ConfData, quantity uint32) ([]string, error) {
depGraph := graphll.New()
for sname, sdata := range conf.Services {
depGraph.Add(sname, sdata.Weight, sdata.Dependencies)
}
return graphdeppicker.Pick(depGraph, quantity)
}
// PickFromYaml picks random nodes as PickRandDeps, but it read a yaml file
func PickFromYaml(filePath string, quantity uint32) ([]string, error) {
fdata, err := util.ReadFile(filePath)
if err != nil {
return nil, err
}
return Pick(fdata, quantity)
}