• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang cotterpin.Snapshotable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/soundcloud/cotterpin.Snapshotable的典型用法代码示例。如果您正苦于以下问题:Golang Snapshotable类的具体用法?Golang Snapshotable怎么用?Golang Snapshotable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Snapshotable类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: getApp

func getApp(name string, s cp.Snapshotable) (*App, error) {
	sp := s.GetSnapshot()
	app := storeFromSnapshotable(s).NewApp(name, "", "")

	f, err := sp.GetSnapshot().GetFile(app.dir.Prefix("attrs"), new(cp.JsonCodec))
	if err != nil {
		if cp.IsErrNoEnt(err) {
			err = errorf(ErrNotFound, `app "%s" not found`, app.Name)
		}
		return nil, err
	}

	value := f.Value.(map[string]interface{})

	app.RepoURL = value["repo-url"].(string)
	app.Stack = value["stack"].(string)
	app.DeployType = value["deploy-type"].(string)

	f, err = app.dir.GetFile(registeredPath, new(cp.StringCodec))
	if err != nil {
		if cp.IsErrNoEnt(err) {
			err = errorf(ErrNotFound, "registered not found for %s", app.Name)
		}
		return nil, err
	}
	app.Registered, err = parseTime(f.Value.(string))
	if err != nil {
		return nil, err
	}

	return app, nil
}
开发者ID:soundcloud,项目名称:visor,代码行数:32,代码来源:app.go


示例2: getProc

func getProc(app *App, name string, s cp.Snapshotable) (*Proc, error) {
	p := &Proc{
		dir:  cp.NewDir(app.dir.Prefix(procsPath, name), s.GetSnapshot()),
		Name: name,
		App:  app,
	}

	port, err := p.dir.GetFile(procsPortPath, new(cp.IntCodec))
	if err != nil {
		if cp.IsErrNoEnt(err) {
			exists, _, err := s.GetSnapshot().Exists(p.dir.Name)
			if err != nil {
				return nil, err
			}
			if !exists {
				return nil, errorf(ErrNotFound, `proc "%s" not found for app %s`, name, app.Name)
			}
			return nil, errorf(ErrNotFound, "port not found for %s:%s", app.Name, name)
		}
		return nil, err
	}
	p.Port = port.Value.(int)

	controlPort, err := p.dir.GetFile(procsControlPortPath, new(cp.IntCodec))
	if err != nil {
		if IsErrNotFound(err) {
			p.ControlPort = 0
		} else {
			return nil, err
		}
	} else {
		p.ControlPort = controlPort.Value.(int)
	}

	_, err = p.dir.GetFile(procsAttrsPath, &cp.JsonCodec{DecodedVal: &p.Attrs})
	if err != nil && !cp.IsErrNoEnt(err) {
		return nil, err
	}

	f, err := p.dir.GetFile(registeredPath, new(cp.StringCodec))
	if err != nil {
		if cp.IsErrNoEnt(err) {
			err = errorf(ErrNotFound, "registered not found for %s:%s", app.Name, name)
		}
		return nil, err
	}
	p.Registered, err = parseTime(f.Value.(string))
	if err != nil {
		return nil, err
	}

	return p, nil
}
开发者ID:soundcloud,项目名称:visor,代码行数:53,代码来源:proc.go


示例3: getProcInstanceIds

func getProcInstanceIds(p *Proc, s cp.Snapshotable) ([]int64, error) {
	sp := s.GetSnapshot()
	revs, err := sp.Getdir(p.dir.Prefix("instances"))
	if err != nil {
		return nil, err
	}
	ids := []int64{}
	for _, rev := range revs {
		iids, err := getInstanceIds(p.App.Name, rev, p.Name, sp)
		if err != nil {
			return nil, err
		}
		ids = append(ids, iids...)
	}
	return ids, nil
}
开发者ID:soundcloud,项目名称:visor,代码行数:16,代码来源:proc.go


示例4: getTag

func getTag(a *App, name string, s cp.Snapshotable) (*Tag, error) {
	t := &Tag{}
	c := &cp.JsonCodec{DecodedVal: t}

	f, err := s.GetSnapshot().GetFile(a.dir.Prefix(tagsPath, name), c)
	if err != nil {
		if cp.IsErrNoEnt(err) {
			err = errorf(ErrNotFound, `tag "%s" not found`, name)
		}
		return nil, err
	}

	t.file = f
	t.App = a

	return t, nil
}
开发者ID:soundcloud,项目名称:visor,代码行数:17,代码来源:tag.go


