Example #1
0
func (m *Manager) update(cmd string) {
	args := strings.Split(strings.TrimSuffix(strings.TrimSpace(cmd), ";"), " ")
	if len(args) < 2 {
		fmt.Println("not enough arguments to 'update' command")
		return
	}

	if !m.isClusterSet() {
		return
	}

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

	nodes := cluster.ListNodes(m.Cluster, false)
	for node, address := range nodes {
		status := "done"
		err = network.SendUpdateCommand(address, args[1], m.Cluster)
		if err != nil {
			fmt.Println("Error sending update command to node ", node)
			status = "error"
		}

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

	w.Flush()
}
Example #2
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()
}
Example #3
0
func setService(clusterName string, who string, what string, to_what []string) {
	nodes := cluster.ListNodes(clusterName, false)
	names := []string{}
	for name, _ := range cluster.ListServices(clusterName) {
		names = append(names, name)
	}

	ok, _ := checkValidServices([]string{who}, names)
	if !ok {
		fmt.Println("Unrecognized service ", who)
		return
	}
	service := cluster.GetService(clusterName, who)
	switch what {
	case "TODO":
		cluster.UpdateService(clusterName, who, service)
		for _, address := range nodes {
			network.SendUpdateCommand(address, "TODO", who)
		}
	default:
		fmt.Println("Unrecognized parameter ", what)
	}
}
Example #4
0
func (m *Manager) undeploy() {
	if !m.isClusterSet() {
		return
	}

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

	services := cluster.ListServices(m.Cluster)
	nodes := cluster.ListNodes(m.Cluster, false)
	for node, address := range nodes {
		status := "done"
		err = network.SendUpdateCommand(address, "node-base-services", []string{})
		if err != nil {
			fmt.Println("Error sending update command to ", address)
			status = "error"
		}

		for service, _ := range services {
			err = network.SendStopServiceCommand(address, service)
			if err != nil {
				fmt.Println("Error sending stop service command to node ", node)
				status = "error"
			}
		}

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

	w.Flush()
}
Example #5
0
func setNode(clusterName string, who string, what string, to_what []string) {
	nodes := cluster.ListNodes(clusterName, false)
	dest := []string{}

	if who == "all" {
		for _, address := range nodes {
			dest = append(dest, address)
		}
	} else {
		if address, ok := nodes[who]; !ok {
			fmt.Println("Unrecognized node ", who)
			return
		} else {
			dest = append(dest, address)
		}
	}

	switch what {
	case "base-services":
		services := cluster.ListServices(clusterName)
		names := make([]string, 0, len(services))
		for k, _ := range services {
			names = append(names, k)
		}
		ok, notValid := checkValidServices(to_what, names)
		if !ok {
			fmt.Println("Services are not valid:")
			for _, name := range notValid {
				fmt.Println(name)
			}
			return
		}
		for _, address := range dest {
			err := network.SendUpdateCommand(address, "node-base-services", to_what)
			if err != nil {
				fmt.Println("Error sending update command to ", address)
			}
		}
	case "cpumin":
		cpumin := to_what[0]
		if ok, value := checkValidCpuValue(cpumin); ok {
			for _, address := range dest {
				err := network.SendUpdateCommand(address, "node-cpumin", value)
				if err != nil {
					fmt.Println("Error sending update command to ", address)
				}
			}
		} else {
			fmt.Println("CPU value not valid: it should be a float between 0.0 and 1.0")
		}
	case "cpumax":
		cpumax := to_what[0]
		if ok, value := checkValidCpuValue(cpumax); ok {
			for _, address := range dest {
				err := network.SendUpdateCommand(address, "node-cpumax", value)
				if err != nil {
					fmt.Println("Error sending update command to ", address)
				}
			}
		} else {
			fmt.Println("CPU value not valid: it should be a float between 0.0 and 1.0")
		}
	default:
		fmt.Println("Unrecognized parameter ", what)
	}
}