當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。