示例5: getRunner

func getRunner(addr string, s cp.Snapshotable) (*Runner, error) {
	sp := s.GetSnapshot()
	f, err := sp.GetFile(runnerPath(addr), new(cp.ListCodec))
	if err != nil {
		if cp.IsErrNoEnt(err) {
			err = errorf(ErrNotFound, "runner '%s' not found", addr)
		}
		return nil, err
	}
	data := f.Value.([]string)
	insIDStr := data[0]
	insID, err := parseInstanceID(insIDStr)
	if err != nil {
		return nil, err
	}

	return storeFromSnapshotable(sp).NewRunner(addr, insID), nil
}
开发者ID:soundcloud,项目名称:visor,代码行数:18,代码来源:runner.go


示例6: getHook

func getHook(app *App, name string, s cp.Snapshotable) (*Hook, error) {
	c := new(cp.JsonCodec)
	c.DecodedVal = &Hook{}

	f, err := s.GetSnapshot().GetFile(app.dir.Prefix(hooksPath, name), c)
	if err != nil {
		if cp.IsErrNoEnt(err) {
			err = errorf(ErrNotFound, `hook not found for "%s"`, name)
		}
		return nil, err
	}

	h, ok := f.Value.(*Hook)
	if !ok {
		return nil, errors.New("retrieved file is not a hook")
	}
	h.file = f
	h.App = app

	return h, nil
}
开发者ID:soundcloud,项目名称:visor,代码行数:21,代码来源:hook.go


示例7: getInstanceIds

func getInstanceIds(app, rev, proc string, s cp.Snapshotable) (ids Int64Slice, err error) {
	sp := s.GetSnapshot()
	p := procInstancesPath(app, rev, proc)
	exists, _, err := sp.Exists(p)
	if err != nil || !exists {
		return
	}

	dir, err := sp.Getdir(p)
	if err != nil {
		return
	}
	ids = Int64Slice{}
	for _, f := range dir {
		id, e := parseInstanceID(f)
		if e != nil {
			return nil, e
		}
		ids = append(ids, id)
	}
	sort.Sort(ids)
	return
}
开发者ID:soundcloud,项目名称:visor,代码行数:23,代码来源:instance.go


示例8: getRevision

func getRevision(app *App, ref string, s cp.Snapshotable) (*Revision, error) {
	r := &Revision{
		dir: cp.NewDir(app.dir.Prefix(revsPath, ref), s.GetSnapshot()),
		App: app,
		Ref: ref,
	}

	f, err := r.dir.GetFile(archiveURLPath, new(cp.StringCodec))
	if err != nil {
		if cp.IsErrNoEnt(err) {
			exists, _, err := s.GetSnapshot().Exists(r.dir.Name)
			if err != nil {
				return nil, err
			}
			if !exists {
				return nil, errorf(ErrNotFound, `revision "%s" not found for app %s`, ref, app.Name)
			}
			return nil, errorf(ErrNotFound, "archive-url not found for %s:%s", app.Name, ref)
		}
		return nil, err
	}
	r.ArchiveURL = f.Value.(string)

	f, err = r.dir.GetFile(registeredPath, new(cp.StringCodec))
	if err != nil {
		if cp.IsErrNoEnt(err) {
			err = errorf(ErrNotFound, "registered not found for %s:%s", app.Name, ref)
		}
		return nil, err
	}
	r.Registered, err = parseTime(f.Value.(string))
	if err != nil {
		return nil, err
	}

	return r, nil
}
开发者ID:soundcloud,项目名称:visor,代码行数:37,代码来源:revision.go


示例9: getEnv

func getEnv(app *App, ref string, s cp.Snapshotable) (*Env, error) {
	e := &Env{
		dir: cp.NewDir(app.dir.Prefix(envsPath, ref), s.GetSnapshot()),
		App: app,
		Ref: ref,
	}

	_, err := e.dir.GetFile(varsPath, &cp.JsonCodec{DecodedVal: &e.Vars})
	if err != nil {
		if cp.IsErrNoEnt(err) {
			exists, _, err := s.GetSnapshot().Exists(e.dir.Name)
			if err != nil {
				return nil, err
			}
			if !exists {
				return nil, errorf(ErrNotFound, `env "%s" not found for app %s`, ref, app.Name)
			}
			return nil, errorf(ErrNotFound, "vars not found for %s#%s", app.Name, ref)
		}
		return nil, err
	}

	f, err := e.dir.GetFile(registeredPath, new(cp.StringCodec))
	if err != nil {
		if cp.IsErrNoEnt(err) {
			err = errorf(ErrNotFound, `registered not found for %s`, ref)
		}
		return nil, err
	}
	e.Registered, err = parseTime(f.Value.(string))
	if err != nil {
		return nil, err
	}

	return e, nil
}
开发者ID:soundcloud,项目名称:visor,代码行数:36,代码来源:env.go


