Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename setters/getters/builders for Logging classes to meet proto conventions #1313

Merged
merged 3 commits into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ import java.util.Iterator;
LoggingOptions options = LoggingOptions.defaultInstance();
try(Logging logging = options.service()) {

LogEntry firstEntry = LogEntry.builder(StringPayload.of("message"))
.logName("test-log")
.resource(MonitoredResource.builder("global")
LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message"))
.setLogName("test-log")
.setResource(MonitoredResource.builder("global")
.addLabel("project_id", options.projectId())
.build())
.build();
Expand Down
2 changes: 1 addition & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ uses the `RemoteLoggingHelper` to create a metric.
```java
RemoteLoggingHelper loggingHelper =
RemoteLoggingHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
Logging logging = loggingHelper.options().service();
Logging logging = loggingHelper.getOptions().service();
// Pick a name for the resource with low probability of clashing
String metricName = RemoteLoggingHelper.formatForTest("test-metric");
MetricInfo metricInfo = MetricInfo.of(name, "logName:syslog");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ public static class Builder {
* {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object.
* For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL.
*/
@Deprecated
public Builder type(String type) {
return setType(type);
}

/**
* Sets the monitored resource type. This value must match the one of
* {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object.
* For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL.
*/
public Builder setType(String type) {
this.type = type;
return this;
}
Expand All @@ -76,7 +86,17 @@ public Builder type(String type) {
* descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute
* Engine VM instances use the labels {@code instance_id} and {@code zone}.
*/
@Deprecated
public Builder labels(Map<String, String> labels) {
return setLabels(labels);
}

/**
* Sets the values for all the labels required by the corresponding monitored resource
* descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute
* Engine VM instances use the labels {@code instance_id} and {@code zone}.
*/
public Builder setLabels(Map<String, String> labels) {
this.labels = new HashMap<>(checkNotNull(labels));
return this;
}
Expand Down Expand Up @@ -112,7 +132,17 @@ public MonitoredResource build() {
* {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object.
* For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL.
*/
@Deprecated
public String type() {
return getType();
}

/**
* Returns the monitored resource type. This value must match the one of
* {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object.
* For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL.
*/
public String getType() {
return type;
}

Expand All @@ -121,7 +151,17 @@ public String type() {
* descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute
* Engine VM instances use the labels {@code instance_id} and {@code zone}.
*/
@Deprecated
public Map<String, String> labels() {
return getLabels();
}

/**
* Returns the values for all the labels required by the corresponding monitored resource
* descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute
* Engine VM instances use the labels {@code instance_id} and {@code zone}.
*/
public Map<String, String> getLabels() {
return labels;
}

Expand Down Expand Up @@ -167,18 +207,26 @@ public Builder toBuilder() {
/**
* Returns a builder for {@code MonitoredResource} objects given the resource's type.
*/
@Deprecated
public static Builder builder(String type) {
return newBuilder(type);
}

/**
* Returns a builder for {@code MonitoredResource} objects given the resource's type.
*/
public static Builder newBuilder(String type) {
return new Builder(type);
}

/**
* Creates a {@code MonitoredResource} object given the resource's type and labels.
*/
public static MonitoredResource of(String type, Map<String, String> labels) {
return builder(type).labels(labels).build();
return newBuilder(type).setLabels(labels).build();
}

public static MonitoredResource fromPb(com.google.api.MonitoredResource descriptorPb) {
return new Builder(descriptorPb.getType()).labels(descriptorPb.getLabels()).build();
return new Builder(descriptorPb.getType()).setLabels(descriptorPb.getLabelsMap()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,47 @@ static ValueType fromPb(com.google.api.LabelDescriptor.ValueType typePb) {
/**
* Returns the key associated to this label.
*/
@Deprecated
public String key() {
return getKey();
}

/**
* Returns the key associated to this label.
*/
public String getKey() {
return key;
}

/**
* Returns the type of data that can be assigned to this label.
*/
@Deprecated
public ValueType valueType() {
return getValueType();
}

/**
* Returns the type of data that can be assigned to this label.
*/
public ValueType getValueType() {
return valueType;
}

/**
* Returns the optional human-readable description for this label. If not set, this method
* returns {@code null}.
*/
@Deprecated
public String description() {
return getDescription();
}

/**
* Returns the optional human-readable description for this label. If not set, this method
* returns {@code null}.
*/
public String getDescription() {
return description;
}

Expand Down Expand Up @@ -199,22 +224,22 @@ static class Builder {
this.type = type;
}

Builder name(String name) {
Builder setName(String name) {
this.name = name;
return this;
}

Builder displayName(String displayName) {
Builder setDisplayName(String displayName) {
this.displayName = displayName;
return this;
}

Builder description(String description) {
Builder setDescription(String description) {
this.description = description;
return this;
}

Builder labels(List<LabelDescriptor> labels) {
Builder setLabels(List<LabelDescriptor> labels) {
this.labels = labels;
return this;
}
Expand All @@ -236,15 +261,33 @@ MonitoredResourceDescriptor build() {
* Returns the monitored resource type. For example, the type {@code cloudsql_database} represents
* databases in Google Cloud SQL.
*/
@Deprecated
public String type() {
return getType();
}

/**
* Returns the monitored resource type. For example, the type {@code cloudsql_database} represents
* databases in Google Cloud SQL.
*/
public String getType() {
return type;
}

/**
* Returns an optional name for the monitored resource descriptor. If not set, this method returns
* {@code null}.
*/
@Deprecated
public String name() {
return getName();
}

/**
* Returns an optional name for the monitored resource descriptor. If not set, this method returns
* {@code null}.
*/
public String getName() {
return name;
}

Expand All @@ -253,15 +296,34 @@ public String name() {
* in user interfaces. For example, {@code Google Cloud SQL Database}. If not set, this method
* returns {@code null}.
*/
@Deprecated
public String displayName() {
return getDisplayName();
}

/**
* Returns an optional concise name for the monitored resource type. This value might be displayed
* in user interfaces. For example, {@code Google Cloud SQL Database}. If not set, this method
* returns {@code null}.
*/
public String getDisplayName() {
return displayName;
}

/**
* Returns an optional detailed description of the monitored resource type. This value might be
* used in documentation. If not set, this method returns {@code null}.
*/
@Deprecated
public String description() {
return getDescription();
}

/**
* Returns an optional detailed description of the monitored resource type. This value might be
* used in documentation. If not set, this method returns {@code null}.
*/
public String getDescription() {
return description;
}

Expand All @@ -270,7 +332,17 @@ public String description() {
* example, an individual Google Cloud SQL database is identified by values for the labels
* {@code database_id} and {@code region}.
*/
@Deprecated
public List<LabelDescriptor> labels() {
return getLabels();
}

/**
* Returns a list of labels used to describe instances of this monitored resource type. For
* example, an individual Google Cloud SQL database is identified by values for the labels
* {@code database_id} and {@code region}.
*/
public List<LabelDescriptor> getLabels() {
return labels;
}

Expand Down Expand Up @@ -323,23 +395,24 @@ public com.google.api.MonitoredResourceDescriptor toPb() {
return builder.build();
}

static Builder builder(String type) {
static Builder newBuilder(String type) {
return new Builder(type);
}

public static MonitoredResourceDescriptor fromPb(
com.google.api.MonitoredResourceDescriptor descriptorPb) {
Builder builder = builder(descriptorPb.getType());
Builder builder = newBuilder(descriptorPb.getType());
if (descriptorPb.getName() != null && !descriptorPb.getName().equals("")) {
builder.name(descriptorPb.getName());
builder.setName(descriptorPb.getName());
}
if (descriptorPb.getDisplayName() != null && !descriptorPb.getDisplayName().equals("")) {
builder.displayName(descriptorPb.getDisplayName());
builder.setDisplayName(descriptorPb.getDisplayName());
}
if (descriptorPb.getDescription() != null && !descriptorPb.getDescription().equals("")) {
builder.description(descriptorPb.getDescription());
builder.setDescription(descriptorPb.getDescription());
}
builder.labels(Lists.transform(descriptorPb.getLabelsList(), LabelDescriptor.FROM_PB_FUNCTION));
builder.setLabels(Lists.transform(descriptorPb.getLabelsList(),
LabelDescriptor.FROM_PB_FUNCTION));
return builder.build();
}
}
Loading