Beispiel #1
0
func createClusterPlans(controller *cluster.ClusterControler, projectDir string) []*plan.ClusterUpdatePlan {

	clusters := controller.SearchClusters(projectDir)
	plans := controller.CreateClusterUpdatePlans(clusters)

	for _, plan := range plans {
		fmt.Printf("Cluster '%s'\n", plan.Name)

		fmt.Println(color.Cyan(fmt.Sprintf("\t[Add] num = %d", len(plan.NewServices))))
		for _, add := range plan.NewServices {
			fmt.Println(color.Cyan(fmt.Sprintf("\t\t (+) %s", add.Name)))
		}

		fmt.Println(color.Green(fmt.Sprintf("\t[Update] num = %d", len(plan.UpdateServices))))
		for _, update := range plan.UpdateServices {
			fmt.Println(color.Green(fmt.Sprintf("\t\t (+) %s(%s)", *update.Before.ServiceName, *update.Before.ClusterARN)))
		}

		fmt.Println(color.Red(fmt.Sprintf("\t[Remove] num = %d", len(plan.DeleteServices))))
		for _, delete := range plan.DeleteServices {
			fmt.Println(color.Red(fmt.Sprintf("\t\t (-) %s(%s)", *delete.ServiceName, *delete.ClusterARN)))
		}
		fmt.Println()
	}

	return plans
}
Beispiel #2
0
func (self *ServiceController) RoundColorStatus(status string) *color.Escape {

	if status == "RUNNING" {
		return color.Green(status)
	} else if status == "PENDING" {
		return color.Yellow(status)
	} else if status == "STOPPED" {
		return color.Red(status)
	} else {
		return color.Magenta(status)
	}
}
Beispiel #3
0
func (self *BlueGreenController) ApplyBlueGreenDeploy(bgplan *plan.BlueGreenPlan, nodeploy bool) error {

	apias := self.Ecs.AutoscalingApi()

	targetGreen := bgplan.IsBlueWithPrimaryElb()

	var currentLabel *color.Escape
	var nextLabel *color.Escape
	var current *plan.ServiceSet
	var next *plan.ServiceSet
	primaryLb := bgplan.PrimaryElb
	standbyLb := bgplan.StandbyElb
	if targetGreen {
		current = bgplan.Blue
		next = bgplan.Green
		currentLabel = color.Cyan("blue")
		nextLabel = color.Green("green")
	} else {
		current = bgplan.Green
		next = bgplan.Blue
		currentLabel = color.Green("green")
		nextLabel = color.Cyan("blue")
	}

	logger.Main.Infof("Current status is '%s'", currentLabel)
	logger.Main.Infof("Start Blue-Green Deployment: %s to %s ...", currentLabel, nextLabel)
	if nodeploy {
		logger.Main.Infof("Without deployment. It only replaces load balancers.")
	} else {
		// deploy service
		logger.Main.Infof("Updating %s@%s service at %s ...", next.NewService.Service, next.NewService.Cluster, nextLabel)
		if err := self.ClusterController.ApplyServicePlan(next.ClusterUpdatePlan); err != nil {
			return err
		}
	}

	// attach next group to primary lb
	_, erratt := apias.AttachLoadBalancers(*next.AutoScalingGroup.AutoScalingGroupName, []string{
		primaryLb,
	})
	if erratt != nil {
		return erratt
	}
	logger.Main.Infof("Attached to attach %s group to %s(primary).", nextLabel, primaryLb)

	errwlb := self.waitLoadBalancer(*next.AutoScalingGroup.AutoScalingGroupName, primaryLb)
	if errwlb != nil {
		return errwlb
	}
	logger.Main.Infof("Added %s group to primary", nextLabel)

	// detach current group from primary lb
	_, errelbb := apias.DetachLoadBalancers(*current.AutoScalingGroup.AutoScalingGroupName, []string{
		primaryLb,
	})
	if errelbb != nil {
		return errelbb
	}
	logger.Main.Infof("Detached %s group from %s(primary).", currentLabel, primaryLb)

	// detach next group from standby lb
	_, errelbg := apias.DetachLoadBalancers(*next.AutoScalingGroup.AutoScalingGroupName, []string{
		standbyLb,
	})
	if errelbg != nil {
		return errelbg
	}
	logger.Main.Infof("Detached %s group from %s(standby).", nextLabel, standbyLb)

	// attach current group to standby lb
	_, errelba := apias.AttachLoadBalancers(*current.AutoScalingGroup.AutoScalingGroupName, []string{
		standbyLb,
	})
	if errelba != nil {
		return errelba
	}
	logger.Main.Infof("Attached %s group to %s(standby).", currentLabel, standbyLb)

	return nil
}
Beispiel #4
0
func PrintlnGreen(a ...interface{}) (int, error) {
	return Println(color.Green(fmt.Sprint(a...)))
}