Пример #1
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
		}
	}
}
Пример #2
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
}