当前位置: 首页>>代码示例>>Golang>>正文


Golang db.Storage类代码示例

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


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

示例1: createApp

func createApp(conn *db.Storage, name, state string) {
	a := app.App{
		Name: name,
	}
	err := conn.Apps().Insert(&a)
	if err != nil {
		panic(err)
	}
}
开发者ID:ningjh,项目名称:tsuru,代码行数:9,代码来源:runner_test.go

示例2: createTestApp

func createTestApp(conn *db.Storage, name, framework string, teams []string) (app.App, error) {
	a := app.App{
		Name:     name,
		Platform: framework,
		Teams:    teams,
	}
	err := conn.Apps().Insert(&a)
	return a, err
}
开发者ID:ningjh,项目名称:tsuru,代码行数:9,代码来源:bind_test.go

示例3: getFakeApps

func getFakeApps(conn *db.Storage) ([]app.App, []string) {
	apps := make([]app.App, 20)
	names := make([]string, len(apps))
	for i := range apps {
		name := fmt.Sprintf("app%d", i+1)
		names[i] = name
		apps[i] = app.App{
			Name:     name,
			Platform: "python",
		}
		err := conn.Apps().Insert(apps[i])
		if err != nil {
			panic(err)
		}
	}
	return apps, names
}
开发者ID:rochacon,项目名称:tsuru,代码行数:17,代码来源:bench_test.go

示例4: RemoveCName

