agent: adding ability to reload services and checks

This commit is contained in:
Armon Dadgar 2014-02-07 12:19:56 -08:00
parent c1637b4978
commit e12e5f7f68
3 changed files with 45 additions and 3 deletions

View File

@ -314,6 +314,16 @@ func (a *Agent) StartSync() {
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.
// This entry is persistent and the agent will make a best effort to
// ensure it is registered

View File

@ -323,7 +323,39 @@ func (c *Command) handleReload(config *Config) *Config {
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
}

View File

@ -97,8 +97,8 @@ func (l *localState) Pause() {
atomic.StoreInt32(&l.paused, 1)
}
// Unpause is used to resume state syncronization
func (l *localState) Unpause() {
// Resume is used to resume state syncronization
func (l *localState) Resume() {
atomic.StoreInt32(&l.paused, 0)
l.changeMade()
}