Skip to content

Commit

Permalink
Update domain deprecation command to fail if workflow exists (#4126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaddoll authored Apr 14, 2021
1 parent 6fea8dd commit 8d3519b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tools/cli/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,60 @@ func (s *cliAppSuite) TestDomainUpdate_Failed() {
}

func (s *cliAppSuite) TestDomainDeprecate() {
s.clientFrontendClient.EXPECT().ListClosedWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListClosedWorkflowExecutionsResponse{}, nil)
s.clientFrontendClient.EXPECT().ListOpenWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListOpenWorkflowExecutionsResponse{}, nil)
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(nil)
err := s.app.Run([]string{"", "--do", domainName, "domain", "deprecate"})
s.Nil(err)
}

func (s *cliAppSuite) TestDomainDeprecate_DomainNotExist() {
s.clientFrontendClient.EXPECT().ListClosedWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListClosedWorkflowExecutionsResponse{}, nil)
s.clientFrontendClient.EXPECT().ListOpenWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListOpenWorkflowExecutionsResponse{}, nil)
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(&types.EntityNotExistsError{})
errorCode := s.RunErrorExitCode([]string{"", "--do", domainName, "domain", "deprecate"})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestDomainDeprecate_Failed() {
s.clientFrontendClient.EXPECT().ListClosedWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListClosedWorkflowExecutionsResponse{}, nil)
s.clientFrontendClient.EXPECT().ListOpenWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListOpenWorkflowExecutionsResponse{}, nil)
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(&types.BadRequestError{"faked error"})
errorCode := s.RunErrorExitCode([]string{"", "--do", domainName, "domain", "deprecate"})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestDomainDeprecate_ClosedWorkflowsExist() {
s.clientFrontendClient.EXPECT().ListClosedWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(listClosedWorkflowExecutionsResponse, nil)
errorCode := s.RunErrorExitCode([]string{"", "--do", domainName, "domain", "deprecate"})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestDomainDeprecate_OpenWorkflowsExist() {
s.clientFrontendClient.EXPECT().ListClosedWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(&shared.ListClosedWorkflowExecutionsResponse{}, nil)
s.clientFrontendClient.EXPECT().ListOpenWorkflowExecutions(gomock.Any(), gomock.Any(), callOptions...).Return(listOpenWorkflowExecutionsResponse, nil)
errorCode := s.RunErrorExitCode([]string{"", "--do", domainName, "domain", "deprecate"})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestDomainDeprecate_Force() {
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(nil)
err := s.app.Run([]string{"", "--do", domainName, "domain", "deprecate", "--force"})
s.Nil(err)
}

func (s *cliAppSuite) TestDomainDeprecate_DomainNotExist_Force() {
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(&types.EntityNotExistsError{})
errorCode := s.RunErrorExitCode([]string{"", "--do", domainName, "domain", "deprecate", "--force"})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestDomainDeprecate_Failed_Force() {
s.serverFrontendClient.EXPECT().DeprecateDomain(gomock.Any(), gomock.Any()).Return(&types.BadRequestError{"faked error"})
errorCode := s.RunErrorExitCode([]string{"", "--do", domainName, "domain", "deprecate", "--force"})
s.Equal(1, errorCode)
}

func (s *cliAppSuite) TestDomainDescribe() {
resp := describeDomainResponseServer
s.serverFrontendClient.EXPECT().DescribeDomain(gomock.Any(), gomock.Any()).Return(resp, nil)
Expand Down
14 changes: 14 additions & 0 deletions tools/cli/domainCommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,24 @@ func (d *domainCLIImpl) UpdateDomain(c *cli.Context) {
func (d *domainCLIImpl) DeprecateDomain(c *cli.Context) {
domainName := getRequiredGlobalOption(c, FlagDomain)
securityToken := c.String(FlagSecurityToken)
force := c.Bool(FlagForce)

ctx, cancel := newContext(c)
defer cancel()

if !force {
// check if there is any workflow in this domain, if exists, do not deprecate
wfs, _ := listClosedWorkflow(getWorkflowClient(c), 1, 0, time.Now().UnixNano(), "", "", workflowStatusNotSet, nil, c)
if len(wfs) > 0 {
ErrorAndExit("Operation DeprecateDomain failed.", errors.New("Workflow history not cleared in this domain."))
return
}
wfs, _ = listOpenWorkflow(getWorkflowClient(c), 1, 0, time.Now().UnixNano(), "", "", nil, c)
if len(wfs) > 0 {
ErrorAndExit("Operation DeprecateDomain failed.", errors.New("Workflow still running in this domain."))
return
}
}
err := d.deprecateDomain(ctx, &types.DeprecateDomainRequest{
Name: domainName,
SecurityToken: securityToken,
Expand Down
4 changes: 4 additions & 0 deletions tools/cli/domainUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ var (
Name: FlagSecurityTokenWithAlias,
Usage: "Optional token for security check",
},
cli.BoolFlag{
Name: FlagForce,
Usage: "Deprecate domain regardless of domain history.",
},
}

describeDomainFlags = []cli.Flag{
Expand Down
1 change: 1 addition & 0 deletions tools/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const (
FlagAllWithAlias = FlagAll + ", a"
FlagDeprecated = "deprecated"
FlagDeprecatedWithAlias = FlagDeprecated + ", dep"
FlagForce = "force"
FlagPageSize = "pagesize"
FlagPageSizeWithAlias = FlagPageSize + ", ps"
FlagEarliestTime = "earliest_time"
Expand Down

0 comments on commit 8d3519b

Please sign in to comment.