Skip to content

Commit

Permalink
[PLAT-16058][YBA CLI] Release management APIs - list, get
Browse files Browse the repository at this point in the history
Summary:
Add list and get command for YBDB releases
List:
```
./yba yb-db-version list -h
List YugabyteDB versions

Usage:
  yba yb-db-version list [flags]

Aliases:
  list, ls

Examples:
yba yb-db-version list

Flags:
      --deployment-type string   [Optional] Deployment type of the YugabyteDB version. Allowed values: x86_64, aarch64, kubernetes
      --type string              [Optional] Release type. Allowed values: lts, sts, preview
  -h, --help                     help for list

Global Flags:
  -a, --apiToken string    YugabyteDB Anywhere api token.
      --config string      Config file, defaults to $HOME/.yba-cli.yaml
      --debug              Use debug mode, same as --logLevel debug.
      --disable-color      Disable colors in output. (default false)
  -H, --host string        YugabyteDB Anywhere Host (default "http://localhost:9000")
  -l, --logLevel string    Select the desired log level format. Allowed values: debug, info, warn, error, fatal. (default "info")
  -o, --output string      Select the desired output format. Allowed values: table, json, pretty. (default "table")
      --timeout duration   Wait command timeout, example: 5m, 1h. (default 168h0m0s)
      --wait               Wait until the task is completed, otherwise it will exit immediately. (default true)
```

Describe:
```
./yba yb-db-version describe
Describe a version of YugabyteDB

Usage:
  yba yb-db-version describe [flags]

Aliases:
  describe, get

Examples:
yba yb-db-version describe --version <version>

Flags:
  -v, --version string           [Required] The version to be described.
      --deployment-type string   [Optional] Deployment type of the YugabyteDB version. Allowed values: x86_64, aarch64, kubernetes
  -h, --help                     help for describe

Global Flags:
  -a, --apiToken string    YugabyteDB Anywhere api token.
      --config string      Config file, defaults to $HOME/.yba-cli.yaml
      --debug              Use debug mode, same as --logLevel debug.
      --disable-color      Disable colors in output. (default false)
  -H, --host string        YugabyteDB Anywhere Host (default "http://localhost:9000")
  -l, --logLevel string    Select the desired log level format. Allowed values: debug, info, warn, error, fatal. (default "info")
  -o, --output string      Select the desired output format. Allowed values: table, json, pretty. (default "table")
      --timeout duration   Wait command timeout, example: 5m, 1h. (default 168h0m0s)
      --wait               Wait until the task is completed, otherwise it will exit immediately. (default true)
```

