Skip to content

Commit 2035a94

Browse files
committed
---
yaml --- r: 6827 b: refs/heads/tswast-patch-1 c: 5be58b3 h: refs/heads/master i: 6825: ca2bdc2 6823: bea1158
1 parent 40d2336 commit 2035a94

5 files changed

Lines changed: 210 additions & 74 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: b12854832fd42476a4f15fe0150f620bc68ac054
60+
refs/heads/tswast-patch-1: 5be58b3e91cade1d349014122484a29e254ba8f3
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
439439
* @see <a href="https://cloud.google.com/dns/api/v1/managedZones/get">Cloud DNS Managed Zones:
440440
* get</a>
441441
*/
442-
ZoneInfo getZone(String zoneName, ZoneOption... options);
442+
Zone getZone(String zoneName, ZoneOption... options);
443443

444444
/**
445445
* Lists the zones inside the project.

branches/tswast-patch-1/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java

Lines changed: 98 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
import com.google.gcloud.Page;
2222

23-
import java.io.Serializable;
23+
import java.util.List;
24+
import java.util.Objects;
2425

2526
/**
2627
* A Google Cloud DNS Zone object.
@@ -33,20 +34,87 @@
3334
* @see <a href="https://cloud.google.com/dns/zones/">Google Cloud DNS managed zone
3435
* documentation</a>
3536
*/
36-
public class Zone implements Serializable {
37+
public class Zone extends ZoneInfo {
3738

38-
// TODO(mderka) Zone and zoneInfo to be merged. Opened issue #605.
39+
private static final long serialVersionUID = 564454483894599281L;
40+
private transient Dns dns;
3941

40-
private static final long serialVersionUID = 6847890192129375500L;
41-
private final ZoneInfo zoneInfo;
42-
private final Dns dns;
42+
/**
43+
* Builder for {@code Zone}.
44+
*/
45+
public static class Builder extends ZoneInfo.Builder {
46+
private final Dns dns;
47+
private final ZoneInfo.BuilderImpl infoBuilder;
48+
49+
private Builder(Zone zone) {
50+
this.dns = zone.dns;
51+
this.infoBuilder = new ZoneInfo.BuilderImpl(zone);
52+
}
53+
54+
@Override
55+
public Builder name(String name) {
56+
infoBuilder.name(name);
57+
return this;
58+
}
59+
60+
@Override
61+
Builder id(String id) {
62+
infoBuilder.id(id);
63+
return this;
64+
}
65+
66+
@Override
67+
Builder creationTimeMillis(long creationTimeMillis) {
68+
infoBuilder.creationTimeMillis(creationTimeMillis);
69+
return this;
70+
}
71+
72+
@Override
73+
public Builder dnsName(String dnsName) {
74+
infoBuilder.dnsName(dnsName);
75+
return this;
76+
}
77+
78+
@Override
79+
public Builder description(String description) {
80+
infoBuilder.description(description);
81+
return this;
82+
}
83+
84+
@Override
85+
public Builder nameServerSet(String nameServerSet) {
86+
infoBuilder.nameServerSet(nameServerSet);
87+
return this;
88+
}
89+
90+
@Override
91+
Builder nameServers(List<String> nameServers) {
92+
infoBuilder.nameServers(nameServers); // infoBuilder makes a copy
93+
return this;
94+
}
95+
96+
@Override
97+
public Zone build() {
98+
return new Zone(dns, infoBuilder);
99+
}
100+
}
101+
102+
Zone(Dns dns, ZoneInfo.BuilderImpl infoBuilder) {
103+
super(infoBuilder);
104+
this.dns = dns;
105+
}
106+
107+
@Override
108+
public Builder toBuilder() {
109+
return new Builder(this);
110+
}
43111

44112
/**
45113
* Constructs a {@code Zone} object that contains the given {@code zoneInfo}.
46114
*/
47115
public Zone(Dns dns, ZoneInfo zoneInfo) {
48-
this.zoneInfo = checkNotNull(zoneInfo);
49-
this.dns = checkNotNull(dns);
116+
super(new BuilderImpl(zoneInfo));
117+
this.dns = dns;
50118
}
51119

52120
/**
@@ -61,8 +129,7 @@ public Zone(Dns dns, ZoneInfo zoneInfo) {
61129
public static Zone get(Dns dnsService, String zoneName, Dns.ZoneOption... options) {
62130
checkNotNull(zoneName);
63131
checkNotNull(dnsService);
64-
ZoneInfo zoneInfo = dnsService.getZone(zoneName, options);
65-
return zoneInfo == null ? null : new Zone(dnsService, zoneInfo);
132+
return dnsService.getZone(zoneName, options);
66133
}
67134

68135
/**
@@ -73,7 +140,7 @@ public static Zone get(Dns dnsService, String zoneName, Dns.ZoneOption... option
73140
* @throws DnsException upon failure
74141
*/
75142
public Zone reload(Dns.ZoneOption... options) {
76-
return Zone.get(dns, zoneInfo.name(), options);
143+
return dns.getZone(name(), options);
77144
}
78145

79146
/**
@@ -83,7 +150,7 @@ public Zone reload(Dns.ZoneOption... options) {
83150
* @throws DnsException upon failure
84151
*/
85152
public boolean delete() {
86-
return dns.delete(zoneInfo.name());
153+
return dns.delete(name());
87154
}
88155

89156
/**
@@ -94,7 +161,7 @@ public boolean delete() {
94161
* @throws DnsException upon failure or if the zone is not found
95162
*/
96163
public Page<DnsRecord> listDnsRecords(Dns.DnsRecordListOption... options) {
97-
return dns.listDnsRecords(zoneInfo.name(), options);
164+
return dns.listDnsRecords(name(), options);
98165
}
99166

100167
/**
@@ -108,7 +175,7 @@ public Page<DnsRecord> listDnsRecords(Dns.DnsRecordListOption... options) {
108175
public ChangeRequest applyChangeRequest(ChangeRequest changeRequest,
109176
Dns.ChangeRequestOption... options) {
110177
checkNotNull(changeRequest);
111-
return dns.applyChangeRequest(zoneInfo.name(), changeRequest, options);
178+
return dns.applyChangeRequest(name(), changeRequest, options);
112179
}
113180

114181
/**
@@ -124,7 +191,7 @@ public ChangeRequest applyChangeRequest(ChangeRequest changeRequest,
124191
public ChangeRequest getChangeRequest(String changeRequestId,
125192
Dns.ChangeRequestOption... options) {
126193
checkNotNull(changeRequestId);
127-
return dns.getChangeRequest(zoneInfo.name(), changeRequestId, options);
194+
return dns.getChangeRequest(name(), changeRequestId, options);
128195
}
129196

130197
/**
@@ -136,14 +203,7 @@ public ChangeRequest getChangeRequest(String changeRequestId,
136203
* @throws DnsException upon failure or if the zone is not found
137204
*/
138205
public Page<ChangeRequest> listChangeRequests(Dns.ChangeRequestListOption... options) {
139-
return dns.listChangeRequests(zoneInfo.name(), options);
140-
}
141-
142-
/**
143-
* Returns the {@link ZoneInfo} object containing information about this zone.
144-
*/
145-
public ZoneInfo info() {
146-
return zoneInfo;
206+
return dns.listChangeRequests(name(), options);
147207
}
148208

149209
/**
@@ -152,4 +212,19 @@ public ZoneInfo info() {
152212
public Dns dns() {
153213
return this.dns;
154214
}
215+
216+
@Override
217+
public boolean equals(Object obj) {
218+
return obj instanceof Zone && Objects.equals(toPb(), ((Zone) obj).toPb());
219+
}
220+
221+
@Override
222+
public int hashCode() {
223+
return super.hashCode();
224+
}
225+
226+
static Zone fromPb(Dns dns, com.google.api.services.dns.model.ManagedZone zone) {
227+
ZoneInfo info = ZoneInfo.fromPb(zone);
228+
return new Zone(dns, info);
229+
}
155230
}

branches/tswast-patch-1/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,55 @@ public class ZoneInfo implements Serializable {
4949
private final List<String> nameServers;
5050

5151
/**
52-
* A builder for {@code ZoneInfo}.
52+
* Builder for {@code ZoneInfo}.
5353
*/
54-
public static class Builder {
54+
public abstract static class Builder {
55+
/**
56+
* Sets a mandatory user-provided name for the zone. It must be unique within the project.
57+
*/
58+
public abstract Builder name(String name);
59+
60+
/**
61+
* Sets an id for the zone which is assigned to the zone by the server.
62+
*/
63+
abstract Builder id(String id);
64+
65+
/**
66+
* Sets the time when this zone was created.
67+
*/
68+
abstract Builder creationTimeMillis(long creationTimeMillis);
69+
70+
/**
71+
* Sets a mandatory DNS name of this zone, for instance "example.com.".
72+
*/
73+
public abstract Builder dnsName(String dnsName);
74+
75+
/**
76+
* Sets a mandatory description for this zone. The value is a string of at most 1024 characters
77+
* which has no effect on the zone's function.
78+
*/
79+
public abstract Builder description(String description);
80+
81+
/**
82+
* Optionally specifies the NameServerSet for this zone. A NameServerSet is a set of DNS name
83+
* servers that all host the same zones. Most users will not need to specify this value.
84+
*/
85+
public abstract Builder nameServerSet(String nameServerSet);
86+
// todo(mderka) add more to the doc when questions are answered by the service owner
87+
88+
/**
89+
* Sets a list of servers that hold the information about the zone. This information is provided
90+
* by Google Cloud DNS and is read only.
91+
*/
92+
abstract Builder nameServers(List<String> nameServers);
93+
94+
/**
95+
* Builds the instance of {@code ZoneInfo} based on the information set by this builder.
96+
*/
97+
public abstract ZoneInfo build();
98+
}
99+
100+
public static class BuilderImpl extends Builder {
55101
private String name;
56102
private String id;
57103
private Long creationTimeMillis;
@@ -60,14 +106,14 @@ public static class Builder {
60106
private String nameServerSet;
61107
private List<String> nameServers = new LinkedList<>();
62108

63-
private Builder(String name) {
109+
private BuilderImpl(String name) {
64110
this.name = checkNotNull(name);
65111
}
66112

67113
/**
68114
* Creates a builder from an existing ZoneInfo object.
69115
*/
70-
Builder(ZoneInfo info) {
116+
BuilderImpl(ZoneInfo info) {
71117
this.name = info.name;
72118
this.id = info.id;
73119
this.creationTimeMillis = info.creationTimeMillis;
@@ -77,76 +123,56 @@ private Builder(String name) {
77123
this.nameServers.addAll(info.nameServers);
78124
}
79125

80-
/**
81-
* Sets a mandatory user-provided name for the zone. It must be unique within the project.
82-
*/
126+
@Override
83127
public Builder name(String name) {
84128
this.name = checkNotNull(name);
85129
return this;
86130
}
87131

88-
/**
89-
* Sets an id for the zone which is assigned to the zone by the server.
90-
*/
132+
@Override
91133
Builder id(String id) {
92134
this.id = id;
93135
return this;
94136
}
95137

96-
/**
97-
* Sets the time when this zone was created.
98-
*/
138+
@Override
99139
Builder creationTimeMillis(long creationTimeMillis) {
100140
this.creationTimeMillis = creationTimeMillis;
101141
return this;
102142
}
103143

104-
/**
105-
* Sets a mandatory DNS name of this zone, for instance "example.com.".
106-
*/
144+
@Override
107145
public Builder dnsName(String dnsName) {
108146
this.dnsName = checkNotNull(dnsName);
109147
return this;
110148
}
111149

112-
/**
113-
* Sets a mandatory description for this zone. The value is a string of at most 1024 characters
114-
* which has no effect on the zone's function.
115-
*/
150+
@Override
116151
public Builder description(String description) {
117152
this.description = checkNotNull(description);
118153
return this;
119154
}
120155

121-
/**
122-
* Optionally specifies the NameServerSet for this zone. A NameServerSet is a set of DNS name
123-
* servers that all host the same zones. Most users will not need to specify this value.
124-
*/
156+
@Override
125157
public Builder nameServerSet(String nameServerSet) {
126-
// todo(mderka) add more to the doc when questions are answered by the service owner
127158
this.nameServerSet = checkNotNull(nameServerSet);
128159
return this;
129160
}
130161

131-
/**
132-
* Sets a list of servers that hold the information about the zone. This information is provided
133-
* by Google Cloud DNS and is read only.
134-
*/
162+
@Override
135163
Builder nameServers(List<String> nameServers) {
136164
checkNotNull(nameServers);
137165
this.nameServers = Lists.newLinkedList(nameServers);
138166
return this;
139167
}
140168

141-
/**
142-
* Builds the instance of {@code ZoneInfo} based on the information set by this builder.
143-
*/
169+
@Override
144170
public ZoneInfo build() {
145171
return new ZoneInfo(this);
146172
}
147173
}
148174

149-
private ZoneInfo(Builder builder) {
175+
ZoneInfo(BuilderImpl builder) {
150176
this.name = builder.name;
151177
this.id = builder.id;
152178
this.creationTimeMillis = builder.creationTimeMillis;
@@ -160,7 +186,7 @@ private ZoneInfo(Builder builder) {
160186
* Returns a builder for {@code ZoneInfo} with an assigned {@code name}.
161187
*/
162188
public static Builder builder(String name) {
163-
return new Builder(name);
189+
return new BuilderImpl(name);
164190
}
165191

166192
/**
@@ -217,7 +243,7 @@ public List<String> nameServers() {
217243
* Returns a builder for {@code ZoneInfo} prepopulated with the metadata of this zone.
218244
*/
219245
public Builder toBuilder() {
220-
return new Builder(this);
246+
return new BuilderImpl(this);
221247
}
222248

223249
com.google.api.services.dns.model.ManagedZone toPb() {
@@ -240,7 +266,7 @@ com.google.api.services.dns.model.ManagedZone toPb() {
240266
}
241267

242268
static ZoneInfo fromPb(com.google.api.services.dns.model.ManagedZone pb) {
243-
Builder builder = new Builder(pb.getName());
269+
Builder builder = new BuilderImpl(pb.getName());
244270
if (pb.getDescription() != null) {
245271
builder.description(pb.getDescription());
246272
}

0 commit comments

Comments
 (0)