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

uber / cadence-java-client / 1841

pending completion
1841

Pull #820

buildkite

Shaddoll
Add isolation group header to service client
Pull Request #820: Add isolation group header to service client

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

11116 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 isolaationGroup of the service */
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

129
    this.isolationGroup = builder.isolationGroup;
1✔
130
  }
1✔
131

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

229
    private Builder() {}
1✔
230

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

373
    /**
374
     * Builds and returns a ClientOptions object.
375
     *
376
     * @return ClientOptions object with the specified params.
377
     */
378
    public ClientOptions build() {
379
      return new ClientOptions(this);
1✔
380
    }
381
  }
382
}
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