Test Plan:
List:
```
./yba yb-db-version list
YugabyteDB Version                                             UUID                                   Release Type        Architecture         Release Date                      State
2024.1.2.0-b77                                                 73c8b6dd-a603-4117-9ab9-d6ec696c15ae   STS                 x86_64, kubernetes                                     ACTIVE
2.20.3.1-b2                                                    a3aa06c2-c9d8-4a52-85e6-03915a4c6588   LTS                 x86_64                                                 ACTIVE
2.20.3.1-b2-sanketh                                            d53f5835-9094-4cc3-a707-3fdccaf8d962   LTS                 x86_64                                                 ACTIVE
2.20.2.0-b145-https-aarch64                                    cc39415d-8dca-4c8f-ad8c-dcd9f1e98e67   LTS                 aarch64                                                ACTIVE
2.20.1.3-b3-https-aarch64                                      f7660b90-e8cd-4e81-900e-319ce260a689   LTS                 aarch64                                                ACTIVE
2.20.1.2-b1-https-aarch64                                      90c0c4bd-edb5-4235-9b3d-9e64daf5316b   LTS                 aarch64                                                ACTIVE
2.20.1.1-b4-https-aarch64                                      32baf77f-f248-4d86-a96f-9907848d70c1   LTS                 aarch64                                                ACTIVE
2.20.1.0-b97-https-aarch64                                     bfd83656-62cb-4391-a372-8c73ca0d3e42   LTS                 aarch64                                                ACTIVE
2.20.0.2-b1-https-aarch64                                      9e3a3385-26f0-4d15-89c0-d7bb59f56907   LTS                 aarch64                                                ACTIVE
2.20.0.1-b1-https-aarch64                                      64c5e239-405f-4ec4-aaac-d0c7f552a8c1   LTS                 aarch64                                                ACTIVE
2.20.0.0-b76-https-aarch64                                     c2a7989c-9b20-4596-a6cb-1bbb38f479aa   LTS                 aarch64                                                ACTIVE
2.18.5.0-b99922278-s3-enk-ci16292-3973d9f37e-20231109-010603   dc49cfac-a8c5-4635-bd85-690f877fe029   STS                 x86_64                                                 ACTIVE
2.18.5.0-b99922278                                             a8266281-ff36-4116-a404-d39b4de58fe2   STS                 x86_64                                                 ACTIVE
2.18.0.1-b4-https-aarch64                                      ee931f30-9b97-48e0-963d-8559ec9fbcf6   STS                 aarch64                                                ACTIVE
2.14.17.0-b3                                                   e56c8253-2181-4b0f-b417-db963ea0f69c   LTS                 x86_64                                                 ACTIVE
2.25.0.0-b144                                                  e1b92742-8aad-4d56-abc7-cafef57b62bd   PREVIEW             x86_64               Wed, 16 Oct 2024 00:11:19 +0000   ACTIVE
2.25.0.0-b143                                                  92fd8195-0b55-43c9-aea2-6efea4d6baea   PREVIEW             x86_64                                                 ACTIVE
2.25.0.0-b124                                                  a3eb1506-a687-49f5-8d27-2cc7157053b0   PREVIEW             x86_64                                                 ACTIVE
2.25.0.0-b20                                                   768799b1-b30a-4b87-9155-49b1757e5453   PREVIEW             x86_64                                                 ACTIVE
2.23.1.0-b190                                                  66993e46-00b8-43ca-af7f-a07be1c87fc0   PREVIEW             x86_64                                                 ACTIVE
2.23.1.0-b148                                                  ca14e845-74d4-439d-a723-fc36fc200c0a   PREVIEW             x86_64                                                 ACTIVE
2.23.1.0-b113                                                  0c7805c7-b2b3-4ff0-9781-683d0ca242aa   PREVIEW             x86_64                                                 ACTIVE
2.23.1.0-b17                                                   271e0429-818a-4c05-9565-f1d503c2e521   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b99929504                                             a3adfed3-e3c2-44fc-ac6e-38aacf65b733   PREVIEW (DEFAULT)   x86_64               Fri, 19 Apr 2024 04:42:44 +0000   ACTIVE
2.23.0.0-b710                                                  c25ce541-4db9-42b6-a241-b82b33694588   PREVIEW             aarch64                                                ACTIVE
2.23.0.0-b690                                                  1a10f211-d83e-475b-9d8f-e6f4c214b930   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b678                                                  3b3093e3-f90b-4410-b1b8-fe76dde825bd   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b658                                                  be891556-a486-4432-83d2-81adf14bab5b   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b631                                                  45c8131a-81b5-4932-8425-39c3b0cbc126   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b625                                                  bfaca8ed-7fdf-45e2-b029-0e4ca38a073d   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b590                                                  bbfbaddb-a898-4809-beab-9489a4d7fb59   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b462                                                  cbd0a339-9968-4aca-a4f1-a677842b453b   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b350                                                  fe3a62eb-8583-4820-8d67-0690a6add970   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b293                                                  8cc2797d-336d-4fa3-9a98-a9e5b13e5a8c   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b270                                                  4f835b56-25f8-4825-a110-1d24cb728053   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b228                                                  665186cc-cf47-4e00-90c7-124dd9093a24   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b170                                                  dba79338-8fb3-4e76-8275-87bf0240b5c5   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b137                                                  323c5d48-57f7-4b59-a662-7e31494100b7   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b104                                                  b158d606-dfdb-4269-99c1-f78d2368e247   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b67                                                   bdf13e75-e6b0-4c60-8365-8253926042a8   PREVIEW             x86_64                                                 ACTIVE
2.23.0.0-b15                                                   8b1f119f-a234-41fb-823d-15c4069646d4   PREVIEW             x86_64                                                 ACTIVE
2.21.1.0-b271                                                  b3f34e4c-6652-481e-96cf-37761536d29f   PREVIEW             aarch64                                                ACTIVE
2.21.1.0-b250                                                  513839e9-82cf-4ae9-be4a-e528ec31c7c0   PREVIEW             x86_64                                                 ACTIVE
2.21.1.0-b208                                                  e805d116-2b31-4c89-b3eb-3d946a6b21a2   PREVIEW             x86_64                                                 ACTIVE
2.21.1.0-b182                                                  8b63f640-ecc9-4c7d-afb5-eeb03721a62b   PREVIEW             x86_64                                                 ACTIVE
2.21.1.0-b111                                                  b077d545-ccb4-4ef6-81e5-0da98e157f51   PREVIEW             x86_64                                                 ACTIVE
2.21.1.0-b96                                                   74de7b0d-efb5-4371-b094-b41a7d93b5cd   PREVIEW             x86_64                                                 ACTIVE
2.21.1.0-b36                                                   df7ed84c-9977-4429-a296-f70dc3e17090   PREVIEW             x86_64                                                 ACTIVE
2.21.0.0-b545-https-aarch64                                    5ccdcc88-4260-4d31-a455-3d37b2e01322   PREVIEW             aarch64                                                ACTIVE
2.21.0.0-b438                                                  a5049f68-f412-4bf3-9d68-1d74f126c4a5   PREVIEW             x86_64                                                 ACTIVE
2.21.0.0-b312                                                  c37abdb8-3acc-43fe-a6b4-23617b1cb80d   PREVIEW             x86_64                                                 ACTIVE
2.21.0.0-b266                                                  30e8adf5-85ae-4f0e-86ac-c431cbc8e475   PREVIEW             x86_64                                                 ACTIVE
2.21.0.0-b186                                                  923ebf59-b3fe-4983-9e38-6685d90f0554   PREVIEW             x86_64                                                 ACTIVE
2.21.0.0-b179                                                  3fbde610-1dc9-4519-aaa9-a86e6abd2618   PREVIEW             x86_64                                                 ACTIVE
2.21.0.0-b119                                                  e5b98961-cabc-4d33-a0d8-f4de5197441a   PREVIEW             x86_64                                                 ACTIVE
2.21.0.0-b99                                                   17c325fb-2364-4246-ad68-df358aa5ac54   PREVIEW             x86_64                                                 ACTIVE
2.21.0.0-b70                                                   63020b7d-f3d8-4528-9080-581e94f3de6e   PREVIEW             x86_64                                                 ACTIVE
2.21.0.0-b12                                                   3dfef3ea-8b57-49d3-a4f2-782a34889730   PREVIEW             x86_64                                                 ACTIVE
2.19.3.0-b140-https-aarch64                                    58e85b70-213c-4373-a934-50c9b3ac1f15   PREVIEW             aarch64                                                ACTIVE
2.19.3.0-b87                                                   13458493-b3f2-43a3-9cef-df98d4dd5737   PREVIEW             x86_64                                                 ACTIVE
2.19.3.0-b71                                                   544b354f-d012-47dd-9def-dcbdcae09b0b   PREVIEW             x86_64                                                 ACTIVE
2.19.3.0-b55                                                   67c7f594-87f9-41fc-a9ce-03a1692809cd   PREVIEW             x86_64                                                 ACTIVE
2.19.3.0-b26                                                   ff9f8c64-94d3-4e71-9641-c275bf267b20   PREVIEW             x86_64                                                 ACTIVE
2.19.3.0-b14                                                   97621541-35a5-4a41-8e6b-34bbb0ae9ef7   PREVIEW             x86_64                                                 ACTIVE
2.19.3.0-b8                                                    0fe522ac-0f21-49fc-9c89-3c00e6c4fd4d   PREVIEW             x86_64                                                 ACTIVE
2.19.3.0-b2                                                    1bd2c631-03f9-492e-a547-557823ee7f2e   PREVIEW             x86_64                                                 ACTIVE
2.19.2.0-b121-https-aarch64                                    a85882ff-4666-4457-b2ca-a18cede239b2   PREVIEW             aarch64                                                ACTIVE
2.19.2.0-b96                                                   1da9c108-ce2b-4855-927e-16f25a353520   PREVIEW             x86_64                                                 ACTIVE
2.19.2.0-b27                                                   6174c1a0-a54f-410c-915d-39501f109f5e   PREVIEW             x86_64                                                 ACTIVE
2.19.2.0-b7                                                    7708d084-eb0a-463d-bc51-de2b1f143155   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b397                                                  79a842d3-ae64-42cd-ac7d-80fdfba2300c   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b386                                                  ee6f6206-f884-4940-8d28-606e5e20387e   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b373                                                  79f13199-2de8-427e-8a6d-1059c055acea   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b345                                                  4a14e92b-30f8-45a8-bb52-15441f8482a1   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b322                                                  54face83-aa7b-49e4-b726-96e0bcc17a9e   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b315                                                  e3345a12-a7fc-4e4c-a26b-30899c661840   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b250                                                  d807a1aa-5368-4391-8271-29650054b7da   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b203                                                  379f409e-ce2f-4307-9b8c-1d64b0edcca8   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b195                                                  367ebf68-f68d-4a25-83f1-c51e6e2a7c52   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b184                                                  88ff2dad-0d6d-4e30-91de-b46ef166d100   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b159                                                  597f58ce-15ad-4ba1-858a-1a8d0f5347ed   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b149                                                  20588656-c2d8-4f69-b294-b05ed379572d   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b141                                                  66421a11-f620-4180-8d65-7551b71cf72b   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b138                                                  d101d7b9-8259-4ab7-b4c8-0dd23e1abc56   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b126                                                  f2d5c78e-bd64-4bf2-81f5-9dafa5208cee   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b109                                                  b3c9e9cc-1d44-4416-9b55-7014cf508c4f   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b103                                                  cfe0fbdb-d240-4e17-8f37-bdff54ee2c06   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b96                                                   9e1468f3-60fa-47ac-ac0c-de4ce3a52743   PREVIEW             x86_64                                                 ACTIVE
2.19.1.0-b80                                                   e2d20777-5ad6-4d54-8698-4920d61c2cc8   PREVIEW             x86_64                                                 ACTIVE
2.19.0.0-b190-https-aarch64                                    13145c51-7fae-4bee-a967-49f52b8b80a2   PREVIEW             aarch64                                                ACTIVE
2.19.0.0-b179                                                  da07f29b-6463-477e-b4a8-e56de535eebd   PREVIEW             x86_64                                                 ACTIVE
2.19.0.0-b148                                                  f496605c-2ded-47fe-adac-91ef37e2cc34   PREVIEW             x86_64                                                 ACTIVE
2.19.0.0-b114                                                  aec4f5fb-b6d7-4c87-99b0-dfeb4e2d9ca0   PREVIEW             x86_64                                                 ACTIVE
2.19.0.0-b106                                                  f592aa1a-df68-4804-9f39-07cf5119f4b4   PREVIEW             x86_64                                                 ACTIVE
2.19.0.0-b85                                                   d4f8c6f0-0360-4ca0-a024-41ca2b836d12   PREVIEW             x86_64                                                 ACTIVE
2.19.0.0-b23                                                   27f5f2f2-b0cc-425a-932b-4c86267a73cf   PREVIEW             x86_64                                                 ACTIVE
2.19.0.0-b9                                                    c6a5bcc4-be94-4b00-a671-f0e4aa339f44   PREVIEW             x86_64                                                 ACTIVE
2.17.4.0-b67                                                   576788ca-c3c7-4bdf-a300-b4ef46084ea0   PREVIEW             x86_64                                                 ACTIVE
2.17.4.0-b35                                                   94a8bae9-0447-4d6c-81fa-031e4ab1f498   PREVIEW             x86_64                                                 ACTIVE
2.17.4.0-b18                                                   1abb9b47-593e-46a9-b366-25f41919eda7   PREVIEW             x86_64                                                 ACTIVE
2.17.3.0-b152-https-aarch64                                    cbd2231b-a853-4c0a-b9d1-72e63057a87c   PREVIEW             aarch64                                                ACTIVE
2.17.3.0-b132                                                  a8a17996-d7e1-441d-a279-a734f2de580b   PREVIEW             x86_64                                                 ACTIVE
2.17.3.0-b119                                                  3282cd0a-0c3e-4a09-80c1-bdb0f42da890   PREVIEW             x86_64                                                 ACTIVE
2.17.3.0-b82                                                   7f82905c-4e23-4a3e-b3ef-e5aed692cbf7   PREVIEW             x86_64                                                 ACTIVE
2.17.3.0-b25                                                   215c5740-9501-4e8c-bb12-a9b802b5b6e2   PREVIEW             x86_64                                                 ACTIVE
2.17.2.0-b216-https-aarch64                                    0522e8ba-33df-4d67-9b00-61781d12daab   PREVIEW             aarch64                                                ACTIVE
2.17.2.0-b176                                                  6398db2b-61eb-4126-83dc-d3c0cd0b4df5   PREVIEW             x86_64                                                 ACTIVE
2.17.2.0-b109                                                  b4928c42-caa1-4711-bfbc-91d127186b14   PREVIEW             x86_64                                                 ACTIVE
```

