34 lines
1.0 KiB
Go
34 lines
1.0 KiB
Go
package fleet
|
|
|
|
import "context"
|
|
|
|
// AdaptiveStrategy resolves tier order from phenotype learning or defaults.
|
|
type AdaptiveStrategy struct {
|
|
Store *Store
|
|
}
|
|
|
|
// OrderForHost returns tier execution order for a host, cloning from phenotype siblings when available.
|
|
func (a *AdaptiveStrategy) OrderForHost(ctx context.Context, hostID string) ([]int, error) {
|
|
report, err := RunRecon()
|
|
if err != nil {
|
|
return defaultOrderInts(), nil
|
|
}
|
|
phenotype := PhenotypeFromRecon(report)
|
|
_ = a.Store.SetHostPhenotype(ctx, hostID, ReconJSON(report), phenotype)
|
|
return a.Store.GetAdaptiveOrder(ctx, phenotype)
|
|
}
|
|
|
|
// CloneFromSibling copies winning tier order from a sibling with same phenotype.
|
|
func (a *AdaptiveStrategy) CloneFromSibling(ctx context.Context, hostID string) ([]int, error) {
|
|
report, err := RunRecon()
|
|
if err != nil {
|
|
return defaultOrderInts(), err
|
|
}
|
|
phenotype := PhenotypeFromRecon(report)
|
|
order, err := a.Store.GetAdaptiveOrder(ctx, phenotype)
|
|
if err != nil {
|
|
return defaultOrderInts(), err
|
|
}
|
|
return order, nil
|
|
}
|