-
Notifications
You must be signed in to change notification settings - Fork 134
/
runner.go
178 lines (159 loc) · 5.14 KB
/
runner.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
175
176
177
178
package simulator
import (
"fmt"
"path/filepath"
"strings"
"github.com/mattn/go-zglob"
"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/armadaproject/armada/internal/armada/configuration"
commonconfig "github.com/armadaproject/armada/internal/common/config"
)
func SchedulingConfigsByFilePathFromPattern(pattern string) (map[string]configuration.SchedulingConfig, error) {
filePaths, err := zglob.Glob(pattern)
if err != nil {
return nil, errors.WithStack(err)
}
filePathConfigMap := make(map[string]configuration.SchedulingConfig)
for _, path := range filePaths {
config, err := SchedulingConfigsFromFilePaths(filePaths)
if err != nil {
return nil, err
}
filePathConfigMap[path] = config[0]
}
return filePathConfigMap, nil
}
func SchedulingConfigsFromPattern(pattern string) ([]configuration.SchedulingConfig, error) {
filePaths, err := zglob.Glob(pattern)
if err != nil {
return nil, errors.WithStack(err)
}
return SchedulingConfigsFromFilePaths(filePaths)
}
func SchedulingConfigsFromFilePaths(filePaths []string) ([]configuration.SchedulingConfig, error) {
rv := make([]configuration.SchedulingConfig, len(filePaths))
for i, filePath := range filePaths {
config, err := SchedulingConfigFromFilePath(filePath)
if err != nil {
return nil, err
}
rv[i] = config
}
return rv, nil
}
func SchedulingConfigFromFilePath(filePath string) (configuration.SchedulingConfig, error) {
config := configuration.SchedulingConfig{}
v := viper.NewWithOptions(viper.KeyDelimiter("::"))
v.SetConfigFile(filePath)
if err := v.ReadInConfig(); err != nil {
err = errors.WithMessagef(err, "failed to read in SchedulingConfig %s", filePath)
return config, errors.WithStack(err)
}
if err := v.Unmarshal(&config, commonconfig.CustomHooks...); err != nil {
err = errors.WithMessagef(err, "failed to unmarshal SchedulingConfig %s", filePath)
return config, errors.WithStack(err)
}
return config, nil
}
func ClusterSpecsFromPattern(pattern string) ([]*ClusterSpec, error) {
filePaths, err := zglob.Glob(pattern)
if err != nil {
return nil, errors.WithStack(err)
}
return ClusterSpecsFromFilePaths(filePaths)
}
func WorkloadsFromPattern(pattern string) ([]*WorkloadSpec, error) {
filePaths, err := zglob.Glob(pattern)
if err != nil {
return nil, errors.WithStack(err)
}
return WorkloadSpecsFromFilePaths(filePaths)
}
func ClusterSpecsFromFilePaths(filePaths []string) ([]*ClusterSpec, error) {
rv := make([]*ClusterSpec, len(filePaths))
for i, filePath := range filePaths {
clusterSpec, err := ClusterSpecFromFilePath(filePath)
if err != nil {
return nil, err
}
rv[i] = clusterSpec
}
return rv, nil
}
func WorkloadSpecsFromFilePaths(filePaths []string) ([]*WorkloadSpec, error) {
rv := make([]*WorkloadSpec, len(filePaths))
for i, filePath := range filePaths {
workloadSpec, err := WorkloadSpecFromFilePath(filePath)
if err != nil {
return nil, err
}
rv[i] = workloadSpec
}
return rv, nil
}
func ClusterSpecFromFilePath(filePath string) (*ClusterSpec, error) {
rv := &ClusterSpec{}
v := viper.NewWithOptions(viper.KeyDelimiter("::"))
v.SetConfigFile(filePath)
if err := v.ReadInConfig(); err != nil {
err = errors.WithMessagef(err, "failed to read in ClusterSpec %s", filePath)
return nil, errors.WithStack(err)
}
if err := v.Unmarshal(rv, commonconfig.CustomHooks...); err != nil {
err = errors.WithMessagef(err, "failed to unmarshal ClusterSpec %s", filePath)
return nil, errors.WithStack(err)
}
// If no test name is provided, set it to be the filename.
if rv.Name == "" {
fileName := filepath.Base(filePath)
fileName = strings.TrimSuffix(fileName, filepath.Ext(fileName))
rv.Name = fileName
}
initialiseClusterSpec(rv)
return rv, nil
}
func WorkloadSpecFromFilePath(filePath string) (*WorkloadSpec, error) {
rv := &WorkloadSpec{}
v := viper.NewWithOptions(viper.KeyDelimiter("::"))
v.SetConfigFile(filePath)
if err := v.ReadInConfig(); err != nil {
err = errors.WithMessagef(err, "failed to read in WorkloadSpec %s", filePath)
return nil, errors.WithStack(err)
}
if err := v.Unmarshal(rv, commonconfig.CustomHooks...); err != nil {
err = errors.WithMessagef(err, "failed to unmarshal WorkloadSpec %s", filePath)
return nil, errors.WithStack(err)
}
// If no test name is provided, set it to be the filename.
if rv.Name == "" {
fileName := filepath.Base(filePath)
fileName = strings.TrimSuffix(fileName, filepath.Ext(fileName))
rv.Name = fileName
}
initialiseWorkloadSpec(rv)
return rv, nil
}
func initialiseClusterSpec(clusterSpec *ClusterSpec) {
// Assign names to executors with none specified.
for _, pool := range clusterSpec.Pools {
for i, executorGroup := range pool.ClusterGroups {
for j, executor := range executorGroup.Clusters {
if executor.Name == "" {
executor.Name = fmt.Sprintf("%s-%d-%d", pool.Name, i, j)
}
}
}
}
}
func initialiseWorkloadSpec(workloadSpec *WorkloadSpec) {
// Assign names to jobTemplates with none specified.
for _, queue := range workloadSpec.Queues {
for i, jobTemplate := range queue.JobTemplates {
if jobTemplate.Id == "" {
jobTemplate.Id = fmt.Sprintf("%s-%d", queue.Name, i)
}
jobTemplate.Queue = queue.Name
}
}
}