common

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var (
	// KnownStates is the set of all known states, excluding "other".
	KnownStates = []string{
		Busy,
		Cleaning,
		Dirty,
		Free,
		Leased,
		ToBeDeleted,
		Tombstone,
	}
)

Functions

func GenerateDynamicResourceName

func GenerateDynamicResourceName() string

GenerateDynamicResourceName generates a unique name for dynamic resources

func ResourceTypeNotFoundMessage

func ResourceTypeNotFoundMessage(rType string) string

func ValidateConfig

func ValidateConfig(config *BoskosConfig) error

ValidateConfig validates config with existing resources In: boskosConfig - a boskos config defining resources Out: nil on success, error on failure

Types

type BoskosConfig

type BoskosConfig struct {
	Resources []ResourceEntry `json:"resources"`
}

BoskosConfig defines config used by boskos server

func ParseConfig

func ParseConfig(configPath string) (*BoskosConfig, error)

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

type CommaSeparatedStrings

type CommaSeparatedStrings []string

CommaSeparatedStrings is used to parse comma separated string flag into a list of strings

func (*CommaSeparatedStrings) Set

func (r *CommaSeparatedStrings) Set(value string) error

Set parses the flag value into a CommaSeparatedStrings

func (*CommaSeparatedStrings) String

func (r *CommaSeparatedStrings) String() string

func (*CommaSeparatedStrings) Type

func (r *CommaSeparatedStrings) Type() string

type ConfigType

type ConfigType struct {
	// Identifier of the struct this maps back to
	Type string `json:"type,omitempty"`
	// Marshaled JSON content
	Content string `json:"content,omitempty"`
}

ConfigType gather the type of config to be applied by Mason in order to construct the resource

type DRLCByName

type DRLCByName []DynamicResourceLifeCycle

DRLCByName helps sorting ResourcesConfig by name

func (DRLCByName) Len

func (ut DRLCByName) Len() int

func (DRLCByName) Less

func (ut DRLCByName) Less(i, j int) bool

func (DRLCByName) Swap

func (ut DRLCByName) Swap(i, j int)

type Duration

type Duration struct {
	*time.Duration
}

Duration is a wrapper around time.Duration that parses times in either 'integer number of nanoseconds' or 'duration string' formats and serializes to 'duration string' format.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON implement the JSON Unmarshaler interface in order to be able parse string to time.Duration.

type DynamicResourceLifeCycle

type DynamicResourceLifeCycle struct {
	Type string `json:"type"`
	// Initial state to be created as
	InitialState string `json:"state"`
	// Minimum number of resources to be use as a buffer.
	// Resources in the process of being deleted and cleaned up are included in this count.
	MinCount int `json:"min-count"`
	// Maximum number of resources expected. This maximum may be temporarily
	// exceeded while resources are in the process of being deleted, though this
	// is only expected when MaxCount is lowered.
	MaxCount int `json:"max-count"`
	// Lifespan of a resource, time after which the resource should be reset.
	LifeSpan *time.Duration `json:"lifespan,omitempty"`
	// Config information about how to create the object
	Config ConfigType `json:"config,omitempty"`
	// Needs define the resource needs to create the object
	Needs ResourceNeeds `json:"needs,omitempty"`
}

DynamicResourceLifeCycle defines the life cycle of a dynamic resource. All Resource of a given type will be constructed using the same configuration

func NewDynamicResourceLifeCycleFromConfig

func NewDynamicResourceLifeCycleFromConfig(e ResourceEntry) DynamicResourceLifeCycle

NewDynamicResourceLifeCycleFromConfig parse the a ResourceEntry into a DynamicResourceLifeCycle

type LeasedResources

type LeasedResources []string

LeasedResources is a list of resources name that used in order to create another resource by Mason

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

func NewMetric

func NewMetric(rtype string) Metric

NewMetric returns a new Metric struct.

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

func NewResource

func NewResource(name, rtype, state, owner string, t time.Time) Resource

NewResource creates a new Boskos Resource.

func NewResourcesFromConfig

func NewResourcesFromConfig(e ResourceEntry) []Resource

NewResourcesFromConfig parse the a ResourceEntry into a list of resources

type ResourceByName

type ResourceByName []Resource

ResourceByName helps sorting resources by name

func (ResourceByName) Len

func (ut ResourceByName) Len() int

func (ResourceByName) Less

func (ut ResourceByName) Less(i, j int) bool

func (ResourceByName) Swap

func (ut ResourceByName) Swap(i, j int)

type ResourceEntry

type ResourceEntry struct {
	Type     string        `json:"type"`
	State    string        `json:"state"`
	Names    []string      `json:"names"`
	MaxCount int           `json:"max-count,omitempty"`
	MinCount int           `json:"min-count,omitempty"`
	LifeSpan *Duration     `json:"lifespan,omitempty"`
	Config   ConfigType    `json:"config,omitempty"`
	Needs    ResourceNeeds `json:"needs,omitempty"`
}

ResourceEntry is resource config format defined from config.yaml

func (*ResourceEntry) IsDRLC

func (re *ResourceEntry) IsDRLC() bool

type ResourceNeeds

type ResourceNeeds map[string]int

ResourceNeeds maps the type to count of resources types needed

type TypeToResources

type TypeToResources map[string][]Resource

TypeToResources stores all the leased resources with the same type f

func (TypeToResources) Copy

Copy returns a copy of the TypeToResources

type UserData

type UserData struct {
	sync.Map
}

UserData is a map of Name to user defined interface, serialized into a string

func UserDataFromMap

func UserDataFromMap(m UserDataMap) *UserData

UserDataFromMap returns a UserData from a map

func (*UserData) Extract

func (ud *UserData) Extract(id string, out interface{}) error

Extract unmarshalls a string a given struct if it exists

func (*UserData) FromMap

func (ud *UserData) FromMap(m UserDataMap)

FromMap feels updates user data from a map

func (*UserData) MarshalJSON

func (ud *UserData) MarshalJSON() ([]byte, error)

MarshalJSON implements JSON Marshaler interface

func (*UserData) Set

func (ud *UserData) Set(id string, in interface{}) error

Set marshalls a struct to a string into the UserData

func (*UserData) ToMap

func (ud *UserData) ToMap() UserDataMap

ToMap converts a UserData to UserDataMap

func (*UserData) UnmarshalJSON

func (ud *UserData) UnmarshalJSON(data []byte) error

UnmarshalJSON implements JSON Unmarshaler interface

func (*UserData) Update

func (ud *UserData) Update(new *UserData) *UserData

Update updates existing UserData with new UserData. If a key as an empty string, the key will be deleted

type UserDataMap

type UserDataMap map[string]string

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

Jump to

Keyboard shortcuts

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