Skip to content

Commit 7ae9d3c

Browse files
committed
---
yaml --- r: 4345 b: refs/heads/gcs-nio c: 6e1a3f9 h: refs/heads/master i: 4343: 7354cc9
1 parent d4faa53 commit 7ae9d3c

4 files changed

Lines changed: 52 additions & 47 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ refs/tags/v0.0.12: 2fd8066e891fb3dfea69b65f6bf6461db79342b9
1111
refs/heads/compute-alpha: 969cba2627f1d53d352cc4a5ffe0879dacf65e6c
1212
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
1313
refs/heads/dns-alpha-batch: 17442b07867021b85d0452f5f3eda29a3413288f
14-
refs/heads/gcs-nio: 2d691aacdd3379389db290eb142f6f73a59ef8cd
14+
refs/heads/gcs-nio: 6e1a3f920c375b3ab5d0c4e2fb1d5e6b78874674
1515
refs/heads/logging-alpha: db5312bffa7fccac194f6a7feb8cc3066de16aff
1616
refs/tags/v0.1.0: a615317f7424ed58621b1f65d5c4d8cbbe8a6ed8
1717
refs/tags/v0.1.1: 7a7f6985fe465e9dd6a075af55493f42b4933be0

branches/gcs-nio/gcloud-java-compute/src/main/java/com/google/gcloud/compute/Address.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424

