Skip to content

Commit

Permalink
Update DeprecateDomain handler to handle global domain deprecation (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaddoll authored Mar 8, 2021
1 parent 1e8b738 commit 0c46f3d
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 6 deletions.
35 changes: 29 additions & 6 deletions common/domain/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,6 @@ func (d *handlerImpl) DeprecateDomain(
deprecateRequest *types.DeprecateDomainRequest,
) error {

clusterMetadata := d.clusterMetadata
// TODO remove the IsGlobalDomainEnabled check once cross DC is public
if clusterMetadata.IsGlobalDomainEnabled() && !clusterMetadata.IsMasterCluster() {
return errNotMasterCluster
}

// must get the metadata (notificationVersion) first
// this version can be regarded as the lock on the v2 domain table
// and since we do not know which table will return the domain afterwards
Expand All @@ -594,21 +588,50 @@ func (d *handlerImpl) DeprecateDomain(
return err
}

isGlobalDomain := getResponse.IsGlobalDomain
if isGlobalDomain && !d.clusterMetadata.IsMasterCluster() {
return errNotMasterCluster
}
getResponse.ConfigVersion = getResponse.ConfigVersion + 1
getResponse.Info.Status = persistence.DomainStatusDeprecated

updateReq := &persistence.UpdateDomainRequest{
Info: getResponse.Info,
Config: getResponse.Config,
ReplicationConfig: getResponse.ReplicationConfig,
ConfigVersion: getResponse.ConfigVersion,
FailoverVersion: getResponse.FailoverVersion,
FailoverNotificationVersion: getResponse.FailoverNotificationVersion,
FailoverEndTime: getResponse.FailoverEndTime,
PreviousFailoverVersion: getResponse.PreviousFailoverVersion,
LastUpdatedTime: d.timeSource.Now().UnixNano(),
NotificationVersion: notificationVersion,
}
err = d.metadataMgr.UpdateDomain(ctx, updateReq)
if err != nil {
return err
}

if isGlobalDomain {
if err := d.domainReplicator.HandleTransmissionTask(
ctx,
types.DomainOperationUpdate,
getResponse.Info,
getResponse.Config,
getResponse.ReplicationConfig,
getResponse.ConfigVersion,
getResponse.FailoverVersion,
getResponse.PreviousFailoverVersion,
isGlobalDomain,
); err != nil {
return err
}
}

d.logger.Info("DeprecateDomain domain succeeded",
tag.WorkflowDomainName(getResponse.Info.Name),
tag.WorkflowDomainID(getResponse.Info.ID),
)
return nil
}

Expand Down
62 changes: 62 additions & 0 deletions common/domain/handler_GlobalDomainDisabled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,68 @@ func (s *domainHandlerGlobalDomainDisabledSuite) TestUpdateGetDomain_AllAttrSet(
)
}

func (s *domainHandlerGlobalDomainDisabledSuite) TestDeprecateGetDomain() {
// setup domain
domainName := s.getRandomDomainName()
domain := s.setupLocalDomain(domainName)

// execute the function to be tested
err := s.handler.DeprecateDomain(context.Background(), &types.DeprecateDomainRequest{
Name: domainName,
})
s.Nil(err)

// verify the execution result
expectedResp := domain
expectedResp.DomainInfo.Status = types.DomainStatusDeprecated.Ptr()

getResp, err := s.handler.DescribeDomain(context.Background(), &types.DescribeDomainRequest{
Name: common.StringPtr(domainName),
})
s.Nil(err)
assertDomainEqual(s.Suite, getResp, expectedResp)
}

func (s *domainHandlerGlobalDomainDisabledSuite) getRandomDomainName() string {
return "domain" + uuid.New()
}

func (s *domainHandlerGlobalDomainDisabledSuite) setupLocalDomain(domainName string) *types.DescribeDomainResponse {
return setupLocalDomain(s.Suite, s.handler, s.ClusterMetadata, domainName)
}

func setupLocalDomain(s suite.Suite, handler *handlerImpl, clusterMetadata cluster.Metadata, domainName string) *types.DescribeDomainResponse {
description := "some random description"
email := "some random email"
retention := int32(7)
emitMetric := true
data := map[string]string{"some random key": "some random value"}
var clusters []*types.ClusterReplicationConfiguration
for _, replicationConfig := range persistence.GetOrUseDefaultClusters(clusterMetadata.GetCurrentClusterName(), nil) {
clusters = append(clusters, &types.ClusterReplicationConfiguration{
ClusterName: replicationConfig.ClusterName,
})
}
err := handler.RegisterDomain(context.Background(), &types.RegisterDomainRequest{
Name: domainName,
Description: description,
OwnerEmail: email,
WorkflowExecutionRetentionPeriodInDays: retention,
EmitMetric: common.BoolPtr(emitMetric),
Clusters: clusters,
ActiveClusterName: clusterMetadata.GetCurrentClusterName(),
Data: data,
})
s.Nil(err)
getResp, err := handler.DescribeDomain(context.Background(), &types.DescribeDomainRequest{
Name: common.StringPtr(domainName),
})
s.Nil(err)
return getResp
}

