Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed ManagedZoneInfo to ZoneInfo and added time units for ttl. #592

Merged
merged 3 commits into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/**
* A class representing an atomic update to a collection of {@link DnsRecord}s within a {@code
* ManagedZone}.
* Zone}.
*
* @see <a href="https://cloud.google.com/dns/api/v1/changes">Google Cloud DNS documentation</a>
*/
Expand Down Expand Up @@ -102,7 +102,7 @@ public Builder additions(List<DnsRecord> additions) {
this.additions = Lists.newLinkedList(checkNotNull(additions));
return this;
}

/**
* Sets a collection of {@link DnsRecord}s which are to be deleted from the zone upon executing
* this {@code ChangeRequest}.
Expand Down
30 changes: 20 additions & 10 deletions gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
* A class that represents a Google Cloud DNS record set.
*
* <p>A {@code DnsRecord} is the unit of data that will be returned by the DNS servers upon a DNS
* request for a specific domain. The {@code DnsRecord} holds the current state of the DNS records
* that make up a managed zone. You can read the records but you cannot modify them directly.
* Rather, you edit the records in a managed zone by creating a ChangeRequest.
* that make up a zone. You can read the records but you cannot modify them directly. Rather, you
* edit the records in a zone by creating a ChangeRequest.
*
* @see <a href="https://cloud.google.com/dns/api/v1/resourceRecordSets">Google Cloud DNS
* documentation</a>
Expand All @@ -44,7 +45,7 @@ public class DnsRecord implements Serializable {
private static final long serialVersionUID = 2016011914302204L;
private final String name;
private final List<String> rrdatas;
private final Integer ttl;
private final Integer ttl; // this is in seconds
private final Type type;

/**
Expand Down Expand Up @@ -176,14 +177,23 @@ public Builder name(String name) {
}

/**
* Sets the number of seconds that this record can be cached by resolvers. This number must be
* non-negative.
* Sets the time that this record can be cached by resolvers. This number must be non-negative.
* The maximum duration must be equivalent to at most {@link Integer#MAX_VALUE} seconds.
*
* @param ttl A non-negative number of seconds
* @param duration A non-negative number of time units
* @param unit The unit of the ttl parameter
*/
public Builder ttl(int ttl) {
checkArgument(ttl >= 0, "TTL cannot be negative. The supplied value was %s.", ttl);
this.ttl = ttl;
public Builder ttl(int duration, TimeUnit unit) {
checkArgument(duration >= 0,
"Duration cannot be negative. The supplied value was %s.", duration);
checkNotNull(unit);
// convert to seconds and check that we are not overflowing int
// we cannot do that because pb does not support it
long converted = unit.toSeconds(duration);

This comment was marked as spam.

checkArgument(converted <= Integer.MAX_VALUE,
"The duration converted to seconds is out of range of int. The value converts to %s sec.",
converted);
ttl = (int) converted;
return this;
}

Expand Down Expand Up @@ -278,7 +288,7 @@ static DnsRecord fromPb(com.google.api.services.dns.model.ResourceRecordSet pb)
builder.records(pb.getRrdatas());
}
if (pb.getTtl() != null) {
builder.ttl(pb.getTtl());
builder.ttl(pb.getTtl(), TimeUnit.SECONDS);
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/**
* The class provides the Google Cloud DNS information associated with this project. A project is a
* top level container for resources including {@code ManagedZone}s. Projects can be created only in
* top level container for resources including {@code Zone}s. Projects can be created only in
* the APIs console.
*
* @see <a href="https://cloud.google.com/dns/api/v1/projects">Google Cloud DNS documentation</a>
Expand Down Expand Up @@ -75,7 +75,7 @@ public static class Quota {
}

/**
* Returns the maximum allowed number of managed zones in the project.
* Returns the maximum allowed number of zones in the project.
*/
public int zones() {
return zones;
Expand Down Expand Up @@ -104,7 +104,7 @@ public int rrsetDeletionsPerChange() {
}

/**
* Returns the maximum allowed number of {@link DnsRecord}s per {@link ManagedZoneInfo} in the
* Returns the maximum allowed number of {@link DnsRecord}s per {@link ZoneInfo} in the
* project.
*/
public int rrsetsPerManagedZone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
import java.util.Objects;

/**
* A {@code ManagedZone} represents a DNS zone hosted by the Google Cloud DNS service. A zone is a
* subtree of the DNS namespace under one administrative responsibility. See <a
* A {@code Zone} represents a DNS zone hosted by the Google Cloud DNS service. A zone is a subtree
* of the DNS namespace under one administrative responsibility. See <a
* href="https://cloud.google.com/dns/api/v1/managedZones">Google Cloud DNS documentation</a> for
* more information.
*/
public class ManagedZoneInfo implements Serializable {
public class ZoneInfo implements Serializable {

private static final long serialVersionUID = 201601191647L;
private final String name;
Expand All @@ -49,7 +49,7 @@ public class ManagedZoneInfo implements Serializable {
private final List<String> nameServers;

/**
* A builder for {@code ManagedZoneInfo}.
* A builder for {@code ZoneInfo}.
*/
public static class Builder {
private String name;
Expand All @@ -61,8 +61,7 @@ public static class Builder {
private List<String> nameServers = new LinkedList<>();

/**
* Returns an empty builder for {@code ManagedZoneInfo}. We use it internally in {@code
* toPb()}.
* Returns an empty builder for {@code ZoneInfo}. We use it internally in {@code toPb()}.
*/
private Builder() {
}
Expand All @@ -81,9 +80,9 @@ private Builder(String name, BigInteger id) {
}

/**
* Creates a builder from an existing ManagedZoneInfo object.
* Creates a builder from an existing ZoneInfo object.
*/
Builder(ManagedZoneInfo info) {
Builder(ZoneInfo info) {
this.name = info.name;
this.id = info.id;
this.creationTimeMillis = info.creationTimeMillis;
Expand All @@ -102,42 +101,41 @@ public Builder name(String name) {
}

/**
* Sets an id for the managed zone which is assigned to the managed zone by the server.
* Sets an id for the zone which is assigned to the zone by the server.
*/
Builder id(BigInteger id) {
this.id = id;
return this;
}

/**
* Sets the time when this managed zone was created.
* Sets the time when this zone was created.
*/
Builder creationTimeMillis(long creationTimeMillis) {
this.creationTimeMillis = creationTimeMillis;
return this;
}

/**
* Sets a mandatory DNS name of this managed zone, for instance "example.com.".
* Sets a mandatory DNS name of this zone, for instance "example.com.".
*/
public Builder dnsName(String dnsName) {
this.dnsName = checkNotNull(dnsName);
return this;
}

/**
* Sets a mandatory description for this managed zone. The value is a string of at most 1024
* characters which has no effect on the managed zone's function.
* Sets a mandatory description for this zone. The value is a string of at most 1024 characters
* which has no effect on the zone's function.
*/
public Builder description(String description) {
this.description = checkNotNull(description);
return this;
}

/**
* Optionally specifies the NameServerSet for this managed zone. A NameServerSet is a set of DNS
* name servers that all host the same ManagedZones. Most users will not need to specify this
* value.
* Optionally specifies the NameServerSet for this zone. A NameServerSet is a set of DNS name
* servers that all host the same zones. Most users will not need to specify this value.
*/
public Builder nameServerSet(String nameServerSet) {
// todo(mderka) add more to the doc when questions are answered by the service owner
Expand All @@ -146,8 +144,8 @@ public Builder nameServerSet(String nameServerSet) {
}

/**
* Sets a list of servers that hold the information about the managed zone. This information is
* provided by Google Cloud DNS and is read only.
* Sets a list of servers that hold the information about the zone. This information is provided
* by Google Cloud DNS and is read only.
*/
Builder nameServers(List<String> nameServers) {
checkNotNull(nameServers);
Expand All @@ -156,14 +154,14 @@ Builder nameServers(List<String> nameServers) {
}

/**
* Builds the instance of {@code ManagedZoneInfo} based on the information set by this builder.
* Builds the instance of {@code ZoneInfo} based on the information set by this builder.
*/
public ManagedZoneInfo build() {
return new ManagedZoneInfo(this);
public ZoneInfo build() {
return new ZoneInfo(this);
}
}

private ManagedZoneInfo(Builder builder) {
private ZoneInfo(Builder builder) {
this.name = builder.name;
this.id = builder.id;
this.creationTimeMillis = builder.creationTimeMillis;
Expand All @@ -174,80 +172,78 @@ private ManagedZoneInfo(Builder builder) {
}

/**
* Returns a builder for {@code ManagedZoneInfo} with an assigned {@code name}.
* Returns a builder for {@code ZoneInfo} with an assigned {@code name}.
*/
public static Builder builder(String name) {
return new Builder(name);
}

/**
* Returns a builder for {@code ManagedZoneInfo} with an assigned {@code id}.
* 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 ManagedZoneInfo} with an assigned {@code name} and {@code 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 managed zone.
* Returns the user-defined name of the zone.
*/
public String name() {
return name;
}

/**
* Returns the read-only managed zone id assigned by the server.
* Returns the read-only zone id assigned by the server.
*/
public BigInteger id() {
return id;
}

/**
* Returns the time when this time that this managed zone was created on the server.
* Returns the time when this time that this zone was created on the server.

This comment was marked as spam.

This comment was marked as spam.

*/
public Long creationTimeMillis() {
return creationTimeMillis;
}

/**
* Returns the DNS name of this managed zone, for instance "example.com.".
* Returns the DNS name of this zone, for instance "example.com.".
*/
public String dnsName() {
return dnsName;
}

/**
* Returns the description of this managed zone.
* Returns the description of this zone.
*/
public String description() {
return description;
}

/**
* Returns the optionally specified set of DNS name servers that all host this managed zone.
* Returns the optionally specified set of DNS name servers that all host this zone.
*/
public String nameServerSet() {
// todo(mderka) update this doc after finding out more about this from the service owners
return nameServerSet;
}

/**
* The nameservers that the managed zone should be delegated to. This is defined by the Google DNS
* cloud.
* The nameservers that the zone should be delegated to. This is defined by the Google DNS cloud.
*/
public List<String> nameServers() {
return nameServers;
}

/**
* Returns a builder for {@code ManagedZoneInfo} prepopulated with the metadata of this managed
* zone.
* Returns a builder for {@code ZoneInfo} prepopulated with the metadata of this zone.
*/
public Builder toBuilder() {
return new Builder(this);
Expand All @@ -272,35 +268,35 @@ com.google.api.services.dns.model.ManagedZone toPb() {
return pb;
}

static ManagedZoneInfo fromPb(com.google.api.services.dns.model.ManagedZone pb) {
Builder b = new Builder();
static ZoneInfo fromPb(com.google.api.services.dns.model.ManagedZone pb) {
Builder builder = new Builder();
if (pb.getDescription() != null) {
b.description(pb.getDescription());
builder.description(pb.getDescription());
}
if (pb.getDnsName() != null) {
b.dnsName(pb.getDnsName());
builder.dnsName(pb.getDnsName());
}
if (pb.getId() != null) {
b.id(pb.getId());
builder.id(pb.getId());
}
if (pb.getName() != null) {
b.name(pb.getName());
builder.name(pb.getName());
}
if (pb.getNameServers() != null) {
b.nameServers(pb.getNameServers());
builder.nameServers(pb.getNameServers());
}
if (pb.getNameServerSet() != null) {
b.nameServerSet(pb.getNameServerSet());
builder.nameServerSet(pb.getNameServerSet());
}
if (pb.getCreationTime() != null) {
b.creationTimeMillis(DateTime.parse(pb.getCreationTime()).getMillis());
builder.creationTimeMillis(DateTime.parse(pb.getCreationTime()).getMillis());
}
return b.build();
return builder.build();
}

@Override
public boolean equals(Object obj) {
return obj instanceof ManagedZoneInfo && Objects.equals(toPb(), ((ManagedZoneInfo) obj).toPb());
return obj instanceof ZoneInfo && Objects.equals(toPb(), ((ZoneInfo) obj).toPb());
}

@Override
Expand Down
Loading