NewGraph returns the dependency graph of the services
(project *types.Project, initialStatus ServiceStatus)
| 249 | |
| 250 | // NewGraph returns the dependency graph of the services |
| 251 | func NewGraph(project *types.Project, initialStatus ServiceStatus) (*Graph, error) { |
| 252 | graph := &Graph{ |
| 253 | lock: sync.RWMutex{}, |
| 254 | Vertices: map[string]*Vertex{}, |
| 255 | } |
| 256 | |
| 257 | for _, s := range project.Services { |
| 258 | graph.AddVertex(s.Name, s.Name, initialStatus) |
| 259 | } |
| 260 | |
| 261 | for index, s := range project.Services { |
| 262 | for _, name := range s.GetDependencies() { |
| 263 | err := graph.AddEdge(s.Name, name) |
| 264 | if err != nil { |
| 265 | if !s.DependsOn[name].Required { |
| 266 | delete(s.DependsOn, name) |
| 267 | project.Services[index] = s |
| 268 | continue |
| 269 | } |
| 270 | if api.IsNotFoundError(err) { |
| 271 | ds, err := project.GetDisabledService(name) |
| 272 | if err == nil { |
| 273 | return nil, fmt.Errorf("service %s is required by %s but is disabled. Can be enabled by profiles %s", name, s.Name, ds.Profiles) |
| 274 | } |
| 275 | } |
| 276 | return nil, err |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | if b, err := graph.HasCycles(); b { |
| 282 | return nil, err |
| 283 | } |
| 284 | |
| 285 | return graph, nil |
| 286 | } |
| 287 | |
| 288 | // NewVertex is the constructor function for the Vertex |
| 289 | func NewVertex(key string, service string, initialStatus ServiceStatus) *Vertex { |