Skip to content

Commit

Permalink
Merge pull request #35 from stormcat24/feature/keep_desired_count
Browse files Browse the repository at this point in the history
Add option of keep desired_count at updating service
  • Loading branch information
Akinori Yamada committed Sep 28, 2015
2 parents a1f1b85 + 2c42045 commit b088788
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions operation/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
28 changes: 13 additions & 15 deletions service/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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) {
Expand All @@ -59,4 +57,4 @@ func CreateServiceMap(data []byte) (map[string]Service, error) {
}

return servicesMap, err
}
}
17 changes: 16 additions & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b088788

Please sign in to comment.