mirror of
https://github.com/spaytac/orbiter.git
synced 2026-01-22 03:24:52 +00:00
Add new API call to get all the autoscalers currently managed by orbiter: ``` curl http://localhost:8000/autoscaler ``` Add command into the CLI to get this list ``` export ORBITER_HOST=http://localhost:8000 orbiter autoscler ls ``` Add command into the CLI to print all the events fired by the daemon: ``` export ORBITER_HOST=http://localhost:8000 orbiter system events ```
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package autoscaler
|
|
|
|
import "github.com/Sirupsen/logrus"
|
|
|
|
type Provider interface {
|
|
Scale(string, int, bool) error
|
|
Name() string
|
|
}
|
|
|
|
type Autoscalers map[string]Autoscaler
|
|
|
|
type Autoscaler struct {
|
|
provider Provider
|
|
serviceId string
|
|
targetUp int
|
|
targetDown int
|
|
}
|
|
|
|
func NewAutoscaler(p Provider, serviceId string, targetUp int, targetDown int) Autoscaler {
|
|
a := Autoscaler{
|
|
provider: p,
|
|
serviceId: serviceId,
|
|
targetUp: targetUp,
|
|
targetDown: targetDown,
|
|
}
|
|
return a
|
|
}
|
|
|
|
func (a *Autoscaler) ScaleUp() error {
|
|
logrus.WithFields(logrus.Fields{
|
|
"service": a.serviceId,
|
|
"direction": true,
|
|
}).Infof("Received a new request to scale up %s with %d task.", a.serviceId, a.targetUp)
|
|
|
|
err := a.provider.Scale(a.serviceId, a.targetUp, true)
|
|
|
|
if err != nil {
|
|
logrus.WithFields(logrus.Fields{
|
|
"service": a.serviceId,
|
|
"direction": true,
|
|
"error": err.Error(),
|
|
}).Warnf("We had some problems to scale up %s.", a.serviceId)
|
|
} else {
|
|
logrus.WithFields(logrus.Fields{
|
|
"service": a.serviceId,
|
|
"direction": true,
|
|
}).Infof("Service %s scaled up.", a.serviceId)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (a *Autoscaler) ScaleDown() error {
|
|
logrus.WithFields(logrus.Fields{
|
|
"service": a.serviceId,
|
|
"direction": false,
|
|
}).Infof("Received a new request to scale down %s with %d task.", a.serviceId, a.targetDown)
|
|
|
|
err := a.provider.Scale(a.serviceId, a.targetDown, false)
|
|
|
|
if err != nil {
|
|
logrus.WithFields(logrus.Fields{
|
|
"service": a.serviceId,
|
|
"direction": false,
|
|
"error": err.Error(),
|
|
}).Warnf("We had some problems to scale down %s.", a.serviceId)
|
|
} else {
|
|
logrus.WithFields(logrus.Fields{
|
|
"service": a.serviceId,
|
|
"direction": false,
|
|
}).Infof("Service %s scaled down.", a.serviceId)
|
|
}
|
|
return err
|
|
}
|