Documentation ¶
Overview ¶
Package boskos implements a boskos client.
Index ¶
- Constants
- Variables
- func ResourceTypeNotFoundMessage(rType string) string
- type Client
- func (c *Client) Acquire(rtype, state, dest string) (*Resource, error)
- func (c *Client) AcquireByState(state, dest string, names []string) ([]Resource, error)
- func (c *Client) AcquireByStateWait(ctx context.Context, state, dest string, names []string) ([]Resource, error)
- func (c *Client) AcquireWait(ctx context.Context, rtype, state, dest string) (*Resource, error)
- func (c *Client) AcquireWaitWithPriority(ctx context.Context, rtype, state, dest, requestID string) (*Resource, error)
- func (c *Client) AcquireWithPriority(rtype, state, dest, requestID string) (*Resource, error)
- func (c *Client) HasResource() bool
- func (c *Client) Metric(rtype string) (Metric, error)
- func (c *Client) Release(name, dest string) error
- func (c *Client) ReleaseAll(dest string) error
- func (c *Client) ReleaseOne(name, dest string) error
- func (c *Client) Reset(rtype, state string, expire time.Duration, dest string) (map[string]string, error)
- func (c *Client) SyncAll() error
- func (c *Client) Update(name, state string, userData *UserData) error
- func (c *Client) UpdateAll(state string) error
- func (c *Client) UpdateOne(name, state string, userData *UserData) error
- type DialerWithRetry
- type Metric
- type PersistenceLayer
- type Resource
- type UserData
- func (ud *UserData) Extract(id string, out interface{}) error
- func (ud *UserData) FromMap(m UserDataMap)
- func (ud *UserData) MarshalJSON() ([]byte, error)
- func (ud *UserData) ToMap() UserDataMap
- func (ud *UserData) UnmarshalJSON(data []byte) error
- func (ud *UserData) Update(newUserData *UserData) *UserData
- type UserDataMap
- type UserDataNotFound
Constants ¶
const ( // Busy state defines a resource being used. Busy = "busy" // Cleaning state defines a resource being cleaned. Cleaning = "cleaning" // Dirty state defines a resource that needs cleaning. Dirty = "dirty" // Free state defines a resource that is usable. Free = "free" // Leased state defines a resource being leased in order to make a new resource. Leased = "leased" // ToBeDeleted is used for resources about to be deleted, they will be verified by a cleaner which mark them as tombstone. ToBeDeleted = "toBeDeleted" // Tombstone is the state in which a resource can safely be deleted. Tombstone = "tombstone" // Other is used to agglomerate unspecified states for metrics reporting. Other = "other" )
Variables ¶
var ( // ErrNotFound is returned by Acquire() when no resources are available. ErrNotFound = errors.New("resources not found") // ErrAlreadyInUse is returned by Acquire when resources are already being requested. ErrAlreadyInUse = errors.New("resources already used by another user") // ErrContextRequired is returned by AcquireWait and AcquireByStateWait when // they are invoked with a nil context. ErrContextRequired = errors.New("context required") // ErrTypeNotFound is returned when the requested resource type (rtype) does not exist. // For this error to be returned, you must set DistinguishNotFoundVsTypeNotFound to true. ErrTypeNotFound = errors.New("resource type not found") )
var SleepFunc = time.Sleep
SleepFunc is called when requests are retried. This may be replaced in tests.
Functions ¶
func ResourceTypeNotFoundMessage ¶
ResourceTypeNotFoundMessage returns a resource type not found message.
Types ¶
type Client ¶
type Client struct { // Dialer is the net.Dialer used to establish connections to the remote // boskos endpoint. Dialer DialerWithRetry // DistinguishNotFoundVsTypeNotFound, if set, will make it possible to distinguish between // ErrNotFound and ErrTypeNotFound. For backwards-compatibility, this flag is off by // default. DistinguishNotFoundVsTypeNotFound bool // contains filtered or unexported fields }
Client defines the public Boskos client object.
func NewClient ¶
NewClient creates a Boskos client for the specified URL and resource owner.
Clients created with this function default to retrying failed connection attempts three times with a ten second pause between each attempt. Note: username & passwordFile was dropped to avoid a dependency on "k8s.io/test-infra/prow/config/secret".
func (*Client) Acquire ¶
Acquire asks boskos for a resource of certain type in certain state, and set the resource to dest state. Returns the resource on success.
func (*Client) AcquireByState ¶
AcquireByState asks boskos for a resources of certain type, and set the resource to dest state. Returns a list of resources on success.
func (*Client) AcquireByStateWait ¶
func (c *Client) AcquireByStateWait(ctx context.Context, state, dest string, names []string) ([]Resource, error)
AcquireByStateWait blocks until AcquireByState returns the specified resource(s) or the provided context is cancelled or its deadline exceeded.
func (*Client) AcquireWait ¶
AcquireWait blocks until Acquire returns the specified resource or the provided context is cancelled or its deadline exceeded.
func (*Client) AcquireWaitWithPriority ¶
func (c *Client) AcquireWaitWithPriority(ctx context.Context, rtype, state, dest, requestID string) (*Resource, error)
AcquireWaitWithPriority blocks until Acquire returns the specified resource or the provided context is cancelled or its deadline exceeded. This allows you to pass in a request priority. Boskos Priority are FIFO.
func (*Client) AcquireWithPriority ¶
AcquireWithPriority asks boskos for a resource of certain type in certain state, and set the resource to dest state. Returns the resource on success. Boskos Priority are FIFO.
func (*Client) HasResource ¶
HasResource tells if current client holds any resources.
func (*Client) Metric ¶
Metric will query current metric for target resource type. Return a common.Metric object on success.
func (*Client) ReleaseAll ¶
ReleaseAll returns all resources hold by the client back to boskos and set them to dest state.
func (*Client) ReleaseOne ¶
ReleaseOne returns one of owned resources back to boskos and set it to dest state.
func (*Client) Reset ¶
func (c *Client) Reset(rtype, state string, expire time.Duration, dest string) (map[string]string, error)
Reset will scan all boskos resources of type, in state, last updated before expire, and set them to dest state. Returns a map of {resourceName:owner} for further actions.
type DialerWithRetry ¶
type DialerWithRetry struct { net.Dialer // RetryCount is the number of times to retry a connection attempt. RetryCount uint // RetrySleep is the length of time to pause between retry attempts. RetrySleep time.Duration }
DialerWithRetry is a composite version of the net.Dialer that retries connection attempts.
func (*DialerWithRetry) Dial ¶
func (d *DialerWithRetry) Dial(network, address string) (net.Conn, error)
Dial connects to the address on the named network.
func (*DialerWithRetry) DialContext ¶
func (d *DialerWithRetry) DialContext(ctx context.Context, network, address string) (net.Conn, error)
DialContext connects to the address on the named network using the provided context.
type Metric ¶
type Metric struct { Type string `json:"type"` Current map[string]int `json:"current"` Owners map[string]int `json:"owner"` }
Metric contains analytics about a specific resource type.
type PersistenceLayer ¶
type PersistenceLayer interface { Add(r Resource) error Delete(name string) error Update(r Resource) (Resource, error) Get(name string) (Resource, error) List() ([]Resource, error) }
PersistenceLayer defines a simple interface to persists Boskos Information.
func NewMemoryStorage ¶
func NewMemoryStorage() PersistenceLayer
NewMemoryStorage creates an in memory persistence layer.
type Resource ¶
type Resource struct { Type string `json:"type"` Name string `json:"name"` State string `json:"state"` Owner string `json:"owner"` LastUpdate time.Time `json:"lastupdate"` // Customized UserData UserData *UserData `json:"userdata"` // Used to clean up dynamic resources ExpirationDate *time.Time `json:"expiration-date,omitempty"` }
Resource abstracts any resource type that can be tracked by boskos.
type UserData ¶
UserData is a map of Name to user defined interface, serialized into a string.
func (*UserData) FromMap ¶
func (ud *UserData) FromMap(m UserDataMap)
FromMap feels updates user data from a map.
func (*UserData) MarshalJSON ¶
MarshalJSON implements JSON Marshaler interface.
func (*UserData) ToMap ¶
func (ud *UserData) ToMap() UserDataMap
ToMap converts a UserData to UserDataMap.
func (*UserData) UnmarshalJSON ¶
UnmarshalJSON implements JSON Unmarshaler interface.
type UserDataMap ¶
UserDataMap is the standard Map version of UserMap, it is used to ease UserMap creation.
type UserDataNotFound ¶
type UserDataNotFound struct {
ID string
}
UserDataNotFound will be returned if requested resource does not exist.
func (*UserDataNotFound) Error ¶
func (ud *UserDataNotFound) Error() string