Documentation ¶
Index ¶
- Constants
- type Action
- type Effect
- type Instance
- type Iter
- type Lease
- func (ls *Lease) Consumptive() (matched bool)
- func (ls *Lease) DecayTime() time.Time
- func (ls *Lease) Decayed(at time.Time) bool
- func (ls *Lease) EffectiveRefresh() (interval time.Duration)
- func (ls *Lease) ExpirationTime() time.Time
- func (ls *Lease) Expired(at time.Time) bool
- func (ls *Lease) MatchHostUser(resource, host, user string) (matched bool)
- func (ls *Lease) MatchInstance(resource string, inst Instance) (matched bool)
- func (ls *Lease) MatchResource(resource string) (matched bool)
- func (ls *Lease) MatchStatus(status Status) (matched bool)
- func (ls *Lease) ResourceName() string
- type Op
- type Processor
- type Properties
- type Provider
- type Refresh
- type Set
- func (s Set) DecayDuration(at time.Time) (duration time.Duration)
- func (s Set) DecayTime() (decay time.Time)
- func (s Set) ExpirationTime() (expiration time.Time)
- func (s Set) HostUser(resource, host, user string) (matched Set)
- func (s Set) Index(resource string, instance Instance) (index int)
- func (s Set) Instance(resource string, instance Instance) (ls Lease, found bool)
- func (s Set) Len() int
- func (s Set) Less(i, j int) bool
- func (s Set) Property(keys ...string) (values []string)
- func (s Set) Resource(resource string) (matched Set)
- func (s Set) Stats() (stats Stats)
- func (s Set) Status(status Status) (matched Set)
- func (s Set) Swap(i, j int)
- func (s Set) User(user string) (matched Set)
- type Snapshot
- type State
- type Stats
- type Status
- type Subject
- type Tally
- type Tx
- func (tx *Tx) Create(ls Lease) error
- func (tx *Tx) Delete(instance Instance) error
- func (tx *Tx) Effects() (effects []Effect)
- func (tx *Tx) Empty() bool
- func (tx *Tx) HostUser(host, user string) (matched Set)
- func (tx *Tx) Instance(instance Instance) (ls Lease, found bool)
- func (tx *Tx) Leases() Set
- func (tx *Tx) Ops() []Op
- func (tx *Tx) Process(process Processor)
- func (tx *Tx) ProcessReverse(process Processor)
- func (tx *Tx) Release(instance Instance, at time.Time) error
- func (tx *Tx) Resource() string
- func (tx *Tx) Revision() uint64
- func (tx *Tx) Stats() Stats
- func (tx *Tx) Update(instance Instance, ls Lease) error
- type UpdateType
Constants ¶
const MinimumRefresh = time.Second
MinimumRefresh is the minimum amount of time that should pass between lease refresh attempts. It is a hard limit intended to avoid hammering the server when policies are misconfigured.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Instance ¶
type Instance struct { Host string `json:"host,omitempty"` User string `json:"user,omitempty"` ID string `json:"id,omitempty"` }
An Instance identifies a specific instance of a lease consumer.
type Iter ¶
type Iter struct { Lease // contains filtered or unexported fields }
Iter is a lease iterator that allows changes to be recorded in a transaction.
type Lease ¶
type Lease struct { Subject Properties Properties `json:"properties"` // Properties of the lease Status Status `json:"status"` Started time.Time `json:"started,omitempty"` Renewed time.Time `json:"renewed,omitempty"` Released time.Time `json:"released,omitempty"` Strategy strategy.Strategy `json:"strategy,omitempty"` Limit uint `json:"limit"` Duration time.Duration `json:"duration"` Decay time.Duration `json:"decay"` Refresh Refresh `json:"refresh,omitempty"` }
Lease describes a single assignment of a leased resource.
func (*Lease) Consumptive ¶
Consumptive returns true if the lease is active or released.
func (*Lease) EffectiveRefresh ¶
EffectiveRefresh returns the effective refresh interval for the lease.
If the lease refresh interval is non-zero, it will be returned. If the refresh interval is zero a computed interval of half the lease duration will will be returned instead.
The returned value will always be greater than or equal to the minimum refresh rate defined by MinimumRefresh.
func (*Lease) ExpirationTime ¶
ExpirationTime returns the time at which the lease expires.
func (*Lease) MatchHostUser ¶
MatchHostUser returns true if the lease is for the given resource, host and user.
func (*Lease) MatchInstance ¶
MatchInstance returns true if the lease is for the given resource and instance.
func (*Lease) MatchResource ¶
MatchResource returns true if the lease is for the given resource.
func (*Lease) MatchStatus ¶
MatchStatus returns true if the lease has the given status.
func (*Lease) ResourceName ¶
ResourceName returns the user-friendly name of the resource.
type Op ¶
Op is a lease operation describing a create, update or delete action
func (*Op) Consumptive ¶
Consumptive returns true if the operation affects a consumptive lease.
func (*Op) UpdateType ¶
func (op *Op) UpdateType() UpdateType
UpdateType returns the type of update for update operations.
type Processor ¶
type Processor func(iter *Iter)
Processor is a function that processes a lease iterator.
type Properties ¶
Properties is a key/value map of lease properties.
func MergeProperties ¶
func MergeProperties(props ...Properties) (merged Properties)
MergeProperties merges the given properties into a single property map. The source properties are not modified.
func (Properties) Clone ¶
func (p Properties) Clone() Properties
Clone returns a deep clone of the lease properties.
type Provider ¶
type Provider interface { // ProviderName returns the name of the provider. ProviderName() string // LeaseResources returns all of the resources with lease data. LeaseResources() (resources []string, err error) // LeaseView returns the current revision and lease set for the resource. LeaseView(resource string) (revision uint64, leases Set, err error) // LeaseCommit will attempt to commit the lease transaction. LeaseCommit(tx *Tx) (err error) // Close releases any resources consumed by the provider. Close() error }
Provider is a lease management interface. It provides access to transactions for specific resources.
type Refresh ¶
type Refresh struct { Active time.Duration `json:"active,omitempty"` // Active lease refresh interval Queued time.Duration `json:"queued,omitempty"` // Queued lease refresh interval }
Refresh defines the active and queued refresh rates for a lease.
type Set ¶
type Set []Lease
Set is a set of leases.
func (Set) DecayDuration ¶
DecayDuration returns the interval between the given time and the earliest time at which a member of the set will decay.
If the decay time is before the given time a zero duration will be returned.
func (Set) ExpirationTime ¶
ExpirationTime returns the earliest time at which a member of the set will expire.
func (Set) HostUser ¶
HostUser returns the set of leases matching the requested resource, host and user.
func (Set) Index ¶
Index returns the index of the first lease within s that matches the given parameters, or -1 if no such lease is present in s.
func (Set) Instance ¶
Instance returns the first lease that matches the requested resource and instance.
func (Set) Less ¶
Less reports whether the lease with index i should sort before the lease with index j.
Leases of greater permanence come before leases of lesser permanence.
func (Set) Property ¶
Property returns a slice of property values from the leases. Keys are are supplied in preferential order, and the first key in each lease that exists is returned as the value for that key.
func (Set) Stats ¶
Stats returns the resource consumption statistics for each resource counting strategy.
The set must be sorted prior to calling this function.
type Snapshot ¶
type Snapshot struct { Resource string `json:"resource"` Revision uint64 `json:"revision"` Leases Set `json:"leases"` Stats Stats `json:"stats"` }
Snapshot includes a set of leases for a particular resource at a revision.
type State ¶
type State struct { Online bool // Do we have a live connection to the guardian server? LeaseNotRequired bool // Did the server tell us we don't need a lease? Acquired bool // Have we acquired a lease of any status? Lease Lease // The most recent lease received from the server Leases Set // All leases for our lease resource Retry time.Duration // Retry interval when not holding a lease Err error // The most recent acquisition error }
State holds state information about a lease for a lease holder.
type Stats ¶
type Stats struct { Instance Tally `json:"instance"` // The number of leases with each lease status Consumer Tally `json:"consumer"` // The number of consumers with each lease status }
Stats is a set of resource consumption statistics for each resource counting strategy.
func (*Stats) Active ¶
Active returns the number of active resources according to the provided resource counting strategy.
func (*Stats) Consumed ¶
Consumed returns the number of consumed resources according to the provided resource counting strategy.
Both both active and released resources contribute towards consumption.
func (*Stats) Queued ¶
Queued returns the number of queued resources according to the provided resource counting strategy.
type Status ¶
type Status string
Status indicates the current condition of a lease.
const ( // Queued indicates that a lease is pending and does not yet count against // the resource allocation counts. Queued Status = "queued" // Active indicates that a lease is in use and included in the resource // allocation counts. Active Status = "active" // Released indicates that a lease has ended but is in a state of decay. // Decaying leases are still included in resource allocation counts. Released Status = "released" )
type Subject ¶
type Subject struct { Resource string `json:"resource"` // The resource that is being consumed Instance Instance `json:"instance"` // The thing that is consuming the resource }
Subject describes what a lease consumes and what consumes it.
type Tally ¶
type Tally struct { Active uint `json:"active"` Released uint `json:"released"` Queued uint `json:"queued"` Consumed uint `json:"consumed"` Users map[string]uint `json:"-"` }
Tally is a set of resource statistics for a particular resource counting strategy.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is a lease transaction that describes a series of operations to be atomically applied to a lease set.
func (*Tx) Process ¶
Process iterates through each lease and applies the given lease processing function to it.
func (*Tx) ProcessReverse ¶
ProcessReverse iterates through each lease in reverse order and applies the given lease processing function to it.
type UpdateType ¶
type UpdateType uint32
UpdateType is a type of lease update.
const ( Renew UpdateType = iota Downgrade Upgrade Replace Exchange Transmute )
Lease update types
func (UpdateType) String ¶
func (t UpdateType) String() string
String returns a string representation of the update type.