11package com .google .gcloud .spi ;
22
3+ import static com .google .gcloud .spi .DnsRpc .ListResult .of ;
34import static com .google .gcloud .spi .DnsRpc .Option .DNS_NAME ;
5+ import static com .google .gcloud .spi .DnsRpc .Option .NAME ;
46import static com .google .gcloud .spi .DnsRpc .Option .DNS_TYPE ;
57import static com .google .gcloud .spi .DnsRpc .Option .FIELDS ;
68import static com .google .gcloud .spi .DnsRpc .Option .PAGE_SIZE ;
3032 */
3133public class DefaultDnsRpc implements DnsRpc {
3234
33- private static final String SORTING_KEY = "changeSequence" ;
35+ private static final String SORT_BY = "changeSequence" ;
3436 private final Dns dns ;
3537 private final DnsOptions options ;
3638
@@ -77,17 +79,16 @@ public ManagedZone getZone(String zoneName, Map<Option, ?> options) throws DnsEx
7779 }
7880
7981 @ Override
80- public Tuple <String , Iterable <ManagedZone >> listZones (Map <Option , ?> options )
81- throws DnsException {
82+ public ListResult <ManagedZone > listZones (Map <Option , ?> options ) throws DnsException {
8283 // fields, page token, page size
8384 try {
8485 ManagedZonesListResponse zoneList = dns .managedZones ().list (this .options .projectId ())
8586 .setFields (FIELDS .getString (options ))
8687 .setMaxResults (PAGE_SIZE .getInt (options ))
88+ .setDnsName (DNS_NAME .getString (options ))
8789 .setPageToken (PAGE_TOKEN .getString (options ))
8890 .execute ();
89- return Tuple .<String , Iterable <ManagedZone >>of (zoneList .getNextPageToken (),
90- zoneList .getManagedZones ());
91+ return of (zoneList .getNextPageToken (), zoneList .getManagedZones ());
9192 } catch (IOException ex ) {
9293 throw translate (ex );
9394 }
@@ -108,20 +109,19 @@ public boolean deleteZone(String zoneName) throws DnsException {
108109 }
109110
110111 @ Override
111- public Tuple < String , Iterable < ResourceRecordSet >> listDnsRecords (String zoneName ,
112- Map < Option , ?> options ) throws DnsException {
112+ public ListResult < ResourceRecordSet > listDnsRecords (String zoneName , Map < Option , ?> options )
113+ throws DnsException {
113114 // options are fields, page token, dns name, type
114115 try {
115116 ResourceRecordSetsListResponse response = dns .resourceRecordSets ()
116117 .list (this .options .projectId (), zoneName )
117118 .setFields (FIELDS .getString (options ))
118119 .setPageToken (PAGE_TOKEN .getString (options ))
119120 .setMaxResults (PAGE_SIZE .getInt (options ))
120- .setName (DNS_NAME .getString (options ))
121+ .setName (NAME .getString (options ))
121122 .setType (DNS_TYPE .getString (options ))
122123 .execute ();
123- return Tuple .<String , Iterable <ResourceRecordSet >>of (response .getNextPageToken (),
124- response .getRrsets ());
124+ return of (response .getNextPageToken (), response .getRrsets ());
125125 } catch (IOException ex ) {
126126 throw translate (ex );
127127 }
@@ -159,8 +159,7 @@ public Change getChangeRequest(String zoneName, String changeRequestId, Map<Opti
159159 } catch (IOException ex ) {
160160 DnsException serviceException = translate (ex );
161161 if (serviceException .code () == HTTP_NOT_FOUND ) {
162- // message format "The 'parameters.changeId' resource named '4' does not exist."
163- if (serviceException .getMessage ().contains ("changeId" )) {
162+ if (serviceException .location ().equals ("entity.parameters.changeId" )) {
164163 // the change id was not found, but the zone exists
165164 return null ;
166165 }
@@ -171,7 +170,7 @@ public Change getChangeRequest(String zoneName, String changeRequestId, Map<Opti
171170 }
172171
173172 @ Override
174- public Tuple < String , Iterable < Change > > listChangeRequests (String zoneName , Map <Option , ?> options )
173+ public ListResult < Change > listChangeRequests (String zoneName , Map <Option , ?> options )
175174 throws DnsException {
176175 // options are fields, page token, page size, sort order
177176 try {
@@ -181,10 +180,10 @@ public Tuple<String, Iterable<Change>> listChangeRequests(String zoneName, Map<O
181180 .setPageToken (PAGE_TOKEN .getString (options ));
182181 if (SORTING_ORDER .getString (options ) != null ) {
183182 // todo check and change if more sorting options are implemented, issue #604
184- request = request .setSortBy (SORTING_KEY ).setSortOrder (SORTING_ORDER .getString (options ));
183+ request = request .setSortBy (SORT_BY ).setSortOrder (SORTING_ORDER .getString (options ));
185184 }
186185 ChangesListResponse response = request .execute ();
187- return Tuple .< String , Iterable < Change >> of (response .getNextPageToken (), response .getChanges ());
186+ return ListResult . of (response .getNextPageToken (), response .getChanges ());
188187 } catch (IOException ex ) {
189188 throw translate (ex );
190189 }
0 commit comments