• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence-java-client / 1847

pending completion
1847

Pull #821

buildkite

Shaddoll
dummy change
Pull Request #821: Add isolation group header to service client

10 of 10 new or added lines in 3 files covered. (100.0%)

11117 of 18414 relevant lines covered (60.37%)

0.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.22
/src/main/java/com/uber/cadence/serviceclient/ClientOptions.java
1
/*
2
 *  Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
3
 *  Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
4
 *  Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 *  Licensed under the Apache License, Version 2.0 (the "License"). You may not
7
 *  use this file except in compliance with the License. A copy of the License is
8
 *  located at
9
 *
10
 *  http://aws.amazon.com/apache2.0
11
 *
12
 *  or in the "license" file accompanying this file. This file is distributed on
13
 *  an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14
 *  express or implied. See the License for the specific language governing
15
 *  permissions and limitations under the License.
16
 */
17

18
package com.uber.cadence.serviceclient;
19

20
import com.google.common.base.Strings;
21
import com.google.common.collect.ImmutableMap;
22
import com.uber.cadence.FeatureFlags;
23
import com.uber.cadence.internal.metrics.NoopScope;
24
import com.uber.cadence.serviceclient.auth.IAuthorizationProvider;
25
import com.uber.m3.tally.Scope;
26
import io.grpc.ManagedChannel;
27
import java.util.Map;
28

