Skip to content

Commit 6ecba58

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 1831 b: refs/heads/pubsub-alpha c: 6636e23 h: refs/heads/master i: 1829: 5bb6c11 1827: eb98930 1823: 30193bb
1 parent 94edf75 commit 6ecba58

19 files changed

Lines changed: 195 additions & 733 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: fac76879723ae3cd4be83f5011d492531c4111c5
6+
refs/heads/pubsub-alpha: 6636e23cac4c18a9fcc4a826aecc531294a564c0
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud;
18+
19+
/**
20+
* Base service exception.
21+
*/
22+
public class BaseServiceException extends RuntimeException {
23+
24+
private static final long serialVersionUID = 5028833760039966178L;
25+
26+
private final int code;
27+
private final boolean retryable;
28+
29+
public BaseServiceException(int code, String message, boolean retryable) {
30+
super(message);
31+
this.code = code;
32+
this.retryable = retryable;
33+
}
34+
35+
public BaseServiceException(int code, String message, boolean retryable, Exception cause) {
36+
super(message, cause);
37+
this.code = code;
38+
this.retryable = retryable;
39+
}
40+
41+
/**
42+
* Returns the code associated with this exception.
43+
*/
44+
public int code() {
45+
return code;
46+
}
47+
48+
public boolean retryable() {
49+
return retryable;
50+
}
51+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud;
18+
19+
import static org.junit.Assert.assertEquals;
20+
21+
import org.junit.Test;
22+
23+
/**
24+
* Tests for {@link BaseServiceException}.
25+
*/
26+
public class BaseServiceExceptionTest {
27+
28+
private final int code = 1;
29+
private final String message = "some message";
30+
private final boolean retryable = true;
31+
32+
@Test
33+
public void testBaseServiceException() {
34+
BaseServiceException serviceException = new BaseServiceException(code, message, retryable);
35+
assertEquals(serviceException.code(), code);
36+
assertEquals(serviceException.getMessage(), message);
37+
assertEquals(serviceException.getCause(), null);
38+
39+
Exception cause = new RuntimeException();
40+
serviceException = new BaseServiceException(code, message, retryable, cause);
41+
assertEquals(serviceException.code(), code);
42+
assertEquals(serviceException.getMessage(), message);
43+
assertEquals(serviceException.getCause(), cause);
44+
}
45+
}

branches/pubsub-alpha/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreException.java

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

1919
import com.google.common.base.MoreObjects;
2020
import com.google.common.collect.ImmutableMap;
21+
import com.google.gcloud.BaseServiceException;
2122
import com.google.gcloud.RetryHelper;
2223
import com.google.gcloud.RetryHelper.RetryHelperException;
2324
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException;
@@ -26,21 +27,21 @@
2627
import java.util.HashMap;
2728
import java.util.Map;
2829

29-
public class DatastoreException extends RuntimeException {
30+
public class DatastoreException extends BaseServiceException {
3031

31-
private static final long serialVersionUID = 8170357898917041899L;
32-
private static final ImmutableMap<String, Code> REASON_TO_CODE;
33-
private static final ImmutableMap<Integer, Code> HTTP_TO_CODE;
32+
private static final long serialVersionUID = -2336749234060754893L;
33+
private static final ImmutableMap<String, ErrorInfo> REASON_TO_CODE;
34+
private static final ImmutableMap<Integer, ErrorInfo> HTTP_TO_CODE;
3435

35-
private final Code code;
36+
private final ErrorInfo errorInfo;
3637

3738
/**
38-
* An error code to represent the failure.
39+
* Represent metadata about {@link DatastoreException}s.
3940
*
4041
* @see <a href="https://cloud.google.com/datastore/docs/concepts/errors#Error_Codes">Google Cloud
4142
* Datastore error codes</a>
4243
*/
43-
public enum Code {
44+
public enum ErrorInfo {
4445

4546
ABORTED(Reason.ABORTED),
4647
DEADLINE_EXCEEDED(Reason.DEADLINE_EXCEEDED),
@@ -57,11 +58,11 @@ public enum Code {
5758
private final String description;
5859
private final int httpStatus;
5960

60-
Code(Reason reason) {
61+
ErrorInfo(Reason reason) {
6162
this(reason.retryable(), reason.description(), reason.httpStatus());
6263
}
6364

64-
Code(boolean retryable, String description, int httpStatus) {
65+
ErrorInfo(boolean retryable, String description, int httpStatus) {
6566
this.retryable = retryable;
6667
this.description = description;
6768
this.httpStatus = httpStatus;
@@ -89,30 +90,31 @@ DatastoreException translate(DatastoreRpcException exception, String message) {
8990
}
9091

9192
static {
92-
ImmutableMap.Builder<String, Code> builder = ImmutableMap.builder();
93-
Map<Integer, Code> httpCodes = new HashMap<>();
94-
for (Code code : Code.values()) {
93+
ImmutableMap.Builder<String, ErrorInfo> builder = ImmutableMap.builder();
94+
Map<Integer, ErrorInfo> httpCodes = new HashMap<>();
95+
for (ErrorInfo code : ErrorInfo.values()) {
9596
builder.put(code.name(), code);
9697
httpCodes.put(code.httpStatus(), code);
9798
}
9899
REASON_TO_CODE = builder.build();
99100
HTTP_TO_CODE = ImmutableMap.copyOf(httpCodes);
100101
}
101102

102-
public DatastoreException(Code code, String message, Exception cause) {
103-
super(MoreObjects.firstNonNull(message, code.description), cause);
104-
this.code = code;
103+
public DatastoreException(ErrorInfo errorInfo, String message, Exception cause) {
104+
super(errorInfo.httpStatus(), MoreObjects.firstNonNull(message, errorInfo.description),
105+
errorInfo.retryable(), cause);
106+
this.errorInfo = errorInfo;
105107
}
106108

107-
public DatastoreException(Code code, String message) {
108-
this(code, message, null);
109+
public DatastoreException(ErrorInfo errorInfo, String message) {
110+
this(errorInfo, message, null);
109111
}
110112

111113
/**
112114
* Returns the code associated with this exception.
113115
*/
114-
public Code code() {
115-
return code;
116+
public ErrorInfo errorInfo() {
117+
return errorInfo;
116118
}
117119

118120
static DatastoreException translateAndThrow(RetryHelperException ex) {
@@ -122,7 +124,7 @@ static DatastoreException translateAndThrow(RetryHelperException ex) {
122124
if (ex instanceof RetryHelper.RetryInterruptedException) {
123125
RetryHelper.RetryInterruptedException.propagate();
124126
}
125-
throw new DatastoreException(Code.UNKNOWN, ex.getMessage(), ex);
127+
throw new DatastoreException(ErrorInfo.UNKNOWN, ex.getMessage(), ex);
126128
}
127129

128130
/**
@@ -133,9 +135,9 @@ static DatastoreException translateAndThrow(RetryHelperException ex) {
133135
*/
134136
static DatastoreException translateAndThrow(DatastoreRpcException exception) {
135137
String message = exception.getMessage();
136-
Code code = REASON_TO_CODE.get(exception.reason());
138+
ErrorInfo code = REASON_TO_CODE.get(exception.reason());
137139
if (code == null) {
138-
code = MoreObjects.firstNonNull(HTTP_TO_CODE.get(exception.httpStatus()), Code.UNKNOWN);
140+
code = MoreObjects.firstNonNull(HTTP_TO_CODE.get(exception.httpStatus()), ErrorInfo.UNKNOWN);
139141
}
140142
throw code.translate(exception, message);
141143
}
@@ -147,10 +149,10 @@ static DatastoreException translateAndThrow(DatastoreRpcException exception) {
147149
* @throws DatastoreException every time
148150
*/
149151
static DatastoreException throwInvalidRequest(String massage, Object... params) {
150-
throw new DatastoreException(Code.FAILED_PRECONDITION, String.format(massage, params));
152+
throw new DatastoreException(ErrorInfo.FAILED_PRECONDITION, String.format(massage, params));
151153
}
152154

153155
static DatastoreException propagateUserException(Exception ex) {
154-
throw new DatastoreException(Code.UNKNOWN, ex.getMessage(), ex);
156+
throw new DatastoreException(ErrorInfo.UNKNOWN, ex.getMessage(), ex);
155157
}
156158
}

branches/pubsub-alpha/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreExceptionTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.fail;
2121

22-
import com.google.gcloud.datastore.DatastoreException.Code;
22+
import com.google.gcloud.datastore.DatastoreException.ErrorInfo;
2323
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException;
2424
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException.Reason;
2525

@@ -30,14 +30,14 @@ public class DatastoreExceptionTest {
3030
@Test
3131
public void testCode() throws Exception {
3232
for (Reason reason : Reason.values()) {
33-
Code code = Code.valueOf(reason.name());
33+
ErrorInfo code = ErrorInfo.valueOf(reason.name());
3434
assertEquals(reason.retryable(), code.retryable());
3535
assertEquals(reason.description(), code.description());
3636
assertEquals(reason.httpStatus(), code.httpStatus());
3737
}
3838

39-
DatastoreException exception = new DatastoreException(Code.ABORTED, "bla");
40-
assertEquals(Code.ABORTED, exception.code());
39+
DatastoreException exception = new DatastoreException(ErrorInfo.ABORTED, "bla");
40+
assertEquals(ErrorInfo.ABORTED, exception.errorInfo());
4141
}
4242

4343
@Test
@@ -47,7 +47,7 @@ public void testTranslateAndThrow() throws Exception {
4747
DatastoreException.translateAndThrow(new DatastoreRpcException(reason));
4848
fail("Exception expected");
4949
} catch (DatastoreException ex) {
50-
assertEquals(reason.name(), ex.code().name());
50+
assertEquals(reason.name(), ex.errorInfo().name());
5151
}
5252
}
5353
}
@@ -58,7 +58,7 @@ public void testThrowInvalidRequest() throws Exception {
5858
DatastoreException.throwInvalidRequest("message %s %d", "a", 1);
5959
fail("Exception expected");
6060
} catch (DatastoreException ex) {
61-
assertEquals(Code.FAILED_PRECONDITION, ex.code());
61+
assertEquals(ErrorInfo.FAILED_PRECONDITION, ex.errorInfo());
6262
assertEquals("message a 1", ex.getMessage());
6363
}
6464
}

branches/pubsub-alpha/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public void testTransactionWithRead() {
197197
transaction.commit();
198198
fail("Expecting a failure");
199199
} catch (DatastoreException expected) {
200-
assertEquals(DatastoreException.Code.ABORTED, expected.code());
200+
assertEquals(DatastoreException.ErrorInfo.ABORTED, expected.errorInfo());
201201
}
202202
}
203203

@@ -225,7 +225,7 @@ public void testTransactionWithQuery() {
225225
transaction.commit();
226226
fail("Expecting a failure");
227227
} catch (DatastoreException expected) {
228-
assertEquals(DatastoreException.Code.ABORTED, expected.code());
228+
assertEquals(DatastoreException.ErrorInfo.ABORTED, expected.errorInfo());
229229
}
230230
}
231231

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.gcloud.spi;
1616

1717
import static com.google.gcloud.spi.StorageRpc.Option.DELIMITER;
18-
import static com.google.gcloud.spi.StorageRpc.Option.FIELDS;
1918
import static com.google.gcloud.spi.StorageRpc.Option.IF_GENERATION_MATCH;
2019
import static com.google.gcloud.spi.StorageRpc.Option.IF_GENERATION_NOT_MATCH;
2120
import static com.google.gcloud.spi.StorageRpc.Option.IF_METAGENERATION_MATCH;
@@ -151,7 +150,6 @@ public Tuple<String, Iterable<Bucket>> list(Map<Option, ?> options) {
151150
.setPrefix(PREFIX.getString(options))
152151
.setMaxResults(MAX_RESULTS.getLong(options))
153152
.setPageToken(PAGE_TOKEN.getString(options))
154-
.setFields(FIELDS.getString(options))
155153
.execute();
156154
return Tuple.<String, Iterable<Bucket>>of(buckets.getNextPageToken(), buckets.getItems());
157155
} catch (IOException ex) {
@@ -170,7 +168,6 @@ public Tuple<String, Iterable<StorageObject>> list(String bucket, Map<Option, ?>
170168
.setPrefix(PREFIX.getString(options))
171169
.setMaxResults(MAX_RESULTS.getLong(options))
172170
.setPageToken(PAGE_TOKEN.getString(options))
173-
.setFields(FIELDS.getString(options))
174171
.execute();
175172
return Tuple.<String, Iterable<StorageObject>>of(
176173
objects.getNextPageToken(), objects.getItems());
@@ -187,7 +184,6 @@ public Bucket get(Bucket bucket, Map<Option, ?> options) {
187184
.setProjection(DEFAULT_PROJECTION)
188185
.setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(options))
189186
.setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(options))
190-
.setFields(FIELDS.getString(options))
191187
.execute();
192188
} catch (IOException ex) {
193189
throw translate(ex);
@@ -211,8 +207,7 @@ private Storage.Objects.Get getRequest(StorageObject object, Map<Option, ?> opti
211207
.setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(options))
212208
.setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(options))
213209
.setIfGenerationMatch(IF_GENERATION_MATCH.getLong(options))
214-
.setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(options))
215-
.setFields(FIELDS.getString(options));
210+
.setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(options));
216211
}
217212

218213
@Override

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ enum Option {
4747
MAX_RESULTS("maxResults"),
4848
PAGE_TOKEN("pageToken"),
4949
DELIMITER("delimiter"),
50-
VERSIONS("versions"),
51-
FIELDS("fields");
50+
VERSIONS("versions");
5251

5352
private final String value;
5453

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

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

1919
import com.google.common.collect.ImmutableMap;
2020
import com.google.common.collect.Lists;
21-
import com.google.gcloud.storage.Storage.BlobGetOption;
2221
import com.google.gcloud.storage.Storage.BlobSourceOption;
2322
import com.google.gcloud.storage.Storage.BlobTargetOption;
2423

@@ -36,13 +35,13 @@ public final class BatchRequest implements Serializable {
3635

3736
private final Map<BlobId, Iterable<BlobSourceOption>> toDelete;
3837
private final Map<BlobInfo, Iterable<BlobTargetOption>> toUpdate;
39-
private final Map<BlobId, Iterable<BlobGetOption>> toGet;
38+
private final Map<BlobId, Iterable<BlobSourceOption>> toGet;
4039

4140
public static class Builder {
4241

4342
private Map<BlobId, Iterable<BlobSourceOption>> toDelete = new LinkedHashMap<>();
4443
private Map<BlobInfo, Iterable<BlobTargetOption>> toUpdate = new LinkedHashMap<>();
45-
private Map<BlobId, Iterable<BlobGetOption>> toGet = new LinkedHashMap<>();
44+
private Map<BlobId, Iterable<BlobSourceOption>> toGet = new LinkedHashMap<>();
4645

4746
private Builder() {}
4847

@@ -73,15 +72,15 @@ public Builder update(BlobInfo blobInfo, BlobTargetOption... options) {
7372
/**
7473
* Retrieve metadata for the given blob.
7574
*/
76-
public Builder get(String bucket, String blob, BlobGetOption... options) {
75+
public Builder get(String bucket, String blob, BlobSourceOption... options) {
7776
toGet.put(BlobId.of(bucket, blob), Lists.newArrayList(options));
7877
return this;
7978
}
8079

8180
/**
8281
* Retrieve metadata for the given blob.
8382
*/
84-
public Builder get(BlobId blob, BlobGetOption... options) {
83+
public Builder get(BlobId blob, BlobSourceOption... options) {
8584
toGet.put(blob, Lists.newArrayList(options));
8685
return this;
8786
}
@@ -121,7 +120,7 @@ public Map<BlobInfo, Iterable<BlobTargetOption>> toUpdate() {
121120
return toUpdate;
122121
}
123122

124-
public Map<BlobId, Iterable<BlobGetOption>> toGet() {
123+
public Map<BlobId, Iterable<BlobSourceOption>> toGet() {
125124
return toGet;
126125
}
127126

0 commit comments

Comments
 (0)