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

Addressed codacy issues in DNS. #850

Merged
merged 3 commits into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion gcloud-java-dns/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java-dns</artifactId>
<packaging>jar</packaging>
<name>GCloud Java DNS</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static ChangeRequest fromPb(Dns dns, String zoneName, Change pb) {
static Function<Change, ChangeRequest> fromPbFunction(final Dns dns, final String zoneName) {
return new Function<Change, ChangeRequest>() {
@Override
public ChangeRequest apply(com.google.api.services.dns.model.Change pb) {
public ChangeRequest apply(Change pb) {

This comment was marked as spam.

This comment was marked as spam.

return ChangeRequest.fromPb(dns, zoneName, pb);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.gcloud.Service;
import com.google.gcloud.dns.spi.DnsRpc;

import java.io.Serializable;
import java.util.List;

/**
Expand Down
61 changes: 29 additions & 32 deletions gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package com.google.gcloud.dns;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.gcloud.RetryHelper.RetryHelperException;
import static com.google.gcloud.RetryHelper.runWithRetries;

import com.google.api.services.dns.model.Change;
import com.google.api.services.dns.model.ManagedZone;
import com.google.api.services.dns.model.Project;
import com.google.api.services.dns.model.ResourceRecordSet;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -121,8 +121,7 @@ private static Page<Zone> listZones(final DnsOptions serviceOptions,
// this differs from the other list operations since zone is functional and requires dns service
Function<ManagedZone, Zone> pbToZoneFunction = new Function<ManagedZone, Zone>() {
@Override
public Zone apply(
com.google.api.services.dns.model.ManagedZone zonePb) {
public Zone apply(ManagedZone zonePb) {
return Zone.fromPb(serviceOptions.service(), zonePb);
}
};
Expand All @@ -142,7 +141,7 @@ public DnsRpc.ListResult<ManagedZone> call() {
? ImmutableList.<Zone>of() : Iterables.transform(result.results(), pbToZoneFunction);
return new PageImpl<>(new ZonePageFetcher(serviceOptions, cursor, optionsMap),
cursor, zones);
} catch (RetryHelperException e) {
} catch (RetryHelper.RetryHelperException e) {
throw DnsException.translateAndThrow(e);
}
}
Expand All @@ -169,10 +168,10 @@ public DnsRpc.ListResult<Change> call() {
Iterable<ChangeRequest> changes = result.results() == null
? ImmutableList.<ChangeRequest>of()
: Iterables.transform(result.results(),
ChangeRequest.fromPbFunction(serviceOptions.service(), zoneName));
ChangeRequest.fromPbFunction(serviceOptions.service(), zoneName));
return new PageImpl<>(new ChangeRequestPageFetcher(zoneName, serviceOptions, cursor,
optionsMap), cursor, changes);
} catch (RetryHelperException e) {
} catch (RetryHelper.RetryHelperException e) {
throw DnsException.translateAndThrow(e);
}
}
Expand Down Expand Up @@ -201,7 +200,7 @@ public DnsRpc.ListResult<ResourceRecordSet> call() {
: Iterables.transform(result.results(), RecordSet.FROM_PB_FUNCTION);
return new PageImpl<>(new DnsRecordPageFetcher(zoneName, serviceOptions, cursor, optionsMap),
cursor, recordSets);
} catch (RetryHelperException e) {
} catch (RetryHelper.RetryHelperException e) {
throw DnsException.translateAndThrow(e);
}
}
Expand All @@ -210,10 +209,10 @@ public DnsRpc.ListResult<ResourceRecordSet> call() {
public Zone create(final ZoneInfo zoneInfo, Dns.ZoneOption... options) {
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
try {
com.google.api.services.dns.model.ManagedZone answer = runWithRetries(
new Callable<com.google.api.services.dns.model.ManagedZone>() {
ManagedZone answer = runWithRetries(
new Callable<ManagedZone>() {
@Override
public com.google.api.services.dns.model.ManagedZone call() {
public ManagedZone call() {
return dnsRpc.create(zoneInfo.toPb(), optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
Expand All @@ -227,10 +226,10 @@ public com.google.api.services.dns.model.ManagedZone call() {
public Zone getZone(final String zoneName, Dns.ZoneOption... options) {
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
try {
com.google.api.services.dns.model.ManagedZone answer = runWithRetries(
new Callable<com.google.api.services.dns.model.ManagedZone>() {
ManagedZone answer = runWithRetries(
new Callable<ManagedZone>() {
@Override
public com.google.api.services.dns.model.ManagedZone call() {
public ManagedZone call() {
return dnsRpc.getZone(zoneName, optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
Expand Down Expand Up @@ -258,10 +257,10 @@ public Boolean call() {
public ProjectInfo getProject(Dns.ProjectOption... fields) {
final Map<DnsRpc.Option, ?> optionsMap = optionMap(fields);
try {
com.google.api.services.dns.model.Project answer = runWithRetries(
new Callable<com.google.api.services.dns.model.Project>() {
Project answer = runWithRetries(
new Callable<Project>() {
@Override
public com.google.api.services.dns.model.Project call() {
public Project call() {
return dnsRpc.getProject(optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
Expand All @@ -276,14 +275,13 @@ public ChangeRequest applyChangeRequest(final String zoneName,
final ChangeRequestInfo changeRequest, ChangeRequestOption... options) {
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
try {
com.google.api.services.dns.model.Change answer =
runWithRetries(
new Callable<com.google.api.services.dns.model.Change>() {
@Override
public com.google.api.services.dns.model.Change call() {
return dnsRpc.applyChangeRequest(zoneName, changeRequest.toPb(), optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
Change answer = runWithRetries(
new Callable<Change>() {
@Override
public Change call() {
return dnsRpc.applyChangeRequest(zoneName, changeRequest.toPb(), optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
return answer == null ? null : ChangeRequest.fromPb(this, zoneName, answer); // not null
} catch (RetryHelper.RetryHelperException ex) {
throw DnsException.translateAndThrow(ex);
Expand All @@ -295,14 +293,13 @@ public ChangeRequest getChangeRequest(final String zoneName, final String change
Dns.ChangeRequestOption... options) {
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
try {
com.google.api.services.dns.model.Change answer =
runWithRetries(
new Callable<com.google.api.services.dns.model.Change>() {
@Override
public com.google.api.services.dns.model.Change call() {
return dnsRpc.getChangeRequest(zoneName, changeRequestId, optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
Change answer = runWithRetries(
new Callable<Change>() {
@Override
public Change call() {
return dnsRpc.getChangeRequest(zoneName, changeRequestId, optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
return answer == null ? null : ChangeRequest.fromPb(this, zoneName, answer);
} catch (RetryHelper.RetryHelperException ex) {
throw DnsException.translateAndThrow(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull;

import com.google.api.services.dns.model.Project;
import com.google.common.base.MoreObjects;

import java.io.Serializable;
Expand Down Expand Up @@ -143,14 +144,13 @@ com.google.api.services.dns.model.Quota toPb() {
}

static Quota fromPb(com.google.api.services.dns.model.Quota pb) {
Quota quota = new Quota(pb.getManagedZones(),
return new Quota(pb.getManagedZones(),
pb.getResourceRecordsPerRrset(),
pb.getRrsetAdditionsPerChange(),
pb.getRrsetDeletionsPerChange(),
pb.getRrsetsPerManagedZone(),
pb.getTotalRrdataSizePerChange()
);
return quota;
}

@Override
Expand Down Expand Up @@ -243,8 +243,8 @@ String id() {
return id;
}

com.google.api.services.dns.model.Project toPb() {
com.google.api.services.dns.model.Project pb = new com.google.api.services.dns.model.Project();
Project toPb() {
Project pb = new Project();
pb.setId(id);
pb.setNumber(number);
if (this.quota != null) {
Expand All @@ -253,7 +253,7 @@ com.google.api.services.dns.model.Project toPb() {
return pb;
}

static ProjectInfo fromPb(com.google.api.services.dns.model.Project pb) {
static ProjectInfo fromPb(Project pb) {
Builder builder = builder();
if (pb.getId() != null) {
builder.id(pb.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,16 @@ public boolean equals(Object obj) {
return obj instanceof RecordSet && Objects.equals(this.toPb(), ((RecordSet) obj).toPb());
}

com.google.api.services.dns.model.ResourceRecordSet toPb() {
com.google.api.services.dns.model.ResourceRecordSet pb =
new com.google.api.services.dns.model.ResourceRecordSet();
ResourceRecordSet toPb() {
ResourceRecordSet pb = new ResourceRecordSet();
pb.setName(this.name());
pb.setRrdatas(this.records());
pb.setTtl(this.ttl());
pb.setType(this.type().name());
return pb;
}

static RecordSet fromPb(com.google.api.services.dns.model.ResourceRecordSet pb) {
static RecordSet fromPb(ResourceRecordSet pb) {
Builder builder = builder(pb.getName(), Type.valueOf(pb.getType()));
if (pb.getRrdatas() != null) {
builder.records(pb.getRrdatas());
Expand Down
7 changes: 4 additions & 3 deletions gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

import com.google.api.services.dns.model.ManagedZone;
import com.google.gcloud.Page;

import java.io.IOException;
Expand Down Expand Up @@ -205,12 +206,12 @@ public int hashCode() {
return Objects.hash(super.hashCode(), options);
}

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
this.dns = options.service();
}

static Zone fromPb(Dns dns, com.google.api.services.dns.model.ManagedZone zone) {
static Zone fromPb(Dns dns, ManagedZone zone) {
ZoneInfo info = ZoneInfo.fromPb(zone);
return new Zone(dns, new ZoneInfo.BuilderImpl(info));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

import com.google.api.services.dns.model.ManagedZone;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -248,9 +249,9 @@ public Builder toBuilder() {
return new BuilderImpl(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();
ManagedZone toPb() {
ManagedZone pb =
new ManagedZone();
pb.setDescription(this.description());
pb.setDnsName(this.dnsName());
if (this.generatedId() != null) {
Expand All @@ -267,7 +268,7 @@ com.google.api.services.dns.model.ManagedZone toPb() {
return pb;
}

static ZoneInfo fromPb(com.google.api.services.dns.model.ManagedZone pb) {
static ZoneInfo fromPb(ManagedZone pb) {
Builder builder = new BuilderImpl(pb.getName());
if (pb.getDescription() != null) {
builder.description(pb.getDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public class LocalDnsHelper {
}
}

private long delayChange;
private final long delayChange;
private final HttpServer server;
private final int port;

Expand All @@ -140,8 +140,8 @@ private enum CallRegex {
PROJECT_GET("GET", CONTEXT + "/[^/]+"),
RECORD_LIST("GET", CONTEXT + "/[^/]+/managedZones/[^/]+/rrsets");

private String method;
private String pathRegex;
private final String method;
private final String pathRegex;

CallRegex(String method, String pathRegex) {
this.pathRegex = pathRegex;
Expand Down Expand Up @@ -382,7 +382,7 @@ ConcurrentSkipListMap<String, ProjectContainer> projects() {
}

/**
* Creates new {@link LocalDnsHelper} instance that listens to requests on the local machine. This
* Creates new {@code LocalDnsHelper} instance that listens to requests on the local machine. This
* instance processes changes in separate thread. The parameter determines how long a thread
* should wait before processing a change. If it is set to 0, the threading is turned off and the
* mock will behave synchronously.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
*/
class OptionParsers {

private OptionParsers() {
}

static Map<String, Object> parseListZonesOptions(String query) {
Map<String, Object> options = new HashMap<>();
if (query != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.api.services.dns.model.Change;
import com.google.common.collect.ImmutableList;

import org.junit.Test;
Expand Down Expand Up @@ -209,7 +210,7 @@ public void testRemoveDeletion() {
@Test
public void testDateParsing() {
String startTime = "2016-01-26T18:33:43.512Z"; // obtained from service
com.google.api.services.dns.model.Change change = CHANGE.toPb().setStartTime(startTime);
Change change = CHANGE.toPb().setStartTime(startTime);
ChangeRequestInfo converted = ChangeRequest.fromPb(change);
assertNotNull(converted.startTimeMillis());
assertEquals(change, converted.toPb());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.api.services.dns.model.Change;
import com.google.api.services.dns.model.ManagedZone;
import com.google.api.services.dns.model.ResourceRecordSet;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -69,8 +70,7 @@ public class DnsImplTest {
CHANGE_REQUEST_PARTIAL.toPb()));
private static final DnsRpc.ListResult<ManagedZone> LIST_RESULT_OF_PB_ZONES =
DnsRpc.ListResult.of("cursor", ImmutableList.of(ZONE_INFO.toPb()));
private static final DnsRpc.ListResult<com.google.api.services.dns.model.ResourceRecordSet>
LIST_OF_PB_DNS_RECORDS =
private static final DnsRpc.ListResult<ResourceRecordSet> LIST_OF_PB_DNS_RECORDS =
DnsRpc.ListResult.of("cursor", ImmutableList.of(DNS_RECORD1.toPb(), DNS_RECORD2.toPb()));

// Field options
Expand Down
Loading