Skip to content

Commit

Permalink
fix(api): workflow import link nodes to existing joins (#5069)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored Mar 20, 2020
1 parent e1e4fc3 commit c93784b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
6 changes: 5 additions & 1 deletion sdk/exportentities/v1/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,12 @@ func (e *NodeEntry) processNodeAncestors(name string, w *sdk.Workflow) (bool, er
var join *sdk.Node
for i := range w.WorkflowData.Joins {
j := &w.WorkflowData.Joins[i]
var joinFound = true

if len(e.DependsOn) != len(j.JoinContext) {
continue
}

var joinFound = true
for _, ref := range j.JoinContext {
var refFound bool
for _, a := range e.DependsOn {
Expand Down
13 changes: 9 additions & 4 deletions sdk/exportentities/v2/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ func (w Workflow) GetWorkflow() (*sdk.Workflow, error) {
wf.HistoryLength = sdk.DefaultHistoryLength
}

rand.Seed(time.Now().Unix())
r := rand.New(rand.NewSource(time.Now().Unix()))
var attempt int
fakeID := rand.Int63n(5000)
fakeID := r.Int63n(5000)
// attempt is there to avoid infinite loop, but it should not happened becase we check validity and dependencies earlier
for len(w.Workflow) != 0 && attempt < 10000 {
for name, entry := range w.Workflow {
Expand Down Expand Up @@ -503,8 +503,9 @@ func (e *NodeEntry) processNodeAncestors(name string, w *sdk.Workflow) (bool, er
ancestor := w.WorkflowData.NodeByName(a)
if ancestor == nil {
ancestorsExist = false
} else {
ancestors = append(ancestors, ancestor)
}
ancestors = append(ancestors, ancestor)
} else {
for _, a := range e.DependsOn {
//Looking for the ancestor
Expand Down Expand Up @@ -546,8 +547,12 @@ func (e *NodeEntry) processNodeAncestors(name string, w *sdk.Workflow) (bool, er
var join *sdk.Node
for i := range w.WorkflowData.Joins {
j := &w.WorkflowData.Joins[i]
var joinFound = true

if len(e.DependsOn) != len(j.JoinContext) {
continue
}

var joinFound = true
for _, ref := range j.JoinContext {
var refFound bool
for _, a := range e.DependsOn {
Expand Down
52 changes: 52 additions & 0 deletions sdk/exportentities/v2/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,58 @@ workflow:
- success
pipeline: env
one_at_a_time: true
`,
},
{
name: "Workflow no declared joins",
yaml: `name: nojoins
version: v2.0
workflow:
p1:
pipeline: env
p5:
depends_on:
- p21
- p31
- p41
pipeline: env
p6:
depends_on:
- p21
- p31
- p41
- p42
pipeline: env
p7:
depends_on:
- p21
- p31
- p42
pipeline: env
p21:
depends_on:
- p1
pipeline: env
p22:
depends_on:
- p1
pipeline: env
p31:
depends_on:
- p1
pipeline: env
p32:
depends_on:
- p1
pipeline: env
p41:
depends_on:
- p1
pipeline: env
p42:
depends_on:
- p1
pipeline: env
`,
},
}
Expand Down

0 comments on commit c93784b

Please sign in to comment.