open-nomad/nomad/client_endpoint.go

50 lines
1.3 KiB
Go
Raw Normal View History

2015-06-07 19:14:41 +00:00
package nomad
import (
"fmt"
"time"
"github.com/armon/go-metrics"
"github.com/hashicorp/nomad/nomad/structs"
)
// Client endpoint is used for client interactions
type Client struct {
srv *Server
}
// Register is used to upsert a client that is available for scheduling
2015-07-04 01:41:36 +00:00
func (c *Client) Register(args *structs.RegisterRequest, reply *structs.GenericResponse) error {
2015-06-07 19:14:41 +00:00
if done, err := c.srv.forward("Client.Register", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "client", "register"}, time.Now())
// Validate the arguments
2015-07-04 00:47:55 +00:00
if args.Node == nil {
return fmt.Errorf("missing node for client registration")
}
if args.Node.ID == "" {
return fmt.Errorf("missing node ID for client registration")
}
if args.Node.Datacenter == "" {
2015-06-07 19:14:41 +00:00
return fmt.Errorf("missing datacenter for client registration")
}
2015-07-04 00:47:55 +00:00
if args.Node.Name == "" {
2015-06-07 19:14:41 +00:00
return fmt.Errorf("missing node name for client registration")
}
// Default the status if none is given
2015-07-04 00:47:55 +00:00
if args.Node.Status == "" {
args.Node.Status = structs.NodeStatusInit
2015-06-07 19:14:41 +00:00
}
// Commit this update via Raft
_, err := c.srv.raftApply(structs.RegisterRequestType, args)
if err != nil {
c.srv.logger.Printf("[ERR] nomad.client: Register failed: %v", err)
return err
}
return nil
}