mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-08 16:06:47 +00:00
Graph logic moves into depgraph package and makes internal fields inaccessible. Completes feedback from @LucasRoesler from previous PR where the dependency graph was added for 0.9.1 Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
42 lines
692 B
Go
42 lines
692 B
Go
package pkg
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/openfaas/faasd/pkg/depgraph"
|
|
)
|
|
|
|
func buildDeploymentOrder(svcs []Service) []string {
|
|
|
|
graph := buildServiceGraph(svcs)
|
|
|
|
order := graph.Resolve()
|
|
|
|
log.Printf("Start-up order:\n")
|
|
for _, node := range order {
|
|
log.Printf("- %s\n", node)
|
|
}
|
|
|
|
return order
|
|
}
|
|
|
|
func buildServiceGraph(svcs []Service) *depgraph.Graph {
|
|
graph := depgraph.NewDepgraph()
|
|
|
|
nodeMap := map[string]*depgraph.Node{}
|
|
for _, s := range svcs {
|
|
n := &depgraph.Node{Name: s.Name}
|
|
nodeMap[s.Name] = n
|
|
graph.Add(n)
|
|
|
|
}
|
|
|
|
for _, s := range svcs {
|
|
for _, d := range s.DependsOn {
|
|
nodeMap[s.Name].Edges = append(nodeMap[s.Name].Edges, nodeMap[d])
|
|
}
|
|
}
|
|
|
|
return graph
|
|
}
|