Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
2bf4925
Initial project for Google Cloud DNS in gcloud-java
mderka Jan 16, 2016
fe4e137
Added DnsRecord as a part of the basic data model.
mderka Jan 16, 2016
f652277
Implemented comments by @mziccard
mderka Jan 19, 2016
b29945f
Second round of comments from @mziccard
mderka Jan 20, 2016
1fc0e32
Implemented comments by @aozarov. Also removed incomplete
mderka Jan 21, 2016
01662be
Implements comments by @ajkannan
mderka Jan 21, 2016
1c65715
Removed the method for removing a record by index.
mderka Jan 21, 2016
f994057
Another round of comments from @aozarov.
mderka Jan 22, 2016
7493f1a
Merge pull request #559 from mderka/gcloud-dns
aozarov Jan 22, 2016
1c69b05
Merge pull request #574 from GoogleCloudPlatform/master
mderka Jan 22, 2016
e8dd142
Created a ManagedZoneInfo class as part of the model.
mderka Jan 20, 2016
c95c3aa
Implemented comments by @aozarov.
mderka Jan 23, 2016
dacea19
Another round of comments from @aozarov.
mderka Jan 25, 2016
20f325b
Merge pull request #575 from mderka/dns-managed-zone
aozarov Jan 26, 2016
273b441
Implemented ChangeRequest.
mderka Jan 26, 2016
35cfd61
Added test for ChangeRequest.
mderka Jan 26, 2016
6f9e1c0
Implements comments from @ajkannan and @aozarov.
mderka Jan 27, 2016
438c05a
Merge pull request #587 from mderka/dns-change
mderka Jan 27, 2016
9b4ff48
Added ProjectInfo.
mderka Jan 26, 2016
a47158d
Fixed serialization, javadoc and checkstyle.
mderka Jan 27, 2016
9db27d4
Implements comment from @aozarov and @ajkannan into ProjectInfo.
mderka Jan 28, 2016
4412c73
Changed documentation @code to @link where applicable.
mderka Jan 28, 2016
2c87334
Merge pull request #590 from mderka/dns-project
mderka Jan 28, 2016
81a46d8
Renames ManagedZone to Zone. Acommodates codecheck. Fixes #579.
mderka Jan 28, 2016
c364ff3
Modified ttl to accept time unit. Fixed #581.
mderka Jan 28, 2016
7bcff48
Implemented comments by @aozarov.
mderka Jan 28, 2016
a2fdb69
Merge pull request #592 from mderka/dns-polishing
mderka Jan 28, 2016
f9b6f6a
Added DnsService interface.
mderka Jan 28, 2016
4fdc8ee
Added AbstractOption.
mderka Jan 28, 2016
06becd8
Added DnsException.
mderka Jan 28, 2016
81cedc4
Added DnsServiceRpc.
mderka Jan 29, 2016
bf1361c
Added DnsServiceOptions and necessary dependencies.
mderka Jan 29, 2016
465f532
Modified DnsException to pass tests.
mderka Jan 29, 2016
a8bee9c
Implements comments by @aozarov.
mderka Jan 30, 2016
762483b
Makes ProjectInfo.Quota serializable. Fixed #599.
mderka Jan 30, 2016
e17bedb
Implemented DnsOptions up to two unavailable classes.
mderka Jan 30, 2016
adf5c1c
Added test for AbstractOption.
mderka Feb 1, 2016
a9cc927
Implemented comments by @aozarov. Added test for option accessors.
mderka Feb 1, 2016
6ecde35
Comments by @aozarov second round.
mderka Feb 2, 2016
c5566eb
Merge pull request #597 from mderka/dns-options
mderka Feb 2, 2016
a69101a
Added Dns methods. Fixes #596. Added Zone and ZoneTest
mderka Feb 2, 2016
e083dfd
Fixed documentation and some code formatting. Declared exceptions to be
mderka Feb 2, 2016
d6daf09
Adjusted documentation, removed getProjectId and getProjectNumber
mderka Feb 3, 2016
e3686e3
Merge pull request #606 from mderka/dns-options
mderka Feb 3, 2016
0338ead
Completes DnsRpc interface by adding methods and doc.
mderka Feb 3, 2016
bc4b820
Implements DefaultDnsRpc. Progress in #595.
mderka Feb 3, 2016
896de75
Fixed documentation and null returns from rpc.
mderka Feb 3, 2016
3ae0f21
Change Tuple<X,Y> into ListResult<X>, added NAME option.
mderka Feb 4, 2016
35dbb34
Merge pull request #616 from mderka/dns-options
aozarov Feb 4, 2016
71f5ae2
Makes name of Zone mandatory and removes id-based methods.
mderka Feb 4, 2016
3183f4a
Added field options for zone create method.
mderka Feb 4, 2016
4057dcd
Fixed doc after refactoring. Made zone name mandatory in fields.
mderka Feb 5, 2016
d722635
Javadoc fixed.
mderka Feb 5, 2016
b128548
Merge pull request #620 from mderka/dns-options
mderka Feb 5, 2016
5be58b3
Makes Zone subclass of ZoneInfo. Fixes #605.
mderka Feb 7, 2016
d1c4512
Added implementation of Dns and test. Renamed getProjectInfo.
mderka Feb 7, 2016
c0c5451
Included options attribute to Zone. Fixed symmetry of toPb and fromPb.
mderka Feb 8, 2016
ee5bb8f
Removed zone.get() and optimized retries.
mderka Feb 9, 2016
86b4356
Merge pull request #629 from mderka/rpc-default
aozarov Feb 9, 2016
db52e09
Made nameServerSet read only and setters package private.
mderka Feb 9, 2016
fa081ac
Merge pull request #633 from mderka/rpc-default
mderka Feb 9, 2016
c3e3549
Added retryable errors.
mderka Mar 1, 2016
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
Prev Previous commit
Next Next commit
Created a ManagedZoneInfo class as part of the model.
  • Loading branch information
