Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update resource-manager branch #368

Merged
merged 67 commits into from
Nov 12, 2015
Merged
Changes from 3 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
ea36a9e
Rename ListResult and move to core module
mziccard Nov 3, 2015
6753c54
Remove implements Serializable from BasePage and implements Iterable …
mziccard Nov 4, 2015
104bf41
Rename BasePage to PageImpl
mziccard Nov 4, 2015
26471e6
Use diamond operator instead of explicit type param for PageImpl
mziccard Nov 4, 2015
cb64ccd
Merge pull request #318 from mziccard/move-list-result
aozarov Nov 4, 2015
deecc14
Add support for selected fields to blob get and list
mziccard Nov 2, 2015
bea0157
Add support for selected fields to bucket get and list
mziccard Nov 3, 2015
f11c05a
Add field selection to StorageRpc bucket get and list
mziccard Nov 4, 2015
ba4bfa6
Add field selection to Bucket.exist
mziccard Nov 4, 2015
46b60df
Delete EntityField class and remove non-accessible fields from Bucket…
mziccard Nov 4, 2015
603d50c
Add IT tests for bucket's field selection, add test for selecting all…
mziccard Nov 4, 2015
af7a08b
Use BlobField and BucketField .values() in IT tests
mziccard Nov 4, 2015
fac7687
Merge pull request #312 from mziccard/add-support-for-selected-fields
aozarov Nov 5, 2015
6636e23
Create BaseServiceException in gcloud-java-core
Nov 5, 2015
b57a13d
Rename enum, fix docs, and make accessors package private
Nov 5, 2015
73d379b
Add sbt/gradle dependencies to READMEs, change update_docs_version.sh
mziccard Nov 5, 2015
561af74
Merge pull request #324 from ajkannan/base-exception
aozarov Nov 5, 2015
2203b91
Run coveralls for PRs as well
Nov 5, 2015
1ea112d
Merge pull request #327 from mziccard/sbt-gradle-dependency-readme
aozarov Nov 5, 2015
c615c91
Merge pull request #325 from ajkannan/always-run-coveralls
aozarov Nov 5, 2015
fa9348e
update location where we look for config file when using gcloud SDK t…
Nov 6, 2015
0e32a4b
Merge pull request #329 from ajkannan/fix-config-loc
aozarov Nov 6, 2015
f4c3a32
Add more detail to README's authentication section
Nov 6, 2015
fe57e98
Add project ID order and clean docs language
Nov 6, 2015
7a72399
Add iterateAll method to Page, update example and snippet
mziccard Nov 6, 2015
c084250
Add project ID section
Nov 6, 2015
67fdcc0
fix order of project ID lookup, cleanup
Nov 6, 2015
74a39cc
Merge pull request #332 from ajkannan/cred-docs
aozarov Nov 6, 2015
2ce257f
update auth dependency
Nov 7, 2015
2de9135
Merge pull request #336 from ajkannan/update-oauth-libs
aozarov Nov 7, 2015
076127d
Add loop for empty pages in PageImpl.iterateAll
mziccard Nov 7, 2015
0a04229
Merge pull request #333 from mziccard/all-pages-iterator
aozarov Nov 9, 2015
b2e1131
scope appliation default credentials
aozarov Nov 10, 2015
49e3bd8
Merge pull request #343 from aozarov/temp
ajkannan Nov 10, 2015
d3db640
Revert 2de9135149e57cec18b070028452db1efef03125
ajkannan Nov 10, 2015
54b8472
Merge pull request #344 from GoogleCloudPlatform/revert-336-update-oa…
aozarov Nov 10, 2015
ad12f41
Allow services to avoid setting project ID
Nov 10, 2015
93c834e
Update version to 0.0.11 in preparation for 0.0.11 release
Nov 10, 2015
1f78e67
Merge pull request #347 from ajkannan/update-pom-v0.0.11
aozarov Nov 10, 2015
ffbfba4
Updating version in README files.
Nov 10, 2015
fc72ea0
Update version to 0.0.12-SNAPSHOT
Nov 10, 2015
98e9c03
Merge pull request #348 from ajkannan/change-version-to-0.0.12-SNAPSHOT
aozarov Nov 10, 2015
6c40825
Make projectIdRequired() method protected. Also supply nice error me…
Nov 10, 2015
ed1d437
Merge pull request #346 from ajkannan/project-id-optional
aozarov Nov 10, 2015
bfd54bd
replace rewrite with copy in the javadoc
aozarov Nov 11, 2015
c440ac5
Merge pull request #352 from aozarov/temp
mziccard Nov 11, 2015
dde30aa
Add javadoc to Acl
mziccard Nov 11, 2015
93dd0c2
Add javadoc to Blob
mziccard Nov 11, 2015
6de12f2
Add javadoc to BlobId
mziccard Nov 11, 2015
e2a4500
Add javadoc to Bucket
mziccard Nov 11, 2015
9608e61
Add javadoc to Cors
mziccard Nov 11, 2015
67bfcdd
Switch from enum to String for location and storageClass in BucketInf…
mziccard Nov 11, 2015
ecaf751
Add javadoc to BlobInfo
mziccard Nov 11, 2015
b9ef508
Add javadoc to Storage
mziccard Nov 11, 2015
3125167
Add getDefaultInstance method to StorageOptions and DatastoreOptions
mziccard Nov 11, 2015
d7845b8
Rename getDefaultInstance to defaultInstance and update READMEs
mziccard Nov 11, 2015
d026540
Make RetryParams conform with our code style
mziccard Nov 11, 2015
b28b307
Make ExceptionHandler conform with our code style
mziccard Nov 11, 2015
abc11ce
Use DatastoreOptions.defaultInstance in site example
mziccard Nov 11, 2015
e4471f9
Merge pull request #357 from mziccard/options-default-instance
aozarov Nov 11, 2015
7193d0d
More detailed javadoc for BlobInfo
mziccard Nov 12, 2015
5f9eaa4
Better javadoc for (Bucket/Blob)ListOptions.prefix
mziccard Nov 12, 2015
9979502
Merge pull request #356 from mziccard/storage-javadoc
aozarov Nov 12, 2015
b8defb8
Better javadoc for BucketInfo
mziccard Nov 12, 2015
da0ea58
Removed unused import from BucketInfo
mziccard Nov 12, 2015
ea56c11
Merge pull request #355 from mziccard/enums-to-string-bucket
aozarov Nov 12, 2015
e112ce6
Merge branch 'master' of https://github.com/GoogleCloudPlatform/gclou…
Nov 12, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.gcloud;

