Skip to content

Commit

Permalink
[CLOUDGA-23248] : CLI Get Cluster - Add CP Status (#248)
Browse files Browse the repository at this point in the history
* [CLOUDGA-23248] : CLI Get Cluster - Add CP Status

* Fixed UTs

* WIP

* UTs fixed

---------

Co-authored-by: Aditya Kaushik <[email protected]>
  • Loading branch information
adityakaushik99-yb and Aditya Kaushik authored Sep 10, 2024
1 parent 0c32861 commit 940db37
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ var _ = Describe("Cluster", func() {
Expect(err).NotTo(HaveOccurred())
session.Wait(2)
o := string(session.Out.Contents()[:])
expected := `Name Tier Version State Health Provider Regions Nodes Node Res.(Vcpu/Mem/DiskGB/IOPS)
stunning-sole Dedicated 2.16.0.1-b7 ACTIVE 💚 AWS us-west-2 1 2 / 8GB / 100GB / -` + "\n"
expected := `Name Tier Version State Health Provider Regions Nodes Node Res.(Vcpu/Mem/DiskGB/IOPS) Connection Pooling Enabled
stunning-sole Dedicated 2.16.0.1-b7 ACTIVE 💚 AWS us-west-2 1 2 / 8GB / 100GB / - false` + "\n"
Expect(o).Should(Equal(expected))
session.Kill()
})
Expand Down
11 changes: 10 additions & 1 deletion internal/formatter/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ import (
)

const (
defaultClusterListing = "table {{.Name}}\t{{.Tier}}\t{{.SoftwareVersion}}\t{{.State}}\t{{.HealthState}}\t{{.Provider}}\t{{.Regions}}\t{{.Nodes}}\t{{.NodesSpec}}"
defaultClusterListing = "table {{.Name}}\t{{.Tier}}\t{{.SoftwareVersion}}\t{{.State}}\t{{.HealthState}}\t{{.Provider}}\t{{.Regions}}\t{{.Nodes}}\t{{.NodesSpec}}\t{{.ConnectionPoolingStatus}}"
numNodesHeader = "Nodes"
nodeInfoHeader = "Node Res.(Vcpu/Mem/DiskGB/IOPS)"
healthStateHeader = "Health"
tierHeader = "Tier"
connectionPoolingHeader = "Connection Pooling Enabled"
)

type ClusterContext struct {
Expand Down Expand Up @@ -86,6 +87,7 @@ func NewClusterContext() *ClusterContext {
"FaultTolerance": faultToleranceHeader,
"DataDistribution": dataDistributionHeader,
"Tier": tierHeader,
"ConnectionPoolingStatus": connectionPoolingHeader,
}
return &clusterCtx
}
Expand Down Expand Up @@ -129,6 +131,13 @@ func (c *ClusterContext) SoftwareVersion() string {
return ""
}

func (c *ClusterContext) ConnectionPoolingStatus() bool {
if v, ok := c.c.Info.GetIsConnectionPoolingEnabledOk(); ok {
return *v
}
return false
}

func (c *ClusterContext) HealthState() string {
if v, ok := c.c.Info.GetHealthInfoOk(); ok {
return clusterHealthStateToEmoji(v.GetState())
Expand Down
11 changes: 10 additions & 1 deletion internal/formatter/clusters_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import (
"github.com/sirupsen/logrus"
"github.com/yugabyte/ybm-cli/internal/client"
"github.com/yugabyte/ybm-cli/internal/cluster"
"github.com/yugabyte/ybm-cli/cmd/util"
ybmclient "github.com/yugabyte/yugabytedb-managed-go-client-internal"
"golang.org/x/exp/slices"
)

const (
defaultFullClusterGeneral = "table {{.Name}}\t{{.ID}}\t{{.SoftwareVersion}}\t{{.State}}\t{{.HealthState}}"
defaultFullClusterGeneral2 = "table {{.Provider}}\t{{.Tier}}\t{{.FaultTolerance}}\t{{.Nodes}}\t{{.NodesSpec}}"
defaultFullClusterGeneral2v2 = "table {{.Provider}}\t{{.Tier}}\t{{.FaultTolerance}}\t{{.Nodes}}\t{{.NodesSpec}}\t{{.ConnectionPoolingStatus}}"
defaultVPCListingCluster = "table {{.Name}}\t{{.State}}\t{{.Provider}}\t{{.Regions}}\t{{.CIDR}}\t{{.Peerings}}"
defaultDefaultFullClusterRegion = "table {{.Region}}\t{{.NumNode}}\t{{.NumCores}}\t{{.MemoryGb}}\t{{.DiskSizeGb}}\t{{.VpcName}}"
defaultFullClusterNalListing = "table {{.Name}}\t{{.Desc}}\t{{.AllowedList}}"
Expand Down Expand Up @@ -157,7 +159,14 @@ func (c *FullClusterContext) Write() error {
}
c.postFormat(tmpl, NewClusterContext())

tmpl, err = c.startSubsection(defaultFullClusterGeneral2)


if util.IsFeatureFlagEnabled(util.CONNECTION_POOLING) {
tmpl, err = c.startSubsection(defaultFullClusterGeneral2v2)
} else {
tmpl, err = c.startSubsection(defaultFullClusterGeneral2)
}

if err != nil {
return err
}
Expand Down

0 comments on commit 940db37

Please sign in to comment.