graph

package
v2.16.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Roots added in v2.7.0

func Roots(g graph.Directed) []graph.Node

Roots returns all nodes that do not have incoming edges

func SortProjects

func SortProjects(projects []project.Project, environments []string) (map[string][]config.Config, []error)

SortProjects is a convenience method to make Graph based sorting an easy plugin for the old toposort variant. Internally it builds dependency graphs and uses these to sort and return the basic sorted configs per environment map.

Types

type ConfigGraph

type ConfigGraph interface {
	graph.Directed
	graph.NodeRemover
}

ConfigGraph is a directed graph containing ConfigNode s

type ConfigGraphPerEnvironment

type ConfigGraphPerEnvironment map[string]*simple.DirectedGraph

ConfigGraphPerEnvironment is a map of directed dependency graphs per environment name.

func New

func New(projects []project.Project, environments []string, nodeOptions ...NodeOption) ConfigGraphPerEnvironment

New creates a new ConfigGraphPerEnvironment based on the given projects and environments.

func (ConfigGraphPerEnvironment) EncodeToDOT

func (graphs ConfigGraphPerEnvironment) EncodeToDOT(environment string) ([]byte, error)

EncodeToDOT returns a DOT string represenation of the dependency graph for the given environment.

func (ConfigGraphPerEnvironment) GetIndependentlySortedConfigs

func (graphs ConfigGraphPerEnvironment) GetIndependentlySortedConfigs(environment string) ([]SortedComponent, error)

GetIndependentlySortedConfigs returns sorted slices of SortedComponent. Dependent configurations are returned as a sub-graph as well as a slice, sorted in the correct order to deploy them sequentially.

func (ConfigGraphPerEnvironment) SortConfigs

func (graphs ConfigGraphPerEnvironment) SortConfigs(environment string) ([]config.Config, error)

SortConfigs returns a slice of config.Config for the given environment sorted according to their dependencies.

type ConfigNode

type ConfigNode struct {
	NodeID      int64
	Config      *config.Config
	DOTEncoding string
}

ConfigNode implements the gonum graph.Node interface and contains a pointer to its respective config.Config in addition to the unique ID required.

func (ConfigNode) DOTID

func (n ConfigNode) DOTID() string

DOTID returns the node's identifier when printed to a DOT file. For readability of files this is the coordinate.Coordinate of the Config, instead of the node's ID integer.

func (ConfigNode) ID

func (n ConfigNode) ID() int64

ID returns the node's integer ID by which it is referenced in the graph.

func (ConfigNode) String

func (n ConfigNode) String() string

type CyclicDependencyError

type CyclicDependencyError struct {
	//The Environment for which the error occurred.
	Environment string `json:"environment"`
	//A slice of all dependency cycles between configurations as slices of DependencyLocation. Each cycle slice is returned in order of dependencies.
	ConfigsInDependencyCycle [][]DependencyLocation `json:"configsInDependencyCycle"`
}

CyclicDependencyError is returned if sorting a graph failed due to cyclic dependencies between configurations.

func (CyclicDependencyError) Error

func (e CyclicDependencyError) Error() string

type DependencyLocation

type DependencyLocation struct {
	// The coordinate.Coordinate of the configuration that is part of a Dependency Cycle
	Coordinate coordinate.Coordinate `json:"coordinate"`
	// The filepath this configuration was loaded from. May be empty.
	Filepath string `json:"filepath,omitempty"`
}

DependencyLocation is a short from location pointing to the coordinate and (if available) file of the configuration.

type NodeOption added in v2.12.0

type NodeOption func(n *ConfigNode)

type SortedComponent

type SortedComponent struct {
	// Graph is a directed graph representation of the weakly connected component/sub-graph found in another graph.
	Graph *simple.DirectedGraph
	// SortedNodes are a topologically sorted slice of graph.Node s, which can be deployed in order.
	// This exists for convenience, so callers of GetIndependentlySortedConfigs can work with the component without implementing graph algorithms.
	SortedNodes []graph.Node
}

SortedComponent represents a weakly connected component found in a graph.

type SortingErrors

type SortingErrors []error

SortingErrors is a slice of errors that implements the error interface. It may contain general errors as well as CyclicDependencyError.

func (SortingErrors) Error

func (errs SortingErrors) Error() string

Jump to

Keyboard shortcuts

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