Skip to content

Commit 07ae574

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 1447 b: refs/heads/master c: d800d1f h: refs/heads/master i: 1445: ff7fb96 1443: f6ff939 1439: d62c6be
1 parent 730fea2 commit 07ae574

7 files changed

Lines changed: 175 additions & 85 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ebcac0b12c00bfb26e12ff87bb1f0ec722301728
2+
refs/heads/master: d800d1fffb7745b46d8cad931f2eaa3bc45c9173
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: d1b373c30c176edc08692348167bec3a244bb823
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.resourcemanager;
18+
19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
21+
import com.google.common.base.MoreObjects;
22+
import com.google.gcloud.spi.ResourceManagerRpc;
23+
24+
import java.io.Serializable;
25+
import java.util.Objects;
26+
27+
/**
28+
* Base class for Resource Manager operation options
29+
*/
30+
public class Option implements Serializable {
31+
32+
private static final long serialVersionUID = 2655177550880762967L;
33+
34+
private final ResourceManagerRpc.Option rpcOption;
35+
private final Object value;
36+
37+
Option(ResourceManagerRpc.Option rpcOption, Object value) {
38+
this.rpcOption = checkNotNull(rpcOption);
39+
this.value = value;
40+
}
41+
42+
ResourceManagerRpc.Option rpcOption() {
43+
return rpcOption;
44+
}
45+
46+
Object value() {
47+
return value;
48+
}
49+
50+
@Override
51+
public boolean equals(Object obj) {
52+
if (!(obj instanceof Option)) {
53+
return false;
54+
}
55+
Option other = (Option) obj;
56+
return Objects.equals(rpcOption, other.rpcOption)
57+
&& Objects.equals(value, other.value);
58+
}
59+
60+
@Override
61+
public int hashCode() {
62+
return Objects.hash(rpcOption, value);
63+
}
64+
65+
@Override
66+
public String toString() {
67+
return MoreObjects.toStringHelper(this)
68+
.add("name", rpcOption.value())
69+
.add("value", value)
70+
.toString();
71+
}
72+
}
73+

