github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/requester/ranking/engines.go (about) 1 package ranking 2 3 import ( 4 "context" 5 6 "github.com/filecoin-project/bacalhau/pkg/model" 7 "github.com/filecoin-project/bacalhau/pkg/requester" 8 "github.com/rs/zerolog/log" 9 ) 10 11 type EnginesNodeRanker struct { 12 } 13 14 func NewEnginesNodeRanker() *EnginesNodeRanker { 15 return &EnginesNodeRanker{} 16 } 17 18 // RankNodes ranks nodes based on the engines the compute nodes are accepting: 19 // - Rank 10: Node is supporting the engine the job is using. 20 // - Rank -1: Node is not supporting the engine the job is using. 21 // - Rank 0: Node supported engines are not set, or the node was discovered not through nodeInfoPublisher (e.g. identity protocol) 22 func (s *EnginesNodeRanker) RankNodes(ctx context.Context, job model.Job, nodes []model.NodeInfo) ([]requester.NodeRank, error) { 23 ranks := make([]requester.NodeRank, len(nodes)) 24 for i, node := range nodes { 25 rank := 0 26 if len(node.ComputeNodeInfo.ExecutionEngines) != 0 { 27 for _, engine := range node.ComputeNodeInfo.ExecutionEngines { 28 if engine == job.Spec.Engine { 29 rank = 10 30 break 31 } 32 } 33 // engine wasn't found 34 if rank == 0 { 35 log.Ctx(ctx).Trace().Msgf("filtering node %s doesn't support engine %s", node.PeerInfo.ID, job.Spec.Engine) 36 rank = -1 37 } 38 } 39 ranks[i] = requester.NodeRank{ 40 NodeInfo: node, 41 Rank: rank, 42 } 43 } 44 return ranks, nil 45 }