29
public class ClientOptions {
30

31
  private static final int DEFAULT_LOCAL_CADENCE_SERVER_PORT = 7933;
32

33
  private static final String LOCALHOST = "127.0.0.1";
34

35
  /** Default RPC timeout used for all non long poll calls. */
36
  private static final long DEFAULT_RPC_TIMEOUT_MILLIS = 3 * 1000;
37
  /** Default RPC timeout used for all long poll calls. */
38
  private static final long DEFAULT_POLL_RPC_TIMEOUT_MILLIS = 30 * 1000;
39

40
  /** Default RPC timeout for QueryWorkflow */
41
  private static final long DEFAULT_QUERY_RPC_TIMEOUT_MILLIS = 10 * 1000;
42

43
  /** Default RPC timeout for ListArchivedWorkflow */
44
  private static final long DEFAULT_LIST_ARCHIVED_WORKFLOW_TIMEOUT_MILLIS = 180 * 1000;
45

46
  private static final String DEFAULT_CLIENT_APP_NAME = "cadence-client";
47

48
  /** Name of the Cadence service front end as required by TChannel. */
49
  private static final String DEFAULT_SERVICE_NAME = "cadence-frontend";
50

51
  private static final ClientOptions DEFAULT_INSTANCE;
52

53
  static {
54
    DEFAULT_INSTANCE = new Builder().build();
1✔
55
  }
1✔
56

57
  private final String host;
58
  private final int port;
59
  private final ManagedChannel gRPCChannel;
60
  /** The tChannel timeout in milliseconds */
61
  private final long rpcTimeoutMillis;
62
  /** The tChannel timeout for long poll calls in milliseconds */
63
  private final long rpcLongPollTimeoutMillis;
64
  /** The tChannel timeout for query workflow call in milliseconds */
65
  private final long rpcQueryTimeoutMillis;
66
  /** The tChannel timeout for list archived workflow call in milliseconds */
67
  private final long rpcListArchivedWorkflowTimeoutMillis;
68
  /** TChannel service name that the Cadence service was started with. */
69
  private final String serviceName;
70
  /** Name of the service using the cadence-client. */
71
  private final String clientAppName;
72
  /** Client for metrics reporting. */
73
  private final Scope metricsScope;
74
  /** Optional TChannel transport headers */
75
  private final Map<String, String> transportHeaders;
76
  /** Optional TChannel headers */
77
  private final Map<String, String> headers;
78
  /** Optional authorization provider */
79
  private final IAuthorizationProvider authProvider;
80
  /** Optional Feature flags to turn on/off some Cadence features */
81
  private final FeatureFlags featureFlags;
82
  /** Optional isolation group of the service if tasklist isolation is enabled */
83
  private final String isolationGroup;
84

85
  private ClientOptions(Builder builder) {
1✔
86
    if (Strings.isNullOrEmpty(builder.host)) {
1✔
87
      host =
1✔
88
          Strings.isNullOrEmpty(System.getenv("CADENCE_SEEDS"))
1✔
89
              ? LOCALHOST
1✔
90
              : System.getenv("CADENCE_SEEDS");
1✔
91
    } else {
92
      host = builder.host;
×
93
    }
94
    this.port = builder.port;
1✔
95
    this.gRPCChannel = builder.gRPCChannel;
1✔
96
    this.rpcTimeoutMillis = builder.rpcTimeoutMillis;
1✔
97
    if (builder.clientAppName == null) {
1✔
98
      this.clientAppName = DEFAULT_CLIENT_APP_NAME;
×
99
    } else {
100
      this.clientAppName = builder.clientAppName;
1✔
101
    }
102
    if (builder.serviceName == null) {
1✔
103
      this.serviceName = DEFAULT_SERVICE_NAME;
1✔
104
    } else {
105
      this.serviceName = builder.serviceName;
×
106
    }
107
    this.rpcLongPollTimeoutMillis = builder.rpcLongPollTimeoutMillis;
1✔
108
    this.rpcQueryTimeoutMillis = builder.rpcQueryTimeoutMillis;
1✔
109
    this.rpcListArchivedWorkflowTimeoutMillis = builder.rpcListArchivedWorkflowTimeoutMillis;
1✔
110
    if (builder.metricsScope == null) {
1✔
111
      builder.metricsScope = NoopScope.getInstance();
1✔
112
    }
113
    this.metricsScope = builder.metricsScope;
1✔
114
    if (builder.transportHeaders != null) {
1✔
115
      this.transportHeaders = ImmutableMap.copyOf(builder.transportHeaders);
×
116
    } else {
117
      this.transportHeaders = ImmutableMap.of();
1✔
118
    }
119

120
    this.featureFlags = builder.featureFlags;
1✔
121

122
    if (builder.headers != null) {
1✔
123
      this.headers = ImmutableMap.copyOf(builder.headers);
×
124
    } else {
125
      this.headers = ImmutableMap.of();
1✔
126
    }
127
    this.authProvider = builder.authProvider;
1✔
128
    this.isolationGroup = builder.isolationGroup;
1✔
129
  }
1✔
130

131
  public static ClientOptions defaultInstance() {
132
    return DEFAULT_INSTANCE;
×
133
  }
134

135
  public static Builder newBuilder() {
136
    return new Builder();
1✔
137
  }
138

139
  public String getHost() {
140
    return host;
1✔
141
  }
142

143
  public int getPort() {
144
    return port;
1✔
145
  }
146

147
  public ManagedChannel getGRPCChannel() {
148
    return gRPCChannel;
×
149
  }
150

151
  /** @return Returns the rpc timeout value in millis. */
152
  public long getRpcTimeoutMillis() {
153
    return rpcTimeoutMillis;
×
154
  }
155

156
  /** @return Returns the rpc timout for long poll requests in millis. */
157
  public long getRpcLongPollTimeoutMillis() {
158
    return rpcLongPollTimeoutMillis;
×
159
  }
160

161
  /** @return Returns the rpc timout for query workflow requests in millis. */
162
  public long getRpcQueryTimeoutMillis() {
163
    return rpcQueryTimeoutMillis;
×
164
  }
165

166
  /** @return Returns the rpc timout for list archived workflow requests in millis. */
167
  public long getRpcListArchivedWorkflowTimeoutMillis() {
168
    return rpcListArchivedWorkflowTimeoutMillis;
×
169
  }
170

171
  /** Returns the client application name. */
172
  public String getClientAppName() {
173
    return this.clientAppName;
1✔
174
  }
175

176
  public String getServiceName() {
177
    return serviceName;
1✔
178
  }
179

180
  public Scope getMetricsScope() {
181
    return metricsScope;
×
182
  }
183

184
  public Map<String, String> getTransportHeaders() {
185
    return transportHeaders;
×
186
  }
187

188
  public Map<String, String> getHeaders() {
189
    return headers;
1✔
190
  }
191

192
  public IAuthorizationProvider getAuthProvider() {
193
    return authProvider;
×
194
  }
195

196
  public FeatureFlags getFeatureFlags() {
197
    return this.featureFlags;
1✔
198
  }
199

200
  public String getIsolationGroup() {
201
    return this.isolationGroup;
1✔
202
  }
203

204
  /**
205
   * Builder is the builder for ClientOptions.
206
   *
207
   * @author venkat
208
   */
209
  public static class Builder {
210

211
    private String host;
212
    private int port = DEFAULT_LOCAL_CADENCE_SERVER_PORT;
1✔
213
    private ManagedChannel gRPCChannel;
214
    private String clientAppName = DEFAULT_CLIENT_APP_NAME;
1✔
215
    private long rpcTimeoutMillis = DEFAULT_RPC_TIMEOUT_MILLIS;
1✔
216
    private long rpcLongPollTimeoutMillis = DEFAULT_POLL_RPC_TIMEOUT_MILLIS;
1✔
217
    private long rpcQueryTimeoutMillis = DEFAULT_QUERY_RPC_TIMEOUT_MILLIS;
1✔
218
    private long rpcListArchivedWorkflowTimeoutMillis =
1✔
219
        DEFAULT_LIST_ARCHIVED_WORKFLOW_TIMEOUT_MILLIS;
220
    private String serviceName;
221
    private Scope metricsScope;
222
    private Map<String, String> transportHeaders;
223
    private Map<String, String> headers;
224
    private IAuthorizationProvider authProvider;
225
    private FeatureFlags featureFlags;
226
    private String isolationGroup;
227

228
    private Builder() {}
1✔
229

230
    public Builder setHost(String host) {
231
      this.host = host;
×
232
      return this;
×
233
    }
234

235
    public Builder setAuthorizationProvider(IAuthorizationProvider provider) {
236
      this.authProvider = provider;
×
237
      return this;
×
238
    }
239

240
    public Builder setPort(int port) {
241
      this.port = port;
×
242
      return this;
×
243
    }
244

245
    /** Sets gRPC channel to use. Exclusive with host and port. */
246
    public Builder setGRPCChannel(ManagedChannel gRPCChannel) {
247
      this.gRPCChannel = gRPCChannel;
×
248
      return this;
×
249
    }
250

251
    /**
252
     * Sets the rpc timeout value for non query and non long poll calls. Default is 1000.
253
     *
254
     * @param timeoutMillis timeout, in millis.
255
     */
256
    public Builder setRpcTimeout(long timeoutMillis) {
257
      this.rpcTimeoutMillis = timeoutMillis;
×
258
      return this;
×
259
    }
260

261
    /**
262
     * Sets the rpc timeout value for the following long poll based operations: PollForDecisionTask,
263
     * PollForActivityTask, GetWorkflowExecutionHistory. Should never be below 60000 as this is
264
     * server side timeout for the long poll. Default is 61000.
265
     *
266
     * @param timeoutMillis timeout, in millis.
267
     */
268
    public Builder setRpcLongPollTimeout(long timeoutMillis) {
269
      this.rpcLongPollTimeoutMillis = timeoutMillis;
×
270
      return this;
×
271
    }
272

273
    /**
274
     * Sets the rpc timeout value for query calls. Default is 10000.
275
     *
276
     * @param timeoutMillis timeout, in millis.
277
     */
278
    public Builder setQueryRpcTimeout(long timeoutMillis) {
279
      this.rpcQueryTimeoutMillis = timeoutMillis;
×
280
      return this;
×
281
    }
282

283
    /**
284
     * Sets the rpc timeout value for query calls. Default is 180000.
285
     *
286
     * @param timeoutMillis timeout, in millis.
287
     */
288
    public Builder setListArchivedWorkflowRpcTimeout(long timeoutMillis) {
289
      this.rpcListArchivedWorkflowTimeoutMillis = timeoutMillis;
×
290
      return this;
×
291
    }
292

293
    /** Returns the feature flags defined in ClientOptions */
294
    public FeatureFlags getFeatureFlags() {
295
      return this.featureFlags;
×
296
    }
297

298
    /**
299
     * Sets the feature flags to turn on/off some Cadence features By default, all features under
300
     * FeatureFlags are turned off.
301
     *
302
     * @param featureFlags FeatureFlags
303
     */
304
    public Builder setFeatureFlags(FeatureFlags featureFlags) {
305
      this.featureFlags = featureFlags;
1✔
306
      return this;
1✔
307
    }
308

309
    /**
310
     * Sets the client application name.
311
     *
312
     * <p>This name will be used as the tchannel client service name. It will also be reported as a
313
     * tag along with metrics emitted to m3.
314
     *
315
     * @param clientAppName String representing the client application name.
316
     * @return Builder for ClentOptions
317
     */
318
    public Builder setClientAppName(String clientAppName) {
319
      this.clientAppName = clientAppName;
×
320
      return this;
×
321
    }
322

323
    /**
324
     * Sets the service name that Cadence service was started with.
325
     *
326
     * @param serviceName String representing the service name
327
     * @return Builder for ClentOptions
328
     */
329
    public Builder setServiceName(String serviceName) {
330
      this.serviceName = serviceName;
×
331
      return this;
×
332
    }
333

334
    /**
335
     * Sets the metrics scope to be used for metrics reporting.
336
     *
337
     * @param metricsScope
338
     * @return Builder for ClentOptions
339
     */
340
    public Builder setMetricsScope(Scope metricsScope) {
341
      this.metricsScope = metricsScope;
×
342
      return this;
×
343
    }
344

345
    /**
346
     * Sets additional transport headers for tchannel client.
347
     *
348
     * @param transportHeaders Map with additional transport headers
349
     * @return Builder for ClentOptions
350
     */
351
    public Builder setTransportHeaders(Map<String, String> transportHeaders) {
352
      this.transportHeaders = transportHeaders;
×
353
      return this;
×
354
    }
355

356
    public Builder setHeaders(Map<String, String> headers) {
357
      this.headers = headers;
×
358
      return this;
×
359
    }
360

361
    /**
362
     * Sets the isolation group to be used for matching.
363
     *
364
     * @param isolationGroup
365
     * @return Builder for ClentOptions
366
     */
367
    public Builder setIsolationGroup(String isolationGroup) {
368
      this.isolationGroup = isolationGroup;
×
369
      return this;
×
370
    }
371

372
    /**
373
     * Builds and returns a ClientOptions object.
374
     *
375
     * @return ClientOptions object with the specified params.
376
     */
377
    public ClientOptions build() {
378
      return new ClientOptions(this);
1✔
379
    }
380
  }
381
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc