Skip to content

Commit 3958763

Browse files
chore: Refactoring/domain handler updates (#7403)
<!-- Describe what has changed in this PR --> **What changed?** - Unified the FailoverDomain Handler code with the UpdateDomain Failover path - Flattened out the path for failover for normal domains and active/active a bit - Added a few bits missing for the FailoverDomain hander in both the CLI and the mappers to support active/active This is not a perfect refactor, I changed a few behaviours while I was here since I considered them low risk: - Stopped publishing active/active failover events to the Domain-data field, since this will be replaced by the FailoverHistory endpoint - Rewrote one of the unit tests for FailoverHandler for clarity <!-- Tell your future self why have you made these changes --> **Why?** <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> **How did you test it?** - [X] Unit tests - [X] Manual testing: - UpdateDomain - [X] Active/passive domain: Failover - [X] Active/Active - FailoverDomain - [X] Active/Passive domain - [X] Active/Active domain <!-- Assuming the worst case, what can be broken when deploying this change to production? --> **Potential risks** <!-- Is it notable for release? e.g. schema updates, configuration or data migration required? If so, please mention it, and also update CHANGELOG.md --> **Release notes** <!-- Is there any documentation updates should be made for config, https://cadenceworkflow.io/docs/operation-guide/setup/ ? If so, please open an PR in https://github.com/cadence-workflow/cadence-docs --> **Documentation Changes** --------- Signed-off-by: David Porter <david.porter@uber.com>
1 parent 8303389 commit 3958763

File tree

8 files changed

+227
-590
lines changed

8 files changed

+227
-590
lines changed

common/domain/handler.go

Lines changed: 65 additions & 305 deletions
Large diffs are not rendered by default.

common/domain/handler_test.go

Lines changed: 109 additions & 273 deletions
Large diffs are not rendered by default.

common/types/mapper/proto/api.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4514,7 +4514,8 @@ func FromFailoverDomainRequest(t *types.FailoverDomainRequest) *apiv1.FailoverDo
45144514
}
45154515
return &apiv1.FailoverDomainRequest{
45164516
DomainName: t.DomainName,
4517-
DomainActiveClusterName: *t.DomainActiveClusterName,
4517+
DomainActiveClusterName: t.GetDomainActiveClusterName(),
4518+
ActiveClusters: FromActiveClusters(t.ActiveClusters),
45184519
}
45194520
}
45204521

@@ -4525,6 +4526,7 @@ func ToFailoverDomainRequest(t *apiv1.FailoverDomainRequest) *types.FailoverDoma
45254526
return &types.FailoverDomainRequest{
45264527
DomainName: t.DomainName,
45274528
DomainActiveClusterName: common.StringPtr(t.DomainActiveClusterName),
4529+
ActiveClusters: ToActiveClusters(t.ActiveClusters),
45284530
}
45294531
}
45304532

