@@ -33,6 +33,7 @@ import (
33
33
34
34
"go.temporal.io/api/serviceerror"
35
35
"go.temporal.io/api/workflowservice/v1"
36
+ "google.golang.org/grpc"
36
37
37
38
"go.temporal.io/server/api/adminservice/v1"
38
39
"go.temporal.io/server/api/historyservice/v1"
@@ -48,14 +49,16 @@ type (
48
49
// Bean is a collection of clients
49
50
Bean interface {
50
51
GetHistoryClient () historyservice.HistoryServiceClient
51
- SetHistoryClient (client historyservice.HistoryServiceClient )
52
52
GetMatchingClient (namespaceIDToName NamespaceIDToNameFunc ) (matchingservice.MatchingServiceClient , error )
53
- SetMatchingClient (client matchingservice.MatchingServiceClient )
54
53
GetFrontendClient () workflowservice.WorkflowServiceClient
55
- SetFrontendClient (client workflowservice.WorkflowServiceClient )
56
- GetRemoteAdminClient (cluster string ) (adminservice.AdminServiceClient , error )
57
- SetRemoteAdminClient (cluster string , client adminservice.AdminServiceClient )
58
- GetRemoteFrontendClient (cluster string ) (workflowservice.WorkflowServiceClient , error )
54
+ GetRemoteAdminClient (string ) (adminservice.AdminServiceClient , error )
55
+ SetRemoteAdminClient (string , adminservice.AdminServiceClient )
56
+ GetRemoteFrontendClient (string ) (grpc.ClientConnInterface , workflowservice.WorkflowServiceClient , error )
57
+ }
58
+
59
+ frontendClient struct {
60
+ connection grpc.ClientConnInterface
61
+ workflowservice.WorkflowServiceClient
59
62
}
60
63
61
64
clientBeanImpl struct {
68
71
adminClientsLock sync.RWMutex
69
72
adminClients map [string ]adminservice.AdminServiceClient
70
73
frontendClientsLock sync.RWMutex
71
- frontendClients map [string ]workflowservice. WorkflowServiceClient
74
+ frontendClients map [string ]frontendClient
72
75
}
73
76
)
74
77
@@ -81,7 +84,7 @@ func NewClientBean(factory Factory, clusterMetadata cluster.Metadata) (Bean, err
81
84
}
82
85
83
86
adminClients := map [string ]adminservice.AdminServiceClient {}
84
- frontendClients := map [string ]workflowservice. WorkflowServiceClient {}
87
+ frontendClients := map [string ]frontendClient {}
85
88
86
89
currentClusterName := clusterMetadata .GetCurrentClusterName ()
87
90
// Init local cluster client with membership info
@@ -92,15 +95,18 @@ func NewClientBean(factory Factory, clusterMetadata cluster.Metadata) (Bean, err
92
95
if err != nil {
93
96
return nil , err
94
97
}
95
- frontendClient , err := factory .NewLocalFrontendClientWithTimeout (
98
+ conn , client , err := factory .NewLocalFrontendClientWithTimeout (
96
99
frontend .DefaultTimeout ,
97
100
frontend .DefaultLongPollTimeout ,
98
101
)
99
102
if err != nil {
100
103
return nil , err
101
104
}
102
105
adminClients [currentClusterName ] = adminClient
103
- frontendClients [currentClusterName ] = frontendClient
106
+ frontendClients [currentClusterName ] = frontendClient {
107
+ connection : conn ,
108
+ WorkflowServiceClient : client ,
109
+ }
104
110
105
111
for clusterName , info := range clusterMetadata .GetAllClusterInfo () {
106
112
if ! info .Enabled || clusterName == currentClusterName {
@@ -111,13 +117,16 @@ func NewClientBean(factory Factory, clusterMetadata cluster.Metadata) (Bean, err
111
117
admin .DefaultTimeout ,
112
118
admin .DefaultLargeTimeout ,
113
119
)
114
- frontendClient = factory .NewRemoteFrontendClientWithTimeout (
120
+ conn , client = factory .NewRemoteFrontendClientWithTimeout (
115
121
info .RPCAddress ,
116
122
frontend .DefaultTimeout ,
117
123
frontend .DefaultLongPollTimeout ,
118
124
)
119
125
adminClients [clusterName ] = adminClient
120
- frontendClients [clusterName ] = frontendClient
126
+ frontendClients [clusterName ] = frontendClient {
127
+ connection : conn ,
128
+ WorkflowServiceClient : client ,
129
+ }
121
130
}
122
131
123
132
bean := & clientBeanImpl {
@@ -154,64 +163,49 @@ func (h *clientBeanImpl) GetHistoryClient() historyservice.HistoryServiceClient
154
163
return h .historyClient
155
164
}
156
165
157
- func (h * clientBeanImpl ) SetHistoryClient (
158
- client historyservice.HistoryServiceClient ,
159
- ) {
160
- h .historyClient = client
161
- }
162
-
163
166
func (h * clientBeanImpl ) GetMatchingClient (namespaceIDToName NamespaceIDToNameFunc ) (matchingservice.MatchingServiceClient , error ) {
164
167
if client := h .matchingClient .Load (); client != nil {
165
168
return client .(matchingservice.MatchingServiceClient ), nil
166
169
}
167
170
return h .lazyInitMatchingClient (namespaceIDToName )
168
171
}
169
172
170
- func (h * clientBeanImpl ) SetMatchingClient (
171
- client matchingservice.MatchingServiceClient ,
172
- ) {
173
- h .matchingClient .Store (client )
174
- }
175
-
176
173
func (h * clientBeanImpl ) GetFrontendClient () workflowservice.WorkflowServiceClient {
177
174
return h .frontendClients [h .clusterMetadata .GetCurrentClusterName ()]
178
175
}
179
176
180
- func (h * clientBeanImpl ) SetFrontendClient (
181
- client workflowservice.WorkflowServiceClient ,
182
- ) {
183
- h .frontendClients [h .clusterMetadata .GetCurrentClusterName ()] = client
184
- }
185
-
186
177
func (h * clientBeanImpl ) GetRemoteAdminClient (cluster string ) (adminservice.AdminServiceClient , error ) {
187
178
h .adminClientsLock .RLock ()
188
179
client , ok := h .adminClients [cluster ]
189
180
h .adminClientsLock .RUnlock ()
181
+ if ok {
182
+ return client , nil
183
+ }
190
184
191
- if ! ok {
192
- clusterInfo , clusterFound := h .clusterMetadata .GetAllClusterInfo ()[cluster ]
193
- if ! clusterFound {
194
- return nil , & serviceerror.NotFound {
195
- Message : fmt .Sprintf (
196
- "Unknown cluster name: %v with given cluster information map: %v." ,
197
- cluster ,
198
- clusterInfo ,
199
- ),
200
- }
185
+ clusterInfo , clusterFound := h .clusterMetadata .GetAllClusterInfo ()[cluster ]
186
+ if ! clusterFound {
187
+ return nil , & serviceerror.NotFound {
188
+ Message : fmt .Sprintf (
189
+ "Unknown cluster name: %v with given cluster information map: %v." ,
190
+ cluster ,
191
+ clusterInfo ,
192
+ ),
201
193
}
194
+ }
202
195
203
- h .adminClientsLock .Lock ()
204
- defer h .adminClientsLock .Unlock ()
205
- client , ok = h .adminClients [cluster ]
206
- if ! ok {
207
- client = h .factory .NewRemoteAdminClientWithTimeout (
208
- clusterInfo .RPCAddress ,
209
- admin .DefaultTimeout ,
210
- admin .DefaultLargeTimeout ,
211
- )
212
- h .setRemoteAdminClientLocked (cluster , client )
213
- }
196
+ h .adminClientsLock .Lock ()
197
+ defer h .adminClientsLock .Unlock ()
198
+ client , ok = h .adminClients [cluster ]
199
+ if ok {
200
+ return client , nil
214
201
}
202
+
203
+ client = h .factory .NewRemoteAdminClientWithTimeout (
204
+ clusterInfo .RPCAddress ,
205
+ admin .DefaultTimeout ,
206
+ admin .DefaultLargeTimeout ,
207
+ )
208
+ h .adminClients [cluster ] = client
215
209
return client , nil
216
210
}
217
211
@@ -222,46 +216,47 @@ func (h *clientBeanImpl) SetRemoteAdminClient(
222
216
h .adminClientsLock .Lock ()
223
217
defer h .adminClientsLock .Unlock ()
224
218
225
- h .setRemoteAdminClientLocked ( cluster , client )
219
+ h .adminClients [ cluster ] = client
226
220
}
227
221
228
- func (h * clientBeanImpl ) GetRemoteFrontendClient (cluster string ) (workflowservice.WorkflowServiceClient , error ) {
222
+ func (h * clientBeanImpl ) GetRemoteFrontendClient (clusterName string ) (grpc. ClientConnInterface , workflowservice.WorkflowServiceClient , error ) {
229
223
h .frontendClientsLock .RLock ()
230
- client , ok := h .frontendClients [cluster ]
224
+ client , ok := h .frontendClients [clusterName ]
231
225
h .frontendClientsLock .RUnlock ()
226
+ if ok {
227
+ return client .connection , client , nil
228
+ }
232
229
233
- if ! ok {
234
- clusterInfo , clusterFound := h .clusterMetadata .GetAllClusterInfo ()[cluster ]
235
- if ! clusterFound {
236
- return nil , & serviceerror.NotFound {
237
- Message : fmt .Sprintf (
238
- "Unknown cluster name: %v with given cluster information map: %v." ,
239
- cluster ,
240
- clusterInfo ,
241
- ),
242
- }
230
+ clusterInfo , clusterFound := h .clusterMetadata .GetAllClusterInfo ()[clusterName ]
231
+ if ! clusterFound {
232
+ return nil , nil , & serviceerror.NotFound {
233
+ Message : fmt .Sprintf (
234
+ "Unknown clusterName name: %v with given clusterName information map: %v." ,
235
+ clusterName ,
236
+ clusterInfo ,
237
+ ),
243
238
}
239
+ }
244
240
245
- h .frontendClientsLock .Lock ()
246
- defer h .frontendClientsLock .Unlock ()
247
- client , ok = h .frontendClients [cluster ]
248
- if ! ok {
249
- client = h .factory .NewRemoteFrontendClientWithTimeout (
250
- clusterInfo .RPCAddress ,
251
- frontend .DefaultTimeout ,
252
- frontend .DefaultLongPollTimeout ,
253
- )
254
- h .setRemoteFrontendClientLocked (cluster , client )
255
- }
241
+ h .frontendClientsLock .Lock ()
242
+ defer h .frontendClientsLock .Unlock ()
243
+
244
+ client , ok = h .frontendClients [clusterName ]
245
+ if ok {
246
+ return client .connection , client , nil
256
247
}
257
- return client , nil
258
- }
259
248
260
- func (h * clientBeanImpl ) setRemoteFrontendClientLocked (
261
- cluster string ,
262
- client workflowservice.WorkflowServiceClient ,
263
- ) {
264
- h .frontendClients [cluster ] = client
249
+ conn , fClient := h .factory .NewRemoteFrontendClientWithTimeout (
250
+ clusterInfo .RPCAddress ,
251
+ frontend .DefaultTimeout ,
252
+ frontend .DefaultLongPollTimeout ,
253
+ )
254
+ client = frontendClient {
255
+ connection : conn ,
256
+ WorkflowServiceClient : fClient ,
257
+ }
258
+ h .frontendClients [clusterName ] = client
259
+ return client .connection , client , nil
265
260
}
266
261
267
262
func (h * clientBeanImpl ) setRemoteAdminClientLocked (
0 commit comments