Skip to content

Commit caf8659

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 2051 b: refs/heads/pubsub-alpha c: a50d770 h: refs/heads/master i: 2049: 6173cae 2047: 9b1d5b2
1 parent 84999f0 commit caf8659

3 files changed

Lines changed: 49 additions & 14 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: e6954ae90e5f7e0e8955a7525f2b6702458053b9
6+
refs/heads/pubsub-alpha: a50d770e002a6035529bfd9bbc27c9e83e35e6e3
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/spi/DefaultResourceManagerRpc.java

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package com.google.gcloud.spi;
22

3+
import static com.google.gcloud.spi.ResourceManagerRpc.Option.FIELDS;
4+
import static com.google.gcloud.spi.ResourceManagerRpc.Option.FILTER;
5+
import static com.google.gcloud.spi.ResourceManagerRpc.Option.PAGE_SIZE;
6+
import static com.google.gcloud.spi.ResourceManagerRpc.Option.PAGE_TOKEN;
7+
38
import com.google.api.client.googleapis.json.GoogleJsonError;
49
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
510
import com.google.api.client.http.HttpRequestInitializer;
611
import com.google.api.client.http.HttpTransport;
712
import com.google.api.client.json.jackson.JacksonFactory;
813
import com.google.api.services.cloudresourcemanager.Cloudresourcemanager;
14+
import com.google.api.services.cloudresourcemanager.model.ListProjectsResponse;
915
import com.google.api.services.cloudresourcemanager.model.Project;
1016
import com.google.common.collect.ImmutableSet;
1117
import com.google.gcloud.resourcemanager.ResourceManagerException;
@@ -20,13 +26,11 @@ public class DefaultResourceManagerRpc implements ResourceManagerRpc {
2026
// see https://cloud.google.com/resource-manager/v1/errors/core_errors
2127
private static final Set<Integer> RETRYABLE_CODES = ImmutableSet.of(503, 500, 429, 417);
2228

23-
private final ResourceManagerOptions options;
2429
private final Cloudresourcemanager resourceManager;
2530

2631
public DefaultResourceManagerRpc(ResourceManagerOptions options) {
2732
HttpTransport transport = options.httpTransportFactory().create();
2833
HttpRequestInitializer initializer = options.httpRequestInitializer();
29-
this.options = options;
3034
resourceManager =
3135
new Cloudresourcemanager.Builder(transport, new JacksonFactory(), initializer)
3236
.setRootUrl(options.host())
@@ -52,37 +56,68 @@ private static ResourceManagerException translate(GoogleJsonError exception) {
5256

5357
@Override
5458
public Project create(Project project) throws ResourceManagerException {
55-
// TODO(ajaykannan): fix me!
56-
return null;
59+
try {
60+
return resourceManager.projects().create(project).execute();
61+
} catch (IOException ex) {
62+
throw translate(ex);
63+
}
5764
}
5865

5966
@Override
6067
public void delete(String projectId) throws ResourceManagerException {
61-
// TODO(ajaykannan): fix me!
68+
try {
69+
resourceManager.projects().delete(projectId).execute();
70+
} catch (IOException ex) {
71+
throw translate(ex);
72+
}
6273
}
6374

6475
@Override
6576
public Project get(String projectId, Map<Option, ?> options) throws ResourceManagerException {
66-
// TODO(ajaykannan): fix me!
67-
return null;
77+
try {
78+
return resourceManager.projects()
79+
.get(projectId)
80+
.setFields(FIELDS.getString(options))
81+
.execute();
82+
} catch (IOException ex) {
83+
throw translate(ex);
84+
}
6885
}
6986

7087
@Override
7188
public Tuple<String, Iterable<Project>> list(Map<Option, ?> options)
7289
throws ResourceManagerException {
73-
// TODO(ajaykannan): fix me!
74-
return null;
90+
try {
91+
ListProjectsResponse response = resourceManager.projects()
92+
.list()
93+
.setFilter(FIELDS.getString(options))
94+
.setFilter(FILTER.getString(options))
95+
.setPageSize(PAGE_SIZE.getInt(options))
96+
.setPageToken(PAGE_TOKEN.getString(options))
97+
.execute();
98+
return Tuple.<String, Iterable<Project>>of(
99+
response.getNextPageToken(), response.getProjects());
100+
} catch (IOException ex) {
101+
throw translate(ex);
102+
}
75103
}
76104

77105
@Override
78106
public void undelete(String projectId) throws ResourceManagerException {
79-
// TODO(ajaykannan): fix me!
107+
try {
108+
resourceManager.projects().undelete(projectId).execute();
109+
} catch (IOException ex) {
110+
throw translate(ex);
111+
}
80112
}
81113

82114
@Override
83115
public Project replace(Project project) throws ResourceManagerException {
84-
// TODO(ajaykannan): fix me!
85-
return null;
116+
try {
117+
return resourceManager.projects().update(project.getProjectId(), project).execute();
118+
} catch (IOException ex) {
119+
throw translate(ex);
120+
}
86121
}
87122
}
88123

branches/pubsub-alpha/gcloud-java-resourcemanager/src/main/java/com/google/gcloud/spi/ResourceManagerRpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ String getString(Map<Option, ?> options) {
4848
return get(options);
4949
}
5050

51-
Long getInt(Map<Option, ?> options) {
51+
Integer getInt(Map<Option, ?> options) {
5252
return get(options);
5353
}
5454
}

0 commit comments

Comments
 (0)