func do(appEnvObj interface{}) error { appEnv := appEnvObj.(*appEnv) discoveryClient, err := getEtcdClient() if err != nil { return err } address := appEnv.Address if address == "" { address, err = netutil.ExternalIP() if err != nil { return err } } address = fmt.Sprintf("%s:%d", address, appEnv.Port) sharder := shard.NewSharder( discoveryClient, appEnv.NumShards, appEnv.NumReplicas, "namespace", ) var driver drive.Driver switch appEnv.DriverType { case "btrfs": driver, err = btrfs.NewDriver(appEnv.DriverRoot, "") if err != nil { return err } default: return fmt.Errorf("unknown value for PFS_DRIVER_TYPE: %s", appEnv.DriverType) } apiServer := server.NewAPIServer( route.NewSharder( appEnv.NumShards, 0, ), route.NewRouter( sharder, grpcutil.NewDialer( grpc.WithInsecure(), ), address, ), ) go func() { if err := sharder.RegisterFrontend(nil, address, apiServer); err != nil { protolog.Printf("Error from sharder.RegisterFrontend %s", err.Error()) } }() internalAPIServer := server.NewInternalAPIServer( route.NewSharder( appEnv.NumShards, 0, ), route.NewRouter( sharder, grpcutil.NewDialer( grpc.WithInsecure(), ), address, ), driver, ) go func() { if err := sharder.Register(nil, address, internalAPIServer); err != nil { protolog.Printf("Error from sharder.Register %s", err.Error()) } }() return protoserver.Serve( uint16(appEnv.Port), func(s *grpc.Server) { pfs.RegisterAPIServer(s, apiServer) pfs.RegisterInternalAPIServer(s, internalAPIServer) }, protoserver.ServeOptions{ HTTPPort: uint16(appEnv.HTTPPort), DebugPort: uint16(appEnv.DebugPort), Version: pachyderm.Version, HTTPRegisterFunc: func(ctx context.Context, mux *runtime.ServeMux, clientConn *grpc.ClientConn) error { return pfs.RegisterAPIHandler(ctx, mux, clientConn) }, }, ) }
func do(appEnvObj interface{}) error { appEnv := appEnvObj.(*appEnv) logrus.Register() discoveryClient, err := getEtcdClient() if err != nil { return err } address := appEnv.Address if address == "" { address, err = netutil.ExternalIP() if err != nil { return err } } sharder := route.NewSharder(appEnv.NumShards, 0) address = fmt.Sprintf("%s:%d", address, appEnv.Port) addresser := route.NewDiscoveryAddresser( discoveryClient, sharder, "namespace", ) var driver drive.Driver switch appEnv.DriverType { case "btrfs": driver, err = btrfs.NewDriver(appEnv.DriverRoot, "") if err != nil { return err } default: return fmt.Errorf("unknown value for PFS_DRIVER_TYPE: %s", appEnv.DriverType) } apiServer := server.NewAPIServer( route.NewSharder( appEnv.NumShards, 0, ), route.NewRouter( addresser, grpcutil.NewDialer( grpc.WithInsecure(), ), address, ), ) internalAPIServer := server.NewInternalAPIServer( route.NewSharder( appEnv.NumShards, 0, ), route.NewRouter( addresser, grpcutil.NewDialer( grpc.WithInsecure(), ), address, ), driver, ) go func() { if err := addresser.Register(nil, "id", address, internalAPIServer); err != nil { log.Print(err) } }() go func() { if err := addresser.AssignRoles(nil); err != nil { log.Print(err) } }() // TODO(pedge): no! trace.AuthRequest = func(_ *http.Request) (bool, bool) { return true, true } return protoserver.Serve( uint16(appEnv.Port), func(s *grpc.Server) { pfs.RegisterApiServer(s, apiServer) pfs.RegisterInternalApiServer(s, internalAPIServer) }, protoserver.ServeOptions{ HTTPPort: uint16(appEnv.HTTPPort), DebugPort: uint16(appEnv.DebugPort), Version: pachyderm.Version, HTTPRegisterFunc: func(ctx context.Context, mux *runtime.ServeMux, clientConn *grpc.ClientConn) error { return pfs.RegisterApiHandler(ctx, mux, clientConn) }, }, ) }