-
Notifications
You must be signed in to change notification settings - Fork 127
/
queue.go
162 lines (140 loc) · 5 KB
/
queue.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
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/armadaproject/armada/internal/armadactl"
"github.com/armadaproject/armada/pkg/api"
"github.com/armadaproject/armada/pkg/client/queue"
)
func queueCreateCmd() *cobra.Command {
return queueCreateCmdWithApp(armadactl.New())
}
// Takes a caller-supplied app struct; useful for testing.
func queueCreateCmdWithApp(a *armadactl.App) *cobra.Command {
cmd := &cobra.Command{
Use: "queue <queueName>",
Short: "Create new queue",
Long: `Every job submitted to armada needs to be associated with queue.
Job priority is evaluated inside queue, queue has its own priority.`,
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
return initParams(cmd, a.Params)
},
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
// TODO cmd.Flags().GetFloat64("priorityFactor") returns (0, nil) for invalid input (e.g., "not_a_float")
// TODO the other Flags get methods also fail to return errors on invalid input
priorityFactor, err := cmd.Flags().GetFloat64("priorityFactor")
if err != nil {
return fmt.Errorf("error reading priorityFactor: %s", err)
}
owners, err := cmd.Flags().GetStringSlice("owners")
if err != nil {
return fmt.Errorf("error reading owners: %s", err)
}
groups, err := cmd.Flags().GetStringSlice("groupOwners")
if err != nil {
return fmt.Errorf("error reading groupOwners: %s", err)
}
queue, err := queue.NewQueue(&api.Queue{
Name: name,
PriorityFactor: priorityFactor,
UserOwners: owners,
GroupOwners: groups,
})
if err != nil {
return fmt.Errorf("invalid queue data: %s", err)
}
return a.CreateQueue(queue)
},
}
cmd.Flags().Float64("priorityFactor", 1, "Set queue priority factor - lower number makes queue more important, must be > 0.")
cmd.Flags().StringSlice("owners", []string{}, "Comma separated list of queue owners, defaults to current user.")
cmd.Flags().StringSlice("groupOwners", []string{}, "Comma separated list of queue group owners, defaults to empty list.")
return cmd
}
func queueDeleteCmd() *cobra.Command {
return queueDeleteCmdWithApp(armadactl.New())
}
// Takes a caller-supplied app struct; useful for testing.
func queueDeleteCmdWithApp(a *armadactl.App) *cobra.Command {
cmd := &cobra.Command{
Use: "queue <queueName>",
Short: "Delete existing queue",
Long: "Deletes queue if it exists, the queue needs to be empty at the time of deletion.",
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
return initParams(cmd, a.Params)
},
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
return a.DeleteQueue(name)
},
}
return cmd
}
func queueGetCmd() *cobra.Command {
return queueGetCmdWithApp(armadactl.New())
}
// Takes a caller-supplied app struct; useful for testing.
func queueGetCmdWithApp(a *armadactl.App) *cobra.Command {
cmd := &cobra.Command{
Use: "queue <queueName>",
Short: "Gets Queue Information.",
Long: "Gets Queue Information",
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
return initParams(cmd, a.Params)
},
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
return a.GetQueue(name)
},
}
return cmd
}
func queueUpdateCmd() *cobra.Command {
return queueUpdateCmdWithApp(armadactl.New())
}
// Takes a caller-supplied app struct; useful for testing.
func queueUpdateCmdWithApp(a *armadactl.App) *cobra.Command {
cmd := &cobra.Command{
Use: "queue <queueName>",
Short: "Update an existing queue",
Long: "Update settings of an existing queue",
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
return initParams(cmd, a.Params)
},
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
priorityFactor, err := cmd.Flags().GetFloat64("priorityFactor")
if err != nil {
return fmt.Errorf("error reading priorityFactor: %s", err)
}
owners, err := cmd.Flags().GetStringSlice("owners")
if err != nil {
return fmt.Errorf("error reading owners: %s", err)
}
groups, err := cmd.Flags().GetStringSlice("groupOwners")
if err != nil {
return fmt.Errorf("error reading groupOwners: %s", err)
}
queue, err := queue.NewQueue(&api.Queue{
Name: name,
PriorityFactor: priorityFactor,
UserOwners: owners,
GroupOwners: groups,
})
if err != nil {
return fmt.Errorf("invalid queue data: %s", err)
}
return a.UpdateQueue(queue)
},
}
// TODO this will overwrite existing values with default values if not all flags are provided
cmd.Flags().Float64("priorityFactor", 1, "Set queue priority factor - lower number makes queue more important, must be > 0.")
cmd.Flags().StringSlice("owners", []string{}, "Comma separated list of queue owners, defaults to current user.")
cmd.Flags().StringSlice("groupOwners", []string{}, "Comma separated list of queue group owners, defaults to empty list.")
return cmd
}