Skip to content

Commit b137cad

Browse files
authored
Merge pull request #1053 from mziccard/master-into-pubsub
Merge master branch into pubsub
2 parents 2fd2d56 + 3208eb3 commit b137cad

File tree

333 files changed

+46987
-2234
lines changed

Some content is hidden

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

333 files changed

+46987
-2234
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ before_install:
99
- cp target/travis/settings.xml ~/.m2/settings.xml
1010
install: mvn install -DskipTests=true -Dgpg.skip=true
1111
script:
12-
- utilities/verify.sh
12+
- travis_wait 30 utilities/verify.sh
1313
after_success:
1414
- utilities/after_success.sh
1515
env:

CONTRIBUTING.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ Contributing
22
============
33

44
1. **Please sign one of the contributor license agreements below.**
5-
1. Fork the repo, develop and test your code changes, add docs.
6-
1. Make sure that your commit messages clearly describe the changes.
7-
1. Send a pull request.
5+
2. Fork the repo, develop and test your code changes, add docs.
6+
3. Make sure that your commit messages clearly describe the changes.
7+
4. Send a pull request.
88

99

1010
Here are some guidelines for hacking on gcloud-java.
@@ -43,6 +43,9 @@ The feature must work fully on Java 7 and above.
4343
The feature must not add unnecessary dependencies (where "unnecessary" is of course subjective,
4444
but new dependencies should be discussed).
4545

46+
Adding Support for a New Service
47+
--------------------------------
48+
See [SUPPORTING_NEW_SERVICES](./SUPPORTING_NEW_SERVICES.md) for guidelines on how to add support for a new Google Cloud service to `gcloud-java`.
4649

4750
Coding Style
4851
------------

README.md

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services.
1515
This client supports the following Google Cloud Platform services:
1616

