agent: adding ability to reload services and checks
This commit is contained in:
parent
7534346103
commit
fb34815562
|
@ -314,6 +314,16 @@ func (a *Agent) StartSync() {
|
||||||
go a.state.antiEntropy(a.shutdownCh)
|
go a.state.antiEntropy(a.shutdownCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PauseSync is called to pause anti-entropy while bulk changes are make
|
||||||
|
func (a *Agent) PauseSync() {
|
||||||
|
a.state.Pause()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResumeSync is called to to unpause anti-entropy after bulk changes are make
|
||||||
|
func (a *Agent) ResumeSync() {
|
||||||
|
a.state.Resume()
|
||||||
|
}
|
||||||
|
|
||||||
// AddService is used to add a service entry.
|
// AddService is used to add a service entry.
|
||||||
// This entry is persistent and the agent will make a best effort to
|
// This entry is persistent and the agent will make a best effort to
|
||||||
// ensure it is registered
|
// ensure it is registered
|
||||||
|
|
|
@ -323,7 +323,39 @@ func (c *Command) handleReload(config *Config) *Config {
|
||||||
newConf.LogLevel = config.LogLevel
|
newConf.LogLevel = config.LogLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Update the services and checks
|
// Bulk update the services and checks
|
||||||
|
c.agent.PauseSync()
|
||||||
|
defer c.agent.ResumeSync()
|
||||||
|
|
||||||
|
// Deregister the old services
|
||||||
|
for _, service := range config.Services {
|
||||||
|
ns := service.NodeService()
|
||||||
|
c.agent.RemoveService(ns.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deregister the old checks
|
||||||
|
for _, check := range config.Checks {
|
||||||
|
health := check.HealthCheck(config.NodeName)
|
||||||
|
c.agent.RemoveCheck(health.CheckID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register the services
|
||||||
|
for _, service := range newConf.Services {
|
||||||
|
ns := service.NodeService()
|
||||||
|
chkType := service.CheckType()
|
||||||
|
if err := c.agent.AddService(ns, chkType); err != nil {
|
||||||
|
c.Ui.Error(fmt.Sprintf("Failed to register service '%s': %v", service.Name, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register the checks
|
||||||
|
for _, check := range newConf.Checks {
|
||||||
|
health := check.HealthCheck(config.NodeName)
|
||||||
|
chkType := &check.CheckType
|
||||||
|
if err := c.agent.AddCheck(health, chkType); err != nil {
|
||||||
|
c.Ui.Error(fmt.Sprintf("Failed to register check '%s': %v %v", check.Name, err, check))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return newConf
|
return newConf
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,8 +97,8 @@ func (l *localState) Pause() {
|
||||||
atomic.StoreInt32(&l.paused, 1)
|
atomic.StoreInt32(&l.paused, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unpause is used to resume state syncronization
|
// Resume is used to resume state syncronization
|
||||||
func (l *localState) Unpause() {
|
func (l *localState) Resume() {
|
||||||
atomic.StoreInt32(&l.paused, 0)
|
atomic.StoreInt32(&l.paused, 0)
|
||||||
l.changeMade()
|
l.changeMade()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue