autopilot+lnrpc: wire up SetNodeScores RPC to set scores of agent

This commit is contained in:
Johan T. Halseth
2019-02-14 11:37:47 +01:00
parent b23e53ea33
commit 5dabb1ae29
2 changed files with 42 additions and 0 deletions

View File

@@ -287,3 +287,27 @@ func (m *Manager) QueryHeuristics(nodes []NodeID) (HeuristicScores, error) {
log.Debugf("Querying heuristics for %d nodes", len(n))
return m.pilot.queryHeuristics(n)
}
// SetNodeScores is used to set the scores of the given heuristic, if it is
// active, and ScoreSettable.
func (m *Manager) SetNodeScores(name string, scores map[NodeID]float64) error {
// It must be ScoreSettable to be available for external
// scores.
s, ok := m.cfg.PilotCfg.Heuristic.(ScoreSettable)
if !ok {
return fmt.Errorf("current heuristic doesn't support " +
"external scoring")
}
// Heuristic was found, set its node scores.
applied, err := s.SetNodeScores(name, scores)
if err != nil {
return err
}
if !applied {
return fmt.Errorf("heuristic with name %v not found", name)
}
return nil
}