Skip to content

Commit 47260bc

Browse files
committed
---
yaml --- r: 2861 b: refs/heads/dns-alpha c: 71f5ae2 h: refs/heads/master i: 2859: 5637b2e
1 parent 09cf87e commit 47260bc

7 files changed

Lines changed: 224 additions & 675 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd
1111
refs/tags/v0.0.11: ffbfba48a6426ff63c08ff2117e58681f251fbf2
1212
refs/tags/v0.0.12: 2fd8066e891fb3dfea69b65f6bf6461db79342b9
1313
refs/heads/compute-alpha: b1274b5bdf4eea955f3588b56378a5ae4ba59cef
14-
refs/heads/dns-alpha: 35dbb341514db95fea1ec0fb0ca674bf67a2dc24
14+
refs/heads/dns-alpha: 71f5ae22187569bf20461bcb6021761bc9864856

branches/dns-alpha/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.gcloud.spi.DnsRpc;
2424

2525
import java.io.Serializable;
26-
import java.math.BigInteger;
2726
import java.util.Set;
2827

2928
/**
@@ -69,8 +68,7 @@ static String selector(ProjectField... fields) {
6968
* The fields of a zone.
7069
*
7170
* <p>These values can be used to specify the fields to include in a partial response when calling
72-
* {@link Dns#getZone(BigInteger, ZoneOption...)} or {@link Dns#getZone(String, ZoneOption...)}.
73-
* The ID is always returned, even if not specified.
71+
* {@link Dns#getZone(String, ZoneOption...)}. The ID is always returned, even if not specified.
7472
*/
7573
enum ZoneField {
7674
CREATION_TIME("creationTime"),
@@ -105,9 +103,8 @@ static String selector(ZoneField... fields) {
105103
* The fields of a DNS record.
106104
*
107105
* <p>These values can be used to specify the fields to include in a partial response when calling
108-
* {@link Dns#listDnsRecords(BigInteger, DnsRecordListOption...)} or {@link
109-
* Dns#listDnsRecords(String, DnsRecordListOption...)}. The name is always returned even if not
110-
* selected.
106+
* {@link Dns#listDnsRecords(String, DnsRecordListOption...)}. The name is always returned even if
107+
* not selected.
111108
*/
112109
enum DnsRecordField {
113110
DNS_RECORDS("rrdatas"),
@@ -139,8 +136,7 @@ static String selector(DnsRecordField... fields) {
139136
* The fields of a change request.
140137
*
141138
* <p>These values can be used to specify the fields to include in a partial response when calling
142-
* {@link Dns#applyChangeRequest(BigInteger, ChangeRequest, ChangeRequestOption...)} or {@link
143-
* Dns#applyChangeRequest(String, ChangeRequest, ChangeRequestOption...)} The ID is always
139+
* {@link Dns#applyChangeRequest(String, ChangeRequest, ChangeRequestOption...)} The ID is always
144140
* returned even if not selected.
145141
*/
146142
enum ChangeRequestField {
@@ -444,16 +440,6 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
444440
*/
445441
ZoneInfo getZone(String zoneName, ZoneOption... options);
446442

447-
/**
448-
* Returns the zone by the specified zone id. Returns {@code null} if the zone is not found. The
449-
* returned fields can be optionally restricted by specifying {@link ZoneOption}s.
450-
*
451-
* @throws DnsException upon failure
452-
* @see <a href="https://cloud.google.com/dns/api/v1/managedZones/get">Cloud DNS Managed Zones:
453-
* get</a>
454-
*/
455-
ZoneInfo getZone(BigInteger zoneId, ZoneOption... options);
456-
457443
/**
458444
* Lists the zones inside the project.
459445
*
@@ -479,17 +465,6 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
479465
*/
480466
boolean delete(String zoneName); // delete does not admit any options
481467

482-
/**
483-
* Deletes an existing zone identified by id. Returns {@code true} if the zone was successfully
484-
* deleted and {@code false} otherwise.
485-
*
486-
* @return {@code true} if zone was found and deleted and {@code false} otherwise
487-
* @throws DnsException upon failure
488-
* @see <a href="https://cloud.google.com/dns/api/v1/managedZones/delete">Cloud DNS Managed Zones:
489-
* delete</a>
490-
*/
491-
boolean delete(BigInteger zoneId); // delete does not admit any options
492-
493468
/**
494469
* Lists the DNS records in the zone identified by name.
495470
*
@@ -502,18 +477,6 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
502477
*/
503478
Page<DnsRecord> listDnsRecords(String zoneName, DnsRecordListOption... options);
504479

505-
/**
506-
* Lists the DNS records in the zone identified by ID.
507-
*
508-
* <p>The fields to be returned, page size and page tokens can be specified using {@link
509-
* DnsRecordListOption}s.
510-
*
511-
* @throws DnsException upon failure or if the zone cannot be found
512-
* @see <a href="https://cloud.google.com/dns/api/v1/resourceRecordSets/list">Cloud DNS
513-
* ResourceRecordSets: list</a>
514-
*/
515-
Page<DnsRecord> listDnsRecords(BigInteger zoneId, DnsRecordListOption... options);
516-
517480
/**
518481
* Retrieves the information about the current project. The returned fields can be optionally
519482
* restricted by specifying {@link ProjectOption}s.
@@ -523,18 +486,6 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
523486
*/
524487
ProjectInfo getProjectInfo(ProjectOption... fields);
525488

526-
/**
527-
* Submits a change request for the specified zone. The returned object contains the following
528-
* read-only fields supplied by the server: id, start time and status. time, id, and list of name
529-
* servers. The fields to be returned can be selected by {@link ChangeRequestOption}s.
530-
*
531-
* @return the new {@link ChangeRequest} or {@code null} if zone is not found
532-
* @throws DnsException upon failure
533-
* @see <a href="https://cloud.google.com/dns/api/v1/changes/create">Cloud DNS Changes: create</a>
534-
*/
535-
ChangeRequest applyChangeRequest(BigInteger zoneId, ChangeRequest changeRequest,
536-
ChangeRequestOption... options);
537-
538489
/**
539490
* Submits a change request for the specified zone. The returned object contains the following
540491
* read-only fields supplied by the server: id, start time and status. time, id, and list of name
@@ -547,18 +498,6 @@ ChangeRequest applyChangeRequest(BigInteger zoneId, ChangeRequest changeRequest,
547498
ChangeRequest applyChangeRequest(String zoneName, ChangeRequest changeRequest,
548499
ChangeRequestOption... options);
549500

550-
/**
551-
* Retrieves updated information about a change request previously submitted for a zone identified
552-
* by ID. Returns {@code null} if the request cannot be found and throws an exception if the zone
553-
* does not exist. The fields to be returned using can be specified using {@link
554-
* ChangeRequestOption}s.
555-
*
556-
* @throws DnsException upon failure or if the zone cannot be found
557-
* @see <a href="https://cloud.google.com/dns/api/v1/changes/get">Cloud DNS Chages: get</a>
558-
*/
559-
ChangeRequest getChangeRequest(BigInteger zoneId, String changeRequestId,
560-
ChangeRequestOption... options);
561-
562501
/**
563502
* Retrieves updated information about a change request previously submitted for a zone identified
564503
* by ID. Returns {@code null} if the request cannot be found and throws an exception if the zone
@@ -571,18 +510,6 @@ ChangeRequest getChangeRequest(BigInteger zoneId, String changeRequestId,
571510
ChangeRequest getChangeRequest(String zoneName, String changeRequestId,
572511
ChangeRequestOption... options);
573512

574-
/**
575-
* Lists the change requests for the zone identified by ID that were submitted to the service.
576-
*
577-
* <p>The sorting order for changes (based on when they were received by the server), fields to be
578-
* returned, page size and page token can be specified using {@link ChangeRequestListOption}s.
579-
*
580-
* @return A page of change requests
581-
* @throws DnsException upon failure or if the zone cannot be found
582-
* @see <a href="https://cloud.google.com/dns/api/v1/changes/list">Cloud DNS Chages: list</a>
583-
*/
584-
Page<ChangeRequest> listChangeRequests(BigInteger zoneId, ChangeRequestListOption... options);
585-
586513
/**
587514
* Lists the change requests for the zone identified by name that were submitted to the service.
588515
*

branches/dns-alpha/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java

Lines changed: 20 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616

1717
package com.google.gcloud.dns;
1818

19-
import static com.google.common.base.Preconditions.checkArgument;
2019
import static com.google.common.base.Preconditions.checkNotNull;
2120

2221
import com.google.gcloud.Page;
2322

2423
import java.io.Serializable;
25-
import java.math.BigInteger;
2624

2725
/**
2826
* A Google Cloud DNS Zone object.
@@ -39,7 +37,7 @@ public class Zone implements Serializable {
3937

4038
// TODO(mderka) Zone and zoneInfo to be merged. Opened issue #605.
4139

42-
private static final long serialVersionUID = -4012581571095484813L;
40+
private static final long serialVersionUID = 6847890192129375500L;
4341
private final ZoneInfo zoneInfo;
4442
private final Dns dns;
4543

@@ -68,166 +66,81 @@ public static Zone get(Dns dnsService, String zoneName, Dns.ZoneOption... option
6866
}
6967

7068
/**
71-
* Constructs a {@code Zone} object that contains information received from the Google Cloud DNS
72-
* service for the provided {@code zoneId}.
73-
*
74-
* @param zoneId ID of the zone to be searched for
75-
* @param options optional restriction on what fields should be returned by the service
76-
* @return zone object containing zone's information or {@code null} if not not found
77-
* @throws DnsException upon failure
78-
*/
79-
public static Zone get(Dns dnsService, BigInteger zoneId, Dns.ZoneOption... options) {
80-
checkNotNull(zoneId);
81-
checkNotNull(dnsService);
82-
ZoneInfo zoneInfo = dnsService.getZone(zoneId, options);
83-
return zoneInfo == null ? null : new Zone(dnsService, zoneInfo);
84-
}
85-
86-
/**
87-
* Retrieves the latest information about the zone. The method first attempts to retrieve the zone
88-
* by ID and if not set or zone is not found, it searches by name.
69+
* Retrieves the latest information about the zone. The method retrieves the zone by name which
70+
* must always be initialized.
8971
*
9072
* @param options optional restriction on what fields should be fetched
9173
* @return zone object containing updated information or {@code null} if not not found
9274
* @throws DnsException upon failure
93-
* @throws NullPointerException if both zone ID and name are not initialized
9475
*/
9576
public Zone reload(Dns.ZoneOption... options) {
96-
checkNameOrIdNotNull();
97-
Zone zone = null;
98-
if (zoneInfo.id() != null) {
99-
zone = Zone.get(dns, zoneInfo.id(), options);
100-
}
101-
if (zone == null && zoneInfo.name() != null) {
102-
// zone was not found by id or id is not set at all
103-
zone = Zone.get(dns, zoneInfo.name(), options);
104-
}
105-
return zone;
77+
return Zone.get(dns, zoneInfo.name(), options);
10678
}
10779

10880
/**
109-
* Deletes the zone. The method first attempts to delete the zone by ID. If the zone is not found
110-
* or id is not set, it attempts to delete by name.
81+
* Deletes the zone. The method first deletes the zone by name which must always be initialized.
11182
*
11283
* @return {@code true} is zone was found and deleted and {@code false} otherwise
11384
* @throws DnsException upon failure
114-
* @throws NullPointerException if both zone ID and name are not initialized
11585
*/
11686
public boolean delete() {
117-
checkNameOrIdNotNull();
118-
boolean deleted = false;
119-
if (zoneInfo.id() != null) {
120-
deleted = dns.delete(zoneInfo.id());
121-
}
122-
if (!deleted && zoneInfo.name() != null) {
123-
// zone was not found by id or id is not set at all
124-
deleted = dns.delete(zoneInfo.name());
125-
}
126-
return deleted;
87+
return dns.delete(zoneInfo.name());
12788
}
12889

12990
/**
130-
* Lists all {@link DnsRecord}s associated with this zone. First searches for zone by ID and if
131-
* not found then by name.
91+
* Lists all {@link DnsRecord}s associated with this zone. The method searches for zone by name
92+
* which must always be initialized.
13293
*
13394
* @param options optional restriction on listing and fields of {@link DnsRecord}s returned
13495
* @return a page of DNS records
13596
* @throws DnsException upon failure or if the zone is not found
136-
* @throws NullPointerException if both zone ID and name are not initialized
13797
*/
13898
public Page<DnsRecord> listDnsRecords(Dns.DnsRecordListOption... options) {
139-
checkNameOrIdNotNull();
140-
Page<DnsRecord> page = null;
141-
if (zoneInfo.id() != null) {
142-
page = dns.listDnsRecords(zoneInfo.id(), options);
143-
}
144-
if (page == null && zoneInfo.name() != null) {
145-
// zone was not found by id or id is not set at all
146-
page = dns.listDnsRecords(zoneInfo.name(), options);
147-
}
148-
return page;
99+
return dns.listDnsRecords(zoneInfo.name(), options);
149100
}
150101

151102
/**
152-
* Submits {@link ChangeRequest} to the service for it to applied to this zone. First searches for
153-
* the zone by ID and if not found then by name. Returns a {@link ChangeRequest} with
154-
* server-assigned ID or {@code null} if the zone was not found.
103+
* Submits {@link ChangeRequest} to the service for it to applied to this zone. The method
104+
* searches for zone by name which must always be initialized.
155105
*
156106
* @param options optional restriction on what fields of {@link ChangeRequest} should be returned
157107
* @return ChangeRequest with server-assigned ID
158108
* @throws DnsException upon failure or if the zone is not found
159-
* @throws NullPointerException if both zone ID and name are not initialized
160109
*/
161110
public ChangeRequest applyChangeRequest(ChangeRequest changeRequest,
162111
Dns.ChangeRequestOption... options) {
163-
checkNameOrIdNotNull();
164112
checkNotNull(changeRequest);
165-
ChangeRequest updated = null;
166-
if (zoneInfo.id() != null) {
167-
updated = dns.applyChangeRequest(zoneInfo.id(), changeRequest, options);
168-
}
169-
if (updated == null && zoneInfo.name() != null) {
170-
// zone was not found by id or id is not set at all
171-
updated = dns.applyChangeRequest(zoneInfo.name(), changeRequest, options);
172-
}
173-
return updated;
113+
return dns.applyChangeRequest(zoneInfo.name(), changeRequest, options);
174114
}
175115

176116
/**
177117
* Retrieves an updated information about a change request previously submitted to be applied to
178-
* this zone. First searches for the zone by ID and if not found then by name. Returns a {@link
179-
* ChangeRequest} if found and {@code null} is the zone or the change request was not found.
118+
* this zone. The method searches for zone by name which must always be initialized. Returns a
119+
* {@link ChangeRequest} if and {@code null} if the change request was not found. Throws {@link
120+
* DnsException} if the zone is not found.
180121
*
181122
* @param options optional restriction on what fields of {@link ChangeRequest} should be returned
182123
* @return updated ChangeRequest
183124
* @throws DnsException upon failure or if the zone is not found
184-
* @throws NullPointerException if both zone ID and name are not initialized
185125
* @throws NullPointerException if the change request does not have initialized id
186126
*/
187127
public ChangeRequest getChangeRequest(String changeRequestId,
188128
Dns.ChangeRequestOption... options) {
189-
checkNameOrIdNotNull();
190129
checkNotNull(changeRequestId);
191-
ChangeRequest updated = null;
192-
if (zoneInfo.id() != null) {
193-
updated = dns.getChangeRequest(zoneInfo.id(), changeRequestId, options);
194-
}
195-
if (updated == null && zoneInfo.name() != null) {
196-
// zone was not found by id or id is not set at all
197-
updated = dns.getChangeRequest(zoneInfo.name(), changeRequestId, options);
198-
}
199-
return updated;
130+
return dns.getChangeRequest(zoneInfo.name(), changeRequestId, options);
200131
}
201132

202133
/**
203-
* Retrieves all change requests for this zone. First searches for the zone by ID and if not found
204-
* then by name. Returns a page of {@link ChangeRequest}s or {@code null} if the zone is not
205-
* found.
134+
* Retrieves all change requests for this zone. The method searches for zone by name which must
135+
* always be initialized. Returns a page of {@link ChangeRequest}s. Throws a {@link DnsException}
136+
* if the zone is not found.
206137
*
207138
* @param options optional restriction on listing and fields to be returned
208139
* @return a page of change requests
209140
* @throws DnsException upon failure or if the zone is not found
210-
* @throws NullPointerException if both zone ID and name are not initialized
211141
*/
212142
public Page<ChangeRequest> listChangeRequests(Dns.ChangeRequestListOption... options) {
213-
checkNameOrIdNotNull();
214-
Page<ChangeRequest> changeRequests = null;
215-
if (zoneInfo.id() != null) {
216-
changeRequests = dns.listChangeRequests(zoneInfo.id(), options);
217-
}
218-
if (changeRequests == null && zoneInfo.name() != null) {
219-
// zone was not found by id or id is not set at all
220-
changeRequests = dns.listChangeRequests(zoneInfo.name(), options);
221-
}
222-
return changeRequests;
223-
}
224-
225-
/**
226-
* Check that at least one of name and ID are initialized and throw and exception if not.
227-
*/
228-
private void checkNameOrIdNotNull() {
229-
checkArgument(zoneInfo != null && (zoneInfo.id() != null || zoneInfo.name() != null),
230-
"Both zoneInfo.id and zoneInfo.name are null. This is should never happen.");
143+
return dns.listChangeRequests(zoneInfo.name(), options);
231144
}
232145

233146
/**

0 commit comments

Comments
 (0)