From 939261adc953445a1162e86342687b905bf056d6 Mon Sep 17 00:00:00 2001 From: stormcat24 Date: Mon, 28 Sep 2015 11:40:30 +0900 Subject: [PATCH 1/3] add keep_desired_count --- operation/service.go | 1 + service/schema.go | 28 +++++++++++++--------------- service/service.go | 17 ++++++++++++++++- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/operation/service.go b/operation/service.go index 7060859..8635124 100644 --- a/operation/service.go +++ b/operation/service.go @@ -120,6 +120,7 @@ func createClusterPlans(controller *service.ServiceController, projectDir string util.PrintlnYellow(fmt.Sprintf(" ----------[%s]----------", add.Name)) util.PrintlnYellow(fmt.Sprintf(" TaskDefinition = %s", add.TaskDefinition)) util.PrintlnYellow(fmt.Sprintf(" DesiredCount = %d", add.DesiredCount)) + util.PrintlnYellow(fmt.Sprintf(" KeepDesiredCount = %t", add.KeepDesiredCount)) for _, lb := range add.LoadBalancers { util.PrintlnYellow(fmt.Sprintf(" ELB:%s", lb.Name)) } diff --git a/service/schema.go b/service/schema.go index b52e099..3ff4f17 100644 --- a/service/schema.go +++ b/service/schema.go @@ -5,25 +5,24 @@ import ( ) type Cluster struct { - - Name string - Services map[string]Service + Name string + Services map[string]Service } type Service struct { - - Name string - TaskDefinition string `yaml:"task_definition"` - DesiredCount int64 `yaml:"desired_count"` - LoadBalancers []LoadBalancer `yaml:"load_balancers"` - Role string `yaml:"role"` + Name string + TaskDefinition string `yaml:"task_definition"` + DesiredCount int64 `yaml:"desired_count"` + KeepDesiredCount bool `yaml:"keep_desired_count"` + LoadBalancers []LoadBalancer `yaml:"load_balancers"` + Role string `yaml:"role"` } func (self *Service) FindLoadBalancerByContainer(conname string, port int64) *LoadBalancer { for _, lb := range self.LoadBalancers { if lb.ContainerName == conname && - lb.ContainerPort == port { + lb.ContainerPort == port { return &lb } } @@ -42,10 +41,9 @@ func (self *Service) FindLoadBalancerByName(name string) *LoadBalancer { } type LoadBalancer struct { - - Name string `yaml:"name"` - ContainerName string `yaml:"container_name"` - ContainerPort int64 `yaml:"container_port"` + Name string `yaml:"name"` + ContainerName string `yaml:"container_name"` + ContainerPort int64 `yaml:"container_port"` } func CreateServiceMap(data []byte) (map[string]Service, error) { @@ -59,4 +57,4 @@ func CreateServiceMap(data []byte) (map[string]Service, error) { } return servicesMap, err -} \ No newline at end of file +} diff --git a/service/service.go b/service/service.go index dc0f69c..6f8bbf3 100644 --- a/service/service.go +++ b/service/service.go @@ -181,7 +181,10 @@ func (self *ServiceController) ApplyServicePlan(plan *ServiceUpdatePlan) error { api := self.manager.EcsApi() + currentSizeMap := make(map[string]int64, 0) + for _, current := range plan.CurrentServices { + currentSizeMap[*current.ServiceName] = *current.DesiredCount // set desired_count = 0 if _, err := api.UpdateService(plan.Name, *current.ServiceName, 0, *current.TaskDefinition); err != nil { @@ -210,7 +213,19 @@ func (self *ServiceController) ApplyServicePlan(plan *ServiceUpdatePlan) error { for _, add := range plan.NewServices { - result, err := api.CreateService(plan.Name, add.Name, add.DesiredCount, toLoadBalancers(&add.LoadBalancers), add.TaskDefinition, add.Role) + var nextDesiredCount int64 + if add.KeepDesiredCount { + if dc, ok := currentSizeMap[add.Name]; ok { + nextDesiredCount = dc + logger.Main.Infof("Keep DesiredCount %d at '%s'", *add.Name, nextDesiredCount) + } else { + nextDesiredCount = add.DesiredCount + } + } else { + nextDesiredCount = add.DesiredCount + } + + result, err := api.CreateService(plan.Name, add.Name, nextDesiredCount, toLoadBalancers(&add.LoadBalancers), add.TaskDefinition, add.Role) if err != nil { return err } From 755e2a8452f542251e6fd6fb6315e15275102666 Mon Sep 17 00:00:00 2001 From: stormcat24 Date: Mon, 28 Sep 2015 11:54:55 +0900 Subject: [PATCH 2/3] add document --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index bfd0564..6abfc5a 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,21 @@ test-service: container_port: 80 ``` +#### Keep desired_count at updating service + +If you modify value of `desired_count` by AWS Management Console or aws-cli, you'll fear override value of `desired_count` by ecs-formation. This value should be flexibly changed in the operation. + +If `keep_desired_count` is `true`, keep current `desired_count` at updating service. + +```bash +(path-to-path/test-ecs-formation/service) $ vim test-cluster.yml +test-service: + task_definition: test-definition + desired_count: 1 + keep_desired_count: true +``` + + #### Manage Task Definitions Show update plan. From 2c42045f14e7759d14b71488ea82f2419d57dd35 Mon Sep 17 00:00:00 2001 From: stormcat24 Date: Mon, 28 Sep 2015 11:58:52 +0900 Subject: [PATCH 3/3] fixed build --- service/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/service.go b/service/service.go index 6f8bbf3..a5db770 100644 --- a/service/service.go +++ b/service/service.go @@ -217,7 +217,7 @@ func (self *ServiceController) ApplyServicePlan(plan *ServiceUpdatePlan) error { if add.KeepDesiredCount { if dc, ok := currentSizeMap[add.Name]; ok { nextDesiredCount = dc - logger.Main.Infof("Keep DesiredCount %d at '%s'", *add.Name, nextDesiredCount) + logger.Main.Infof("Keep DesiredCount %d at '%s'", add.Name, nextDesiredCount) } else { nextDesiredCount = add.DesiredCount }