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 60
/
index.go
71 lines (56 loc) · 1.64 KB
/
index.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
package common
import (
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/core"
"github.com/lyft/flytepropeller/pkg/compiler/errors"
"k8s.io/apimachinery/pkg/util/sets"
)
// Defines an index of nodebuilders based on the id.
type NodeIndex map[NodeID]NodeBuilder
// Defines an index of tasks based on the id.
type TaskIndex map[TaskIDKey]Task
type WorkflowIndex map[WorkflowIDKey]*core.CompiledWorkflow
// Defines a string adjacency list.
type AdjacencyList map[string]IdentifierSet
type StringAdjacencyList map[string]sets.String
// Converts the sets in the adjacency list to sorted arrays.
func (l AdjacencyList) ToMapOfLists() map[string][]Identifier {
res := make(map[string][]Identifier, len(l))
for key, set := range l {
res[key] = set.List()
}
return res
}
// Creates a new TaskIndex.
func NewTaskIndex(tasks ...Task) TaskIndex {
res := make(TaskIndex, len(tasks))
for _, task := range tasks {
id := task.GetID()
res[(&id).String()] = task
}
return res
}
// Creates a new NodeIndex
func NewNodeIndex(nodes ...NodeBuilder) NodeIndex {
res := make(NodeIndex, len(nodes))
for _, task := range nodes {
res[task.GetId()] = task
}
return res
}
func NewWorkflowIndex(workflows []*core.CompiledWorkflow, errs errors.CompileErrors) (index WorkflowIndex, ok bool) {
ok = true
index = make(WorkflowIndex, len(workflows))
for _, wf := range workflows {
if wf.Template.Id == nil {
// TODO: Log/Return error
return nil, false
}
if _, found := index[wf.Template.Id.String()]; found {
errs.Collect(errors.NewDuplicateIDFoundErr(wf.Template.Id.String()))
ok = false
} else {
index[wf.Template.Id.String()] = wf
}
}
return
}