Describe:
```
./yba yb-db-version describe -v 2.25.0.0-b144
General
YugabyteDB Version   UUID                                   Release Type   Release Date                      State
2.25.0.0-b144        e1b92742-8aad-4d56-abc7-cafef57b62bd   PREVIEW        Wed, 16 Oct 2024 00:11:19 +0000   ACTIVE

Release Details
Release Tag   YugabyteDB Type
              YBDB

Release Notes

Artifacts
Artifact 1: Details
Architecture   Platform
x86_64         LINUX

Package File ID   Package URL
                  https://s3.us-west-2.amazonaws.com/releases.yugabyte.com/2.25.0.0-b144/yugabyte-2.25.0.0-b144-centos-x86_64.tar.gz

SHA256
```

Describe with Pretty output format:
```
./yba yb-db-version describe -v 2.25.0.0-b144 -o pretty
{
  "artifacts": [
    {
      "architecture": "x86_64",
      "package_file_id": "",
      "package_url": "https://s3.us-west-2.amazonaws.com/releases.yugabyte.com/2.25.0.0-b144/yugabyte-2.25.0.0-b144-centos-x86_64.tar.gz",
      "platform": "LINUX",
      "sha256": ""
    }
  ],
  "release_date_msecs": 1729037479000,
  "release_notes": "",
  "release_tag": "",
  "release_type": "PREVIEW",
  "release_uuid": "e1b92742-8aad-4d56-abc7-cafef57b62bd",
  "state": "ACTIVE",
  "universes": [],
  "version": "2.25.0.0-b144",
  "yb_type": "YBDB"
}
```