/**
* Base class for all service exceptions.
*/
public class BaseServiceException extends RuntimeException {

private static final long serialVersionUID = 5028833760039966178L;

private final int code;
private final boolean retryable;

public BaseServiceException(int code, String message, boolean retryable) {
super(message);
this.code = code;
this.retryable = retryable;
}

public BaseServiceException(int code, String message, boolean retryable, Exception cause) {
super(message, cause);
this.code = code;
this.retryable = retryable;
}

/**
* Returns the code associated with this exception.
*/
public int code() {
return code;
}

/**
* Returns {@code true} when it is safe to retry the operation that caused this exception.
*/
public boolean retryable() {
return retryable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.gcloud;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
* Tests for {@link BaseServiceException}.
*/
public class BaseServiceExceptionTest {

private final int code = 1;
private final String message = "some message";
private final boolean retryable = true;

@Test
public void testBaseServiceException() {
BaseServiceException serviceException = new BaseServiceException(code, message, retryable);
assertEquals(serviceException.code(), code);
assertEquals(serviceException.getMessage(), message);
assertEquals(serviceException.getCause(), null);

Exception cause = new RuntimeException();
serviceException = new BaseServiceException(code, message, retryable, cause);
assertEquals(serviceException.code(), code);
assertEquals(serviceException.getMessage(), message);
assertEquals(serviceException.getCause(), cause);
}
}
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.gcloud.BaseServiceException;
import com.google.gcloud.RetryHelper;
import com.google.gcloud.RetryHelper.RetryHelperException;
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException;
@@ -26,21 +27,21 @@
import java.util.HashMap;
import java.util.Map;

public class DatastoreException extends RuntimeException {
public class DatastoreException extends BaseServiceException {

private static final long serialVersionUID = 8170357898917041899L;
private static final ImmutableMap<String, Code> REASON_TO_CODE;
private static final ImmutableMap<Integer, Code> HTTP_TO_CODE;
private static final long serialVersionUID = -2336749234060754893L;
private static final ImmutableMap<String, DatastoreError> REASON_TO_ERROR;
private static final ImmutableMap<Integer, DatastoreError> HTTP_TO_ERROR;

private final Code code;
private final DatastoreError error;

/**
* An error code to represent the failure.
* Represents Datastore errors.
*
* @see <a href="https://cloud.google.com/datastore/docs/concepts/errors#Error_Codes">Google Cloud
* Datastore error codes</a>
*/
public enum Code {
public enum DatastoreError {

ABORTED(Reason.ABORTED),
DEADLINE_EXCEEDED(Reason.DEADLINE_EXCEEDED),
@@ -57,29 +58,25 @@ public enum Code {
private final String description;
private final int httpStatus;

Code(Reason reason) {
DatastoreError(Reason reason) {
this(reason.retryable(), reason.description(), reason.httpStatus());
}

Code(boolean retryable, String description, int httpStatus) {
DatastoreError(boolean retryable, String description, int httpStatus) {
this.retryable = retryable;
this.description = description;
this.httpStatus = httpStatus;
}

public String description() {
String description() {
return description;
}

public int httpStatus() {
int httpStatus() {
return httpStatus;
}

/**
* Returns {@code true} if this exception is transient and the same request could be retried.
* For any retry it is highly recommended to apply an exponential backoff.
*/
public boolean retryable() {
boolean retryable() {
return retryable;
}

@@ -89,30 +86,31 @@ DatastoreException translate(DatastoreRpcException exception, String message) {
}

static {
ImmutableMap.Builder<String, Code> builder = ImmutableMap.builder();
Map<Integer, Code> httpCodes = new HashMap<>();
for (Code code : Code.values()) {
builder.put(code.name(), code);
httpCodes.put(code.httpStatus(), code);
ImmutableMap.Builder<String, DatastoreError> builder = ImmutableMap.builder();
Map<Integer, DatastoreError> httpCodes = new HashMap<>();
for (DatastoreError error : DatastoreError.values()) {
builder.put(error.name(), error);
httpCodes.put(error.httpStatus(), error);
}
REASON_TO_CODE = builder.build();
HTTP_TO_CODE = ImmutableMap.copyOf(httpCodes);
REASON_TO_ERROR = builder.build();
HTTP_TO_ERROR = ImmutableMap.copyOf(httpCodes);
}

public DatastoreException(Code code, String message, Exception cause) {
super(MoreObjects.firstNonNull(message, code.description), cause);
this.code = code;
public DatastoreException(DatastoreError error, String message, Exception cause) {
super(error.httpStatus(), MoreObjects.firstNonNull(message, error.description),
error.retryable(), cause);
this.error = error;
}

public DatastoreException(Code code, String message) {
this(code, message, null);
public DatastoreException(DatastoreError error, String message) {
this(error, message, null);
}

/**
* Returns the code associated with this exception.
* Returns the DatastoreError associated with this exception.
*/
public Code code() {
return code;
public DatastoreError datastoreError() {
return error;
}

static DatastoreException translateAndThrow(RetryHelperException ex) {
@@ -122,35 +120,36 @@ static DatastoreException translateAndThrow(RetryHelperException ex) {
if (ex instanceof RetryHelper.RetryInterruptedException) {
RetryHelper.RetryInterruptedException.propagate();
}
throw new DatastoreException(Code.UNKNOWN, ex.getMessage(), ex);
throw new DatastoreException(DatastoreError.UNKNOWN, ex.getMessage(), ex);
}

/**
* Translate DatastoreException to DatastoreException based on their
* Translate DatastoreRpcExceptions to DatastoreExceptions based on their
* HTTP error codes. This method will always throw a new DatastoreException.
*
* @throws DatastoreException every time
*/
static DatastoreException translateAndThrow(DatastoreRpcException exception) {
String message = exception.getMessage();
Code code = REASON_TO_CODE.get(exception.reason());
if (code == null) {
code = MoreObjects.firstNonNull(HTTP_TO_CODE.get(exception.httpStatus()), Code.UNKNOWN);
DatastoreError error = REASON_TO_ERROR.get(exception.reason());
if (error == null) {
error = MoreObjects.firstNonNull(
HTTP_TO_ERROR.get(exception.httpStatus()), DatastoreError.UNKNOWN);
}
throw code.translate(exception, message);
throw error.translate(exception, message);
}

/**
* Throw a DatastoreException with {@code FAILED_PRECONDITION} code and the {@code message}
* Throw a DatastoreException with {@code FAILED_PRECONDITION} error and the {@code message}
* in a nested exception.
*
* @throws DatastoreException every time
*/
static DatastoreException throwInvalidRequest(String massage, Object... params) {
throw new DatastoreException(Code.FAILED_PRECONDITION, String.format(massage, params));
throw new DatastoreException(DatastoreError.FAILED_PRECONDITION, String.format(massage, params));
}

static DatastoreException propagateUserException(Exception ex) {
throw new DatastoreException(Code.UNKNOWN, ex.getMessage(), ex);
throw new DatastoreException(DatastoreError.UNKNOWN, ex.getMessage(), ex);
}
}
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import com.google.gcloud.datastore.DatastoreException.Code;
import com.google.gcloud.datastore.DatastoreException.DatastoreError;
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException;
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException.Reason;

@@ -28,16 +28,16 @@
public class DatastoreExceptionTest {

@Test
public void testCode() throws Exception {
public void testDatastoreError() throws Exception {
for (Reason reason : Reason.values()) {
Code code = Code.valueOf(reason.name());
assertEquals(reason.retryable(), code.retryable());
assertEquals(reason.description(), code.description());
assertEquals(reason.httpStatus(), code.httpStatus());
DatastoreError error = DatastoreError.valueOf(reason.name());
assertEquals(reason.retryable(), error.retryable());
assertEquals(reason.description(), error.description());
assertEquals(reason.httpStatus(), error.httpStatus());
}

DatastoreException exception = new DatastoreException(Code.ABORTED, "bla");
assertEquals(Code.ABORTED, exception.code());
DatastoreException exception = new DatastoreException(DatastoreError.ABORTED, "bla");
assertEquals(DatastoreError.ABORTED, exception.datastoreError());
}

@Test
@@ -47,7 +47,7 @@ public void testTranslateAndThrow() throws Exception {
DatastoreException.translateAndThrow(new DatastoreRpcException(reason));
fail("Exception expected");
} catch (DatastoreException ex) {
assertEquals(reason.name(), ex.code().name());
assertEquals(reason.name(), ex.datastoreError().name());
}
}
}
@@ -58,7 +58,7 @@ public void testThrowInvalidRequest() throws Exception {
DatastoreException.throwInvalidRequest("message %s %d", "a", 1);
fail("Exception expected");
} catch (DatastoreException ex) {
assertEquals(Code.FAILED_PRECONDITION, ex.code());
assertEquals(DatastoreError.FAILED_PRECONDITION, ex.datastoreError());
assertEquals("message a 1", ex.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -197,7 +197,7 @@ public void testTransactionWithRead() {
transaction.commit();
fail("Expecting a failure");
} catch (DatastoreException expected) {
assertEquals(DatastoreException.Code.ABORTED, expected.code());
assertEquals(DatastoreException.DatastoreError.ABORTED, expected.datastoreError());
}
}

@@ -225,7 +225,7 @@ public void testTransactionWithQuery() {
transaction.commit();
fail("Expecting a failure");
} catch (DatastoreException expected) {
assertEquals(DatastoreException.Code.ABORTED, expected.code());
assertEquals(DatastoreException.DatastoreError.ABORTED, expected.datastoreError());
}
}

Original file line number Diff line number Diff line change
@@ -16,38 +16,24 @@

package com.google.gcloud.storage;

import com.google.gcloud.BaseServiceException;
import com.google.gcloud.RetryHelper;
import com.google.gcloud.RetryHelper.RetryHelperException;
import com.google.gcloud.RetryHelper.RetryInterruptedException;

/**
* Storage service exception.
*
* @see <a href="https://cloud.google.com/storage/docs/json_api/v1/status-codes">Google Cloud
* Storage error codes</a>
*/
public class StorageException extends RuntimeException {
public class StorageException extends BaseServiceException {

private static final long serialVersionUID = -3748432005065428084L;
private static final long serialVersionUID = 8088235105953640145L;
private static final int UNKNOWN_CODE = -1;

private final int code;
private final boolean retryable;

public StorageException(int code, String message, boolean retryable) {
super(message);
this.code = code;
this.retryable = retryable;
}

/**
* Returns the code associated with this exception.
*/
public int code() {
return code;
}

public boolean retryable() {
return retryable;
super(code, message, retryable);
}

/**