mderka committed Jan 22, 2016
commit e8dd142fb0a6db4322fb83b79e999d97bd88e94e
Original file line number Diff line number Diff line change
@@ -0,0 +1,334 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.gcloud.dns;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;

import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

/**
* This class is a container for the managed zone metainformation. Managed zone is a resource that
* represents a DNS zone hosted by the Cloud DNS service. See <a href="https://cloud.google.com/dns/api/v1/managedZones">Google
* Cloud DNS documentation</a> for more information.
*/
public class ManagedZoneInfo implements Serializable {

private static final long serialVersionUID = 201601191647L;
private final String name;
private final Long id;
private final Long creationTimeMillis;
private final String dnsName;
private final String description;
private final String nameServerSet;
private final List<String> nameServers;

/**
* A builder for {@code ManagedZoneInfo}.
*/
public static class Builder {
private String name;
private Long id;
private Long creationTimeMillis;
private String dnsName;
private String description;
private String nameServerSet;
private List<String> nameServers = new LinkedList<>();

private Builder() {
}

private Builder(Long id) {
this.id = checkNotNull(id);
}

private Builder(String name) {
this.name = checkNotNull(name);
}

private Builder(String name, Long id) {
this.name = checkNotNull(name);
this.id = checkNotNull(id);
}

/**
* Creates a builder from an existing ManagedZoneInfo object.
*/
Builder(ManagedZoneInfo info) {
this.name = info.name;
this.id = info.id;
this.creationTimeMillis = info.creationTimeMillis;
this.dnsName = info.dnsName;
this.description = info.description;
this.nameServerSet = info.nameServerSet;
this.nameServers.addAll(info.nameServers);
}

/**
* Sets a mandatory user-provided name for the zone. It must be unique within the project.
*/
public Builder name(String name) {
this.name = checkNotNull(name);
return this;
}

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

/**
* Sets the time when this managed zone was created.
*/
Builder creationTimeMillis(long creationTimeMillis) {
checkArgument(creationTimeMillis >= 0, "The timestamp cannot be negative.");
this.creationTimeMillis = creationTimeMillis;
return this;
}

/**
* Sets a mandatory DNS name of this managed 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 (this limit is posed by Google Cloud DNS; gcloud-java does not enforce the limit)
* which has no effect on the managed 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.
*/
public Builder nameServerSet(String nameServerSet) {
// todo(mderka) add more to the doc when questions are answered by the service owner
this.nameServerSet = checkNotNull(nameServerSet);
return this;
}

/**
* 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.
*/
Builder nameServers(List<String> nameServers) {
this.nameServers.addAll(checkNotNull(nameServers));
return this;
}

/**
* Removes all the nameservers from the list.
*/
Builder clearNameServers() {
this.nameServers.clear();
return this;
}

/**
* Builds the instance of ManagedZoneInfo based on the information set here.
*/
public ManagedZoneInfo build() {
return new ManagedZoneInfo(this);
}
}

private ManagedZoneInfo(Builder builder) {
this.name = builder.name;
this.id = builder.id;
this.creationTimeMillis = builder.creationTimeMillis;
this.dnsName = builder.dnsName;
this.description = builder.description;
this.nameServerSet = builder.nameServerSet;
this.nameServers = ImmutableList.copyOf(builder.nameServers);
}

/**
* Returns a builder for {@code ManagedZoneInfo} 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}.
*/
public static Builder builder(Long id) {
return new Builder(id);
}

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

/**
* Returns an empty builder for {@code ManagedZoneInfo}. We use it internally in {@code toPb()}.
*/
private static Builder builder() {
return new Builder();
}

/**
* Returns the user-defined name of the managed zone.
*/
public String name() {
return name;
}

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

/**
* Returns the time when this time that this managed zone was created on the server.
*/
public Long creationTimeMillis() {
return creationTimeMillis;
}

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

/**
* Returns the description of this managed zone. This is at most 1024 long mandatory string
* provided by the user.
*/
public String description() {
return description;
}

/**
* Returns the optionally specified set of DNS name servers that all host this managed 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.
*/
public List<String> nameServers() {
return nameServers;
}

/**
* Returns a builder for {@code ManagedZoneInfo} prepopulated with the metadata of this managed
* zone.
*/
public Builder toBuilder() {
return new Builder(this);
}

com.google.api.services.dns.model.ManagedZone toPb() {
com.google.api.services.dns.model.ManagedZone pb =
new com.google.api.services.dns.model.ManagedZone();
pb.setDescription(this.description());
pb.setDnsName(this.dnsName());
if (this.id() != null) {
pb.setId(BigInteger.valueOf(this.id()));
}
pb.setName(this.name());
pb.setNameServers(this.nameServers());
pb.setNameServerSet(this.nameServerSet());
if (this.creationTimeMillis() != null) {
pb.setCreationTime(ISODateTimeFormat.dateTime()
.withZoneUTC()
.print(this.creationTimeMillis()));
}
return pb;
}

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

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

@Override
public int hashCode() {
return Objects.hash(name, id, creationTimeMillis, dnsName,
description, nameServerSet, nameServers);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("name", name())
.add("id", id())
.add("description", description())
.add("dnsName", dnsName())
.add("nameServerSet", nameServerSet())
.add("nameServers", nameServers())
.toString();
}
}
Loading