boskos/ranch/ranch.go
func (r *Ranch) Acquire(rType, state, dest, owner string) (*common.Resource, error) {
	r.resourcesLock.Lock()
	defer r.resourcesLock.Unlock()

	resources, err := r.Storage.GetResources()
	if err != nil {
		logrus.WithError(err).Errorf("could not get resources")
		return nil, &ResourceNotFound{rType}
	}

	foundType := false
	for idx := range resources {
		res := resources[idx]
		if rType == res.Type {
			foundType = true
			if state == res.State && res.Owner == "" {
				res.LastUpdate = r.UpdateTime()
				res.Owner = owner
				res.State = dest
				if err := r.Storage.UpdateResource(res); err != nil {
					logrus.WithError(err).Errorf("could not update resource %s", res.Name)
					return nil, err
				}
				return &res, nil
			}
		}
	}
	if foundType {
		return nil, &ResourceNotFound{rType}
	}
	return nil, &ResourceTypeNotFound{rType}
}
func (r *Ranch) Acquire(rType, state, dest, owner string) (*common.Resource, error) {
	r.resourcesLock.Lock()
	defer r.resourcesLock.Unlock()

	resources, err := r.Storage.GetResources()
	if err != nil {
		logrus.WithError(err).Errorf("could not get resources")
		return nil, &ResourceNotFound{rType}
	}

	foundType := false
	for idx := range resources {
		res := resources[idx]
		if rType == res.Type {
			foundType = true
			if state == res.State && res.Owner == "" {
				res.LastUpdate = r.UpdateTime()
				res.Owner = owner
				res.State = dest
				if err := r.Storage.UpdateResource(res); err != nil {
					logrus.WithError(err).Errorf("could not update resource %s", res.Name)
					return nil, err
				}
				return &res, nil
			}
		}
	}
	if foundType {
		return nil, &ResourceNotFound{rType}
	}
	return nil, &ResourceTypeNotFound{rType}
}
// Acquire checks out a type of resource in certain state without an owner,
// and move the checked out resource to the end of the resource list.
// In: rtype - name of the target resource
//     state - current state of the requested resource
//     dest - destination state of the requested resource
//     owner - requester of the resource
// Out: A valid Resource object on success, or
//      ResourceNotFound error if target type resource does not exist in target state.