Skip to content

Commit 86b4356

Browse files
committed
Merge pull request #629 from mderka/rpc-default
Merges Zone and ZoneInfo. Adds implementation of Dns.
2 parents b128548 + ee5bb8f commit 86b4356

File tree

10 files changed

+985
-146
lines changed

10 files changed

+985
-146
lines changed

gcloud-java-dns/src/main/java/com/google/gcloud/dns/ChangeRequest.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

21-
import com.google.api.services.dns.model.ResourceRecordSet;
21+
import com.google.api.services.dns.model.Change;
2222
import com.google.common.base.Function;
2323
import com.google.common.base.MoreObjects;
2424
import com.google.common.collect.ImmutableList;
@@ -40,21 +40,14 @@
4040
*/
4141
public class ChangeRequest implements Serializable {
4242

43-
private static final Function<ResourceRecordSet, DnsRecord> FROM_PB_FUNCTION =
44-
new Function<com.google.api.services.dns.model.ResourceRecordSet, DnsRecord>() {
43+
static final Function<Change, ChangeRequest> FROM_PB_FUNCTION =
44+
new Function<Change, ChangeRequest>() {
4545
@Override
46-
public DnsRecord apply(com.google.api.services.dns.model.ResourceRecordSet pb) {
47-
return DnsRecord.fromPb(pb);
46+
public ChangeRequest apply(com.google.api.services.dns.model.Change pb) {
47+
return ChangeRequest.fromPb(pb);
4848
}
4949
};
50-
private static final Function<DnsRecord, ResourceRecordSet> TO_PB_FUNCTION =
51-
new Function<DnsRecord, ResourceRecordSet>() {
52-
@Override
53-
public com.google.api.services.dns.model.ResourceRecordSet apply(DnsRecord error) {
54-
return error.toPb();
55-
}
56-
};
57-
private static final long serialVersionUID = -8703939628990291682L;
50+
private static final long serialVersionUID = -9027378042756366333L;
5851
private final List<DnsRecord> additions;
5952
private final List<DnsRecord> deletions;
6053
private final String id;
@@ -274,9 +267,9 @@ com.google.api.services.dns.model.Change toPb() {
274267
pb.setStatus(status().name().toLowerCase());
275268
}
276269
// set a list of additions
277-
pb.setAdditions(Lists.transform(additions(), TO_PB_FUNCTION));
270+
pb.setAdditions(Lists.transform(additions(), DnsRecord.TO_PB_FUNCTION));
278271
// set a list of deletions
279-
pb.setDeletions(Lists.transform(deletions(), TO_PB_FUNCTION));
272+
pb.setDeletions(Lists.transform(deletions(), DnsRecord.TO_PB_FUNCTION));
280273
return pb;
281274
}
282275

@@ -293,10 +286,10 @@ static ChangeRequest fromPb(com.google.api.services.dns.model.Change pb) {
293286
builder.status(ChangeRequest.Status.valueOf(pb.getStatus().toUpperCase()));
294287
}
295288
if (pb.getDeletions() != null) {
296-
builder.deletions(Lists.transform(pb.getDeletions(), FROM_PB_FUNCTION));
289+
builder.deletions(Lists.transform(pb.getDeletions(), DnsRecord.FROM_PB_FUNCTION));
297290
}
298291
if (pb.getAdditions() != null) {
299-
builder.additions(Lists.transform(pb.getAdditions(), FROM_PB_FUNCTION));
292+
builder.additions(Lists.transform(pb.getAdditions(), DnsRecord.FROM_PB_FUNCTION));
300293
}
301294
return builder.build();
302295
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public interface Dns extends Service<DnsOptions> {
3636
* The fields of a project.
3737
*
3838
* <p>These values can be used to specify the fields to include in a partial response when calling
39-
* {@link Dns#getProjectInfo(ProjectOption...)}. Project ID is always returned, even if not
39+
* {@link Dns#getProject(ProjectOption...)}. Project ID is always returned, even if not
4040
* specified.
4141
*/
4242
enum ProjectField {
@@ -419,7 +419,7 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
419419
/**
420420
* Creates a new zone.
421421
*
422-
* <p>Returns {@link ZoneInfo} object representing the new zone's information. In addition to the
422+
* <p>Returns {@link Zone} object representing the new zone's information. In addition to the
423423
* name, dns name and description (supplied by the user within the {@code zoneInfo} parameter),
424424
* the returned object can include the following read-only fields supplied by the server: creation
425425
* time, id, and list of name servers. The returned fields can be optionally restricted by
@@ -429,7 +429,7 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
429429
* @see <a href="https://cloud.google.com/dns/api/v1/managedZones/create">Cloud DNS Managed Zones:
430430
* create</a>
431431
*/
432-
ZoneInfo create(ZoneInfo zoneInfo, ZoneOption... options);
432+
Zone create(ZoneInfo zoneInfo, ZoneOption... options);
433433

434434
/**
435435
* Returns the zone by the specified zone name. Returns {@code null} if the zone is not found. The
@@ -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.
@@ -485,7 +485,7 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
485485
* @throws DnsException upon failure
486486
* @see <a href="https://cloud.google.com/dns/api/v1/projects/get">Cloud DNS Projects: get</a>
487487
*/
488-
ProjectInfo getProjectInfo(ProjectOption... fields);
488+
ProjectInfo getProject(ProjectOption... fields);
489489

490490
/**
491491
* Submits a change request for the specified zone. The returned object contains the following

gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsException.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.google.gcloud.dns;
1818

1919
import com.google.gcloud.BaseServiceException;
20+
import com.google.gcloud.RetryHelper.RetryHelperException;
21+
import com.google.gcloud.RetryHelper.RetryInterruptedException;
2022

2123
import java.io.IOException;
2224

@@ -31,5 +33,21 @@ public DnsException(IOException exception) {
3133
super(exception, true);
3234
}
3335

36+
public DnsException(int code, String message) {
37+
super(code, message, null, true);
38+
}
39+
40+
/**
41+
* Translate RetryHelperException to the DnsException that caused the error. This method will
42+
* always throw an exception.
43+
*
44+
* @throws DnsException when {@code ex} was caused by a {@code DnsException}
45+
* @throws RetryInterruptedException when {@code ex} is a {@code RetryInterruptedException}
46+
*/
47+
static DnsException translateAndThrow(RetryHelperException ex) {
48+
BaseServiceException.translateAndPropagateIfPossible(ex);
49+
throw new DnsException(UNKNOWN_CODE, ex.getMessage());
50+
}
51+
3452
//TODO(mderka) Add translation and retry functionality. Created issue #593.
3553
}

0 commit comments

Comments
 (0)