(ctx context.Context, app string, sync bool, types []string)
| 21 | } |
| 22 | |
| 23 | func Scale(ctx context.Context, app string, sync bool, types []string) error { |
| 24 | var ( |
| 25 | size string |
| 26 | containerTypes []scalingo.ContainerType |
| 27 | modificator byte |
| 28 | err error |
| 29 | ) |
| 30 | |
| 31 | c, err := config.ScalingoClient(ctx) |
| 32 | if err != nil { |
| 33 | return errors.Wrapf(ctx, err, "fail to get Scalingo client") |
| 34 | } |
| 35 | scaleParams := &scalingo.AppsScaleParams{} |
| 36 | typesWithAutoscaler := []string{} |
| 37 | autoscalers, err := c.AutoscalersList(ctx, app) |
| 38 | if err != nil { |
| 39 | return errors.Wrapf(ctx, err, "fail to list the autoscalers") |
| 40 | } |
| 41 | |
| 42 | for _, t := range types { |
| 43 | splitT := strings.Split(t, ":") |
| 44 | if len(splitT) != 2 && len(splitT) != 3 { |
| 45 | return errors.Newf(ctx, "%s is invalid, format is <type>:<amount>[:<size>]", t) |
| 46 | } |
| 47 | typeName, typeAmount := splitT[0], splitT[1] |
| 48 | if len(splitT) == 3 { |
| 49 | size = splitT[2] |
| 50 | } |
| 51 | |
| 52 | if typeAmount[0] == '-' || typeAmount[0] == '+' { |
| 53 | modificator = typeAmount[0] |
| 54 | typeAmount = typeAmount[1:] |
| 55 | if size != "" { |
| 56 | return errors.Newf(ctx, "%s is invalid, can't use relative modificator with size, change the size first", t) |
| 57 | } |
| 58 | if containerTypes == nil { |
| 59 | containerTypes, err = c.AppsContainerTypes(ctx, app) |
| 60 | if err != nil { |
| 61 | return errors.Wrapf(ctx, err, "fail to get list of running containers") |
| 62 | } |
| 63 | debug.Println("get container list", containerTypes) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | amount, err := strconv.ParseInt(typeAmount, 10, 32) |
| 68 | if err != nil { |
| 69 | return errors.Newf(ctx, "%s in %s should be an integer", typeAmount, t) |
| 70 | } |
| 71 | |
| 72 | for _, a := range autoscalers { |
| 73 | if a.ContainerType == typeName { |
| 74 | typesWithAutoscaler = append(typesWithAutoscaler, typeName) |
| 75 | break |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | newContainerConfig := scalingo.ContainerType{Name: typeName, Size: size} |
| 80 | if modificator != 0 { |
no test coverage detected