Skip to content

Commit 8bf9eab

Browse files
authored
Rename setters/getters/builders for Logging classes to meet proto conventions (#1313)
* Rename setters/getters/builders for Logging classes to meet proto conventions * Update Logging examples, snippets and READMEs to use renamed getters/setters/builders * Make deprecated methods call renamed ones
1 parent 82b5032 commit 8bf9eab

51 files changed

Lines changed: 1955 additions & 678 deletions

Some content is hidden

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

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@ import java.util.Iterator;
412412
LoggingOptions options = LoggingOptions.defaultInstance();
413413
try(Logging logging = options.service()) {
414414
415-
LogEntry firstEntry = LogEntry.builder(StringPayload.of("message"))
416-
.logName("test-log")
417-
.resource(MonitoredResource.builder("global")
415+
LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message"))
416+
.setLogName("test-log")
417+
.setResource(MonitoredResource.builder("global")
418418
.addLabel("project_id", options.projectId())
419419
.build())
420420
.build();

TESTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ uses the `RemoteLoggingHelper` to create a metric.
164164
```java
165165
RemoteLoggingHelper loggingHelper =
166166
RemoteLoggingHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
167-
Logging logging = loggingHelper.options().service();
167+
Logging logging = loggingHelper.getOptions().service();
168168
// Pick a name for the resource with low probability of clashing
169169
String metricName = RemoteLoggingHelper.formatForTest("test-metric");
170170
MetricInfo metricInfo = MetricInfo.of(name, "logName:syslog");

google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ public static class Builder {
6666
* {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object.
6767
* For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL.
6868
*/
69+
@Deprecated
6970
public Builder type(String type) {
71+
return setType(type);
72+
}
73+
74+
/**
75+
* Sets the monitored resource type. This value must match the one of
76+
* {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object.
77+
* For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL.
78+
*/
79+
public Builder setType(String type) {
7080
this.type = type;
7181
return this;
7282
}
@@ -76,7 +86,17 @@ public Builder type(String type) {
7686
* descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute
7787
* Engine VM instances use the labels {@code instance_id} and {@code zone}.
7888
*/
89+
@Deprecated
7990
public Builder labels(Map<String, String> labels) {
91+
return setLabels(labels);
92+
}
93+
94+
/**
95+
* Sets the values for all the labels required by the corresponding monitored resource
96+
* descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute
97+
* Engine VM instances use the labels {@code instance_id} and {@code zone}.
98+
*/
99+
public Builder setLabels(Map<String, String> labels) {
80100
this.labels = new HashMap<>(checkNotNull(labels));
81101
return this;
82102
}
@@ -112,7 +132,17 @@ public MonitoredResource build() {
112132
* {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object.
113133
* For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL.
114134
*/
135+
@Deprecated
115136
public String type() {
137+
return getType();
138+
}
139+
140+
/**
141+
* Returns the monitored resource type. This value must match the one of
142+
* {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object.
143+
* For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL.
144+
*/
145+
public String getType() {
116146
return type;
117147
}
118148

@@ -121,7 +151,17 @@ public String type() {
121151
* descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute
122152
* Engine VM instances use the labels {@code instance_id} and {@code zone}.
123153
*/
154+
@Deprecated
124155
public Map<String, String> labels() {
156+
return getLabels();
157+
}
158+
159+
/**
160+
* Returns the values for all the labels required by the corresponding monitored resource
161+
* descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute
162+
* Engine VM instances use the labels {@code instance_id} and {@code zone}.
163+
*/
164+
public Map<String, String> getLabels() {
125165
return labels;
126166
}
127167

@@ -167,18 +207,26 @@ public Builder toBuilder() {
167207
/**
168208
* Returns a builder for {@code MonitoredResource} objects given the resource's type.
169209
*/
210+
@Deprecated
170211
public static Builder builder(String type) {
212+
return newBuilder(type);
213+
}
214+
215+
/**
216+
* Returns a builder for {@code MonitoredResource} objects given the resource's type.
217+
*/
218+
public static Builder newBuilder(String type) {
171219
return new Builder(type);
172220
}
173221

174222
/**
175223
* Creates a {@code MonitoredResource} object given the resource's type and labels.
176224
*/
177225
public static MonitoredResource of(String type, Map<String, String> labels) {
178-
return builder(type).labels(labels).build();
226+
return newBuilder(type).setLabels(labels).build();
179227
}
180228

181229
public static MonitoredResource fromPb(com.google.api.MonitoredResource descriptorPb) {
182-
return new Builder(descriptorPb.getType()).labels(descriptorPb.getLabels()).build();
230+
return new Builder(descriptorPb.getType()).setLabels(descriptorPb.getLabelsMap()).build();
183231
}
184232
}

google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,47 @@ static ValueType fromPb(com.google.api.LabelDescriptor.ValueType typePb) {
120120
/**
121121
* Returns the key associated to this label.
122122
*/
123+
@Deprecated
123124
public String key() {
125+
return getKey();
126+
}
127+
128+
/**
129+
* Returns the key associated to this label.
130+
*/
131+
public String getKey() {
124132
return key;
125133
}
126134

127135
/**
128136
* Returns the type of data that can be assigned to this label.
129137
*/
138+
@Deprecated
130139
public ValueType valueType() {
140+
return getValueType();
141+
}
142+
143+
/**
144+
* Returns the type of data that can be assigned to this label.
145+
*/
146+
public ValueType getValueType() {
131147
return valueType;
132148
}
133149

134150
/**
135151
* Returns the optional human-readable description for this label. If not set, this method
136152
* returns {@code null}.
137153
*/
154+
@Deprecated
138155
public String description() {
156+
return getDescription();
157+
}
158+
159+
/**
160+
* Returns the optional human-readable description for this label. If not set, this method
161+
* returns {@code null}.
162+
*/
163+
public String getDescription() {
139164
return description;
140165
}
141166

@@ -199,22 +224,22 @@ static class Builder {
199224
this.type = type;
200225
}
201226

202-
Builder name(String name) {
227+
Builder setName(String name) {
203228
this.name = name;
204229
return this;
205230
}
206231

207-
Builder displayName(String displayName) {
232+
Builder setDisplayName(String displayName) {
208233
this.displayName = displayName;
209234
return this;
210235
}
211236

212-
Builder description(String description) {
237+
Builder setDescription(String description) {
213238
this.description = description;
214239
return this;
215240
}
216241

217-
Builder labels(List<LabelDescriptor> labels) {
242+
Builder setLabels(List<LabelDescriptor> labels) {
218243
this.labels = labels;
219244
return this;
220245
}
@@ -236,15 +261,33 @@ MonitoredResourceDescriptor build() {
236261
* Returns the monitored resource type. For example, the type {@code cloudsql_database} represents
237262
* databases in Google Cloud SQL.
238263
*/
264+
@Deprecated
239265
public String type() {
266+
return getType();
267+
}
268+
269+
/**
270+
* Returns the monitored resource type. For example, the type {@code cloudsql_database} represents
271+
* databases in Google Cloud SQL.
272+
*/
273+
public String getType() {
240274
return type;
241275
}
242276

243277
/**
244278
* Returns an optional name for the monitored resource descriptor. If not set, this method returns
245279
* {@code null}.
246280
*/
281+
@Deprecated
247282
public String name() {
283+
return getName();
284+
}
285+
286+
/**
287+
* Returns an optional name for the monitored resource descriptor. If not set, this method returns
288+
* {@code null}.
289+
*/
290+
public String getName() {
248291
return name;
249292
}
250293

@@ -253,15 +296,34 @@ public String name() {
253296
* in user interfaces. For example, {@code Google Cloud SQL Database}. If not set, this method
254297
* returns {@code null}.
255298
*/
299+
@Deprecated
256300
public String displayName() {
301+
return getDisplayName();
302+
}
303+
304+
/**
305+
* Returns an optional concise name for the monitored resource type. This value might be displayed
306+
* in user interfaces. For example, {@code Google Cloud SQL Database}. If not set, this method
307+
* returns {@code null}.
308+
*/
309+
public String getDisplayName() {
257310
return displayName;
258311
}
259312

260313
/**
261314
* Returns an optional detailed description of the monitored resource type. This value might be
262315
* used in documentation. If not set, this method returns {@code null}.
263316
*/
317+
@Deprecated
264318
public String description() {
319+
return getDescription();
320+
}
321+
322+
/**
323+
* Returns an optional detailed description of the monitored resource type. This value might be
324+
* used in documentation. If not set, this method returns {@code null}.
325+
*/
326+
public String getDescription() {
265327
return description;
266328
}
267329

@@ -270,7 +332,17 @@ public String description() {
270332
* example, an individual Google Cloud SQL database is identified by values for the labels
271333
* {@code database_id} and {@code region}.
272334
*/
335+
@Deprecated
273336
public List<LabelDescriptor> labels() {
337+
return getLabels();
338+
}
339+
340+
/**
341+
* Returns a list of labels used to describe instances of this monitored resource type. For
342+
* example, an individual Google Cloud SQL database is identified by values for the labels
343+
* {@code database_id} and {@code region}.
344+
*/
345+
public List<LabelDescriptor> getLabels() {
274346
return labels;
275347
}
276348

@@ -323,23 +395,24 @@ public com.google.api.MonitoredResourceDescriptor toPb() {
323395
return builder.build();
324396
}
325397

326-
static Builder builder(String type) {
398+
static Builder newBuilder(String type) {
327399
return new Builder(type);
328400
}
329401

330402
public static MonitoredResourceDescriptor fromPb(
331403
com.google.api.MonitoredResourceDescriptor descriptorPb) {
332-
Builder builder = builder(descriptorPb.getType());
404+
Builder builder = newBuilder(descriptorPb.getType());
333405
if (descriptorPb.getName() != null && !descriptorPb.getName().equals("")) {
334-
builder.name(descriptorPb.getName());
406+
builder.setName(descriptorPb.getName());
335407
}
336408
if (descriptorPb.getDisplayName() != null && !descriptorPb.getDisplayName().equals("")) {
337-
builder.displayName(descriptorPb.getDisplayName());
409+
builder.setDisplayName(descriptorPb.getDisplayName());
338410
}
339411
if (descriptorPb.getDescription() != null && !descriptorPb.getDescription().equals("")) {
340-
builder.description(descriptorPb.getDescription());
412+
builder.setDescription(descriptorPb.getDescription());
341413
}
342-
builder.labels(Lists.transform(descriptorPb.getLabelsList(), LabelDescriptor.FROM_PB_FUNCTION));
414+
builder.setLabels(Lists.transform(descriptorPb.getLabelsList(),
415+
LabelDescriptor.FROM_PB_FUNCTION));
343416
return builder.build();
344417
}
345418
}

0 commit comments

Comments
 (0)