Skip to content

Commit

Permalink
- Add support to manipulate cluster name
Browse files Browse the repository at this point in the history
  GetClusterName() to fetch cluster name
  SetClusterName() to rename the cluster
  • Loading branch information
sheepkiller committed Jul 21, 2017
1 parent e4c5f41 commit 21a9e87
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ resp, err := rmqc.DeleteShovel("/", "a.shovel")

```

### Operations on cluster name
``` go
// Get cluster name
cn, err := rmqc.GetClusterName()
// => ClusterName, err

// Rename cluster
resp, err := rmqc.SetClusterName(ClusterName{Name: "rabbitmq@rabbit-hole"})
// => *http.Response, err

```

### HTTPS Connections

``` go
Expand All @@ -302,7 +314,7 @@ rmqc, err := NewTLSClient("https://127.0.0.1:15672", "guest", "guest", transport
``` go
var transport *http.Transport

...
...

rmqc.SetTransport(transport)
```
Expand Down
3 changes: 3 additions & 0 deletions bin/ci/before_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ $CTL eval 'supervisor2:terminate_child(rabbit_mgmt_agent_sup_sup, rabbit_mgmt_ag
$CTL add_vhost "rabbit/hole"
$CTL set_permissions -p "rabbit/hole" guest ".*" ".*" ".*"

# set cluster name
$CTL set_cluster_name rabbitmq@localhost

# Enable shovel plugin
$PLUGINS enable rabbitmq_shovel
$PLUGINS enable rabbitmq_shovel_management
38 changes: 38 additions & 0 deletions cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package rabbithole

import (
"encoding/json"
"net/http"
)

type ClusterName struct {
Name string `json:"name"`
}

func (c *Client) GetClusterName() (rec *ClusterName, err error) {
req, err := newGETRequest(c, "cluster-name/")
if err != nil {
return nil, err
}

if err = executeAndParseRequest(c, req, &rec); err != nil {
return nil, err
}

return rec, nil
}

func (c *Client) SetClusterName(cn ClusterName) (res *http.Response, err error) {
body, err := json.Marshal(cn)
if err != nil {
return nil, err
}
req, err := newRequestWithBody(c, "PUT", "cluster-name", body)
if err != nil {
return nil, err
}

res, err = executeRequest(c, req)

return res, nil
}
9 changes: 9 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,14 @@ Managing Permissions
// revokes permissions in vhost
resp, err := rmqc.ClearPermissionsIn("/", "my.user")
// => *http.Response, err
Operations on cluster name
// Get cluster name
cn, err := rmqc.GetClusterName()
// => ClusterName, err
// Rename cluster
resp, err := rmqc.SetClusterName(ClusterName{Name: "rabbitmq@rabbit-hole"})
// => *http.Response, err
*/
package rabbithole
21 changes: 21 additions & 0 deletions rabbithole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,27 @@ var _ = Describe("Rabbithole", func() {
})
})

Context("PUT /cluster-name", func() {
It("Set cluster name", func() {
previousClusterName, err := rmqc.GetClusterName()
Ω(err).Should(BeNil())
Ω(previousClusterName.Name).Should(Equal("rabbitmq@localhost"))
cnStr := "rabbitmq@rabbit-hole-test"
cn := ClusterName{Name: cnStr}
resp, err := rmqc.SetClusterName(cn)
Ω(err).Should(BeNil())
Ω(resp.Status).Should(Equal("204 No Content"))
awaitEventPropagation()
cn2, err := rmqc.GetClusterName()
Ω(err).Should(BeNil())
Ω(cn2.Name).Should(Equal(cnStr))
// Restore cluster name
rmqc.SetClusterName(*previousClusterName)
Ω(err).Should(BeNil())
Ω(resp.Status).Should(Equal("204 No Content"))
})
})

Context("GET /connections when there are active connections", func() {
It("returns decoded response", func() {
// this really should be tested with > 1 connection and channel. MK.
Expand Down

0 comments on commit 21a9e87

Please sign in to comment.