From 7ad84f464b79f2ed3f7569d30db59372a94cdead Mon Sep 17 00:00:00 2001 From: Bowei Xu Date: Thu, 26 Apr 2018 01:00:38 -0700 Subject: [PATCH] Refactor domain client update and describe for crossdc --- client/client.go | 13 +++++------ internal/client.go | 13 +++++------ internal/internal_workflow_client.go | 21 ++++++----------- mocks/DomainClient.go | 35 +++++++++++----------------- 4 files changed, 32 insertions(+), 50 deletions(-) diff --git a/client/client.go b/client/client.go index fd0ccdd34..f76c73b95 100644 --- a/client/client.go +++ b/client/client.go @@ -259,23 +259,22 @@ type ( // - InternalServiceError Register(ctx context.Context, request *s.RegisterDomainRequest) error - // Describe a domain. The domain has two part of information. - // DomainInfo - Which has Name, Status, Description, Owner Email. + // Describe a domain. The domain has 3 part of information + // DomainInfo - Which has Name, Status, Description, Owner Email // DomainConfiguration - Configuration like Workflow Execution Retention Period In Days, Whether to emit metrics. + // ReplicationConfiguration - replication config like clusters and active cluster name // The errors it can throw: // - EntityNotExistsError // - BadRequestError // - InternalServiceError - Describe(ctx context.Context, name string) (*s.DomainInfo, *s.DomainConfiguration, error) + Describe(ctx context.Context, name string) (*s.DescribeDomainResponse, error) - // Update a domain. The domain has two part of information. - // UpdateDomainInfo - To update domain Description and Owner Email. - // DomainConfiguration - Configuration like Workflow Execution Retention Period In Days, Whether to emit metrics. + // Update a domain. // The errors it can throw: // - EntityNotExistsError // - BadRequestError // - InternalServiceError - Update(ctx context.Context, name string, domainInfo *s.UpdateDomainInfo, domainConfig *s.DomainConfiguration) error + Update(ctx context.Context, request *s.UpdateDomainRequest) error } ) diff --git a/internal/client.go b/internal/client.go index 79a96ef07..269aca175 100644 --- a/internal/client.go +++ b/internal/client.go @@ -285,23 +285,22 @@ type ( // - InternalServiceError Register(ctx context.Context, request *s.RegisterDomainRequest) error - // Describe a domain. The domain has two part of information. - // DomainInfo - Which has Name, Status, Description, Owner Email. + // Describe a domain. The domain has 3 part of information + // DomainInfo - Which has Name, Status, Description, Owner Email // DomainConfiguration - Configuration like Workflow Execution Retention Period In Days, Whether to emit metrics. + // ReplicationConfiguration - replication config like clusters and active cluster name // The errors it can throw: // - EntityNotExistsError // - BadRequestError // - InternalServiceError - Describe(ctx context.Context, name string) (*s.DomainInfo, *s.DomainConfiguration, error) + Describe(ctx context.Context, name string) (*s.DescribeDomainResponse, error) - // Update a domain. The domain has two part of information. - // UpdateDomainInfo - To update domain Description and Owner Email. - // DomainConfiguration - Configuration like Workflow Execution Retention Period In Days, Whether to emit metrics. + // Update a domain. // The errors it can throw: // - EntityNotExistsError // - BadRequestError // - InternalServiceError - Update(ctx context.Context, name string, domainInfo *s.UpdateDomainInfo, domainConfig *s.DomainConfiguration) error + Update(ctx context.Context, request *s.UpdateDomainRequest) error } // WorkflowIDReusePolicy defines workflow ID reuse behavior. diff --git a/internal/internal_workflow_client.go b/internal/internal_workflow_client.go index 4204255ab..66c81537c 100644 --- a/internal/internal_workflow_client.go +++ b/internal/internal_workflow_client.go @@ -656,14 +656,15 @@ func (dc *domainClient) Register(ctx context.Context, request *s.RegisterDomainR }, serviceOperationRetryPolicy, isServiceTransientError) } -// Describe a domain. The domain has two part of information +// Describe a domain. The domain has 3 part of information // DomainInfo - Which has Name, Status, Description, Owner Email // DomainConfiguration - Configuration like Workflow Execution Retention Period In Days, Whether to emit metrics. +// ReplicationConfiguration - replication config like clusters and active cluster name // The errors it can throw: // - EntityNotExistsError // - BadRequestError // - InternalServiceError -func (dc *domainClient) Describe(ctx context.Context, name string) (*s.DomainInfo, *s.DomainConfiguration, error) { +func (dc *domainClient) Describe(ctx context.Context, name string) (*s.DescribeDomainResponse, error) { request := &s.DescribeDomainRequest{ Name: common.StringPtr(name), } @@ -678,25 +679,17 @@ func (dc *domainClient) Describe(ctx context.Context, name string) (*s.DomainInf return err }, serviceOperationRetryPolicy, isServiceTransientError) if err != nil { - return nil, nil, err + return nil, err } - return response.DomainInfo, response.Configuration, nil + return response, nil } -// Update a domain. The domain has two part of information -// DomainInfo - Which has Name, Status, Description, Owner Email -// DomainConfiguration - Configuration like Workflow Execution Retention Period In Days, Whether to emit metrics. +// Update a domain. // The errors it can throw: // - EntityNotExistsError // - BadRequestError // - InternalServiceError -func (dc *domainClient) Update(ctx context.Context, name string, domainInfo *s.UpdateDomainInfo, domainConfig *s.DomainConfiguration) error { - request := &s.UpdateDomainRequest{ - Name: common.StringPtr(name), - UpdatedInfo: domainInfo, - Configuration: domainConfig, - } - +func (dc *domainClient) Update(ctx context.Context, request *s.UpdateDomainRequest) error { return backoff.Retry(ctx, func() error { tchCtx, cancel, opt := newChannelContext(ctx) diff --git a/mocks/DomainClient.go b/mocks/DomainClient.go index 86a4c2d08..b993594fa 100644 --- a/mocks/DomainClient.go +++ b/mocks/DomainClient.go @@ -31,35 +31,26 @@ type DomainClient struct { } // Describe provides a mock function with given fields: ctx, name -func (_m *DomainClient) Describe(ctx context.Context, name string) (*shared.DomainInfo, *shared.DomainConfiguration, error) { +func (_m *DomainClient) Describe(ctx context.Context, name string) (*shared.DescribeDomainResponse, error) { ret := _m.Called(ctx, name) - var r0 *shared.DomainInfo - if rf, ok := ret.Get(0).(func(context.Context, string) *shared.DomainInfo); ok { + var r0 *shared.DescribeDomainResponse + if rf, ok := ret.Get(0).(func(context.Context, string) *shared.DescribeDomainResponse); ok { r0 = rf(ctx, name) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*shared.DomainInfo) + r0 = ret.Get(0).(*shared.DescribeDomainResponse) } } - var r1 *shared.DomainConfiguration - if rf, ok := ret.Get(1).(func(context.Context, string) *shared.DomainConfiguration); ok { + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { r1 = rf(ctx, name) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*shared.DomainConfiguration) - } + r1 = ret.Error(1) } - var r2 error - if rf, ok := ret.Get(2).(func(context.Context, string) error); ok { - r2 = rf(ctx, name) - } else { - r2 = ret.Error(2) - } - - return r0, r1, r2 + return r0, r1 } // Register provides a mock function with given fields: ctx, request @@ -76,13 +67,13 @@ func (_m *DomainClient) Register(ctx context.Context, request *shared.RegisterDo return r0 } -// Update provides a mock function with given fields: ctx, name, domainInfo, domainConfig -func (_m *DomainClient) Update(ctx context.Context, name string, domainInfo *shared.UpdateDomainInfo, domainConfig *shared.DomainConfiguration) error { - ret := _m.Called(ctx, name, domainInfo, domainConfig) +// Update provides a mock function with given fields: ctx, request +func (_m *DomainClient) Update(ctx context.Context, request *shared.UpdateDomainRequest) error { + ret := _m.Called(ctx) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, *shared.UpdateDomainInfo, *shared.DomainConfiguration) error); ok { - r0 = rf(ctx, name, domainInfo, domainConfig) + if rf, ok := ret.Get(0).(func(context.Context, *shared.UpdateDomainRequest) error); ok { + r0 = rf(ctx, request) } else { r0 = ret.Error(0) }