Exemple #1
0
func allocate() {
	//This is the allocate thread.  It set up a client for ctl messages to
	//flunky master.  On each iteration it grabs new nodes from heckle to be
	//allocated and send them off to flunkymaster.
	heckleDaemon.DaemonLog.LogDebug("Starting allocation go routine.")

	for i := range heckleToAllocateChan {
		cm := new(iface.Ctlmsg)
		cm.Image = i.Image
		cm.Addresses = i.Addresses
		cm.AllocNum = uint64(i.AllocNum)
		// FIXME: need to add in extradata

		/*js, _ := json.Marshal(cm)
		buf := bytes.NewBufferString(string(js))*/

		_, err := fs.PostServer("/ctl", cm)
		heckleDaemon.DaemonLog.LogError("Failed to post for allocation of nodes.", err)

		if err == nil {
			allocateToPollingChan <- i.Addresses

			_, err = ps.PostServer("/command/reboot", i.Addresses)
			heckleDaemon.DaemonLog.LogError("Failed to post for reboot of nodes in allocation go routine.", err)
		}
	}
	close(allocateToPollingChan)
}
Exemple #2
0
func polling() {
	//This function sets up an http client for polling flunky master.  Every
	//iteration through the loop it grabs all new addresses from the allocation
	//thread, polls on all addresses in that list, send those messages to heckle,
	//grabs nodes for cancelation and removes them from the list.
	heckleDaemon.DaemonLog.LogDebug("Starting polling go routine.")
	pollAddresses := []string{}
	pollingOutletStatus := make(map[string]string)
	var pollAddressesLock sync.Mutex
	pollTime := time.Now()

	go addToPollList(&pollAddressesLock, &pollAddresses)
	go deleteFromPollList(&pollAddressesLock, &pollAddresses)

	for ; ; time.Sleep(10000000000) {
		heckleDaemon.DaemonLog.LogDebug("Polling for messages from flunky master and power daemons.")
		statRequest := new(iface.Ctlmsg)
		pollAddressesLock.Lock()
		statRequest.Addresses = pollAddresses
		pollAddressesLock.Unlock()
		if len(statRequest.Addresses) != 0 {
			statRequest.Time = pollTime.Unix()

			var statmap map[string]*iface.StatusMessage
			/*sRjs, _ := json.Marshal(statRequest)
			reqbuf := bytes.NewBufferString(string(sRjs))*/

			ret, _ := fs.PostServer("/status", statRequest)
			pollTime = time.Now()
			json.Unmarshal(ret, &statmap)

			outletStatus := make(map[string]States)

			ret, _ = ps.PostServer("/status", pollAddresses)
			json.Unmarshal(ret, &outletStatus)

			var pstat string
			//This garbage needs to change!
			for key, value := range statmap {
				if outletStatus[key].Reboot {
					pstat = "currently rebooting"
				} else if outletStatus[key].State {
					pstat = "On"
				} else {
					pstat = "Off"
				}
				if _, ok := pollingOutletStatus[key]; !ok {
					value.Info = append(value.Info, iface.InfoMsg{time.Now().Unix(), "Power outlet for " + key + " is " + pstat + ".", "Info"})
					pollingOutletStatus[key] = pstat
				} else if pollingOutletStatus[key] != pstat {
					value.Info = append(value.Info, iface.InfoMsg{time.Now().Unix(), "Power outlet for " + key + " is " + pstat + ".", "Info"})
					pollingOutletStatus[key] = pstat
				}
			}
			heckleDaemon.DaemonLog.LogDebug("Sending status messages to main routine.")
			pollingToHeckleChan <- statmap
		}
	}
}
Exemple #3
0
func ControlMsg(nodes []string, times int64) (*bytes.Buffer, *interfaces.Ctlmsg) {
	req := new(interfaces.Ctlmsg)
	req.Addresses = nodes
	req.Time = times
	req.Image = "ubuntu-Rescue"
	resp, _ := json.Marshal(req)
	buf := bytes.NewBufferString(string(resp))
	return buf, req
}