Skip to content

Commit e1e0623

Browse files
Capture DatabricksError when retrying API calls.
1 parent fb97b89 commit e1e0623

File tree

12 files changed

+46
-27
lines changed

12 files changed

+46
-27
lines changed

.release_metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"timestamp": "2025-03-26 13:43:47+0000"
2+
"timestamp": "2025-04-10 13:35:44+0000"
33
}

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Version changelog
22

3+
## Release v0.44.0
4+
5+
### Bug Fixes
6+
* Fix issue deserializing HTTP responses with an empty body ([#426](https://github.com/databricks/databricks-sdk-java/pull/426)).
7+
8+
39
## Release v0.43.0
410

511
### API Changes

NEXT_CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# NEXT CHANGELOG
22

3-
## Release v0.44.0
3+
## Release v0.45.0
44

55
### New Features and Improvements
66

77
### Bug Fixes
8-
* Fix issue deserializing HTTP responses with an empty body ([#426](https://github.com/databricks/databricks-sdk-java/pull/426)).
98

109
### Documentation
1110

1211
### Internal Changes
12+
* Capture DatabricksError when retrying API calls ([#427](https://github.com/databricks/databricks-sdk-java/pull/427)).
1313

1414
### API Changes

databricks-sdk-java/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.databricks</groupId>
77
<artifactId>databricks-sdk-parent</artifactId>
8-
<version>0.43.0</version>
8+
<version>0.44.0</version>
99
</parent>
1010
<artifactId>databricks-sdk-java</artifactId>
1111
<properties>

databricks-sdk-java/src/main/java/com/databricks/sdk/core/ApiClient.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.fasterxml.jackson.core.JsonProcessingException;
1616
import com.fasterxml.jackson.databind.JavaType;
1717
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import com.google.common.base.Strings;
1819
import java.io.IOException;
1920
import java.io.InputStream;
2021
import java.lang.reflect.Field;
@@ -219,7 +220,7 @@ private Response executeInner(Request in, String path) {
219220
// after the first invocation to config.authenticate()
220221
String userAgent = UserAgent.asString();
221222
String authType = getAuthTypeFunc.apply(null);
222-
if (authType != "") {
223+
if (!Strings.isNullOrEmpty(authType)) {
223224
userAgent += String.format(" auth/%s", authType);
224225
}
225226
in.withHeader("User-Agent", userAgent);
@@ -247,12 +248,13 @@ private Response executeInner(Request in, String path) {
247248
}
248249
if (attemptNumber == maxAttempts) {
249250
throw new DatabricksException(
250-
String.format("Request %s failed after %d retries", in, maxAttempts), err);
251+
String.format("Request %s failed after %d retries", in, maxAttempts), databricksError);
251252
}
252253

253254
// Retry after a backoff.
254255
long sleepMillis = getBackoffMillis(out, attemptNumber);
255-
LOG.debug(String.format("Retry %s in %dms", in.getRequestLine(), sleepMillis));
256+
LOG.debug(
257+
String.format("Retry %s in %dms", in.getRequestLine(), sleepMillis), databricksError);
256258
try {
257259
timer.sleep(sleepMillis);
258260
} catch (InterruptedException ex) {

databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,17 @@ public DatabricksConfig setAzureUseMsi(boolean azureUseMsi) {
374374
return this;
375375
}
376376

377-
/** @deprecated Use {@link #getAzureUseMsi()} instead. */
377+
/**
378+
* @deprecated Use {@link #getAzureUseMsi()} instead.
379+
*/
378380
@Deprecated()
379381
public boolean getAzureUseMSI() {
380382
return azureUseMsi;
381383
}
382384

383-
/** @deprecated Use {@link #setAzureUseMsi(boolean)} instead. */
385+
/**
386+
* @deprecated Use {@link #setAzureUseMsi(boolean)} instead.
387+
*/
384388
@Deprecated
385389
public DatabricksConfig setAzureUseMSI(boolean azureUseMsi) {
386390
this.azureUseMsi = azureUseMsi;

databricks-sdk-java/src/main/java/com/databricks/sdk/core/UserAgent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public String getValue() {
3636
// TODO: check if reading from
3737
// /META-INF/maven/com.databricks/databrics-sdk-java/pom.properties
3838
// or getClass().getPackage().getImplementationVersion() is enough.
39-
private static final String version = "0.43.0";
39+
private static final String version = "0.44.0";
4040

4141
public static void withProduct(String product, String productVersion) {
4242
UserAgent.product = product;

databricks-sdk-java/src/test/java/com/databricks/sdk/core/ApiClientTest.java

+20-13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.fasterxml.jackson.annotation.JsonProperty;
1212
import com.fasterxml.jackson.core.JsonProcessingException;
1313
import com.fasterxml.jackson.databind.ObjectMapper;
14+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
1415
import java.io.IOException;
1516
import java.net.MalformedURLException;
1617
import java.net.URL;
@@ -88,12 +89,13 @@ private <T> void runApiClientTest(
8889
runApiClientTest(client, request, clazz, expectedResponse);
8990
}
9091

91-
private void runFailingApiClientTest(
92-
Request request, List<ResponseProvider> responses, Class<?> clazz, String expectedMessage)
93-
throws IOException {
92+
@CanIgnoreReturnValue
93+
private DatabricksException runFailingApiClientTest(
94+
Request request, List<ResponseProvider> responses, Class<?> clazz, String expectedMessage) {
9495
DatabricksException exception =
9596
runFailingApiClientTest(request, responses, clazz, DatabricksException.class);
9697
assertEquals(exception.getMessage(), expectedMessage);
98+
return exception;
9799
}
98100

99101
private <T extends Throwable> T runFailingApiClientTest(
@@ -217,16 +219,21 @@ void retry429() throws IOException {
217219
@Test
218220
void failAfterTooManyRetries() throws IOException {
219221
Request req = getBasicRequest();
220-
runFailingApiClientTest(
221-
req,
222-
Arrays.asList(
223-
getTooManyRequestsResponseWithRetryAfterDateHeader(req),
224-
getTooManyRequestsResponse(req),
225-
getTooManyRequestsResponse(req),
226-
getTooManyRequestsResponse(req),
227-
getSuccessResponse(req)),
228-
MyEndpointResponse.class,
229-
"Request GET /api/my/endpoint failed after 4 retries");
222+
DatabricksException exception =
223+
runFailingApiClientTest(
224+
req,
225+
Arrays.asList(
226+
getTooManyRequestsResponseWithRetryAfterDateHeader(req),
227+
getTooManyRequestsResponse(req),
228+
getTooManyRequestsResponse(req),
229+
getTooManyRequestsResponse(req),
230+
getSuccessResponse(req)),
231+
MyEndpointResponse.class,
232+
"Request GET /api/my/endpoint failed after 4 retries");
233+
assertInstanceOf(DatabricksError.class, exception.getCause());
234+
DatabricksError cause = (DatabricksError) exception.getCause();
235+
assertEquals(cause.getErrorCode(), "TOO_MANY_REQUESTS");
236+
assertEquals(cause.getStatusCode(), 429);
230237
}
231238

232239
@Test

examples/docs/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<dependency>
2525
<groupId>com.databricks</groupId>
2626
<artifactId>databricks-sdk-java</artifactId>
27-
<version>0.43.0</version>
27+
<version>0.44.0</version>
2828
</dependency>
2929
</dependencies>
3030
</project>

examples/spring-boot-oauth-u2m-demo/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<dependency>
3838
<groupId>com.databricks</groupId>
3939
<artifactId>databricks-sdk-java</artifactId>
40-
<version>0.43.0</version>
40+
<version>0.44.0</version>
4141
</dependency>
4242
<dependency>
4343
<groupId>com.fasterxml.jackson.datatype</groupId>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.databricks</groupId>
66
<artifactId>databricks-sdk-parent</artifactId>
7-
<version>0.43.0</version>
7+
<version>0.44.0</version>
88
<packaging>pom</packaging>
99
<name>Databricks SDK for Java</name>
1010
<description>The Databricks SDK for Java includes functionality to accelerate development with Java for

shaded/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55

66
<properties>
7-
<sdk.version>0.43.0</sdk.version>
7+
<sdk.version>0.44.0</sdk.version>
88
</properties>
99

1010
<groupId>com.databricks</groupId>

0 commit comments

Comments
 (0)