Skip to content

Commit

Permalink
Merge pull request #629 from mderka/rpc-default
Browse files Browse the repository at this point in the history
Merges Zone and ZoneInfo. Adds implementation of Dns.
  • Loading branch information
aozarov committed Feb 9, 2016
2 parents b128548 + ee5bb8f commit 86b4356
Show file tree
Hide file tree
Showing 10 changed files with 985 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

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

private static final Function<ResourceRecordSet, DnsRecord> FROM_PB_FUNCTION =
new Function<com.google.api.services.dns.model.ResourceRecordSet, DnsRecord>() {
static final Function<Change, ChangeRequest> FROM_PB_FUNCTION =
new Function<Change, ChangeRequest>() {
@Override
public DnsRecord apply(com.google.api.services.dns.model.ResourceRecordSet pb) {
return DnsRecord.fromPb(pb);
public ChangeRequest apply(com.google.api.services.dns.model.Change pb) {
return ChangeRequest.fromPb(pb);
}
};
private static final Function<DnsRecord, ResourceRecordSet> TO_PB_FUNCTION =
new Function<DnsRecord, ResourceRecordSet>() {
@Override
public com.google.api.services.dns.model.ResourceRecordSet apply(DnsRecord error) {
return error.toPb();
}
};
private static final long serialVersionUID = -8703939628990291682L;
private static final long serialVersionUID = -9027378042756366333L;
private final List<DnsRecord> additions;
private final List<DnsRecord> deletions;
private final String id;
Expand Down Expand Up @@ -274,9 +267,9 @@ com.google.api.services.dns.model.Change toPb() {
pb.setStatus(status().name().toLowerCase());
}
// set a list of additions
pb.setAdditions(Lists.transform(additions(), TO_PB_FUNCTION));
pb.setAdditions(Lists.transform(additions(), DnsRecord.TO_PB_FUNCTION));
// set a list of deletions
pb.setDeletions(Lists.transform(deletions(), TO_PB_FUNCTION));
pb.setDeletions(Lists.transform(deletions(), DnsRecord.TO_PB_FUNCTION));
return pb;
}

Expand All @@ -293,10 +286,10 @@ static ChangeRequest fromPb(com.google.api.services.dns.model.Change pb) {
builder.status(ChangeRequest.Status.valueOf(pb.getStatus().toUpperCase()));
}
if (pb.getDeletions() != null) {
builder.deletions(Lists.transform(pb.getDeletions(), FROM_PB_FUNCTION));
builder.deletions(Lists.transform(pb.getDeletions(), DnsRecord.FROM_PB_FUNCTION));
}
if (pb.getAdditions() != null) {
builder.additions(Lists.transform(pb.getAdditions(), FROM_PB_FUNCTION));
builder.additions(Lists.transform(pb.getAdditions(), DnsRecord.FROM_PB_FUNCTION));
}
return builder.build();
}
Expand Down
10 changes: 5 additions & 5 deletions gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface Dns extends Service<DnsOptions> {
* The fields of a project.
*
* <p>These values can be used to specify the fields to include in a partial response when calling
* {@link Dns#getProjectInfo(ProjectOption...)}. Project ID is always returned, even if not
* {@link Dns#getProject(ProjectOption...)}. Project ID is always returned, even if not
* specified.
*/
enum ProjectField {
Expand Down Expand Up @@ -419,7 +419,7 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
/**
* Creates a new zone.
*
* <p>Returns {@link ZoneInfo} object representing the new zone's information. In addition to the
* <p>Returns {@link Zone} 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 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
Expand All @@ -429,7 +429,7 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
* @see <a href="https://cloud.google.com/dns/api/v1/managedZones/create">Cloud DNS Managed Zones:
* create</a>
*/
ZoneInfo create(ZoneInfo zoneInfo, ZoneOption... options);
Zone create(ZoneInfo zoneInfo, ZoneOption... options);

/**
* Returns the zone by the specified zone name. Returns {@code null} if the zone is not found. The
Expand All @@ -439,7 +439,7 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
* @see <a href="https://cloud.google.com/dns/api/v1/managedZones/get">Cloud DNS Managed Zones:
* get</a>
*/
ZoneInfo getZone(String zoneName, ZoneOption... options);
Zone getZone(String zoneName, ZoneOption... options);

/**
* Lists the zones inside the project.
Expand Down Expand Up @@ -485,7 +485,7 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) {
* @throws DnsException upon failure
* @see <a href="https://cloud.google.com/dns/api/v1/projects/get">Cloud DNS Projects: get</a>
*/
ProjectInfo getProjectInfo(ProjectOption... fields);
ProjectInfo getProject(ProjectOption... fields);

/**
* Submits a change request for the specified zone. The returned object contains the following
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.google.gcloud.dns;

import com.google.gcloud.BaseServiceException;
import com.google.gcloud.RetryHelper.RetryHelperException;
import com.google.gcloud.RetryHelper.RetryInterruptedException;

import java.io.IOException;

Expand All @@ -31,5 +33,21 @@ public DnsException(IOException exception) {
super(exception, true);
}

public DnsException(int code, String message) {
super(code, message, null, true);
}

/**
* Translate RetryHelperException to the DnsException that caused the error. This method will
* always throw an exception.
*
* @throws DnsException when {@code ex} was caused by a {@code DnsException}
* @throws RetryInterruptedException when {@code ex} is a {@code RetryInterruptedException}
*/
static DnsException translateAndThrow(RetryHelperException ex) {
BaseServiceException.translateAndPropagateIfPossible(ex);
throw new DnsException(UNKNOWN_CODE, ex.getMessage());
}

//TODO(mderka) Add translation and retry functionality. Created issue #593.
}
Loading

0 comments on commit 86b4356

Please sign in to comment.