зеркало из https://github.com/github/vulcanizer.git
Коммит
4eaecb532f
10
ROADMAP.md
10
ROADMAP.md
|
@ -20,16 +20,20 @@ Functionality:
|
|||
* Enable or disable cluster allocation entirely
|
||||
|
||||
|
||||
### v0.2.0 - Proposed
|
||||
## v0.2.0 - [Released](https://github.com/github/vulcanizer/releases/tag/v0.2.0)
|
||||
|
||||
Handle more cases around repositories and snapshots.
|
||||
|
||||
Functionality:
|
||||
* List repositories
|
||||
* Verify a repository
|
||||
* Create a repository
|
||||
* Delete a snapshot
|
||||
|
||||
#### v0.2.1 - Proposed
|
||||
|
||||
Functionality:
|
||||
* List repositories
|
||||
* Create a repository
|
||||
|
||||
### v0.3.0 - Proposed
|
||||
|
||||
Show more information around shard allocation and recovery.
|
||||
|
|
45
es.go
45
es.go
|
@ -74,6 +74,10 @@ type snapshotWrapper struct {
|
|||
Snapshots []Snapshot `json:"snapshots"`
|
||||
}
|
||||
|
||||
type acknowledgedResponse struct {
|
||||
Acknowledged bool `json:"acknowledged"`
|
||||
}
|
||||
|
||||
//Holds information about an Elasticsearch snapshot, based on the snapshot API: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html
|
||||
type Snapshot struct {
|
||||
State string `json:"state"`
|
||||
|
@ -169,6 +173,14 @@ func (c *Client) buildPutRequest(path string) *gorequest.SuperAgent {
|
|||
return gorequest.New().Put(fmt.Sprintf("http://%s:%v/%s", c.Host, c.Port, path))
|
||||
}
|
||||
|
||||
func (c *Client) buildDeleteRequest(path string) *gorequest.SuperAgent {
|
||||
return gorequest.New().Delete(fmt.Sprintf("http://%s:%v/%s", c.Host, c.Port, path))
|
||||
}
|
||||
|
||||
func (c *Client) buildPostRequest(path string) *gorequest.SuperAgent {
|
||||
return gorequest.New().Post(fmt.Sprintf("http://%s:%v/%s", c.Host, c.Port, path))
|
||||
}
|
||||
|
||||
// Get current cluster settings for shard allocation exclusion rules.
|
||||
func (c *Client) GetClusterExcludeSettings() (ExcludeSettings, error) {
|
||||
body, err := handleErrWithBytes(c.buildGetRequest(clusterSettingsPath))
|
||||
|
@ -434,3 +446,36 @@ func (c *Client) GetSnapshotStatus(repository string, snapshot string) (Snapshot
|
|||
|
||||
return snapshotWrapper.Snapshots[0], nil
|
||||
}
|
||||
|
||||
//Delete a snapshot
|
||||
//
|
||||
//Use case: You want to delete older snapshots so that they don't take up extra space.
|
||||
func (c *Client) DeleteSnapshot(repository string, snapshot string) error {
|
||||
var response acknowledgedResponse
|
||||
|
||||
err := handleErrWithStruct(c.buildDeleteRequest(fmt.Sprintf("_snapshot/%s/%s", repository, snapshot)).Timeout(10*time.Minute), &response)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !response.Acknowledged {
|
||||
return fmt.Errorf(`Request to delete snapshot "%s" on respository "%s" was not acknowledged. %+v`, snapshot, repository, response)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
//Verify a snapshot repository
|
||||
//
|
||||
//Use case: Have Elasticsearch verify a repository to make sure that all nodes can access the snapshot location correctly.
|
||||
func (c *Client) VerifyRepository(repository string) (bool, error) {
|
||||
|
||||
_, err := handleErrWithBytes(c.buildPostRequest(fmt.Sprintf("_snapshot/%s/_verify", repository)))
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
|
38
es_test.go
38
es_test.go
|
@ -659,3 +659,41 @@ func TestGetSnapshotStatus(t *testing.T) {
|
|||
t.Errorf("Unexpected name, got %+v", snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteSnapshot(t *testing.T) {
|
||||
testSetup := &ServerSetup{
|
||||
Method: "DELETE",
|
||||
Path: "/_snapshot/octocat/snapshot1",
|
||||
Response: `{"acknowledged": true}`,
|
||||
}
|
||||
|
||||
host, port, ts := setupTestServers(t, []*ServerSetup{testSetup})
|
||||
defer ts.Close()
|
||||
client := NewClient(host, port)
|
||||
|
||||
err := client.DeleteSnapshot("octocat", "snapshot1")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error, got %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifyRepository(t *testing.T) {
|
||||
testSetup := &ServerSetup{
|
||||
Method: "POST",
|
||||
Path: "/_snapshot/octocat/_verify",
|
||||
Response: `{"nodes":{"YaTBa_BtRmOoz1bHKJeQ8w":{"name":"YaTBa_B"}}}`,
|
||||
}
|
||||
|
||||
host, port, ts := setupTestServers(t, []*ServerSetup{testSetup})
|
||||
defer ts.Close()
|
||||
client := NewClient(host, port)
|
||||
|
||||
verified, err := client.VerifyRepository("octocat")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error, got %s", err)
|
||||
}
|
||||
|
||||
if !verified {
|
||||
t.Errorf("Expected repository to be verified, got %v", verified)
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче