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

	// Setup the blocking query
	opts := blockingOptions{
		queryOpts: &args.QueryOptions,
		queryMeta: &reply.QueryMeta,
		run: func(ws memdb.WatchSet, state *state.StateStore) error {
			// Capture all the nodes
			var err error
			var iter memdb.ResultIterator
			if prefix := args.QueryOptions.Prefix; prefix != "" {
				iter, err = state.NodesByIDPrefix(ws, prefix)
			} else {
				iter, err = state.Nodes(ws)
			}
			if err != nil {
				return err
			}

			var nodes []*structs.NodeListStub
			for {
				raw := iter.Next()
				if raw == nil {
					break
				}
				node := raw.(*structs.Node)
				nodes = append(nodes, node.Stub())
			}
			reply.Nodes = nodes

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

			// Set the query response
			n.srv.setQueryMeta(&reply.QueryMeta)
			return nil
		}}
	return n.srv.blockingRPC(&opts)
}
// List is used to list the available nodes
List is used to list the available nodes
// List is used to list the available nodes
func (n *Node) List(args *structs.NodeListRequest,
	reply *structs.NodeListResponse) error {
	if done, err := n.srv.forward("Node.List", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"nomad", "client", "list"}, time.Now())
	opts := blockingOptions{
		queryOpts: &args.QueryOptions,
		queryMeta: &reply.QueryMeta,
		run: func(ws memdb.WatchSet, state *state.StateStore) error {
			var err error
			var iter memdb.ResultIterator
			if prefix := args.QueryOptions.Prefix; prefix != "" {
				iter, err = state.NodesByIDPrefix(ws, prefix)
			} else {
				iter, err = state.Nodes(ws)
			}
			if err != nil {
				return err
			}
			var nodes []*structs.NodeListStub
			for {
				raw := iter.Next()
				if raw == nil {
					break
				}
				node := raw.(*structs.Node)
				nodes = append(nodes, node.Stub())
			}
			reply.Nodes = nodes
			index, err := state.Index("nodes")
			if err != nil {
				return err
			}
			reply.Index = index
			n.srv.setQueryMeta(&reply.QueryMeta)
			return nil
		}}
	return n.srv.blockingRPC(&opts)
}
func ( n * Node ) List ( args * structs . NodeListRequest , reply * structs . NodeListResponse ) error { if done , err := n . srv . forward ( " " , args , args , reply ) ; done { return err } defer metrics . MeasureSince ( [ ] string { " " , " " , " " } , time . Now ( ) ) opts := blockingOptions { queryOpts : & args . QueryOptions , queryMeta : & reply . QueryMeta , run : func ( ws memdb . WatchSet , state * state . StateStore ) error { var err error var iter memdb . ResultIterator if prefix := args . QueryOptions . Prefix ; prefix != " " { iter , err = state . NodesByIDPrefix ( ws , prefix ) } else { iter , err = state . Nodes ( ws ) } if err != nil { return err } var nodes [ ] * structs . NodeListStub for { raw := iter . Next ( ) if raw == nil { break } node := raw . ( * structs . Node ) nodes = append ( nodes , node . Stub ( ) ) } reply . Nodes = nodes index , err := state . Index ( " " ) if err != nil { return err } reply . Index = index n . srv . setQueryMeta ( & reply . QueryMeta ) return nil } } return n . srv . blockingRPC ( & opts ) }
List is used to list the available nodes
List is used to list the available nodes
// Setup the blocking query // Capture all the nodes // Use the last index that affected the jobs table // Set the query response