Beispiel #1
0
func main() {
	var error error
	if len(allocationList) != 0 && numNodes != 0 {
		hclient.PrintError("Cannot use node list, and number of nodes option at the same time.", errors.New("Flag contradiction"))
		os.Exit(1)
	} else if (len(allocationList) == 0 && numNodes == 0 && timeIncrease == 0 && freeAlloc == 0) || help {
		hclient.Usage()
		os.Exit(0)
	}

	if bs, error = hallocC.SetupClient("heckle"); error != nil {
		hclient.PrintError("Failed to setup client in halloc.", errors.New("Client Setup Failed"))
		os.Exit(1)
	}

	if timeIncrease != 0 {
		requestTimeIncrease()
	}

	if numNodes != 0 {
		allocationNumber = requestNumber()
		pollForStatus()
	} else if len(allocationList) != 0 {
		allocationNumber = requestList()
		pollForStatus()
	}
}
Beispiel #2
0
func freeAlloc(alloc int64) (err error) {
	bs := new(fnet.BuildServer)
	allocfree, err := cli.NewClient()
	cli.PrintError("Failed to create a new client", err)
	bs, err = allocfree.SetupClient("heckle")
	cli.PrintError("Falied to setup heckle as a client", err)

	_, err = bs.PostServer("/freeAllocation", alloc)
	if err != nil {
		return
	}

	return
}
Beispiel #3
0
func main() {
	flag.Parse()

	if help {
		cli.Usage()
		os.Exit(0)
	}

	if len(flag.Args()) <= 0 {
		cli.Usage()
		os.Exit(0)
	}

	allocations := flag.Args()
	alloc, _ := strconv.ParseInt(allocations[0], 10, 64)

	err := freeAlloc(alloc)
	if err != nil {
		cli.PrintError(fmt.Sprintf("Unable to free allocation #%d. Allocation does not exsist.", alloc), err)
		os.Exit(1)
	} else {
		fmt.Println(fmt.Sprintf("Freed allocation #%d.", alloc))
	}

}
Beispiel #4
0
func requestTimeIncrease() {
	tmpTimeMsg := int64(timeIncrease * 3600)

	_, error := bs.PostServer("/increaseTime", tmpTimeMsg)
	hclient.PrintError("Failed to post the request for time increase to heckle.", error)

	return
}
Beispiel #5
0
func requestList() (tmpAllocationNumber uint64) {
	nm := iface.Listmsg{allocationList, image, 300, 0}

	someBytes, error := bs.PostServer("/list", nm)
	hclient.PrintError("Failed to post the request for list of nodes to heckle.", error)

	if len(someBytes) == 0 {
		allocationFail("list")
	}

	error = json.Unmarshal(someBytes, &tmpAllocationNumber)
	hclient.PrintError("Failed to unmarshal allocation number from http response in request list.", error)

	fmt.Fprintf(os.Stdout, "Your allocation number is %s.\n", strconv.FormatUint(tmpAllocationNumber, 10))

	return
}
Beispiel #6
0
func requestNumber() (tmpAllocationNumber uint64) {
	nm := iface.Nummsg{numNodes, image, 300}

	someBytes, error := bs.PostServer("/number", nm)
	hclient.PrintError("Failed to post the request for number of nodes to heckle.", error)

	if len(someBytes) == 0 {
		allocationFail("number")
	}

	error = json.Unmarshal(someBytes, &tmpAllocationNumber)
	hclient.PrintError("Failed to unmarshal allocation number from http response in request number.", error)

	fmt.Fprintf(os.Stdout, "Your allocation number is %d.", tmpAllocationNumber)

	return
}
Beispiel #7
0
func commPower(nodes []string, cmd string) (outletStatus map[string]States, err error) {
	var powerCommand string
	if cmd == "status" {
		powerCommand = "/status"
	} else {
		powerCommand = "/command/" + cmd
	}

	powerServ, err := cli.NewClient()
	if err != nil {
		cli.PrintError("Unable to set up communication to power", err)
		return
	}

	client, err := powerServ.SetupClient("power")
	if err != nil {
		cli.PrintError("Unable to lookup power", err)
		return
	}

	statusRet, err := client.PostServer(powerCommand, nodes)

	if err != nil {
		cli.PrintError("Unable to post", err)
		return
	}

	switch cmd {
	case "on", "off", "reboot":
		outletStatus = nil
		break
	case "status":
		err = json.Unmarshal(statusRet, &outletStatus)
		if err != nil {
			cli.PrintError("Unable to unmarsahll status", err)
		}
		break
	}
	return

}
Beispiel #8
0
func main() {
	flag.Parse()
	if help || minutesTimeout < 1 {
		fclient.Usage()
		os.Exit(0)
	}

	comm, err := fclient.NewClient()
	if err != nil {
		fclient.PrintError("Failed to setup communcation", err)
		os.Exit(1)
	}

	secondsTimeout := minutesTimeout * 60 * 1000000000
	cancelTime := time.Now().Add(time.Duration(secondsTimeout))
	addresses := flag.Args()

	bs, err := comm.SetupClient("flunky")

	bs.DebugLog(fmt.Sprintf("Allocating hosts: %s", flag.Args()))

	if image == "" {
		fclient.PrintError("-i option is required\n", errors.New("wrong arg"))
		fclient.Usage()
		os.Exit(1)
	}

	cm := new(ctlmsg)
	cm.Image = image
	cm.Addresses = addresses
	// FIXME: need to add in extradata
	_, err = bs.PostServer("/ctl", cm)
	if err != nil {
		fclient.PrintError("Failed to allocate node", err)
		os.Exit(1)
	}

	pollForMessages(cancelTime, addresses, bs)
	fmt.Fprintf(os.Stdout, "Done allocating your nodes. Report failed builds to your system administrator.\n")
}
Beispiel #9
0
func pollForStatus() {
	start := time.Now()
	statMap := make(map[string]*iface.StatusMessage)
	pollStatus := make(map[string]string)
	for {
		time.Sleep(10000000000)

		someBytes, error := bs.PostServer("/status", allocationNumber)
		hclient.PrintError("Failed to post for status of nodes to heckle.", error)

		error = json.Unmarshal(someBytes, &statMap)
		hclient.PrintError("Failed to unmarshal status info from http response in status polling.", error)

		done := false
		for key, value := range statMap {
			pollStatus[key] = value.Status
			done = true
			for i := range value.Info {
				if len(value.Info) != 0 {
					printStatus(key, value, i)
				}
			}
			done = done && (pollStatus[key] == "Ready")
			if pollStatus[key] == "Cancel" {
				delete(pollStatus, key)
			}

		}
		//Get list of nodes for message
		if done {
			end := time.Now()
			final := end.Sub(start).String()
			fmt.Println(fmt.Sprintf("Allocation #%d complete.  The build process for allocation %d took: %s", allocationNumber, allocationNumber, final))
			os.Exit(0)
		}
	}
}
Beispiel #10
0
func init() {
	var err error
	if hstat, err = cli.NewClient(); err != nil {
		fmt.Fprintf(os.Stderr, "Failed to get new client.\n")
		os.Exit(1)
	}

	if bs, err = hstat.SetupClient("heckle"); err != nil {
		cli.PrintError("Failed to setup client in halloc.", errors.New("Client Setup Failed"))
		os.Exit(1)
	}

	flag.BoolVar(&help, "h", false, "Print usage of command.")
	flag.StringVar(&user, "u", " ", "Find user")
	flag.StringVar(&node, "n", " ", "Find nodes")
	flag.StringVar(&alloc, "a", " ", "Find alloc")
	flag.StringVar(&image, "i", " ", "Find image")
}
Beispiel #11
0
func main() {
	flag.Parse()
	if help {
		fmt.Println("Usage of pm: pm [-0] [-1] [-c] [-q] <optional node list>")
		os.Exit(0)
	}

	var command string

	node := flag.Args()

	switch {
	case cycle == true:
		command = "reboot"
	case turnon == true:
		command = "on"
	case turnoff == true:
		command = "off"
	case query == true:
		command = "status"
	default:
		fmt.Println("One of -0 -1 -c or -q is required")
		os.Exit(1)
	}

	if command == "status" {
		status, err := commPower(node, command)
		if err != nil {
			os.Exit(1)
		}
		format(status)
	} else {
		_, err := commPower(node, command)
		if err != nil {
			cli.PrintError(fmt.Sprintf("Failed to %s nodes %s", command, node), err)
			os.Exit(1)
		}
	}
}
Beispiel #12
0
func logs(name string) string {
	var errorLog string
	logName := "/var/log/" + name + ".log"
	_, err := os.Stat(logName)
	if err != nil {
		fclient.PrintError(err.Error(), err)
		os.Exit(1)
	}
	file, err := ioutil.ReadFile(logName)
	if log {
		return string(file)
	}
	if error_ {
		contents := strings.Split(string(file), "\n")
		for _, data := range contents {
			dex := strings.Index(data, "ERROR")
			if dex > 0 {
				errorLog = errorLog + data + "\n"
			}
		}
		return (errorLog)
	}
	return ""
}
Beispiel #13
0
func main() {
	flag.Parse()

	if help {
		cli.Usage()
		os.Exit(0)
	}

	someBytes, err := getStatus()
	if err != nil {
		cli.PrintError("Cannot find the status of nodes in heckle.", err)
		os.Exit(1)
	}

	if len(someBytes) <= 0 {
		cli.PrintError("Your request does not exsist.", errors.New("no data"))
		os.Exit(1)
	}

	if user != " " {
		validList := findValues("OWNER", string(someBytes), user)
		if len(validList) > 0 {
			printStatus(validList)
		} else {
			cli.PrintError("User does not exist in the system", errors.New("Unknown user"))
			os.Exit(1)
		}

	}

	if node != " " {
		validList := findValues("NODE", string(someBytes), node)
		if len(validList) > 0 {
			printStatus(validList)
		} else {
			cli.PrintError("Node is not allocated or does not exsist", errors.New("Missing"))
			os.Exit(1)
		}
	}

	if alloc != " " {
		validList := findValues("ALLOCATION", string(someBytes), alloc)
		if len(validList) > 0 {
			printStatus(validList)
		} else {
			cli.PrintError("Allocation number does not exsist", errors.New("Allocation does not exsist"))
			os.Exit(1)
		}
	}

	if image != " " {
		validList := findValues("IMAGE", string(someBytes), image)
		if len(validList) > 0 {
			printStatus(validList)
		} else {
			cli.PrintError("Image does not exist.", errors.New("No image"))
			os.Exit(1)
		}
	}

	if len(os.Args) < 2 {
		printStatus(string(someBytes))
	}

}
Beispiel #14
0
func main() {
	flag.Parse()
	clientList := make(map[string]*fnet.BuildServer)

	if help {
		fmt.Println(fmt.Sprintf("Command syntax -- %s daemon1 daemon2 ...daemonN", os.Args[0]))
		fclient.Usage()
		os.Exit(0)
	}

	if len(os.Args) <= 1 {
		fclient.PrintError("No arguments provided", errors.New("no args"))
		fmt.Println(fmt.Sprintf("Command syntax -- %s daemon1 daemon2 ...daemonN", os.Args[0]))
		fclient.Usage()
		os.Exit(1)
	}

	components := flag.Args()
	if len(components) == 0 {
		fclient.PrintError("No clients specified", errors.New("no client"))
		os.Exit(1)
	}

	for _, name := range components {
		comm, err := fclient.NewClient()
		if err != nil {
			fclient.PrintError("Failed to setup communication", err)
			os.Exit(1)
		}
		client, err := comm.SetupClient(name)
		if err != nil {
			fclient.PrintError(fmt.Sprintf("Failed to lookup component %s", name), err)
			os.Exit(1)
		}
		clientList[name] = client
	}

	if stat {
		var statusType Status
		respList := make(map[string]Status)
		for name, client := range clientList {
			resp, err := client.Get("daemon")
			if err != nil {
				fclient.PrintError("Could not get daemon status", err)
				os.Exit(1)
			}
			err = json.Unmarshal(resp, &statusType)
			if err != nil {
				fclient.PrintError(err.Error(), err)
			}
			respList[name] = statusType
		}
		printStatus(respList)
	}

	if dump {
		for name, client := range clientList {
			resp, err := client.Get("dump")
			if err != nil {
				fclient.PrintError(fmt.Sprintf("Failed to contact component %s", name), err)
				os.Exit(1)
			}
			fmt.Println(string(resp))
		}
	}

	if log {
		for name, _ := range clientList {
			logging := logs(name)
			fmt.Println(logging)
		}
	}

	if error_ {
		for name, _ := range clientList {
			errorLogging := logs(name)
			if len(errorLogging) <= 0 {
				fmt.Println(fmt.Sprintf("No errors exsist in the logs for %s", name))
			} else {
				fmt.Println(errorLogging)
			}
		}
	}

}