Skip to content

Commit 7d5ad6b

Browse files
author
Reynald Borer
committed
Merge branch 'master' into dependency-convergence
2 parents 44409b9 + 733ccc5 commit 7d5ad6b

File tree

102 files changed

+700
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+700
-218
lines changed

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryExceptionTest.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
import static org.junit.Assert.assertSame;
2727
import static org.junit.Assert.assertTrue;
2828

29+
import com.google.api.client.http.HttpHeaders;
30+
import com.google.api.client.http.HttpResponseException;
2931
import com.google.cloud.BaseServiceException;
3032
import com.google.cloud.RetryHelper.RetryHelperException;
31-
32-
import org.junit.Test;
33-
3433
import java.io.IOException;
3534
import java.net.SocketTimeoutException;
35+
import org.junit.Test;
3636

3737
public class BigQueryExceptionTest {
3838

@@ -112,6 +112,34 @@ public void testBigqueryException() {
112112
assertTrue(exception.isRetryable());
113113
assertTrue(exception.isIdempotent());
114114
assertSame(cause, exception.getCause());
115+
116+
117+
HttpResponseException httpResponseException =
118+
new HttpResponseException.Builder(404, "Service Unavailable", new HttpHeaders()).build();
119+
exception = new BigQueryException(httpResponseException);
120+
assertEquals(404, exception.getCode());
121+
assertFalse(exception.isRetryable());
122+
123+
httpResponseException = new HttpResponseException.Builder(504, null, new HttpHeaders()).build();
124+
exception = new BigQueryException(httpResponseException);
125+
assertEquals(504, exception.getCode());
126+
assertTrue(exception.isRetryable());
127+
128+
httpResponseException = new HttpResponseException.Builder(503, null, new HttpHeaders()).build();
129+
exception = new BigQueryException(httpResponseException);
130+
assertEquals(503, exception.getCode());
131+
assertTrue(exception.isRetryable());
132+
133+
httpResponseException = new HttpResponseException.Builder(502, null, new HttpHeaders()).build();
134+
exception = new BigQueryException(httpResponseException);
135+
assertEquals(502, exception.getCode());
136+
assertTrue(exception.isRetryable());
137+
138+
httpResponseException = new HttpResponseException.Builder(500, null, new HttpHeaders()).build();
139+
exception = new BigQueryException(httpResponseException);
140+
assertEquals(500, exception.getCode());
141+
assertTrue(exception.isRetryable());
142+
115143
}
116144

117145
@Test

google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.api.client.googleapis.json.GoogleJsonError;
2020
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
21+
import com.google.api.client.http.HttpResponseException;
2122
import com.google.api.gax.grpc.ApiException;
2223
import com.google.common.base.MoreObjects;
2324

@@ -140,20 +141,27 @@ public BaseServiceException(IOException exception, boolean idempotent) {
140141
String location = null;
141142
String debugInfo = null;
142143
Boolean retryable = null;
143-
if (exception instanceof GoogleJsonResponseException) {
144-
GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails();
145-
if (jsonError != null) {
146-
Error error = new Error(jsonError.getCode(), reason(jsonError));
147-
code = error.code;
148-
reason = error.reason;
149-
retryable = isRetryable(idempotent, error);
150-
if (reason != null) {
151-
GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0);
152-
location = errorInfo.getLocation();
153-
debugInfo = (String) errorInfo.get("debugInfo");
144+
if (exception instanceof HttpResponseException) {
145+
if (exception instanceof GoogleJsonResponseException) {
146+
GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails();
147+
if (jsonError != null) {
148+
Error error = new Error(jsonError.getCode(), reason(jsonError));
149+
code = error.code;
150+
reason = error.reason;
151+
retryable = isRetryable(idempotent, error);
152+
if (reason != null) {
153+
GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0);
154+
location = errorInfo.getLocation();
155+
debugInfo = (String) errorInfo.get("debugInfo");
156+
}
157+
} else {
158+
code = ((GoogleJsonResponseException) exception).getStatusCode();
154159
}
155160
} else {
156-
code = ((GoogleJsonResponseException) exception).getStatusCode();
161+
// In cases where an exception is an instance of HttpResponseException but not
162+
// an instance of GoogleJsonResponseException, check the status code to determine whether it's retryable
163+
code = ((HttpResponseException) exception).getStatusCode();
164+
retryable = isRetryable(idempotent, new Error(code, null));
157165
}
158166
}
159167
this.retryable = MoreObjects.firstNonNull(retryable, isRetryable(idempotent, exception));

google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public abstract class ServiceOptions<ServiceT extends Service<OptionsT>, Service
104104
* @param <OptionsT> the {@code ServiceOptions} subclass corresponding to the service
105105
* @param <B> the {@code ServiceOptions} builder
106106
*/
107-
protected abstract static class Builder<ServiceT extends Service<OptionsT>, ServiceRpcT,
107+
public abstract static class Builder<ServiceT extends Service<OptionsT>, ServiceRpcT,
108108
OptionsT extends ServiceOptions<ServiceT, ServiceRpcT, OptionsT>,
109109
B extends Builder<ServiceT, ServiceRpcT, OptionsT, B>> {
110110

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceSettings.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,7 +66,7 @@
6666
* </code>
6767
* </pre>
6868
*/
69-
@Generated("by GAPIC")
69+
@Generated("by GAPIC v0.0.5")
7070
@ExperimentalApi
7171
public class ErrorGroupServiceSettings extends ClientSettings {
7272
/** The default address of the service. */
@@ -79,6 +79,9 @@ public class ErrorGroupServiceSettings extends ClientSettings {
7979
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
8080
ImmutableList.<String>builder().add("https://www.googleapis.com/auth/cloud-platform").build();
8181

82+
private static final String DEFAULT_GAPIC_NAME = "gapic";
83+
private static final String DEFAULT_GAPIC_VERSION = "";
84+
8285
private final SimpleCallSettings<GetGroupRequest, ErrorGroup> getGroupSettings;
8386
private final SimpleCallSettings<UpdateGroupRequest, ErrorGroup> updateGroupSettings;
8487

@@ -122,9 +125,15 @@ public static InstantiatingChannelProvider.Builder defaultChannelProviderBuilder
122125
return InstantiatingChannelProvider.newBuilder()
123126
.setServiceAddress(DEFAULT_SERVICE_ADDRESS)
124127
.setPort(DEFAULT_SERVICE_PORT)
128+
.setGeneratorHeader(DEFAULT_GAPIC_NAME, getGapicVersion())
125129
.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
126130
}
127131

132+
private static String getGapicVersion() {
133+
String packageVersion = ErrorGroupServiceSettings.class.getPackage().getImplementationVersion();
134+
return packageVersion != null ? packageVersion : DEFAULT_GAPIC_VERSION;
135+
}
136+
128137
/** Returns a builder for this class with recommended defaults. */
129138
public static Builder defaultBuilder() {
130139
return Builder.createDefault();
@@ -163,7 +172,9 @@ public static class Builder extends ClientSettings.Builder {
163172
Sets.immutableEnumSet(
164173
Lists.<Status.Code>newArrayList(
165174
Status.Code.DEADLINE_EXCEEDED, Status.Code.UNAVAILABLE)));
166-
definitions.put("non_idempotent", Sets.immutableEnumSet(Lists.<Status.Code>newArrayList()));
175+
definitions.put(
176+
"non_idempotent",
177+
Sets.immutableEnumSet(Lists.<Status.Code>newArrayList(Status.Code.UNAVAILABLE)));
167178
RETRYABLE_CODE_DEFINITIONS = definitions.build();
168179
}
169180

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceSettings.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,7 +79,7 @@
7979
* </code>
8080
* </pre>
8181
*/
82-
@Generated("by GAPIC")
82+
@Generated("by GAPIC v0.0.5")
8383
@ExperimentalApi
8484
public class ErrorStatsServiceSettings extends ClientSettings {
8585
/** The default address of the service. */
@@ -92,6 +92,9 @@ public class ErrorStatsServiceSettings extends ClientSettings {
9292
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
9393
ImmutableList.<String>builder().add("https://www.googleapis.com/auth/cloud-platform").build();
9494

95+
private static final String DEFAULT_GAPIC_NAME = "gapic";
96+
private static final String DEFAULT_GAPIC_VERSION = "";
97+
9598
private final PagedCallSettings<
9699
ListGroupStatsRequest, ListGroupStatsResponse, ListGroupStatsPagedResponse>
97100
listGroupStatsSettings;
@@ -147,9 +150,15 @@ public static InstantiatingChannelProvider.Builder defaultChannelProviderBuilder
147150
return InstantiatingChannelProvider.newBuilder()
148151
.setServiceAddress(DEFAULT_SERVICE_ADDRESS)
149152
.setPort(DEFAULT_SERVICE_PORT)
153+
.setGeneratorHeader(DEFAULT_GAPIC_NAME, getGapicVersion())
150154
.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
151155
}
152156

157+
private static String getGapicVersion() {
158+
String packageVersion = ErrorStatsServiceSettings.class.getPackage().getImplementationVersion();
159+
return packageVersion != null ? packageVersion : DEFAULT_GAPIC_VERSION;
160+
}
161+
153162
/** Returns a builder for this class with recommended defaults. */
154163
public static Builder defaultBuilder() {
155164
return Builder.createDefault();
@@ -296,7 +305,9 @@ public static class Builder extends ClientSettings.Builder {
296305
Sets.immutableEnumSet(
297306
Lists.<Status.Code>newArrayList(
298307
Status.Code.DEADLINE_EXCEEDED, Status.Code.UNAVAILABLE)));
299-
definitions.put("non_idempotent", Sets.immutableEnumSet(Lists.<Status.Code>newArrayList()));
308+
definitions.put(
309+
"non_idempotent",
310+
Sets.immutableEnumSet(Lists.<Status.Code>newArrayList(Status.Code.UNAVAILABLE)));
300311
RETRYABLE_CODE_DEFINITIONS = definitions.build();
301312
}
302313

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/PagedResponseWrappers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceSettings.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016, Google Inc. All rights reserved.
2+
* Copyright 2017, Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,7 +65,7 @@
6565
* </code>
6666
* </pre>
6767
*/
68-
@Generated("by GAPIC")
68+
@Generated("by GAPIC v0.0.5")
6969
@ExperimentalApi
7070
public class ReportErrorsServiceSettings extends ClientSettings {
7171
/** The default address of the service. */
@@ -78,6 +78,9 @@ public class ReportErrorsServiceSettings extends ClientSettings {
7878
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
7979
ImmutableList.<String>builder().add("https://www.googleapis.com/auth/cloud-platform").build();
8080

81+
private static final String DEFAULT_GAPIC_NAME = "gapic";
82+
private static final String DEFAULT_GAPIC_VERSION = "";
83+
8184
private final SimpleCallSettings<ReportErrorEventRequest, ReportErrorEventResponse>
8285
reportErrorEventSettings;
8386

@@ -117,9 +120,16 @@ public static InstantiatingChannelProvider.Builder defaultChannelProviderBuilder
117120
return InstantiatingChannelProvider.newBuilder()
118121
.setServiceAddress(DEFAULT_SERVICE_ADDRESS)
119122
.setPort(DEFAULT_SERVICE_PORT)
123+
.setGeneratorHeader(DEFAULT_GAPIC_NAME, getGapicVersion())
120124
.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
121125
}
122126

127+
private static String getGapicVersion() {
128+
String packageVersion =
129+
ReportErrorsServiceSettings.class.getPackage().getImplementationVersion();
130+
return packageVersion != null ? packageVersion : DEFAULT_GAPIC_VERSION;
131+
}
132+
123133
/** Returns a builder for this class with recommended defaults. */
124134
public static Builder defaultBuilder() {
125135
return Builder.createDefault();
@@ -157,7 +167,9 @@ public static class Builder extends ClientSettings.Builder {
157167
Sets.immutableEnumSet(
158168
Lists.<Status.Code>newArrayList(
159169
Status.Code.DEADLINE_EXCEEDED, Status.Code.UNAVAILABLE)));
160-
definitions.put("non_idempotent", Sets.immutableEnumSet(Lists.<Status.Code>newArrayList()));
170+
definitions.put(
171+
"non_idempotent",
172+
Sets.immutableEnumSet(Lists.<Status.Code>newArrayList(Status.Code.UNAVAILABLE)));
161173
RETRYABLE_CODE_DEFINITIONS = definitions.build();
162174
}
163175

0 commit comments

Comments
 (0)