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

[Improve] Add admin api GetListActiveBrokers #1212

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions pulsaradmin/pkg/admin/brokers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import (

// Brokers is admin interface for brokers management
type Brokers interface {

// GetListActiveBrokers Get the list of active brokers in the local cluster.
GetListActiveBrokers() ([]string, error)
// GetActiveBrokers returns the list of active brokers in the cluster.
GetActiveBrokers(cluster string) ([]string, error)

Expand Down Expand Up @@ -86,6 +89,16 @@ func (b *broker) GetActiveBrokers(cluster string) ([]string, error) {
return res, nil
}

func (b *broker) GetListActiveBrokers() ([]string, error) {
endpoint := b.pulsar.endpoint(b.basePath)
var res []string
err := b.pulsar.Client.Get(endpoint, &res)
if err != nil {
return nil, err
}
return res, nil
}

func (b *broker) GetDynamicConfigurationNames() ([]string, error) {
endpoint := b.pulsar.endpoint(b.basePath, "/configuration/")
var res []string
Expand Down
15 changes: 15 additions & 0 deletions pulsaradmin/pkg/admin/brokers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ func TestGetLeaderBroker(t *testing.T) {
assert.NotEmpty(t, leaderBroker.ServiceURL)
assert.NotEmpty(t, leaderBroker.BrokerID)
}

func TestGetAllActiveBrokers(t *testing.T) {
readFile, err := os.ReadFile("../../../integration-tests/tokens/admin-token")
assert.NoError(t, err)
cfg := &config.Config{
Token: string(readFile),
}
admin, err := New(cfg)
assert.NoError(t, err)
assert.NotNil(t, admin)

brokers, err := admin.Brokers().GetListActiveBrokers()
assert.NoError(t, err)
assert.NotEmpty(t, brokers)
}
Loading