internal

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const AllGenerations int64 = 0
View Source
const CONTEXT_TYPE = "config" + datacontext.OCM_CONTEXT_SUFFIX
View Source
const KIND_CONFIGSET = "config set"
View Source
const KIND_CONFIGTYPE = "config type"
View Source
const OCM_CONFIG_SUFFIX = ".config.ocm.software"

OCM_CONFIG_SUFFIX is the standard suffix used for all configuration types provided by this library.

View Source
const OCM_CONFIG_TYPE_SUFFIX = ".config" + common.OCM_TYPE_GROUP_SUFFIX

OCM_CONFIG_TYPE_SUFFIX is the standard suffix used for configuration types provided by this library.

Variables

View Source
var AllAppliedConfigs = AppliedConfigSelectorFunction(func(*AppliedConfig) bool { return true })
View Source
var AllConfigs = AppliedConfigSelectorFunction(func(*AppliedConfig) bool { return true })
View Source
var DefaultConfigTypeScheme = NewConfigTypeScheme(nil)

DefaultConfigTypeScheme contains all globally known access serializer.

View Source
var DefaultContext = Builder{}.New(datacontext.MODE_SHARED)

DefaultContext is the default context initialized by init functions.

View Source
var Realm = ocmlog.DefineSubRealm("configuration management", "config")

Functions

func ErrNoContext

func ErrNoContext(name string) error

func IsErrConfigNotApplicable

func IsErrConfigNotApplicable(err error) bool

func IsErrNoContext

func IsErrNoContext(err error) bool

func IsGeneric

func IsGeneric(cfg Config) bool

func NewStrictConfigTypeScheme added in v0.3.0

func NewStrictConfigTypeScheme(base ...ConfigTypeScheme) runtime.VersionedTypeRegistry[Config, ConfigType]

Types

type AppliedConfig

type AppliedConfig struct {
	// contains filtered or unexported fields
}

type AppliedConfigSelector

type AppliedConfigSelector interface {
	Select(cfg *AppliedConfig) bool
}

func AppliedAndSelector

func AppliedAndSelector(and ...AppliedConfigSelector) AppliedConfigSelector

func AppliedConfigSelectorFor

func AppliedConfigSelectorFor(s ConfigSelector) AppliedConfigSelector

func AppliedGenerationSelector

func AppliedGenerationSelector(gen int64) AppliedConfigSelector

func AppliedVersionSelector

func AppliedVersionSelector(v string) AppliedConfigSelector

type AppliedConfigSelectorFunction

type AppliedConfigSelectorFunction func(cfg *AppliedConfig) bool

func (AppliedConfigSelectorFunction) Select

type AppliedConfigs

type AppliedConfigs []*AppliedConfig

func (AppliedConfigs) Configs

func (l AppliedConfigs) Configs() []Config

func (AppliedConfigs) Len

func (l AppliedConfigs) Len() int

func (AppliedConfigs) Less

func (l AppliedConfigs) Less(i, j int) bool

func (AppliedConfigs) Swap

func (l AppliedConfigs) Swap(i, j int)

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func (Builder) Bound

func (b Builder) Bound() (Context, context.Context)

func (Builder) New

func (b Builder) New(m ...datacontext.BuilderMode) Context

func (Builder) WithConfigTypeScheme

func (b Builder) WithConfigTypeScheme(scheme ConfigTypeScheme) Builder

func (Builder) WithContext

func (b Builder) WithContext(ctx context.Context) Builder

func (Builder) WithSharedAttributes

func (b Builder) WithSharedAttributes(ctx datacontext.AttributesContext) Builder

type Config

type Config interface {
	runtime.VersionedTypedObject

	ApplyTo(Context, interface{}) error
}

func NewGenericConfig

func NewGenericConfig(data []byte, unmarshaler runtime.Unmarshaler) (Config, error)

type ConfigApplier added in v0.7.0

type ConfigApplier interface {
	ApplyConfigTo(Context, cfg, tgt interface{}) error
}

type ConfigApplierFunction added in v0.7.0

type ConfigApplierFunction func(ctx Context, cfg, tgt interface{}) error

func (ConfigApplierFunction) ApplyConfigTo added in v0.7.0

func (f ConfigApplierFunction) ApplyConfigTo(ctx Context, cfg, tgt interface{}) error

type ConfigDecoder added in v0.3.0

type ConfigDecoder = runtime.TypedObjectDecoder[Config]

type ConfigSelector

type ConfigSelector interface {
	Select(Config) bool
}

type ConfigSelectorFunction

type ConfigSelectorFunction func(Config) bool

func (ConfigSelectorFunction) Select

func (f ConfigSelectorFunction) Select(cfg Config) bool

type ConfigSet added in v0.3.0

type ConfigSet struct {
	Description       string `json:"description,omitempty"`
	ConfigurationList `json:",inline"`
}

type ConfigStore

type ConfigStore struct {
	// contains filtered or unexported fields
}

func NewConfigStore

func NewConfigStore() *ConfigStore

func (*ConfigStore) AddSet added in v0.3.0

func (c *ConfigStore) AddSet(name string, set *ConfigSet)

func (*ConfigStore) Apply

func (s *ConfigStore) Apply(c Config, desc string)

func (*ConfigStore) Generation

func (s *ConfigStore) Generation() int64

