-
Notifications
You must be signed in to change notification settings - Fork 134
/
submit.go
51 lines (43 loc) · 1.41 KB
/
submit.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
package armadactl
import (
"fmt"
"github.com/pkg/errors"
"github.com/armadaproject/armada/pkg/api"
"github.com/armadaproject/armada/pkg/client"
"github.com/armadaproject/armada/pkg/client/domain"
"github.com/armadaproject/armada/pkg/client/util"
"github.com/armadaproject/armada/pkg/client/validation"
)
// Submit a job, represented by a file, to the Armada server.
// If dry-run is true, the job file is validated but not submitted.
func (a *App) Submit(path string, dryRun bool) error {
ok, err := validation.ValidateSubmitFile(path)
if !ok {
return err
}
submitFile := &domain.JobSubmitFile{}
err = util.BindJsonOrYaml(path, submitFile)
if err != nil {
return err
}
if dryRun {
return nil
}
requests := client.CreateChunkedSubmitRequests(submitFile.Queue, submitFile.JobSetId, submitFile.Jobs)
return client.WithSubmitClient(a.Params.ApiConnectionDetails, func(c api.SubmitClient) error {
for _, request := range requests {
response, err := client.SubmitJobs(c, request)
if err != nil {
return errors.WithMessagef(err, "error submitting request %#v", request)
}
for _, jobResponseItem := range response.JobResponseItems {
if jobResponseItem.Error != "" {
fmt.Fprintf(a.Out, "Error submitting job: %s\n", jobResponseItem.Error)
} else {
fmt.Fprintf(a.Out, "Submitted job with id %s to job set %s\n", jobResponseItem.JobId, request.JobSetId)
}
}
}
return nil
})
}