Skip to content

Commit

Permalink
Merge pull request #73 from stormcat24/feature/0.2.0-RC4
Browse files Browse the repository at this point in the history
Improved performance of applying service
  • Loading branch information
Akinori Yamada committed Mar 30, 2016
2 parents 8f434fc + 30f1d6d commit 029de2b
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 42 deletions.
18 changes: 14 additions & 4 deletions bluegreen/bluegreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,27 @@ type BlueGreenController struct {
manager *aws.AwsManager
ClusterController *service.ServiceController
blueGreenMap map[string]*BlueGreen
TargetResource string
targetResource string
params map[string]string
}

func NewBlueGreenController(manager *aws.AwsManager, projectDir string, targetResource string, params map[string]string) (*BlueGreenController, error) {

ccon, err := service.NewServiceController(manager, projectDir, "", params)
targetResources := make([]string, 0)
if targetResource != "" {
targetResources = append(targetResources, fmt.Sprintf("%s-blue", targetResource))
targetResources = append(targetResources, fmt.Sprintf("%s-green", targetResource))
}

ccon, err := service.NewServiceController(manager, projectDir, targetResources, params)
if err != nil {
return nil, err
}

con := &BlueGreenController{
manager: manager,
ClusterController: ccon,
TargetResource: targetResource,
targetResource: targetResource,
params: params,
}

Expand All @@ -60,6 +66,10 @@ func (self *BlueGreenController) searchBlueGreen(projectDir string) (map[string]
return nil
}

if self.targetResource != "" && !strings.HasSuffix(path, fmt.Sprintf("%s.yml", self.targetResource)) {
return nil
}

content, err := ioutil.ReadFile(path)
if err != nil {
return err
Expand Down Expand Up @@ -101,7 +111,7 @@ func (self *BlueGreenController) CreateBlueGreenPlans(bgmap map[string]*BlueGree

for name, bg := range bgmap {

if len(self.TargetResource) == 0 || self.TargetResource == name {
if len(self.targetResource) == 0 || self.targetResource == name {

bgplan, err := self.CreateBlueGreenPlan(bg, cplans)
if err != nil {
Expand Down
35 changes: 19 additions & 16 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import:
- package: gopkg.in/yaml.v2
version: 7ad95dd0798a40da1ccdff6dff35fd177b5edf40
- package: github.com/aws/aws-sdk-go
ref: v1.0.7
ref: v1.1.15
subpackages:
- aws
- private/endpoints
Expand Down
1 change: 1 addition & 0 deletions operation/bluegreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func createBlueGreenPlans(controller *bluegreen.BlueGreenController, jsonOutput
StandbyElb: bgplan.StandbyElb,
Active: active,
})

}

if jsonOutput {
Expand Down
2 changes: 1 addition & 1 deletion operation/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func doService(c *cli.Context) {
}

jsonOutput := c.Bool("json-output")
clusterController, err := service.NewServiceController(awsManager, projectDir, operation.TargetResource, operation.Params)
clusterController, err := service.NewServiceController(awsManager, projectDir, []string{operation.TargetResource}, operation.Params)
if err != nil {
logger.Main.Error(color.Red(err.Error()))
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion operation/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package operation

const Version string = "0.2.0-RC3"
const Version string = "0.2.0-RC4"
49 changes: 30 additions & 19 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ const (
)

type ServiceController struct {
manager *aws.AwsManager
TargetResource string
clusters []Cluster
params map[string]string
manager *aws.AwsManager
targetResources []string
clusters []Cluster
params map[string]string
}

func NewServiceController(manager *aws.AwsManager, projectDir string, targetResource string, params map[string]string) (*ServiceController, error) {
func NewServiceController(manager *aws.AwsManager, projectDir string, targetResources []string, params map[string]string) (*ServiceController, error) {

con := &ServiceController{
manager: manager,
params: params,
manager: manager,
params: params,
targetResources: targetResources,
}

clusters, err := con.searchServices(projectDir)
Expand All @@ -45,10 +46,6 @@ func NewServiceController(manager *aws.AwsManager, projectDir string, targetReso

con.clusters = clusters

if targetResource != "" {
con.TargetResource = targetResource
}

return con, nil
}

Expand All @@ -64,6 +61,20 @@ func (self *ServiceController) searchServices(projectDir string) ([]Cluster, err
return nil
}

if len(self.targetResources) > 0 {

flg := false
for _, res := range self.targetResources {
if strings.HasSuffix(path, fmt.Sprintf("%s.yml", res)) {
flg = true
}
}

if !flg {
return nil
}
}

content, err := ioutil.ReadFile(path)
if err != nil {
return err
Expand Down Expand Up @@ -100,15 +111,13 @@ func (self *ServiceController) CreateServiceUpdatePlans() ([]*ServiceUpdatePlan,
plans := []*ServiceUpdatePlan{}

for _, cluster := range self.GetClusters() {
if len(self.TargetResource) == 0 || self.TargetResource == cluster.Name {
cp, err := self.CreateServiceUpdatePlan(cluster)
if err != nil {
return plans, err
}
cp, err := self.CreateServiceUpdatePlan(cluster)
if err != nil {
return plans, err
}

if cp != nil {
plans = append(plans, cp)
}
if cp != nil {
plans = append(plans, cp)
}
}
return plans, nil
Expand All @@ -125,6 +134,8 @@ func (self *ServiceController) CreateServiceUpdatePlan(cluster Cluster) (*Servic

if len(output.Failures) > 0 {
return nil, errors.New(fmt.Sprintf("Cluster '%s' not found", cluster.Name))
} else {
logger.Main.Infof("Cluster '%v' is found.", cluster.Name)
}

rlci, errlci := api.ListContainerInstances(cluster.Name)
Expand Down

0 comments on commit 029de2b

Please sign in to comment.