graph

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph

type Graph struct {
	Name   string // Name of the graph
	Source *Node  // The single source node of the graph
	Sink   *Node  // The single sink node of the graph

	// Nodes are keyed on node id, which is a string
	Nodes    map[string]*Node    // All nodes
	Edges    map[string][]string // All edges
	RevEdges map[string][]string // All reverse edges (sink -> source)

	Order []*Node // Topological ordering of nodes (only used in sequence graphs)
}

Graph is a DAG where nodes are node specs (if a sequence graph) or jobs (if a request graph), and a directed edge (u, v) exists iff u is a dependency of v. It has one source and one sink node.

func (*Graph) GetNext

func (g *Graph) GetNext(n *Node) []*Node

GetNext returns the out edges of a node

func (*Graph) GetPrev

func (g *Graph) GetPrev(n *Node) []*Node

GetPrev returns the in edges of a node

func (*Graph) InsertComponentBetween

func (g *Graph) InsertComponentBetween(component *Graph, prev *Node, next *Node) error

InsertComponentBetween takes a Graph as input and inserts it between the given prev and next nodes. Preconditions:

component and g are connected and acyclic
prev and next both are present in g
next "comes after" prev in the graph, when traversing from the source node

func (*Graph) IsValidGraph

func (g *Graph) IsValidGraph() error

IsValidGraph asserts that g is a valid graph by ensuring that g is acyclic and connected (not fully connected), and that the edge map matches the reverse edge map.

func (*Graph) PrintDot

func (g *Graph) PrintDot()

PrintDot prints out g in DOT graph format. Copy and paste output into http://www.webgraphviz.com/ It's not used anywhere in the code, but it is a very useful debugging tool.

type Grapher

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

Grapher builds sequence graphs. A single node in a sequence graph represents a node spec, and edges indicate dependencies between nodes in the spec. Each sequence graphs describes a single sequence spec. Sequence, conditional, and expandable sequence nodes correspond to a single node in a sequence graph, and are later resolved into a request subgraph consisting of only job nodes by the Resolver.

func NewGrapher

func NewGrapher(specs spec.Specs, idGenFactory id.GeneratorFactory) *Grapher

TODO: Grapher may soon have fields that need to be initialized, e.g. it might store the sequence graph map, and we want it to start off non-nil.

func (*Grapher) CheckSequences

func (gr *Grapher) CheckSequences() (map[string]*Graph, *spec.CheckResults)

CheckSequences performs graph checks for all sequences and returns a map of sequence name -> sequence graph and a map of sequence name --> error. If any error occurs, the sequence graph map is nil.

type Node

type Node struct {
	// Always valid
	Id   string // UID within graph
	Name string // Descriptive name for debugging and visualizing graph

	// Used when node represents a node spec
	Spec *spec.Node // Node spec that this graph node represents

	// Used when node represents a job
	JobBytes          []byte                 // return value of Job.Serialize method
	Args              map[string]interface{} // The args the node was created with
	Retry             uint                   // The number of times to retry a node
	RetryWait         string                 // The time to sleep between retries
	SequenceId        string                 // ID for first node in sequence
	SequenceRetry     uint                   // Number of times to retry a sequence. Only set for first node in sequence.
	SequenceRetryWait string                 // The time to sleep between sequence retries
}

Node represents a node spec (if a sequence graph) or a job (if a request graph). Validity of fields depends on use case.

type Resolver

type Resolver interface {
	// Convert job args map to a list of proto.RequestArgs.
	RequestArgs(jobArgs map[string]interface{}) ([]proto.RequestArg, error)

	// Build the request graph. Returns an error if any error occurs.
	BuildRequestGraph(jobArgs map[string]interface{}) (*Graph, error)
}

Resolver builds a request graph for a specific request.

type ResolverFactory

type ResolverFactory interface {
	// Make makes a Resolver. A new resolver should be made for every request.
	Make(proto.Request) Resolver
}

ResolverFactory returns Resolvers tailored to create request graphs for a specific input request.

func NewResolverFactory

func NewResolverFactory(jf job.Factory, seqSpecs map[string]*spec.Sequence, seqGraphs map[string]*Graph, idf id.GeneratorFactory) ResolverFactory

Jump to

Keyboard shortcuts

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