Exemple #1
0
func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
	var context *cli.Context

	a := cli.NewApp()
	a.Commands = []cli.Command{
		{
			Name: "foo",
			Action: func(c *cli.Context) {
				context = c
			},
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "lang",
					Value: "english",
					Usage: "language for the greeting",
				},
			},
			Before: func(_ *cli.Context) error { return nil },
		},
	}
	a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})

	expect(t, context.Args().Get(0), "abcd")
	expect(t, context.String("lang"), "spanish")
}
Exemple #2
0
func manage(c *cli.Context) {
	etcdAddress := c.String("etcdserver")
	man, err := manager.New(etcdAddress)
	if err != nil {
		log.WithField("err", err).Fatalln("Cannot start manager")
	}
	man.Run()
}
Exemple #3
0
func create(c *cli.Context) {
	var clusterName string
	if !c.Args().Present() {
		log.Fatalln("Error: missing cluster name")
	} else {
		clusterName = c.Args().First()
	}
	// Get etcd address
	etcdAddress := c.String("etcdserver")

	// Initialize etcd client
	discovery.New("etcd", etcdAddress)

	// Generate cluster
	id, err := utils.GenerateUUID()
	if err != nil {
		log.WithField("err", err).Fatalln("Error generating cluster UUID")
	}
	cluster.RegisterCluster(clusterName, id)
	// Print cluster UUID for join
	fmt.Println(clusterName + ":" + id)
}
Exemple #4
0
func join(c *cli.Context) {
	var clusterName string

	if !c.Args().Present() {
		log.Fatalln("Error: missing cluster name")
	} else {
		clusterName = c.Args().First()
	}
	ipAddress := c.String("address")
	port := c.String("port")
	etcdAddress := c.String("etcdserver")
	nodeName := c.String("name")

	// infrastructure
	initializeNetwork(ipAddress, port)
	initializeDiscovery("etcd", etcdAddress)
	// Configuration
	initializeAgent(clusterName)
	initializeServices(clusterName)
	initializePolicy(clusterName)
	initializeAnalytics(clusterName)
	// Core agent services
	initializeStorage()
	initializeMetricSerivice()
	initializeContainerEngine()
	// Resources
	initializeResources()
	initializeNode(nodeName, clusterName)
	// Join Cluster
	registerToCluster(clusterName)
	agent.StartMonitoring()
	defer api.StartServer(port)

	fmt.Printf("Joined cluster %s.\nWaiting for commands...\n", clusterName)
}