Skip to content

Commit

Permalink
Add queue getters
Browse files Browse the repository at this point in the history
Signed-off-by: raihankhan <[email protected]>
  • Loading branch information
raihankhan committed May 23, 2024
1 parent 298fa81 commit a728695
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module kubedb.dev/db-client-go

go 1.22.0

toolchain go1.22.1

require (
github.com/IBM/sarama v1.42.1
github.com/Masterminds/semver/v3 v3.2.1
Expand Down
74 changes: 74 additions & 0 deletions rabbitmq/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package rabbitmq

import (
"fmt"

Check failure on line 20 in rabbitmq/http_client.go

View workflow job for this annotation

GitHub Actions / Build

File is not `goimports`-ed (goimports)
rabbithole "github.com/michaelklishin/rabbit-hole/v2"
"k8s.io/klog/v2"
)

Expand All @@ -42,3 +43,76 @@ func (c *HTTPClient) IsAllNodesRunningInCluster(replicas int) (bool, error) {
klog.Info("All required nodes running in cluster")
return true, nil
}

func (c *HTTPClient) getQueues() ([]rabbithole.QueueInfo, error) {

Check failure on line 47 in rabbitmq/http_client.go

View workflow job for this annotation

GitHub Actions / Build

func `(*HTTPClient).getQueues` is unused (unused)
queues, err := c.Client.ListQueues()
if err != nil {
klog.Error(err, "Failed to get queue lists")
return nil, err
}
return queues, nil
}

func (c *HTTPClient) getClassicQueues() ([]rabbithole.QueueInfo, error) {

Check failure on line 56 in rabbitmq/http_client.go

View workflow job for this annotation

GitHub Actions / Build

func `(*HTTPClient).getClassicQueues` is unused (unused)
queues, err := c.getQueues()
if err != nil {
klog.Error(err, "Failed to get queue lists")
return nil, err
}
classicQueues := []rabbithole.QueueInfo{}

for _, q := range queues {
if q.Type == rabbitmqQueueTypeClassic {
classicQueues = append(classicQueues, q)
}
}

return classicQueues, nil
}

func (c *HTTPClient) hasNodeAnyClassicQueue(queues []rabbithole.QueueInfo, node string) bool {

Check failure on line 73 in rabbitmq/http_client.go

View workflow job for this annotation

GitHub Actions / Build

func `(*HTTPClient).hasNodeAnyClassicQueue` is unused (unused)
for _, q := range queues {
if q.Type == rabbitmqQueueTypeClassic && q.Node == node {
return true
}
}
return false
}

func (c *HTTPClient) getQuorumQueues() ([]rabbithole.QueueInfo, error) {

Check failure on line 82 in rabbitmq/http_client.go

View workflow job for this annotation

GitHub Actions / Build

func `(*HTTPClient).getQuorumQueues` is unused (unused)
queues, err := c.getQueues()
if err != nil {
klog.Error(err, "Failed to get queue lists")
return nil, err
}
quorumQueues := []rabbithole.QueueInfo{}

for _, q := range queues {
if q.Type == rabbitmqQueueTypeQuorum {
quorumQueues = append(quorumQueues, q)
}
}

return quorumQueues, nil
}

func (c *HTTPClient) hasNodeAnyQuorumQueue(queues []rabbithole.QueueInfo, node string) bool {

Check failure on line 99 in rabbitmq/http_client.go

View workflow job for this annotation

GitHub Actions / Build

func `(*HTTPClient).hasNodeAnyQuorumQueue` is unused (unused)
for _, q := range queues {
if q.Type == rabbitmqQueueTypeQuorum && q.Node == node {
return true
}
}
return false
}

func (c *HTTPClient) getNodeNameFromPodURL(url string) string {

Check failure on line 108 in rabbitmq/http_client.go

View workflow job for this annotation

GitHub Actions / Build

func `(*HTTPClient).getNodeNameFromPodURL` is unused (unused)
podClient, err := rabbithole.NewClient(url, c.Username, c.Password)
if err != nil {
return ""
}
overview, err := podClient.Overview()
if err != nil {
return ""
}
return overview.Node
}
5 changes: 5 additions & 0 deletions rabbitmq/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ type KubeDBClientBuilder struct {
disableAMQPClient bool
}

const (
rabbitmqQueueTypeQuorum = "quorum"

Check failure on line 48 in rabbitmq/kubedb_client_builder.go

View workflow job for this annotation

GitHub Actions / Build

const `rabbitmqQueueTypeQuorum` is unused (unused)
rabbitmqQueueTypeClassic = "classic"

Check failure on line 49 in rabbitmq/kubedb_client_builder.go

View workflow job for this annotation

GitHub Actions / Build

const `rabbitmqQueueTypeClassic` is unused (unused)
)

func NewKubeDBClientBuilder(kc client.Client, db *api.RabbitMQ) *KubeDBClientBuilder {
return &KubeDBClientBuilder{
kc: kc,
Expand Down

0 comments on commit a728695

Please sign in to comment.