This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
/
builders.go
executable file
·160 lines (126 loc) · 4.01 KB
/
builders.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package compiler
import (
"fmt"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
c "github.com/flyteorg/flytepropeller/pkg/compiler/common"
)
type flyteTask = core.TaskTemplate
type flyteWorkflow = core.CompiledWorkflow
type flyteNode = core.Node
// A builder object for the Graph struct. This contains information the compiler uses while building the final Graph
// struct.
type workflowBuilder struct {
CoreWorkflow *flyteWorkflow
LaunchPlans map[c.WorkflowIDKey]c.InterfaceProvider
Tasks c.TaskIndex
downstreamNodes c.StringAdjacencyList
upstreamNodes c.StringAdjacencyList
Nodes c.NodeIndex
NodeBuilderIndex c.NodeIndex
// These are references to all subgraphs and tasks passed to CompileWorkflow. They will be passed around but will
// not show in their entirety in the final Graph. The required subset of these will be added to each subgraph as
// the compile traverses them.
allLaunchPlans map[string]c.InterfaceProvider
allTasks c.TaskIndex
allSubWorkflows c.WorkflowIndex
allCompiledSubWorkflows c.WorkflowIndex
}
func (w workflowBuilder) GetFailureNode() c.Node {
if w.GetCoreWorkflow() != nil && w.GetCoreWorkflow().GetTemplate() != nil && w.GetCoreWorkflow().GetTemplate().FailureNode != nil {
return w.GetOrCreateNodeBuilder(w.GetCoreWorkflow().GetTemplate().FailureNode)
}
return nil
}
func (w workflowBuilder) GetNodes() c.NodeIndex {
return w.Nodes
}
func (w workflowBuilder) GetTasks() c.TaskIndex {
return w.Tasks
}
func (w workflowBuilder) GetDownstreamNodes() c.StringAdjacencyList {
return w.downstreamNodes
}
func (w workflowBuilder) GetUpstreamNodes() c.StringAdjacencyList {
return w.upstreamNodes
}
func (w workflowBuilder) GetOrCreateNodeBuilder(n *flyteNode) c.NodeBuilder {
address := fmt.Sprintf("%p", n)
if existingBuilder, found := w.NodeBuilderIndex[address]; found {
return existingBuilder
}
newObj := &nodeBuilder{flyteNode: n}
w.NodeBuilderIndex[address] = newObj
return newObj
}
func (w workflowBuilder) GetNode(id c.NodeID) (node c.NodeBuilder, found bool) {
node, found = w.Nodes[id]
return
}
func (w workflowBuilder) GetTask(id c.TaskID) (task c.Task, found bool) {
task, found = w.Tasks[id.String()]
return
}
func (w workflowBuilder) GetLaunchPlan(id c.LaunchPlanID) (wf c.InterfaceProvider, found bool) {
wf, found = w.LaunchPlans[id.String()]
return
}
func (w workflowBuilder) StoreCompiledSubWorkflow(id c.WorkflowID, compiledWorkflow *core.CompiledWorkflow) {
w.allCompiledSubWorkflows[id.String()] = compiledWorkflow
}
func (w workflowBuilder) GetCompiledSubWorkflow(id c.WorkflowID) (wf *core.CompiledWorkflow, found bool) {
wf, found = w.allCompiledSubWorkflows[id.String()]
return
}
func (w workflowBuilder) GetSubWorkflow(id c.WorkflowID) (wf *core.CompiledWorkflow, found bool) {
wf, found = w.allSubWorkflows[id.String()]
return
}
func (w workflowBuilder) GetCoreWorkflow() *flyteWorkflow {
return w.CoreWorkflow
}
// A wrapper around core.nodeBuilder to augment with computed fields during compilation
type nodeBuilder struct {
*flyteNode
subWorkflow c.Workflow
Task c.Task
Iface *core.TypedInterface
}
func (n nodeBuilder) GetTask() c.Task {
return n.Task
}
func (n *nodeBuilder) SetTask(task c.Task) {
n.Task = task
}
func (n nodeBuilder) GetSubWorkflow() c.Workflow {
return n.subWorkflow
}
func (n nodeBuilder) GetCoreNode() *core.Node {
return n.flyteNode
}
func (n nodeBuilder) GetInterface() *core.TypedInterface {
return n.Iface
}
func (n *nodeBuilder) SetInterface(iface *core.TypedInterface) {
n.Iface = iface
}
func (n *nodeBuilder) SetSubWorkflow(wf c.Workflow) {
n.subWorkflow = wf
}
func (n *nodeBuilder) SetInputs(inputs []*core.Binding) {
n.Inputs = inputs
}
func (n *nodeBuilder) SetID(id string) {
n.Id = id
}
type taskBuilder struct {
*flyteTask
}
func (t taskBuilder) GetCoreTask() *core.TaskTemplate {
return t.flyteTask
}
func (t taskBuilder) GetID() c.Identifier {
if t.flyteTask.Id != nil {
return *t.flyteTask.Id
}
return c.Identifier{}
}