Skip to content

Commit

Permalink
Merge pull request #488 from mziccard/bigquery
Browse files Browse the repository at this point in the history
Merge master into bigquery
  • Loading branch information
aozarov committed Dec 18, 2015
2 parents 433c286 + a08e7bb commit ec115cb
Show file tree
Hide file tree
Showing 76 changed files with 2,254 additions and 833 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ before_install:
install: mvn install -DskipTests=true -Dgpg.skip=true
script:
- utilities/verify.sh
branches:
only:
- master
after_success:
- utilities/after_success.sh
env:
Expand Down
74 changes: 63 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ If you are using Maven, add this to your pom.xml file
<dependency>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java</artifactId>
<version>0.0.10</version>
<version>0.1.0</version>
</dependency>
```
If you are using Gradle, add this to your dependencies
```Groovy
compile 'com.google.gcloud:gcloud-java:jar:0.0.10'
compile 'com.google.gcloud:gcloud-java:0.1.0'
```
If you are using SBT, add this to your dependencies
```Scala
libraryDependencies += "com.google.gcloud" % "gcloud-java" % "0.0.10"
libraryDependencies += "com.google.gcloud" % "gcloud-java" % "0.1.0"
```

Example Applications
Expand All @@ -45,15 +45,63 @@ 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. Google Cloud SDK project ID
5. Compute Engine project ID

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

There are multiple ways to authenticate to use Google Cloud services.
First, ensure that the necessary Google Cloud APIs are enabled for your project. To do this, follow the instructions on the [authentication document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/authentication/readme.md#authentication) shared by all the gcloud language libraries.

Next, choose a method for authenticating API requests from within your project:

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 @@ -75,7 +123,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 Expand Up @@ -118,8 +166,7 @@ import com.google.gcloud.storage.StorageOptions;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
StorageOptions options = StorageOptions.builder().projectId("project").build();
Storage storage = options.service();
Storage storage = StorageOptions.defaultInstance().service();
BlobId blobId = BlobId.of("bucket", "blob_name");
Blob blob = Blob.load(storage, blobId);
if (blob == null) {
Expand All @@ -135,6 +182,11 @@ if (blob == null) {
}
```
Troubleshooting
---------------
To get help, follow the `gcloud-java` links in the `gcloud-*` [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting).
Java Versions
-------------
Expand All @@ -161,7 +213,7 @@ Contributing
Contributions to this library are always welcome and highly encouraged.
See [CONTRIBUTING] for more information on how to get started.
See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.

Expand All @@ -172,7 +224,7 @@ Apache 2.0 - See [LICENSE] for more information.


