-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
93 lines (84 loc) · 2.02 KB
/
main.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
package main
import (
"fmt"
"os"
"github.com/dgruber/drmaa2interface"
"github.com/dgruber/qsub/pkg/cli"
"github.com/dgruber/qsub/pkg/job"
"github.com/dgruber/qsub/pkg/server"
"github.com/dgruber/qsub/pkg/template"
)
func main() {
request, err := cli.ParseCommandline(os.Args[1:])
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to submit job: %s\n", err.Error())
os.Exit(1)
}
if request.Client == false && request.ServeHost != "" {
// start qsub as server
password, err := server.GetOrCreateSecret()
if err != nil {
fmt.Fprintf(os.Stderr, "Qsub server failed: %s\n",
err.Error())
os.Exit(1)
}
err = server.Serve(server.Config{
Host: request.ServeHost,
Port: request.ServePort,
Password: password,
Backend: request.Backend,
})
if err != nil {
fmt.Fprintf(os.Stderr, "Qsub server failed: %s\n",
err.Error())
os.Exit(1)
}
return
}
var jt drmaa2interface.JobTemplate
if request.Backend == "" {
// default backend with all parameters from cli
jt, err = template.Create(request)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(2)
}
request.Backend = "kubernetes"
} else {
// job template from file
jt, err = job.ReadJobTemplateFromJSONFile(request.JobTemplatePath)
if err != nil {
fmt.Printf("Failed parsing job template: %s\n", err.Error())
os.Exit(3)
}
}
_, job, err := job.SubmitToBackend(request, jt)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(4)
}
if !request.Quiet {
fmt.Printf("Job submitted\n")
}
if job != nil && !request.Quiet {
fmt.Printf("Job ID: %s\n", job.JobID())
}
if request.Sync {
// wait for the job to finish
if job == nil {
fmt.Fprintf(os.Stderr,
fmt.Sprintf("Backend %s does not yet support sync\n",
request.Backend))
} else {
if !request.Quiet {
fmt.Printf("Waiting for job to finish...\n")
}
// forwards the exit code of the job + 128
exitCode := job.ExitStatus()
if exitCode == 0 {
os.Exit(0)
}
os.Exit(exitCode + 128)
}
}
}