Skip to content

Commit

Permalink
Rename id to generatedId for Dns resources
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Apr 1, 2016
1 parent d4faad3 commit 8df138b
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 168 deletions.
6 changes: 3 additions & 3 deletions gcloud-java-dns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ZoneInfo zoneInfo = ZoneInfo.of(zoneName, domainName, description);

// Create zone in Google Cloud DNS
Zone zone = dns.create(zoneInfo);
System.out.printf("Zone was created and assigned ID %s.%n", zone.id());
System.out.printf("Zone was created and assigned ID %s.%n", zone.generatedId());
```

You now have an empty zone hosted in Google Cloud DNS which is ready to be populated with
Expand Down Expand Up @@ -226,7 +226,7 @@ while (ChangeRequestInfo.Status.PENDING.equals(changeRequest.status())) {
} catch (InterruptedException e) {
System.err.println("The thread was interrupted while waiting...");
}
changeRequest = dns.getChangeRequest(zone.name(), changeRequest.id());
changeRequest = dns.getChangeRequest(zone.name(), changeRequest.generatedId());
}
System.out.println("The change request has been applied.");
```
Expand Down Expand Up @@ -315,7 +315,7 @@ if (!changeRequest.deletions().isEmpty()) {
}

// Update the change, but fetch only change ID and status
changeRequest = dns.getChangeRequest(zoneName, changeRequest.id(), option);
changeRequest = dns.getChangeRequest(zoneName, changeRequest.generatedId(), option);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public Builder removeDeletion(RecordSet recordSet) {
}

