func newServer() (*server, error) { // Determine hostname in case it hasn't been specified in -rpc or -http. host, err := os.Hostname() if err != nil { host = "127.0.0.1" } // Resolve if strings.HasPrefix(*rpcAddr, ":") { *rpcAddr = host + *rpcAddr } addr, err := net.ResolveTCPAddr("tcp", *rpcAddr) if err != nil { return nil, util.Errorf("unable to resolve RPC address %q: %v", *rpcAddr, err) } s := &server{ host: host, mux: http.NewServeMux(), rpc: rpc.NewServer(addr), } s.gossip = gossip.New() s.kvDB = kv.NewDB(s.gossip) s.kvREST = rest.NewRESTServer(s.kvDB) s.node = NewNode(s.kvDB, s.gossip) s.admin = newAdminServer(s.kvDB) s.status = newStatusServer(s.kvDB) s.structuredDB = structured.NewDB(s.kvDB) s.structuredREST = structured.NewRESTServer(s.structuredDB) return s, nil }
func startNewServer() *kvTestServer { s := &kvTestServer{} // Initialize engine, store, and localDB. engine := storage.NewInMem(storage.Attributes{}, 1<<20) localDB, err := server.BootstrapCluster("test-cluster", engine) if err != nil { panic(err) } s.db = localDB // Rip through the stores (should be just one) and grab the first range (there should also just be one). localDB.VisitStores(func(store *storage.Store) error { rs := store.GetRanges() if len(rs) > 0 { s.firstRange = rs[0] } return nil }) if s.firstRange == nil { panic("Internal Error: Expected to find a range while initializing test server!") } // Initialize the REST server. s.rest = rest.NewRESTServer(s.db) s.httpServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { s.rest.HandleAction(w, r) })) return s }
func newServer() (*server, error) { // Determine hostname in case it hasn't been specified in -rpc or -http. host, err := os.Hostname() if err != nil { host = "127.0.0.1" } // Resolve if strings.HasPrefix(*rpcAddr, ":") { *rpcAddr = host + *rpcAddr } _, err = net.ResolveTCPAddr("tcp", *rpcAddr) if err != nil { return nil, util.Errorf("unable to resolve RPC address %q: %v", *rpcAddr, err) } var tlsConfig *rpc.TLSConfig if *certDir == "" { tlsConfig = rpc.LoadInsecureTLSConfig() } else { var err error if tlsConfig, err = rpc.LoadTLSConfig(*certDir); err != nil { return nil, util.Errorf("unable to load TLS config: %v", err) } } s := &server{ host: host, mux: http.NewServeMux(), clock: hlc.NewClock(hlc.UnixNano), rpc: rpc.NewServer(util.MakeRawAddr("tcp", *rpcAddr), tlsConfig), } s.clock.SetMaxDrift(*maxDrift) s.gossip = gossip.New(tlsConfig) s.kvDB = kv.NewDB(kv.NewDistKV(s.gossip), s.clock) s.kvREST = rest.NewRESTServer(s.kvDB) s.node = NewNode(s.kvDB, s.gossip) s.admin = newAdminServer(s.kvDB) s.status = newStatusServer(s.kvDB) s.structuredDB = structured.NewDB(s.kvDB) s.structuredREST = structured.NewRESTServer(s.structuredDB) return s, nil }
func startNewServer() *kvTestServer { s := &kvTestServer{} // Initialize engine, store, and localDB. e := engine.NewInMem(proto.Attributes{}, 1<<20) db, err := server.BootstrapCluster("test-cluster", e) if err != nil { panic(err) } s.db = db // Initialize the REST server. s.rest = rest.NewRESTServer(s.db) s.httpServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { s.rest.HandleAction(w, r) })) return s }