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
Show file tree
Hide file tree
Changes from all 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
64 changes: 59 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ This client supports the following Google Cloud Platform services:

Quickstart
----------
Add this to your pom.xml file
If you are using Maven, add this to your pom.xml file
```xml
<dependency>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java</artifactId>
<version>0.0.10</version>
<version>0.0.11</version>
</dependency>
```
If you are using Gradle, add this to your dependencies
```Groovy
compile 'com.google.gcloud:gcloud-java:jar:0.0.11'
```
If you are using SBT, add this to your dependencies
```Scala
libraryDependencies += "com.google.gcloud" % "gcloud-java" % "0.0.11"
```

Example Applications
--------------------
Expand All @@ -37,15 +45,61 @@ Example Applications
- [`StorageExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java) - A simple command line interface providing some of Cloud Storage's functionality
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/StorageExample.html).

Specifying a Project ID
-----------------------

Most `gcloud-java` libraries require a project ID. There are multiple ways to specify this project ID.

1. When using `gcloud-java` libraries from within Compute/App Engine, there's no need to specify a project ID. It is automatically inferred from the production environment.
2. When using `gcloud-java` elsewhere, you can do one of the following:
* Supply the project ID when building the service options. For example, to use Datastore from a project with ID "PROJECT_ID", you can write:

```java
Datastore datastore = DatastoreOptions.builder().projectId("PROJECT_ID").build().service();
```
* Specify the environment variable `GCLOUD_PROJECT` to be your desired project ID.
* Set the project ID using the [Google Cloud SDK](https://cloud.google.com/sdk/?hl=en). To use the SDK, [download the SDK](https://cloud.google.com/sdk/?hl=en) if you haven't already, and set the project ID from the command line. For example:

```
gcloud config set project PROJECT_ID
```

`gcloud-java` determines the project ID from the following sources in the listed order, stopping once it finds a value:

1. Project ID supplied when building the service options
2. Project ID specified by the environment variable `GCLOUD_PROJECT`
3. App Engine project ID
4. Compute Engine project ID
5. Google Cloud SDK project ID

Authentication
--------------

There are multiple ways to authenticate to use Google Cloud services.

1. When using `gcloud-java` libraries from within Compute/App Engine, no additional authentication steps are necessary.
2. When using `gcloud-java` libraries elsewhere, there are two options:
* [Generate a JSON service account key](https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts). Supply a path to the downloaded JSON credentials file when building the options supplied to datastore/storage constructor.
* If running locally for development/testing, you can use use [Google Cloud SDK](https://cloud.google.com/sdk/?hl=en). To use the SDK authentication, [download the SDK](https://cloud.google.com/sdk/?hl=en) if you haven't already. Then login using the SDK (`gcloud auth login` in command line), and set your current project using `gcloud config set project PROJECT_ID`.
* [Generate a JSON service account key](https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts). After downloading that key, you must do one of the following:
* Define the environment variable GOOGLE_APPLICATION_CREDENTIALS to be the location of the key. For example:
```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/key.json
```
* Supply the JSON credentials file when building the service options. For example, this Storage object has the necessary permissions to interact with your Google Cloud Storage data:
```java
Storage storage = StorageOptions.builder()
.authCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json"))
.build()
.service();
```
* If running locally for development/testing, you can use use Google Cloud SDK. Download the SDK if you haven't already, then login using the SDK (`gcloud auth login` in command line). Be sure to set your project ID as described above.

`gcloud-java` looks for credentials in the following order, stopping once it finds credentials:

1. Credentials supplied when building the service options
2. App Engine credentials
3. Key file pointed to by the GOOGLE_APPLICATION_CREDENTIALS environment variable
4. Google Cloud SDK credentials
5. Compute Engine credentials

Google Cloud Datastore
----------------------
Expand All @@ -67,7 +121,7 @@ import com.google.gcloud.datastore.Entity;
import com.google.gcloud.datastore.Key;
import com.google.gcloud.datastore.KeyFactory;

Datastore datastore = DatastoreOptions.getDefaultInstance().service();
Datastore datastore = DatastoreOptions.defaultInstance().service();
KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND);
Key key = keyFactory.newKey(keyName);
Entity entity = datastore.get(key);
Expand Down
12 changes: 10 additions & 2 deletions gcloud-java-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ This module provides common functionality required by service-specific modules o

Quickstart
----------
Add this to your pom.xml file
If you are using Maven, add this to your pom.xml file
```xml
<dependency>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java-core</artifactId>
<version>0.0.10</version>
<version>0.0.11</version>
</dependency>
```
If you are using Gradle, add this to your dependencies
```Groovy
compile 'com.google.gcloud:gcloud-java-core:jar:0.0.11'
```
If you are using SBT, add this to your dependencies
```Scala
libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.11"
```

Java Versions
-------------
Expand Down
2 changes: 1 addition & 1 deletion gcloud-java-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java-pom</artifactId>
<version>0.0.11-SNAPSHOT</version>
<version>0.0.12-SNAPSHOT</version>
</parent>
<properties>
<site.installationModule>gcloud-java-core</site.installationModule>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public boolean equals(Object obj) {
@Override
protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport,
Set<String> scopes) {
return new HttpCredentialsAdapter(googleCredentials);
return new HttpCredentialsAdapter(googleCredentials.createScoped(scopes));
}

@Override
Expand Down
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
Expand Up @@ -231,11 +231,11 @@ void verifyCaller(Callable<?> callable) {
}
}

public Set<Class<? extends Exception>> getRetriableExceptions() {
public Set<Class<? extends Exception>> retriableExceptions() {
return retriableExceptions;
}

public Set<Class<? extends Exception>> getNonRetriableExceptions() {
public Set<Class<? extends Exception>> nonRetriableExceptions() {
return nonRetriableExceptions;
}

Expand All @@ -262,7 +262,7 @@ boolean shouldRetry(Exception ex) {
/**
* Returns an instance which retry any checked exception and abort on any runtime exception.
*/
public static ExceptionHandler getDefaultInstance() {
public static ExceptionHandler defaultInstance() {
return DEFAULT_INSTANCE;
}

Expand Down
67 changes: 67 additions & 0 deletions gcloud-java-core/src/main/java/com/google/gcloud/Page.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 java.util.Iterator;

/**
* Interface for Google Cloud paginated results.
*
* <p>
* Use {@code Page} to iterate through all values (also in next pages):
* <pre> {@code
* Page<T> page = ...; // get a Page<T> instance
* Iterator<T> iterator = page.iterateAll();
* while (iterator.hasNext()) {
* T value = iterator.next();
* // do something with value
* }}</pre>
* <p>
* Or handle pagination explicitly:
* <pre> {@code
* Page<T> page = ...; // get a Page<T> instance
* while (page != null) {
* for (T value : page.values()) {
* // do something with value
* }
* page = page.nextPage();
* }}</pre>
*/
public interface Page<T> {

/**
* Returns the values contained in this page.
*/
Iterable<T> values();

/**
* Returns an iterator for all values, possibly also in the next pages. Once current page's values
* are traversed the iterator fetches next page, if any.
*/
Iterator<T> iterateAll();

/**
* Returns the cursor for the nextPage or {@code null} if no more results.
*/
String nextPageCursor();

/**
* Returns the next page of results or {@code null} if no more result.
*/
Page<T> nextPage();

}
111 changes: 111 additions & 0 deletions gcloud-java-core/src/main/java/com/google/gcloud/PageImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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 com.google.common.collect.AbstractIterator;

import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import java.util.Objects;

/**
* Base implementation for Google Cloud paginated results.
*/
public class PageImpl<T> implements Page<T>, Serializable {

private static final long serialVersionUID = 3914827379823557934L;

private final String cursor;
private final Iterable<T> results;
private final NextPageFetcher<T> pageFetcher;

public interface NextPageFetcher<T> extends Serializable {
Page<T> nextPage();
}

static class PageIterator<T> extends AbstractIterator<T> {

private Iterator<T> currentPageIterator;
private Page<T> currentPage;

PageIterator(Page<T> currentPage) {
this.currentPageIterator = currentPage.values().iterator();
this.currentPage = currentPage;
}

@Override
protected T computeNext() {
while (!currentPageIterator.hasNext()) {
currentPage = currentPage.nextPage();
if (currentPage == null) {
return endOfData();
}
currentPageIterator = currentPage.values().iterator();
}
return currentPageIterator.next();
}
}

/**
* Creates a {@code PageImpl} object. In order for the object to be serializable the {@code
* results} parameter must be serializable.
*/
public PageImpl(NextPageFetcher<T> pageFetcher, String cursor, Iterable<T> results) {
this.pageFetcher = pageFetcher;
this.cursor = cursor;
this.results = results;
}

@Override
public Iterable<T> values() {
return results == null ? Collections.EMPTY_LIST : results;
}

@Override
public Iterator<T> iterateAll() {
return new PageIterator<T>(this);
}

@Override
public String nextPageCursor() {
return cursor;
}

@Override
public Page<T> nextPage() {
if (cursor == null || pageFetcher == null) {
return null;
}
return pageFetcher.nextPage();
}

@Override
public int hashCode() {
return Objects.hash(cursor, results);
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof PageImpl)) {
return false;
}
PageImpl<?> other = (PageImpl<?>) obj;
return Objects.equals(cursor, other.cursor)
&& Objects.equals(results, other.results);
}
}
Loading