Beispiel #1
0
// returns a started nameserver -- we must start lease server in order to boot up nameserver, so
func NewMaster(cfg *MasterConfig, format bool) (*Master, error) {
	nls := &Master{}
	var err error = nil
	nls.leaseServer = leaseserver.NewLeaseServer()
	nls.nameserver, err = nameserver.NewNameServer(cfg.NameHome, cfg.ReplicationFactor, format)
	if err != nil {
		log.Printf("Error creating nameserver: %s\n\n Nameserver config: %+v\n", err.Error(), cfg)
		return nls, err
	}
	opMap := make(map[uint32]func(*net.TCPConn))
	opMap[SERVNO_LEASESERVER] = nls.leaseServer.ServeConn
	log.Printf("Starting master on addr %s", cfg.BindAddr)
	nls.serv, err = mrpc.CloseableRPC(cfg.BindAddr, "NameService", maggiefs.NewNameServiceService(nls.nameserver), opMap)
	if err != nil {
		return nls, err
	}
	_, port, _ := net.SplitHostPort(cfg.BindAddr)
	nls.port, _ = strconv.Atoi(port)
	return nls, err
}
Beispiel #2
0
// returns a started nameserver -- we must start lease server in order to boot up nameserver, so
func NewNameServer(cfg *conf.NSConfig, format bool) (*NameLeaseServer, error) {
	nls := &NameLeaseServer{}
	var err error = nil
	fmt.Println("creating lease server")
	nls.leaseServer, err = leaseserver.NewLeaseServer(cfg.LeaseBindAddr)
	if err != nil {
		return nls, err
	}
	nls.leaseServer.Start()
	fmt.Println("creating lease client")
	leaseService, err := leaseserver.NewLeaseClient(cfg.LeaseBindAddr)
	if err != nil {
		return nls, err
	}
	fmt.Println("creating name server")
	nls.nameserver, err = nameserver.NewNameServer(leaseService, cfg.NameBindAddr, cfg.WebBindAddr, cfg.NNHomeDir, cfg.ReplicationFactor, format)
	if err != nil {
		fmt.Printf("Error creating nameserver: %s\n\n Nameserver config: %+v\n", err.Error(), cfg)
		return nls, err
	}
	nls.nameserver.Start()
	return nls, err
}