-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration.go
59 lines (53 loc) · 1.44 KB
/
migration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package api
import (
"github.com/in4it/ecs-deploy/provider/ecs"
"github.com/in4it/ecs-deploy/service"
"github.com/juju/loggo"
"strconv"
"strings"
"time"
)
// logging
var migrationLogger = loggo.GetLogger("migration")
// Migration struct
type Migration struct {
}
func (m *Migration) run(apiVersion string) error {
var runningMajor, runningMinor int
v := strings.Split(apiVersion, ".")
if len(v) > 1 {
runningMajor, _ = strconv.Atoi(v[0])
runningMinor, _ = strconv.Atoi(v[1])
} else {
runningMajor = 1
runningMinor = 0
}
if runningMajor == 1 && runningMinor < 2 {
migrationLogger.Infof("Starting migration from %v to %v", apiVersion, m.getApiVersion())
var dss service.DynamoServices
s := service.NewService()
e := ecs.ECS{}
err := s.GetServices(&dss)
if err != nil {
return err
}
for _, ds := range dss.Services {
// doing one per half second not to overload db
s.ClusterName = ds.C
s.ServiceName = ds.S
d, err := s.GetLastDeploy()
if err != nil {
return err
}
cpuReservation, cpuLimit, memoryReservation, memoryLimit := e.GetContainerLimits(*d.DeployData)
s.UpdateServiceLimits(s.ClusterName, s.ServiceName, cpuReservation, cpuLimit, memoryReservation, memoryLimit)
time.Sleep(500 * time.Millisecond)
}
s.SetApiVersion(m.getApiVersion())
migrationLogger.Infof("Updated API version to %v", m.getApiVersion())
}
return nil
}
func (m *Migration) getApiVersion() string {
return apiVersion
}