func (n *Node) UpdateDrain(args *structs.NodeUpdateDrainRequest,
	reply *structs.NodeDrainUpdateResponse) error {
	if done, err := n.srv.forward("Node.UpdateDrain", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"nomad", "client", "update_drain"}, time.Now())

	// Verify the arguments
	if args.NodeID == "" {
		return fmt.Errorf("missing node ID for drain update")
	}

	// Look for the node
	snap, err := n.srv.fsm.State().Snapshot()
	if err != nil {
		return err
	}
	ws := memdb.NewWatchSet()
	node, err := snap.NodeByID(ws, args.NodeID)
	if err != nil {
		return err
	}
	if node == nil {
		return fmt.Errorf("node not found")
	}

	// Update the timestamp to
	node.StatusUpdatedAt = time.Now().Unix()

	// Commit this update via Raft
	var index uint64
	if node.Drain != args.Drain {
		_, index, err = n.srv.raftApply(structs.NodeUpdateDrainRequestType, args)
		if err != nil {
			n.srv.logger.Printf("[ERR] nomad.client: drain update failed: %v", err)
			return err
		}
		reply.NodeModifyIndex = index
	}

	// Always attempt to create Node evaluations because there may be a System
	// job registered that should be evaluated.
	evalIDs, evalIndex, err := n.createNodeEvals(args.NodeID, index)
	if err != nil {
		n.srv.logger.Printf("[ERR] nomad.client: eval creation failed: %v", err)
		return err
	}
	reply.EvalIDs = evalIDs
	reply.EvalCreateIndex = evalIndex

	// Set the reply index
	reply.Index = index
	return nil
}
// UpdateDrain is used to update the drain mode of a client node
UpdateDrain is used to update the drain mode of a client node
// UpdateDrain is used to update the drain mode of a client node
func (n *Node) UpdateDrain(args *structs.NodeUpdateDrainRequest,
	reply *structs.NodeDrainUpdateResponse) error {
	if done, err := n.srv.forward("Node.UpdateDrain", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"nomad", "client", "update_drain"}, time.Now())
	if args.NodeID == "" {
		return fmt.Errorf("missing node ID for drain update")
	}
	snap, err := n.srv.fsm.State().Snapshot()
	if err != nil {
		return err
	}
	ws := memdb.NewWatchSet()
	node, err := snap.NodeByID(ws, args.NodeID)
	if err != nil {
		return err
	}
	if node == nil {
		return fmt.Errorf("node not found")
	}
	node.StatusUpdatedAt = time.Now().Unix()
	var index uint64
	if node.Drain != args.Drain {
		_, index, err = n.srv.raftApply(structs.NodeUpdateDrainRequestType, args)
		if err != nil {
			n.srv.logger.Printf("[ERR] nomad.client: drain update failed: %v", err)
			return err
		}
		reply.NodeModifyIndex = index
	}
	evalIDs, evalIndex, err := n.createNodeEvals(args.NodeID, index)
	if err != nil {
		n.srv.logger.Printf("[ERR] nomad.client: eval creation failed: %v", err)
		return err
	}
	reply.EvalIDs = evalIDs
	reply.EvalCreateIndex = evalIndex
	reply.Index = index
	return nil
}
func ( n * Node ) UpdateDrain ( args * structs . NodeUpdateDrainRequest , reply * structs . NodeDrainUpdateResponse ) error { if done , err := n . srv . forward ( " " , args , args , reply ) ; done { return err } defer metrics . MeasureSince ( [ ] string { " " , " " , " " } , time . Now ( ) ) if args . NodeID == " " { return fmt . Errorf ( " " ) } snap , err := n . srv . fsm . State ( ) . Snapshot ( ) if err != nil { return err } ws := memdb . NewWatchSet ( ) node , err := snap . NodeByID ( ws , args . NodeID ) if err != nil { return err } if node == nil { return fmt . Errorf ( " " ) } node . StatusUpdatedAt = time . Now ( ) . Unix ( ) var index uint64 if node . Drain != args . Drain { _ , index , err = n . srv . raftApply ( structs . NodeUpdateDrainRequestType , args ) if err != nil { n . srv . logger . Printf ( " " , err ) return err } reply . NodeModifyIndex = index } evalIDs , evalIndex , err := n . createNodeEvals ( args . NodeID , index ) if err != nil { n . srv . logger . Printf ( " " , err ) return err } reply . EvalIDs = evalIDs reply . EvalCreateIndex = evalIndex reply . Index = index return nil }
UpdateDrain is used to update the drain mode of a client node
UpdateDrain is used to update the drain mode of a client node
// Verify the arguments // Look for the node // Update the timestamp to // Commit this update via Raft // Always attempt to create Node evaluations because there may be a System // job registered that should be evaluated. // Set the reply index