2525
/**
2626
* A Google Compute Engine address. With Compute Engine you can create static external IP addresses
27-
* that are assigned to your project and persists until you explicitly release them. A region
28-
* address can be assigned to a Compute Engine instance or to a regional forwarding rule. Compute
29-
* Engine also allows to create global addresses that are used for global forwarding rules. Both
30-
* global addresses and global forwarding rules can only be used for HTTP load balancing.
31-
* {@code Address} adds a layer of service-related functionality over {@link AddressInfo}. Objects
32-
* of this class are immutable. To get an {@code Address} object with the most recent information
33-
* use {@link #reload}.
27+
* that are assigned to your project and persist until you explicitly release them. A region address
28+
* can be assigned to a Compute Engine instance or to a regional forwarding rule. Compute Engine
29+
* also allows you to create global addresses that are used for global forwarding rules. Both global
30+
* addresses and global forwarding rules can only be used for HTTP load balancing. {@code Address}
31+
* adds a layer of service-related functionality over {@link AddressInfo}. Objects of this class are
32+
* immutable. To get an {@code Address} object with the most recent information use {@link #reload}.
3433
*
3534
* @see <a href="https://cloud.google.com/compute/docs/instances-and-network#reservedaddress">
3635
* Static external IP addresses</a>
@@ -87,7 +86,7 @@ Builder id(String id) {
8786
}
8887

8988
@Override
90-
Builder addressId(AddressId addressId) {
89+
public Builder addressId(AddressId addressId) {
9190
infoBuilder.addressId(addressId);
9291
return this;
9392
}
@@ -122,19 +121,19 @@ public Address build() {
122121
* @return {@code true} if this address exists, {@code false} otherwise
123122
* @throws ComputeException upon failure
124123
*/
125-
public boolean exists() throws ComputeException {
124+
public boolean exists() {
126125
return reload(Compute.AddressOption.fields()) != null;
127126
}
128127

129128
/**
130-
* Fetches current address' latest information. Returns {@code null} if the address does not
129+
* Fetches the current address' latest information. Returns {@code null} if the address does not
131130
* exist.
132131
*
133132
* @param options address options
134133
* @return an {@code Address} object with latest information or {@code null} if not found
135134
* @throws ComputeException upon failure
136135
*/
137-
public Address reload(Compute.AddressOption... options) throws ComputeException {
136+
public Address reload(Compute.AddressOption... options) {
138137
return compute.get(addressId(), options);
139138
}
140139

@@ -145,7 +144,7 @@ public Address reload(Compute.AddressOption... options) throws ComputeException
145144
* the address was not found
146145
* @throws ComputeException upon failure
147146
*/
148-
public Operation delete(Compute.OperationOption... options) throws ComputeException {
147+
public Operation delete(Compute.OperationOption... options) {
149148
return compute.delete(addressId(), options);
150149
}
151150

branches/gcs-nio/gcloud-java-compute/src/main/java/com/google/gcloud/compute/AddressInfo.java

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434

3535
/**
3636
* A Google Compute Engine address. With Compute Engine you can create static external IP addresses
37-
* that are assigned to your project and persists until you explicitly release them. A region
38-
* address can be assigned to a Compute Engine instance or to a regional forwarding rule. To create
39-
* a region address use a {@link RegionAddressId} identity. Compute Engine also allows to create
40-
* global addresses that are used for global forwarding rules. Both global addresses and global
41-
* forwarding rules can only be used for HTTP load balancing. To create a global address use a
37+
* that are assigned to your project and persist until you explicitly release them. A region address
38+
* can be assigned to a Compute Engine instance or to a regional forwarding rule. To create a region
39+
* address, use a {@link RegionAddressId} identity. Compute Engine also allows you to create global
40+
* addresses that are used for global forwarding rules. Both global addresses and global forwarding
41+
* rules can only be used for HTTP load balancing. To create a global address, use a
4242
* {@link GlobalAddressId} identity.
4343
*
4444
* @see <a href="https://cloud.google.com/compute/docs/instances-and-network#reservedaddress">
@@ -94,8 +94,8 @@ public enum Status {
9494
* class represent different possible usages of a Compute Engine address. {@link InstanceUsage}
9595
* contains information for region addresses assigned to a Google Compute Engine instance.
9696
* {@link RegionForwardingUsage} contains information for region addresses assigned to one or more
97-
* region forwarding rule. {@link GlobalForwardingUsage} contains information for global addresses
98-
* assigned to one or more global forwarding rule.
97+
* region forwarding rules. {@link GlobalForwardingUsage} contains information for global
98+
* addresses assigned to one or more global forwarding rules.
9999
*/
100100
public abstract static class Usage implements Serializable {
101101

@@ -106,7 +106,7 @@ public abstract static class Usage implements Serializable {
106106
/**
107107
* Returns the identities of resources currently using this address.
108108
*/
109-
public abstract List<ResourceId> users();
109+
public abstract List<? extends ResourceId> users();
110110

111111
final boolean baseEquals(Usage usage) {
112112
return Objects.equals(toPb(), usage.toPb());
@@ -128,8 +128,10 @@ static <T extends Usage> T fromPb(Address addressPb) {
128128
return (T) InstanceUsage.fromPb(addressPb);
129129
} else if (RegionForwardingRuleId.matchesUrl(url)) {
130130
return (T) RegionForwardingUsage.fromPb(addressPb);
131-
} else {
131+
} else if (GlobalForwardingRuleId.matchesUrl(url)) {
132132
return (T) GlobalForwardingUsage.fromPb(addressPb);
133+
} else {
134+
throw new IllegalArgumentException("Unexpected resource URL for address user");
133135
}
134136
}
135137
}
@@ -156,8 +158,8 @@ public InstanceId instance() {
156158
}
157159

158160
@Override
159-
public List<ResourceId> users() {
160-
return ImmutableList.<ResourceId>of(instance);
161+
public List<InstanceId> users() {
162+
return ImmutableList.of(instance);
161163
}
162164

163165
@Override
@@ -203,9 +205,8 @@ public List<RegionForwardingRuleId> forwardingRules() {
203205
}
204206

205207
@Override
206-
@SuppressWarnings("unchecked")
207-
public List<ResourceId> users() {
208-
return (List<ResourceId>) (List) forwardingRules;
208+
public List<RegionForwardingRuleId> users() {
209+
return forwardingRules;
209210
}
210211

211212
@Override
@@ -252,9 +253,8 @@ public List<GlobalForwardingRuleId> forwardingRules() {
252253
}
253254

254255
@Override
255-
@SuppressWarnings("unchecked")
256-
public List<ResourceId> users() {
257-
return (List<ResourceId>) (List) forwardingRules;
256+
public List<GlobalForwardingRuleId> users() {
257+
return forwardingRules;
258258
}
259259

260260
@Override
@@ -298,7 +298,7 @@ public abstract static class Builder {
298298

299299
abstract Builder id(String id);
300300

301-
abstract Builder addressId(AddressId addressId);
301+
public abstract Builder addressId(AddressId addressId);
302302

303303
abstract Builder status(Status status);
304304

@@ -379,7 +379,7 @@ BuilderImpl id(String id) {
379379
}
380380

381381
@Override
382-
BuilderImpl addressId(AddressId addressId) {
382+
public BuilderImpl addressId(AddressId addressId) {
383383
this.addressId = checkNotNull(addressId);
384384
return this;
385385
}
@@ -457,11 +457,11 @@ public Status status() {
457457
}
458458

459459
/**
460-
* Returns the usage information of the address. Returns a {@link InstanceUsage} object for region
461-
* addresses that are assigned to VM instances. Returns a {@link RegionForwardingUsage} object for
462-
* region addresses assigned to region forwarding rules. Returns a {@link GlobalForwardingUsage}
463-
* object for global addresses assigned to global forwarding rules. Returns {@code null} if the
464-
* address is not in use.
460+
* Returns the usage information of the address. Returns an {@link InstanceUsage} object for
461+
* region addresses that are assigned to VM instances. Returns a {@link RegionForwardingUsage}
462+
* object for region addresses assigned to region forwarding rules. Returns a
463+
* {@link GlobalForwardingUsage} object for global addresses assigned to global forwarding rules.
464+
* Returns {@code null} if the address is not in use.
465465
*/
466466
@SuppressWarnings("unchecked")
467467
public <T extends Usage> T usage() {
@@ -501,14 +501,10 @@ public boolean equals(Object obj) {
501501
}
502502

503503
AddressInfo setProjectId(String projectId) {
504-
Builder builder = toBuilder();
505-
AddressId addressIdWithProject;
506-
if (addressId instanceof RegionAddressId) {
507-
addressIdWithProject = this.<RegionAddressId>addressId().setProjectId(projectId);
508-
} else {
509-
addressIdWithProject = this.<GlobalAddressId>addressId().setProjectId(projectId);
510-
}
511-
return builder.addressId(addressIdWithProject).build();
504+
if (addressId().project() != null) {
505+
return this;
506+
}
507+
return toBuilder().addressId(addressId.setProjectId(projectId)).build();
512508
}
513509

514510
Address toPb() {

branches/gcs-nio/gcloud-java-compute/src/test/java/com/google/gcloud/compute/AddressTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.junit.After;
3333
import org.junit.Test;
3434

35-
import java.math.BigInteger;
3635
import java.util.List;
3736

3837
public class AddressTest {
@@ -114,7 +113,7 @@ public void tearDown() throws Exception {
114113

115114
@Test
116115
public void testBuilder() {
117-
initializeExpectedAddress(5);
116+
initializeExpectedAddress(6);
118117
assertEquals(ADDRESS, instanceAddress.address());
119118
assertEquals(CREATION_TIMESTAMP, instanceAddress.creationTimestamp());
120119
assertEquals(DESCRIPTION, instanceAddress.description());
@@ -157,6 +156,17 @@ public void testBuilder() {
157156
assertNull(address.id());
158157
assertNull(address.status());
159158
assertNull(address.usage());
159+
address = new Address.Builder(serviceMockReturnsOptions, REGION_ADDRESS_ID)
160+
.addressId(GLOBAL_ADDRESS_ID)
161+
.build();
162+
assertEquals(GLOBAL_ADDRESS_ID, address.addressId());
163+
assertSame(serviceMockReturnsOptions, address.compute());
164+
assertNull(address.address());
165+
assertNull(address.creationTimestamp());
166+
assertNull(address.description());
167+
assertNull(address.id());
168+
assertNull(address.status());
169+
assertNull(address.usage());
160170
}
161171

162172
@Test

0 commit comments

Comments
 (0)