diff --git a/api/api.go b/api/api.go index f21455bba..32d9b87b0 100644 --- a/api/api.go +++ b/api/api.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -35,9 +34,6 @@ type QueryOptions struct { // If set, used as prefix for resource list searches Prefix string - - // If set, pretty print the response json. - Pretty bool } // WriteOptions are used to parameterize a write @@ -160,9 +156,6 @@ func (r *request) setQueryOptions(q *QueryOptions) { if q.Prefix != "" { r.params.Set("prefix", q.Prefix) } - if q.Pretty { - r.params.Set("pretty", "true") - } } // durToMsec converts a duration to a millisecond specified string @@ -272,29 +265,6 @@ func (c *Client) query(endpoint string, out interface{}, q *QueryOptions) (*Quer return qm, nil } -// rawQuery is used to do a GET request against an endpoint and return the raw -// string result. -func (c *Client) rawQuery(endpoint string, q *QueryOptions) (string, *QueryMeta, error) { - r := c.newRequest("GET", endpoint) - r.setQueryOptions(q) - rtt, resp, err := requireOK(c.doRequest(r)) - if err != nil { - return "", nil, err - } - defer resp.Body.Close() - - qm := &QueryMeta{} - parseQueryMeta(resp, qm) - qm.RequestTime = rtt - - raw, err := ioutil.ReadAll(resp.Body) - if err != nil { - return "", nil, err - } - - return string(raw), qm, nil -} - // write is used to do a PUT request against an endpoint // and serialize/deserialized using the standard Nomad conventions. func (c *Client) write(endpoint string, in, out interface{}, q *WriteOptions) (*WriteMeta, error) { diff --git a/api/jobs.go b/api/jobs.go index fc8720a03..9ff4d8376 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -63,20 +63,6 @@ func (j *Jobs) Info(jobID string, q *QueryOptions) (*Job, *QueryMeta, error) { return &resp, qm, nil } -// RawJob is used to retrieve information about a particular -// job given its unique ID and return the raw json. -func (j *Jobs) RawJob(jobID string, q *QueryOptions) (string, *QueryMeta, error) { - if q == nil { - q = &QueryOptions{} - } - q.Pretty = true - raw, qm, err := j.client.rawQuery("/v1/job/"+jobID, q) - if err != nil { - return "", nil, err - } - return raw, qm, nil -} - // Allocations is used to return the allocs for a given job ID. func (j *Jobs) Allocations(jobID string, q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error) { var resp []*AllocationListStub diff --git a/api/jobs_test.go b/api/jobs_test.go index a2659a667..45e6325df 100644 --- a/api/jobs_test.go +++ b/api/jobs_test.go @@ -83,39 +83,6 @@ func TestJobs_Info(t *testing.T) { } } -func TestJobs_RawJob(t *testing.T) { - c, s := makeClient(t, nil, nil) - defer s.Stop() - jobs := c.Jobs() - - // Trying to retrieve a job by ID before it exists - // returns an error - _, _, err := jobs.RawJob("job1", nil) - if err == nil || !strings.Contains(err.Error(), "not found") { - t.Fatalf("expected not found error, got: %#v", err) - } - - // Register the job - job := testJob() - _, wm, err := jobs.Register(job, nil) - if err != nil { - t.Fatalf("err: %s", err) - } - assertWriteMeta(t, wm) - - // Query the job again and ensure it exists - result, qm, err := jobs.RawJob("job1", nil) - if err != nil { - t.Fatalf("err: %s", err) - } - assertQueryMeta(t, qm) - - // Check that the result is what we expect - if result == "" || !strings.Contains(result, job.ID) { - t.Fatalf("expect: %#v, got: %#v", job, result) - } -} - func TestJobs_PrefixList(t *testing.T) { c, s := makeClient(t, nil, nil) defer s.Stop() diff --git a/command/inspect.go b/command/inspect.go index a519a6f31..3a77b8a3a 100644 --- a/command/inspect.go +++ b/command/inspect.go @@ -1,8 +1,11 @@ package command import ( + "encoding/json" "fmt" "strings" + + "github.com/hashicorp/nomad/api" ) type InspectCommand struct { @@ -74,13 +77,20 @@ func (c *InspectCommand) Run(args []string) int { } // Prefix lookup matched a single job - job, _, err := client.Jobs().RawJob(jobs[0].ID, nil) + job, _, err := client.Jobs().Info(jobs[0].ID, nil) if err != nil { c.Ui.Error(fmt.Sprintf("Error inspecting job: %s", err)) return 1 } // Print the contents of the job - c.Ui.Output(job) + req := api.RegisterJobRequest{job} + buf, err := json.MarshalIndent(req, "", " ") + if err != nil { + c.Ui.Error(fmt.Sprintf("Error converting job: %s", err)) + return 1 + } + + c.Ui.Output(string(buf)) return 0 }