func NewServer(config *configuration.Configuration) (*Server, error) { log.Info("Opening database at %s", config.DataDir) db, err := datastore.NewLevelDbDatastore(config.DataDir, config.LevelDbMaxOpenFiles) if err != nil { return nil, err } clusterConfig := coordinator.NewClusterConfiguration(config) raftServer := coordinator.NewRaftServer(config, clusterConfig) coord := coordinator.NewCoordinatorImpl(db, raftServer, clusterConfig) go coord.SyncLogs() requestHandler := coordinator.NewProtobufRequestHandler(db, coord, clusterConfig) protobufServer := coordinator.NewProtobufServer(config.ProtobufPortString(), requestHandler) eng, err := engine.NewQueryEngine(coord) if err != nil { return nil, err } raftServer.AssignEngineAndCoordinator(eng, coord) httpApi := http.NewHttpServer(config.ApiHttpPortString(), config.AdminAssetsDir, eng, coord, coord) httpApi.EnableSsl(config.ApiHttpSslPortString(), config.ApiHttpCertPath) adminServer := admin.NewHttpServer(config.AdminAssetsDir, config.AdminHttpPortString()) return &Server{ RaftServer: raftServer, Db: db, ProtobufServer: protobufServer, ClusterConfig: clusterConfig, HttpApi: httpApi, Coordinator: coord, AdminServer: adminServer, Config: config, RequestHandler: requestHandler}, nil }
func NewServer(config *configuration.Configuration) (*Server, error) { log.Info("Opening database at %s", config.DataDir) shardDb, err := datastore.NewLevelDbShardDatastore(config) if err != nil { return nil, err } newClient := func(connectString string) cluster.ServerConnection { return coordinator.NewProtobufClient(connectString, config.ProtobufTimeout.Duration) } writeLog, err := wal.NewWAL(config) if err != nil { return nil, err } clusterConfig := cluster.NewClusterConfiguration(config, writeLog, shardDb, newClient) raftServer := coordinator.NewRaftServer(config, clusterConfig) clusterConfig.LocalRaftName = raftServer.GetRaftName() clusterConfig.SetShardCreator(raftServer) clusterConfig.CreateFutureShardsAutomaticallyBeforeTimeComes() coord := coordinator.NewCoordinatorImpl(config, raftServer, clusterConfig) requestHandler := coordinator.NewProtobufRequestHandler(coord, clusterConfig) protobufServer := coordinator.NewProtobufServer(config.ProtobufPortString(), requestHandler) raftServer.AssignCoordinator(coord) httpApi := http.NewHttpServer(config.ApiHttpPortString(), config.ApiReadTimeout, config.AdminAssetsDir, coord, coord, clusterConfig, raftServer) httpApi.EnableSsl(config.ApiHttpSslPortString(), config.ApiHttpCertPath) graphiteApi := graphite.NewServer(config, coord, clusterConfig) adminServer := admin.NewHttpServer(config.AdminAssetsDir, config.AdminHttpPortString()) return &Server{ RaftServer: raftServer, ProtobufServer: protobufServer, ClusterConfig: clusterConfig, HttpApi: httpApi, GraphiteApi: graphiteApi, Coordinator: coord, AdminServer: adminServer, Config: config, RequestHandler: requestHandler, writeLog: writeLog, shardStore: shardDb}, nil }