[Improve] Add admin api GetListActiveBrokers (#1212)
### Motivation
To keep consistent with the [Java client](https://github.com/apache/pulsar/pull/14702).
### Modifications
Add admin api GetListActiveBrokers
diff --git a/pulsaradmin/pkg/admin/brokers.go b/pulsaradmin/pkg/admin/brokers.go
index 650fab8..7dcea80 100644
--- a/pulsaradmin/pkg/admin/brokers.go
+++ b/pulsaradmin/pkg/admin/brokers.go
@@ -27,6 +27,9 @@
// 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)
@@ -86,6 +89,16 @@
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
diff --git a/pulsaradmin/pkg/admin/brokers_test.go b/pulsaradmin/pkg/admin/brokers_test.go
index 9767975..3ae9e4a 100644
--- a/pulsaradmin/pkg/admin/brokers_test.go
+++ b/pulsaradmin/pkg/admin/brokers_test.go
@@ -58,3 +58,18 @@
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)
+}