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


Golang App.UnbindUnit方法代码示例

本文整理汇总了Golang中github.com/tsuru/tsuru/provision.App.UnbindUnit方法的典型用法代码示例。如果您正苦于以下问题:Golang App.UnbindUnit方法的具体用法?Golang App.UnbindUnit怎么用?Golang App.UnbindUnit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/tsuru/tsuru/provision.App的用法示例。


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

示例1: Destroy

func (p *dockerProvisioner) Destroy(app provision.App) error {
	containers, err := p.listContainersByApp(app.GetName())
	if err != nil {
		log.Errorf("Failed to list app containers: %s", err.Error())
		return err
	}
	runInContainers(containers, func(c *container, _ chan *container) error {
		unit := c.asUnit(app)
		err := app.UnbindUnit(&unit)
		if err != nil {
			log.Errorf("Unable to unbind unit %q: %s", c.ID, err)
		}
		err = p.removeContainer(c, app)
		if err != nil {
			log.Errorf("Unable to destroy container %s: %s", c.ID, err.Error())
		}
		return nil
	}, nil, true)
	images, err := listAppImages(app.GetName())
	if err != nil {
		log.Errorf("Failed to get image ids for app %s: %s", app.GetName(), err.Error())
	}
	cluster := p.getCluster()
	for _, imageId := range images {
		err := cluster.RemoveImage(imageId)
		if err != nil {
			log.Errorf("Failed to remove image %s: %s", imageId, err.Error())
		}
		err = cluster.RemoveFromRegistry(imageId)
		if err != nil {
			log.Errorf("Failed to remove image %s from registry: %s", imageId, err.Error())
		}
	}
	err = deleteAllAppImageNames(app.GetName())
	if err != nil {
		log.Errorf("Failed to remove image names from storage for app %s: %s", app.GetName(), err.Error())
	}
	r, err := getRouterForApp(app)
	if err != nil {
		log.Errorf("Failed to get router: %s", err.Error())
		return err
	}
	err = r.RemoveBackend(app.GetName())
	if err != nil {
		log.Errorf("Failed to remove route backend: %s", err.Error())
		return err
	}
	return nil
}
开发者ID:Lh4cKg,项目名称:tsuru,代码行数:49,代码来源:provisioner.go

示例2: RemoveUnits

func (p *dockerProvisioner) RemoveUnits(a provision.App, units uint, processName string, w io.Writer) error {
	if a == nil {
		return errors.New("remove units: app should not be nil")
	}
	if units == 0 {
		return errors.New("cannot remove zero units")
	}
	var err error
	if w == nil {
		w = ioutil.Discard
	}
	imgId, err := appCurrentImageName(a.GetName())
	if err != nil {
		return err
	}
	_, processName, err = processCmdForImage(processName, imgId)
	if err != nil {
		return err
	}
	containers, err := p.listContainersByProcess(a.GetName(), processName)
	if err != nil {
		return err
	}
	if len(containers) < int(units) {
		return fmt.Errorf("cannot remove %d units from process %q, only %d available", units, processName, len(containers))
	}
	var plural string
	if units > 1 {
		plural = "s"
	}
	fmt.Fprintf(w, "\n---- Removing %d unit%s ----\n", units, plural)
	coll := p.collection()
	defer coll.Close()
	toRemove := make([]container, 0, units)
	for i := 0; i < int(units); i++ {
		var containerID string
		var c *container
		containerID, err = p.scheduler.GetRemovableContainer(a.GetName(), processName)
		if err != nil {
			fmt.Println("GetRemovableContainer")
			break
		}
		c, err = p.getContainer(containerID)
		if err != nil {
			fmt.Println("getContainer")
			break
		}
		err = coll.Remove(bson.M{"id": c.ID})
		if err != nil {
			fmt.Println("remove")
			break
		}
		toRemove = append(toRemove, *c)
	}
	if err != nil {
		for _, c := range toRemove {
			coll.Insert(c)
		}
		return err
	}
	runInContainers(toRemove, func(c *container, toRollback chan *container) error {
		unit := c.asUnit(a)
		err = a.UnbindUnit(&unit)
		if err != nil {
			log.Errorf("Ignored error trying to unbind unit %q: %s", c.ID, err)
		}
		err = p.removeContainer(c, a)
		if err != nil {
			log.Errorf("Ignored error trying to remove unit %q: %s", c.ID, err)
		}
		fmt.Fprintf(w, " ---> Removed unit %s...\n", c.shortID())
		return nil
	}, nil, true)
	return nil
}
开发者ID:Lh4cKg,项目名称:tsuru,代码行数:75,代码来源:provisioner.go


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