Reviewers: dshubin, sneelakantan

Reviewed By: dshubin

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D39846
  • Loading branch information
Deepti-yb committed Nov 12, 2024
1 parent b1b63ee commit 6216e45
Show file tree
Hide file tree
Showing 19 changed files with 1,014 additions and 257 deletions.
128 changes: 128 additions & 0 deletions managed/yba-cli/cmd/release/describe_release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (c) YugaByte, Inc.
*/

package release

import (
"fmt"
"os"
"strings"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
ybaclient "github.com/yugabyte/platform-go-client"
"github.com/yugabyte/yugabyte-db/managed/yba-cli/cmd/util"
ybaAuthClient "github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/client"
"github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/formatter"
"github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/formatter/release"
)

var describeReleaseCmd = &cobra.Command{
Use: "describe",
Aliases: []string{"get"},
Short: "Describe a YugabyteDB version",
Long: "Describe a version of YugabyteDB",
Example: `yba yb-db-version describe --version <version>`,
PreRun: func(cmd *cobra.Command, args []string) {
versionFlag, err := cmd.Flags().GetString("version")
if err != nil {
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
}
if len(versionFlag) == 0 {
cmd.Help()
logrus.Fatalln(
formatter.Colorize("No YugabyteDB version found to describe\n", formatter.RedColor))
}
},
Run: func(cmd *cobra.Command, args []string) {
authAPI := ybaAuthClient.NewAuthAPIClientAndCustomer()

version, err := cmd.Flags().GetString("version")
if err != nil {
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
}

releasesListRequest := authAPI.ListNewReleases()

deploymentType, err := cmd.Flags().GetString("deployment-type")
if err != nil {
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
}
if len(strings.TrimSpace(deploymentType)) != 0 {
releasesListRequest = releasesListRequest.DeploymentType(
strings.ToLower(deploymentType))
}

rList, response, err := releasesListRequest.Execute()
if err != nil {
errMessage := util.ErrorFromHTTPResponse(response, err, "Release", "List")
logrus.Fatalf(formatter.Colorize(errMessage.Error()+"\n", formatter.RedColor))
}

requestedRelease := make([]ybaclient.ResponseRelease, 0)
releaseUUID := ""
for _, v := range rList {
if strings.Compare(v.GetVersion(), version) == 0 {
requestedRelease = append(requestedRelease, v)
break
}
}

if len(requestedRelease) < 1 {
logrus.Fatalf(
formatter.Colorize(
fmt.Sprintf("No YugabyteDB version: %s found\n", version),
formatter.RedColor,
))
}

releaseUUID = requestedRelease[0].GetReleaseUuid()

releaseResponse, response, err := authAPI.GetNewRelease(releaseUUID).Execute()
if err != nil {
errMessage := util.ErrorFromHTTPResponse(response, err, "Release", "Describe")
logrus.Fatalf(formatter.Colorize(errMessage.Error()+"\n", formatter.RedColor))
}

r := make([]ybaclient.ResponseRelease, 0)
r = append(r, releaseResponse)

if len(r) > 0 && util.IsOutputType(formatter.TableFormatKey) {
fullReleaseContext := *release.NewFullReleaseContext()
fullReleaseContext.Output = os.Stdout
fullReleaseContext.Format = release.NewFullReleaseFormat(viper.GetString("output"))
fullReleaseContext.SetFullRelease(r[0])
fullReleaseContext.Write()
return
}

if len(r) < 1 {
logrus.Fatalf(
formatter.Colorize(
fmt.Sprintf("No YugabyteDB version: %s found\n", version),
formatter.RedColor,
))
}

releaseCtx := formatter.Context{
Command: "describe",
Output: os.Stdout,
Format: release.NewReleaseFormat(viper.GetString("output")),
}
release.Write(releaseCtx, r)

},
}

