// GetApps returns the list of all registered Apps. func (s *Store) GetApps() ([]*App, error) { sp, err := s.GetSnapshot().FastForward() if err != nil { return nil, err } exists, _, err := sp.Exists(appsPath) if err != nil || !exists { return nil, err } names, err := sp.Getdir(appsPath) if err != nil { return nil, err } apps := []*App{} ch, errch := cp.GetSnapshotables(names, func(name string) (cp.Snapshotable, error) { return getApp(name, sp) }) for i := 0; i < len(names); i++ { select { case r := <-ch: apps = append(apps, r.(*App)) case err := <-errch: return nil, err } } return apps, nil }
// GetTags returns a list of all Tags for the app. func (a *App) GetTags() ([]*Tag, error) { sp, err := a.GetSnapshot().FastForward() if err != nil { return nil, err } names, err := sp.Getdir(a.dir.Prefix(tagsPath)) if err != nil { return nil, err } tags := []*Tag{} ch, errch := cp.GetSnapshotables(names, func(name string) (cp.Snapshotable, error) { return getTag(a, name, sp) }) for i := 0; i < len(names); i++ { select { case t := <-ch: tags = append(tags, t.(*Tag)) case err := <-errch: return nil, err } } return tags, nil }
// GetRevisions returns all registered Revisions for the App func (a *App) GetRevisions() ([]*Revision, error) { sp, err := a.GetSnapshot().FastForward() if err != nil { return nil, err } revs, err := sp.Getdir(a.dir.Prefix("revs")) if err != nil { return nil, err } revisions := []*Revision{} ch, errch := cp.GetSnapshotables(revs, func(name string) (cp.Snapshotable, error) { return getRevision(a, name, sp) }) for i := 0; i < len(revs); i++ { select { case r := <-ch: revisions = append(revisions, r.(*Revision)) case err := <-errch: return nil, err } } return revisions, nil }
// GetProcs returns all registered Procs for the App func (a *App) GetProcs() (procs []*Proc, err error) { sp, err := a.GetSnapshot().FastForward() if err != nil { return } names, err := sp.Getdir(a.dir.Prefix(procsPath)) if err != nil || len(names) == 0 { if cp.IsErrNoEnt(err) { err = nil } return } ch, errch := cp.GetSnapshotables(names, func(name string) (cp.Snapshotable, error) { return getProc(a, name, sp) }) for i := 0; i < len(names); i++ { select { case r := <-ch: procs = append(procs, r.(*Proc)) case err := <-errch: return nil, err } } return }
// GetHooks returns a list of all Hooks for the app. func (a *App) GetHooks() ([]*Hook, error) { sp, err := a.GetSnapshot().FastForward() if err != nil { return nil, err } names, err := sp.Getdir(a.dir.Prefix(hooksPath)) if err != nil { return nil, err } hooks := []*Hook{} ch, errch := cp.GetSnapshotables(names, func(name string) (cp.Snapshotable, error) { return getHook(a, name, sp) }) for i := 0; i < len(names); i++ { select { case h := <-ch: hooks = append(hooks, h.(*Hook)) case err := <-errch: return nil, err } } return hooks, nil }
// GetInstances returns all existing instances. func (s *Store) GetInstances() ([]*Instance, error) { sp, err := s.GetSnapshot().FastForward() if err != nil { return nil, err } ids, err := sp.Getdir(instancesPath) if err != nil { return nil, err } instances := []*Instance{} ch, errch := cp.GetSnapshotables(ids, func(idstr string) (cp.Snapshotable, error) { id, err := parseInstanceID(idstr) if err != nil { return nil, err } return getInstance(id, sp) }) errStr := "" for i := 0; i < len(ids); i++ { select { case i := <-ch: instances = append(instances, i.(*Instance)) case err := <-errch: errStr = fmt.Sprintf("%s\n%s", errStr, err) } } if len(errStr) > 0 { return instances, NewError(ErrNotFound, errStr) } return instances, nil }
// RunnersByHost returns all Runners for a given host. func (s *Store) RunnersByHost(host string) ([]*Runner, error) { sp, err := s.GetSnapshot().FastForward() if err != nil { return nil, err } ids, err := sp.Getdir(path.Join(runnersPath, host)) if err != nil { return nil, err } ch, errch := cp.GetSnapshotables(ids, func(id string) (cp.Snapshotable, error) { return getRunner(runnerAddr(host, id), sp) }) runners := []*Runner{} for i := 0; i < len(ids); i++ { select { case r := <-ch: runners = append(runners, r.(*Runner)) case err := <-errch: if err != nil { return nil, err } } } return runners, nil }
// GetEnvs returns a list of all Envs for the app. func (a *App) GetEnvs() ([]*Env, error) { sp, err := a.GetSnapshot().FastForward() if err != nil { return nil, err } refs, err := sp.Getdir(a.dir.Prefix(envsPath)) if err != nil { return nil, err } envs := []*Env{} ch, errch := cp.GetSnapshotables(refs, func(ref string) (cp.Snapshotable, error) { return getEnv(a, ref, sp) }) for i := 0; i < len(refs); i++ { select { case e := <-ch: envs = append(envs, e.(*Env)) case err := <-errch: return nil, err } } return envs, nil }
func getProcInstances(ids []string, s cp.Snapshotable) ([]*Instance, error) { ch, errch := cp.GetSnapshotables(ids, func(idstr string) (cp.Snapshotable, error) { id, err := parseInstanceID(idstr) if err != nil { return nil, err } return getInstance(id, s) }) ins := []*Instance{} for i := 0; i < len(ids); i++ { select { case r := <-ch: ins = append(ins, r.(*Instance)) case err := <-errch: return nil, err } } return ins, nil }