[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md
[cloud-platform]: https://cloud.google.com/
Expand Down
16 changes: 12 additions & 4 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ This script takes an optional argument denoting the new version. By default, if
2. Create a PR to update the pom.xml version.
The PR should look something like [#225](https://github.com/GoogleCloudPlatform/gcloud-java/pull/225). After this PR is merged into GoogleCloudPlatform/gcloud-java, Travis CI will push a new website to GoogleCloudPlatform/gh-pages, push a new artifact to the Maven Central Repository, and update versions in the README files.

3. Create a release on Github manually.
Go to the [releases page](https://github.com/GoogleCloudPlatform/gcloud-java/releases) and click "Draft a new release." Use `vX.Y.Z` as the "Tag Version" and `X.Y.Z` as the "Release Title", where `X.Y.Z` is the release version as listed in the `pom.xml` files.
3. Before moving on, verify that the artifacts have successfully been pushed to the Maven Central Repository. Open Travis CI, click the ["Build History" tab](https://travis-ci.org/GoogleCloudPlatform/gcloud-java/builds), and open the second build's logs for Step 2's PR. Be sure that you are not opening the "Pull Request" build logs. When the build finishes, scroll to the end of the log and verify that the artifacts were successfully staged and deployed. You can also search for `gcloud-java` on the [Sonatype website](https://oss.sonatype.org/#nexus-search;quick~gcloud-java) and check the latest version number. If the deployment didn't succeed because of a flaky test, rerun the build.

4. Run `utilities/update_pom_version.sh` again (to include "-SNAPSHOT" in the project version).
4. Publish a release on Github manually.
Go to the [releases page](https://github.com/GoogleCloudPlatform/gcloud-java/releases) and open the appropriate release draft. Make sure the "Tag Version" is `vX.Y.Z` and the "Release Title" is `X.Y.Z`, where `X.Y.Z` is the release version as listed in the `pom.xml` files. The draft should already have all changes that impact users since the previous release. To double check this, you can use the `git log` command and look through the merged master branch pull requests. Here is an example of the log command to get non-merge commits between v0.0.12 and v0.1.0:

```
git --no-pager log v0.0.12..v0.1.0 --pretty=oneline --abbrev-commit --no-merges
```

Ensure that the format is consistent with previous releases (for an example, see the [0.1.0 release](https://github.com/GoogleCloudPlatform/gcloud-java/releases/tag/v0.1.0)). After adding any missing updates and reformatting as necessary, publish the draft. Finally, create a new draft for the next release.

5. Run `utilities/update_pom_version.sh` again (to include "-SNAPSHOT" in the project version).
As mentioned before, there is an optional version argument. By default, the script will update the version from "X.Y.Z" to "X.Y.Z+1-SNAPSHOT". Suppose a different version is desired, for example X+1.0.0-SNAPSHOT. Then the appropriate command to run would be `utilities/update_pom_version.sh X+1.0.0-SNAPSHOT`.

5. Create and merge in another PR to reflect the updated project version. For an example of what this PR should look like, see [#227](https://github.com/GoogleCloudPlatform/gcloud-java/pull/227).
6. Create and merge in another PR to reflect the updated project version. For an example of what this PR should look like, see [#227](https://github.com/GoogleCloudPlatform/gcloud-java/pull/227).

### To push a snapshot version

Expand Down
2 changes: 1 addition & 1 deletion gcloud-java-bigquery/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.1.1-SNAPSHOT</version>
</parent>
<properties>
<site.installationModule>gcloud-java-bigquery</site.installationModule>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ public void setUp() {
EasyMock.replay(rpcFactoryMock);
options = BigQueryOptions.builder()
.projectId(PROJECT)
.authCredentials(AuthCredentials.noCredentials())
.serviceRpcFactory(rpcFactoryMock)
.build();
}
Expand Down Expand Up @@ -1011,7 +1010,7 @@ public void testRetryableException() {
.andThrow(new BigQueryException(500, "InternalError", true))
.andReturn(DATASET_INFO_WITH_PROJECT.toPb());
EasyMock.replay(bigqueryRpcMock);
bigquery = options.toBuilder().retryParams(RetryParams.getDefaultInstance()).build().service();
bigquery = options.toBuilder().retryParams(RetryParams.defaultInstance()).build().service();
DatasetInfo dataset = bigquery.getDataset(DATASET);
assertEquals(DATASET_INFO_WITH_PROJECT, dataset);
}
Expand All @@ -1022,7 +1021,7 @@ public void testNonRetryableException() {
EasyMock.expect(bigqueryRpcMock.getDataset(DATASET, EMPTY_RPC_OPTIONS))
.andThrow(new BigQueryException(501, exceptionMessage, false));
EasyMock.replay(bigqueryRpcMock);
bigquery = options.toBuilder().retryParams(RetryParams.getDefaultInstance()).build().service();
bigquery = options.toBuilder().retryParams(RetryParams.defaultInstance()).build().service();
thrown.expect(BigQueryException.class);
thrown.expectMessage(exceptionMessage);
bigquery.getDataset(DatasetId.of(DATASET));
Expand All @@ -1034,7 +1033,7 @@ public void testRuntimeException() {
EasyMock.expect(bigqueryRpcMock.getDataset(DATASET, EMPTY_RPC_OPTIONS))
.andThrow(new RuntimeException(exceptionMessage));
EasyMock.replay(bigqueryRpcMock);
bigquery = options.toBuilder().retryParams(RetryParams.getDefaultInstance()).build().service();
bigquery = options.toBuilder().retryParams(RetryParams.defaultInstance()).build().service();
thrown.expect(BigQueryException.class);
thrown.expectMessage(exceptionMessage);
bigquery.getDataset(DATASET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ public void testServiceOptions() throws Exception {

options = options.toBuilder()
.projectId("p2")
.retryParams(RetryParams.getDefaultInstance())
.authCredentials(AuthCredentials.noCredentials())
.retryParams(RetryParams.defaultInstance())
.authCredentials(null)
.build();
serializedCopy = serializeAndDeserialize(options);
assertEquals(options, serializedCopy);
Expand Down
16 changes: 12 additions & 4 deletions gcloud-java-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@ If you are using Maven, add this to your pom.xml file
<dependency>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java-core</artifactId>
<version>0.0.10</version>
<version>0.1.0</version>
</dependency>
```
If you are using Gradle, add this to your dependencies
```Groovy
compile 'com.google.gcloud:gcloud-java-core:jar:0.0.10'
compile 'com.google.gcloud:gcloud-java-core:jar:0.1.0'
```
If you are using SBT, add this to your dependencies
```Scala
libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.0.10"
libraryDependencies += "com.google.gcloud" % "gcloud-java-core" % "0.1.0"
```

Troubleshooting
---------------

To get help, follow the `gcloud-java` links in the `gcloud-*` [shared Troubleshooting document](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/troubleshooting/readme.md#troubleshooting).

Java Versions
-------------

Expand All @@ -39,7 +44,9 @@ Contributing

Contributions to this library are always welcome and highly encouraged.

See [CONTRIBUTING] for more information on how to get started.
See `gcloud-java`'s [CONTRIBUTING] documentation and the `gcloud-*` [shared documentation](https://github.com/GoogleCloudPlatform/gcloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) for more information on how to get started.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.

Versioning
----------
Expand All @@ -57,5 +64,6 @@ Apache 2.0 - See [LICENSE] for more information.


[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
[cloud-platform]: https://cloud.google.com/
12 changes: 9 additions & 3 deletions 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.1.1-SNAPSHOT</version>
</parent>
<properties>
<site.installationModule>gcloud-java-core</site.installationModule>
Expand All @@ -20,12 +20,18 @@
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-credentials</artifactId>
<version>0.1.0</version>
<version>0.3.1</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>0.1.0</version>
<version>0.3.1</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
Expand Down
Loading

0 comments on commit ec115cb

Please sign in to comment.