Exemplo n.º 1
0
// runFollower runs the follower FSM loop
func (d *MasterDaemon) runFollower() {
	router := mux.NewRouter()
	router.PathPrefix("/").HandlerFunc(slaveProxyHandler)

	// acquire listener mutex
	d.listenerMutex.Lock()
	defer d.listenerMutex.Unlock()

	// start server
	server := &http.Server{Handler: router}
	server.SetKeepAlivesEnabled(false)
	listener, err := net.Listen("tcp", d.ListenURL)
	if nil != err {
		log.Fatalln(err)
	}

	listener = utils.ListenWrapper(listener)

	// start server
	go server.Serve(listener)

	// Register netmaster service
	d.registerService()

	// just wait on stop channel
	log.Infof("Listening in follower mode")
	<-d.stopFollowerChan

	// Close the listener and exit
	listener.Close()
	log.Info("Exiting follower mode")
}
Exemplo n.º 2
0
// runLeader runs leader loop
func (d *daemon) runLeader() {
	router := mux.NewRouter()

	// acquire listener mutex
	d.listenerMutex.Lock()
	defer d.listenerMutex.Unlock()

	// Create a new api controller
	d.apiController = objApi.NewAPIController(router, d.clusterStore)

	//Restore state from clusterStore

	d.restoreCache()

	// Register netmaster service
	d.registerService()

	// initialize policy manager
	mastercfg.InitPolicyMgr(d.stateDriver, d.ofnetMaster)

	// setup HTTP routes
	d.registerRoutes(router)

	// Create HTTP server and listener
	server := &http.Server{Handler: router}
	server.SetKeepAlivesEnabled(false)
	listener, err := net.Listen("tcp", d.listenURL)
	if nil != err {
		log.Fatalln(err)
	}

	log.Infof("Netmaster listening on %s", d.listenURL)

	listener = utils.ListenWrapper(listener)

	// start server
	go server.Serve(listener)

	// Wait till we are asked to stop
	<-d.stopLeaderChan

	// Close the listener and exit
	listener.Close()
	log.Infof("Exiting Leader mode")
}