This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
/
node_exec_context.go
174 lines (145 loc) · 4.53 KB
/
node_exec_context.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package nodes
import (
"context"
"fmt"
"github.com/lyft/flyteidl/clients/go/events"
"github.com/lyft/flyteplugins/go/tasks/pluginmachinery/io"
"github.com/lyft/flyteplugins/go/tasks/pluginmachinery/ioutils"
"github.com/lyft/flytestdlib/storage"
"k8s.io/apimachinery/pkg/types"
"github.com/lyft/flytepropeller/pkg/apis/flyteworkflow/v1alpha1"
"github.com/lyft/flytepropeller/pkg/controller/nodes/handler"
"github.com/lyft/flytepropeller/pkg/utils"
)
const NodeIDLabel = "node-id"
const TaskNameLabel = "task-name"
type execMetadata struct {
v1alpha1.WorkflowMeta
}
func (e execMetadata) GetK8sServiceAccount() string {
return e.WorkflowMeta.GetServiceAccountName()
}
func (e execMetadata) GetOwnerID() types.NamespacedName {
return types.NamespacedName{Name: e.GetName(), Namespace: e.GetNamespace()}
}
type execContext struct {
store *storage.DataStore
tr handler.TaskReader
md handler.NodeExecutionMetadata
er events.TaskEventRecorder
inputs io.InputReader
node v1alpha1.ExecutableNode
nodeStatus v1alpha1.ExecutableNodeStatus
maxDatasetSizeBytes int64
nsm *nodeStateManager
enqueueOwner func() error
w v1alpha1.ExecutableWorkflow
nodeLabels map[string]string
}
func (e execContext) EnqueueOwnerFunc() func() error {
return e.enqueueOwner
}
func (e execContext) Workflow() v1alpha1.ExecutableWorkflow {
return e.w
}
func (e execContext) TaskReader() handler.TaskReader {
return e.tr
}
func (e execContext) NodeStateReader() handler.NodeStateReader {
return e.nsm
}
func (e execContext) NodeStateWriter() handler.NodeStateWriter {
return e.nsm
}
func (e execContext) DataStore() *storage.DataStore {
return e.store
}
func (e execContext) InputReader() io.InputReader {
return e.inputs
}
func (e execContext) EventsRecorder() events.TaskEventRecorder {
return e.er
}
func (e execContext) NodeID() v1alpha1.NodeID {
return e.node.GetID()
}
func (e execContext) Node() v1alpha1.ExecutableNode {
return e.node
}
func (e execContext) CurrentAttempt() uint32 {
return e.nodeStatus.GetAttempts()
}
func (e execContext) NodeStatus() v1alpha1.ExecutableNodeStatus {
return e.nodeStatus
}
func (e execContext) NodeExecutionMetadata() handler.NodeExecutionMetadata {
return e.md
}
func (e execContext) MaxDatasetSizeBytes() int64 {
return e.maxDatasetSizeBytes
}
func (e execContext) GetLabels() map[string]string {
return e.nodeLabels
}
func newNodeExecContext(_ context.Context, store *storage.DataStore, w v1alpha1.ExecutableWorkflow, node v1alpha1.ExecutableNode, nodeStatus v1alpha1.ExecutableNodeStatus, inputs io.InputReader, maxDatasetSize int64, er events.TaskEventRecorder, tr handler.TaskReader, nsm *nodeStateManager, enqueueOwner func() error) *execContext {
md := execMetadata{WorkflowMeta: w}
// Copying the labels before updating it for this node
nodeLabels := make(map[string]string)
for k, v := range md.GetLabels() {
nodeLabels[k] = v
}
nodeLabels[NodeIDLabel] = utils.SanitizeLabelValue(node.GetID())
if tr != nil && tr.GetTaskID() != nil {
nodeLabels[TaskNameLabel] = utils.SanitizeLabelValue(tr.GetTaskID().Name)
}
return &execContext{
md: md,
store: store,
node: node,
nodeStatus: nodeStatus,
inputs: inputs,
er: er,
maxDatasetSizeBytes: maxDatasetSize,
tr: tr,
nsm: nsm,
enqueueOwner: enqueueOwner,
w: w,
nodeLabels: nodeLabels,
}
}
func (c *nodeExecutor) newNodeExecContextDefault(ctx context.Context, w v1alpha1.ExecutableWorkflow, n v1alpha1.ExecutableNode, s v1alpha1.ExecutableNodeStatus) (*execContext, error) {
var tr handler.TaskReader
if n.GetKind() == v1alpha1.NodeKindTask {
if n.GetTaskID() == nil {
return nil, fmt.Errorf("bad state, no task-id defined for node [%s]", n.GetID())
}
tk, err := w.GetTask(*n.GetTaskID())
if err != nil {
return nil, err
}
tr = &taskReader{TaskTemplate: tk.CoreTask()}
}
workflowEnqueuer := func() error {
c.enqueueWorkflow(w.GetID())
return nil
}
return newNodeExecContext(ctx, c.store, w, n, s,
ioutils.NewCachedInputReader(
ctx,
ioutils.NewRemoteFileInputReader(
ctx,
c.store,
ioutils.NewInputFilePaths(
ctx,
c.store,
s.GetDataDir(),
),
),
),
c.maxDatasetSizeBytes,
&taskEventRecorder{TaskEventRecorder: c.taskRecorder},
tr,
newNodeStateManager(ctx, s),
workflowEnqueuer,
), nil
}