示例#1
0
func doCluster(c *cli.Context) {

	ecsManager, err := buildECSManager()

	if err != nil {
		fmt.Fprintf(os.Stderr, "[ERROR]%s\n", color.Red(err.Error()))
		os.Exit(1)
	}

	operation, errSubCommand := createOperation(c.Args())

	if errSubCommand != nil {
		fmt.Fprintf(os.Stderr, "[ERROR]%s\n", color.Red(errSubCommand.Error()))
		os.Exit(1)
	}

	projectDir, err := os.Getwd()
	if err != nil {
		panic(err)
	}

	clusterController := cluster.ClusterControler{
		Ecs:            ecsManager,
		TargetResource: operation.TargetResource,
	}

	plans := createClusterPlans(&clusterController, projectDir)

	if operation.SubCommand == "apply" {
		clusterController.ApplyClusterPlans(plans)
	}
}
示例#2
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
}