bind

package
v0.0.0-...-be2ef80 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotEnoughParams is returned from ParseData when the data does
	// not contain the required number of fields to construct a bind
	// argument.
	ErrNotEnoughParams = errors.New("Not enough parameters provided")

	// ErrUnknownBindType is returned from ParseData when the data
	// includes a Bind type other than Required or Optional.
	ErrUnknownBindType = errors.New("Unknown bind type")
)

Functions

func RDeps

func RDeps(serviceList []string, allServices []habpkg.HabPkg, binds Binds) ([]habpkg.HabPkg, error)

RDeps returns all of the reverse dependencies of the given packages.

func TopoSort

func TopoSort(serviceList []string, allServices []habpkg.HabPkg, binds Binds) ([]habpkg.HabPkg, error)

TopoSort is like TopoSortAll but only returns the nodes in allServices reachable from the nodes identified in services.

func TopoSortAll

func TopoSortAll(services []habpkg.HabPkg, binds Binds) ([]habpkg.HabPkg, error)

TopoSortAll topologically sorts the slice of service packages based on the given binds data. It returns a slice of sorted HabPkgs. If error is non-nil there is a dependency cycle.

The service list and dependency information is passed separately rather than using a more standard adjacency list representation simply to save on data-munging (services and binds are parsed separately currently)

This uses a "depth-first" approach. It uses more memory than it needs to to facilitate nice errors and a bit of programming ease.

Types

type Bind

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

Bind represents a bind name and a service group it is bound to

func New

func New(name string, serviceGroup string) Bind

New returns a Bind serviceGroup can be an empty string to represent and unbound bind

func (Bind) IsBound

func (b Bind) IsBound() bool

IsBound returns true if the bind has a service group

func (Bind) Name

func (b Bind) Name() string

Name returns the bind name

func (Bind) ServiceGroup

func (b Bind) ServiceGroup() string

ServiceGroup returns the service group

type BindLookup

type BindLookup interface {
	AllForService(string) []string
}

type BindModeMap

type BindModeMap map[string]string

BindModeMap maps components to their binding modes

type Bindmap

type Bindmap map[string][]string

Bindmap maps components to the things they bind to

type Binds

type Binds struct {
	Optional Bindmap
	Required Bindmap
	BindMode BindModeMap
}

Binds is a type that holds optional and required bindings for all components

func ParseData

func ParseData(data []byte) (Binds, error)

ParseData parses a text description of binds an returns a Binds struct.

func (*Binds) AllForService

func (b *Binds) AllForService(name string) []string

AllForService returns a list of all binds (both optional and non-optional) for a service.

func (*Binds) DefaultsForService

func (b *Binds) DefaultsForService(name string) (Info, error)

DefaultsForService is a helper function that returns a BindInfo struct for the given service.

The returned BindSpecs assume that all binds should be mapped to the service of the same name in the default group.

An error is returned if any of the assumptions are violated:

- All services must specify a binding mode

func (*Binds) ModeForService

func (b *Binds) ModeForService(name string) (string, error)

func (*Binds) ToReverseBinds

func (b *Binds) ToReverseBinds() *ReverseBinds

type Collection

type Collection struct {
	Binds []Bind
}

Collection is a set of binds

func WithBinds

func WithBinds(binds ...Bind) Collection

WithBinds creates a set of Binds

func (Collection) Equal

func (xs Collection) Equal(ys Collection) bool

Equal compares 2 sets of Binds for equality

type Info

type Info struct {
	// Specs is an array of strings in the form of
	// BIND:SERVICE_GROUP, each representing a bind->service_group
	// map that that can be passed to Habitat.
	Specs []string
	// Mode is a bind mode.  Must be non-empty if len(Specs) > 0
	Mode string
}

Info contains the bind information for a single service required for interaction with Habitat. Right now this is lossy and we lose required vs optional bind information.

type ReverseBinds

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

ReverseBinds holds reverse bind dependencies, ignoring the optional vs required distinction.

func (*ReverseBinds) AllForService

func (r *ReverseBinds) AllForService(name string) []string

Jump to

Keyboard shortcuts

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