示例#1
0
func (watchagent *Watchagent) reportVMEvents() {
	fmt.Println("Started reportvmevents")
	go Runme()
	fmt.Println("listening on tokenchan")
	for x := range Tokenchan {
		fmt.Println("got one")
		watchagent.Vmdata.Servervms = x.Vmlista
		if x.Status == 2 {
			MakeKnown(x.Vmuuid)
			vmdetection := new(utilities.VMDetection)
			vmdetection.Reporter_ovip = watchagent.Ovip
			vmdetection.Reporter_dcid = watchagent.Dcid
			vmdetection.Dcid = watchagent.Dcid
			vmdetection.Breakage = false
			vmdetection.Epoch = watchagent.Vmdata.Serverepoch
			vmdetection.Ovip = watchagent.Ovip
			vmdetection.Timestamp = time.Now()
			vmdetection.Vmid = []string{x.Vmuuid}
			watchagent.persistencylayer.InsertVMDetection(vmdetection)
		}
		fmt.Printf("Lista length for broadcasting == %d\n", len(x.Vmlista))
		servermutex.Lock()
		watchers := watchagent.Ovpwatchers
		servermutex.Unlock()
		if watchers != nil {
			q := BroadcastUpdate(&watchagent.Watchmedata, watchers) //TODO, do something on error
			fmt.Printf("Broadcasted to %d\n", q.Size())
		}
	}
}
示例#2
0
func (watchagent *Watchagent) reportHostevents() {
	fmt.Println("Started reporthostevents")
	for nodevent := range watchagent.observer.Notifier {
		fmt.Println("hostevent " + strconv.Itoa(int(nodevent.Mesgtype)))
		if nodevent.Mesgtype == NOTIFY_LEAVE {
			fmt.Println("LEFT " + nodevent.Name)
			sd := new(utilities.OPData)

			//try to unmarshal from  name
			if err := json.Unmarshal([]byte(nodevent.Name), sd); err != nil {
				panic(err.Error)
			}

			//pass through if not running
			if temp := watchagent.isRunning(); temp != nil {
				return
			}

			announce := false
			servermutex.Lock()
			vmdata, ok := watchagent.watching[sd.OPConfig]
			if ok {
				if sd.Epoch < vmdata.Serverepoch { //stray previous detection but missed deregister
					panic("stray previous detection but missed deregister")
				} else if sd.Epoch > vmdata.Serverepoch {
					panic("left from future but missed register")
				} else {
					delete(watchagent.watching, sd.OPConfig)
					watchagent.recreateObservers()
					announce = true
				}
			}
			servermutex.Unlock()

			if announce {

				vmnames := make([]string, len(vmdata.Servervms))
				indy := 0
				for vmuuid := range vmdata.Servervms {
					_ = MakeKnown(vmuuid)
					vmnames[indy] = vmuuid
					indy++
				}
				vmdetection := new(utilities.VMDetection)
				vmdetection.Reporter_ovip = watchagent.Ovip
				vmdetection.Reporter_dcid = watchagent.Dcid
				vmdetection.Breakage = true
				vmdetection.Dcid = sd.Dcid
				vmdetection.Epoch = sd.Epoch
				vmdetection.Ovip = sd.Ovip
				vmdetection.Timestamp = time.Now()
				vmdetection.Vmid = vmnames
				watchagent.persistencylayer.InsertVMDetection(vmdetection)
			}
		}
	}
}