@Override
Builder id(String id) {
infoBuilder.id(id);
Builder generatedId(String generatedId) {
infoBuilder.generatedId(generatedId);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public ChangeRequestInfo apply(Change pb) {
return ChangeRequestInfo.fromPb(pb);
}
};
private static final long serialVersionUID = -9027378042756366333L;
private static final long serialVersionUID = -6029143477639439169L;
private final List<RecordSet> additions;
private final List<RecordSet> deletions;
private final String id;
private final String generatedId;
private final Long startTimeMillis;
private final ChangeRequestInfo.Status status;

Expand Down Expand Up @@ -119,9 +119,9 @@ public abstract static class Builder {
public abstract Builder removeDeletion(RecordSet recordSet);

/**
* Associates a server-assigned id to this {@code ChangeRequestInfo}.
* Associates a service-generated id to this {@code ChangeRequestInfo}.
*/
abstract Builder id(String id);
abstract Builder generatedId(String generatedId);

/**
* Sets the time when this change request was started by a server.
Expand All @@ -143,7 +143,7 @@ public abstract static class Builder {
static class BuilderImpl extends Builder {
private List<RecordSet> additions;
private List<RecordSet> deletions;
private String id;
private String generatedId;
private Long startTimeMillis;
private ChangeRequestInfo.Status status;

Expand All @@ -155,7 +155,7 @@ static class BuilderImpl extends Builder {
BuilderImpl(ChangeRequestInfo info) {
this.additions = Lists.newLinkedList(info.additions());
this.deletions = Lists.newLinkedList(info.deletions());
this.id = info.id();
this.generatedId = info.generatedId;
this.startTimeMillis = info.startTimeMillis;
this.status = info.status;
}
Expand Down Expand Up @@ -214,8 +214,8 @@ public ChangeRequestInfo build() {
}

@Override
Builder id(String id) {
this.id = checkNotNull(id);
Builder generatedId(String generatedId) {
this.generatedId = checkNotNull(generatedId);
return this;
}

Expand All @@ -235,7 +235,7 @@ Builder status(ChangeRequestInfo.Status status) {
ChangeRequestInfo(BuilderImpl builder) {
this.additions = ImmutableList.copyOf(builder.additions);
this.deletions = ImmutableList.copyOf(builder.deletions);
this.id = builder.id;
this.generatedId = builder.generatedId;
this.startTimeMillis = builder.startTimeMillis;
this.status = builder.status;
}
Expand Down Expand Up @@ -271,22 +271,22 @@ public List<RecordSet> deletions() {
}

/**
* Returns the id assigned to this {@code ChangeRequest} by the server.
* Returns the service-generated id for this change request.
*/
public String id() {
return id;
public String generatedId() {
return generatedId;
}

/**
* Returns the time when this {@code ChangeRequest} was started by the server.
* Returns the time when this change request was started by the server.
*/
public Long startTimeMillis() {
return startTimeMillis;
}

/**
* Returns the status of this {@code ChangeRequest}. If the change request has not been applied
* yet, the status is {@code PENDING}.
* Returns the status of this change request. If the change request has not been applied yet, the
* status is {@code PENDING}.
*/
public ChangeRequestInfo.Status status() {
return status;
Expand All @@ -295,8 +295,8 @@ public ChangeRequestInfo.Status status() {
Change toPb() {
Change pb = new Change();
// set id
if (id() != null) {
pb.setId(id());
if (generatedId() != null) {
pb.setId(generatedId());
}
// set timestamp
if (startTimeMillis() != null) {
Expand All @@ -316,7 +316,7 @@ Change toPb() {
static ChangeRequestInfo fromPb(Change pb) {
Builder builder = builder();
if (pb.getId() != null) {
builder.id(pb.getId());
builder.generatedId(pb.getId());
}
if (pb.getStartTime() != null) {
builder.startTimeMillis(DateTime.parse(pb.getStartTime()).getMillis());
Expand All @@ -342,15 +342,15 @@ public boolean equals(Object other) {

@Override
public int hashCode() {
return Objects.hash(additions, deletions, id, startTimeMillis, status);
return Objects.hash(additions, deletions, generatedId, startTimeMillis, status);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("additions", additions)
.add("deletions", deletions)
.add("id", id)
.add("generatedId", generatedId)
.add("startTimeMillis", startTimeMillis)
.add("status", status)
.toString();
Expand Down
4 changes: 2 additions & 2 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 @@ -61,8 +61,8 @@ public Builder name(String name) {
}

@Override
Builder id(String id) {
infoBuilder.id(id);
Builder generatedId(String generatedId) {
infoBuilder.generatedId(generatedId);
return this;
}

Expand Down
36 changes: 18 additions & 18 deletions gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
*/
public class ZoneInfo implements Serializable {

private static final long serialVersionUID = 201601191647L;
private static final long serialVersionUID = -5313169712036079818L;
private final String name;
private final String id;
private final String generatedId;
private final Long creationTimeMillis;
private final String dnsName;
private final String description;
Expand All @@ -57,9 +57,9 @@ public abstract static class Builder {
public abstract Builder name(String name);

/**
* Sets an id for the zone which is assigned to the zone by the server.
* Sets service-generated id for the zone.
*/
abstract Builder id(String id);
abstract Builder generatedId(String generatedId);

/**
* Sets the time when this zone was created.
Expand Down Expand Up @@ -98,7 +98,7 @@ public abstract static class Builder {

static class BuilderImpl extends Builder {
private String name;
private String id;
private String generatedId;
private Long creationTimeMillis;
private String dnsName;
private String description;
Expand All @@ -114,7 +114,7 @@ private BuilderImpl(String name) {
*/
BuilderImpl(ZoneInfo info) {
this.name = info.name;
this.id = info.id;
this.generatedId = info.generatedId;
this.creationTimeMillis = info.creationTimeMillis;
this.dnsName = info.dnsName;
this.description = info.description;
Expand All @@ -131,8 +131,8 @@ public Builder name(String name) {
}

@Override
Builder id(String id) {
this.id = id;
Builder generatedId(String generatedId) {
this.generatedId = generatedId;
return this;
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public ZoneInfo build() {

ZoneInfo(BuilderImpl builder) {
this.name = builder.name;
this.id = builder.id;
this.generatedId = builder.generatedId;
this.creationTimeMillis = builder.creationTimeMillis;
this.dnsName = builder.dnsName;
this.description = builder.description;
Expand All @@ -199,10 +199,10 @@ public String name() {
}

/**
* Returns the read-only zone id assigned by the server.
* Returns the service-generated id for this zone.
*/
public String id() {
return id;
public String generatedId() {
return generatedId;
}

/**
Expand Down Expand Up @@ -253,8 +253,8 @@ com.google.api.services.dns.model.ManagedZone toPb() {
new com.google.api.services.dns.model.ManagedZone();
pb.setDescription(this.description());
pb.setDnsName(this.dnsName());
if (this.id() != null) {
pb.setId(new BigInteger(this.id()));
if (this.generatedId() != null) {
pb.setId(new BigInteger(this.generatedId()));
}
pb.setName(this.name());
pb.setNameServers(this.nameServers); // do use real attribute value which may be null
Expand All @@ -276,7 +276,7 @@ static ZoneInfo fromPb(com.google.api.services.dns.model.ManagedZone pb) {
builder.dnsName(pb.getDnsName());
}
if (pb.getId() != null) {
builder.id(pb.getId().toString());
builder.generatedId(pb.getId().toString());
}
if (pb.getNameServers() != null) {
builder.nameServers(pb.getNameServers());
Expand All @@ -298,15 +298,15 @@ public boolean equals(Object obj) {

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

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("name", name())
.add("id", id())
.add("generatedId", generatedId())
.add("description", description())
.add("dnsName", dnsName())
.add("nameServerSet", nameServerSet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

public class ChangeRequestInfoTest {

private static final String ID = "cr-id-1";
private static final String GENERATED_ID = "cr-id-1";
private static final Long START_TIME_MILLIS = 12334567890L;
private static final ChangeRequest.Status STATUS = ChangeRequest.Status.PENDING;
private static final String NAME1 = "dns1";
Expand All @@ -51,7 +51,7 @@ public class ChangeRequestInfoTest {
.delete(RECORD3)
.startTimeMillis(START_TIME_MILLIS)
.status(STATUS)
.id(ID)
.generatedId(GENERATED_ID)
.build();

@Test
Expand All @@ -65,7 +65,7 @@ public void testEmptyBuilder() {

@Test
public void testBuilder() {
assertEquals(ID, CHANGE.id());
assertEquals(GENERATED_ID, CHANGE.generatedId());
assertEquals(STATUS, CHANGE.status());
assertEquals(START_TIME_MILLIS, CHANGE.startTimeMillis());
assertEquals(ADDITIONS, CHANGE.additions());
Expand All @@ -85,7 +85,7 @@ public void testEqualsAndNotEquals() {
assertEquals(CHANGE, clone);
clone = ChangeRequest.fromPb(CHANGE.toPb());
assertEquals(CHANGE, clone);
clone = CHANGE.toBuilder().id("some-other-id").build();
clone = CHANGE.toBuilder().generatedId("some-other-id").build();
assertNotEquals(CHANGE, clone);
clone = CHANGE.toBuilder().startTimeMillis(CHANGE.startTimeMillis() + 1).build();
assertNotEquals(CHANGE, clone);
Expand All @@ -112,7 +112,7 @@ public void testToAndFromPb() {
assertEquals(CHANGE, ChangeRequest.fromPb(CHANGE.toPb()));
ChangeRequestInfo partial = ChangeRequest.builder().build();
assertEquals(partial, ChangeRequest.fromPb(partial.toPb()));
partial = ChangeRequest.builder().id(ID).build();
partial = ChangeRequest.builder().generatedId(GENERATED_ID).build();
assertEquals(partial, ChangeRequest.fromPb(partial.toPb()));
partial = ChangeRequest.builder().add(RECORD1).build();
assertEquals(partial, ChangeRequest.fromPb(partial.toPb()));
Expand All @@ -133,7 +133,7 @@ public void testToBuilder() {
assertEquals(CHANGE, CHANGE.toBuilder().build());
ChangeRequestInfo partial = ChangeRequest.builder().build();
assertEquals(partial, partial.toBuilder().build());
partial = ChangeRequest.builder().id(ID).build();
partial = ChangeRequest.builder().generatedId(GENERATED_ID).build();
assertEquals(partial, partial.toBuilder().build());
partial = ChangeRequest.builder().add(RECORD1).build();
assertEquals(partial, partial.toBuilder().build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setUp() throws Exception {
changeRequest = new ChangeRequest(dns, ZONE_NAME, new ChangeRequestInfo.BuilderImpl(
CHANGE_REQUEST_INFO.toBuilder()
.startTimeMillis(132L)
.id("12")
.generatedId("12")
.status(ChangeRequest.Status.DONE)
.build()));
changeRequestPartial = new ChangeRequest(dns, ZONE_NAME,
Expand Down Expand Up @@ -104,8 +104,8 @@ public void testBuilder() {
// one for each build() call because it invokes a constructor
expect(dns.options()).andReturn(OPTIONS).times(9);
replay(dns);
String id = changeRequest.id() + "aaa";
assertEquals(id, changeRequest.toBuilder().id(id).build().id());
String id = changeRequest.generatedId() + "aaa";
assertEquals(id, changeRequest.toBuilder().generatedId(id).build().generatedId());
ChangeRequest modified =
changeRequest.toBuilder().status(ChangeRequest.Status.PENDING).build();
assertEquals(ChangeRequest.Status.PENDING, modified.status());
Expand Down
Loading

0 comments on commit 8df138b

Please sign in to comment.