Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add admin list domain command #3472

Merged
merged 1 commit into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion service/frontend/dcRedirectionHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/uber/cadence/common/client"

"github.com/uber/cadence/.gen/go/cadence/workflowservicetest"
"github.com/uber/cadence/.gen/go/shared"
"github.com/uber/cadence/common"
"github.com/uber/cadence/common/client"
"github.com/uber/cadence/common/cluster"
"github.com/uber/cadence/common/metrics"
"github.com/uber/cadence/common/resource"
Expand Down
2 changes: 1 addition & 1 deletion service/frontend/workflowHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/uber/cadence/common/client"

"github.com/uber/cadence/.gen/go/history/historyservicetest"
"github.com/uber/cadence/.gen/go/shared"
Expand All @@ -41,6 +40,7 @@ import (
"github.com/uber/cadence/common/archiver"
"github.com/uber/cadence/common/archiver/provider"
"github.com/uber/cadence/common/cache"
"github.com/uber/cadence/common/client"
"github.com/uber/cadence/common/cluster"
"github.com/uber/cadence/common/domain"
"github.com/uber/cadence/common/messaging"
Expand Down
23 changes: 23 additions & 0 deletions tools/cli/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,29 @@ func newAdminDomainCommands() []cli.Command {
AdminGetDomainIDOrName(c)
},
},
{
Name: "list",
Aliases: []string{"l"},
Usage: "List all domains in the cluster",
Flags: []cli.Flag{
cli.IntFlag{
Name: FlagPageSizeWithAlias,
Value: 10,
Usage: "Result page size",
},
cli.BoolFlag{
Name: FlagAllWithAlias,
Usage: "List all domains, by default only domains in REGISTERED status are listed",
},
cli.BoolFlag{
Name: FlagPrintFullyDetailWithAlias,
Usage: "Print full domain detail",
},
},
Action: func(c *cli.Context) {
newDomainCLI(c, false).ListDomains(c)
},
},
}
}

Expand Down
84 changes: 84 additions & 0 deletions tools/cli/domainCommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,39 @@ func (d *domainCLIImpl) DescribeDomain(c *cli.Context) {
}
}

func (d *domainCLIImpl) ListDomains(c *cli.Context) {
domains := d.getAllDomains(c)
pageSize := c.Int(FlagPageSize)
printAll := c.Bool(FlagAll)
printFull := c.Bool(FlagPrintFullyDetail)

table := createTableForListDomains(printAll, printFull)

currentPageSize := 0
for i, domain := range domains {
if !printAll && !domain.DomainInfo.Status.Equals(shared.DomainStatusRegistered) {
continue
}

appendDomainToTable(table, domain, printAll, printFull)
currentPageSize++

if currentPageSize != pageSize {
continue
}

// page is full
table.Render()
if i == len(domains)-1 || !showNextPage() {
return
}
table.ClearRows()
currentPageSize = 0
}

table.Render()
}

func (d *domainCLIImpl) listDomains(
ctx context.Context,
request *shared.ListDomainsRequest,
Expand Down Expand Up @@ -485,6 +518,57 @@ func (d *domainCLIImpl) describeDomain(
return d.domainHandler.DescribeDomain(ctx, request)
}

func createTableForListDomains(printAll, printFull bool) *tablewriter.Table {
table := tablewriter.NewWriter(os.Stdout)
table.SetBorder(false)
table.SetColumnSeparator("|")
header := []string{"Name", "UUID", "Domain Data"}
if printAll || printFull {
header = append(header, "Status")
}
header = append(header, "Is Global Domain", "Active Cluster")
if printFull {
header = append(header, "Clusters", "Retention Days", "History Archival Status", "History Archival URI", "Visibility Archival Status", "Visibility Archival URI")
}
headerColor := make([]tablewriter.Colors, len(header))
for i := range headerColor {
headerColor[i] = tableHeaderBlue
}
table.SetHeader(header)
table.SetHeaderColor(headerColor...)
table.SetHeaderLine(false)

return table
}

func appendDomainToTable(
table *tablewriter.Table,
domain *shared.DescribeDomainResponse,
printAll bool,
printFull bool,
) {
row := []string{
domain.DomainInfo.GetName(),
domain.DomainInfo.GetUUID(),
mapToString(domain.DomainInfo.GetData(), ", "),
}
if printAll || printFull {
row = append(row, domain.DomainInfo.GetStatus().String())
}
row = append(row, strconv.FormatBool(domain.GetIsGlobalDomain()), domain.ReplicationConfiguration.GetActiveClusterName())
if printFull {
row = append(row,
clustersToString(domain.ReplicationConfiguration.GetClusters()),
fmt.Sprintf("%v", domain.Configuration.GetWorkflowExecutionRetentionPeriodInDays()),
domain.Configuration.GetHistoryArchivalStatus().String(),
domain.Configuration.GetHistoryArchivalURI(),
domain.Configuration.GetVisibilityArchivalStatus().String(),
domain.Configuration.GetVisibilityArchivalURI(),
)
}
table.Append(row)
}

func archivalStatus(c *cli.Context, statusFlagName string) *shared.ArchivalStatus {
if c.IsSet(statusFlagName) {
switch c.String(statusFlagName) {
Expand Down
9 changes: 9 additions & 0 deletions tools/cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,15 @@ func mapKeysToArray(m map[string]string) []string {
return out
}

func mapToString(m map[string]string, sep string) string {
kv := make([]string, 0, len(m))
for key, value := range m {
kv = append(kv, key+": "+value)
}

return strings.Join(kv, sep)
}

func intSliceToSet(s []int) map[int]struct{} {
var ret = make(map[int]struct{}, len(s))
for _, v := range s {
Expand Down