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

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

	// Setup the blocking query
	opts := blockingOptions{
		queryOpts: &args.QueryOptions,
		queryMeta: &reply.QueryMeta,
		run: func(ws memdb.WatchSet, state *state.StateStore) error {
			// Look for the node
			allocs, err := state.AllocsByNode(ws, args.NodeID)
			if err != nil {
				return err
			}

			// Setup the output
			if len(allocs) != 0 {
				reply.Allocs = allocs
				for _, alloc := range allocs {
					reply.Index = maxUint64(reply.Index, alloc.ModifyIndex)
				}
			} else {
				reply.Allocs = nil

				// Use the last index that affected the nodes table
				index, err := state.Index("allocs")
				if err != nil {
					return err
				}

				// Must provide non-zero index to prevent blocking
				// Index 1 is impossible anyways (due to Raft internals)
				if index == 0 {
					reply.Index = 1
				} else {
					reply.Index = index
				}
			}
			return nil
		}}
	return n.srv.blockingRPC(&opts)
}
// GetAllocs is used to request allocations for a specific node
GetAllocs is used to request allocations for a specific node
// GetAllocs is used to request allocations for a specific node
func (n *Node) GetAllocs(args *structs.NodeSpecificRequest,
	reply *structs.NodeAllocsResponse) error {
	if done, err := n.srv.forward("Node.GetAllocs", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"nomad", "client", "get_allocs"}, time.Now())
	if args.NodeID == "" {
		return fmt.Errorf("missing node ID")
	}
	opts := blockingOptions{
		queryOpts: &args.QueryOptions,
		queryMeta: &reply.QueryMeta,
		run: func(ws memdb.WatchSet, state *state.StateStore) error {
			allocs, err := state.AllocsByNode(ws, args.NodeID)
			if err != nil {
				return err
			}
			if len(allocs) != 0 {
				reply.Allocs = allocs
				for _, alloc := range allocs {
					reply.Index = maxUint64(reply.Index, alloc.ModifyIndex)
				}
			} else {
				reply.Allocs = nil
				index, err := state.Index("allocs")
				if err != nil {
					return err
				}
				if index == 0 {
					reply.Index = 1
				} else {
					reply.Index = index
				}
			}
			return nil
		}}
	return n.srv.blockingRPC(&opts)
}
func ( n * Node ) GetAllocs ( args * structs . NodeSpecificRequest , reply * structs . NodeAllocsResponse ) 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 ( " " ) } opts := blockingOptions { queryOpts : & args . QueryOptions , queryMeta : & reply . QueryMeta , run : func ( ws memdb . WatchSet , state * state . StateStore ) error { allocs , err := state . AllocsByNode ( ws , args . NodeID ) if err != nil { return err } if len ( allocs ) != 0 { reply . Allocs = allocs for _ , alloc := range allocs { reply . Index = maxUint64 ( reply . Index , alloc . ModifyIndex ) } } else { reply . Allocs = nil index , err := state . Index ( " " ) if err != nil { return err } if index == 0 { reply . Index = 1 } else { reply . Index = index } } return nil } } return n . srv . blockingRPC ( & opts ) }
GetAllocs is used to request allocations for a specific node
GetAllocs is used to request allocations for a specific node
// Verify the arguments // Setup the blocking query // Look for the node // Setup the output // Use the last index that affected the nodes table // Must provide non-zero index to prevent blocking // Index 1 is impossible anyways (due to Raft internals)