fetch capacity and simulate task fitting (#33)

This commit is contained in:
Tan N. Le 2022-08-02 10:37:31 -07:00 committed by GitHub
parent 66bd6308ce
commit 14691698f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 171 additions and 3 deletions

View file

@ -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)
}
}

View file

@ -29,7 +29,8 @@ import (
var username, password, zkAddr, schedAddr string
var env, role, name = new(string), new(string), new(string)
var ram, disk int64
var dedicated string
var ram, disk, gpu, port int64
var cpu float64
var client *realis.Client
var skipCertVerification bool

61
cmd/simulate.go Normal file
View file

@ -0,0 +1,61 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cmd
import (
"fmt"
"github.com/aurora-scheduler/australis/internal"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(simulateCmd)
simulateCmd.AddCommand(fitCmd)
}
var simulateCmd = &cobra.Command{
Use: "simulate",
Short: "Simulate some work based on the current cluster condition, and return the output",
}
var fitCmd = &cobra.Command{
Use: "fit",
Short: "Compute how many tasks can we fit to a cluster",
Run: fit,
Args: cobra.RangeArgs(1, 2),
}
func fit(cmd *cobra.Command, args []string) {
log.Infof("Compute how many tasks can be fit in the remaining cluster capacity")
taskConfig, err := internal.UnmarshalTaskConfig(args[0])
if err != nil {
log.Fatalln(err)
}
offers, err := client.Offers()
if err != nil {
log.Fatal("error: %+v", err)
}
numTasks, err := client.FitTasks(taskConfig, offers)
if err != nil {
log.Fatal("error: %+v", err)
}
fmt.Println(numTasks)
}