This is an automated email from the ASF dual-hosted git repository.
zike pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git
The following commit(s) were added to refs/heads/master by this push:
new 8fa0878c [Improve] Add admin api GetListActiveBrokers (#1212)
8fa0878c is described below
commit 8fa0878c88ee4b6e002c7764a10c79012b14be90
Author: crossoverJie <[email protected]>
AuthorDate: Tue May 7 11:13:11 2024 +0800
[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
---
pulsaradmin/pkg/admin/brokers.go | 13 +++++++++++++
pulsaradmin/pkg/admin/brokers_test.go | 15 +++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/pulsaradmin/pkg/admin/brokers.go b/pulsaradmin/pkg/admin/brokers.go
index 650fab8e..7dcea800 100644
--- a/pulsaradmin/pkg/admin/brokers.go
+++ b/pulsaradmin/pkg/admin/brokers.go
@@ -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)
@@ -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
diff --git a/pulsaradmin/pkg/admin/brokers_test.go
b/pulsaradmin/pkg/admin/brokers_test.go
index 97679759..3ae9e4ae 100644
--- a/pulsaradmin/pkg/admin/brokers_test.go
+++ b/pulsaradmin/pkg/admin/brokers_test.go
@@ -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)
+}