func assertDomainEqual(s suite.Suite, autual, expected *types.DescribeDomainResponse) {
s.NotEmpty(autual.DomainInfo.GetUUID())
expected.DomainInfo.UUID = autual.DomainInfo.GetUUID()
s.Equal(expected, autual)
}
89 changes: 89 additions & 0 deletions common/domain/handler_GlobalDomainEnabled_MasterCluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,25 @@ func (s *domainHandlerGlobalDomainEnabledMasterClusterSuite) TestUpdateGetDomain
)
}

func (s *domainHandlerGlobalDomainEnabledMasterClusterSuite) TestDeprecateGetDomain_LocalDomain() {
domainName := s.getRandomDomainName()
domain := s.setupLocalDomain(domainName)

err := s.handler.DeprecateDomain(context.Background(), &types.DeprecateDomainRequest{
Name: domainName,
})
s.Nil(err)

expectedResp := domain
expectedResp.DomainInfo.Status = types.DomainStatusDeprecated.Ptr()

getResp, err := s.handler.DescribeDomain(context.Background(), &types.DescribeDomainRequest{
Name: common.StringPtr(domainName),
})
s.Nil(err)
assertDomainEqual(s.Suite, getResp, expectedResp)
}

func (s *domainHandlerGlobalDomainEnabledMasterClusterSuite) TestRegisterGetDomain_GlobalDomain_AllDefault() {
domainName := s.getRandomDomainName()
isGlobalDomain := true
Expand Down Expand Up @@ -915,6 +934,76 @@ func (s *domainHandlerGlobalDomainEnabledMasterClusterSuite) TestUpdateDomain_Co
s.Error(err)
}

func (s *domainHandlerGlobalDomainEnabledMasterClusterSuite) TestDeprecateGetDomain_GlobalDomain() {
domainName := s.getRandomDomainName()
domain := s.setupGlobalDomain(domainName)

s.mockProducer.On("Publish", mock.Anything, mock.Anything).Return(nil).Once()

err := s.handler.DeprecateDomain(context.Background(), &types.DeprecateDomainRequest{
Name: domainName,
})
s.Nil(err)

expectedResp := domain
expectedResp.DomainInfo.Status = types.DomainStatusDeprecated.Ptr()

getResp, err := s.handler.DescribeDomain(context.Background(), &types.DescribeDomainRequest{
Name: common.StringPtr(domainName),
})
s.Nil(err)
assertDomainEqual(s.Suite, getResp, expectedResp)
}

func (s *domainHandlerGlobalDomainEnabledMasterClusterSuite) getRandomDomainName() string {
return "domain" + uuid.New()
}

func (s *domainHandlerGlobalDomainEnabledMasterClusterSuite) setupLocalDomain(domainName string) *types.DescribeDomainResponse {
return setupLocalDomain(s.Suite, s.handler, s.ClusterMetadata, domainName)
}

func (s *domainHandlerGlobalDomainEnabledMasterClusterSuite) setupGlobalDomain(domainName string) *types.DescribeDomainResponse {
s.mockProducer.On("Publish", mock.Anything, mock.Anything).Return(nil).Once()
return setupGlobalDomain(s.Suite, s.handler, s.ClusterMetadata, domainName)
}

func setupGlobalDomain(s suite.Suite, handler *handlerImpl, clusterMetadata cluster.Metadata, domainName string) *types.DescribeDomainResponse {
description := "some random description"
email := "some random email"
retention := int32(7)
emitMetric := true
data := map[string]string{"some random key": "some random value"}
activeClusterName := ""
clusters := []*types.ClusterReplicationConfiguration{}
for clusterName := range clusterMetadata.GetAllClusterInfo() {
if clusterName != clusterMetadata.GetCurrentClusterName() {
activeClusterName = clusterName
}
clusters = append(clusters, &types.ClusterReplicationConfiguration{
ClusterName: clusterName,
})
}
s.True(len(activeClusterName) > 0)
s.True(len(clusters) > 1)
isGlobalDomain := true

err := handler.RegisterDomain(context.Background(), &types.RegisterDomainRequest{
Name: domainName,
Description: description,
OwnerEmail: email,
WorkflowExecutionRetentionPeriodInDays: retention,
EmitMetric: common.BoolPtr(emitMetric),
Clusters: clusters,
ActiveClusterName: activeClusterName,
Data: data,
IsGlobalDomain: isGlobalDomain,
})
s.Nil(err)

getResp, err := handler.DescribeDomain(context.Background(), &types.DescribeDomainRequest{
Name: common.StringPtr(domainName),
})
s.Nil(err)
return getResp
}
91 changes: 91 additions & 0 deletions common/domain/handler_GlobalDomainEnabled_NotMasterCluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,25 @@ func (s *domainHandlerGlobalDomainEnabledNotMasterClusterSuite) TestUpdateGetDom
)
}

