Skip to content

Commit d529b3a

Browse files
committed
---
yaml --- r: 4859 b: refs/heads/logging-alpha c: 3565376 h: refs/heads/master i: 4857: b82011e 4855: 6ad1254
1 parent 95e3852 commit d529b3a

23 files changed

Lines changed: 4067 additions & 33 deletions

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ refs/heads/compute-alpha: 969cba2627f1d53d352cc4a5ffe0879dacf65e6c
1212
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
1313
refs/heads/dns-alpha-batch: 17442b07867021b85d0452f5f3eda29a3413288f
1414
refs/heads/gcs-nio: 283aeaf15efdcf3621eb6859f05e55ad7764375d
15-
refs/heads/logging-alpha: de30a254b7e9e994bbf87644f5a0a0bf41ed97f4
15+
refs/heads/logging-alpha: 3565376d4ce72e7a182e0c0a0ee91373ff700b61
1616
refs/tags/v0.1.0: a615317f7424ed58621b1f65d5c4d8cbbe8a6ed8
1717
refs/tags/v0.1.1: 7a7f6985fe465e9dd6a075af55493f42b4933be0
1818
refs/tags/v0.1.2: 3eb3fe866ba22487686048f45d927b8c8638ea3f
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.compute;
18+
19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
21+
import java.io.IOException;
22+
import java.io.ObjectInputStream;
23+
import java.util.Objects;
24+
25+
/**
26+
* 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}.
34+
*
35+
* @see <a href="https://cloud.google.com/compute/docs/instances-and-network#reservedaddress">
36+
* Static external IP addresses</a>
37+
* @see <a href="https://cloud.google.com/compute/docs/load-balancing/http/">HTTP Load Balancing</a>
38+
*/
39+
public class Address extends AddressInfo {
40+
41+
private static final long serialVersionUID = 3457542817554062712L;
42+
43+
private final ComputeOptions options;
44+
private transient Compute compute;
45+
46+
/**
47+
* A builder for {@code Address} objects.
48+
*/
49+
public static class Builder extends AddressInfo.Builder {
50+
51+
private final Compute compute;
52+
private final AddressInfo.BuilderImpl infoBuilder;
53+
54+
Builder(Compute compute, AddressId addressId) {
55+
this.compute = compute;
56+
this.infoBuilder = new AddressInfo.BuilderImpl();
57+
this.infoBuilder.addressId(addressId);
58+
}
59+
60+
Builder(Address address) {
61+
this.compute = address.compute;
62+
this.infoBuilder = new AddressInfo.BuilderImpl(address);
63+
}
64+
65+
@Override
66+
public Builder address(String address) {
67+
infoBuilder.address(address);
68+
return this;
69+
}
70+
71+
@Override
72+
Builder creationTimestamp(Long creationTimestamp) {
73+
infoBuilder.creationTimestamp(creationTimestamp);
74+
return this;
75+
}
76+
77+
@Override
78+
public Builder description(String description) {
79+
infoBuilder.description(description);
80+
return this;
81+
}
82+
83+
@Override
84+
Builder id(String id) {
85+
infoBuilder.id(id);
86+
return this;
87+
}
88+
89+
@Override
90+
Builder addressId(AddressId addressId) {
91+
infoBuilder.addressId(addressId);
92+
return this;
93+
}
94+
95+
@Override
96+
Builder status(Status status) {
97+
infoBuilder.status(status);
98+
return this;
99+
}
100+
101+
@Override
102+
Builder usage(Usage usage) {
103+
infoBuilder.usage(usage);
104+
return this;
105+
}
106+
107+
@Override
108+
public Address build() {
109+
return new Address(compute, infoBuilder);
110+
}
111+
}
112+
113+
Address(Compute compute, AddressInfo.BuilderImpl infoBuilder) {
114+
super(infoBuilder);
115+
this.compute = checkNotNull(compute);
116+
this.options = compute.options();
117+
}
118+
119+
/**
120+
* Checks if this address exists.
121+
*
122+
* @return {@code true} if this address exists, {@code false} otherwise
123+
* @throws ComputeException upon failure
124+
*/
125+
public boolean exists() throws ComputeException {
126+
return reload(Compute.AddressOption.fields()) != null;
127+
}
128+
129+
/**
130+
* Fetches current address' latest information. Returns {@code null} if the address does not
131+
* exist.
132+
*
133+
* @param options address options
134+
* @return an {@code Address} object with latest information or {@code null} if not found
135+
* @throws ComputeException upon failure
136+
*/
137+
public Address reload(Compute.AddressOption... options) throws ComputeException {
138+
return compute.get(addressId(), options);
139+
}
140+
141+
/**
142+
* Deletes this address.
143+
*
144+
* @return an operation object if delete request was successfully sent, {@code null} if the
145+
* address was not found
146+
* @throws ComputeException upon failure
147+
*/
148+
public Operation delete(Compute.OperationOption... options) throws ComputeException {
149+
return compute.delete(addressId(), options);
150+
}
151+
152+
/**
153+
* Returns the address's {@code Compute} object used to issue requests.
154+
*/
155+
public Compute compute() {
156+
return compute;
157+
}
158+
159+
@Override
160+
public Builder toBuilder() {
161+
return new Builder(this);
162+
}
163+
164+
@Override
165+
public final boolean equals(Object obj) {
166+
return obj instanceof Address
167+
&& Objects.equals(toPb(), ((Address) obj).toPb())
168+
&& Objects.equals(options, ((Address) obj).options);
169+
}
170+
171+
@Override
172+
public final int hashCode() {
173+
return Objects.hash(super.hashCode(), options);
174+
}
175+
176+
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
177+
in.defaultReadObject();
178+
this.compute = options.service();
179+
}
180+
181+
static Address fromPb(Compute compute, com.google.api.services.compute.model.Address addressPb) {
182+
return new Address(compute, new AddressInfo.BuilderImpl(addressPb));
183+
}
184+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.compute;
18+
19+
/**
20+
* Interface for Google Compute Engine address identities.
21+
*/
22+
public interface AddressId {
23+
24+
/**
25+
* Possible types for a Google Compute Engine address identity.
26+
*/
27+
enum Type {
28+
/**
29+
* Global static external IP addresses can be assigned to global forwarding rules.
30+
*/
31+
GLOBAL,
32+
/**
33+
* Region static external IP addresses can be assigned to instances and region forwarding rules.
34+
*/
35+
REGION
36+
}
37+
38+
/**
39+
* Returns the type of this address identity.
40+
*/
41+
Type type();
42+
43+
/**
44+
* Returns the name of the project.
45+
*/
46+
String project();
47+
48+
/**
49+
* Returns the name of the address resource. The name must be 1-63 characters long, and comply
50+
* with RFC1035. Specifically, the name must be 1-63 characters long and match the regular
51+
* expression {@code [a-z]([-a-z0-9]*[a-z0-9])?} which means the first character must be a
52+
* lowercase letter, and all following characters must be a dash, lowercase letter, or digit,
53+
* except the last character, which cannot be a dash.
54+
*
55+
* @see <a href="https://www.ietf.org/rfc/rfc1035.txt">RFC1035</a>
56+
*/
57+
String address();
58+
59+
/**
60+
* Returns a fully qualified URL to the entity.
61+
*/
62+
String selfLink();
63+
}

0 commit comments

Comments
 (0)