示例10: storeFromSnapshotable

func storeFromSnapshotable(sp cp.Snapshotable) *Store {
	return &Store{sp.GetSnapshot()}
}
开发者ID:soundcloud,项目名称:visor,代码行数:3,代码来源:visor.go


示例11: getInstance

func getInstance(id int64, s cp.Snapshotable) (*Instance, error) {
	i := &Instance{
		ID:     id,
		Status: InsStatusPending,
		dir:    cp.NewDir(instancePath(id), s.GetSnapshot()),
	}

	exists, _, err := s.GetSnapshot().Exists(i.dir.Name)
	if err != nil {
		return nil, err
	}
	if !exists {
		return nil, errorf(ErrNotFound, `instance '%d' not found`, id)
	}

	f, err := i.dir.GetFile(startPath, new(cp.ListCodec))
	if cp.IsErrNoEnt(err) {
		// Ignore
	} else if err != nil {
		return nil, err
	} else {
		fields := f.Value.([]string)

		if len(fields) > 0 { // IP
			i.Status = InsStatusClaimed
			i.IP = fields[0]
		}
		if len(fields) > 1 { // Port
			i.Status = InsStatusRunning
			i.Port, err = strconv.Atoi(fields[1])
			if err != nil {
				return nil, errorf(ErrInvalidPort, "invalid port: "+fields[1])
			}
		}
		if len(fields) > 2 { // Hostname
			i.Host = fields[2]
		}
		if len(fields) > 3 { // TelePort
			i.TelePort, err = strconv.Atoi(fields[3])
			if err != nil {
				return nil, errorf(ErrInvalidPort, "invalid teleport: "+fields[3])
			}
		}
	}

	statusStr, _, err := i.dir.Get(statusPath)
	if cp.IsErrNoEnt(err) {
		err = nil
	} else if err == nil {
		i.Status = InsStatus(statusStr)
	} else {
		return nil, err
	}

	if i.Status == InsStatusRunning {
		_, _, err := i.dir.Get(stopPath)
		if err == nil {
			i.Status = InsStatusStopping
		} else if !cp.IsErrNoEnt(err) {
			return nil, err
		}
	}

	f, err = i.dir.GetFile(objectPath, new(cp.ListCodec))
	if err != nil {
		return nil, errorf(ErrNotFound, "object file not found for instance %d", id)
	}

	fields := f.Value.([]string)
	if len(fields) < 3 {
		return nil, errorf(ErrInvalidFile, "object file for %d has %d instead %d fields", id, len(fields), 3)
	}

	i.AppName = fields[0]
	i.RevisionName = fields[1]
	i.ProcessName = fields[2]
	i.Env = fields[3]

	i.Restarts, _, err = i.getRestarts()
	if err != nil {
		return nil, err
	}

	f, err = i.dir.GetFile(registeredPath, new(cp.StringCodec))
	if err != nil {
		return nil, err
	}
	i.Registered, err = parseTime(f.Value.(string))
	if err != nil {
		return nil, err
	}

	f, err = i.claimDir().GetFile(i.IP, new(cp.StringCodec))
	if err != nil {
		if cp.IsErrNoEnt(err) {
			return i, nil
		}
		return nil, err
	}

//.........这里部分代码省略.........
开发者ID:soundcloud,项目名称:visor,代码行数:101,代码来源:instance.go


示例12: waitRunners

func waitRunners(s cp.Snapshotable) (cp.Event, error) {
	sp := s.GetSnapshot()
	return sp.Wait(path.Join(runnersPath, "*", "*"))
}
开发者ID:soundcloud,项目名称:visor,代码行数:4,代码来源:runner.go



注:本文中的github.com/soundcloud/cotterpin.Snapshotable类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang doozer.Conn类代码示例发布时间:2022-05-28
下一篇:
Golang store.StoreManager类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap