| type appStartupOrder int | |
| const ( | |
| orderBefore appStartupOrder = iota | |
| orderAfter | |
| ) | |
| func (a appStartupOrder) String() string { | |
| switch a { | |
| case orderBefore: | |
| return "before" | |
| case orderAfter: | |
| return "after" | |
| } | |
| panic(fmt.Sprintf("unsupported order: %v", a)) | |
| } | |
| func appStartOrdering(app *AppInfo, order appStartupOrder) []string { | |
| switch order { | |
| case orderBefore: | |
| return app.Before | |
| case orderAfter: | |
| return app.After | |
| } | |
| panic(fmt.Sprintf("unsupported order: %v", order)) | |
| } | |
| func validateAppStartup(app *AppInfo, order appStartupOrder) error { | |
| for _, dep := range appStartOrdering(app, order) { | |
| // dependency is not defined | |
| other, ok := app.Snap.Apps[dep] | |
| if !ok { | |
| return fmt.Errorf("cannot validate app %q startup ordering: needs to be started %s %q, but %q is not defined", | |
| app.Name, order.String(), dep, dep) | |
| } | |
| // it depends on us in the same order, eg. foo is | |
| // started after bar, but bar is to be started after foo | |
| // as well, validate only one dependency step | |
| otherDeps := appStartOrdering(other, order) | |
| if strutil.ListContains(otherDeps, app.Name) { | |
| return fmt.Errorf("cannot validate app %q startup ordering: needs to be started %s %q, but %q is declared to start %s %q", | |
| app.Name, order, other.Name, other.Name, order, app.Name) | |
| } | |
| } | |
| return nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment