func NewClient(nameAddr string, leaseAddr string, connsPerDn int) (*Client, error) { ret := &Client{} var err error ret.Leases, err = leaseserver.NewLeaseClient(leaseAddr) if err != nil { return ret, err } ret.Names, err = NewNameClient(nameAddr) if err != nil { return ret, nil } ret.Datas, err = dataserver.NewDataClient(ret.Names, connsPerDn) return ret, err }
// 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 }
// TODO refactor to use NewConfSet func NewSingleNodeCluster(nncfg *conf.NSConfig, ds []*conf.DSConfig, format bool) (*SingleNodeCluster, error) { cl := &SingleNodeCluster{} nls, err := NewNameServer(nncfg, format) if err != nil { return nil, err } cl.LeaseServer = nls.leaseServer cl.NameServer = nls.nameserver fmt.Println("Starting name client") cl.Names, err = NewNameClient(nncfg.NameBindAddr) if err != nil { return cl, err } fmt.Println("starting lease client") cl.Leases, err = leaseserver.NewLeaseClient(nncfg.LeaseBindAddr) if err != nil { return cl, err } // start data client dc, err := dataserver.NewDataClient(cl.Names, 1) if err != nil { return cl, fmt.Errorf("error building dataclient : %s", err.Error()) } cl.Datas = dc // start dataservers cl.DataNodes = make([]*dataserver.DataServer, len(ds)) for idx, dscfg := range ds { fmt.Println("Starting DS with cfg %+v\n", dscfg) cl.DataNodes[idx], err = dataserver.NewDataServer(dscfg.VolumeRoots, dscfg.DataClientBindAddr, dscfg.NameDataBindAddr, dscfg.WebBindAddr, cl.Names, dc) if err != nil { return cl, err } } return cl, nil }