Skip to content

Commit 6c34057

Browse files
committed
add back in deprecated compute package
1 parent 7a8ef83 commit 6c34057

File tree

126 files changed

+35845
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+35845
-0
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/*
2+
* Copyright 2016 Google LLC
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.cloud.compute.deprecated;
18+
19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
21+
import com.google.cloud.compute.deprecated.Compute.AddressOption;
22+
import com.google.cloud.compute.deprecated.Compute.OperationOption;
23+
24+
import java.io.IOException;
25+
import java.io.ObjectInputStream;
26+
import java.util.Objects;
27+
28+
/**
29+
* A Google Compute Engine address. With Compute Engine you can create static external IP addresses
30+
* that are assigned to your project and persist until you explicitly release them. A region address
31+
* can be assigned to a Compute Engine instance or to a regional forwarding rule. Compute Engine
32+
* also allows you to create global addresses that are used for global forwarding rules. Both global
33+
* addresses and global forwarding rules can only be used for HTTP load balancing. {@code Address}
34+
* adds a layer of service-related functionality over {@link AddressInfo}. Objects of this class are
35+
* immutable. To get an {@code Address} object with the most recent information use {@link #reload}.
36+
*
37+
* @see <a href="https://cloud.google.com/compute/docs/instances-and-network#reservedaddress">
38+
* Static external IP addresses</a>
39+
* @see <a href="https://cloud.google.com/compute/docs/load-balancing/http/">HTTP Load Balancing</a>
40+
*/
41+
public class Address extends AddressInfo {
42+
43+
private static final long serialVersionUID = 3457542817554062712L;
44+
45+
private final ComputeOptions options;
46+
private transient Compute compute;
47+
48+
/**
49+
* A builder for {@code Address} objects.
50+
*/
51+
public static class Builder extends AddressInfo.Builder {
52+
53+
private final Compute compute;
54+
private final AddressInfo.BuilderImpl infoBuilder;
55+
56+
Builder(Compute compute, AddressId addressId) {
57+
this.compute = compute;
58+
this.infoBuilder = new AddressInfo.BuilderImpl();
59+
this.infoBuilder.setAddressId(addressId);
60+
}
61+
62+
Builder(Address address) {
63+
this.compute = address.compute;
64+
this.infoBuilder = new AddressInfo.BuilderImpl(address);
65+
}
66+
67+
@Override
68+
public Builder setAddress(String address) {
69+
infoBuilder.setAddress(address);
70+
return this;
71+
}
72+
73+
@Override
74+
Builder setCreationTimestamp(Long creationTimestamp) {
75+
infoBuilder.setCreationTimestamp(creationTimestamp);
76+
return this;
77+
}
78+
79+
@Override
80+
public Builder setDescription(String description) {
81+
infoBuilder.setDescription(description);
82+
return this;
83+
}
84+
85+
@Override
86+
Builder setGeneratedId(String generatedId) {
87+
infoBuilder.setGeneratedId(generatedId);
88+
return this;
89+
}
90+
91+
@Override
92+
public Builder setAddressId(AddressId addressId) {
93+
infoBuilder.setAddressId(addressId);
94+
return this;
95+
}
96+
97+
@Override
98+
Builder setStatus(Status status) {
99+
infoBuilder.setStatus(status);
100+
return this;
101+
}
102+
103+
@Override
104+
Builder setUsage(Usage usage) {
105+
infoBuilder.setUsage(usage);
106+
return this;
107+
}
108+
109+
@Override
110+
public Address build() {
111+
return new Address(compute, infoBuilder);
112+
}
113+
}
114+
115+
Address(Compute compute, AddressInfo.BuilderImpl infoBuilder) {
116+
super(infoBuilder);
117+
this.compute = checkNotNull(compute);
118+
this.options = compute.getOptions();
119+
}
120+
121+
/**
122+
* Checks if this address exists.
123+
*
124+
* @return {@code true} if this address exists, {@code false} otherwise
125+
* @throws ComputeException upon failure
126+
*/
127+
public boolean exists() {
128+
return reload(AddressOption.fields()) != null;
129+
}
130+
131+
/**
132+
* Fetches the current address' latest information. Returns {@code null} if the address does not
133+
* exist.
134+
*
135+
* @param options address options
136+
* @return an {@code Address} object with latest information or {@code null} if not found
137+
* @throws ComputeException upon failure
138+
*/
139+
public Address reload(AddressOption... options) {
140+
return compute.getAddress(getAddressId(), options);
141+
}
142+
143+
/**
144+
* Deletes this address.
145+
*
146+
* @return an {@code Operation} object if delete request was successfully sent, {@code null} if
147+
* the address was not found
148+
* @throws ComputeException upon failure
149+
*/
150+
public Operation delete(OperationOption... options) {
151+
return compute.deleteAddress(getAddressId(), options);
152+
}
153+
154+
/**
155+
* Returns the address's {@code Compute} object used to issue requests.
156+
*/
157+
public Compute getCompute() {
158+
return compute;
159+
}
160+
161+
@Override
162+
public Builder toBuilder() {
163+
return new Builder(this);
164+
}
165+
166+
@Override
167+
public final boolean equals(Object obj) {
168+
if (obj == this) {
169+
return true;
170+
}
171+
if (obj == null || !obj.getClass().equals(Address.class)) {
172+
return false;
173+
}
174+
Address other = (Address) obj;
175+
return Objects.equals(toPb(), other.toPb()) && Objects.equals(options, other.options);
176+
}
177+
178+
@Override
179+
public final int hashCode() {
180+
return Objects.hash(super.hashCode(), options);
181+
}
182+
183+
private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException {
184+
input.defaultReadObject();
185+
this.compute = options.getService();
186+
}
187+
188+
static Address fromPb(Compute compute, com.google.api.services.compute.model.Address addressPb) {
189+
return new Address(compute, new AddressInfo.BuilderImpl(addressPb));
190+
}
191+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2016 Google LLC
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.cloud.compute.deprecated;
18+
19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
21+
import com.google.common.base.MoreObjects;
22+
23+
import java.util.Objects;
24+
25+
/**
26+
* Base class for Google Compute Engine address identities.
27+
*/
28+
public abstract class AddressId extends ResourceId {
29+
30+
private static final long serialVersionUID = 147328216049936438L;
31+
32+
private final String address;
33+
34+
/**
35+
* Possible types for a Google Compute Engine address identity.
36+
*/
37+
enum Type {
38+
/**
39+
* Global static external IP addresses can be assigned to global forwarding rules.
40+
*/
41+
GLOBAL,
42+
43+
/**
44+
* Region static external IP addresses can be assigned to instances and region forwarding rules.
45+
*/
46+
REGION
47+
}
48+
49+
AddressId(String project, String address) {
50+
super(project);
51+
this.address = checkNotNull(address);
52+
}
53+
54+
/**
55+
* Returns the type of this address identity.
56+
*/
57+
public abstract Type getType();
58+
59+
/**
60+
* Returns the name of the address resource. The name must be 1-63 characters long and comply with
61+
* RFC1035. Specifically, the name must match the regular expression
62+
* {@code [a-z]([-a-z0-9]*[a-z0-9])?} which means the first character must be a lowercase letter,
63+
* and all following characters must be a dash, lowercase letter, or digit, except the last
64+
* character, which cannot be a dash.
65+
*
66+
* @see <a href="https://www.ietf.org/rfc/rfc1035.txt">RFC1035</a>
67+
*/
68+
public String getAddress() {
69+
return address;
70+
}
71+
72+
@Override
73+
MoreObjects.ToStringHelper toStringHelper() {
74+
return super.toStringHelper().add("address", address);
75+
}
76+
77+
@Override
78+
final int baseHashCode() {
79+
return Objects.hash(super.baseHashCode(), address);
80+
}
81+
82+
@Override
83+
final boolean baseEquals(ResourceId resourceId) {
84+
return resourceId instanceof AddressId
85+
&& super.baseEquals(resourceId)
86+
&& Objects.equals(address, ((AddressId) resourceId).address);
87+
}
88+
89+
@Override
90+
abstract AddressId setProjectId(String projectId);
91+
}

0 commit comments

Comments
 (0)