Skip to content

Commit ec57eb2

Browse files
author
Ajay Kannan
committed
Merge changes from upstream/master
2 parents 0864393 + 44a1533 commit ec57eb2

File tree

247 files changed

+32698
-3787
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+32698
-3787
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ before_install:
1010
install: mvn install -DskipTests=true -Dgpg.skip=true
1111
script:
1212
- utilities/verify.sh
13-
branches:
14-
only:
15-
- master
1613
after_success:
1714
- utilities/after_success.sh
1815
env:

CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ Using maven for build/test
1515
After you cloned the repository use Maven for building and running the tests.
1616
Maven 3.0+ is required.
1717

18+
When downloading the source, we recommend you obtain service account credentials.
19+
These credentials will allow you to run integration tests using `mvn verify` in command line.
20+
Follow step 2 of the [authentication instructions](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) to generate and use JSON service account credentials.
21+
22+
It's also important to test that changes don't break compatibility with App/Compute Engine and when running elsewhere.
23+
To run tests on different platforms, try deploying the apps available on the [gcloud-java-examples](https://github.com/GoogleCloudPlatform/gcloud-java-examples) repository.
24+
End-to-end tests should ensure that gcloud-java works when running on the
25+
26+
* App Engine production environment (see the docs for [uploading your app to production App Engine](https://cloud.google.com/appengine/docs/java/tools/maven#uploading_your_app_to_production_app_engine))
27+
* App Engine development server (see the docs for [testing your app with the development server](https://cloud.google.com/appengine/docs/java/tools/maven#testing_your_app_with_the_development_server))
28+
* Compute Engine (see the [Getting Started Guide](https://cloud.google.com/compute/docs/quickstart), and be sure to [enable the appropriate APIs](https://github.com/GoogleCloudPlatform/gcloud-common/tree/master/authentication#on-google-compute-engine))
29+
* Your desktop (using `mvn exec:java`, for example)
30+
31+
When changes are made to authentication and project ID-related code, authentication and project ID inference should be tested using all relevant methods detailed in the [authentication docs](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) and [project ID docs](https://github.com/GoogleCloudPlatform/gcloud-java#specifying-a-project-id).
32+
33+
Known issue: If you have installed the Google Cloud SDK, be sure to log in (using `gcloud auth login`) before running tests. Though the Datastore tests use a local Datastore emulator that doesn't require authentication, they will not run if you have the Google Cloud SDK installed but aren't authenticated.
1834

1935
Adding Features
2036
---------------

README.md

Lines changed: 164 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,151 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services.
1212

1313
This client supports the following Google Cloud Platform services:
1414

15+
- [Google Cloud BigQuery] (#google-cloud-bigquery-alpha) (Alpha)
1516
- [Google Cloud Datastore] (#google-cloud-datastore)
17+
- [Google Cloud Resource Manager] (#google-cloud-resource-manager-alpha) (Alpha)
1618
- [Google Cloud Storage] (#google-cloud-storage)
1719

1820
> Note: This client is a work-in-progress, and may occasionally
1921
> make backwards-incompatible changes.
2022
2123
Quickstart
2224
----------
23-
Add this to your pom.xml file
25+
If you are using Maven, add this to your pom.xml file
2426
```xml
2527
<dependency>
2628
<groupId>com.google.gcloud</groupId>
2729
<artifactId>gcloud-java</artifactId>
28-
<version>0.0.10</version>
30+
<version>0.1.3</version>
2931
</dependency>
3032
```
33+
If you are using Gradle, add this to your dependencies
34+
```Groovy
35+
compile 'com.google.gcloud:gcloud-java:0.1.3'
36+
```
37+
If you are using SBT, add this to your dependencies
38+
```Scala
39+
libraryDependencies += "com.google.gcloud" % "gcloud-java" % "0.1.3"
40+
```
3141

3242
Example Applications
3343
--------------------
3444

45+
- [`BigQueryExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java) - A simple command line interface providing some of Cloud BigQuery's functionality
46+
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/BigQueryExample.html).
47+
- [`Bookshelf`](https://github.com/GoogleCloudPlatform/getting-started-java/tree/master/bookshelf) - An App Engine app that manages a virtual bookshelf.
48+
- This app uses `gcloud-java` to interface with Cloud Datastore and Cloud Storage. It also uses Cloud SQL, another Google Cloud Platform service.
3549
- [`DatastoreExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java) - A simple command line interface for the Cloud Datastore
3650
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/DatastoreExample.html).
51+
- [`ResourceManagerExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/ResourceManagerExample.java) - A simple command line interface providing some of Cloud Resource Manager's functionality
52+
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/ResourceManagerExample.html).
53+
- [`SparkDemo`](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/managedvms/sparkjava) - An example of using gcloud-java-datastore from within the SparkJava and App Engine Managed VM frameworks.
54+
- Read about how it works on the example's [README page](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/managedvms/sparkjava#how-does-it-work).
3755
- [`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
3856
- 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).
3957

58+
Specifying a Project ID
59+
-----------------------
60+
61+
Most `gcloud-java` libraries require a project ID. There are multiple ways to specify this project ID.
62+
63+
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.
64+
2. When using `gcloud-java` elsewhere, you can do one of the following:
65+
* Supply the project ID when building the service options. For example, to use Datastore from a project with ID "PROJECT_ID", you can write:
66+
67+
```java
68+
Datastore datastore = DatastoreOptions.builder().projectId("PROJECT_ID").build().service();
69+
```
70+
* Specify the environment variable `GCLOUD_PROJECT` to be your desired project ID.
71+
* 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:
72+
73+
```
74+
gcloud config set project PROJECT_ID
75+
```
76+
77+
`gcloud-java` determines the project ID from the following sources in the listed order, stopping once it finds a value:
78+
79+
1. Project ID supplied when building the service options
80+
2. Project ID specified by the environment variable `GCLOUD_PROJECT`
81+
3. App Engine project ID
82+
4. Google Cloud SDK project ID
83+
5. Compute Engine project ID
84+
4085
Authentication
4186
--------------
4287

43-
There are multiple ways to authenticate to use Google Cloud services.
88+
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.
89+
90+
Next, choose a method for authenticating API requests from within your project:
4491

4592
1. When using `gcloud-java` libraries from within Compute/App Engine, no additional authentication steps are necessary.
4693
2. When using `gcloud-java` libraries elsewhere, there are two options:
47-
* [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.
48-
* 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`.
94+
* [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:
95+
* Define the environment variable GOOGLE_APPLICATION_CREDENTIALS to be the location of the key. For example:
96+
```bash
97+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/key.json
98+
```
99+
* 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:
100+
```java
101+
Storage storage = StorageOptions.builder()
102+
.authCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json"))
103+
.build()
104+
.service();
105+
```
106+
* 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.
107+
108+
`gcloud-java` looks for credentials in the following order, stopping once it finds credentials:
109+
110+
1. Credentials supplied when building the service options
111+
2. App Engine credentials
112+
3. Key file pointed to by the GOOGLE_APPLICATION_CREDENTIALS environment variable
113+
4. Google Cloud SDK credentials
114+
5. Compute Engine credentials
115+
116+
Google Cloud BigQuery (Alpha)
117+
----------------------
118+
119+
- [API Documentation][bigquery-api]
120+
- [Official Documentation][cloud-bigquery-docs]
121+
122+
#### Preview
123+
124+
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you
125+
must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
126+
127+
```java
128+
import com.google.gcloud.bigquery.BaseTableInfo;
129+
import com.google.gcloud.bigquery.BigQuery;
130+
import com.google.gcloud.bigquery.BigQueryOptions;
131+
import com.google.gcloud.bigquery.Field;
132+
import com.google.gcloud.bigquery.JobStatus;
133+
import com.google.gcloud.bigquery.LoadJobInfo;
134+
import com.google.gcloud.bigquery.Schema;
135+
import com.google.gcloud.bigquery.TableId;
136+
import com.google.gcloud.bigquery.TableInfo;
137+
138+
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
139+
TableId tableId = TableId.of("dataset", "table");
140+
BaseTableInfo info = bigquery.getTable(tableId);
141+
if (info == null) {
142+
System.out.println("Creating table " + tableId);
143+
Field integerField = Field.of("fieldName", Field.Type.integer());
144+
bigquery.create(TableInfo.of(tableId, Schema.of(integerField)));
145+
} else {
146+
System.out.println("Loading data into table " + tableId);
147+
LoadJobInfo loadJob = LoadJobInfo.of(tableId, "gs://bucket/path");
148+
loadJob = bigquery.create(loadJob);
149+
while (loadJob.status().state() != JobStatus.State.DONE) {
150+
Thread.sleep(1000L);
151+
loadJob = bigquery.getJob(loadJob.jobId());
152+
}
153+
if (loadJob.status().error() != null) {
154+
System.out.println("Job completed with errors");
155+
} else {
156+
System.out.println("Job succeeded");
157+
}
158+
}
159+
```
49160
50161
Google Cloud Datastore
51162
----------------------
@@ -61,14 +172,13 @@ Here is a code snippet showing a simple usage example from within Compute/App En
61172
62173
```java
63174
import com.google.gcloud.datastore.Datastore;
64-
import com.google.gcloud.datastore.DatastoreFactory;
65175
import com.google.gcloud.datastore.DatastoreOptions;
66176
import com.google.gcloud.datastore.DateTime;
67177
import com.google.gcloud.datastore.Entity;
68178
import com.google.gcloud.datastore.Key;
69179
import com.google.gcloud.datastore.KeyFactory;
70180
71-
Datastore datastore = DatastoreFactory.instance().get(DatastoreOptions.getDefaultInstance());
181+
Datastore datastore = DatastoreOptions.defaultInstance().service();
72182
KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND);
73183
Key key = keyFactory.newKey(keyName);
74184
Entity entity = datastore.get(key);
@@ -88,6 +198,37 @@ if (entity == null) {
88198
}
89199
```
90200
201+
Google Cloud Resource Manager (Alpha)
202+
----------------------
203+
204+
- [API Documentation][resourcemanager-api]
205+
- [Official Documentation][cloud-resourcemanager-docs]
206+
207+
#### Preview
208+
209+
Here is a code snippet showing a simple usage example. Note that you must supply Google SDK credentials for this service, not other forms of authentication listed in the [Authentication section](#authentication).
210+
211+
```java
212+
import com.google.gcloud.resourcemanager.ProjectInfo;
213+
import com.google.gcloud.resourcemanager.ResourceManager;
214+
import com.google.gcloud.resourcemanager.ResourceManagerOptions;
215+
216+
import java.util.Iterator;
217+
218+
ResourceManager resourceManager = ResourceManagerOptions.defaultInstance().service();
219+
ProjectInfo myProject = resourceManager.get("some-project-id"); // Use an existing project's ID
220+
ProjectInfo newProjectInfo = resourceManager.replace(myProject.toBuilder()
221+
.addLabel("launch-status", "in-development").build());
222+
System.out.println("Updated the labels of project " + newProjectInfo.projectId()
223+
+ " to be " + newProjectInfo.labels());
224+
// List all the projects you have permission to view.
225+
Iterator<ProjectInfo> projectIterator = resourceManager.list().iterateAll();
226+
System.out.println("Projects I can view:");
227+
while (projectIterator.hasNext()) {
228+
System.out.println(projectIterator.next().projectId());
229+
}
230+
```
231+
91232
Google Cloud Storage
92233
----------------------
93234
@@ -106,16 +247,14 @@ import static java.nio.charset.StandardCharsets.UTF_8;
106247
import com.google.gcloud.storage.Blob;
107248
import com.google.gcloud.storage.BlobId;
108249
import com.google.gcloud.storage.Storage;
109-
import com.google.gcloud.storage.StorageFactory;
110250
import com.google.gcloud.storage.StorageOptions;
111251
112252
import java.nio.ByteBuffer;
113253
import java.nio.channels.WritableByteChannel;
114254
115-
StorageOptions options = StorageOptions.builder().projectId("project").build();
116-
Storage storage = StorageFactory.instance().get(options);
255+
Storage storage = StorageOptions.defaultInstance().service();
117256
BlobId blobId = BlobId.of("bucket", "blob_name");
118-
Blob blob = Blob.load(storage, blobId);
257+
Blob blob = Blob.get(storage, blobId);
119258
if (blob == null) {
120259
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
121260
storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
@@ -129,6 +268,11 @@ if (blob == null) {
129268
}
130269
```
131270
271+
Troubleshooting
272+
---------------
273+
274+
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).
275+
132276
Java Versions
133277
-------------
134278
@@ -155,7 +299,7 @@ Contributing
155299
156300
Contributions to this library are always welcome and highly encouraged.
157301
158-
See [CONTRIBUTING] for more information on how to get started.
302+
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.
159303
160304
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.
161305
@@ -166,7 +310,7 @@ Apache 2.0 - See [LICENSE] for more information.
166310
167311
168312
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
169-
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md
313+
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
170314
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
171315
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md
172316
[cloud-platform]: https://cloud.google.com/
@@ -183,3 +327,10 @@ Apache 2.0 - See [LICENSE] for more information.
183327
[cloud-storage-create-bucket]: https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets
184328
[cloud-storage-activation]: https://cloud.google.com/storage/docs/signup
185329
[storage-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/storage/package-summary.html
330+
331+
[resourcemanager-api]:http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/resourcemanager/package-summary.html
332+
[cloud-resourcemanager-docs]:https://cloud.google.com/resource-manager/
333+
334+
[cloud-bigquery]: https://cloud.google.com/bigquery/
335+
[cloud-bigquery-docs]: https://cloud.google.com/bigquery/docs/overview
336+
[bigquery-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/bigquery/package-summary.html

0 commit comments

Comments
 (0)