func cmdScale(c *cli.Context) { _, app, err := stdcli.DirApp(c, ".") if err != nil { stdcli.Error(err) return } v := url.Values{} if c.IsSet("count") { v.Set("count", c.String("count")) } if c.IsSet("memory") { v.Set("mem", c.String("memory")) } if len(v) > 0 { _, err = ConvoxPostForm("/apps/"+app, v) if err != nil { stdcli.Error(err) return } } data, err := ConvoxGet("/apps/" + app) if err != nil { stdcli.Error(err) return } var a *App err = json.Unmarshal(data, &a) if err != nil { stdcli.Error(err) return } fmt.Printf("Count %v\n", a.Parameters["DesiredCount"]) fmt.Printf("Memory %v\n", a.Parameters["Memory"]) }
func cmdSystemScale(c *cli.Context) { v := url.Values{} if c.IsSet("count") { v.Set("count", c.String("count")) } if c.IsSet("type") { v.Set("type", c.String("type")) } if len(v) > 0 { _, err := ConvoxPostForm("/system", v) if err != nil { stdcli.Error(err) return } } cmdSystem(c) }
func cmdScale(c *cli.Context) { _, app, err := stdcli.DirApp(c, ".") if err != nil { stdcli.Error(err) return } if len(c.Args()) < 1 { stdcli.Usage(c, "scale") return } v := url.Values{} if c.IsSet("count") { v.Set("count", c.String("count")) } if c.IsSet("memory") { v.Set("mem", c.String("memory")) } if len(v) > 0 { v.Set("process", c.Args()[0]) _, err = ConvoxPostForm("/apps/"+app, v) if err != nil { stdcli.Error(err) return } } data, err := ConvoxGet("/apps/" + app) if err != nil { stdcli.Error(err) return } var a *App err = json.Unmarshal(data, &a) if err != nil { stdcli.Error(err) return } processes := make(map[string]Process, 0) longest := 7 for k, v := range a.Parameters { if !strings.HasSuffix(k, "DesiredCount") { continue } ps := strings.Replace(k, "DesiredCount", "", 1) p := strings.ToLower(ps) i, err := strconv.ParseInt(v, 10, 64) if err != nil { stdcli.Error(err) return } m, err := strconv.ParseInt(a.Parameters[ps+"Memory"], 10, 64) if err != nil { stdcli.Error(err) return } processes[p] = Process{Name: p, Count: i, Memory: m} } fmt.Printf(fmt.Sprintf("%%-%ds %%-5s %%-5s\n", longest), "PROCESS", "COUNT", "MEM") for _, ps := range processes { fmt.Printf(fmt.Sprintf("%%-%ds %%-5d %%-5d\n", longest), ps.Name, ps.Count, ps.Memory) } }
func cmdScale(c *cli.Context) { _, app, err := stdcli.DirApp(c, ".") if err != nil { stdcli.Error(err) return } v := url.Values{} if c.IsSet("count") { v.Set("count", c.String("count")) } if c.IsSet("memory") { v.Set("mem", c.String("memory")) } if len(v) > 0 { v.Set("process", c.Args()[0]) _, err = ConvoxPostForm("/apps/"+app, v) if err != nil { stdcli.Error(err) return } } data, err := ConvoxGet("/apps/" + app) if err != nil { stdcli.Error(err) return } var a *App err = json.Unmarshal(data, &a) if err != nil { stdcli.Error(err) return } processes := map[string]Process{} names := []string{} for k, v := range a.Parameters { if !strings.HasSuffix(k, "DesiredCount") { continue } ps := strings.Replace(k, "DesiredCount", "", 1) p := strings.ToLower(ps) i, err := strconv.ParseInt(v, 10, 64) if err != nil { stdcli.Error(err) return } m, err := strconv.ParseInt(a.Parameters[ps+"Memory"], 10, 64) if err != nil { stdcli.Error(err) return } processes[p] = Process{Name: p, Count: i, Memory: m} names = append(names, p) } sort.Strings(names) t := stdcli.NewTable("PROCESS", "COUNT", "MEM") for _, name := range names { ps := processes[name] t.AddRow(ps.Name, fmt.Sprintf("%d", ps.Count), fmt.Sprintf("%d", ps.Memory)) } t.Print() }