@@ -5810,7 +5812,6 @@ func ToActiveClusters(t *apiv1.ActiveClusters) *types.ActiveClusters {
58105812

58115813
var attributeScopes map[string]types.ClusterAttributeScope
58125814

5813-
// Start with ActiveClustersByClusterAttribute if it exists
58145815
if t.ActiveClustersByClusterAttribute != nil {
58155816
attributeScopes = make(map[string]types.ClusterAttributeScope)
58165817
for scopeType, scope := range t.ActiveClustersByClusterAttribute {

common/types/mapper/thrift/shared.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ func FromFailoverDomainRequest(t *types.FailoverDomainRequest) *shared.FailoverD
16221622
return &shared.FailoverDomainRequest{
16231623
DomainName: &t.DomainName,
16241624
DomainActiveClusterName: t.DomainActiveClusterName,
1625+
ActiveClusters: FromActiveClusters(t.ActiveClusters),
16251626
}
16261627
}
16271628

@@ -1633,6 +1634,7 @@ func ToFailoverDomainRequest(t *shared.FailoverDomainRequest) *types.FailoverDom
16331634
return &types.FailoverDomainRequest{
16341635
DomainName: t.GetDomainName(),
16351636
DomainActiveClusterName: t.DomainActiveClusterName,
1637+
ActiveClusters: ToActiveClusters(t.ActiveClusters),
16361638
}
16371639
}
16381640

common/types/shared.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,8 +1779,20 @@ func (v *DescribeDomainResponse) GetFailoverInfo() (o *FailoverInfo) {
17791779

17801780
// FailoverDomainRequest is an internal type (TBD...)
17811781
type FailoverDomainRequest struct {
1782-
DomainName string `json:"domainName,omitempty"`
1783-
DomainActiveClusterName *string `json:"domainActiveClusterName,omitempty"`
1782+
DomainName string `json:"domainName,omitempty"`
1783+
DomainActiveClusterName *string `json:"domainActiveClusterName,omitempty"`
1784+
ActiveClusters *ActiveClusters `json:"activeClusters,omitempty"`
1785+
}
1786+
1787+
func (v *FailoverDomainRequest) ToUpdateDomainRequest() *UpdateDomainRequest {
1788+
if v == nil {
1789+
return nil
1790+
}
1791+
return &UpdateDomainRequest{
1792+
Name: v.DomainName,
1793+
ActiveClusterName: v.DomainActiveClusterName,
1794+
ActiveClusters: v.ActiveClusters,
1795+
}
17841796
}
17851797

17861798
// GetDomainName is an internal getter (TBD...)
@@ -8053,6 +8065,19 @@ type UpdateDomainResponse struct {
80538065
IsGlobalDomain bool `json:"isGlobalDomain,omitempty"`
80548066
}
80558067

8068+
func (v *UpdateDomainResponse) ToFailoverDomainResponse() *FailoverDomainResponse {
8069+
if v == nil {
8070+
return nil
8071+
}
8072+
return &FailoverDomainResponse{
8073+
DomainInfo: v.DomainInfo,
8074+
Configuration: v.Configuration,
8075+
ReplicationConfiguration: v.ReplicationConfiguration,
8076+
FailoverVersion: v.FailoverVersion,
8077+
IsGlobalDomain: v.IsGlobalDomain,
8078+
}
8079+
}
8080+
80568081
// GetDomainInfo is an internal getter (TBD...)
80578082
func (v *UpdateDomainResponse) GetDomainInfo() (o *DomainInfo) {
80588083
if v != nil && v.DomainInfo != nil {

service/frontend/api/request_validator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ func (v *requestValidatorImpl) ValidateFailoverDomainRequest(ctx context.Context
374374
return validate.ErrDomainNotSet
375375
}
376376

377-
if failoverDomainRequest.DomainActiveClusterName == nil {
378-
return &types.BadRequestError{Message: "DomainActiveClusterName must be provided to failover the domain"}
377+
if failoverDomainRequest.DomainActiveClusterName == nil && failoverDomainRequest.ActiveClusters == nil {
378+
return &types.BadRequestError{Message: "DomainActiveClusterName or ActiveClusters must be provided to failover the domain"}
379379
}
380380

381381
// Security token is not required for failover request - reject the failover if the cluster is in lockdown

tools/cli/domain_commands.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,22 +457,30 @@ func (d *domainCLIImpl) FailoverDomain(c *cli.Context) error {
457457
return commoncli.Problem("Required flag not found: ", err)
458458
}
459459

460-
var failoverRequest *types.FailoverDomainRequest
460+
failoverRequest := &types.FailoverDomainRequest{
461+
DomainName: domainName,
462+
}
461463

462464
ctx, cancel, err := newContext(c)
463465
defer cancel()
464466
if err != nil {
465467
return commoncli.Problem("Error in creating context: ", err)
466468
}
467469

470+
if !c.IsSet(FlagActiveClusterName) && !c.IsSet(FlagActiveClusters) {
471+
return commoncli.Problem("At least one of the flags --active-cluster-name or --active-clusters must be provided.", nil)
472+
}
473+
468474
if c.IsSet(FlagActiveClusterName) { // active-passive domain failover
469475
activeCluster := c.String(FlagActiveClusterName)
470-
fmt.Printf("Will set active cluster name to: %s, other flag will be omitted.\n", activeCluster)
471-
472-
failoverRequest = &types.FailoverDomainRequest{
473-
DomainName: domainName,
474-
DomainActiveClusterName: common.StringPtr(activeCluster),
476+
failoverRequest.DomainActiveClusterName = common.StringPtr(activeCluster)
477+
}
478+
if c.IsSet(FlagActiveClusters) { // active-active domain failover
479+
ac, err := parseActiveClustersByClusterAttribute(c.String(FlagActiveClusters))
480+
if err != nil {
481+
return err
475482
}
483+
failoverRequest.ActiveClusters = &ac
476484
}
477485
_, err = d.failoverDomain(ctx, failoverRequest)
478486
if err != nil {

tools/cli/domain_utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ var (
270270
Aliases: []string{"ac"},
271271
Usage: "Active cluster name",
272272
},
273+
&cli.StringSliceFlag{
274+
Name: FlagActiveClusters,
275+
Aliases: []string{"acs"},
276+
Usage: "Active clusters by cluster attribute in the format '<cluster-attr>.<scope>:<name> ie: region.manilla:cluster0,region.newyork:cluster1'",
277+
},
273278
}
274279

275280
listFailoverHistoryFlags = []cli.Flag{

0 commit comments

Comments
 (0)