Пример #1
0
func (self *ServiceController) checkRunningTask(dto *ecs.DescribeTasksOutput) TaskWatchStatus {

	logger.Main.Info("Current task conditions as follows:")

	status := []string{}
	for _, task := range dto.Tasks {
		util.Println(fmt.Sprintf("    %s:", *task.TaskARN))
		util.Println(fmt.Sprintf("        LastStatus:%s", self.RoundColorStatus(*task.LastStatus)))
		util.Println("        Containers:")

		for _, con := range task.Containers {
			util.Println(fmt.Sprintf("            ----------[%s]----------", *con.Name))
			util.Println(fmt.Sprintf("            ContainerARN:%s", *con.ContainerARN))
			util.Println(fmt.Sprintf("            Status:%s", self.RoundColorStatus(*con.LastStatus)))
			util.Println()
		}

		status = append(status, *task.LastStatus)
	}

	// if RUNNING at least one, ecs-formation deals with ok.
	for _, s := range status {
		if s == "RUNNING" {
			return WatchFinish
		} else if s == "STOPPED" {
			return WatchTerminate
		}
	}

	return WatchContinue
}
Пример #2
0
func createTaskPlans(controller *task.TaskDefinitionController, projectDir string) []*plan.TaskUpdatePlan {

	taskDefs := controller.GetTaskDefinitionMap()
	plans := controller.CreateTaskUpdatePlans(taskDefs)

	for _, plan := range plans {
		logger.Main.Infof("Task Definition '%s'", plan.Name)

		for _, add := range plan.NewContainers {
			util.PrintlnCyan(fmt.Sprintf("    (+) %s", add.Name))
			util.PrintlnCyan(fmt.Sprintf("      image: %s", add.Image))
			util.PrintlnCyan(fmt.Sprintf("      ports: %s", add.Ports))
			util.PrintlnCyan(fmt.Sprintf("      environment:\n%s", util.StringValueWithIndent(add.Environment, 4)))
			util.PrintlnCyan(fmt.Sprintf("      links: %s", add.Links))
			util.PrintlnCyan(fmt.Sprintf("      volumes: %s", add.Volumes))
		}

		util.Println()
	}

	return plans
}
Пример #3
0
func createBlueGreenPlans(controller *bluegreen.BlueGreenController, jsonOutput bool) ([]*plan.BlueGreenPlan, error) {

	if jsonOutput {
		util.Output = false
		defer func() {
			util.Output = true
		}()
	}

	bgmap := controller.GetBlueGreenMap()

	cplans, errcp := controller.ClusterController.CreateServiceUpdatePlans()
	if errcp != nil {
		return []*plan.BlueGreenPlan{}, errcp
	}

	bgplans, errbgp := controller.CreateBlueGreenPlans(bgmap, cplans)
	if errbgp != nil {
		return bgplans, errbgp
	}

	jsonItems := []BlueGreenPlanJson{}
	for _, bgplan := range bgplans {
		util.PrintlnCyan("    Blue:")
		util.PrintlnCyan(fmt.Sprintf("        Cluster = %s", bgplan.Blue.NewService.Cluster))
		util.PrintlnCyan(fmt.Sprintf("        AutoScalingGroupARN = %s", *bgplan.Blue.AutoScalingGroup.AutoScalingGroupARN))
		util.PrintlnCyan("        Current services as follows:")
		for _, bcs := range bgplan.Blue.ClusterUpdatePlan.CurrentServices {
			util.PrintlnCyan(fmt.Sprintf("            %s:", *bcs.ServiceName))
			util.PrintlnCyan(fmt.Sprintf("                ServiceARN = %s", *bcs.ServiceARN))
			util.PrintlnCyan(fmt.Sprintf("                TaskDefinition = %s", *bcs.TaskDefinition))
			util.PrintlnCyan(fmt.Sprintf("                DesiredCount = %d", *bcs.DesiredCount))
			util.PrintlnCyan(fmt.Sprintf("                PendingCount = %d", *bcs.PendingCount))
			util.PrintlnCyan(fmt.Sprintf("                RunningCount = %d", *bcs.RunningCount))
		}

		var active string
		if bgplan.IsBlueWithPrimaryElb() {
			active = "blue"
		} else {
			active = "green"
		}

		util.PrintlnGreen("    Green:")
		util.PrintlnGreen(fmt.Sprintf("        Cluster = %s", bgplan.Green.NewService.Cluster))
		util.PrintlnGreen(fmt.Sprintf("        AutoScalingGroupARN = %s", *bgplan.Green.AutoScalingGroup.AutoScalingGroupARN))
		util.PrintlnGreen("        Current services as follows:")
		for _, gcs := range bgplan.Green.ClusterUpdatePlan.CurrentServices {
			util.PrintlnGreen(fmt.Sprintf("            %s:", *gcs.ServiceName))
			util.PrintlnGreen(fmt.Sprintf("                ServiceARN = %s", *gcs.ServiceARN))
			util.PrintlnGreen(fmt.Sprintf("                TaskDefinition = %s", *gcs.TaskDefinition))
			util.PrintlnGreen(fmt.Sprintf("                DesiredCount = %d", *gcs.DesiredCount))
			util.PrintlnGreen(fmt.Sprintf("                PendingCount = %d", *gcs.PendingCount))
			util.PrintlnGreen(fmt.Sprintf("                RunningCount = %d", *gcs.RunningCount))
		}

		util.Println()

		jsonItems = append(jsonItems, BlueGreenPlanJson{

			Blue: BlueGreenServiceJson{
				ClusterARN:          *bgplan.Blue.CurrentService.ClusterARN,
				AutoScalingGroupARN: *bgplan.Blue.AutoScalingGroup.AutoScalingGroupARN,
				Instances:           bgplan.Blue.AutoScalingGroup.Instances,
				TaskDefinition:      *bgplan.Blue.CurrentService.TaskDefinition,
				DesiredCount:        *bgplan.Blue.CurrentService.DesiredCount,
				PendingCount:        *bgplan.Blue.CurrentService.PendingCount,
				RunningCount:        *bgplan.Blue.CurrentService.RunningCount,
			},
			Green: BlueGreenServiceJson{
				ClusterARN:          *bgplan.Green.CurrentService.ClusterARN,
				AutoScalingGroupARN: *bgplan.Green.AutoScalingGroup.AutoScalingGroupARN,
				Instances:           bgplan.Green.AutoScalingGroup.Instances,
				TaskDefinition:      *bgplan.Green.CurrentService.TaskDefinition,
				DesiredCount:        *bgplan.Green.CurrentService.DesiredCount,
				PendingCount:        *bgplan.Green.CurrentService.PendingCount,
				RunningCount:        *bgplan.Green.CurrentService.RunningCount,
			},
			PrimaryElb: bgplan.PrimaryElb,
			StandbyElb: bgplan.StandbyElb,
			Active:     active,
		})
	}

	if jsonOutput {
		bt, err := json.Marshal(&jsonItems)
		if err != nil {
			return bgplans, err
		}
		fmt.Println(string(bt))
	}

	return bgplans, nil
}
Пример #4
0
func createClusterPlans(controller *service.ServiceController, projectDir string, jsonOutput bool) ([]*plan.ServiceUpdatePlan, error) {

	if jsonOutput {
		util.Output = false
		defer func() {
			util.Output = true
		}()
	}

	util.Infoln("Checking services on clusters...")
	plans, err := controller.CreateServiceUpdatePlans()

	if err != nil {
		return []*plan.ServiceUpdatePlan{}, err
	}

	for _, plan := range plans {

		util.PrintlnYellow(fmt.Sprintf("Current status of ECS Cluster '%s':", plan.Name))
		if len(plan.InstanceARNs) > 0 {
			util.PrintlnYellow("    Container Instances as follows:")
			for _, instance := range plan.InstanceARNs {
				util.PrintlnYellow(fmt.Sprintf("        %s", *instance))
			}
		}

		util.PrintlnYellow("    Services as follows:")
		if len(plan.CurrentServices) == 0 {
			util.PrintlnYellow("         No services are deployed.")
		}

		for _, cs := range plan.CurrentServices {
			util.PrintlnYellow(fmt.Sprintf("        ServiceName = %s", *cs.ServiceName))
			util.PrintlnYellow(fmt.Sprintf("        ServiceARN = %s", *cs.ServiceARN))
			util.PrintlnYellow(fmt.Sprintf("        TaskDefinition = %s", *cs.TaskDefinition))
			util.PrintlnYellow(fmt.Sprintf("        DesiredCount = %d", *cs.DesiredCount))
			util.PrintlnYellow(fmt.Sprintf("        PendingCount = %d", *cs.PendingCount))
			util.PrintlnYellow(fmt.Sprintf("        RunningCount = %d", *cs.RunningCount))
			for _, lb := range cs.LoadBalancers {
				util.PrintlnYellow(fmt.Sprintf("        ELB = %s:", *lb.LoadBalancerName))
				util.PrintlnYellow(fmt.Sprintf("            ContainerName = %s", *lb.ContainerName))
				util.PrintlnYellow(fmt.Sprintf("            ContainerName = %d", *lb.ContainerPort))
			}
			util.PrintlnYellow(fmt.Sprintf("        STATUS = %s", *cs.Status))
		}

		util.Println()
		util.PrintlnYellow(fmt.Sprintf("Service update plan '%s':", plan.Name))

		util.PrintlnYellow("    Services:")
		for _, add := range plan.NewServices {
			util.PrintlnYellow(fmt.Sprintf("        ----------[%s]----------", add.Name))
			util.PrintlnYellow(fmt.Sprintf("        TaskDefinition = %s", add.TaskDefinition))
			util.PrintlnYellow(fmt.Sprintf("        DesiredCount = %d", add.DesiredCount))
			for _, lb := range add.LoadBalancers {
				util.PrintlnYellow(fmt.Sprintf("        ELB:%s", lb.Name))
			}
			util.Println()
		}

		util.Println()
	}

	if jsonOutput {
		bt, err := json.Marshal(&plans)
		if err != nil {
			return plans, err
		}
		fmt.Println(string(bt))
	}

	return plans, nil
}