From 6b9e941a17916c68ad9c99246398b320a503438a Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 16 Dec 2015 09:44:58 -0800 Subject: [PATCH] Fix docs and return null if project not found by get. --- README.md | 7 ++-- TESTING.md | 4 +-- gcloud-java-resourcemanager/README.md | 18 ++++------ .../resourcemanager/ResourceManager.java | 30 ++++++++-------- .../resourcemanager/ResourceManagerImpl.java | 36 ++++++++++--------- .../ResourceManagerOptions.java | 4 +-- .../gcloud/spi/DefaultResourceManagerRpc.java | 7 +++- .../LocalResourceManagerHelperTest.java | 16 ++------- .../ResourceManagerImplTest.java | 35 ++++++++++-------- 9 files changed, 76 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index f8c04e2ffc57..abb241c3aa1b 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,6 @@ Google Cloud Resource Manager 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). ```java -import com.google.common.collect.ImmutableMap; import com.google.gcloud.resourcemanager.ProjectInfo; import com.google.gcloud.resourcemanager.ResourceManager; import com.google.gcloud.resourcemanager.ResourceManagerOptions; @@ -203,10 +202,10 @@ import java.util.Iterator; ResourceManager resourceManager = ResourceManagerOptions.defaultInstance().service(); ProjectInfo myProject = resourceManager.get("some-project-id-that-I-own"); -ProjectInfo newProjectInfo = resourceManager.replace(projectFromServer.toBuilder() - .labels(ImmutableMap.of("launch-status", "in-development")).build()); +ProjectInfo newProjectInfo = resourceManager.replace(myProject.toBuilder() + .addLabel("launch-status", "in-development").build()); System.out.println("Updated the labels of project " + newProjectInfo.projectId() - + " to be " + newProjectInfo.labels() + System.lineSeparator()); + + " to be " + newProjectInfo.labels()); // List all the projects you have permission to view. Iterator projectIterator = resourceManager.list().iterateAll(); System.out.println("Projects I can view:"); diff --git a/TESTING.md b/TESTING.md index d6edd000e6d6..7f513a023621 100644 --- a/TESTING.md +++ b/TESTING.md @@ -82,7 +82,7 @@ You can test against a temporary local Resource Manager by following these steps This will spawn a server thread that listens to `localhost` at an ephemeral port for Resource Manager requests. -2. In your program, create and use a Resource Manager service object whose host is set host to `localhost` at the appropriate port. For example: +2. In your program, create and use a Resource Manager service object whose host is set to `localhost` at the appropriate port. For example: ```java ResourceManager resourceManager = ResourceManagerOptions.builder() @@ -97,7 +97,7 @@ You can test against a temporary local Resource Manager by following these steps helper.stop(); ``` - This method will block a short amount of time until the server thread has been terminated. + This method will block until the server thread has been terminated. #### On a remote machine diff --git a/gcloud-java-resourcemanager/README.md b/gcloud-java-resourcemanager/README.md index 2a229720536c..de7b660580e9 100644 --- a/gcloud-java-resourcemanager/README.md +++ b/gcloud-java-resourcemanager/README.md @@ -50,7 +50,7 @@ with the Cloud Resource Manager using this client Library. Getting Started --------------- #### Prerequisites -You will also need to set up the local development environment by [installing the Google Cloud SDK](https://cloud.google.com/sdk/) and running the following commands in command line: `gcloud auth login`. +You will need to set up the local development environment by [installing the Google Cloud SDK](https://cloud.google.com/sdk/) and running the following command in command line: `gcloud auth login`. > Note: You don't need a project ID to use this service. If you have a project ID set in the Google Cloud SDK, you can unset it by typing `gcloud config unset project` in command line. @@ -68,7 +68,7 @@ ResourceManager resourceManager = ResourceManagerOptions.defaultInstance().servi ``` #### Creating a project -All you need to create a project is a globally unique project ID. You can also optionally attach a non-unique name and labels to your project. Read more about naming guidelines for project IDs, names, and labels [here](https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects). To create a project, add the following imports at the top of your file: +All you need to create a project is a globally unique project ID. You can also optionally attach a non-unique name and labels to your project. Read more about naming guidelines for project IDs, names, and labels [here](https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects). To create a project, add the following import at the top of your file: ```java import com.google.gcloud.resourcemanager.ProjectInfo; @@ -84,7 +84,7 @@ ProjectInfo myProject = resourceManager.create(ProjectInfo.builder(myProjectId). Note that the return value from `create` is a `ProjectInfo` that includes additional read-only information, like creation time, project number, and lifecycle state. Read more about these fields on the [Projects page](https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects). #### Getting a specific project -You can load a project if you know it's project ID and have read permissions to the project. For example, say we wanted to get the project we just created. We can do the following: +You can load a project if you know it's project ID and have read permissions to the project. For example, to get the project we just created we can do the following: ```java ProjectInfo projectFromServer = resourceManager.get(myProjectId); @@ -93,23 +93,17 @@ ProjectInfo projectFromServer = resourceManager.get(myProjectId); #### Editing a project To edit a project, create a new `ProjectInfo` object and pass it in to the `ResourceManager.replace` method. -Suppose that you want to add a label for the newly created project to denote that it's launch status is "in development". Import the following: - -```java -import com.google.common.collect.ImmutableMap; -``` - -Then add the following code to your program: +For example, to add a label for the newly created project to denote that it's launch status is "in development", add the following code: ```java ProjectInfo newProjectInfo = resourceManager.replace(projectFromServer.toBuilder() - .labels(ImmutableMap.of("launch-status", "in-development")).build()); + .addLabel("launch-status", "in-development").build()); ``` Note that the values of the project you pass in to `replace` overwrite the server's values for non-read-only fields, namely `projectName` and `labels`. For example, if you create a project with `projectName` "some-project-name" and subsequently call replace using a `ProjectInfo` object that didn't set the `projectName`, then the server will unset the project's name. The server ignores any attempted changes to the read-only fields `projectNumber`, `lifecycleState`, and `createTime`. The `projectId` cannot change. #### Listing all projects -Suppose that we want list of all projects for which we have read permissions. Add the following import: +Suppose that we want a list of all projects for which we have read permissions. Add the following import: ```java import java.util.Iterator; diff --git a/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/ResourceManager.java b/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/ResourceManager.java index 1562fe51dad1..9ae524e28017 100644 --- a/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/ResourceManager.java +++ b/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/ResourceManager.java @@ -36,7 +36,7 @@ public interface ResourceManager extends Service { /** * The fields of a project. * - * These values can be used to specify the fields to include in a partial response when calling + *

These values can be used to specify the fields to include in a partial response when calling * {@link ResourceManager#get} or {@link ResourceManager#list}. Project ID is always returned, * even if not specified. */ @@ -82,7 +82,7 @@ private ProjectGetOption(ResourceManagerRpc.Option option, Object value) { /** * Returns an option to specify the project's fields to be returned by the RPC call. * - * If this option is not provided all project fields are returned. + *

If this option is not provided all project fields are returned. * {@code ProjectGetOption.fields} can be used to specify only the fields of interest. Project * ID is always returned, even if not specified. {@link ProjectField} provides a list of fields * that can be used. @@ -106,17 +106,17 @@ private ProjectListOption(ResourceManagerRpc.Option option, Object value) { /** * Returns an option to specify a filter. * - * Filter rules are case insensitive. The fields eligible for filtering are: + *

Filter rules are case insensitive. The fields eligible for filtering are: *

    *
  • name *
  • project ID *
  • labels.key, where key is the name of a label *
* - * You can specify multiple filters by adding a space between each filter. Multiple filters + *

You can specify multiple filters by adding a space between each filter. Multiple filters * are composed using "and". * - * Some examples of filters: + *

Some examples of filters: *