本文整理汇总了Golang中github.com/soundcloud/cotterpin.Snapshotable.GetSnapshot方法的典型用法代码示例。如果您正苦于以下问题:Golang Snapshotable.GetSnapshot方法的具体用法?Golang Snapshotable.GetSnapshot怎么用?Golang Snapshotable.GetSnapshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/soundcloud/cotterpin.Snapshotable
的用法示例。
在下文中一共展示了Snapshotable.GetSnapshot方法的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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例10: storeFromSnapshotable
func storeFromSnapshotable(sp cp.Snapshotable) *Store {
return &Store{sp.GetSnapshot()}
}
示例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
}
//.........这里部分代码省略.........
示例12: waitRunners
func waitRunners(s cp.Snapshotable) (cp.Event, error) {
sp := s.GetSnapshot()
return sp.Wait(path.Join(runnersPath, "*", "*"))
}