-
Notifications
You must be signed in to change notification settings - Fork 134
/
app.go
66 lines (57 loc) · 2.2 KB
/
app.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
/*
Package armadactl contains all the business logic for armadactl.
It has no dependency on either viper or cobra libraries, and can be unit tested.
Output writer for the App is configurable so that tests can easily capture
and perform assertions on it. Params are initialised in the param package,
so that this package can be clear of viper dependency.
# TODO there should be a type that uniquely represents a job, instead of having to pass around several parameters
TODO add methods for querying more detailed info about queues and jobs (current priority and so on)
*/
package armadactl
import (
"crypto/rand"
"io"
"os"
"github.com/armadaproject/armada/pkg/client"
"github.com/armadaproject/armada/pkg/client/queue"
)
type App struct {
// Parameters passed to the CLI by the user.
Params *Params
// Out is used to write the output. Default to standard out,
// but can be overridden in tests to make assertions on the applications's output.
Out io.Writer
// Source of randomness. Tests can use a mocked random source in order to provide
// deterministic testing behaviour.
Random io.Reader
}
// Params struct holds all user-customizable parameters.
// Using a single struct for all CLI commands ensures that all flags are distinct
// and that they can be provided either dynamically on a command line, or
// statically in a config file that's reused between command runs.
type Params struct {
ApiConnectionDetails *client.ApiConnectionDetails
QueueAPI *QueueAPI
}
// QueueAPI struct holds pointers to functions that are called by armadactl.
// The function types are defined in in /pkg/client/queue.
// By default, they point to functions defined in /pkg/client/queue, which call the Armada server gRPC API.
// However, they are user-replaceable to facilitate testing.
// TODO Consider replacing with an interface
type QueueAPI struct {
Create queue.CreateAPI
Delete queue.DeleteAPI
GetInfo queue.GetInfoAPI
Update queue.UpdateAPI
}
// New instantiates an App with default parameters, including standard output
// and cryptographically secure random source.
func New() *App {
app := &App{
Params: &Params{},
Out: os.Stdout,
Random: rand.Reader,
}
app.Params.QueueAPI = &QueueAPI{}
return app
}