1717
- [Google Cloud BigQuery] (#google-cloud-bigquery-alpha) (Alpha)
18+
- [Google Cloud Compute] (#google-cloud-compute-alpha) (Alpha)
1819
- [Google Cloud Datastore] (#google-cloud-datastore)
1920
- [Google Cloud DNS] (#google-cloud-dns-alpha) (Alpha)
2021
- [Google Cloud Resource Manager] (#google-cloud-resource-manager-alpha) (Alpha)
@@ -33,23 +34,25 @@ If you are using Maven, add this to your pom.xml file
3334
<dependency>
3435
<groupId>com.google.cloud</groupId>
3536
<artifactId>gcloud-java</artifactId>
36-
<version>0.2.0</version>
37+
<version>0.2.3</version>
3738
</dependency>
3839
```
3940
If you are using Gradle, add this to your dependencies
4041
```Groovy
41-
compile 'com.google.cloud:gcloud-java:0.2.0'
42+
compile 'com.google.cloud:gcloud-java:0.2.3'
4243
```
4344
If you are using SBT, add this to your dependencies
4445
```Scala
45-
libraryDependencies += "com.google.cloud" % "gcloud-java" % "0.2.0"
46+
libraryDependencies += "com.google.cloud" % "gcloud-java" % "0.2.3"
4647
```
4748

4849
Example Applications
4950
--------------------
5051

5152
- [`BigQueryExample`](./gcloud-java-examples/src/main/java/com/google/cloud/examples/bigquery/BigQueryExample.java) - A simple command line interface providing some of Cloud BigQuery's functionality
5253
- Read more about using this application on the [`BigQueryExample` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/cloud/examples/bigquery/BigQueryExample.html).
54+
- [`ComputeExample`](./gcloud-java-examples/src/main/java/com/google/cloud/examples/compute/ComputeExample.java) - A simple command line interface providing some of Cloud Compute's functionality
55+
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/cloud/examples/compute/ComputeExample.html).
5356
- [`Bookshelf`](https://github.com/GoogleCloudPlatform/getting-started-java/tree/master/bookshelf) - An App Engine app that manages a virtual bookshelf.
5457
- This app uses `gcloud-java` to interface with Cloud Datastore and Cloud Storage. It also uses Cloud SQL, another Google Cloud Platform service.
5558
- [`DatastoreExample`](./gcloud-java-examples/src/main/java/com/google/cloud/examples/datastore/DatastoreExample.java) - A simple command line interface for Cloud Datastore
@@ -104,7 +107,7 @@ First, ensure that the necessary Google Cloud APIs are enabled for your project.
104107
Next, choose a method for authenticating API requests from within your project:
105108

106109
1. When using `gcloud-java` libraries from within Compute/App Engine, no additional authentication steps are necessary.
107-
2. When using `gcloud-java` libraries elsewhere, there are two options:
110+
2. When using `gcloud-java` libraries elsewhere, there are three options:
108111
* [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:
109112
* Define the environment variable GOOGLE_APPLICATION_CREDENTIALS to be the location of the key. For example:
110113
```bash
@@ -113,11 +116,18 @@ Next, choose a method for authenticating API requests from within your project:
113116
* 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:
114117
```java
115118
Storage storage = StorageOptions.builder()
116-
.authCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json"))
119+
.authCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json"))
120+
.build()
121+
.service();
122+
```
123+
* If running locally for development/testing, you can 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.
124+
* If you already have an OAuth2 access token, you can use it to authenticate (notice that in this case the access token will not be automatically refreshed):
125+
```java
126+
Storage storage = StorageOptions.builder()
127+
.authCredentials(AuthCredentials.createFor("your_access_token"))
117128
.build()
118129
.service();
119-
```
120-
* 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.
130+
```
121131
122132
`gcloud-java` looks for credentials in the following order, stopping once it finds credentials:
123133
@@ -163,16 +173,79 @@ if (table == null) {
163173
}
164174
System.out.println("Loading data into table " + tableId);
165175
Job loadJob = table.load(FormatOptions.csv(), "gs://bucket/path");
166-
while (!loadJob.isDone()) {
167-
Thread.sleep(1000L);
168-
}
176+
loadJob = loadJob.waitFor();
169177
if (loadJob.status().error() != null) {
170178
System.out.println("Job completed with errors");
171179
} else {
172180
System.out.println("Job succeeded");
173181
}
174182
```
175183
184+
Google Cloud Compute (Alpha)
185+
----------------------
186+
187+
- [API Documentation][compute-api]
188+
- [Official Documentation][cloud-compute-docs]
189+
190+
#### Preview
191+
192+
Here are two code snippets showing simple usage examples from within Compute/App Engine. Note that
193+
you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
194+
195+
The first snippet shows how to create a snapshot from an existing disk. Complete source code can be
196+
found at
197+
[CreateSnapshot.java](./gcloud-java-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateSnapshot.java).
198+
199+
```java
200+
import com.google.cloud.compute.Compute;
201+
import com.google.cloud.compute.ComputeOptions;
202+
import com.google.cloud.compute.Disk;
203+
import com.google.cloud.compute.DiskId;
204+
import com.google.cloud.compute.Snapshot;
205+
206+
Compute compute = ComputeOptions.defaultInstance().service();
207+
DiskId diskId = DiskId.of("us-central1-a", "disk-name");
208+
Disk disk = compute.getDisk(diskId, Compute.DiskOption.fields());
209+
if (disk != null) {
210+
String snapshotName = "disk-name-snapshot";
211+
Operation operation = disk.createSnapshot(snapshotName);
212+
operation = operation.waitFor();
213+
if (operation.errors() == null) {
214+
// use snapshot
215+
Snapshot snapshot = compute.getSnapshot(snapshotName);
216+
}
217+
}
218+
```
219+
The second snippet shows how to create a virtual machine instance. Complete source code can be found
220+
at
221+
[CreateInstance.java](./gcloud-java-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateInstance.java).
222+
```java
223+
import com.google.cloud.compute.AttachedDisk;
224+
import com.google.cloud.compute.Compute;
225+
import com.google.cloud.compute.ComputeOptions;
226+
import com.google.cloud.compute.ImageId;
227+
import com.google.cloud.compute.Instance;
228+
import com.google.cloud.compute.InstanceId;
229+
import com.google.cloud.compute.InstanceInfo;
230+
import com.google.cloud.compute.MachineTypeId;
231+
import com.google.cloud.compute.NetworkId;
232+
233+
Compute compute = ComputeOptions.defaultInstance().service();
234+
ImageId imageId = ImageId.of("debian-cloud", "debian-8-jessie-v20160329");
235+
NetworkId networkId = NetworkId.of("default");
236+
AttachedDisk attachedDisk = AttachedDisk.of(AttachedDisk.CreateDiskConfiguration.of(imageId));
237+
NetworkInterface networkInterface = NetworkInterface.of(networkId);
238+
InstanceId instanceId = InstanceId.of("us-central1-a", "instance-name");
239+
MachineTypeId machineTypeId = MachineTypeId.of("us-central1-a", "n1-standard-1");
240+
Operation operation =
241+
compute.create(InstanceInfo.of(instanceId, machineTypeId, attachedDisk, networkInterface));
242+
operation = operation.waitFor();
243+
if (operation.errors() == null) {
244+
// use instance
245+
Instance instance = compute.getInstance(instanceId);
246+
}
247+
```
248+
176249
Google Cloud Datastore
177250
----------------------
178251
@@ -455,3 +528,7 @@ Apache 2.0 - See [LICENSE] for more information.
455528
[cloud-bigquery]: https://cloud.google.com/bigquery/
456529
[cloud-bigquery-docs]: https://cloud.google.com/bigquery/docs/overview
457530
[bigquery-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/cloud/bigquery/package-summary.html
531+
532+
[cloud-compute]: https://cloud.google.com/compute/
533+
[cloud-compute-docs]: https://cloud.google.com/compute/docs/overview
534+
[compute-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/cloud/compute/package-summary.html

0 commit comments

Comments
 (0)