Skip to content

Commit d299e06

Browse files
committed
Merge branch 'master' into bigquery
2 parents 862905f + 9bcebd3 commit d299e06

64 files changed

Lines changed: 4122 additions & 236 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.

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This client supports the following Google Cloud Platform services:
1414

1515
- [Google Cloud Datastore] (#google-cloud-datastore)
1616
- [Google Cloud Storage] (#google-cloud-storage)
17+
- [Google Cloud Resource Manager] (#google-cloud-resource-manager)
1718

1819
> Note: This client is a work-in-progress, and may occasionally
1920
> make backwards-incompatible changes.
@@ -182,6 +183,37 @@ if (blob == null) {
182183
}
183184
```
184185
186+
Google Cloud Resource Manager
187+
----------------------
188+
189+
- [API Documentation][resourcemanager-api]
190+
- [Official Documentation][cloud-resourcemanager-docs]
191+
192+
#### Preview
193+
194+
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).
195+
196+
```java
197+
import com.google.gcloud.resourcemanager.ProjectInfo;
198+
import com.google.gcloud.resourcemanager.ResourceManager;
199+
import com.google.gcloud.resourcemanager.ResourceManagerOptions;
200+
201+
import java.util.Iterator;
202+
203+
ResourceManager resourceManager = ResourceManagerOptions.defaultInstance().service();
204+
ProjectInfo myProject = resourceManager.get("some-project-id"); // Use an existing project's ID
205+
ProjectInfo newProjectInfo = resourceManager.replace(myProject.toBuilder()
206+
.addLabel("launch-status", "in-development").build());
207+
System.out.println("Updated the labels of project " + newProjectInfo.projectId()
208+
+ " to be " + newProjectInfo.labels());
209+
// List all the projects you have permission to view.
210+
Iterator<ProjectInfo> projectIterator = resourceManager.list().iterateAll();
211+
System.out.println("Projects I can view:");
212+
while (projectIterator.hasNext()) {
213+
System.out.println(projectIterator.next().projectId());
214+
}
215+
```
216+
185217
Troubleshooting
186218
---------------
187219
@@ -241,3 +273,6 @@ Apache 2.0 - See [LICENSE] for more information.
241273
[cloud-storage-create-bucket]: https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets
242274
[cloud-storage-activation]: https://cloud.google.com/storage/docs/signup
243275
[storage-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/storage/package-summary.html
276+
277+
[resourcemanager-api]:http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/resourcemanager/package-summary.html
278+
[cloud-resourcemanager-docs]:https://cloud.google.com/resource-manager/

TESTING.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
## gcloud-java tools for testing
22

3-
This library provides tools to help write tests for code that uses gcloud-java services.
3+
This library provides tools to help write tests for code that uses the following gcloud-java services:
4+
5+
- [Datastore] (#testing-code-that-uses-datastore)
6+
- [Storage] (#testing-code-that-uses-storage)
7+
- [Resource Manager] (#testing-code-that-uses-resource-manager)
48

59
### Testing code that uses Datastore
610

@@ -51,7 +55,8 @@ Currently, there isn't an emulator for Google Cloud Storage, so an alternative i
5155
3. Create a `RemoteGcsHelper` object using your project ID and JSON key.
5256
Here is an example that uses the `RemoteGcsHelper` to create a bucket.
5357
```java
54-
RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/my/JSON/key.json");
58+
RemoteGcsHelper gcsHelper =
59+
RemoteGcsHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
5560
Storage storage = gcsHelper.options().service();
5661
String bucket = RemoteGcsHelper.generateBucketName();
5762
storage.create(BucketInfo.of(bucket));
@@ -65,5 +70,38 @@ Here is an example that clears the bucket created in Step 3 with a timeout of 5
6570
RemoteGcsHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
6671
```
6772

73+
### Testing code that uses Resource Manager
74+
75+
#### On your machine
76+
77+
You can test against a temporary local Resource Manager by following these steps:
78+
79+
1. Before running your testing code, start the Resource Manager emulator `LocalResourceManagerHelper`. This can be done as follows:
80+
81+
```java
82+
import com.google.gcloud.resourcemanager.testing.LocalResourceManagerHelper;
83+
84+
LocalResourceManagerHelper helper = LocalResourceManagerHelper.create();
85+
helper.start();
86+
```
87+
88+
This will spawn a server thread that listens to `localhost` at an ephemeral port for Resource Manager requests.
89+
90+
2. In your program, create and use a Resource Manager service object whose host is set to `localhost` at the appropriate port. For example:
91+
92+
```java
93+
ResourceManager resourceManager = LocalResourceManagerHelper.options().service();
94+
```
95+
96+
3. Run your tests.
97+
98+
4. Stop the Resource Manager emulator.
99+
100+
```java
101+
helper.stop();
102+
```
103+
104+
This method will block until the server thread has been terminated.
105+
68106

69107
[cloud-platform-storage-authentication]:https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseDatastoreBatchWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected DatastoreException newInvalidRequest(String msg, Object... params) {
199199
return DatastoreException.throwInvalidRequest(String.format(msg, params));
200200
}
201201

202-
protected DatastoreV1.Mutation.Builder toMutationPb() {
202+
DatastoreV1.Mutation.Builder toMutationPb() {
203203
DatastoreV1.Mutation.Builder mutationPb = DatastoreV1.Mutation.newBuilder();
204204
for (FullEntity<IncompleteKey> entity : toAddAutoId()) {
205205
mutationPb.addInsertAutoId(entity.toPb());

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseEntity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private B self() {
9090
}
9191

9292
@SuppressWarnings("unchecked")
93-
protected B fill(DatastoreV1.Entity entityPb) {
93+
B fill(DatastoreV1.Entity entityPb) {
9494
Map<String, Value<?>> copiedProperties = Maps.newHashMap();
9595
for (DatastoreV1.Property property : entityPb.getPropertyList()) {
9696
copiedProperties.put(property.getName(), Value.fromPb(property.getValue()));
@@ -375,7 +375,7 @@ ImmutableSortedMap<String, Value<?>> properties() {
375375
}
376376

377377
@Override
378-
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
378+
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
379379
Builder<?, ?> builder = emptyBuilder();
380380
builder.fill(DatastoreV1.Entity.parseFrom(bytesPb));
381381
return builder.build();
@@ -384,7 +384,7 @@ protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
384384
protected abstract Builder<?, ?> emptyBuilder();
385385

386386
@Override
387-
protected final DatastoreV1.Entity toPb() {
387+
final DatastoreV1.Entity toPb() {
388388
DatastoreV1.Entity.Builder entityPb = DatastoreV1.Entity.newBuilder();
389389
for (Map.Entry<String, Value<?>> entry : properties.entrySet()) {
390390
DatastoreV1.Property.Builder propertyPb = DatastoreV1.Property.newBuilder();

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public boolean equals(Object obj) {
172172
}
173173

174174
@Override
175-
protected DatastoreV1.Key toPb() {
175+
DatastoreV1.Key toPb() {
176176
DatastoreV1.Key.Builder keyPb = DatastoreV1.Key.newBuilder();
177177
DatastoreV1.PartitionId.Builder partitionIdPb = DatastoreV1.PartitionId.newBuilder();
178178
if (projectId != null) {

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Blob.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ public static Blob copyFrom(InputStream input) throws IOException {
147147
}
148148

149149
@Override
150-
protected Value toPb() {
150+
Value toPb() {
151151
return DatastoreV1.Value.newBuilder().setBlobValue(byteString).build();
152152
}
153153

154154
@Override
155-
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
155+
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
156156
return new Blob(DatastoreV1.Value.parseFrom(bytesPb).getBlobValue());
157157
}
158158
}

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Cursor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ public static Cursor copyFrom(byte[] bytes) {
102102
}
103103

104104
@Override
105-
protected Value toPb() {
105+
Value toPb() {
106106
return DatastoreV1.Value.newBuilder().setBlobValue(byteString).build();
107107
}
108108

109109
@Override
110-
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
110+
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
111111
return fromPb(DatastoreV1.Value.parseFrom(bytesPb));
112112
}
113113

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DateTime.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ public static DateTime copyFrom(Calendar calendar) {
9898
}
9999

100100
@Override
101-
protected Value toPb() {
101+
Value toPb() {
102102
return DatastoreV1.Value.newBuilder().setIntegerValue(timestampMicroseconds).build();
103103
}
104104

105105
@Override
106-
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
106+
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
107107
return new DateTime(DatastoreV1.Value.parseFrom(bytesPb).getIntegerValue());
108108
}
109109
}

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public boolean equals(Object obj) {
126126
}
127127

128128
@Override
129-
protected DatastoreV1.GqlQueryArg toPb() {
129+
DatastoreV1.GqlQueryArg toPb() {
130130
DatastoreV1.GqlQueryArg.Builder argPb = DatastoreV1.GqlQueryArg.newBuilder();
131131
if (name != null) {
132132
argPb.setName(name);
@@ -141,7 +141,7 @@ protected DatastoreV1.GqlQueryArg toPb() {
141141
}
142142

143143
@Override
144-
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
144+
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
145145
return fromPb(DatastoreV1.GqlQueryArg.parseFrom(bytesPb));
146146
}
147147

@@ -370,7 +370,7 @@ public boolean equals(Object obj) {
370370
}
371371

372372
@Override
373-
protected DatastoreV1.GqlQuery toPb() {
373+
DatastoreV1.GqlQuery toPb() {
374374
DatastoreV1.GqlQuery.Builder queryPb = DatastoreV1.GqlQuery.newBuilder();
375375
queryPb.setQueryString(queryString);
376376
queryPb.setAllowLiteral(allowLiteral);
@@ -384,18 +384,18 @@ protected DatastoreV1.GqlQuery toPb() {
384384
}
385385

386386
@Override
387-
protected void populatePb(DatastoreV1.RunQueryRequest.Builder requestPb) {
387+
void populatePb(DatastoreV1.RunQueryRequest.Builder requestPb) {
388388
requestPb.setGqlQuery(toPb());
389389
}
390390

391391
@Override
392-
protected GqlQuery<V> nextQuery(DatastoreV1.QueryResultBatch responsePb) {
392+
GqlQuery<V> nextQuery(DatastoreV1.QueryResultBatch responsePb) {
393393
// See issue #17
394394
throw new UnsupportedOperationException("paging for this query is not implemented yet");
395395
}
396396

397397
@Override
398-
protected Object fromPb(ResultType<V> resultType, String namespace, byte[] bytesPb)
398+
Object fromPb(ResultType<V> resultType, String namespace, byte[] bytesPb)
399399
throws InvalidProtocolBufferException {
400400
return fromPb(resultType, namespace, DatastoreV1.GqlQuery.parseFrom(bytesPb));
401401
}

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/IncompleteKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public IncompleteKey build() {
5454
}
5555

5656
@Override
57-
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
57+
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
5858
return fromPb(DatastoreV1.Key.parseFrom(bytesPb));
5959
}
6060

0 commit comments

Comments
 (0)