Skip to content

Commit e26160e

Browse files
committed
Made Java client deadlines backward-compatible
Signed-off-by: Jose Acevedo <sharp.acevedo@gmail.com>
1 parent 7c9dcde commit e26160e

2 files changed

Lines changed: 39 additions & 5 deletions

File tree

java/serving-client/src/main/java/dev/feast/FeastClient.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,47 @@ public class FeastClient implements AutoCloseable {
5858
* @param port port number of Feast serving GRPC server
5959
* @return {@link FeastClient}
6060
*/
61+
public static FeastClient create(String host, int port) {
62+
// configure client with no security config.
63+
return FeastClient.createSecure(host, port, SecurityConfig.newBuilder().build());
64+
}
65+
66+
/**
67+
* Create a client to access Feast Serving.
68+
*
69+
* @param host hostname or ip address of Feast serving GRPC server
70+
* @param port port number of Feast serving GRPC server
71+
* @param deadline GRPC deadline of Feast serving GRPC server {@link Deadline}
72+
* @return {@link FeastClient}
73+
*/
6174
public static FeastClient create(String host, int port, Deadline deadline) {
6275
// configure client with no security config.
6376
return FeastClient.createSecure(host, port, SecurityConfig.newBuilder().build(), deadline);
6477
}
6578

6679
/**
67-
* Create a authenticated client that can access Feast serving with authentication enabled.
80+
* Create an authenticated client that can access Feast serving with authentication enabled.
6881
*
6982
* @param host hostname or ip address of Feast serving GRPC server
7083
* @param port port number of Feast serving GRPC server
7184
* @param securityConfig security options to configure the Feast client. See {@link
7285
* SecurityConfig} for options.
7386
* @return {@link FeastClient}
7487
*/
88+
public static FeastClient createSecure(String host, int port, SecurityConfig securityConfig) {
89+
return createSecure(host, port, securityConfig, null);
90+
}
91+
92+
/**
93+
* Create an authenticated client that can access Feast serving with authentication enabled.
94+
*
95+
* @param host hostname or ip address of Feast serving GRPC server
96+
* @param port port number of Feast serving GRPC server
97+
* @param securityConfig security options to configure the Feast client. See {@link
98+
* SecurityConfig} for options.
99+
* @param deadline GRPC deadline of Feast serving GRPC server {@link Deadline}
100+
* @return {@link FeastClient}
101+
*/
75102
public static FeastClient createSecure(String host, int port, SecurityConfig securityConfig, Deadline deadline) {
76103
// Configure client TLS
77104
ManagedChannel channel = null;
@@ -99,7 +126,7 @@ public static FeastClient createSecure(String host, int port, SecurityConfig sec
99126
channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build();
100127
}
101128

102-
return new FeastClient(channel, securityConfig.getCredentials(), deadline);
129+
return new FeastClient(channel, securityConfig.getCredentials(), Optional.ofNullable(deadline));
103130
}
104131

105132
/**
@@ -202,7 +229,11 @@ public List<Row> getOnlineFeatures(List<String> featureRefs, List<Row> rows, Str
202229
return getOnlineFeatures(featureRefs, rows);
203230
}
204231

205-
protected FeastClient(ManagedChannel channel, Optional<CallCredentials> credentials, Deadline deadline) {
232+
protected FeastClient(ManagedChannel channel, Optional<CallCredentials> credentials) {
233+
this(channel, credentials, Optional.empty());
234+
}
235+
236+
protected FeastClient(ManagedChannel channel, Optional<CallCredentials> credentials, Optional<Deadline> deadline) {
206237
this.channel = channel;
207238
TracingClientInterceptor tracingInterceptor =
208239
TracingClientInterceptor.newBuilder().withTracer(GlobalTracer.get()).build();
@@ -214,7 +245,9 @@ protected FeastClient(ManagedChannel channel, Optional<CallCredentials> credenti
214245
servingStub = servingStub.withCallCredentials(credentials.get());
215246
}
216247

217-
servingStub = servingStub.withDeadline(deadline);
248+
if (deadline.isPresent()) {
249+
servingStub = servingStub.withDeadline(deadline.get());
250+
}
218251

219252
this.stub = servingStub;
220253
}

java/serving-client/src/test/java/dev/feast/FeastClientTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
public class FeastClientTest {
4848
private final String AUTH_TOKEN = "test token";
49+
private final Deadline DEADLINE = Deadline.after(200, TimeUnit.MILLISECONDS);
4950

5051
@Rule public GrpcCleanupRule grpcRule;
5152
private AtomicBoolean isAuthenticated;
@@ -87,7 +88,7 @@ public void setup() throws Exception {
8788
ManagedChannel channel =
8889
this.grpcRule.register(
8990
InProcessChannelBuilder.forName(serverName).directExecutor().build());
90-
this.client = new FeastClient(channel, Optional.empty(), Deadline.after(200, TimeUnit.MILLISECONDS));
91+
this.client = new FeastClient(channel, Optional.empty(), Optional.of(DEADLINE));
9192
}
9293

9394
@Test

0 commit comments

Comments
 (0)