Documentation ¶
Index ¶
- func ParseConfig(configPath string) ([]common.Resource, error)
- type OwnerNotMatch
- type Ranch
- func (r *Ranch) Acquire(rType, state, dest, owner string) (*common.Resource, error)
- func (r *Ranch) AcquireByState(state, dest, owner string, names []string) ([]common.Resource, error)
- func (r *Ranch) LogStatus()
- func (r *Ranch) Metric(rtype string) (common.Metric, error)
- func (r *Ranch) Release(name, dest, owner string) error
- func (r *Ranch) Reset(rtype, state string, expire time.Duration, dest string) (map[string]string, error)
- func (r *Ranch) SyncConfig(config string) error
- func (r *Ranch) Update(name, owner, state string, ud *common.UserData) error
- type ResourceNotFound
- type StateNotMatch
- type Storage
- func (s *Storage) AddResource(resource common.Resource) error
- func (s *Storage) DeleteResource(name string) error
- func (s *Storage) GetResource(name string) (common.Resource, error)
- func (s *Storage) GetResources() ([]common.Resource, error)
- func (s *Storage) SyncResources(data []common.Resource) error
- func (s *Storage) UpdateResource(resource common.Resource) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type OwnerNotMatch ¶
type OwnerNotMatch struct {
// contains filtered or unexported fields
}
OwnerNotMatch will be returned if request owner does not match current owner for target resource.
func (OwnerNotMatch) Error ¶
func (o OwnerNotMatch) Error() string
type Ranch ¶
type Ranch struct { Storage *Storage // For testing UpdateTime func() time.Time // contains filtered or unexported fields }
Ranch is the place which all of the Resource objects lives.
func NewRanch ¶
NewRanch creates a new Ranch object. In: config - path to resource file
storage - path to where to save/restore the state data
Out: A Ranch object, loaded from config/storage, or error
func (*Ranch) Acquire ¶
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.
func (*Ranch) AcquireByState ¶
func (r *Ranch) AcquireByState(state, dest, owner string, names []string) ([]common.Resource, error)
AcquireByState checks out resources of a given type without an owner, that matches a list of resources names. In: state - current state of the requested resource
dest - destination state of the requested resource owner - requester of the resource names - names of resource to acquire
Out: A valid list of Resource object on success, or
ResourceNotFound error if target type resource does not exist in target state.
func (*Ranch) LogStatus ¶
func (r *Ranch) LogStatus()
LogStatus outputs current status of all resources
func (*Ranch) Release ¶
Release unsets owner for target resource and move it to a new state. In: name - name of the target resource
dest - destination state of the resource owner - owner of the resource
Out: nil on success, or
OwnerNotMatch error if owner does not match current owner of the resource, or ResourceNotFound error if target named resource does not exist.
func (*Ranch) Reset ¶
func (r *Ranch) Reset(rtype, state string, expire time.Duration, dest string) (map[string]string, error)
Reset unstucks a type of stale resource to a new state. In: rtype - type of the resource
state - current state of the resource expire - duration before resource's last update dest - destination state of expired resources
Out: map of resource name - resource owner.
func (*Ranch) SyncConfig ¶
SyncConfig updates resource list from a file
func (*Ranch) Update ¶
Update updates the timestamp of a target resource. In: name - name of the target resource
state - current state of the resource owner - current owner of the resource info - information on how to use the resource
Out: nil on success, or
OwnerNotMatch error if owner does not match current owner of the resource, or ResourceNotFound error if target named resource does not exist, or StateNotMatch error if state does not match current state of the resource.
type ResourceNotFound ¶
type ResourceNotFound struct {
// contains filtered or unexported fields
}
ResourceNotFound will be returned if requested resource does not exist.
func (ResourceNotFound) Error ¶
func (r ResourceNotFound) Error() string
type StateNotMatch ¶
type StateNotMatch struct {
// contains filtered or unexported fields
}
StateNotMatch will be returned if requested state does not match current state for target resource.
func (StateNotMatch) Error ¶
func (s StateNotMatch) Error() string
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage is used to decouple ranch functionality with the resource persistence layer
func NewStorage ¶
func NewStorage(r storage.PersistenceLayer, storage string) (*Storage, error)
NewStorage instantiates a new Storage with a PersistenceLayer implementation If storage string is not empty, it will read resource data from the file
func (*Storage) AddResource ¶
AddResource adds a new resource
func (*Storage) DeleteResource ¶
DeleteResource deletes a resource if it exists, errors otherwise
func (*Storage) GetResource ¶
GetResource gets an existing resource, errors otherwise
func (*Storage) GetResources ¶
GetResources list all resources
func (*Storage) SyncResources ¶
SyncResources will update resources every 10 mins. It will append newly added resources to ranch.Resources, And try to remove newly deleted resources from ranch.Resources. If the newly deleted resource is currently held by a user, the deletion will yield to next update cycle.