Esempio n. 1
0
// NewManager constructs NodeManager instances
func NewManager(port int, rMgr region.Manager, pers persist.MGMDB, notify notifier, log logger.Log) Manager {
	mgr := Manager{}
	mgr.listenPort = port
	mgr.mgm = pers
	mgr.log = logger.Wrap("HOST", log)
	mgr.internalMsgs = make(chan internalMsg, 32)
	mgr.requestChan = make(chan Message, 32)
	mgr.rMgr = rMgr
	mgr.notify = notify
	//ch := make(chan hostSession, 32)

	//go mgr.listen(ch)

	regions := rMgr.GetRegions()
	mgr.hosts = make(map[int64]mgm.Host)
	mgr.hostStats = make(map[int64]mgm.HostStat)
	mgr.hostConnections = make(map[int64]hostConn)
	mgr.hMutex = &sync.Mutex{}
	mgr.hsMutex = &sync.Mutex{}
	mgr.hcMutex = &sync.Mutex{}
	for _, h := range pers.QueryHosts() {
		mgr.hosts[h.ID] = h
		mgr.hostStats[h.ID] = mgm.HostStat{ID: h.ID}
	}
	for _, r := range regions {
		h, ok := mgr.hosts[r.Host]
		if ok {
			h.Regions = append(h.Regions, r.UUID)
			mgr.hosts[h.ID] = h
		}
	}

	return mgr
}
Esempio n. 2
0
// NewManager constructs a user.Manager for use
func NewManager(rMgr region.Manager, hMgr host.Manager, jMgr job.Manager, userConnector core.UserConnector, pers persist.MGMDB, notify notifier, log logger.Log) Manager {
	um := Manager{}
	um.log = logger.Wrap("USER", log)
	um.conn = userConnector
	um.hMgr = hMgr
	um.rMgr = rMgr
	um.jMgr = jMgr
	um.mgm = pers
	um.users = make(map[uuid.UUID]mgm.User)
	um.uMutex = &sync.Mutex{}
	um.pendingUsers = make(map[string]mgm.PendingUser)
	um.puMutex = &sync.Mutex{}
	um.estates = make(map[int64]mgm.Estate)
	um.estateMutex = &sync.Mutex{}
	um.groups = make(map[uuid.UUID]mgm.Group)
	um.groupMutex = &sync.Mutex{}
	um.notify = notify

	// Get users from simian
	users, err := userConnector.GetUsers()
	if err != nil {
		um.log.Fatal("Cannot get users from simian: ", err.Error())
	}
	for _, u := range users {
		um.users[u.UserID] = u
	}

	// get pending users from mysql
	for _, u := range pers.QueryPendingUsers() {
		um.pendingUsers[u.Email] = u
	}

	//get estates from mysql
	for _, e := range pers.QueryEstates() {
		um.estates[e.ID] = e
	}

	// Get groups from simian
	groups, err := userConnector.GetGroups()
	if err != nil {
		um.log.Fatal("Cannot get groups from simian: ", err.Error())
	}
	for _, g := range groups {
		um.groups[g.ID] = g
	}

	return um
}
Esempio n. 3
0
// NewManager constructs a RegionManager for use
func NewManager(mgmURL string, simianURL string, pers persist.MGMDB, osdb persist.Database, notify notifier, log logger.Log) Manager {
	rMgr := Manager{}
	rMgr.simianURL = simianURL
	rMgr.mgmURL = mgmURL
	rMgr.mgm = pers
	rMgr.osdb = osdb
	rMgr.log = logger.Wrap("REGION", log)
	rMgr.regions = make(map[uuid.UUID]mgm.Region)
	rMgr.regionStats = make(map[uuid.UUID]mgm.RegionStat)
	rMgr.rMutex = &sync.Mutex{}
	rMgr.rsMutex = &sync.Mutex{}
	rMgr.notify = notify

	for _, r := range pers.QueryRegions() {
		rMgr.regions[r.UUID] = r
		rMgr.regionStats[r.UUID] = mgm.RegionStat{}
	}

	return rMgr
}
Esempio n. 4
0
// NewManager constructs a jobManager for use
func NewManager(filePath string, mgmURL string, hubRegion uuid.UUID, pers persist.MGMDB, notify notifier, log logger.Log) Manager {

	j := Manager{}
	j.fileUp = make(chan fileUpload, 32)
	j.localPath = filePath
	j.mgmURL = mgmURL
	j.log = logger.Wrap("JOB", log)
	j.mgm = pers
	j.hub = hubRegion
	j.rUp = make(chan uuid.UUID, 32)
	j.rDn = make(chan uuid.UUID, 32)
	j.notify = notify

	j.jobs = make(map[int64]mgm.Job)
	for _, t := range pers.QueryJobs() {
		j.jobs[t.ID] = t
	}
	j.jMutex = &sync.Mutex{}

	go j.process()

	return j
}