-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #828 from hashicorp/f-gc-endpoint
Job GC endpoint
- Loading branch information
Showing
12 changed files
with
391 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package api | ||
|
||
// Status is used to query the status-related endpoints. | ||
type System struct { | ||
client *Client | ||
} | ||
|
||
// System returns a handle on the system endpoints. | ||
func (c *Client) System() *System { | ||
return &System{client: c} | ||
} | ||
|
||
func (s *System) GarbageCollect() error { | ||
var req struct{} | ||
_, err := s.client.write("/v1/system/gc", &req, nil, nil) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package api | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSystem_GarbageCollect(t *testing.T) { | ||
c, s := makeClient(t, nil, nil) | ||
defer s.Stop() | ||
e := c.System() | ||
if err := e.GarbageCollect(); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package agent | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/hashicorp/nomad/nomad/structs" | ||
) | ||
|
||
func (s *HTTPServer) GarbageCollectRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { | ||
if req.Method != "PUT" { | ||
return nil, CodedError(405, ErrInvalidMethod) | ||
} | ||
|
||
var args structs.GenericRequest | ||
if s.parse(resp, req, &args.Region, &args.QueryOptions) { | ||
return nil, nil | ||
} | ||
|
||
var gResp structs.GenericResponse | ||
if err := s.agent.RPC("System.GarbageCollect", &args, &gResp); err != nil { | ||
return nil, err | ||
} | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package agent | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestHTTP_SystemGarbageCollect(t *testing.T) { | ||
httpTest(t, nil, func(s *TestServer) { | ||
// Make the HTTP request | ||
req, err := http.NewRequest("PUT", "/v1/system/gc", nil) | ||
if err != nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
respW := httptest.NewRecorder() | ||
|
||
// Make the request | ||
if _, err := s.Server.GarbageCollectRequest(respW, req); err != nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.