func do(appEnvObj interface{}) error { appEnv := appEnvObj.(*appEnv) rethinkClient, err := getRethinkClient(appEnv.DatabaseAddress, appEnv.DatabaseName) if err != nil { return err } apiClient, err := getPfsAPIClient(appEnv.PfsAddress) if err != nil { return err } return grpcutil.GrpcDo( appEnv.APIPort, appEnv.TracePort, pachyderm.Version, func(s *grpc.Server) { pps.RegisterApiServer(s, server.NewAPIServer(apiClient, rethinkClient, timing.NewSystemTimer())) }, ) }
func do() error { runtime.GOMAXPROCS(runtime.NumCPU()) appEnv := &appEnv{} if err := env.Populate(appEnv, env.PopulateOptions{}); err != nil { return err } //address := fmt.Sprintf("0.0.0.0:%d", appEnv.APIPort) s := grpc.NewServer(grpc.MaxConcurrentStreams(math.MaxUint32)) pps.RegisterApiServer(s, server.NewAPIServer(store.NewInMemoryClient())) listener, err := net.Listen("tcp", fmt.Sprintf(":%d", appEnv.APIPort)) if err != nil { return err } errC := make(chan error) go func() { errC <- s.Serve(listener) }() //go func() { errC <- http.ListenAndServe(":8080", nil) }() if appEnv.TracePort != 0 { go func() { errC <- http.ListenAndServe(fmt.Sprintf(":%d", appEnv.TracePort), nil) }() } return <-errC }
func do(appEnvObj interface{}) error { appEnv := appEnvObj.(*appEnv) etcdClient := getEtcdClient(appEnv) rethinkAPIServer, err := getRethinkAPIServer(appEnv) if err != nil { return err } kubeClient, err := getKubeClient(appEnv) if err != nil { return err } address, err := netutil.ExternalIP() if err != nil { return err } address = fmt.Sprintf("%s:%d", address, appEnv.Port) sharder := shard.NewSharder( etcdClient, appEnv.NumShards, appEnv.Namespace, ) go func() { if err := sharder.AssignRoles(address, nil); err != nil { protolion.Printf("Error from sharder.AssignRoles: %s", err.Error()) } }() driver, err := drive.NewDriver(address) if err != nil { return err } apiServer := pfs_server.NewAPIServer( pfs.NewHasher( appEnv.NumShards, 1, ), shard.NewRouter( sharder, grpcutil.NewDialer( grpc.WithInsecure(), ), address, ), ) go func() { if err := sharder.RegisterFrontends(nil, address, []shard.Frontend{apiServer}); err != nil { protolion.Printf("Error from sharder.RegisterFrontend %s", err.Error()) } }() internalAPIServer := pfs_server.NewInternalAPIServer( pfs.NewHasher( appEnv.NumShards, 1, ), shard.NewRouter( sharder, grpcutil.NewDialer( grpc.WithInsecure(), ), address, ), driver, ) go func() { if err := sharder.Register(nil, address, []shard.Server{internalAPIServer}); err != nil { protolion.Printf("Error from sharder.Register %s", err.Error()) } }() ppsAPIServer := pps_server.NewAPIServer( pps.NewHasher(appEnv.NumShards, appEnv.NumShards), shard.NewRouter( sharder, grpcutil.NewDialer( grpc.WithInsecure(), ), address, ), address, rethinkAPIServer, kubeClient, ) var blockAPIServer pfs.BlockAPIServer if err := func() error { bucket, err := ioutil.ReadFile("/amazon-secret/bucket") if err != nil { return err } id, err := ioutil.ReadFile("/amazon-secret/id") if err != nil { return err } secret, err := ioutil.ReadFile("/amazon-secret/secret") if err != nil { return err } token, err := ioutil.ReadFile("/amazon-secret/token") if err != nil { return err } region, err := ioutil.ReadFile("/amazon-secret/region") if err != nil { return err } objClient, err := obj.NewAmazonClient(string(bucket), string(id), string(secret), string(token), string(region)) if err != nil { return err } blockAPIServer, err = pfs_server.NewObjBlockAPIServer(appEnv.StorageRoot, objClient) if err != nil { return err } return nil }(); err != nil { protolion.Errorf("failed to create obj backend, falling back to local") blockAPIServer, err = pfs_server.NewLocalBlockAPIServer(appEnv.StorageRoot) if err != nil { return err } } return protoserver.ServeWithHTTP( func(s *grpc.Server) { pfs.RegisterAPIServer(s, apiServer) pfs.RegisterInternalAPIServer(s, internalAPIServer) pfs.RegisterBlockAPIServer(s, blockAPIServer) pps.RegisterAPIServer(s, ppsAPIServer) }, func(ctx context.Context, mux *runtime.ServeMux, clientConn *grpc.ClientConn) error { return pfs.RegisterAPIHandler(ctx, mux, clientConn) }, protoserver.ServeWithHTTPOptions{ ServeOptions: protoserver.ServeOptions{ Version: pachyderm.Version, }, }, protoserver.ServeEnv{ GRPCPort: appEnv.Port, }, pkghttp.HandlerEnv{ Port: appEnv.HTTPPort, }, ) }