Files
nomad/command/agent/resources_endpoint.go
Chelsea Holland Komlo b2df34cf18 further refactoring
2017-08-04 22:50:41 +00:00

32 lines
861 B
Go

package agent
import (
"github.com/hashicorp/nomad/nomad/structs"
"net/http"
)
// ResourceListRequest accepts a prefix and context and returns a list of matching
// IDs for that context.
func (s *HTTPServer) ResourceListRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method == "POST" || req.Method == "PUT" {
return s.resourcesRequest(resp, req)
}
return nil, CodedError(405, ErrInvalidMethod)
}
func (s *HTTPServer) resourcesRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
args := structs.ResourceListRequest{}
if err := decodeBody(req, &args); err != nil {
return nil, CodedError(400, err.Error())
}
var out structs.ResourceListResponse
if err := s.agent.RPC("Resources.List", &args, &out); err != nil {
return nil, err
}
setMeta(resp, &out.QueryMeta)
return out, nil
}