From 0f02f804cf6a1e948652f906754ab8e3bf5daa5a Mon Sep 17 00:00:00 2001 From: Jon Seymour Date: Sat, 9 Apr 2016 16:41:19 +1000 Subject: [PATCH] PR #443: Add support to a Validation phase to the task lifecycle. It is better if we can detect and report configuration errors of task pipeline early, during task definition, rather than deferring such checks to runtime (when this is possible). To support such checks, we add a Validate() error method to the pipeline.Node() interface which gives pipeline nodes a chance to validate their configuration. Any pipeline containing nodes that do not pass these test cannot be saved. Signed-off-by: Jon Seymour --- pipeline/node.go | 8 ++++++++ pipeline/pipeline.go | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/pipeline/node.go b/pipeline/node.go index 29257f737a..3ed075f765 100644 --- a/pipeline/node.go +++ b/pipeline/node.go @@ -61,6 +61,9 @@ type Node interface { // The type of output the node provides. Provides() EdgeType + // Check that the definition of the node is consistent + Validate() error + // Helper methods for walking DAG tMark() bool setTMark(b bool) @@ -167,6 +170,11 @@ func (n *node) Provides() EdgeType { return n.provides } +// tick:ignore +func (n *node) Validate() error { + return nil +} + func (n *node) dot(buf *bytes.Buffer) { for _, c := range n.children { buf.Write([]byte(fmt.Sprintf("%s -> %s;\n", n.Name(), c.Name()))) diff --git a/pipeline/pipeline.go b/pipeline/pipeline.go index 63ffedf668..175e38d48b 100644 --- a/pipeline/pipeline.go +++ b/pipeline/pipeline.go @@ -60,6 +60,12 @@ func CreatePipeline(script string, sourceEdge EdgeType, scope *tick.Scope, deadm return nil, fmt.Errorf("source edge type must be either Stream or Batch not %s", sourceEdge) } } + if err = p.Walk( + func(n Node) error { + return n.Validate() + }); err != nil { + return nil, err + } return p, nil }