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

Change domain data CLI parameter for consistency #4240

Merged
merged 2 commits into from
May 29, 2021
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ You can find a list of previous releases on the [github releases](https://github
- This change contains breaking change on user config. The masterClusterName config key is deprecated and is replaced with primaryClusterName key. (#4185)

### Changed
- Bump CLI version to v0.18.3 (#3959)
- Bump CLI version to v0.19.0
- Change `--connect-attributes` in `cadence-sql-tool` from URL encoding to the format of k1=v1,k2=v2...
- Change `--domain_data` in `cadence domain update/register` from the format of k1:v1,k2:v2... to the format of k1=v1,k2=v2...

## [0.18.0] - 2021-01-22

Expand Down
2 changes: 1 addition & 1 deletion tools/cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
const (
// Version is the controlled version string. It should be updated every time
// before we release a new version.
Version = "0.18.4"
Version = "0.19.0"
)

// SetFactory is used to set the ClientFactory global
Expand Down
17 changes: 0 additions & 17 deletions tools/cli/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package cli

import (
"fmt"
"strings"

"github.com/urfave/cli"
)
Expand All @@ -46,22 +45,6 @@ func checkRequiredDomainDataKVs(domainData map[string]string) error {
return nil
}

func parseDomainDataKVs(domainDataStr string) (map[string]string, error) {
kvstrs := strings.Split(domainDataStr, ",")
kvMap := map[string]string{}
for _, kvstr := range kvstrs {
kv := strings.Split(kvstr, ":")
if len(kv) != 2 {
return kvMap, fmt.Errorf("domain data format error. It must be k1:v2,k2:v2,...,kn:vn")
}
k := strings.TrimSpace(kv[0])
v := strings.TrimSpace(kv[1])
kvMap[k] = v
}

return kvMap, nil
}

func newDomainCommands() []cli.Command {
return []cli.Command{
{
Expand Down
24 changes: 9 additions & 15 deletions tools/cli/domainCommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"strings"
"time"

"github.com/uber/cadence/tools/common/flag"

"github.com/olekukonko/tablewriter"
"github.com/urfave/cli"

Expand Down Expand Up @@ -94,16 +96,12 @@ func (d *domainCLIImpl) RegisterDomain(c *cli.Context) {
}
}

domainData := map[string]string{}
var domainData *flag.StringMap
if c.IsSet(FlagDomainData) {
domainDataStr := getRequiredOption(c, FlagDomainData)
domainData, err = parseDomainDataKVs(domainDataStr)
if err != nil {
ErrorAndExit(fmt.Sprintf("Option %s format is invalid.", FlagDomainData), err)
}
domainData = c.Generic(FlagDomainData).(*flag.StringMap)
}
if len(requiredDomainDataKeys) > 0 {
err = checkRequiredDomainDataKVs(domainData)
err = checkRequiredDomainDataKVs(domainData.Value())
if err != nil {
ErrorAndExit("Domain data missed required data.", err)
}
Expand Down Expand Up @@ -131,7 +129,7 @@ func (d *domainCLIImpl) RegisterDomain(c *cli.Context) {
Name: domainName,
Description: description,
OwnerEmail: ownerEmail,
Data: domainData,
Data: domainData.Value(),
WorkflowExecutionRetentionPeriodInDays: int32(retentionDays),
Clusters: clusters,
ActiveClusterName: activeClusterName,
Expand Down Expand Up @@ -205,13 +203,9 @@ func (d *domainCLIImpl) UpdateDomain(c *cli.Context) {
if c.IsSet(FlagOwnerEmail) {
ownerEmail = c.String(FlagOwnerEmail)
}
domainData := map[string]string{}
var domainData *flag.StringMap
if c.IsSet(FlagDomainData) {
domainDataStr := c.String(FlagDomainData)
domainData, err = parseDomainDataKVs(domainDataStr)
if err != nil {
ErrorAndExit("Domain data format is invalid.", err)
}
domainData = c.Generic(FlagDomainData).(*flag.StringMap)
}
if c.IsSet(FlagRetentionDays) {
retentionDays = int32(c.Int(FlagRetentionDays))
Expand Down Expand Up @@ -255,7 +249,7 @@ func (d *domainCLIImpl) UpdateDomain(c *cli.Context) {
Name: domainName,
Description: common.StringPtr(description),
OwnerEmail: common.StringPtr(ownerEmail),
Data: domainData,
Data: domainData.Value(),
WorkflowExecutionRetentionPeriodInDays: common.Int32Ptr(retentionDays),
EmitMetric: common.BoolPtr(emitMetric),
HistoryArchivalStatus: archivalStatus(c, FlagHistoryArchivalStatus),
Expand Down
12 changes: 8 additions & 4 deletions tools/cli/domainUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ package cli
import (
"strings"

"github.com/uber/cadence/tools/common/flag"

"github.com/stretchr/testify/mock"
"github.com/uber-go/tally"
"github.com/urfave/cli"
Expand Down Expand Up @@ -77,9 +79,10 @@ var (
Name: FlagIsGlobalDomainWithAlias,
Usage: "Flag to indicate whether domain is a global domain",
},
cli.StringFlag{
cli.GenericFlag{
Name: FlagDomainDataWithAlias,
Usage: "Domain data of key value pairs, in format of k1:v1,k2:v2,k3:v3",
Usage: "Domain data of key value pairs (must be in key1=value1,key2=value2,...,keyN=valueN format, e.g. cluster=dca or cluster=dca,instance=cadence)",
Value: &flag.StringMap{},
},
cli.StringFlag{
Name: FlagSecurityTokenWithAlias,
Expand Down Expand Up @@ -127,9 +130,10 @@ var (
Name: FlagClustersWithAlias,
Usage: "Clusters",
},
cli.StringFlag{
cli.GenericFlag{
Name: FlagDomainDataWithAlias,
Usage: "Domain data of key value pairs, in format of k1:v1,k2:v2,k3:v3 ",
Usage: "Domain data of key value pairs (must be in key1=value1,key2=value2,...,keyN=valueN format, e.g. cluster=dca or cluster=dca,instance=cadence)",
Value: &flag.StringMap{},
},
cli.StringFlag{
Name: FlagSecurityTokenWithAlias,
Expand Down