2015-09-06 22:37:21 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *HTTPServer) AllocsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
if req.Method != "GET" {
|
|
|
|
return nil, CodedError(405, ErrInvalidMethod)
|
|
|
|
}
|
|
|
|
|
|
|
|
args := structs.AllocListRequest{}
|
|
|
|
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var out structs.AllocListResponse
|
|
|
|
if err := s.agent.RPC("Alloc.List", &args, &out); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
setMeta(resp, &out.QueryMeta)
|
2015-09-07 17:03:10 +00:00
|
|
|
if out.Allocations == nil {
|
|
|
|
out.Allocations = make([]*structs.AllocListStub, 0)
|
|
|
|
}
|
2015-09-06 22:37:21 +00:00
|
|
|
return out.Allocations, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HTTPServer) AllocSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
allocID := strings.TrimPrefix(req.URL.Path, "/v1/allocation/")
|
2015-09-06 22:49:44 +00:00
|
|
|
if req.Method != "GET" {
|
2015-09-06 22:37:21 +00:00
|
|
|
return nil, CodedError(405, ErrInvalidMethod)
|
|
|
|
}
|
|
|
|
|
2015-09-06 22:49:44 +00:00
|
|
|
args := structs.AllocSpecificRequest{
|
|
|
|
AllocID: allocID,
|
|
|
|
}
|
|
|
|
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var out structs.SingleAllocResponse
|
|
|
|
if err := s.agent.RPC("Alloc.GetAlloc", &args, &out); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-09-06 22:37:21 +00:00
|
|
|
|
2015-09-06 22:49:44 +00:00
|
|
|
setMeta(resp, &out.QueryMeta)
|
|
|
|
if out.Alloc == nil {
|
|
|
|
return nil, CodedError(404, "alloc not found")
|
|
|
|
}
|
|
|
|
return out.Alloc, nil
|
2015-09-06 22:37:21 +00:00
|
|
|
}
|