Example #1
0
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
}
Example #2
0
func (e *ListEnvsExecutor) Execute(t *Task) error {
	var err error
	if e.arg.App == "" || e.arg.Sha == "" {
		e.reply.Envs, err = datamodel.ListEnvs()
	} else {
		e.reply.Envs, err = datamodel.ListAppEnvs(e.arg.App, e.arg.Sha)
	}
	if err != nil {
		e.reply.Status = StatusError
	} else {
		sort.Strings(e.reply.Envs)
		e.reply.Status = StatusOk
	}
	return err
}
func getContainerIDsOfSha(t *Task, app, sha string) ([]string, error) {
	containerIDs := []string{}
	envs, err := datamodel.ListAppEnvs(app, sha)
	if err != nil {
		return nil, errors.New(fmt.Sprintf("Error listing environments of %s @ %s: %s", app, sha, err.Error()))
	}
	for _, env := range envs {
		tmpContainerIDs, err := getContainerIDsOfShaEnv(t, app, sha, env)
		if err != nil {
			return nil, err
		}
		containerIDs = append(containerIDs, tmpContainerIDs...)
	}
	return containerIDs, nil
}