コード例 #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
}
コード例 #2
0
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
}
コード例 #3
0
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
}
コード例 #4
0
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
}