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

Thrift clients #3695

Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 2 additions & 3 deletions client/admin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"go.uber.org/yarpc"

"github.com/uber/cadence/.gen/go/admin"
"github.com/uber/cadence/.gen/go/admin/adminserviceclient"
"github.com/uber/cadence/.gen/go/replicator"
"github.com/uber/cadence/.gen/go/shared"
"github.com/uber/cadence/common"
Expand Down Expand Up @@ -360,13 +359,13 @@ func (c *clientImpl) createContextWithLargeTimeout(parent context.Context) (cont
return context.WithTimeout(parent, c.largeTimeout)
}

func (c *clientImpl) getRandomClient() (adminserviceclient.Interface, error) {
func (c *clientImpl) getRandomClient() (Client, error) {
// generate a random shard key to do load balancing
key := uuid.New()
client, err := c.clients.GetClientForKey(key)
if err != nil {
return nil, err
}

return client.(adminserviceclient.Interface), nil
return client.(Client), nil
}
29 changes: 27 additions & 2 deletions client/admin/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,34 @@

package admin

import "github.com/uber/cadence/.gen/go/admin/adminserviceclient"
import (
"context"

"go.uber.org/yarpc"

"github.com/uber/cadence/.gen/go/admin"
"github.com/uber/cadence/.gen/go/replicator"
"github.com/uber/cadence/.gen/go/shared"
)

// Client is the interface exposed by admin service client
type Client interface {
adminserviceclient.Interface
AddSearchAttribute(context.Context, *admin.AddSearchAttributeRequest, ...yarpc.CallOption) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq: why we will not use the embedded thrift interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed on purpose so that we can change method signatures to accept and return internal types instead of thrift counterparts. Thrift types will be only be used in thrift clients and handlers. These changes will come with upcoming PRs.

CloseShard(context.Context, *shared.CloseShardRequest, ...yarpc.CallOption) error
DescribeCluster(context.Context, ...yarpc.CallOption) (*admin.DescribeClusterResponse, error)
DescribeHistoryHost(context.Context, *shared.DescribeHistoryHostRequest, ...yarpc.CallOption) (*shared.DescribeHistoryHostResponse, error)
DescribeQueue(context.Context, *shared.DescribeQueueRequest, ...yarpc.CallOption) (*shared.DescribeQueueResponse, error)
DescribeWorkflowExecution(context.Context, *admin.DescribeWorkflowExecutionRequest, ...yarpc.CallOption) (*admin.DescribeWorkflowExecutionResponse, error)
GetDLQReplicationMessages(context.Context, *replicator.GetDLQReplicationMessagesRequest, ...yarpc.CallOption) (*replicator.GetDLQReplicationMessagesResponse, error)
GetDomainReplicationMessages(context.Context, *replicator.GetDomainReplicationMessagesRequest, ...yarpc.CallOption) (*replicator.GetDomainReplicationMessagesResponse, error)
GetReplicationMessages(context.Context, *replicator.GetReplicationMessagesRequest, ...yarpc.CallOption) (*replicator.GetReplicationMessagesResponse, error)
GetWorkflowExecutionRawHistoryV2(context.Context, *admin.GetWorkflowExecutionRawHistoryV2Request, ...yarpc.CallOption) (*admin.GetWorkflowExecutionRawHistoryV2Response, error)
MergeDLQMessages(context.Context, *replicator.MergeDLQMessagesRequest, ...yarpc.CallOption) (*replicator.MergeDLQMessagesResponse, error)
PurgeDLQMessages(context.Context, *replicator.PurgeDLQMessagesRequest, ...yarpc.CallOption) error
ReadDLQMessages(context.Context, *replicator.ReadDLQMessagesRequest, ...yarpc.CallOption) (*replicator.ReadDLQMessagesResponse, error)
ReapplyEvents(context.Context, *shared.ReapplyEventsRequest, ...yarpc.CallOption) error
RefreshWorkflowTasks(context.Context, *shared.RefreshWorkflowTasksRequest, ...yarpc.CallOption) error
RemoveTask(context.Context, *shared.RemoveTaskRequest, ...yarpc.CallOption) error
ResendReplicationTasks(context.Context, *admin.ResendReplicationTasksRequest, ...yarpc.CallOption) error
ResetQueue(context.Context, *shared.ResetQueueRequest, ...yarpc.CallOption) error
}
113 changes: 113 additions & 0 deletions client/admin/thriftClient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package admin

import (
"context"

"go.uber.org/yarpc"

"github.com/uber/cadence/.gen/go/admin"
"github.com/uber/cadence/.gen/go/admin/adminserviceclient"
"github.com/uber/cadence/.gen/go/replicator"
"github.com/uber/cadence/.gen/go/shared"
)

type thriftClient struct {
c adminserviceclient.Interface
}

// NewThriftClient creates a new instance of Client with thrift protocol
func NewThriftClient(c adminserviceclient.Interface) Client {
return thriftClient{c}
}

func (t thriftClient) AddSearchAttribute(ctx context.Context, request *admin.AddSearchAttributeRequest, opts ...yarpc.CallOption) error {
return t.c.AddSearchAttribute(ctx, request, opts...)
}

func (t thriftClient) CloseShard(ctx context.Context, request *shared.CloseShardRequest, opts ...yarpc.CallOption) error {
return t.c.CloseShard(ctx, request, opts...)
}

func (t thriftClient) DescribeCluster(ctx context.Context, opts ...yarpc.CallOption) (*admin.DescribeClusterResponse, error) {
return t.c.DescribeCluster(ctx, opts...)
}

func (t thriftClient) DescribeHistoryHost(ctx context.Context, request *shared.DescribeHistoryHostRequest, opts ...yarpc.CallOption) (*shared.DescribeHistoryHostResponse, error) {
return t.c.DescribeHistoryHost(ctx, request, opts...)
}

func (t thriftClient) DescribeQueue(ctx context.Context, request *shared.DescribeQueueRequest, opts ...yarpc.CallOption) (*shared.DescribeQueueResponse, error) {
return t.c.DescribeQueue(ctx, request, opts...)
}

func (t thriftClient) DescribeWorkflowExecution(ctx context.Context, request *admin.DescribeWorkflowExecutionRequest, opts ...yarpc.CallOption) (*admin.DescribeWorkflowExecutionResponse, error) {
return t.c.DescribeWorkflowExecution(ctx, request, opts...)
}

func (t thriftClient) GetDLQReplicationMessages(ctx context.Context, request *replicator.GetDLQReplicationMessagesRequest, opts ...yarpc.CallOption) (*replicator.GetDLQReplicationMessagesResponse, error) {
return t.c.GetDLQReplicationMessages(ctx, request, opts...)
}

func (t thriftClient) GetDomainReplicationMessages(ctx context.Context, request *replicator.GetDomainReplicationMessagesRequest, opts ...yarpc.CallOption) (*replicator.GetDomainReplicationMessagesResponse, error) {
return t.c.GetDomainReplicationMessages(ctx, request, opts...)
}

func (t thriftClient) GetReplicationMessages(ctx context.Context, request *replicator.GetReplicationMessagesRequest, opts ...yarpc.CallOption) (*replicator.GetReplicationMessagesResponse, error) {
return t.c.GetReplicationMessages(ctx, request, opts...)
}

func (t thriftClient) GetWorkflowExecutionRawHistoryV2(ctx context.Context, request *admin.GetWorkflowExecutionRawHistoryV2Request, opts ...yarpc.CallOption) (*admin.GetWorkflowExecutionRawHistoryV2Response, error) {
return t.c.GetWorkflowExecutionRawHistoryV2(ctx, request, opts...)
}

func (t thriftClient) MergeDLQMessages(ctx context.Context, request *replicator.MergeDLQMessagesRequest, opts ...yarpc.CallOption) (*replicator.MergeDLQMessagesResponse, error) {
return t.c.MergeDLQMessages(ctx, request, opts...)
}

func (t thriftClient) PurgeDLQMessages(ctx context.Context, request *replicator.PurgeDLQMessagesRequest, opts ...yarpc.CallOption) error {
return t.c.PurgeDLQMessages(ctx, request, opts...)
}

func (t thriftClient) ReadDLQMessages(ctx context.Context, request *replicator.ReadDLQMessagesRequest, opts ...yarpc.CallOption) (*replicator.ReadDLQMessagesResponse, error) {
return t.c.ReadDLQMessages(ctx, request, opts...)
}

func (t thriftClient) ReapplyEvents(ctx context.Context, request *shared.ReapplyEventsRequest, opts ...yarpc.CallOption) error {
return t.c.ReapplyEvents(ctx, request, opts...)
}

func (t thriftClient) RefreshWorkflowTasks(ctx context.Context, request *shared.RefreshWorkflowTasksRequest, opts ...yarpc.CallOption) error {
return t.c.RefreshWorkflowTasks(ctx, request, opts...)
}

func (t thriftClient) RemoveTask(ctx context.Context, request *shared.RemoveTaskRequest, opts ...yarpc.CallOption) error {
return t.c.RemoveTask(ctx, request, opts...)
}

func (t thriftClient) ResendReplicationTasks(ctx context.Context, request *admin.ResendReplicationTasksRequest, opts ...yarpc.CallOption) error {
return t.c.ResendReplicationTasks(ctx, request, opts...)
}

func (t thriftClient) ResetQueue(ctx context.Context, request *shared.ResetQueueRequest, opts ...yarpc.CallOption) error {
return t.c.ResetQueue(ctx, request, opts...)
}
8 changes: 4 additions & 4 deletions client/clientfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (cf *rpcClientFactory) NewMatchingClientWithTimeout(

clientProvider := func(clientKey string) (interface{}, error) {
dispatcher := cf.rpcFactory.CreateDispatcherForOutbound(matchingCaller, common.MatchingServiceName, clientKey)
return matchingserviceclient.New(dispatcher.ClientConfig(common.MatchingServiceName)), nil
return matching.NewThriftClient(matchingserviceclient.New(dispatcher.ClientConfig(common.MatchingServiceName))), nil
}

client := matching.NewClient(
Expand Down Expand Up @@ -193,7 +193,7 @@ func (cf *rpcClientFactory) NewFrontendClientWithTimeout(

clientProvider := func(clientKey string) (interface{}, error) {
dispatcher := cf.rpcFactory.CreateDispatcherForOutbound(frontendCaller, common.FrontendServiceName, clientKey)
return workflowserviceclient.New(dispatcher.ClientConfig(common.FrontendServiceName)), nil
return frontend.NewThriftClient(workflowserviceclient.New(dispatcher.ClientConfig(common.FrontendServiceName))), nil
}

client := frontend.NewClient(timeout, longPollTimeout, common.NewClientCache(keyResolver, clientProvider))
Expand All @@ -214,7 +214,7 @@ func (cf *rpcClientFactory) NewAdminClientWithTimeoutAndDispatcher(
}

clientProvider := func(clientKey string) (interface{}, error) {
return adminserviceclient.New(dispatcher.ClientConfig(rpcName)), nil
return admin.NewThriftClient(adminserviceclient.New(dispatcher.ClientConfig(rpcName))), nil
}

client := admin.NewClient(timeout, largeTimeout, common.NewClientCache(keyResolver, clientProvider))
Expand All @@ -235,7 +235,7 @@ func (cf *rpcClientFactory) NewFrontendClientWithTimeoutAndDispatcher(
}

clientProvider := func(clientKey string) (interface{}, error) {
return workflowserviceclient.New(dispatcher.ClientConfig(rpcName)), nil
return frontend.NewThriftClient(workflowserviceclient.New(dispatcher.ClientConfig(rpcName))), nil
}

client := frontend.NewClient(timeout, longPollTimeout, common.NewClientCache(keyResolver, clientProvider))
Expand Down
5 changes: 2 additions & 3 deletions client/frontend/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/pborman/uuid"
"go.uber.org/yarpc"

"github.com/uber/cadence/.gen/go/cadence/workflowserviceclient"
"github.com/uber/cadence/.gen/go/shared"
"github.com/uber/cadence/common"
)
Expand Down Expand Up @@ -649,15 +648,15 @@ func (c *clientImpl) createLongPollContext(parent context.Context) (context.Cont
return context.WithTimeout(parent, c.longPollTimeout)
}

func (c *clientImpl) getRandomClient() (workflowserviceclient.Interface, error) {
func (c *clientImpl) getRandomClient() (Client, error) {
// generate a random shard key to do load balancing
key := uuid.New()
client, err := c.clients.GetClientForKey(key)
if err != nil {
return nil, err
}

return client.(workflowserviceclient.Interface), nil
return client.(Client), nil
}

func (c *clientImpl) GetClusterInfo(
Expand Down
45 changes: 43 additions & 2 deletions client/frontend/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,51 @@
package frontend

import (
"github.com/uber/cadence/.gen/go/cadence/workflowserviceclient"
"context"

"go.uber.org/yarpc"

"github.com/uber/cadence/.gen/go/shared"
)

// Client is the interface exposed by frontend service client
type Client interface {
workflowserviceclient.Interface
CountWorkflowExecutions(context.Context, *shared.CountWorkflowExecutionsRequest, ...yarpc.CallOption) (*shared.CountWorkflowExecutionsResponse, error)
DeprecateDomain(context.Context, *shared.DeprecateDomainRequest, ...yarpc.CallOption) error
DescribeDomain(context.Context, *shared.DescribeDomainRequest, ...yarpc.CallOption) (*shared.DescribeDomainResponse, error)
DescribeTaskList(context.Context, *shared.DescribeTaskListRequest, ...yarpc.CallOption) (*shared.DescribeTaskListResponse, error)
DescribeWorkflowExecution(context.Context, *shared.DescribeWorkflowExecutionRequest, ...yarpc.CallOption) (*shared.DescribeWorkflowExecutionResponse, error)
GetClusterInfo(context.Context, ...yarpc.CallOption) (*shared.ClusterInfo, error)
GetSearchAttributes(context.Context, ...yarpc.CallOption) (*shared.GetSearchAttributesResponse, error)
GetWorkflowExecutionHistory(context.Context, *shared.GetWorkflowExecutionHistoryRequest, ...yarpc.CallOption) (*shared.GetWorkflowExecutionHistoryResponse, error)
ListArchivedWorkflowExecutions(context.Context, *shared.ListArchivedWorkflowExecutionsRequest, ...yarpc.CallOption) (*shared.ListArchivedWorkflowExecutionsResponse, error)
ListClosedWorkflowExecutions(context.Context, *shared.ListClosedWorkflowExecutionsRequest, ...yarpc.CallOption) (*shared.ListClosedWorkflowExecutionsResponse, error)
ListDomains(context.Context, *shared.ListDomainsRequest, ...yarpc.CallOption) (*shared.ListDomainsResponse, error)
ListOpenWorkflowExecutions(context.Context, *shared.ListOpenWorkflowExecutionsRequest, ...yarpc.CallOption) (*shared.ListOpenWorkflowExecutionsResponse, error)
ListTaskListPartitions(context.Context, *shared.ListTaskListPartitionsRequest, ...yarpc.CallOption) (*shared.ListTaskListPartitionsResponse, error)
ListWorkflowExecutions(context.Context, *shared.ListWorkflowExecutionsRequest, ...yarpc.CallOption) (*shared.ListWorkflowExecutionsResponse, error)
PollForActivityTask(context.Context, *shared.PollForActivityTaskRequest, ...yarpc.CallOption) (*shared.PollForActivityTaskResponse, error)
PollForDecisionTask(context.Context, *shared.PollForDecisionTaskRequest, ...yarpc.CallOption) (*shared.PollForDecisionTaskResponse, error)
QueryWorkflow(context.Context, *shared.QueryWorkflowRequest, ...yarpc.CallOption) (*shared.QueryWorkflowResponse, error)
RecordActivityTaskHeartbeat(context.Context, *shared.RecordActivityTaskHeartbeatRequest, ...yarpc.CallOption) (*shared.RecordActivityTaskHeartbeatResponse, error)
RecordActivityTaskHeartbeatByID(context.Context, *shared.RecordActivityTaskHeartbeatByIDRequest, ...yarpc.CallOption) (*shared.RecordActivityTaskHeartbeatResponse, error)
RegisterDomain(context.Context, *shared.RegisterDomainRequest, ...yarpc.CallOption) error
RequestCancelWorkflowExecution(context.Context, *shared.RequestCancelWorkflowExecutionRequest, ...yarpc.CallOption) error
ResetStickyTaskList(context.Context, *shared.ResetStickyTaskListRequest, ...yarpc.CallOption) (*shared.ResetStickyTaskListResponse, error)
ResetWorkflowExecution(context.Context, *shared.ResetWorkflowExecutionRequest, ...yarpc.CallOption) (*shared.ResetWorkflowExecutionResponse, error)
RespondActivityTaskCanceled(context.Context, *shared.RespondActivityTaskCanceledRequest, ...yarpc.CallOption) error
RespondActivityTaskCanceledByID(context.Context, *shared.RespondActivityTaskCanceledByIDRequest, ...yarpc.CallOption) error
RespondActivityTaskCompleted(context.Context, *shared.RespondActivityTaskCompletedRequest, ...yarpc.CallOption) error
RespondActivityTaskCompletedByID(context.Context, *shared.RespondActivityTaskCompletedByIDRequest, ...yarpc.CallOption) error
RespondActivityTaskFailed(context.Context, *shared.RespondActivityTaskFailedRequest, ...yarpc.CallOption) error
RespondActivityTaskFailedByID(context.Context, *shared.RespondActivityTaskFailedByIDRequest, ...yarpc.CallOption) error
RespondDecisionTaskCompleted(context.Context, *shared.RespondDecisionTaskCompletedRequest, ...yarpc.CallOption) (*shared.RespondDecisionTaskCompletedResponse, error)
RespondDecisionTaskFailed(context.Context, *shared.RespondDecisionTaskFailedRequest, ...yarpc.CallOption) error
RespondQueryTaskCompleted(context.Context, *shared.RespondQueryTaskCompletedRequest, ...yarpc.CallOption) error
ScanWorkflowExecutions(context.Context, *shared.ListWorkflowExecutionsRequest, ...yarpc.CallOption) (*shared.ListWorkflowExecutionsResponse, error)
SignalWithStartWorkflowExecution(context.Context, *shared.SignalWithStartWorkflowExecutionRequest, ...yarpc.CallOption) (*shared.StartWorkflowExecutionResponse, error)
SignalWorkflowExecution(context.Context, *shared.SignalWorkflowExecutionRequest, ...yarpc.CallOption) error
StartWorkflowExecution(context.Context, *shared.StartWorkflowExecutionRequest, ...yarpc.CallOption) (*shared.StartWorkflowExecutionResponse, error)
TerminateWorkflowExecution(context.Context, *shared.TerminateWorkflowExecutionRequest, ...yarpc.CallOption) error
UpdateDomain(context.Context, *shared.UpdateDomainRequest, ...yarpc.CallOption) (*shared.UpdateDomainResponse, error)
}
Loading