當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Transport.LocatorFor方法代碼示例

本文整理匯總了Golang中github.com/openshift/geard/transport.Transport.LocatorFor方法的典型用法代碼示例。如果您正苦於以下問題:Golang Transport.LocatorFor方法的具體用法?Golang Transport.LocatorFor怎麽用?Golang Transport.LocatorFor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/openshift/geard/transport.Transport的用法示例。


在下文中一共展示了Transport.LocatorFor方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewHostLocators

func NewHostLocators(t transport.Transport, values ...string) (Locators, error) {
	out := make(Locators, 0, len(values))
	for i := range values {
		r, err := t.LocatorFor(values[i])
		if err != nil {
			return out, err
		}
		out = append(out, &ResourceLocator{"", "", r})
	}
	return out, nil
}
開發者ID:rajatchopra,項目名稱:geard,代碼行數:11,代碼來源:locator.go

示例2: NewResourceLocator

func NewResourceLocator(t transport.Transport, defaultType ResourceType, value string) (Locator, error) {
	res, host, id, errs := SplitTypeHostSuffix(value)
	if errs != nil {
		return nil, errs
	}
	if res == "" {
		res = defaultType
	}
	locator, err := t.LocatorFor(host)
	if err != nil {
		return nil, err
	}
	return &ResourceLocator{ResourceType(res), id, locator}, nil
}
開發者ID:rajatchopra,項目名稱:geard,代碼行數:14,代碼來源:locator.go

示例3: LocatorsForDeploymentInstances

func LocatorsForDeploymentInstances(t transport.Transport, instances deployment.InstanceRefs) (cmd.Locators, error) {
	locators := make(cmd.Locators, 0, len(instances))
	for _, instance := range instances {
		if instance.On != nil {
			locator, err := t.LocatorFor(*instance.On)
			if err != nil {
				return cmd.Locators{}, err
			}
			resource := &cmd.ResourceLocator{cloc.ResourceTypeContainer, string(instance.Id), locator}
			locators = append(locators, resource)
		}
	}
	return locators, nil
}
開發者ID:jcantrill,項目名稱:geard,代碼行數:14,代碼來源:deployment.go

示例4: Describe

func (d Deployment) Describe(placement PlacementStrategy, t transport.Transport) (next *Deployment, removed InstanceRefs, err error) {
	// copy the container list and clear any intermediate state
	sources := d.Containers.Copy()

	// assign instances to containers or the remove list
	for i := range d.Instances {
		instance := &d.Instances[i]
		copied := *instance
		// is the instance invalid or no longer part of the cluster
		if instance.On == nil {
			continue
		}
		if instance.on == nil {
			locator, errl := t.LocatorFor(*instance.On)
			if errl != nil {
				err = errors.New(fmt.Sprintf("The host %s for instance %s is not recognized - you may be using a different transport than originally specified: %s", *instance.On, instance.Id, errl.Error()))
				return
			}
			instance.on = locator
		}
		if placement.RemoveFromLocation(instance.on) {
			removed = append(removed, &copied)
			continue
		}
		// locate the container
		c, found := sources.Find(instance.From)
		if !found {
			removed = append(removed, &copied)
			continue
		}
		c.AddInstance(&copied)
	}

	// create new instances for each container
	added := make(InstanceRefs, 0)
	for i := range sources {
		c := &sources[i]
		if errc := d.createInstances(c); errc != nil {
			err = errc
			return
		}
		for j := range c.instances {
			if c.instances[j].add {
				added = append(added, c.instances[j])
			}
		}
	}

	// assign to hosts
	errp := placement.Assign(added, sources)
	if errp != nil {
		err = errp
		return
	}

	// cull any instances flagged for removal and enforce upper limits
	for i := range sources {
		for _, instance := range sources[i].Instances() {
			if instance.On == nil && !instance.remove {
				err = errors.New("deployment: one or more instances were not assigned to a host")
				return
			}
		}
		removed = append(removed, sources[i].trimInstances()...)
	}

	// check for basic link consistency and ordering
	links, erro := sources.OrderLinks()
	if erro != nil {
		err = erro
		return
	}

	// expose ports for all links
	for i := range links {
		if erre := links[i].exposePorts(); erre != nil {
			err = erre
			return
		}
	}

	// load and reserve all ports
	table, errn := NewInstancePortTable(sources)
	if errn != nil {
		err = errn
		return
	}
	for i := range links {
		if errr := links[i].reserve(table); errr != nil {
			err = errr
			return
		}
	}

	// generate the links
	for i := range links {
		if erra := links[i].appendLinks(); erra != nil {
			err = erra
			return
		}
//.........這裏部分代碼省略.........
開發者ID:jhadvig,項目名稱:geard,代碼行數:101,代碼來源:deployment.go


注:本文中的github.com/openshift/geard/transport.Transport.LocatorFor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。