fetch capacity and simulate task fitting (#33)
This commit is contained in:
parent
66bd6308ce
commit
14691698f6
7 changed files with 171 additions and 3 deletions
60
cmd/fetch.go
60
cmd/fetch.go
|
@ -106,6 +106,21 @@ func init() {
|
|||
|
||||
// fetch quota
|
||||
fetchCmd.AddCommand(fetchQuotaCmd)
|
||||
|
||||
// fetch capacity
|
||||
fetchCmd.AddCommand(fetchAvailCapacityCmd)
|
||||
|
||||
// Hijack help function to hide unnecessary global flags
|
||||
fetchAvailCapacityCmd.SetHelpFunc(func(cmd *cobra.Command, s []string) {
|
||||
if cmd.HasInheritedFlags() {
|
||||
cmd.InheritedFlags().VisitAll(func(f *pflag.Flag) {
|
||||
if f.Name != "logLevel" {
|
||||
f.Hidden = true
|
||||
}
|
||||
})
|
||||
}
|
||||
help(cmd, s)
|
||||
})
|
||||
}
|
||||
|
||||
var fetchCmd = &cobra.Command{
|
||||
|
@ -183,6 +198,14 @@ var fetchQuotaCmd = &cobra.Command{
|
|||
Run: fetchQuota,
|
||||
}
|
||||
|
||||
var fetchAvailCapacityCmd = &cobra.Command{
|
||||
Use: "capacity",
|
||||
PreRun: setConfig,
|
||||
Short: "Fetch capacity report",
|
||||
Long: `This command will show detailed capacity report of the cluster`,
|
||||
Run: fetchAvailCapacity,
|
||||
}
|
||||
|
||||
func fetchTasksConfig(cmd *cobra.Command, args []string) {
|
||||
log.Infof("Fetching job configuration for [%s/%s/%s] \n", *env, *role, *name)
|
||||
|
||||
|
@ -416,3 +439,40 @@ func fetchQuota(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//fetchAvailCapacity reports free capacity in details
|
||||
func fetchAvailCapacity(cmd *cobra.Command, args []string) {
|
||||
log.Infof("Fetching available capacity from %s/offers\n", client.GetSchedulerURL())
|
||||
|
||||
report, err := client.AvailOfferReport()
|
||||
if err != nil {
|
||||
log.Fatalf("error: %+v\n", err)
|
||||
}
|
||||
|
||||
// convert report to user-friendly structure
|
||||
capacity := map[string]map[string]map[string]int64{}
|
||||
for g, gv := range report {
|
||||
if _, ok := capacity[g]; !ok {
|
||||
capacity[g] = map[string]map[string]int64{}
|
||||
}
|
||||
|
||||
for r, rc := range gv {
|
||||
if _, ok := capacity[g][r]; !ok {
|
||||
capacity[g][r] = map[string]int64{}
|
||||
}
|
||||
|
||||
for v, c := range rc {
|
||||
capacity[g][r][fmt.Sprint(v)] = c
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if toJson {
|
||||
fmt.Println(internal.ToJSON(capacity))
|
||||
if err != nil {
|
||||
log.Fatalf("error: %+v\n", err)
|
||||
}
|
||||
} else {
|
||||
fmt.Println(capacity)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue