func LoadEnvs() error { envMutex.Lock() // get app+sha -> env apps, err := datamodel.ListApps() if err != nil { envMutex.Unlock() return nil // if we can't get the apps, this means this is a fresh zookeeper. don't fail. } for _, app := range apps { shas, err := datamodel.ListShas(app) if err != nil { envMutex.Unlock() return err } for _, sha := range shas { appSha := app + sha envs, err := datamodel.ListAppEnvs(app, sha) if err != nil { envMutex.Unlock() return err } for _, env := range envs { if _, ok := appShas[env]; ok { appShas[env][appSha]++ } else { appShas[env] = map[string]int{appSha: 1} } } } } envMutex.Unlock() return nil }
func (e *ListShasExecutor) Execute(t *Task) error { var err error if e.arg.App == "" { return errors.New("App is empty") } e.reply.Shas, err = datamodel.ListShas(e.arg.App) if err != nil { e.reply.Status = StatusError } else { sort.Strings(e.reply.Shas) e.reply.Status = StatusOk } return err }
func getContainerIDsOfApp(t *Task, app string) ([]string, error) { containerIDs := []string{} shas, err := datamodel.ListShas(app) if err != nil { return nil, errors.New(fmt.Sprintf("Error listing shas of %s: %s", app, err.Error())) } for _, sha := range shas { tmpContainerIDs, err := getContainerIDsOfSha(t, app, sha) if err != nil { return nil, err } containerIDs = append(containerIDs, tmpContainerIDs...) } return containerIDs, nil }
func getContainerIDsOfEnv(t *Task, app, env string) ([]string, error) { containerIDs := []string{} shas, err := datamodel.ListShas(app) if err != nil { return nil, errors.New(fmt.Sprintf("Error listing shas of %s : %s", app, err.Error())) } for _, sha := range shas { containerIDs, err = datamodel.ListInstances(app, sha, env) if err != nil { return nil, errors.New(fmt.Sprintf("Error listing instances of %s @ %s in %s: %s", app, sha, env, err.Error())) } } return containerIDs, nil }