Skip to content

Commit 396bcc0

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 6639 b: refs/heads/tswast-patch-1 c: a3bbbd2 h: refs/heads/master i: 6637: 5bfd9ae 6635: 1e247e8 6631: 10daa51 6623: 9be25d3
1 parent 3561a43 commit 396bcc0

10 files changed

Lines changed: 62 additions & 56 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 8c12d6797ca95c641e7e59a3dc1a5c1b259a0b80
60+
refs/heads/tswast-patch-1: a3bbbd2c8aa2cc37f48be0c8904286b8ea0be1e6
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ import com.google.gcloud.resourcemanager.ResourceManagerOptions;
201201
import java.util.Iterator;
202202
203203
ResourceManager resourceManager = ResourceManagerOptions.defaultInstance().service();
204-
ProjectInfo myProject = resourceManager.get("some-project-id-that-I-own");
204+
ProjectInfo myProject = resourceManager.get("some-project-id"); // Use an existing project's ID
205205
ProjectInfo newProjectInfo = resourceManager.replace(myProject.toBuilder()
206206
.addLabel("launch-status", "in-development").build());
207207
System.out.println("Updated the labels of project " + newProjectInfo.projectId()

branches/tswast-patch-1/TESTING.md

Lines changed: 6 additions & 15 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

@@ -85,8 +89,7 @@ You can test against a temporary local Resource Manager by following these steps
8589
2. In your program, create and use a Resource Manager service object whose host is set to `localhost` at the appropriate port. For example:
8690

8791
```java
88-
ResourceManager resourceManager = ResourceManagerOptions.builder()
89-
.host("http://localhost:" + helper.port()).build().service();
92+
ResourceManager resourceManager = LocalResourceManagerHelper.options().service();
9093
```
9194

9295
3. Run your tests.
@@ -99,17 +102,5 @@ You can test against a temporary local Resource Manager by following these steps
99102

100103
This method will block until the server thread has been terminated.
101104

102-
#### On a remote machine
103-
104-
You can test against a remote Resource Manager emulator as well. To do this, set the host to the hostname of the remote machine, like the example below.
105-
106-
```java
107-
ResourceManager resourceManager = ResourceManagerOptions.builder()
108-
.host("http://<hostname of machine>:<port>").build();
109-
```
110-
111-
Note that the remote Resource Manager emulator must be running before your tests are run.
112-
113-
114105

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

branches/tswast-patch-1/gcloud-java-resourcemanager/README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,22 @@ Java idiomatic client for [Google Cloud Resource Manager] (https://cloud.google.
1717
1818
Quickstart
1919
----------
20-
This library is currently under development and will be available soon!
21-
<!--TODO(ajaykannan): add in pom.xml snippet once gcloud-java-resourcemanager becomes available on maven -->
20+
If you are using Maven, add this to your pom.xml file
21+
```xml
22+
<dependency>
23+
<groupId>com.google.gcloud</groupId>
24+
<artifactId>gcloud-java-resourcemanager</artifactId>
25+
<version>0.1.0</version>
26+
</dependency>
27+
```
28+
If you are using Gradle, add this to your dependencies
29+
```Groovy
30+
compile 'com.google.gcloud:gcloud-java-resourcemanager:jar:0.1.0'
31+
```
32+
If you are using SBT, add this to your dependencies
33+
```Scala
34+
libraryDependencies += "com.google.gcloud" % "gcloud-java-resourcemanager" % "0.1.0"
35+
```
2236

2337
<!-- TODO(ajaykannan): once the API becomes usable, make an example application
2438
Example Application
@@ -38,7 +52,7 @@ Google [Cloud Resource Manager][cloud-resourcemanager] provides a programmatic w
3852
* Create new projects.
3953
* Update existing projects.
4054
* Delete projects.
41-
* Undelete, or recover, projects that you don't want to delete.
55+
* Undelete projects that you don't want to delete.
4256

4357
Google Cloud Resource Manager is currently in beta and may occasionally make backwards incompatible changes.
4458

@@ -74,7 +88,7 @@ All you need to create a project is a globally unique project ID. You can also
7488
import com.google.gcloud.resourcemanager.ProjectInfo;
7589
```
7690

77-
Then add the following code to create a project (be sure to change `myProjectId` to be something unique).
91+
Then add the following code to create a project (be sure to change `myProjectId` to your own unique project ID).
7892

7993
```java
8094
String myProjectId = "my-globally-unique-project-id"; // Change to a unique project ID.
@@ -121,7 +135,7 @@ while (projectIterator.hasNext()) {
121135

122136
#### Complete source code
123137

124-
Here we put together all the code shown above into one program. This program assumes that you are running from your own desktop.
138+
Here we put together all the code shown above into one program. This program assumes that you are running from your own desktop and used the Google Cloud SDK to authenticate yourself.
125139

126140
```java
127141
import com.google.gcloud.resourcemanager.ProjectInfo;

branches/tswast-patch-1/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/ProjectInfo.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public class ProjectInfo implements Serializable {
5050
*/
5151
public enum State {
5252
/**
53-
* Only used/useful for distinguishing unset values
53+
* Only used/useful for distinguishing unset values.
5454
*/
5555
LIFECYCLE_STATE_UNSPECIFIED,
5656

5757
/**
58-
* The normal and active state
58+
* The normal and active state.
5959
*/
6060
ACTIVE,
6161

@@ -66,7 +66,7 @@ public enum State {
6666
DELETE_REQUESTED,
6767

6868
/**
69-
* the process of deleting the project has begun. Reversing the deletion is no longer possible.
69+
* The process of deleting the project has begun. Reversing the deletion is no longer possible.
7070
*/
7171
DELETE_IN_PROGRESS
7272
}
@@ -105,7 +105,7 @@ com.google.api.services.cloudresourcemanager.model.ResourceId toPb() {
105105
com.google.api.services.cloudresourcemanager.model.ResourceId resourceIdPb =
106106
new com.google.api.services.cloudresourcemanager.model.ResourceId();
107107
resourceIdPb.setId(id);
108-
resourceIdPb.setType(type.toString().toLowerCase());
108+
resourceIdPb.setType(type.toLowerCase());
109109
return resourceIdPb;
110110
}
111111

@@ -141,9 +141,9 @@ private Builder() {
141141
/**
142142
* Set the user-assigned name of the project.
143143
*
144-
* This field is optional and can remain unset. Allowed characters are: lowercase and uppercase
145-
* letters, numbers, hyphen, single-quote, double-quote, space, and exclamation point. This
146-
* field can be changed after project creation.
144+
* <p>This field is optional and can remain unset. Allowed characters are: lowercase and
145+
* uppercase letters, numbers, hyphen, single-quote, double-quote, space, and exclamation point.
146+
* This field can be changed after project creation.
147147
*/
148148
public Builder name(String name) {
149149
this.name = firstNonNull(name, Data.<String>nullOf(String.class));
@@ -153,7 +153,7 @@ public Builder name(String name) {
153153
/**
154154
* Set the unique, user-assigned ID of the project.
155155
*
156-
* The ID must be 6 to 30 lowercase letters, digits, or hyphens. It must start with a letter.
156+
* <p>The ID must be 6 to 30 lowercase letters, digits, or hyphens. It must start with a letter.
157157
* Trailing hyphens are prohibited. This field cannot be changed after the server creates the
158158
* project.
159159
*/
@@ -165,7 +165,7 @@ public Builder projectId(String projectId) {
165165
/**
166166
* Add a label associated with this project.
167167
*
168-
* See {@link #labels} for label restrictions.
168+
* <p>See {@link #labels} for label restrictions.
169169
*/
170170
public Builder addLabel(String key, String value) {
171171
this.labels.put(key, value);
@@ -191,11 +191,11 @@ public Builder clearLabels() {
191191
/**
192192
* Set the labels associated with this project.
193193
*
194-
* Label keys must be between 1 and 63 characters long and must conform to the following regular
195-
* expression: [a-z]([-a-z0-9]*[a-z0-9])?. Label values must be between 0 and 63 characters long
196-
* and must conform to the regular expression ([a-z]([-a-z0-9]*[a-z0-9])?)?. No more than 256
197-
* labels can be associated with a given resource. This field can be changed after project
198-
* creation.
194+
* <p>Label keys must be between 1 and 63 characters long and must conform to the following
195+
* regular expression: [a-z]([-a-z0-9]*[a-z0-9])?. Label values must be between 0 and 63
196+
* characters long and must conform to the regular expression ([a-z]([-a-z0-9]*[a-z0-9])?)?. No
197+
* more than 256 labels can be associated with a given resource. This field can be changed after
198+
* project creation.
199199
*/
200200
public Builder labels(Map<String, String> labels) {
201201
this.labels = Maps.newHashMap(checkNotNull(labels));
@@ -240,7 +240,7 @@ public ProjectInfo build() {
240240
/**
241241
* Get the unique, user-assigned ID of the project.
242242
*
243-
* This field cannot be changed after the server creates the project.
243+
* <p>This field cannot be changed after the server creates the project.
244244
*/
245245
public String projectId() {
246246
return projectId;
@@ -249,7 +249,7 @@ public String projectId() {
249249
/**
250250
* Get the user-assigned name of the project.
251251
*
252-
* This field is optional, can remain unset, and can be changed after project creation.
252+
* <p>This field is optional, can remain unset, and can be changed after project creation.
253253
*/
254254
public String name() {
255255
return Data.isNull(name) ? null : name;
@@ -258,7 +258,7 @@ public String name() {
258258
/**
259259
* Get number uniquely identifying the project.
260260
*
261-
* This field is set by the server and is read-only.
261+
* <p>This field is set by the server and is read-only.
262262
*/
263263
public Long projectNumber() {
264264
return projectNumber;
@@ -274,7 +274,7 @@ public Map<String, String> labels() {
274274
/**
275275
* Get the project's lifecycle state.
276276
*
277-
* This is a read-only field. To change the lifecycle state of your project, use the
277+
* <p>This is a read-only field. To change the lifecycle state of your project, use the
278278
* {@code delete} or {@code undelete} method.
279279
*/
280280
public State state() {
@@ -288,7 +288,7 @@ ResourceId parent() {
288288
/**
289289
* Get the project's creation time (in milliseconds).
290290
*
291-
* This field is set by the server and is read-only.
291+
* <p>This field is set by the server and is read-only.
292292
*/
293293
public Long createTimeMillis() {
294294
return createTimeMillis;
@@ -332,9 +332,8 @@ com.google.api.services.cloudresourcemanager.model.Project toPb() {
332332
}
333333

334334
static ProjectInfo fromPb(com.google.api.services.cloudresourcemanager.model.Project projectPb) {
335-
ProjectInfo.Builder builder =
336-
ProjectInfo.builder(projectPb.getProjectId()).projectNumber(projectPb.getProjectNumber());
337-
if (projectPb.getName() != null) {
335+
Builder builder = builder(projectPb.getProjectId()).projectNumber(projectPb.getProjectNumber());
336+
if (projectPb.getName() != null && !projectPb.getName().equals("Unnamed")) {
338337
builder.name(projectPb.getName());
339338
}
340339
if (projectPb.getLabels() != null) {

branches/tswast-patch-1/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/testing/LocalResourceManagerHelper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.google.common.collect.ImmutableMap;
1313
import com.google.common.collect.ImmutableSet;
1414
import com.google.common.io.ByteStreams;
15+
import com.google.gcloud.resourcemanager.ResourceManagerOptions;
1516

1617
import com.sun.net.httpserver.Headers;
1718
import com.sun.net.httpserver.HttpExchange;
@@ -524,10 +525,10 @@ public static LocalResourceManagerHelper create() {
524525
}
525526

526527
/**
527-
* Returns the port that the LocalResourceManagerHelper listens to for requests.
528+
* Returns a ResourceManagerOptions instance that sets the host to use the mock server.
528529
*/
529-
public int port() {
530-
return port;
530+
public ResourceManagerOptions options() {
531+
return ResourceManagerOptions.builder().host("http://localhost:" + port).build();
531532
}
532533

533534
/**

branches/tswast-patch-1/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/spi/DefaultResourceManagerRpc.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static com.google.gcloud.spi.ResourceManagerRpc.Option.FILTER;
55
import static com.google.gcloud.spi.ResourceManagerRpc.Option.PAGE_SIZE;
66
import static com.google.gcloud.spi.ResourceManagerRpc.Option.PAGE_TOKEN;
7+
import static java.net.HttpURLConnection.HTTP_FORBIDDEN;
78

89
import com.google.api.client.googleapis.json.GoogleJsonError;
910
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
@@ -81,7 +82,7 @@ public Project get(String projectId, Map<Option, ?> options) throws ResourceMana
8182
.execute();
8283
} catch (IOException ex) {
8384
ResourceManagerException translated = translate(ex);
84-
if (translated.code() == 403) {
85+
if (translated.code() == HTTP_FORBIDDEN) {
8586
return null; // Project not found
8687
} else {
8788
throw translated;

branches/tswast-patch-1/gcloud-java-resourcemanager/src/test/java/com/google/gcloud/resourcemanager/LocalResourceManagerHelperTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ public class LocalResourceManagerHelperTest {
3232
private static final Map<ResourceManagerRpc.Option, ?> EMPTY_RPC_OPTIONS = ImmutableMap.of();
3333
private static final LocalResourceManagerHelper RESOURCE_MANAGER_HELPER =
3434
LocalResourceManagerHelper.create();
35-
private static final ResourceManagerRpc rpc = new DefaultResourceManagerRpc(
36-
ResourceManagerOptions.builder()
37-
.host("http://localhost:" + RESOURCE_MANAGER_HELPER.port())
38-
.build());
35+
private static final ResourceManagerRpc rpc =
36+
new DefaultResourceManagerRpc(RESOURCE_MANAGER_HELPER.options());
3937
private static final com.google.api.services.cloudresourcemanager.model.Project PARTIAL_PROJECT =
4038
new com.google.api.services.cloudresourcemanager.model.Project().setProjectId(
4139
"partial-project");

branches/tswast-patch-1/gcloud-java-resourcemanager/src/test/java/com/google/gcloud/resourcemanager/ProjectInfoTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class ProjectInfoTest {
4545
.parent(PARENT)
4646
.build();
4747
private static final ProjectInfo PARTIAL_PROJECT_INFO = ProjectInfo.builder(PROJECT_ID).build();
48+
private static final ProjectInfo UNNAMED_PROJECT_FROM_LIST =
49+
PARTIAL_PROJECT_INFO.toBuilder().name("Unnamed").build();
4850

4951
@Test
5052
public void testBuilder() {
@@ -71,8 +73,10 @@ public void testToBuilder() {
7173

7274
@Test
7375
public void testToAndFromPb() {
76+
assertTrue(FULL_PROJECT_INFO.toPb().getCreateTime().endsWith("Z"));
7477
compareProjects(FULL_PROJECT_INFO, ProjectInfo.fromPb(FULL_PROJECT_INFO.toPb()));
7578
compareProjects(PARTIAL_PROJECT_INFO, ProjectInfo.fromPb(PARTIAL_PROJECT_INFO.toPb()));
79+
compareProjects(PARTIAL_PROJECT_INFO, ProjectInfo.fromPb(UNNAMED_PROJECT_FROM_LIST.toPb()));
7680
}
7781

7882
@Test

branches/tswast-patch-1/gcloud-java-resourcemanager/src/test/java/com/google/gcloud/resourcemanager/ResourceManagerImplTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ public class ResourceManagerImplTest {
4848

4949
private static final LocalResourceManagerHelper RESOURCE_MANAGER_HELPER =
5050
LocalResourceManagerHelper.create();
51-
private static final ResourceManager RESOURCE_MANAGER = ResourceManagerOptions.builder()
52-
.host("http://localhost:" + RESOURCE_MANAGER_HELPER.port())
53-
.build()
54-
.service();
51+
private static final ResourceManager RESOURCE_MANAGER =
52+
RESOURCE_MANAGER_HELPER.options().service();
5553
private static final ProjectGetOption GET_FIELDS =
5654
ProjectGetOption.fields(ProjectField.NAME, ProjectField.CREATE_TIME);
5755
private static final ProjectListOption LIST_FIELDS =

0 commit comments

Comments
 (0)