Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update grpc listen address on scheduler and cdn #1205

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cdn/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func TestConfig_Convert(t *testing.T) {
},
RPCServer: rpcserver.Config{
AdvertiseIP: "127.0.0.1",
Listen: "0.0.0.0",
ListenPort: 8006,
DownloadPort: 8000,
},
Expand Down
1 change: 1 addition & 0 deletions cdn/config/old_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (c DeprecatedConfig) Convert() *Config {
newConfig.CDN.MaxBandwidth = baseProperties.MaxBandwidth
newConfig.RPCServer = rpcserver.Config{
AdvertiseIP: baseProperties.AdvertiseIP,
Listen: "0.0.0.0",
ListenPort: baseProperties.ListenPort,
DownloadPort: baseProperties.DownloadPort,
}
Expand Down
6 changes: 6 additions & 0 deletions cdn/rpcserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type Config struct {
// By default, the first non-loop address is advertised.
AdvertiseIP string `yaml:"advertiseIP" mapstructure:"advertiseIP"`

// Listen stands listen interface, like: 0.0.0.0, 192.168.0.1
Listen string `yaml:"listen" mapstructure:"listen"`

// ListenPort is the port cdn server listens on.
// default: 8002
ListenPort int `yaml:"listenPort" mapstructure:"listenPort"`
Expand All @@ -46,6 +49,9 @@ func (c Config) applyDefaults() Config {
if c.AdvertiseIP == "" {
c.AdvertiseIP = iputils.IPv4
}
if c.Listen == "" {
c.Listen = "0.0.0.0"
}
if c.ListenPort == 0 {
c.ListenPort = DefaultListenPort
}
Expand Down
2 changes: 1 addition & 1 deletion cdn/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (css *Server) SyncPieceTasks(sync cdnsystem.Seeder_SyncPieceTasksServer) er

func (css *Server) ListenAndServe() error {
// Generate GRPC listener
lis, _, err := rpc.ListenWithPortRange(css.config.AdvertiseIP, css.config.ListenPort, css.config.ListenPort)
lis, _, err := rpc.ListenWithPortRange(css.config.Listen, css.config.ListenPort, css.config.ListenPort)
if err != nil {
return err
}
Expand Down
14 changes: 11 additions & 3 deletions scheduler/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ type Config struct {
func New() *Config {
return &Config{
Server: &ServerConfig{
IP: iputils.IPv4,
Host: hostutils.FQDNHostname,
Port: 8002,
IP: iputils.IPv4,
Host: hostutils.FQDNHostname,
Listen: "0.0.0.0",
Port: 8002,
},
Scheduler: &SchedulerConfig{
Algorithm: "default",
Expand Down Expand Up @@ -123,6 +124,10 @@ func (c *Config) Validate() error {
return errors.New("server requires parameter port")
}

if c.Server.Listen == "" {
return errors.New("server requires parameter listen")
}

if c.Scheduler.Algorithm == "" {
return errors.New("scheduler requires parameter algorithm")
}
Expand Down Expand Up @@ -213,6 +218,9 @@ type ServerConfig struct {
// Server hostname
Host string `yaml:"host" mapstructure:"host"`

// Listen stands listen interface, like: 0.0.0.0, 192.168.0.1
Listen string `yaml:"listen" mapstructure:"listen"`

// Server port
Port int `yaml:"port" mapstructure:"port"`

Expand Down
1 change: 1 addition & 0 deletions scheduler/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestConfig_Load(t *testing.T) {
Server: &ServerConfig{
IP: "127.0.0.1",
Host: "foo",
Listen: "0.0.0.0",
Port: 8002,
CacheDir: "foo",
LogDir: "bar",
Expand Down
1 change: 1 addition & 0 deletions scheduler/config/testdata/scheduler.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
server:
ip: 127.0.0.1
host: foo
listen: 0.0.0.0
port: 8002
cacheDir: foo
logDir: bar
Expand Down
2 changes: 1 addition & 1 deletion scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (s *Server) Serve() error {
}

// Generate GRPC limit listener
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.config.Server.IP, s.config.Server.Port))
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.config.Server.Listen, s.config.Server.Port))
if err != nil {
logger.Fatalf("net listener failed to start: %v", err)
}
Expand Down