github.com/observiq/carbon@v0.9.11-0.20200820160507-1b872e368a5e/pipeline/node.go (about) 1 package pipeline 2 3 import ( 4 "hash/fnv" 5 6 "github.com/observiq/carbon/operator" 7 ) 8 9 // OperatorNode is a basic node that represents an operator in a pipeline. 10 type OperatorNode struct { 11 operator operator.Operator 12 id int64 13 outputIDs map[string]int64 14 } 15 16 // Operator returns the operator of the node. 17 func (b OperatorNode) Operator() operator.Operator { 18 return b.operator 19 } 20 21 // ID returns the node id. 22 func (b OperatorNode) ID() int64 { 23 return b.id 24 } 25 26 // DOTID returns the id used to represent this node in a dot graph. 27 func (b OperatorNode) DOTID() string { 28 return b.operator.ID() 29 } 30 31 // OutputIDs returns a map of output operator ids to node ids. 32 func (b OperatorNode) OutputIDs() map[string]int64 { 33 return b.outputIDs 34 } 35 36 // createOperatorNode will create an operator node. 37 func createOperatorNode(operator operator.Operator) OperatorNode { 38 id := createNodeID(operator.ID()) 39 outputIDs := make(map[string]int64) 40 if operator.CanOutput() { 41 for _, output := range operator.Outputs() { 42 outputIDs[output.ID()] = createNodeID(output.ID()) 43 } 44 } 45 return OperatorNode{operator, id, outputIDs} 46 } 47 48 // createNodeID generates a node id from an operator id. 49 func createNodeID(operatorID string) int64 { 50 hash := fnv.New64a() 51 _, _ = hash.Write([]byte(operatorID)) 52 return int64(hash.Sum64()) 53 }