func (app *App) RemoveCName(cnames ...string) error {
	var err error
	var cnamesDone []string
	for _, cname := range cnames {
		count := 0
		for _, appCname := range app.CName {
			if cname == appCname {
				count += 1
			}
		}
		if count == 0 {
			err = stderr.New("cname not exists!")
			break
		}
		if s, ok := Provisioner.(provision.CNameManager); ok {
			err = s.UnsetCName(app, cname)
			if err != nil {
				break
			}
		}
		var conn *db.Storage
		conn, err = db.Conn()
		if err != nil {
			break
		}
		defer conn.Close()
		err = conn.Apps().Update(
			bson.M{"name": app.Name},
			bson.M{"$pull": bson.M{"cname": cname}},
		)
		if err != nil {
			break
		}
		cnamesDone = append(cnamesDone, cname)
	}
	if err != nil {
		var rollback rollbackFunc
		if s, ok := Provisioner.(provision.CNameManager); ok {
			rollback = s.SetCName
		}
		app.rollbackCNames(rollback, cnamesDone, "$push")
		return err
	}
	return nil
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:45,代码来源:app.go

示例5: AddCName

// AddCName adds a CName to app. It updates the attribute,
// calls the SetCName function on the provisioner and saves
// the app in the database, returning an error when it cannot save the change
// in the database or add the CName on the provisioner.
func (app *App) AddCName(cnames ...string) error {
	var cnamesDone []string
	var err error
	for _, cname := range cnames {
		if !cnameRegexp.MatchString(cname) {
			err = stderr.New("Invalid cname")
			break
		}
		if cnameExists(cname) {
			err = stderr.New("cname already exists!")
			break
		}
		if s, ok := Provisioner.(provision.CNameManager); ok {
			err = s.SetCName(app, cname)
			if err != nil {
				break
			}
		}
		var conn *db.Storage
		conn, err = db.Conn()
		if err != nil {
			break
		}
		defer conn.Close()
		err = conn.Apps().Update(
			bson.M{"name": app.Name},
			bson.M{"$push": bson.M{"cname": cname}},
		)
		if err != nil {
			break
		}
		cnamesDone = append(cnamesDone, cname)
	}
	if err != nil {
		var rollback rollbackFunc
		if s, ok := Provisioner.(provision.CNameManager); ok {
			rollback = s.UnsetCName
		}
		app.rollbackCNames(rollback, cnamesDone, "$pull")
		return err
	}
	app.CName = append(app.CName, cnamesDone...)
	return nil
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:48,代码来源:app.go

示例6: RebuildRoutes

func (app *App) RebuildRoutes() (*RebuildRoutesResult, error) {
	routerName, err := app.GetRouter()
	if err != nil {
		return nil, err
	}
	r, err := router.Get(routerName)
	if err != nil {
		return nil, err
	}
	err = r.AddBackend(app.Name)
	if err != nil && err != router.ErrBackendExists {
		return nil, err
	}
	var newAddr string
	if newAddr, err = r.Addr(app.GetName()); err == nil && newAddr != app.Ip {
		var conn *db.Storage
		conn, err = db.Conn()
		if err != nil {
			return nil, err
		}
		defer conn.Close()
		err = conn.Apps().Update(bson.M{"name": app.Name}, bson.M{"$set": bson.M{"ip": newAddr}})
		if err != nil {
			return nil, err
		}
	}
	for _, cname := range app.CName {
		err := r.SetCName(cname, app.Name)
		if err != nil && err != router.ErrCNameExists {
			return nil, err
		}
	}
	oldRoutes, err := r.Routes(app.GetName())
	if err != nil {
		return nil, err
	}
	expectedMap := make(map[string]*url.URL)
	units, err := Provisioner.RoutableUnits(app)
	if err != nil {
		return nil, err
	}
	for _, unit := range units {
		expectedMap[unit.Address.String()] = unit.Address
	}
	var toRemove []*url.URL
	for _, url := range oldRoutes {
		if _, isPresent := expectedMap[url.String()]; isPresent {
			delete(expectedMap, url.String())
		} else {
			toRemove = append(toRemove, url)
		}
	}
	var result RebuildRoutesResult
	for _, toAddUrl := range expectedMap {
		err := r.AddRoute(app.GetName(), toAddUrl)
		if err != nil {
			return nil, err
		}
		result.Added = append(result.Added, toAddUrl.String())
	}
	for _, toRemoveUrl := range toRemove {
		err := r.RemoveRoute(app.GetName(), toRemoveUrl)
		if err != nil {
			return nil, err
		}
		result.Removed = append(result.Removed, toRemoveUrl.String())
	}
	return &result, nil
}
开发者ID:Zapelini,项目名称:tsuru,代码行数:69,代码来源:app.go

示例7: getApp

func getApp(conn *db.Storage, c *gocheck.C) *app.App {
	a := &app.App{Name: "umaappqq"}
	err := conn.Apps().Insert(&a)
	c.Assert(err, gocheck.IsNil)
	return a
}
开发者ID:rochacon,项目名称:tsuru,代码行数:6,代码来源:collector_test.go

示例8: destroyApps

func destroyApps(conn *db.Storage) {
	allApps := append(buildingApps, runningApps...)
	conn.Apps().Remove(bson.M{"name": bson.M{"$in": allApps}})
}
开发者ID:ningjh,项目名称:tsuru,代码行数:4,代码来源:runner_test.go

示例9: Restart

func (p *FakeProvisioner) Restart(app provision.App, process string, w io.Writer) error {
	if err := p.getError("Restart"); err != nil {
		return err
	}
	p.mut.Lock()
	defer p.mut.Unlock()
	pApp, ok := p.apps[app.GetName()]
	if !ok {
		return errNotProvisioned
	}
	pApp.restarts[process]++
	p.apps[app.GetName()] = pApp
	if w != nil {
		fmt.Fprintf(w, "restarting app")
	}
	r := routertest.FakeRouter
	err := r.AddBackend(app.GetName())
	if err != nil && err != router.ErrBackendExists {
		return err
	}
	var newAddr string
	if newAddr, err = r.Addr(app.GetName()); err == nil && newAddr != app.GetIp() {
		var conn *db.Storage
		conn, err = db.Conn()
		if err != nil {
			return err
		}
		defer conn.Close()
		err = conn.Apps().Update(bson.M{"name": app.GetName()}, bson.M{"$set": bson.M{"ip": newAddr}})
		if err != nil {
			return err
		}
	}
	for _, cname := range app.GetCname() {
		err = r.SetCName(cname, app.GetName())
		if err != nil && err != router.ErrCNameExists {
			return err
		}
	}
	oldRoutes, err := r.Routes(app.GetName())
	if err != nil {
		return err
	}
	expectedMap := make(map[string]*url.URL)
	units := p.apps[app.GetName()].units
	if err != nil {
		return err
	}
	for _, unit := range units {
		expectedMap[unit.Address.String()] = unit.Address
	}
	var toRemove []*url.URL
	for _, url := range oldRoutes {
		if _, isPresent := expectedMap[url.String()]; isPresent {
			delete(expectedMap, url.String())
		} else {
			toRemove = append(toRemove, url)
		}
	}
	for _, toAddUrl := range expectedMap {
		err := r.AddRoute(app.GetName(), toAddUrl)
		if err != nil {
			return err
		}
	}
	for _, toRemoveUrl := range toRemove {
		err := r.RemoveRoute(app.GetName(), toRemoveUrl)
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:tsuru,项目名称:tsuru,代码行数:73,代码来源:fake_provisioner.go

示例10:

		}
		for _, cname := range cnames {
			err := cnameRouter.UnsetCName(cname, app.Name)
			if err != nil {
				log.Errorf("BACKWARD set cnames - unable to unset cname: %s", err)
			}
		}
	},
}

var saveCNames = action.Action{
	Name: "add-cname-save-in-database",
	Forward: func(ctx action.FWContext) (action.Result, error) {
		app := ctx.Params[0].(*App)
		cnames := ctx.Params[1].([]string)
		var conn *db.Storage
		conn, err := db.Conn()
		if err != nil {
			return nil, err
		}
		defer conn.Close()
		var cnamesDone []string
		for _, cname := range cnames {
			err = conn.Apps().Update(
				bson.M{"name": app.Name},
				bson.M{"$push": bson.M{"cname": cname}},
			)
			if err != nil {
				for _, c := range cnamesDone {
					conn.Apps().Update(
						bson.M{"name": app.Name},
开发者ID:tsuru,项目名称:tsuru,代码行数:31,代码来源:actions.go


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