func (s *domainHandlerGlobalDomainEnabledNotMasterClusterSuite) TestDeprecateGetDomain_LocalDomain() {
domainName := s.getRandomDomainName()
domain := s.setupLocalDomain(domainName)

err := s.handler.DeprecateDomain(context.Background(), &types.DeprecateDomainRequest{
Name: domainName,
})
s.Nil(err)

expectedResp := domain
expectedResp.DomainInfo.Status = types.DomainStatusDeprecated.Ptr()

getResp, err := s.handler.DescribeDomain(context.Background(), &types.DescribeDomainRequest{
Name: common.StringPtr(domainName),
})
s.Nil(err)
assertDomainEqual(s.Suite, getResp, expectedResp)
}

func (s *domainHandlerGlobalDomainEnabledNotMasterClusterSuite) TestRegisterGetDomain_GlobalDomain_AllDefault() {
domainName := s.getRandomDomainName()
isGlobalDomain := true
Expand Down Expand Up @@ -714,6 +733,78 @@ func (s *domainHandlerGlobalDomainEnabledNotMasterClusterSuite) TestUpdateGetDom
)
}

func (s *domainHandlerGlobalDomainEnabledNotMasterClusterSuite) TestDeprecateGetDomain_GlobalDomain() {
domainName := s.getRandomDomainName()
s.setupGlobalDomainWithMetadataManager(domainName)

err := s.handler.DeprecateDomain(context.Background(), &types.DeprecateDomainRequest{
Name: domainName,
})
s.IsType(&types.BadRequestError{}, err)
}

func (s *domainHandlerGlobalDomainEnabledNotMasterClusterSuite) getRandomDomainName() string {
return "domain" + uuid.New()
}

func (s *domainHandlerGlobalDomainEnabledNotMasterClusterSuite) setupLocalDomain(domainName string) *types.DescribeDomainResponse {
return setupLocalDomain(s.Suite, s.handler, s.ClusterMetadata, domainName)
}

func (s *domainHandlerGlobalDomainEnabledNotMasterClusterSuite) setupGlobalDomainWithMetadataManager(domainName string) *types.DescribeDomainResponse {
return setupGlobalDomainWithMetadataManager(s.Suite, s.handler, s.ClusterMetadata, s.MetadataManager, domainName)
}

func setupGlobalDomainWithMetadataManager(s suite.Suite, handler *handlerImpl, clusterMetadata cluster.Metadata, metadataManager persistence.MetadataManager, domainName string) *types.DescribeDomainResponse {
description := "some random description"
email := "some random email"
retention := int32(7)
emitMetric := true
activeClusterName := ""
clusters := []*persistence.ClusterReplicationConfig{}
for clusterName := range clusterMetadata.GetAllClusterInfo() {
if clusterName != clusterMetadata.GetCurrentClusterName() {
activeClusterName = clusterName
}
clusters = append(clusters, &persistence.ClusterReplicationConfig{
ClusterName: clusterName,
})
}
s.True(len(activeClusterName) > 0)
s.True(len(clusters) > 1)
data := map[string]string{"some random key": "some random value"}
isGlobalDomain := true

_, err := metadataManager.CreateDomain(context.Background(), &persistence.CreateDomainRequest{
Info: &persistence.DomainInfo{
ID: uuid.New(),
Name: domainName,
Status: persistence.DomainStatusRegistered,
Description: description,
OwnerEmail: email,
Data: data,
},
Config: &persistence.DomainConfig{
Retention: retention,
EmitMetric: emitMetric,
HistoryArchivalStatus: types.ArchivalStatusDisabled,
HistoryArchivalURI: "",
VisibilityArchivalStatus: types.ArchivalStatusDisabled,
VisibilityArchivalURI: "",
},
ReplicationConfig: &persistence.DomainReplicationConfig{
ActiveClusterName: activeClusterName,
Clusters: clusters,
},
IsGlobalDomain: isGlobalDomain,
ConfigVersion: 0,
FailoverVersion: clusterMetadata.GetNextFailoverVersion(activeClusterName, 0),
})
s.Nil(err)

getResp, err := handler.DescribeDomain(context.Background(), &types.DescribeDomainRequest{
Name: common.StringPtr(domainName),
})
s.Nil(err)
return getResp
}

0 comments on commit 0c46f3d

Please sign in to comment.