-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.go
More file actions
160 lines (144 loc) · 3.55 KB
/
Copy pathparser.go
File metadata and controls
160 lines (144 loc) · 3.55 KB
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
package app
import (
"github.com/pkg/errors"
"github.com/urfave/cli"
)
func parse() *cli.App {
app := cli.NewApp()
app.Name = "hrctl"
app.Authors = []cli.Author{
{Name: "Heracles Authors", Email: "heracles@cpssd.net"},
}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "manager, m",
Value: "[::]:8081",
Usage: "Address to the manager",
EnvVar: "HERACLES_MANAGER",
},
}
app.Commands = []cli.Command{
{
Name: "schedule",
Usage: "schedule a job from given input file",
Action: schedule,
Flags: []cli.Flag{
cli.StringFlag{
Name: "job_file, f",
Usage: "load the job configuration from `FILE`",
Value: "",
},
},
ArgsUsage: " ",
}, {
Name: "cancel",
Usage: "cancel a job",
Action: cancel,
ArgsUsage: "<job-id>",
}, {
Name: "describe",
Usage: "describe a resource in heracles",
Subcommands: []cli.Command{
{
Name: "cluster",
Usage: "Information about the heracles cluster",
ArgsUsage: " ",
Action: describeCluster,
}, {
Name: "queue",
Usage: "Current jobs in the queue",
ArgsUsage: " ",
Action: describeQueue,
}, {
Name: "job",
Usage: "Specific Job information",
ArgsUsage: "<JOB-ID>",
Action: func(c *cli.Context) error {
if c.Args().First() == "" {
return errors.New("Job ID must be specified")
}
return describeJobs(c)
},
}, {
Name: "jobs",
Usage: "List of jobs which are currently in progress",
ArgsUsage: " ",
Action: describeJobs,
}, {
Name: "task",
Usage: "Specific job nformation",
ArgsUsage: "<TASK-ID>",
Action: func(c *cli.Context) error {
if c.Args().First() == "" {
return errors.New("Task ID must be specified")
}
return describeTasks(c)
},
}, {
Name: "tasks",
Usage: "Lists of all tasks",
ArgsUsage: " ",
Flags: []cli.Flag{
cli.StringFlag{
Name: "job",
Usage: "limit tasks to specific job",
Value: "",
},
},
Action: describeTasks,
},
},
},
}
return app
}
func schedule(c *cli.Context) error {
job, err := loadJob(c.String("job_file"))
if err != nil {
return errors.Wrap(err, "unable to get job from file")
}
conn, err := connect(c.GlobalString("manager"))
if err != nil {
return errors.Wrap(err, "unable to connect to manager")
}
return conn.schedule(job)
}
func cancel(c *cli.Context) error {
conn, err := connect(c.String("manager"))
if err != nil {
return errors.Wrap(err, "unable to connect to manager")
}
jobID := c.Args().First()
if jobID == "" {
return errors.New("job ID cannot be empty")
}
return conn.cancel(jobID)
}
func describeCluster(c *cli.Context) error {
conn, err := connect(c.String("manager"))
if err != nil {
return errors.Wrap(err, "unable to connect to manager")
}
return conn.describeCluster()
}
func describeQueue(c *cli.Context) error {
conn, err := connect(c.String("manager"))
if err != nil {
return errors.Wrap(err, "unable to connect to manager")
}
return conn.describeQueue()
}
func describeJobs(c *cli.Context) error {
conn, err := connect(c.String("manager"))
if err != nil {
return errors.Wrap(err, "unable to connect to manager")
}
return conn.describeJobs(c.Args().First())
}
func describeTasks(c *cli.Context) error {
conn, err := connect(c.String("manager"))
if err != nil {
return errors.Wrap(err, "unable to connect to manager")
}
return conn.describeTasks(c.Args().First(), c.String("job"))
}