These values can be used to specify the fields to include in a partial response when calling
- * {@link Dns#getZone(BigInteger, ZoneOption...)} or {@link Dns#getZone(String, ZoneOption...)}.
- * The ID is always returned, even if not specified.
+ * {@link Dns#getZone(String, ZoneOption...)}. The name is always returned, even if not specified.
*/
enum ZoneField {
CREATION_TIME("creationTime"),
@@ -93,7 +91,7 @@ String selector() {
static String selector(ZoneField... fields) {
Set fieldStrings = Sets.newHashSetWithExpectedSize(fields.length + 1);
- fieldStrings.add(ZONE_ID.selector());
+ fieldStrings.add(NAME.selector());
for (ZoneField field : fields) {
fieldStrings.add(field.selector());
}
@@ -105,9 +103,8 @@ static String selector(ZoneField... fields) {
* The fields of a DNS record.
*
*
These values can be used to specify the fields to include in a partial response when calling
- * {@link Dns#listDnsRecords(BigInteger, DnsRecordListOption...)} or {@link
- * Dns#listDnsRecords(String, DnsRecordListOption...)}. The name is always returned even if not
- * selected.
+ * {@link Dns#listDnsRecords(String, DnsRecordListOption...)}. The name is always returned even if
+ * not selected.
*/
enum DnsRecordField {
DNS_RECORDS("rrdatas"),
@@ -139,8 +136,7 @@ static String selector(DnsRecordField... fields) {
* The fields of a change request.
*
*
These values can be used to specify the fields to include in a partial response when calling
- * {@link Dns#applyChangeRequest(BigInteger, ChangeRequest, ChangeRequestOption...)} or {@link
- * Dns#applyChangeRequest(String, ChangeRequest, ChangeRequestOption...)} The ID is always
+ * {@link Dns#applyChangeRequest(String, ChangeRequest, ChangeRequestOption...)} The ID is always
* returned even if not selected.
*/
enum ChangeRequestField {
@@ -425,14 +421,15 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
*
*
Returns {@link ZoneInfo} object representing the new zone's information. In addition to the
* name, dns name and description (supplied by the user within the {@code zoneInfo} parameter),
- * the returned object will include the following read-only fields supplied by the server:
- * creation time, id, and list of name servers.
+ * the returned object can include the following read-only fields supplied by the server: creation
+ * time, id, and list of name servers. The returned fields can be optionally restricted by
+ * specifying {@link ZoneOption}s.
*
* @throws DnsException upon failure
* @see Cloud DNS Managed Zones:
* create
*/
- ZoneInfo create(ZoneInfo zoneInfo);
+ ZoneInfo create(ZoneInfo zoneInfo, ZoneOption... options);
/**
* Returns the zone by the specified zone name. Returns {@code null} if the zone is not found. The
@@ -444,16 +441,6 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
*/
ZoneInfo getZone(String zoneName, ZoneOption... options);
- /**
- * Returns the zone by the specified zone id. Returns {@code null} if the zone is not found. The
- * returned fields can be optionally restricted by specifying {@link ZoneOption}s.
- *
- * @throws DnsException upon failure
- * @see Cloud DNS Managed Zones:
- * get
- */
- ZoneInfo getZone(BigInteger zoneId, ZoneOption... options);
-
/**
* Lists the zones inside the project.
*
@@ -479,17 +466,6 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
*/
boolean delete(String zoneName); // delete does not admit any options
- /**
- * Deletes an existing zone identified by id. Returns {@code true} if the zone was successfully
- * deleted and {@code false} otherwise.
- *
- * @return {@code true} if zone was found and deleted and {@code false} otherwise
- * @throws DnsException upon failure
- * @see Cloud DNS Managed Zones:
- * delete
- */
- boolean delete(BigInteger zoneId); // delete does not admit any options
-
/**
* Lists the DNS records in the zone identified by name.
*
@@ -502,18 +478,6 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
*/
Page listDnsRecords(String zoneName, DnsRecordListOption... options);
- /**
- * Lists the DNS records in the zone identified by ID.
- *
- *
The fields to be returned, page size and page tokens can be specified using {@link
- * DnsRecordListOption}s.
- *
- * @throws DnsException upon failure or if the zone cannot be found
- * @see Cloud DNS
- * ResourceRecordSets: list
- */
- Page listDnsRecords(BigInteger zoneId, DnsRecordListOption... options);
-
/**
* Retrieves the information about the current project. The returned fields can be optionally
* restricted by specifying {@link ProjectOption}s.
@@ -523,18 +487,6 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
*/
ProjectInfo getProjectInfo(ProjectOption... fields);
- /**
- * Submits a change request for the specified zone. The returned object contains the following
- * read-only fields supplied by the server: id, start time and status. time, id, and list of name
- * servers. The fields to be returned can be selected by {@link ChangeRequestOption}s.
- *
- * @return the new {@link ChangeRequest} or {@code null} if zone is not found
- * @throws DnsException upon failure
- * @see Cloud DNS Changes: create
- */
- ChangeRequest applyChangeRequest(BigInteger zoneId, ChangeRequest changeRequest,
- ChangeRequestOption... options);
-
/**
* Submits a change request for the specified zone. The returned object contains the following
* read-only fields supplied by the server: id, start time and status. time, id, and list of name
@@ -547,18 +499,6 @@ ChangeRequest applyChangeRequest(BigInteger zoneId, ChangeRequest changeRequest,
ChangeRequest applyChangeRequest(String zoneName, ChangeRequest changeRequest,
ChangeRequestOption... options);
- /**
- * Retrieves updated information about a change request previously submitted for a zone identified
- * by ID. Returns {@code null} if the request cannot be found and throws an exception if the zone
- * does not exist. The fields to be returned using can be specified using {@link
- * ChangeRequestOption}s.
- *
- * @throws DnsException upon failure or if the zone cannot be found
- * @see Cloud DNS Chages: get
- */
- ChangeRequest getChangeRequest(BigInteger zoneId, String changeRequestId,
- ChangeRequestOption... options);
-
/**
* Retrieves updated information about a change request previously submitted for a zone identified
* by ID. Returns {@code null} if the request cannot be found and throws an exception if the zone
@@ -571,18 +511,6 @@ ChangeRequest getChangeRequest(BigInteger zoneId, String changeRequestId,
ChangeRequest getChangeRequest(String zoneName, String changeRequestId,
ChangeRequestOption... options);
- /**
- * Lists the change requests for the zone identified by ID that were submitted to the service.
- *
- *
The sorting order for changes (based on when they were received by the server), fields to be
- * returned, page size and page token can be specified using {@link ChangeRequestListOption}s.
- *
- * @return A page of change requests
- * @throws DnsException upon failure or if the zone cannot be found
- * @see Cloud DNS Chages: list
- */
- Page listChangeRequests(BigInteger zoneId, ChangeRequestListOption... options);
-
/**
* Lists the change requests for the zone identified by name that were submitted to the service.
*
diff --git a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java
index 86fc86bc3688..3f4ea8cab3e4 100644
--- a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java
+++ b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java
@@ -16,13 +16,11 @@
package com.google.gcloud.dns;
-import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.gcloud.Page;
import java.io.Serializable;
-import java.math.BigInteger;
/**
* A Google Cloud DNS Zone object.
@@ -39,7 +37,7 @@ public class Zone implements Serializable {
// TODO(mderka) Zone and zoneInfo to be merged. Opened issue #605.
- private static final long serialVersionUID = -4012581571095484813L;
+ private static final long serialVersionUID = 6847890192129375500L;
private final ZoneInfo zoneInfo;
private final Dns dns;
@@ -68,166 +66,77 @@ public static Zone get(Dns dnsService, String zoneName, Dns.ZoneOption... option
}
/**
- * Constructs a {@code Zone} object that contains information received from the Google Cloud DNS
- * service for the provided {@code zoneId}.
- *
- * @param zoneId ID of the zone to be searched for
- * @param options optional restriction on what fields should be returned by the service
- * @return zone object containing zone's information or {@code null} if not not found
- * @throws DnsException upon failure
- */
- public static Zone get(Dns dnsService, BigInteger zoneId, Dns.ZoneOption... options) {
- checkNotNull(zoneId);
- checkNotNull(dnsService);
- ZoneInfo zoneInfo = dnsService.getZone(zoneId, options);
- return zoneInfo == null ? null : new Zone(dnsService, zoneInfo);
- }
-
- /**
- * Retrieves the latest information about the zone. The method first attempts to retrieve the zone
- * by ID and if not set or zone is not found, it searches by name.
+ * Retrieves the latest information about the zone. The method retrieves the zone by name.
*
* @param options optional restriction on what fields should be fetched
* @return zone object containing updated information or {@code null} if not not found
* @throws DnsException upon failure
- * @throws NullPointerException if both zone ID and name are not initialized
*/
public Zone reload(Dns.ZoneOption... options) {
- checkNameOrIdNotNull();
- Zone zone = null;
- if (zoneInfo.id() != null) {
- zone = Zone.get(dns, zoneInfo.id(), options);
- }
- if (zone == null && zoneInfo.name() != null) {
- // zone was not found by id or id is not set at all
- zone = Zone.get(dns, zoneInfo.name(), options);
- }
- return zone;
+ return Zone.get(dns, zoneInfo.name(), options);
}
/**
- * Deletes the zone. The method first attempts to delete the zone by ID. If the zone is not found
- * or id is not set, it attempts to delete by name.
+ * Deletes the zone. The method deletes the zone by name.
*
* @return {@code true} is zone was found and deleted and {@code false} otherwise
* @throws DnsException upon failure
- * @throws NullPointerException if both zone ID and name are not initialized
*/
public boolean delete() {
- checkNameOrIdNotNull();
- boolean deleted = false;
- if (zoneInfo.id() != null) {
- deleted = dns.delete(zoneInfo.id());
- }
- if (!deleted && zoneInfo.name() != null) {
- // zone was not found by id or id is not set at all
- deleted = dns.delete(zoneInfo.name());
- }
- return deleted;
+ return dns.delete(zoneInfo.name());
}
/**
- * Lists all {@link DnsRecord}s associated with this zone. First searches for zone by ID and if
- * not found then by name.
+ * Lists all {@link DnsRecord}s associated with this zone. The method searches for zone by name.
*
* @param options optional restriction on listing and fields of {@link DnsRecord}s returned
* @return a page of DNS records
* @throws DnsException upon failure or if the zone is not found
- * @throws NullPointerException if both zone ID and name are not initialized
*/
public Page listDnsRecords(Dns.DnsRecordListOption... options) {
- checkNameOrIdNotNull();
- Page page = null;
- if (zoneInfo.id() != null) {
- page = dns.listDnsRecords(zoneInfo.id(), options);
- }
- if (page == null && zoneInfo.name() != null) {
- // zone was not found by id or id is not set at all
- page = dns.listDnsRecords(zoneInfo.name(), options);
- }
- return page;
+ return dns.listDnsRecords(zoneInfo.name(), options);
}
/**
- * Submits {@link ChangeRequest} to the service for it to applied to this zone. First searches for
- * the zone by ID and if not found then by name. Returns a {@link ChangeRequest} with
- * server-assigned ID or {@code null} if the zone was not found.
+ * Submits {@link ChangeRequest} to the service for it to applied to this zone. The method
+ * searches for zone by name.
*
* @param options optional restriction on what fields of {@link ChangeRequest} should be returned
* @return ChangeRequest with server-assigned ID
* @throws DnsException upon failure or if the zone is not found
- * @throws NullPointerException if both zone ID and name are not initialized
*/
public ChangeRequest applyChangeRequest(ChangeRequest changeRequest,
Dns.ChangeRequestOption... options) {
- checkNameOrIdNotNull();
checkNotNull(changeRequest);
- ChangeRequest updated = null;
- if (zoneInfo.id() != null) {
- updated = dns.applyChangeRequest(zoneInfo.id(), changeRequest, options);
- }
- if (updated == null && zoneInfo.name() != null) {
- // zone was not found by id or id is not set at all
- updated = dns.applyChangeRequest(zoneInfo.name(), changeRequest, options);
- }
- return updated;
+ return dns.applyChangeRequest(zoneInfo.name(), changeRequest, options);
}
/**
* Retrieves an updated information about a change request previously submitted to be applied to
- * this zone. First searches for the zone by ID and if not found then by name. Returns a {@link
- * ChangeRequest} if found and {@code null} is the zone or the change request was not found.
+ * this zone. Returns a {@link ChangeRequest} or {@code null} if the change request was not found.
+ * Throws {@link DnsException} if the zone is not found.
*
* @param options optional restriction on what fields of {@link ChangeRequest} should be returned
* @return updated ChangeRequest
* @throws DnsException upon failure or if the zone is not found
- * @throws NullPointerException if both zone ID and name are not initialized
- * @throws NullPointerException if the change request does not have initialized id
+ * @throws NullPointerException if {@code changeRequestId} is null
*/
public ChangeRequest getChangeRequest(String changeRequestId,
Dns.ChangeRequestOption... options) {
- checkNameOrIdNotNull();
checkNotNull(changeRequestId);
- ChangeRequest updated = null;
- if (zoneInfo.id() != null) {
- updated = dns.getChangeRequest(zoneInfo.id(), changeRequestId, options);
- }
- if (updated == null && zoneInfo.name() != null) {
- // zone was not found by id or id is not set at all
- updated = dns.getChangeRequest(zoneInfo.name(), changeRequestId, options);
- }
- return updated;
+ return dns.getChangeRequest(zoneInfo.name(), changeRequestId, options);
}
/**
- * Retrieves all change requests for this zone. First searches for the zone by ID and if not found
- * then by name. Returns a page of {@link ChangeRequest}s or {@code null} if the zone is not
- * found.
+ * Retrieves all change requests for this zone. The method searches for zone by name. Returns a
+ * page of {@link ChangeRequest}s.
*
* @param options optional restriction on listing and fields to be returned
* @return a page of change requests
* @throws DnsException upon failure or if the zone is not found
- * @throws NullPointerException if both zone ID and name are not initialized
*/
public Page listChangeRequests(Dns.ChangeRequestListOption... options) {
- checkNameOrIdNotNull();
- Page changeRequests = null;
- if (zoneInfo.id() != null) {
- changeRequests = dns.listChangeRequests(zoneInfo.id(), options);
- }
- if (changeRequests == null && zoneInfo.name() != null) {
- // zone was not found by id or id is not set at all
- changeRequests = dns.listChangeRequests(zoneInfo.name(), options);
- }
- return changeRequests;
- }
-
- /**
- * Check that at least one of name and ID are initialized and throw and exception if not.
- */
- private void checkNameOrIdNotNull() {
- checkArgument(zoneInfo != null && (zoneInfo.id() != null || zoneInfo.name() != null),
- "Both zoneInfo.id and zoneInfo.name are null. This is should never happen.");
+ return dns.listChangeRequests(zoneInfo.name(), options);
}
/**
diff --git a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java
index 524309eaa8e9..a15518ae166f 100644
--- a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java
+++ b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java
@@ -41,7 +41,7 @@ public class ZoneInfo implements Serializable {
private static final long serialVersionUID = 201601191647L;
private final String name;
- private final BigInteger id;
+ private final String id;
private final Long creationTimeMillis;
private final String dnsName;
private final String description;
@@ -53,32 +53,17 @@ public class ZoneInfo implements Serializable {
*/
public static class Builder {
private String name;
- private BigInteger id;
+ private String id;
private Long creationTimeMillis;
private String dnsName;
private String description;
private String nameServerSet;
private List nameServers = new LinkedList<>();
- /**
- * Returns an empty builder for {@code ZoneInfo}. We use it internally in {@code toPb()}.
- */
- private Builder() {
- }
-
- private Builder(BigInteger id) {
- this.id = checkNotNull(id);
- }
-
private Builder(String name) {
this.name = checkNotNull(name);
}
- private Builder(String name, BigInteger id) {
- this.name = checkNotNull(name);
- this.id = checkNotNull(id);
- }
-
/**
* Creates a builder from an existing ZoneInfo object.
*/
@@ -103,7 +88,7 @@ public Builder name(String name) {
/**
* Sets an id for the zone which is assigned to the zone by the server.
*/
- Builder id(BigInteger id) {
+ Builder id(String id) {
this.id = id;
return this;
}
@@ -178,20 +163,6 @@ public static Builder builder(String name) {
return new Builder(name);
}
- /**
- * Returns a builder for {@code ZoneInfo} with an assigned {@code id}.
- */
- public static Builder builder(BigInteger id) {
- return new Builder(id);
- }
-
- /**
- * Returns a builder for {@code ZoneInfo} with an assigned {@code name} and {@code id}.
- */
- public static Builder builder(String name, BigInteger id) {
- return new Builder(name, id);
- }
-
/**
* Returns the user-defined name of the zone.
*/
@@ -202,7 +173,7 @@ public String name() {
/**
* Returns the read-only zone id assigned by the server.
*/
- public BigInteger id() {
+ public String id() {
return id;
}
@@ -255,7 +226,7 @@ com.google.api.services.dns.model.ManagedZone toPb() {
pb.setDescription(this.description());
pb.setDnsName(this.dnsName());
if (this.id() != null) {
- pb.setId(this.id());
+ pb.setId(new BigInteger(this.id()));
}
pb.setName(this.name());
pb.setNameServers(this.nameServers());
@@ -269,7 +240,7 @@ com.google.api.services.dns.model.ManagedZone toPb() {
}
static ZoneInfo fromPb(com.google.api.services.dns.model.ManagedZone pb) {
- Builder builder = new Builder();
+ Builder builder = new Builder(pb.getName());
if (pb.getDescription() != null) {
builder.description(pb.getDescription());
}
@@ -277,10 +248,7 @@ static ZoneInfo fromPb(com.google.api.services.dns.model.ManagedZone pb) {
builder.dnsName(pb.getDnsName());
}
if (pb.getId() != null) {
- builder.id(pb.getId());
- }
- if (pb.getName() != null) {
- builder.name(pb.getName());
+ builder.id(pb.getId().toString());
}
if (pb.getNameServers() != null) {
builder.nameServers(pb.getNameServers());
diff --git a/gcloud-java-dns/src/main/java/com/google/gcloud/spi/DefaultDnsRpc.java b/gcloud-java-dns/src/main/java/com/google/gcloud/spi/DefaultDnsRpc.java
index 73e6ab4036ec..6ed9c7e0f216 100644
--- a/gcloud-java-dns/src/main/java/com/google/gcloud/spi/DefaultDnsRpc.java
+++ b/gcloud-java-dns/src/main/java/com/google/gcloud/spi/DefaultDnsRpc.java
@@ -2,9 +2,9 @@
import static com.google.gcloud.spi.DnsRpc.ListResult.of;
import static com.google.gcloud.spi.DnsRpc.Option.DNS_NAME;
-import static com.google.gcloud.spi.DnsRpc.Option.NAME;
import static com.google.gcloud.spi.DnsRpc.Option.DNS_TYPE;
import static com.google.gcloud.spi.DnsRpc.Option.FIELDS;
+import static com.google.gcloud.spi.DnsRpc.Option.NAME;
import static com.google.gcloud.spi.DnsRpc.Option.PAGE_SIZE;
import static com.google.gcloud.spi.DnsRpc.Option.PAGE_TOKEN;
import static com.google.gcloud.spi.DnsRpc.Option.SORTING_ORDER;
@@ -54,9 +54,12 @@ public DefaultDnsRpc(DnsOptions options) {
}
@Override
- public ManagedZone create(ManagedZone zone) throws DnsException {
+ public ManagedZone create(ManagedZone zone, Map