Browse Source

agent: adding ability to reload services and checks

pull/19/head
Armon Dadgar 11 years ago
parent
commit
e12e5f7f68
  1. 10
      command/agent/agent.go
  2. 34
      command/agent/command.go
  3. 4
      command/agent/local.go

10
command/agent/agent.go

@ -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

34
command/agent/command.go

@ -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
}

4
command/agent/local.go

@ -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()
}

Loading…
Cancel
Save