func init() {
describeReleaseCmd.Flags().SortFlags = false
describeReleaseCmd.Flags().StringP("version", "v", "",
"[Required] The version to be described.")
describeReleaseCmd.MarkFlagRequired("version")

describeReleaseCmd.Flags().String("deployment-type", "",
"[Optional] Deployment type of the YugabyteDB version. "+
"Allowed values: x86_64, aarch64, kubernetes")
}
134 changes: 134 additions & 0 deletions managed/yba-cli/cmd/release/list_release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Copyright (c) YugaByte, Inc.
*/

package release

import (
"os"
"strings"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
ybaclient "github.com/yugabyte/platform-go-client"
"github.com/yugabyte/yugabyte-db/managed/yba-cli/cmd/util"
ybaAuthClient "github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/client"
"github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/formatter"
"github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/formatter/release"

"golang.org/x/exp/slices"
)

var listReleaseCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List YugabyteDB versions",
Long: "List YugabyteDB versions",
Example: `yba yb-db-version list`,
Run: func(cmd *cobra.Command, args []string) {
authAPI := ybaAuthClient.NewAuthAPIClientAndCustomer()

releasesListRequest := authAPI.ListNewReleases()

deploymentType, err := cmd.Flags().GetString("deployment-type")
if err != nil {
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
}
if len(strings.TrimSpace(deploymentType)) != 0 {
releasesListRequest = releasesListRequest.DeploymentType(
strings.ToLower(deploymentType))
}

rList, response, err := releasesListRequest.Execute()
if err != nil {
errMessage := util.ErrorFromHTTPResponse(response, err, "Release", "List")
logrus.Fatalf(formatter.Colorize(errMessage.Error()+"\n", formatter.RedColor))
}

r := make([]ybaclient.ResponseRelease, 0)

releaseType, err := cmd.Flags().GetString("type")
if err != nil {
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
}
if len(strings.TrimSpace(releaseType)) != 0 {
for _, v := range rList {
if strings.Compare(v.GetReleaseType(), strings.ToUpper(releaseType)) == 0 {
r = append(r, v)
}
}
} else {
r = rList
}

sortedReleases := SortReleasesWithMetadata(r)
releaseCtx := formatter.Context{
Command: "list",
Output: os.Stdout,
Format: release.NewReleaseFormat(viper.GetString("output")),
}
if len(sortedReleases) < 1 {
if util.IsOutputType(formatter.TableFormatKey) {
logrus.Infoln("No YugabyteDB versions found\n")
} else {
logrus.Infoln("[]\n")
}
return
}

release.Write(releaseCtx, sortedReleases)

},
}

