mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
agent: use the client
This commit is contained in:
@@ -143,6 +143,12 @@ func NewClient(config *Config) (*Client, error) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Leave is used to prepare the client to leave the cluster
|
||||
func (c *Client) Leave() error {
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
// Shutdown is used to tear down the client
|
||||
func (c *Client) Shutdown() error {
|
||||
c.logger.Printf("[INFO] client: shutting down")
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/nomad/client"
|
||||
"github.com/hashicorp/nomad/nomad"
|
||||
)
|
||||
|
||||
@@ -20,7 +21,7 @@ type Agent struct {
|
||||
logOutput io.Writer
|
||||
|
||||
server *nomad.Server
|
||||
client *nomad.Server // TODO
|
||||
client *client.Client
|
||||
|
||||
shutdown bool
|
||||
shutdownCh chan struct{}
|
||||
@@ -46,6 +47,16 @@ func NewAgent(config *Config, logOutput io.Writer) (*Agent, error) {
|
||||
// Leave is used gracefully exit. Clients will inform servers
|
||||
// of their departure so that allocations can be rescheduled.
|
||||
func (a *Agent) Leave() error {
|
||||
if a.client != nil {
|
||||
if err := a.client.Leave(); err != nil {
|
||||
a.logger.Printf("[ERR] agent: client leave failed: %v", err)
|
||||
}
|
||||
}
|
||||
if a.server != nil {
|
||||
if err := a.server.Leave(); err != nil {
|
||||
a.logger.Printf("[ERR] agent: server leave failed: %v", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -59,17 +70,21 @@ func (a *Agent) Shutdown() error {
|
||||
}
|
||||
|
||||
a.logger.Println("[INFO] agent: requesting shutdown")
|
||||
var err error
|
||||
if a.client != nil {
|
||||
if err := a.client.Shutdown(); err != nil {
|
||||
a.logger.Printf("[ERR] agent: client shutdown failed: %v", err)
|
||||
}
|
||||
}
|
||||
if a.server != nil {
|
||||
err = a.server.Shutdown()
|
||||
} else {
|
||||
err = a.client.Shutdown()
|
||||
if err := a.server.Shutdown(); err != nil {
|
||||
a.logger.Printf("[ERR] agent: server shutdown failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
a.logger.Println("[INFO] agent: shutdown complete")
|
||||
a.shutdown = true
|
||||
close(a.shutdownCh)
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// RPC is used to make an RPC call to the Nomad servers
|
||||
|
||||
Reference in New Issue
Block a user