Skip to content

Commit 59935d5

Browse files
committed
---
yaml --- r: 2193 b: refs/heads/pubsub-alpha c: 55ee5aa h: refs/heads/master i: 2191: 18bd90b
1 parent 6a4bf51 commit 59935d5

14 files changed

Lines changed: 89 additions & 76 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: 1a18033efd5d56596a3d44ea37867b08898a75c5
6+
refs/heads/pubsub-alpha: 55ee5aa0aaeb0d4adcb9228119f6239e6e5442e4
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Acl.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,22 @@ Access toPb() {
370370
}
371371
}
372372

373-
private Acl(Entity entity, Role role) {
373+
/**
374+
* Build an ACL for an {@code entity} and a {@code role}.
375+
*/
376+
public Acl(Entity entity, Role role) {
374377
this.entity = checkNotNull(entity);
375378
this.role = role;
376379
}
377380

381+
/**
382+
* Build an ACL for a view entity.
383+
*/
384+
public Acl(View view) {
385+
this.entity = checkNotNull(view);
386+
this.role = null;
387+
}
388+
378389
/**
379390
* Returns the entity for this ACL.
380391
*/
@@ -389,23 +400,6 @@ public Role role() {
389400
return role;
390401
}
391402

392-
/**
393-
* Returns an Acl object.
394-
*
395-
* @param entity the entity for this ACL object
396-
* @param role the role to associate to the {@code entity} object
397-
*/
398-
public static Acl of(Entity entity, Role role) {
399-
return new Acl(entity, role);
400-
}
401-
402-
/**
403-
* Returns an Acl object for a view entity.
404-
*/
405-
public static Acl of(View view) {
406-
return new Acl(view, null);
407-
}
408-
409403
@Override
410404
public int hashCode() {
411405
return Objects.hash(entity, role);
@@ -438,7 +432,7 @@ Access toPb() {
438432
}
439433

440434
static Acl fromPb(Access access) {
441-
return Acl.of(Entity.fromPb(access),
435+
return new Acl(Entity.fromPb(access),
442436
access.getRole() != null ? Role.valueOf(access.getRole()) : null);
443437
}
444438
}

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQueryException.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,11 @@ public BigQueryException(int code, String message, BigQueryError error) {
5555

5656
public BigQueryException(IOException exception) {
5757
super(exception, true);
58-
BigQueryError bigqueryError = null;
59-
if (exception instanceof GoogleJsonResponseException) {
60-
GoogleJsonError error = ((GoogleJsonResponseException) exception).getDetails();
61-
if (error != null && error.getErrors() != null && !error.getErrors().isEmpty()) {
62-
GoogleJsonError.ErrorInfo errorInfo = error.getErrors().get(0);
63-
bigqueryError = new BigQueryError(errorInfo.getReason(), errorInfo.getLocation(),
64-
errorInfo.getMessage(), (String) error.get("debugInfo"));
65-
}
58+
BigQueryError error = null;
59+
if (reason() != null) {
60+
error = new BigQueryError(reason(), location(), getMessage(), debugInfo());
6661
}
67-
this.error = bigqueryError;
62+
this.error = error;
6863
}
6964

7065
/**

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQueryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ private DatasetInfo setProjectId(DatasetInfo dataset) {
621621
if (viewReferencePb.getProjectId() == null) {
622622
viewReferencePb.setProjectId(options().projectId());
623623
}
624-
acls.add(Acl.of(new Acl.View(TableId.fromPb(viewReferencePb))));
624+
acls.add(new Acl(new Acl.View(TableId.fromPb(viewReferencePb))));
625625
} else {
626626
acls.add(acl);
627627
}

branches/pubsub-alpha/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/AclTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ public void testViewEntity() {
8181
}
8282

8383
@Test
84-
public void testOf() {
85-
Acl acl = Acl.of(Group.ofAllAuthenticatedUsers(), Role.READER);
84+
public void testAcl() {
85+
Acl acl = new Acl(Group.ofAllAuthenticatedUsers(), Role.READER);
8686
assertEquals(Group.ofAllAuthenticatedUsers(), acl.entity());
8787
assertEquals(Role.READER, acl.role());
8888
Dataset.Access pb = acl.toPb();
8989
assertEquals(acl, Acl.fromPb(pb));
9090
View view = new View(TableId.of("project", "dataset", "view"));
91-
acl = Acl.of(view);
91+
acl = new Acl(view);
9292
assertEquals(view, acl.entity());
9393
assertEquals(null, acl.role());
9494
}

branches/pubsub-alpha/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/BigQueryImplTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ public class BigQueryImplTest {
6868
private static final String OTHER_TABLE = "otherTable";
6969
private static final String OTHER_DATASET = "otherDataset";
7070
private static final List<Acl> ACCESS_RULES = ImmutableList.of(
71-
Acl.of(Acl.Group.ofAllAuthenticatedUsers(), Acl.Role.READER),
72-
Acl.of(new Acl.View(TableId.of("dataset", "table")), Acl.Role.WRITER));
71+
new Acl(Acl.Group.ofAllAuthenticatedUsers(), Acl.Role.READER),
72+
new Acl(new Acl.View(TableId.of("dataset", "table")), Acl.Role.WRITER));
7373
private static final List<Acl> ACCESS_RULES_WITH_PROJECT = ImmutableList.of(
74-
Acl.of(Acl.Group.ofAllAuthenticatedUsers(), Acl.Role.READER),
75-
Acl.of(new Acl.View(TableId.of(PROJECT, "dataset", "table"))));
74+
new Acl(Acl.Group.ofAllAuthenticatedUsers(), Acl.Role.READER),
75+
new Acl(new Acl.View(TableId.of(PROJECT, "dataset", "table"))));
7676
private static final DatasetInfo DATASET_INFO = DatasetInfo.builder(DATASET)
7777
.acl(ACCESS_RULES)
7878
.description("description")

branches/pubsub-alpha/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DatasetInfoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
public class DatasetInfoTest {
2929

3030
private static final List<Acl> ACCESS_RULES = ImmutableList.of(
31-
Acl.of(Acl.Group.ofAllAuthenticatedUsers(), Acl.Role.READER),
32-
Acl.of(new Acl.View(TableId.of("project", "dataset", "table")), Acl.Role.WRITER));
31+
new Acl(Acl.Group.ofAllAuthenticatedUsers(), Acl.Role.READER),
32+
new Acl(new Acl.View(TableId.of("project", "dataset", "table")), Acl.Role.WRITER));
3333
private static final Long CREATION_TIME = System.currentTimeMillis();
3434
private static final Long DEFAULT_TABLE_EXPIRATION = CREATION_TIME + 100;
3535
private static final String DESCRIPTION = "description";

branches/pubsub-alpha/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/SerializationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
public class SerializationTest {
4343

4444
private static final Acl DOMAIN_ACCESS =
45-
Acl.of(new Acl.Domain("domain"), Acl.Role.WRITER);
45+
new Acl(new Acl.Domain("domain"), Acl.Role.WRITER);
4646
private static final Acl GROUP_ACCESS =
47-
Acl.of(Acl.Group.ofAllAuthenticatedUsers(), Acl.Role.READER);
48-
private static final Acl USER_ACCESS = Acl.of(new Acl.User("user"), Acl.Role.OWNER);
47+
new Acl(Acl.Group.ofAllAuthenticatedUsers(), Acl.Role.READER);
48+
private static final Acl USER_ACCESS = new Acl(new Acl.User("user"), Acl.Role.OWNER);
4949
private static final Acl VIEW_ACCESS =
50-
Acl.of(new Acl.View(TableId.of("project", "dataset", "table")), Acl.Role.WRITER);
50+
new Acl(new Acl.View(TableId.of("project", "dataset", "table")), Acl.Role.WRITER);
5151
private static final List<Acl> ACCESS_RULES = ImmutableList.of(DOMAIN_ACCESS, GROUP_ACCESS,
5252
VIEW_ACCESS, USER_ACCESS);
5353
private static final Long CREATION_TIME = System.currentTimeMillis() - 10;

branches/pubsub-alpha/gcloud-java-core/src/main/java/com/google/gcloud/BaseServiceException.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,32 @@ public int hashCode() {
8686
private final boolean retryable;
8787
private final String reason;
8888
private final boolean idempotent;
89+
private final String location;
90+
private final String debugInfo;
8991

9092
public BaseServiceException(IOException exception, boolean idempotent) {
9193
super(message(exception), exception);
94+
int code = UNKNOWN_CODE;
95+
String reason = null;
96+
String location = null;
97+
String debugInfo = null;
9298
if (exception instanceof GoogleJsonResponseException) {
93-
Error error = error(((GoogleJsonResponseException) exception).getDetails());
94-
this.code = error.code;
95-
this.reason = error.reason;
96-
this.retryable = error.isRetryable(retryableErrors());
97-
} else {
98-
this.code = UNKNOWN_CODE;
99-
this.reason = null;
100-
this.retryable = idempotent && isRetryable(exception);
99+
GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails();
100+
Error error = error(jsonError);
101+
code = error.code;
102+
reason = error.reason;
103+
if (reason != null) {
104+
GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0);
105+
location = errorInfo.getLocation();
106+
debugInfo = (String) errorInfo.get("debugInfo");
107+
}
101108
}
109+
this.code = code;
110+
this.retryable = idempotent && isRetryable(exception);
111+
this.reason = reason;
102112
this.idempotent = idempotent;
113+
this.location = location;
114+
this.debugInfo = debugInfo;
103115
}
104116

105117
public BaseServiceException(GoogleJsonError error, boolean idempotent) {
@@ -108,6 +120,8 @@ public BaseServiceException(GoogleJsonError error, boolean idempotent) {
108120
this.reason = reason(error);
109121
this.idempotent = idempotent;
110122
this.retryable = idempotent && isRetryable(error);
123+
this.location = null;
124+
this.debugInfo = null;
111125
}
112126

113127
public BaseServiceException(int code, String message, String reason, boolean idempotent) {
@@ -121,6 +135,8 @@ public BaseServiceException(int code, String message, String reason, boolean ide
121135
this.reason = reason;
122136
this.idempotent = idempotent;
123137
this.retryable = idempotent && new Error(code, reason).isRetryable(retryableErrors());
138+
this.location = null;
139+
this.debugInfo = null;
124140
}
125141

126142
protected Set<Error> retryableErrors() {
@@ -166,6 +182,18 @@ public boolean idempotent() {
166182
return idempotent;
167183
}
168184

185+
/**
186+
* Returns the service location where the error causing the exception occurred. Returns
187+
* {@code null} if not set.
188+
*/
189+
public String location() {
190+
return location;
191+
}
192+
193+
protected String debugInfo() {
194+
return debugInfo;
195+
}
196+
169197
protected static String reason(GoogleJsonError error) {
170198
if (error.getErrors() != null && !error.getErrors().isEmpty()) {
171199
return error.getErrors().get(0).getReason();

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,13 @@ String toPb() {
274274
}
275275
}
276276

277-
private Acl(Entity entity, Role role) {
277+
/**
278+
* Creates an ACL object.
279+
*
280+
* @param entity the entity for this ACL object
281+
* @param role the role to associate to the {@code entity} object
282+
*/
283+
public Acl(Entity entity, Role role) {
278284
this.entity = entity;
279285
this.role = role;
280286
}
@@ -293,16 +299,6 @@ public Role role() {
293299
return role;
294300
}
295301

296-
/**
297-
* Returns an Acl object.
298-
*
299-
* @param entity the entity for this ACL object
300-
* @param role the role to associate to the {@code entity} object
301-
*/
302-
public static Acl of(Entity entity, Role role) {
303-
return new Acl(entity, role);
304-
}
305-
306302
@Override
307303
public int hashCode() {
308304
return Objects.hash(entity, role);
@@ -337,11 +333,11 @@ ObjectAccessControl toObjectPb() {
337333

338334
static Acl fromPb(ObjectAccessControl objectAccessControl) {
339335
Role role = Role.valueOf(objectAccessControl.getRole());
340-
return Acl.of(Entity.fromPb(objectAccessControl.getEntity()), role);
336+
return new Acl(Entity.fromPb(objectAccessControl.getEntity()), role);
341337
}
342338

343339
static Acl fromPb(BucketAccessControl bucketAccessControl) {
344340
Role role = Role.valueOf(bucketAccessControl.getRole());
345-
return Acl.of(Entity.fromPb(bucketAccessControl.getEntity()), role);
341+
return new Acl(Entity.fromPb(bucketAccessControl.getEntity()), role);
346342
}
347343
}

0 commit comments

Comments
 (0)