depgraph

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2015 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

The depgraph package is used to create and model a dependency graph of nouns. Each noun can represent a service, server, application, network switch, etc. Nouns can depend on other nouns, and provide versioning constraints. Nouns can also have various meta data that may be relevant to their construction or configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constraint

type Constraint interface {
	Satisfied(head, tail *Noun) (bool, error)
}

Constraint is used by dependencies to allow arbitrary constraints between nouns

type ConstraintError

type ConstraintError struct {
	Violations []*Violation
}

ConstraintError is used to return detailed violation information from CheckConstraints

func (*ConstraintError) Error

func (c *ConstraintError) Error() string

type Dependency

type Dependency struct {
	Name        string
	Meta        interface{}
	Constraints []Constraint
	Source      *Noun
	Target      *Noun
}

Dependency is used to create a directed edge between two nouns. One noun may depend on another and provide version constraints that cannot be violated

func (*Dependency) GoString added in v0.2.0

func (d *Dependency) GoString() string

func (*Dependency) Head

func (d *Dependency) Head() digraph.Node

Head returns the source, or dependent noun

func (*Dependency) String

func (d *Dependency) String() string

func (*Dependency) Tail

func (d *Dependency) Tail() digraph.Node

Tail returns the target, or depended upon noun

type Graph

type Graph struct {
	Name  string
	Meta  interface{}
	Nouns []*Noun
	Root  *Noun
}

Graph is used to represent a dependency graph.

func (*Graph) CheckConstraints

func (g *Graph) CheckConstraints() error

CheckConstraints walks the graph and ensures that all user imposed constraints are satisfied.

func (*Graph) DependsOn added in v0.3.0

func (g *Graph) DependsOn(n *Noun) []*Noun

DependsOn returns the set of nouns that have a dependency on a given noun. This can be used to find the incoming edges to a noun.

func (*Graph) Noun

func (g *Graph) Noun(name string) *Noun

Noun returns the noun with the given name, or nil if it cannot be found.

func (*Graph) String

func (g *Graph) String() string

String generates a little ASCII string of the graph, useful in debugging output.

func (*Graph) Validate

func (g *Graph) Validate() error

Validate is used to ensure that a few properties of the graph are not violated: 1) There must be a single "root", or source on which nothing depends. 2) All nouns in the graph must be reachable from the root 3) The graph must be cycle free, meaning there are no cicular dependencies

func (*Graph) Walk

func (g *Graph) Walk(fn WalkFunc) error

Walk will walk the tree depth-first (dependency first) and call the callback.

The callbacks will be called in parallel, so if you need non-parallelism, then introduce a lock in your callback.

type Noun

type Noun struct {
	Name string // Opaque name
	Meta interface{}
	Deps []*Dependency
}

Nouns are the key structure of the dependency graph. They can be used to represent all objects in the graph. They are linked by depedencies.

func (*Noun) Edges

func (n *Noun) Edges() []digraph.Edge

Edges returns the out-going edges of a Noun

func (*Noun) GoString added in v0.2.0

func (n *Noun) GoString() string

func (*Noun) String

func (n *Noun) String() string

type ValidateError

type ValidateError struct {
	// If set, then the graph is missing a single root, on which
	// there are no depdendencies
	MissingRoot bool

	// Unreachable are nodes that could not be reached from
	// the root noun.
	Unreachable []*Noun

	// Cycles are groups of strongly connected nodes, which
	// form a cycle. This is disallowed.
	Cycles [][]*Noun
}

ValidateError implements the Error interface but provides additional information on a validation error.

func (*ValidateError) Error

func (v *ValidateError) Error() string

type Violation

type Violation struct {
	Source     *Noun
	Target     *Noun
	Dependency *Dependency
	Constraint Constraint
	Err        error
}

Violation is used to pass along information about a constraint violation

func (*Violation) Error

func (v *Violation) Error() string

type WalkFunc

type WalkFunc func(*Noun) error

WalkFunc is the type used for the callback for Walk.

Jump to

Keyboard shortcuts

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