Repository navigation
Expand file tree
/
Copy pathProjectInfo.java
More file actions
288 lines (252 loc) · 7.82 KB
/
Copy pathProjectInfo.java
File metadata and controls
288 lines (252 loc) · 7.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.dns;
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;
import java.math.BigInteger;
import java.util.Objects;
/**
* The class provides the Google Cloud DNS information associated with this project. A project is a
* top level container for resources including {@code Zone}s. Projects can be created only in the
* APIs console.
*
* @see <a href="https://cloud.google.com/dns/api/v1/projects">Google Cloud DNS documentation</a>
*/
public class ProjectInfo implements Serializable {
private static final long serialVersionUID = 8696578863323485036L;
private final String id;
private final BigInteger number;
private final Quota quota;
/**
* This class represents quotas assigned to the {@code ProjectInfo}.
*
* @see <a href="https://cloud.google.com/dns/api/v1/projects#quota">Google Cloud DNS
* documentation</a>
*/
public static class Quota implements Serializable {
private static final long serialVersionUID = 6854685970605363639L;
private final int zones;
private final int resourceRecordsPerRrset;
private final int rrsetAdditionsPerChange;
private final int rrsetDeletionsPerChange;
private final int rrsetsPerZone;
private final int totalRrdataSizePerChange;
/**
* Creates an instance of {@code Quota}.
*
* <p>This is the only way of creating an instance of {@code Quota}. As the service does not
* allow for specifying options, quota is an "all-or-nothing object" and we do not need a
* builder.
*/
Quota(int zones,
int resourceRecordsPerRrset,
int rrsetAdditionsPerChange,
int rrsetDeletionsPerChange,
int rrsetsPerZone,
int totalRrdataSizePerChange) {
this.zones = zones;
this.resourceRecordsPerRrset = resourceRecordsPerRrset;
this.rrsetAdditionsPerChange = rrsetAdditionsPerChange;
this.rrsetDeletionsPerChange = rrsetDeletionsPerChange;
this.rrsetsPerZone = rrsetsPerZone;
this.totalRrdataSizePerChange = totalRrdataSizePerChange;
}
/**
* Returns the maximum allowed number of zones in the project.
*/
public int zones() {
return zones;
}
/**
* Returns the maximum allowed number of records per {@link RecordSet}.
*/
public int resourceRecordsPerRrset() {
return resourceRecordsPerRrset;
}
/**
* Returns the maximum allowed number of {@link RecordSet}s to add per {@link
* ChangeRequest}.
*/
public int rrsetAdditionsPerChange() {
return rrsetAdditionsPerChange;
}
/**
* Returns the maximum allowed number of {@link RecordSet}s to delete per {@link
* ChangeRequest}.
*/
public int rrsetDeletionsPerChange() {
return rrsetDeletionsPerChange;
}
/**
* Returns the maximum allowed number of {@link RecordSet}s per {@link ZoneInfo} in the
* project.
*/
public int rrsetsPerZone() {
return rrsetsPerZone;
}
/**
* Returns the maximum allowed size for total records in one ChangesRequest in bytes.
*/
public int totalRrdataSizePerChange() {
return totalRrdataSizePerChange;
}
@Override
public boolean equals(Object other) {
return (other instanceof Quota) && this.toPb().equals(((Quota) other).toPb());
}
@Override
public int hashCode() {
return Objects.hash(zones, resourceRecordsPerRrset, rrsetAdditionsPerChange,
rrsetDeletionsPerChange, rrsetsPerZone, totalRrdataSizePerChange);
}
com.google.api.services.dns.model.Quota toPb() {
com.google.api.services.dns.model.Quota pb = new com.google.api.services.dns.model.Quota();
pb.setManagedZones(zones);
pb.setResourceRecordsPerRrset(resourceRecordsPerRrset);
pb.setRrsetAdditionsPerChange(rrsetAdditionsPerChange);
pb.setRrsetDeletionsPerChange(rrsetDeletionsPerChange);
pb.setRrsetsPerManagedZone(rrsetsPerZone);
pb.setTotalRrdataSizePerChange(totalRrdataSizePerChange);
return pb;
}
static Quota fromPb(com.google.api.services.dns.model.Quota pb) {
return new Quota(pb.getManagedZones(),
pb.getResourceRecordsPerRrset(),
pb.getRrsetAdditionsPerChange(),
pb.getRrsetDeletionsPerChange(),
pb.getRrsetsPerManagedZone(),
pb.getTotalRrdataSizePerChange()
);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("zones", zones)
.add("resourceRecordsPerRrset", resourceRecordsPerRrset)
.add("rrsetAdditionsPerChange", rrsetAdditionsPerChange)
.add("rrsetDeletionsPerChange", rrsetDeletionsPerChange)
.add("rrsetsPerZone", rrsetsPerZone)
.add("totalRrdataSizePerChange", totalRrdataSizePerChange)
.toString();
}
}
/**
* A builder for {@code ProjectInfo}.
*/
static class Builder {
private String id;
private BigInteger number;
private Quota quota;
private Builder() {
}
/**
* Sets an id of the project.
*/
Builder id(String id) {
this.id = checkNotNull(id);
return this;
}
/**
* Sets a number of the project.
*/
Builder number(BigInteger number) {
this.number = checkNotNull(number);
return this;
}
/**
* Sets quotas assigned to the project.
*/
Builder quota(Quota quota) {
this.quota = checkNotNull(quota);
return this;
}
/**
* Builds an instance of the {@code ProjectInfo}.
*/
ProjectInfo build() {
return new ProjectInfo(this);
}
}
private ProjectInfo(Builder builder) {
this.id = builder.id;
this.number = builder.number;
this.quota = builder.quota;
}
/**
* Returns a builder for {@code ProjectInfo}.
*/
static Builder builder() {
return new Builder();
}
/**
* Returns the {@code Quota} object which contains quotas assigned to this project.
*/
public Quota quota() {
return quota;
}
/**
* Returns project number. For internal use only.
*/
BigInteger number() {
return number;
}
/**
* Returns project id. For internal use only.
*/
String id() {
return id;
}
Project toPb() {
Project pb = new Project();
pb.setId(id);
pb.setNumber(number);
if (this.quota != null) {
pb.setQuota(quota.toPb());
}
return pb;
}
static ProjectInfo fromPb(Project pb) {
Builder builder = builder();
if (pb.getId() != null) {
builder.id(pb.getId());
}
if (pb.getNumber() != null) {
builder.number(pb.getNumber());
}
if (pb.getQuota() != null) {
builder.quota(Quota.fromPb(pb.getQuota()));
}
return builder.build();
}
@Override
public boolean equals(Object other) {
return (other instanceof ProjectInfo) && toPb().equals(((ProjectInfo) other).toPb());
}
@Override
public int hashCode() {
return Objects.hash(id, number, quota);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", id)
.add("number", number)
.add("quota", quota)
.toString();
}
}