Skip to content

Commit 896de75

Browse files
committed
Fixed documentation and null returns from rpc.
1 parent bc4b820 commit 896de75

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

gcloud-java-dns/src/main/java/com/google/gcloud/spi/DefaultDnsRpc.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131
public class DefaultDnsRpc implements DnsRpc {
3232

33+
private static final String SORTING_KEY = "changeSequence";
3334
private final Dns dns;
3435
private final DnsOptions options;
3536

@@ -64,9 +65,14 @@ public ManagedZone getZone(String zoneName, Map<Option, ?> options) throws DnsEx
6465
// just fields option
6566
try {
6667
return dns.managedZones().get(this.options.projectId(), zoneName)
67-
.setFields(FIELDS.getString(options)).execute();
68+
.setFields(FIELDS.getString(options))
69+
.execute();
6870
} catch (IOException ex) {
69-
throw translate(ex);
71+
DnsException serviceException = translate(ex);
72+
if (serviceException.code() == HTTP_NOT_FOUND) {
73+
return null;
74+
}
75+
throw serviceException;
7076
}
7177
}
7278

@@ -151,7 +157,16 @@ public Change getChangeRequest(String zoneName, String changeRequestId, Map<Opti
151157
.setFields(FIELDS.getString(options))
152158
.execute();
153159
} catch (IOException ex) {
154-
throw translate(ex);
160+
DnsException serviceException = translate(ex);
161+
if (serviceException.code() == HTTP_NOT_FOUND) {
162+
// message format "The 'parameters.changeId' resource named '4' does not exist."
163+
if (serviceException.getMessage().contains("changeId")) {
164+
// the change id was not found, but the zone exists
165+
return null;
166+
}
167+
// the zone does not exist, so throw an exception
168+
}
169+
throw serviceException;
155170
}
156171
}
157172

@@ -165,9 +180,8 @@ public Tuple<String, Iterable<Change>> listChangeRequests(String zoneName, Map<O
165180
.setMaxResults(PAGE_SIZE.getInt(options))
166181
.setPageToken(PAGE_TOKEN.getString(options));
167182
if (SORTING_ORDER.getString(options) != null) {
168-
// this needs to be checked and changed if more sorting options are implemented, issue #604
169-
String key = "changeSequence";
170-
request = request.setSortBy(key).setSortOrder(SORTING_ORDER.getString(options));
183+
// todo check and change if more sorting options are implemented, issue #604
184+
request = request.setSortBy(SORTING_KEY).setSortOrder(SORTING_ORDER.getString(options));
171185
}
172186
ChangesListResponse response = request.execute();
173187
return Tuple.<String, Iterable<Change>>of(response.getNextPageToken(), response.getChanges());

gcloud-java-dns/src/main/java/com/google/gcloud/spi/DnsRpc.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public Y y() {
8585
* Creates a new zone.
8686
*
8787
* @param zone a zone to be created
88-
* @return Updated {@link ManagedZone} object
88+
* @return Updated {@code ManagedZone} object
8989
* @throws DnsException upon failure
9090
*/
9191
ManagedZone create(ManagedZone zone) throws DnsException;
@@ -121,7 +121,7 @@ public Y y() {
121121
*
122122
* @param zoneName name of the zone to be listed
123123
* @param options a map of options for the service call
124-
* @throws DnsException upon failure or if zone not found
124+
* @throws DnsException upon failure or if zone was not found
125125
*/
126126
Tuple<String, Iterable<ResourceRecordSet>> listDnsRecords(String zoneName,
127127
Map<Option, ?> options) throws DnsException;
@@ -131,40 +131,40 @@ Tuple<String, Iterable<ResourceRecordSet>> listDnsRecords(String zoneName,
131131
*
132132
* @param options a map of options for the service call
133133
* @return up-to-date project information
134-
* @throws DnsException upon failure
134+
* @throws DnsException upon failure or if the project is not found
135135
*/
136136
Project getProject(Map<Option, ?> options) throws DnsException;
137137

138138
/**
139139
* Applies change request to a zone.
140140
*
141-
* @param zoneName the name of a zone to which the {@link Change} should be applied
141+
* @param zoneName the name of a zone to which the {@code Change} should be applied
142142
* @param changeRequest change to be applied
143143
* @param options a map of options for the service call
144144
* @return updated change object with server-assigned ID
145-
* @throws DnsException upon failure or if zone not found
145+
* @throws DnsException upon failure or if zone was not found
146146
*/
147147
Change applyChangeRequest(String zoneName, Change changeRequest, Map<Option, ?> options)
148148
throws DnsException;
149149

150150
/**
151151
* Returns an existing change request.
152152
*
153-
* @param zoneName the name of a zone to which the {@link Change} was be applied
153+
* @param zoneName the name of a zone to which the {@code Change} was be applied
154154
* @param changeRequestId the unique id assigned to the change by the server
155155
* @param options a map of options for the service call
156-
* @return up-to-date change object
157-
* @throws DnsException upon failure or if zone not found
156+
* @return up-to-date change object or {@code null} if change was not found
157+
* @throws DnsException upon failure or if zone was not found
158158
*/
159159
Change getChangeRequest(String zoneName, String changeRequestId, Map<Option, ?> options)
160160
throws DnsException;
161161

162162
/**
163-
* List an existing change requests for a zone.
163+
* List existing change requests for a zone.
164164
*
165-
* @param zoneName the name of a zone to which the {@link Change}s were be applied
165+
* @param zoneName the name of a zone to which the {@code Change}s were be applied
166166
* @param options a map of options for the service call
167-
* @throws DnsException upon failure or if zone not found
167+
* @throws DnsException upon failure or if zone was not found
168168
*/
169169
Tuple<String, Iterable<Change>> listChangeRequests(String zoneName, Map<Option, ?> options)
170170
throws DnsException;

0 commit comments

Comments
 (0)