trunk/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/Project.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void delete() {
109109
* @see <a href=
110110
* "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/undelete">
111111
* Cloud Resource Manager undelete</a>
112-
* @throws ResourceManagerException
112+
* @throws ResourceManagerException upon failure (including when the project can't be restored)
113113
*/
114114
public void undelete() {
115115
resourceManager.undelete(info.id());

trunk/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/ProjectInfo.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.common.collect.ImmutableMap;
2020
import com.google.common.collect.Maps;
2121

22-
import org.joda.time.DateTime;
2322
import org.joda.time.format.ISODateTimeFormat;
2423

2524
import java.io.Serializable;
@@ -45,19 +44,32 @@ public class ProjectInfo implements Serializable {
4544
* The project lifecycle state.
4645
*
4746
* <ul>
48-
* <li>LIFECYCLE_STATE_UNSPECIFIED: only used/useful for distinguishing unset values
49-
* <li>ACTIVE: the normal and active state
50-
* <li>DELETE_REQUESTED: the project has been marked for deletion by the user or by the system
51-
* (Google Cloud Platform). This can generally be reversed by calling
52-
* {@link ResourceManager#undelete}.
53-
* <li>DELETE_IN_PROGRESS: the process of deleting the project has begun. Reversing the deletion
54-
* is no longer possible.
47+
* <li>LIFECYCLE_STATE_UNSPECIFIED:
48+
* <li>ACTIVE:
49+
* <li>DELETE_REQUESTED:
50+
* <li>DELETE_IN_PROGRESS:
5551
* <ul>
5652
*/
5753
public enum State {
54+
/**
55+
* Only used/useful for distinguishing unset values
56+
*/
5857
LIFECYCLE_STATE_UNSPECIFIED,
58+
59+
/**
60+
* The normal and active state
61+
*/
5962
ACTIVE,
63+
64+
/**
65+
* The project has been marked for deletion by the user or by the system (Google Cloud
66+
* Platform). This can generally be reversed by calling {@link ResourceManager#undelete}.
67+
*/
6068
DELETE_REQUESTED,
69+
70+
/**
71+
* the process of deleting the project has begun. Reversing the deletion is no longer possible.
72+
*/
6173
DELETE_IN_PROGRESS
6274
}
6375

@@ -289,19 +301,11 @@ com.google.api.services.cloudresourcemanager.model.Project toPb() {
289301
}
290302

291303
static ProjectInfo fromPb(com.google.api.services.cloudresourcemanager.model.Project projectPb) {
292-
ProjectInfo.Builder builder =
293-
ProjectInfo.builder(projectPb.getProjectId())
294-
.name(projectPb.getName())
295-
.number(projectPb.getProjectNumber());
304+
ProjectInfo.Builder builder =
305+
ProjectInfo.builder(projectPb.getProjectId()).name(projectPb.getName());
296306
if (projectPb.getLabels() != null) {
297307
builder.labels(projectPb.getLabels());
298308
}
299-
if (projectPb.getLifecycleState() != null) {
300-
builder.state(State.valueOf(projectPb.getLifecycleState()));
301-
}
302-
if (projectPb.getCreateTime() != null) {
303-
builder.createTimeMillis(DateTime.parse(projectPb.getCreateTime()).getMillis());
304-
}
305309
if (projectPb.getParent() != null) {
306310
builder.parent(ResourceId.fromPb(projectPb.getParent()));
307311
}

trunk/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/ResourceId.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
import java.util.Objects;
2121

2222
/**
23-
* Represents a Google Cloud Resource Manager Resource ID
23+
* Represents a Google Cloud Resource Manager Resource ID.
24+
*
25+
* A 'resource' in Google Cloud Platform is a generic term for something you (a developer) may want
26+
* to interact with through one of our API's. Some examples are an AppEngine app, a Compute Engine
27+
* instance, and Cloud SQL database.
2428
*/
2529
public class ResourceId implements Serializable {
2630

@@ -33,10 +37,20 @@ private ResourceId(String id, String type) {
3337
this.type = checkNotNull(type);
3438
}
3539

40+
/**
41+
* Required field for the type-specific ID.
42+
*
43+
* This should correspond to the ID used in the type-specific APIs.
44+
*/
3645
public String id() {
3746
return id;
3847
}
3948

49+
/**
50+
* Required field representing the resource type this ID is for.
51+
*
52+
* At present, the only valid type is "organization".
53+
*/
4054
public String type() {
4155
return type;
4256
}
@@ -51,6 +65,12 @@ public int hashCode() {
5165
return Objects.hash(id, type);
5266
}
5367

68+
/**
69+
* Create a new Resource ID with the given ID and resource type.
70+
*
71+
* The ID should correspond to the ID used in the type-specific APIs. At present, the only valid
72+
* type is "organization".
73+
*/
5474
public static ResourceId of(String id, String type) {
5575
return new ResourceId(id, type);
5676
}

trunk/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/ResourceManager.java

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@
1616

1717
package com.google.gcloud.resourcemanager;
1818

19-
import static com.google.common.base.Preconditions.checkNotNull;
20-
21-
import com.google.common.collect.ImmutableList;
2219
import com.google.gcloud.Page;
2320
import com.google.gcloud.Service;
24-
25-
import java.util.Collections;
26-
import java.util.List;
21+
import com.google.gcloud.spi.ResourceManagerRpc;
2722

2823
/**
2924
* An interface for Google Cloud Resource Manager.
@@ -34,39 +29,66 @@ public interface ResourceManager extends Service<ResourceManagerOptions> {
3429

3530
public static final String DEFAULT_CONTENT_TYPE = "application/octet-stream";
3631

37-
public class ListOptions {
38-
private List<String> filters;
39-
private String pageToken;
40-
private int pageSize;
41-
42-
private static final ListOptions DEFAULT_INSTANCE =
43-
new ListOptions(Collections.<String>emptyList(), null, -1);
44-
45-
ListOptions(List<String> filters, String pageToken, int pageSize) {
46-
this.filters = checkNotNull(ImmutableList.copyOf(filters));
47-
this.pageToken = pageToken;
48-
this.pageSize = pageSize;
49-
}
32+
/**
33+
* Class for specifying project list options.
34+
*/
35+
public class ProjectListOption extends Option {
5036

51-
public static ListOptions getDefaultInstance() {
52-
return DEFAULT_INSTANCE;
53-
}
37+
private static final long serialVersionUID = 7888768979702012328L;
5438

55-
public static ListOptions createListOption(
56-
List<String> filters, String pageToken, int pageSize) {
57-
return new ListOptions(filters, pageToken, pageSize);
39+
private ProjectListOption(ResourceManagerRpc.Option option, Object value) {
40+
super(option, value);
5841
}
5942

60-
public String pageToken() {
61-
return pageToken;
43+
/**
44+
* Returns an option to specify a page token.
45+
*
46+
* The page token (returned from a previous call to list) indicates from where listing should
47+
* continue. Pagination is not yet supported; the server ignores this field. Optional.
48+
*/
49+
public static ProjectListOption pageToken(String pageToken) {
50+
// return new ProjectListOption(ResourceManagerRpc.Option.PAGE_TOKEN, pageToken);
51+
throw new UnsupportedOperationException("paging for project lists is not implemented yet.");
6252
}
6353

64-
public List<String> filters() {
65-
return filters;
54+
/**
55+
* Returns an option to specify a filter.
56+
*
57+
* Filter rules are case insensitive. The fields eligible for filtering are:
58+
* <ul>
59+
* <li>name
60+
* <li>id
61+
* <li>labels.key, where key is the name of a label
62+
* </ul>
63+
*
64+
* Some examples of using labels as filters:
65+
* <ul>
66+
* <li> name:* The project has a name.
67+
* <li> name:Howl The project's name is Howl or howl.
68+
* <li> name:HOWL Equivalent to above.
69+
* <li> NAME:howl Equivalent to above.
70+
* <li> labels.color:* The project has the label color.
71+
* <li> labels.color:red The project's label color has the value red.
72+
* <li> labels.color:red label.size:big The project's label color has the value red and its
73+
* label size has the value big.
74+
* </ul>
75+
*
76+
* Optional.
77+
*/
78+
public static ProjectListOption filter(String filter) {
79+
return new ProjectListOption(ResourceManagerRpc.Option.FILTER, filter);
6680
}
6781

68-
public int pageSize() {
69-
return pageSize;
82+
/**
83+
* The maximum number of projects to return in the response.
84+
*
85+
* The server can return fewer projects than requested. If unspecified, server picks an
86+
* appropriate default. Note: pagination is not yet supported; the server ignores this field.
87+
* Optional.
88+
*/
89+
public static ProjectListOption pageSize(int pageSize) {
90+
// return new ProjectListOption(ResourceManagerRpc.Option.PAGE_SIZE, pageSize);
91+
throw new UnsupportedOperationException("paging for project lists is not implemented yet.");
7092
}
7193
}
7294

@@ -127,15 +149,16 @@ public int pageSize() {
127149
* Lists the projects visible to the current user.
128150
*
129151
* This method returns projects in an unspecified order. New projects do not necessarily appear at
130-
* the end of the list. Use {@link ListOptions} to filter this list, set page size, and set page
131-
* tokens. Note that pagination is currently not implemented by the Cloud Resource Manager API.
152+
* the end of the list. Use {@link ProjectListOption} to filter this list, set page size, and set
153+
* page tokens. Note that pagination is currently not implemented by the Cloud Resource Manager
154+
* API.
132155
*
133156
* @see <a href="https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/list">
134157
* Cloud Resource Manager list</a>
135158
* @return {@code Page<ProjectInfo>}, a page of projects.
136159
* @throws ResourceManagerException upon failure
137160
*/
138-
Page<ProjectInfo> list(ListOptions listOptions);
161+
Page<ProjectInfo> list(ProjectListOption... options);
139162

140163
/**
141164
* Replaces the attributes of the project.

trunk/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/spi/ResourceManagerRpc.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
package com.google.gcloud.spi;
1818

19-
import com.google.api.services.cloudresourcemanager.model.Policy;
2019
import com.google.api.services.cloudresourcemanager.model.Project;
2120
import com.google.gcloud.resourcemanager.ResourceManagerException;
2221

23-
import java.util.List;
2422
import java.util.Map;
2523

2624
public interface ResourceManagerRpc {
@@ -54,27 +52,6 @@ Long getInt(Map<Option, ?> options) {
5452
}
5553
}
5654

57-
public enum Permission {
58-
CREATE("resourcemanager.projects.create"),
59-
DELETE("resourcemanager.projects.delete"),
60-
GET("resourcemanager.projects.get"),
61-
LIST("resourcemanager.projects.list"),
62-
REPLACE("resourcemanager.projects.replace"),
63-
UNDELETE("resourcemanager.projects.undelete"),
64-
GET_IAM_POLICY("resourcemanager.projects.getIamPolicy"),
65-
REPLACE_IAM_POLICY("resourcemanager.projects.setIamPolicy");
66-
67-
String permissionPb;
68-
69-
Permission(String permissionPb) {
70-
this.permissionPb = permissionPb;
71-
}
72-
73-
String toPb() {
74-
return permissionPb;
75-
}
76-
}
77-
7855
class Tuple<X, Y> {
7956
private final X x;
8057
private final Y y;
@@ -109,12 +86,5 @@ public Y y() {
10986

11087
Project replace(Project project) throws ResourceManagerException;
11188

112-
Policy getIamPolicy(String projectId) throws ResourceManagerException;
113-
114-
Policy replaceIamPolicy(String projectId, Policy policy) throws ResourceManagerException;
115-
116-
List<Boolean> hasPermissions(String projectId, List<Permission> permissions)
117-
throws ResourceManagerException;
118-
11989
// TODO(ajaykannan): implement "Organization" functionality when available (issue #319)
12090
}

0 commit comments

Comments
 (0)