func (*ConfigStore) GetConfigForName

func (c *ConfigStore) GetConfigForName(ctx Context, name string, selector AppliedConfigSelector) (int64, AppliedConfigs)

func (*ConfigStore) GetConfigForSelector

func (c *ConfigStore) GetConfigForSelector(ctx Context, selector AppliedConfigSelector) (int64, AppliedConfigs)

func (*ConfigStore) GetConfigForType

func (c *ConfigStore) GetConfigForType(ctx Context, typ string, selector AppliedConfigSelector) (int64, AppliedConfigs)

func (*ConfigStore) GetSet added in v0.3.0

func (c *ConfigStore) GetSet(name string) *ConfigSet

func (*ConfigStore) Reset

func (s *ConfigStore) Reset() int64

type ConfigType

type ConfigType interface {
	runtime.VersionedTypedObjectType[Config]
	Usage() string
}

type ConfigTypeProvider added in v0.3.0

type ConfigTypeProvider = runtime.KnownTypesProvider[Config, ConfigType]

type ConfigTypeScheme

type ConfigTypeScheme interface {
	runtime.TypeScheme[Config, ConfigType]

	Usage() string
}

func NewConfigTypeScheme

func NewConfigTypeScheme(defaultDecoder ConfigDecoder, base ...ConfigTypeScheme) ConfigTypeScheme

type ConfigurationList added in v0.3.0

type ConfigurationList struct {
	Configurations []*GenericConfig `json:"configurations,omitempty"`
}

func (*ConfigurationList) AddConfig added in v0.3.0

func (c *ConfigurationList) AddConfig(cfg Config) error

func (*ConfigurationList) AddConfigData added in v0.5.0

func (c *ConfigurationList) AddConfigData(ctx Context, data []byte) error

type Context

type Context interface {
	datacontext.Context
	ContextProvider

	AttributesContext() datacontext.AttributesContext

	// Info provides the context for nested configuration evaluation
	Info() string
	// WithInfo provides the same context with additional nesting info
	WithInfo(desc string) Context

	ConfigTypes() ConfigTypeScheme

	// GetConfigForData deserialize configuration objects for known
	// configuration types.
	GetConfigForData(data []byte, unmarshaler runtime.Unmarshaler) (Config, error)

	// ApplyData applies the config given by a byte stream to the config store
	// If the config type is not known, a generic config is stored and returned.
	// In this case an unknown error for kind KIND_CONFIGTYPE is returned.
	ApplyData(data []byte, unmarshaler runtime.Unmarshaler, desc string) (Config, error)
	// ApplyConfig applies the config to the config store
	ApplyConfig(spec Config, desc string) error

	GetConfigForType(generation int64, typ string) (int64, []Config)
	GetConfigForName(generation int64, name string) (int64, []Config)
	GetConfig(generation int64, selector ConfigSelector) (int64, []Config)

	AddConfigSet(name string, set *ConfigSet)
	ApplyConfigSet(name string) error

	// Reset all configs applied so far, subsequent calls to ApplyTo will
	// ony see configs allpied after the last reset.
	Reset() int64
	// Generation return the actual config generation.
	// this is a strictly increasing number, regardless of the number
	// of Reset calls.
	Generation() int64
	// ApplyTo applies all configurations applied after the last reset with
	// a generation larger than the given watermark to the specified target.
	// A target may be any object. The applied configuration objects decide
	// on their own whether they are applicable for the given target.
	// The generation of the last applied object is returned to be used as
	// new watermark.
	ApplyTo(gen int64, target interface{}) (int64, error)
}

func DefinedForContext

func DefinedForContext(ctx context.Context) (Context, bool)

func FromContext added in v0.3.0

func FromContext(ctx context.Context) Context

FromContext returns the Context to use for context.Context. This is either an explicit context or the default context. The returned context incorporates the given context.

func FromProvider added in v0.3.0

func FromProvider(p ContextProvider) Context

type ContextProvider

type ContextProvider interface {
	ConfigContext() Context
}

type Evaluator

type Evaluator interface {
	Evaluate(ctx Context) (Config, error)
}

type GenericConfig

type GenericConfig struct {
	runtime.UnstructuredVersionedTypedObject `json:",inline"`
	// contains filtered or unexported fields
}

func ToGenericConfig

func ToGenericConfig(c Config) (*GenericConfig, error)

func (*GenericConfig) ApplyTo

func (s *GenericConfig) ApplyTo(ctx Context, target interface{}) error

func (*GenericConfig) Evaluate

func (s *GenericConfig) Evaluate(ctx Context) (Config, error)

func (*GenericConfig) IsUnknown added in v0.3.0

func (s *GenericConfig) IsUnknown() bool

type Updater

type Updater interface {
	// Update replays missing configuration requests
	// applicable for a dedicated type of context or configuration target
	// stored in a configuration context.
	// It should be created for and called from within such a context
	Update() error
	State() (int64, bool)
	GetContext() Context

	Lock()
	Unlock()
	RLock()
	RUnlock()
}

Updater implements the generation based update protocol to update data contexts based on the config requests made to a configuration context.

func NewUpdater

func NewUpdater(ctx Context, target interface{}) Updater

NewUpdater create a configuration updater for a configuration target based on a dedicated configuration context.

Jump to

Keyboard shortcuts

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