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: add host info for scheduler and cdn #457

Merged
merged 1 commit into from
Jul 13, 2021
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
12 changes: 12 additions & 0 deletions cdnsystem/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func NewDefaultBaseProperties() *BaseProperties {
RetryMaxBackOff: DefaultKeepAliveRetryMaxBackOff,
},
},
Host: HostConfig{},
}
}

Expand Down Expand Up @@ -188,6 +189,9 @@ type BaseProperties struct {

// Manager configuration
Manager ManagerConfig `yaml:"manager" mapstructure:"manager"`

// Host configuration
Host HostConfig `yaml:"host" mapstructure:"host"`
}

type ManagerConfig struct {
Expand All @@ -214,3 +218,11 @@ type KeepAliveConfig struct {
// Keep alive retry max backoff
RetryMaxBackOff float64 `yaml:"retryMaxBackOff" mapstructure:"retryMaxBackOff"`
}

type HostConfig struct {
// Peerhost location for scheduler
Location string `mapstructure:"location" yaml:"location"`

// Peerhost idc for scheduler
IDC string `mapstructure:"idc" yaml:"idc"`
}
6 changes: 6 additions & 0 deletions cdnsystem/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ func (s *Server) Stop() {
func (s *Server) register(ctx context.Context) error {
ip := s.config.AdvertiseIP
port := int32(s.config.ListenPort)
idc := s.config.Host.IDC
location := s.config.Host.Location
downloadPort := int32(s.config.DownloadPort)

var cdn *manager.CDN
Expand All @@ -169,6 +171,8 @@ func (s *Server) register(ctx context.Context) error {
HostName: iputils.HostName,
Ip: ip,
Port: port,
Idc: idc,
Location: location,
DownloadPort: downloadPort,
})
if err != nil {
Expand All @@ -177,6 +181,8 @@ func (s *Server) register(ctx context.Context) error {
HostName: iputils.HostName,
Ip: ip,
Port: port,
Idc: idc,
Location: location,
DownloadPort: downloadPort,
})
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions scheduler/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Config struct {
GC GCConfig `yaml:"gc" mapstructure:"gc"`
Dynconfig *DynconfigOptions `yaml:"dynconfig" mapstructure:"dynconfig"`
Manager ManagerConfig `yaml:"manager" mapstructure:"manager"`
Host HostConfig `yaml:"host" mapstructure:"host"`
}

func New() *Config {
Expand Down Expand Up @@ -127,3 +128,11 @@ type GCConfig struct {
PeerTaskDelay int64 `yaml:"peerTaskDelay" mapstructure:"peerTaskDelay"`
TaskDelay int64 `yaml:"taskDelay" mapstructure:"taskDelay"`
}

type HostConfig struct {
// Peerhost location for scheduler
Location string `mapstructure:"location" yaml:"location"`

// Peerhost idc for scheduler
IDC string `mapstructure:"idc" yaml:"idc"`
}
1 change: 1 addition & 0 deletions scheduler/config/config_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ var config = Config{
RetryMaxBackOff: 10,
},
},
Host: HostConfig{},
}
1 change: 1 addition & 0 deletions scheduler/config/config_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ var config = Config{
RetryMaxBackOff: 10,
},
},
Host: HostConfig{},
}
24 changes: 14 additions & 10 deletions scheduler/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ func TestSchedulerConfig_Load(t *testing.T) {
assert := testifyassert.New(t)

config := &Config{
Manager: ManagerConfig{
Addr: "127.0.0.1:65003",
SchedulerClusterID: 1,
KeepAlive: KeepAliveConfig{
Interval: 1 * time.Second,
RetryMaxAttempts: 100,
RetryInitBackOff: 100,
RetryMaxBackOff: 100,
},
},
Dynconfig: &DynconfigOptions{
Type: dc.LocalSourceType,
Path: "foo",
Expand Down Expand Up @@ -68,6 +58,20 @@ func TestSchedulerConfig_Load(t *testing.T) {
TaskDelay: 3600 * 1000,
PeerTaskDelay: 3600 * 1000,
},
Manager: ManagerConfig{
Addr: "127.0.0.1:65003",
SchedulerClusterID: 1,
KeepAlive: KeepAliveConfig{
Interval: 1 * time.Second,
RetryMaxAttempts: 100,
RetryInitBackOff: 100,
RetryMaxBackOff: 100,
},
},
Host: HostConfig{
IDC: "foo",
Location: "bar",
},
}

schedulerConfigYAML := &Config{}
Expand Down
9 changes: 9 additions & 0 deletions scheduler/config/testdata/scheduler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ dynconfig:
cachePath: bar
addr: 127.0.0.1:8002
cdnDirPath: tmp

scheduler:
abtest: true
ascheduler: "a-scheduler"
bscheduler: "b-scheduler"

server:
ip: "127.0.0.1"
port: 8002

worker:
workerNum: 8
workerJobPoolSize: 10000
senderNum: 10
senderJobPoolSize: 10000

cdn:
servers:
- name: "cdn"
ip: "127.0.0.1"
rpcPort: 8003
downloadPort: 8001

gc:
taskDelay: 3600000
peerTaskDelay: 3600000
Expand All @@ -35,3 +40,7 @@ manager:
retryMaxAttempts: 100
retryInitBackOff: 100
retryMaxBackOff: 100

host:
idc: foo
location: bar
6 changes: 6 additions & 0 deletions scheduler/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ func (s *Server) Stop() (err error) {
func (s *Server) register(ctx context.Context) error {
ip := s.config.Server.IP
port := int32(s.config.Server.Port)
idc := s.config.Host.IDC
location := s.config.Host.Location

var scheduler *manager.Scheduler
var err error
Expand All @@ -178,13 +180,17 @@ func (s *Server) register(ctx context.Context) error {
HostName: iputils.HostName,
Ip: ip,
Port: port,
Idc: idc,
Location: location,
})
if err != nil {
scheduler, err = s.managerClient.UpdateScheduler(ctx, &manager.UpdateSchedulerRequest{
SourceType: manager.SourceType_SCHEDULER_SOURCE,
HostName: iputils.HostName,
Ip: ip,
Port: port,
Idc: idc,
Location: location,
})
if err != nil {
logger.Warnf("update scheduler to manager failed %v", err)
Expand Down