Skip to content

Commit

Permalink
feat: add advertise port (#2156)
Browse files Browse the repository at this point in the history
Co-authored-by: wenmanxiang <wenmanxiang@baidu.com>
  • Loading branch information
2 people authored and gaius-qi committed Jun 28, 2023
1 parent 9077749 commit 0f66064
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion scheduler/announcer/announcer.go
Expand Up @@ -60,7 +60,7 @@ func New(cfg *config.Config, managerClient managerclient.V2) (Announcer, error)
SourceType: managerv2.SourceType_SCHEDULER_SOURCE,
HostName: a.config.Server.Host,
Ip: a.config.Server.AdvertiseIP.String(),
Port: int32(a.config.Server.Port),
Port: int32(a.config.Server.AdvertisePort),
Idc: a.config.Host.IDC,
Location: a.config.Host.Location,
SchedulerClusterId: uint64(a.config.Manager.SchedulerClusterID),
Expand Down
14 changes: 8 additions & 6 deletions scheduler/announcer/announcer_test.go
Expand Up @@ -39,9 +39,10 @@ func TestAnnouncer_New(t *testing.T) {
name: "new announcer",
config: &config.Config{
Server: config.ServerConfig{
Host: "localhost",
AdvertiseIP: net.ParseIP("127.0.0.1"),
Port: 8080,
Host: "localhost",
AdvertiseIP: net.ParseIP("127.0.0.1"),
AdvertisePort: 8004,
Port: 8080,
},
Host: config.HostConfig{
IDC: "foo",
Expand All @@ -66,9 +67,10 @@ func TestAnnouncer_New(t *testing.T) {
name: "update scheduler failed",
config: &config.Config{
Server: config.ServerConfig{
Host: "localhost",
AdvertiseIP: net.ParseIP("127.0.0.1"),
Port: 8080,
Host: "localhost",
AdvertiseIP: net.ParseIP("127.0.0.1"),
AdvertisePort: 8004,
Port: 8080,
},
Host: config.HostConfig{
IDC: "foo",
Expand Down
12 changes: 10 additions & 2 deletions scheduler/config/config.go
Expand Up @@ -81,6 +81,9 @@ type ServerConfig struct {
// AdvertiseIP is advertise ip.
AdvertiseIP net.IP `yaml:"advertiseIP" mapstructure:"advertiseIP"`

// AdvertisePort is advertise port.
AdvertisePort int `yaml:"advertisePort" mapstructure:"advertisePort"`

// ListenIP is listen ip, like: 0.0.0.0, 192.168.0.1.
ListenIP net.IP `yaml:"listenIP" mapstructure:"listenIP"`

Expand Down Expand Up @@ -321,8 +324,9 @@ type ProbeConfig struct {
func New() *Config {
return &Config{
Server: ServerConfig{
Port: DefaultServerPort,
Host: fqdn.FQDNHostname,
Port: DefaultServerPort,
AdvertisePort: DefaultServerAdvertisePort,
Host: fqdn.FQDNHostname,
},
Scheduler: SchedulerConfig{
Algorithm: DefaultSchedulerAlgorithm,
Expand Down Expand Up @@ -404,6 +408,10 @@ func (cfg *Config) Validate() error {
return errors.New("server requires parameter advertiseIP")
}

if cfg.Server.AdvertisePort <= 0 {
return errors.New("server requires parameter advertisePort")
}

if cfg.Server.ListenIP == nil {
return errors.New("server requires parameter listenIP")
}
Expand Down
19 changes: 10 additions & 9 deletions scheduler/config/config_test.go
Expand Up @@ -88,15 +88,16 @@ func TestConfig_Load(t *testing.T) {
},
},
Server: ServerConfig{
AdvertiseIP: net.ParseIP("127.0.0.1"),
ListenIP: net.ParseIP("0.0.0.0"),
Port: 8002,
Host: "foo",
WorkHome: "foo",
CacheDir: "foo",
LogDir: "foo",
PluginDir: "foo",
DataDir: "foo",
AdvertiseIP: net.ParseIP("127.0.0.1"),
AdvertisePort: 8004,
ListenIP: net.ParseIP("0.0.0.0"),
Port: 8002,
Host: "foo",
WorkHome: "foo",
CacheDir: "foo",
LogDir: "foo",
PluginDir: "foo",
DataDir: "foo",
},
DynConfig: DynConfig{
RefreshInterval: 10 * time.Second,
Expand Down
3 changes: 3 additions & 0 deletions scheduler/config/constants.go
Expand Up @@ -43,6 +43,9 @@ const (
const (
// DefaultServerPort is default port for server.
DefaultServerPort = 8002

// DefaultServerAdvertisePort is default advertise port for server.
DefaultServerAdvertisePort = 8002
)

const (
Expand Down
1 change: 1 addition & 0 deletions scheduler/config/testdata/scheduler.yaml
@@ -1,5 +1,6 @@
server:
advertiseIP: 127.0.0.1
advertisePort: 8004
listenIP: 0.0.0.0
port: 8002
host: foo
Expand Down

0 comments on commit 0f66064

Please sign in to comment.