Exemplo n.º 1
0
func CreateWatchAgent(json *utilities.ServerConfig) *Watchagent {
	watchagent := new(Watchagent)
	watchagent.ovpconfig = json.Ovpconfig
	watchagent.observer = CreateObserver()
	watchagent.Agentparked = true
	watchagent.watching = make(map[utilities.OPConfig]VMdata)
	watchagent.persistencylayer = utilities.CreatePersistencyLayer(&json.Dbconfig)
	opdata := watchagent.persistencylayer.Initialize(&json.Opconfig)
	watchagent.OPConfig = opdata.OPConfig
	watchagent.Vmdata.Serverepoch = opdata.Epoch
	watchagent.Vmdata.Servervms = make(map[string]int)
	go watchagent.reportVMEvents()
	go watchagent.reportHostevents()
	watchagent.memberlistagent = CreateMemberlistAgent(opdata, watchagent.observer)
	fmt.Println("ok1")
	ticker := time.NewTicker(watchagent.ovpconfig.Refreshattempts.Timeout)
	go func() {
		for {
			select {
			case <-ticker.C:
				watchagent.Refreshwatchers()
				ticker = time.NewTicker(watchagent.ovpconfig.Refreshattempts.Timeout)
			}
		}
	}()

	fmt.Println("ok2")
	return watchagent
}
Exemplo n.º 2
0
func CreateLandscapeupdater(conf *utilities.ServerConfig) *Landscapeupdater {
	landscapeupdater := new(Landscapeupdater)
	landscapeupdater.persistencylayer = utilities.CreatePersistencyLayer(&conf.Dbconfig)
	landscapeupdater.opdata = landscapeupdater.persistencylayer.Initialize(&conf.Opconfig)
	landscapeupdater.updateinterval = conf.Odpconfig.Landscapeupdateinterval
	landscapeupdater.Dbupdates = make(chan *DBView)

	go func() {
		ticker := time.NewTicker(landscapeupdater.updateinterval)
		for {
			select {
			case <-ticker.C:
				{
					fmt.Println("Updating")
					var pingers []utilities.OPData = nil
					var voters []utilities.OPData = nil
					dst := landscapeupdater.persistencylayer.GetRoute(landscapeupdater.opdata.Dcid)
					operating := landscapeupdater.persistencylayer.GetDatacenterState(dst)
					fmt.Printf("Got dst %+v \n", operating)
					if dst != "" {
						pingers = landscapeupdater.persistencylayer.GetODPPeers(dst)
						resultset := landscapeupdater.persistencylayer.GetODPPeers(landscapeupdater.opdata.Dcid)
						voters = make([]utilities.OPData, len(resultset))
						index := 0
						for i := 0; i < len(voters); i++ {
							if resultset[i].OPConfig != landscapeupdater.opdata.OPConfig {
								voters[index] = resultset[i]
								index++
							}
						}
						voters = voters[:index]
					}
					landscapeupdater.Dbupdates <- &DBView{*operating, landscapeupdater.opdata, pingers, voters}
					ticker = time.NewTicker(landscapeupdater.updateinterval)
				}
			}
		}
	}()
	return landscapeupdater
}