Ejemplo n.º 1
0
func (m *Manager) deploy() {
	if !m.isClusterSet() {
		return
	}

	var err error
	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 1, '\t', 0)
	fmt.Fprintf(w, "NODE\tSERVICE\tSTATUS\n")

	services := cluster.ListServices(m.Cluster)
	servicesNames := make([]string, 0, len(services))
	for name, _ := range services {
		servicesNames = append(servicesNames, name)
	}

	nodes := cluster.ListNodes(m.Cluster, false)
	nodesNames := make([]string, 0, len(nodes))
	for name, _ := range nodes {
		nodesNames = append(nodesNames, name)
	}

	if len(nodes) < len(services) {
		fmt.Println("Cannot deploy: not enough nodes")
		return
	}

	for i := 0; i < len(services); i++ {
		service := servicesNames[i]
		node := nodesNames[i]
		address := nodes[node]
		status := "done"

		err = network.SendUpdateCommand(address, "node-base-services", []string{service})
		if err != nil {
			fmt.Println("Error sending update command to ", address)
			status = "error"

		} else {
			err = network.SendStartServiceCommand(address, service)
			if err != nil {
				fmt.Println("Error sending start service command to node ", node)
				status = "error"
			}
		}

		fmt.Fprintf(w, "%s\t%s\t%s\n",
			node,
			service,
			status,
		)

	}

	w.Flush()
}
Ejemplo n.º 2
0
func (m *Manager) startService(what string, where []string) {
	var err error
	nodes := cluster.ListNodes(m.Cluster, false)
	if where[0] == "all" {
		for name, addr := range nodes {
			err = network.SendStartServiceCommand(addr, what)
			if err != nil {
				fmt.Println("Error sending start service command to node ", name)
			}
		}
	} else {
		for _, node := range where {
			if addr, ok := nodes[node]; ok {
				err = network.SendStartServiceCommand(addr, what)
				if err != nil {
					fmt.Println("Error sending start service command to node ", node)
				}
			} else {
				fmt.Println("Cannot get address of node ", node)
			}
		}
	}
}