boskos/mason/client.go
func (c *Client) Acquire(rtype, state, dest string) (*common.Resource, error) {
	var resourcesToRelease []common.Resource
	releaseOnFailure := func() {
		for _, r := range resourcesToRelease {
			if err := c.basic.ReleaseOne(r.Name, common.Dirty); err != nil {
				logrus.WithError(err).Warningf("failed to release resource %s", r.Name)
			}
		}
	}
	res, err := c.basic.Acquire(rtype, state, dest)
	if err != nil {
		return nil, err
	}
	var leasedResources common.LeasedResources
	if err = res.UserData.Extract(LeasedResources, &leasedResources); err != nil {
		if _, ok := err.(*common.UserDataNotFound); !ok {
			logrus.WithError(err).Errorf("cannot parse %s from User Data", LeasedResources)
			return nil, err
		}
	}
	resourcesToRelease = append(resourcesToRelease, *res)
	resources, err := c.basic.AcquireByState(res.Name, dest, leasedResources)
	if err != nil {
		releaseOnFailure()
		return nil, err
	}
	resourcesToRelease = append(resourcesToRelease, resources...)
	c.updateResource(*res)
	return res, nil
}
func (c *Client) Acquire(rtype, state, dest string) (*common.Resource, error) {
	var resourcesToRelease []common.Resource
	releaseOnFailure := func() {
		for _, r := range resourcesToRelease {
			if err := c.basic.ReleaseOne(r.Name, common.Dirty); err != nil {
				logrus.WithError(err).Warningf("failed to release resource %s", r.Name)
			}
		}
	}
	res, err := c.basic.Acquire(rtype, state, dest)
	if err != nil {
		return nil, err
	}
	var leasedResources common.LeasedResources
	if err = res.UserData.Extract(LeasedResources, &leasedResources); err != nil {
		if _, ok := err.(*common.UserDataNotFound); !ok {
			logrus.WithError(err).Errorf("cannot parse %s from User Data", LeasedResources)
			return nil, err
		}
	}
	resourcesToRelease = append(resourcesToRelease, *res)
	resources, err := c.basic.AcquireByState(res.Name, dest, leasedResources)
	if err != nil {
		releaseOnFailure()
		return nil, err
	}
	resourcesToRelease = append(resourcesToRelease, resources...)
	c.updateResource(*res)
	return res, nil
}
func ( c * Client ) Acquire ( rtype , state , dest string ) ( * common . Resource , error ) { var resourcesToRelease [ ] common . Resource releaseOnFailure := func ( ) { for _ , r := range resourcesToRelease { if err := c . basic . ReleaseOne ( r . Name , common . Dirty ) ; err != nil { logrus . WithError ( err ) . Warningf ( " " , r . Name ) } } } res , err := c . basic . Acquire ( rtype , state , dest ) if err != nil { return nil , err } var leasedResources common . LeasedResources if err = res . UserData . Extract ( LeasedResources , & leasedResources ) ; err != nil { if _ , ok := err . ( * common . UserDataNotFound ) ; ! ok { logrus . WithError ( err ) . Errorf ( " " , LeasedResources ) return nil , err } } resourcesToRelease = append ( resourcesToRelease , * res ) resources , err := c . basic . AcquireByState ( res . Name , dest , leasedResources ) if err != nil { releaseOnFailure ( ) return nil , err } resourcesToRelease = append ( resourcesToRelease , resources ... ) c . updateResource ( * res ) return res , nil }
// Acquire gets a resource with associated leased resources
Acquire gets a resource with associated leased resources