ranch

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseConfig

func ParseConfig(configPath string) ([]common.Resource, error)

ParseConfig reads in configPath and returns a list of resource objects on success.

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

func NewRanch(config string, s *Storage) (*Ranch, error)

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

func (r *Ranch) Acquire(rType, state, dest, owner string) (*common.Resource, error)

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) Metric

func (r *Ranch) Metric(rtype string) (common.Metric, error)

Metric returns a metric object with metrics filled in

func (*Ranch) Release

func (r *Ranch) Release(name, dest, owner string) error

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

func (r *Ranch) SyncConfig(config string) error

SyncConfig updates resource list from a file

func (*Ranch) Update

func (r *Ranch) Update(name, owner, state string, ud *common.UserData) error

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

func (s *Storage) AddResource(resource common.Resource) error

AddResource adds a new resource

func (*Storage) DeleteResource

func (s *Storage) DeleteResource(name string) error

DeleteResource deletes a resource if it exists, errors otherwise

func (*Storage) GetResource

func (s *Storage) GetResource(name string) (common.Resource, error)

GetResource gets an existing resource, errors otherwise

func (*Storage) GetResources

func (s *Storage) GetResources() ([]common.Resource, error)

GetResources list all resources

func (*Storage) SyncResources

func (s *Storage) SyncResources(data []common.Resource) error

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.

func (*Storage) UpdateResource

func (s *Storage) UpdateResource(resource common.Resource) error

UpdateResource updates a resource if it exists, errors otherwise

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL