Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TopologicalSortReferences ¶
func TopologicalSortReferences[Item UniqueName]( chains []*ReferenceChainNode, items []Item, direction ReferenceSortDirection, empty Item, ) ([]Item, error)
TopologicalSortReferences sorts a list of items based on the reference chains provided. Each item in the list is expected to have a unique name that corresponds the `ElementName` field in the reference chain nodes. The direction of the sort is determined by the direction parameter.
Types ¶
type RefChainCollector ¶
type RefChainCollector interface {
// Collect adds a new reference to the reference chain(s) to be used for cycle detection
// and other use cases.
Collect(elementName string, element interface{}, referencedBy string, tags []string) error
// Chain returns the reference chain node for the given element name.
Chain(elementName string) *ReferenceChainNode
// ChainsByDependencies returns a list of root nodes representing elements
// that have no dependencies (i.e. they do not reference any other elements).
ChainsByDependencies() []*ReferenceChainNode
// ChainsByLeafDependants returns a list of root nodes representing elements
// that are not referenced by any other elements.
ChainsByLeafDependants() []*ReferenceChainNode
// FindByTag returns a list of reference chain nodes that have the given tag.
FindByTag(tag string) []*ReferenceChainNode
// FindCircularReferences returns a list of reference chain nodes for which there are
// cycles.
FindCircularReferences() []*ReferenceChainNode
}
RefChainCollector collects references in a set of chains (tree structures) and allows for checking for cycles in references once the full set of chains have been built for the current blueprint. This can also be used to for change staging/deployment stages to determine the order in which changes should be applied to elements in a blueprint.
func NewRefChainCollector ¶
func NewRefChainCollector() RefChainCollector
NewRefChainCollector creates a new instance of the default reference chain collector implementation.
type ReferenceChainNode ¶
type ReferenceChainNode struct {
// ElementName is the unique name in the spec for the current
// element in the chain.
ElementName string
// Element holds the information about the element at the blueprint spec schema-level.
Element interface{}
// References holds the references that the current element makes to other elements
// in the blueprint.
References []*ReferenceChainNode
// ReferencedBy holds the references that other elements make to the current element.
ReferencedBy []*ReferenceChainNode
// Paths holds all the different "routes" to get to the current element in a set of chains.
// These are known as materialised paths in the context of tree data structures.
// Having this information here allows us to efficiently find out if
// there is a relationship between two elements at any depth in the chain.
Paths []string
// Tags provide a way to categorise a reference chain node.
// For example, "link:{dependant}" could be used to indicate that the reference chain node
// that represents a link derived from link selectors in the blueprint.
Tags []string
}
ReferenceChainNode provides a node in a chain of references that contains the name of the current element in the chain.
func DeepCopyReferenceChains ¶
func DeepCopyReferenceChains(chains []*ReferenceChainNode) []*ReferenceChainNode
DeepCopyReferenceChains deep copies a slice of reference chains. This is useful when you want to modify the chains without affecting the original (e.g. in a topological sort algorithm).
type ReferenceSortDirection ¶
type ReferenceSortDirection int
ReferenceSortDirection is an enum type for the direction of topological sorting for reference chains.
const ( // ReferenceSortDirectionReferencedBy is the direction for sorting reference chains // based on the "referenced by" relationship. // For example, this could be used to order elements to be deployed in a blueprint, // making sure that resources are deployed after their dependencies. ReferenceSortDirectionReferencedBy ReferenceSortDirection = iota // ReferenceSortDirectionReferences is the direction for sorting reference chains // based on the "references" relationship. // For example, this could be used to order elements to be removed in a blueprint // for a blueprint, making sure that resources are removed before their dependencies. ReferenceSortDirectionReferences )
type UniqueName ¶
type UniqueName interface {
Name() string
}
UniqueName is an interface for types that have a unique name.