func init() {
listReleaseCmd.Flags().SortFlags = false

listReleaseCmd.Flags().String("deployment-type", "",
"[Optional] Deployment type of the YugabyteDB version. "+
"Allowed values: x86_64, aarch64, kubernetes")
listReleaseCmd.Flags().String("type", "",
"[Optional] Release type. Allowed values: lts, sts, preview")
}

// SortReleasesWithMetadata compares and creates a list of sorted YugabyteDB releases
func SortReleasesWithMetadata(
r []ybaclient.ResponseRelease,
) []ybaclient.ResponseRelease {
sorted := make([]ybaclient.ResponseRelease, 0)

versionsStable := make([]ybaclient.ResponseRelease, 0)
versionsPreview := make([]ybaclient.ResponseRelease, 0)
for _, v := range r {
if util.IsVersionStable(v.GetVersion()) {
versionsStable = append(versionsStable, v)
} else {
versionsPreview = append(versionsPreview, v)
}
}

// the function as described in the documentation is the less function,
// but for the purpose of getting the latest release, it's described as
// a function returning the greater of the 2 versions
slices.SortStableFunc(versionsStable, func(x, y ybaclient.ResponseRelease) int {
compare, err := util.CompareYbVersions(x.GetVersion(), y.GetVersion())
if err != nil {
return 0
}
return compare * -1
})
slices.SortStableFunc(versionsPreview, func(x, y ybaclient.ResponseRelease) int {
compare, err := util.CompareYbVersions(x.GetVersion(), y.GetVersion())
if err != nil {
return 0
}
return compare * -1
})

sorted = append(sorted, versionsStable...)

sorted = append(sorted, versionsPreview...)

return sorted
}
27 changes: 27 additions & 0 deletions managed/yba-cli/cmd/release/release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) YugaByte, Inc.
*/

package release

import (
"github.com/spf13/cobra"
)

// ReleaseCmd set of commands are used to perform operations on releasess
// in YugabyteDB Anywhere
var ReleaseCmd = &cobra.Command{
Use: "yb-db-version",
Short: "Manage YugabyteDB versions",
Long: "Manage YugabyteDB versions",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

func init() {
ReleaseCmd.AddCommand(listReleaseCmd)
ReleaseCmd.AddCommand(describeReleaseCmd)
// ReleaseCmd.AddCommand(deleteReleaseCmd)
// ReleaseCmd.AddCommand(createReleaseCmd)
}
105 changes: 0 additions & 105 deletions managed/yba-cli/cmd/releases/list_releases.go

This file was deleted.

Loading

0 comments on commit 6216e45

Please sign in to comment.