autopilot/manager: add QueryHeuristics

Proxies a query request to the active agent.
This commit is contained in:
Johan T. Halseth 2018-12-19 14:54:55 +01:00
parent 6c556fd92a
commit 8f54a2bd6f
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -1,6 +1,7 @@
package autopilot
import (
"fmt"
"sync"
"sync/atomic"
@ -267,3 +268,22 @@ func (m *Manager) StopAgent() error {
return nil
}
// QueryHeuristics queries the active autopilot agent for node scores.
func (m *Manager) QueryHeuristics(nodes []NodeID) (HeuristicScores, error) {
m.Lock()
defer m.Unlock()
// Not active, so we can return early.
if m.pilot == nil {
return nil, fmt.Errorf("autopilot not active")
}
n := make(map[NodeID]struct{})
for _, node := range nodes {
n[node] = struct{}{}
}
log.Debugf("Querying heuristics for %d nodes", len(n))
return m.pilot.queryHeuristics(n)
}