Skip to content

Commit d163bfb

Browse files
committed
Merge pull request #707 from mderka/merge-master
Merge master
2 parents 030e819 + 5858809 commit d163bfb

164 files changed

Lines changed: 11016 additions & 6032 deletions

File tree

Some content is hidden

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

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ When changes are made to authentication and project ID-related code, authenticat
3232

3333
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.
3434

35+
**Please, do not use your production projects for executing integration tests.** While we do our best to make our tests independent of your project's state and content, they do perform create, modify and deletes, and you do not want to have your production data accidentally modified.
36+
3537
Adding Features
3638
---------------
3739
In order to add a feature to gcloud-java:

README.md

Lines changed: 98 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services.
66
[![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-java)
77
[![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master)
88
[![Maven](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java.svg)]( https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java.svg)
9+
[![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/gcloud-java)
10+
[![Dependency Status](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969)
911

1012
- [Homepage] (https://googlecloudplatform.github.io/gcloud-java/)
1113
- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs)
@@ -27,33 +29,33 @@ If you are using Maven, add this to your pom.xml file
2729
<dependency>
2830
<groupId>com.google.gcloud</groupId>
2931
<artifactId>gcloud-java</artifactId>
30-
<version>0.1.2</version>
32+
<version>0.1.4</version>
3133
</dependency>
3234
```
3335
If you are using Gradle, add this to your dependencies
3436
```Groovy
35-
compile 'com.google.gcloud:gcloud-java:0.1.2'
37+
compile 'com.google.gcloud:gcloud-java:0.1.4'
3638
```
3739
If you are using SBT, add this to your dependencies
3840
```Scala
39-
libraryDependencies += "com.google.gcloud" % "gcloud-java" % "0.1.2"
41+
libraryDependencies += "com.google.gcloud" % "gcloud-java" % "0.1.4"
4042
```
4143

4244
Example Applications
4345
--------------------
4446

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

5860
Specifying a Project ID
5961
-----------------------
@@ -123,38 +125,39 @@ Google Cloud BigQuery (Alpha)
123125
124126
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you
125127
must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
128+
Complete source code can be found at
129+
[CreateTableAndLoadData.java](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/bigquery/snippets/CreateTableAndLoadData.java).
126130
127131
```java
128-
import com.google.gcloud.bigquery.BaseTableInfo;
129132
import com.google.gcloud.bigquery.BigQuery;
130133
import com.google.gcloud.bigquery.BigQueryOptions;
131134
import com.google.gcloud.bigquery.Field;
132-
import com.google.gcloud.bigquery.JobStatus;
133-
import com.google.gcloud.bigquery.LoadJobInfo;
135+
import com.google.gcloud.bigquery.FormatOptions;
136+
import com.google.gcloud.bigquery.Job;
134137
import com.google.gcloud.bigquery.Schema;
138+
import com.google.gcloud.bigquery.StandardTableDefinition;
139+
import com.google.gcloud.bigquery.Table;
135140
import com.google.gcloud.bigquery.TableId;
136141
import com.google.gcloud.bigquery.TableInfo;
137142
138143
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
139144
TableId tableId = TableId.of("dataset", "table");
140-
BaseTableInfo info = bigquery.getTable(tableId);
141-
if (info == null) {
145+
Table table = bigquery.getTable(tableId);
146+
if (table == null) {
142147
System.out.println("Creating table " + tableId);
143148
Field integerField = Field.of("fieldName", Field.Type.integer());
144-
bigquery.create(TableInfo.of(tableId, Schema.of(integerField)));
149+
Schema schema = Schema.of(integerField);
150+
table = bigquery.create(TableInfo.of(tableId, StandardTableDefinition.of(schema)));
151+
}
152+
System.out.println("Loading data into table " + tableId);
153+
Job loadJob = table.load(FormatOptions.csv(), "gs://bucket/path");
154+
while (!loadJob.isDone()) {
155+
Thread.sleep(1000L);
156+
}
157+
if (loadJob.status().error() != null) {
158+
System.out.println("Job completed with errors");
145159
} 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-
}
160+
System.out.println("Job succeeded");
158161
}
159162
```
160163
@@ -168,8 +171,32 @@ Google Cloud Datastore
168171
169172
#### Preview
170173
171-
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
174+
Here are two code snippets showing simple usage examples from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
175+
176+
The first snippet shows how to create a Datastore entity. Complete source code can be found at
177+
[CreateEntity.java](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/datastore/snippets/CreateEntity.java).
178+
179+
```java
180+
import com.google.gcloud.datastore.Datastore;
181+
import com.google.gcloud.datastore.DatastoreOptions;
182+
import com.google.gcloud.datastore.DateTime;
183+
import com.google.gcloud.datastore.Entity;
184+
import com.google.gcloud.datastore.Key;
185+
import com.google.gcloud.datastore.KeyFactory;
172186
187+
Datastore datastore = DatastoreOptions.defaultInstance().service();
188+
KeyFactory keyFactory = datastore.newKeyFactory().kind("keyKind");
189+
Key key = keyFactory.newKey("keyName");
190+
Entity entity = Entity.builder(key)
191+
.set("name", "John Doe")
192+
.set("age", 30)
193+
.set("access_time", DateTime.now())
194+
.build();
195+
datastore.put(entity);
196+
```
197+
The second snippet shows how to update a Datastore entity if it exists. Complete source code can be
198+
found at
199+
[UpdateEntity.java](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/datastore/snippets/UpdateEntity.java).
173200
```java
174201
import com.google.gcloud.datastore.Datastore;
175202
import com.google.gcloud.datastore.DatastoreOptions;
@@ -179,17 +206,10 @@ import com.google.gcloud.datastore.Key;
179206
import com.google.gcloud.datastore.KeyFactory;
180207
181208
Datastore datastore = DatastoreOptions.defaultInstance().service();
182-
KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND);
183-
Key key = keyFactory.newKey(keyName);
209+
KeyFactory keyFactory = datastore.newKeyFactory().kind("keyKind");
210+
Key key = keyFactory.newKey("keyName");
184211
Entity entity = datastore.get(key);
185-
if (entity == null) {
186-
entity = Entity.builder(key)
187-
.set("name", "John Do")
188-
.set("age", 30)
189-
.set("access_time", DateTime.now())
190-
.build();
191-
datastore.put(entity);
192-
} else {
212+
if (entity != null) {
193213
System.out.println("Updating access_time for " + entity.getString("name"));
194214
entity = Entity.builder(entity)
195215
.set("access_time", DateTime.now())
@@ -207,22 +227,26 @@ Google Cloud Resource Manager (Alpha)
207227
#### Preview
208228
209229
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-
230+
Complete source code can be found at
231+
[UpdateAndListProjects.java](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/resourcemanager/snippets/UpdateAndListProjects.java).
211232
```java
212-
import com.google.gcloud.resourcemanager.ProjectInfo;
233+
import com.google.gcloud.resourcemanager.Project;
213234
import com.google.gcloud.resourcemanager.ResourceManager;
214235
import com.google.gcloud.resourcemanager.ResourceManagerOptions;
215236
216237
import java.util.Iterator;
217238
218239
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();
240+
Project project = resourceManager.get("some-project-id"); // Use an existing project's ID
241+
if (project != null) {
242+
Project newProject = project.toBuilder()
243+
.addLabel("launch-status", "in-development")
244+
.build()
245+
.replace();
246+
System.out.println("Updated the labels of project " + newProject.projectId()
247+
+ " to be " + newProject.labels());
248+
}
249+
Iterator<Project> projectIterator = resourceManager.list().iterateAll();
226250
System.out.println("Projects I can view:");
227251
while (projectIterator.hasNext()) {
228252
System.out.println(projectIterator.next().projectId());
@@ -239,8 +263,28 @@ Google Cloud Storage
239263
240264
#### Preview
241265
242-
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
266+
Here are two code snippets showing simple usage examples from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
267+
268+
The first snippet shows how to create a Storage blob. Complete source code can be found at
269+
[CreateBlob.java](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/storage/snippets/CreateBlob.java).
270+
271+
```java
272+
import static java.nio.charset.StandardCharsets.UTF_8;
273+
274+
import com.google.gcloud.storage.Blob;
275+
import com.google.gcloud.storage.BlobId;
276+
import com.google.gcloud.storage.BlobInfo;
277+
import com.google.gcloud.storage.Storage;
278+
import com.google.gcloud.storage.StorageOptions;
243279
280+
Storage storage = StorageOptions.defaultInstance().service();
281+
BlobId blobId = BlobId.of("bucket", "blob_name");
282+
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
283+
Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
284+
```
285+
The second snippet shows how to update a Storage blob if it exists. Complete source code can be
286+
found at
287+
[UpdateBlob.java](./gcloud-java-examples/src/main/java/com/google/gcloud/examples/storage/snippets/UpdateBlob.java).
244288
```java
245289
import static java.nio.charset.StandardCharsets.UTF_8;
246290
@@ -254,12 +298,8 @@ import java.nio.channels.WritableByteChannel;
254298
255299
Storage storage = StorageOptions.defaultInstance().service();
256300
BlobId blobId = BlobId.of("bucket", "blob_name");
257-
Blob blob = Blob.get(storage, blobId);
258-
if (blob == null) {
259-
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
260-
storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
261-
} else {
262-
System.out.println("Updating content for " + blobId.name());
301+
Blob blob = storage.get(blobId);
302+
if (blob != null) {
263303
byte[] prevContent = blob.content();
264304
System.out.println(new String(prevContent, UTF_8));
265305
WritableByteChannel channel = blob.writer();

RELEASING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ As mentioned before, there is an optional version argument. By default, the scr
2626

2727
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).
2828

29+
7. Be sure to update App Engine documentation and [java-docs-samples](https://github.com/GoogleCloudPlatform/java-docs-samples) code as necessary. See directions [here](https://docs.google.com/a/google.com/document/d/1SS3xNn2v0qW7EadGUPBUAPIQAH5VY6WSFmT17ZjjUVE/edit?usp=sharing).
30+
2931
### To push a snapshot version
3032

3133
Pushing a snapshot is completely automated. If "-SNAPSHOT" is included in the version denoted by the base directory's pom.xml, then an updated artifact will be pushed to the snapshot repository when Travis CI successfully completes a non-PR build.

codacy-conf.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)