Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for runtime parameters, e.g. for configuring federation upstream components. #150

Merged
merged 19 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,33 @@ resp, err := rmqc.DeleteShovel("/", "a.shovel")

```

### Operations on Federation Upstreams

```go
// list all upstreams
ups, err := rmqc.ListFederationUpstreams()
// => []FederationUpstream, error

// list upstreams in a vhost
ups, err := rmqc.ListFederationUpstreamsIn("/")
// => []FederationUpstream, error

// information about an upstream
up, err := rmqc.GetFederationUpstream("/", "upstream-name")
// => *FederationUpstream, error

// declare an upstream
resp, err := rmqc.PutFederationUpstream("/", "upstream-name", FederationDefinition{
Uri: "amqp://server-name",
})
// => *http.Response, error

// delete an upstream
resp, err := rmqc.DeleteFederationUpstream("/", "upstream-name")
// => *http.Response, error

```

### Operations on cluster name
``` go
// Get cluster name
Expand Down
4 changes: 4 additions & 0 deletions bin/ci/before_build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ call %RABBITHOLE_RABBITMQCTL% set_permissions -p "rabbit/hole" guest ".*" ".*" "
REM Enable shovel plugin
call %RABBITHOLE_RABBITMQ_PLUGINS% enable rabbitmq_shovel
call %RABBITHOLE_RABBITMQ_PLUGINS% enable rabbitmq_shovel_management

REM Enable shovel plugin
call %RABBITHOLE_RABBITMQ_PLUGINS% enable rabbitmq_federation
call %RABBITHOLE_RABBITMQ_PLUGINS% enable rabbitmq_federation_management
4 changes: 4 additions & 0 deletions bin/ci/before_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ $CTL set_cluster_name rabbitmq@localhost
# Enable shovel plugin
$PLUGINS enable rabbitmq_shovel
$PLUGINS enable rabbitmq_shovel_management

# Enable federation plugin
$PLUGINS enable rabbitmq_federation
$PLUGINS enable rabbitmq_federation_management
24 changes: 24 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,30 @@ Managing Topic Permissions
resp, err := rmqc.DeleteTopicPermissionsIn("/", "my.user", "exchange")
// => *http.Response, err

Managing Federation Upstreams

// list all upstreams
ups, err := rmqc.ListFederationUpstreams()
// => []FederationUpstream, error

// list upstreams in a vhost
ups, err := rmqc.ListFederationUpstreamsIn("/")
// => []FederationUpstream, error

// information about an upstream
up, err := rmqc.GetFederationUpstream("/", "upstream-name")
// => *FederationUpstream, error

// declare an upstream
resp, err := rmqc.PutFederationUpstream("/", "upstream-name", FederationDefinition{
Uri: "amqp://server-name",
})
// => *http.Response, error

// delete an upstream
resp, err := rmqc.DeleteFederationUpstream("/", "upstream-name")
// => *http.Response, error

Operations on cluster name
// Get cluster name
cn, err := rmqc.GetClusterName()
Expand Down
68 changes: 66 additions & 2 deletions federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,83 @@ type FederationDefinition struct {

// Represents a configured Federation upstream.
type FederationUpstream struct {
michaelklishin marked this conversation as resolved.
Show resolved Hide resolved
Name string `json:"name"`
Vhost string `json:"vhost"`
Component string `json:"component"`
Definition FederationDefinition `json:"value"`
}

// FederationDefinitionDTO provides a data transfer object for a FederationDefinition.
type FederationDefinitionDTO struct {
Definition FederationDefinition `json:"value"`
}

//
// GET /api/parameters/federation-upstream
//

// ListFederationUpstreams returns all federation upstreams
func (c *Client) ListFederationUpstreams() (rec []FederationUpstream, err error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be very nice to accompany this (and, perhaps, base it on) with a set of functions that would list, set, and delete arbitrary runtime parameters. Note that RabbitMQ nodes will perform parameter validation so if a component is not known (not registered by a plugin or RabbitMQ core), it will be rejected.

We can also add functions that work with parameters of a certain type. Then federation upstream management would rely on them and pass federation-upstream for component. How does this sound?

req, err := newGETRequest(c, "parameters/federation-upstream")
if err != nil {
return []FederationUpstream{}, err
}

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

return rec, nil
}

//
// GET /api/parameters/federation-upstream/{vhost}
//

// ListFederationUpstreamsIn returns all federation upstreams in a vhost
func (c *Client) ListFederationUpstreamsIn(vhost string) (rec []FederationUpstream, err error) {
req, err := newGETRequest(c, "parameters/federation-upstream/"+url.PathEscape(vhost))
if err != nil {
return []FederationUpstream{}, err
}

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

return rec, nil
}

//
// GET /api/parameters/federation-upstream/{vhost}/{upstream}
//

// GetFederationUpstream returns a federation upstream
func (c *Client) GetFederationUpstream(vhost, upstreamName string) (rec *FederationUpstream, err error) {
req, err := newGETRequest(c, "parameters/federation-upstream/"+url.PathEscape(vhost)+"/"+url.PathEscape(upstreamName))

if err != nil {
return nil, err
}

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

return rec, nil
}

//
// PUT /api/parameters/federation-upstream/{vhost}/{upstream}
//

// Updates a federation upstream
func (c *Client) PutFederationUpstream(vhost string, upstreamName string, fDef FederationDefinition) (res *http.Response, err error) {
fedUp := FederationUpstream{
fedDTO := FederationDefinitionDTO{
Definition: fDef,
}
body, err := json.Marshal(fedUp)

body, err := json.Marshal(fedDTO)
if err != nil {
return nil, err
}
Expand Down
Loading