func (n *Node) GetClientAllocs(args *structs.NodeSpecificRequest,
	reply *structs.NodeClientAllocsResponse) error {
	if done, err := n.srv.forward("Node.GetClientAllocs", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"nomad", "client", "get_client_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
			node, err := state.NodeByID(ws, args.NodeID)
			if err != nil {
				return err
			}

			var allocs []*structs.Allocation
			if node != nil {
				// COMPAT: Remove in 0.6
				// Check if the node should have a SecretID set
				if args.SecretID == "" {
					if pre, err := nodePreSecretID(node); err != nil {
						return err
					} else if !pre {
						return fmt.Errorf("missing node secret ID for client status update")
					}
				} else if args.SecretID != node.SecretID {
					return fmt.Errorf("node secret ID does not match")
				}

				var err error
				allocs, err = state.AllocsByNode(ws, args.NodeID)
				if err != nil {
					return err
				}
			}

			reply.Allocs = make(map[string]uint64)
			// Setup the output
			if len(allocs) != 0 {
				for _, alloc := range allocs {
					reply.Allocs[alloc.ID] = alloc.AllocModifyIndex
					reply.Index = maxUint64(reply.Index, alloc.ModifyIndex)
				}
			} else {
				// 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)
}
// GetClientAllocs is used to request a lightweight list of alloc modify indexes
// per allocation.
GetClientAllocs is used to request a lightweight list of alloc modify indexes
per allocation.
// GetClientAllocs is used to request a lightweight list of alloc modify indexes // per allocation .
func (n *Node) GetClientAllocs(args *structs.NodeSpecificRequest,
	reply *structs.NodeClientAllocsResponse) error {
	if done, err := n.srv.forward("Node.GetClientAllocs", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"nomad", "client", "get_client_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 {
			node, err := state.NodeByID(ws, args.NodeID)
			if err != nil {
				return err
			}
			var allocs []*structs.Allocation
			if node != nil {
				if args.SecretID == "" {
					if pre, err := nodePreSecretID(node); err != nil {
						return err
					} else if !pre {
						return fmt.Errorf("missing node secret ID for client status update")
					}
				} else if args.SecretID != node.SecretID {
					return fmt.Errorf("node secret ID does not match")
				}
				var err error
				allocs, err = state.AllocsByNode(ws, args.NodeID)
				if err != nil {
					return err
				}
			}
			reply.Allocs = make(map[string]uint64)
			if len(allocs) != 0 {
				for _, alloc := range allocs {
					reply.Allocs[alloc.ID] = alloc.AllocModifyIndex
					reply.Index = maxUint64(reply.Index, alloc.ModifyIndex)
				}
			} else {
				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 ) GetClientAllocs ( args * structs . NodeSpecificRequest , reply * structs . NodeClientAllocsResponse ) 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 { node , err := state . NodeByID ( ws , args . NodeID ) if err != nil { return err } var allocs [ ] * structs . Allocation if node != nil { if args . SecretID == " " { if pre , err := nodePreSecretID ( node ) ; err != nil { return err } else if ! pre { return fmt . Errorf ( " " ) } } else if args . SecretID != node . SecretID { return fmt . Errorf ( " " ) } var err error allocs , err = state . AllocsByNode ( ws , args . NodeID ) if err != nil { return err } } reply . Allocs = make ( map [ string ] uint64 ) if len ( allocs ) != 0 { for _ , alloc := range allocs { reply . Allocs [ alloc . ID ] = alloc . AllocModifyIndex reply . Index = maxUint64 ( reply . Index , alloc . ModifyIndex ) } } else { 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 ) }
GetClientAllocs is used to request a lightweight list of alloc modify indexes
per allocation.
GetClientAllocs is used to request a lightweight list of alloc modify indexes per allocation .
// Verify the arguments // Setup the blocking query // Look for the node // COMPAT: Remove in 0.6 // Check if the node should have a SecretID set // 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)