xds: add toString() and delete unnecessary equals()/hashCode() for LB configs (#7451)

This commit is contained in:
Chengyuan Zhang 2020-09-23 17:06:55 -07:00 committed by GitHub
parent f055200566
commit f62742561d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 40 deletions

View File

@ -82,5 +82,10 @@ final class AddressFilter {
PathChain(String name) {
this.name = checkNotNull(name, "name");
}
@Override
public String toString() {
return name + (next == null ? "" : ", " + next);
}
}
}

View File

@ -18,6 +18,7 @@ package io.grpc.xds;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.MoreObjects;
import io.grpc.Internal;
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.Helper;
@ -26,7 +27,6 @@ import io.grpc.NameResolver.ConfigOrError;
import io.grpc.Status;
import io.grpc.internal.JsonUtil;
import java.util.Map;
import java.util.Objects;
/**
* The provider for the "cds" balancing policy. This class should not be directly referenced in
@ -96,20 +96,8 @@ public class CdsLoadBalancerProvider extends LoadBalancerProvider {
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CdsConfig cdsConfig = (CdsConfig) o;
return Objects.equals(name, cdsConfig.name);
}
@Override
public int hashCode() {
return Objects.hash(name);
public String toString() {
return MoreObjects.toStringHelper(this).add("name", name).toString();
}
}
}

View File

@ -19,7 +19,6 @@ package io.grpc.xds;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import io.grpc.Internal;
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.Helper;
@ -95,29 +94,5 @@ public class EdsLoadBalancerProvider extends LoadBalancerProvider {
.add("endpointPickingPolicy", endpointPickingPolicy)
.toString();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof EdsConfig)) {
return false;
}
EdsConfig that = (EdsConfig) obj;
return Objects.equal(this.clusterName, that.clusterName)
&& Objects.equal(this.edsServiceName, that.edsServiceName)
&& Objects.equal(this.lrsServerName, that.lrsServerName)
&& Objects.equal(this.localityPickingPolicy, that.localityPickingPolicy)
&& Objects.equal(this.endpointPickingPolicy, that.endpointPickingPolicy);
}
@Override
public int hashCode() {
return
Objects.hashCode(
clusterName,
edsServiceName,
lrsServerName,
localityPickingPolicy,
endpointPickingPolicy);
}
}
}

View File

@ -18,6 +18,7 @@ package io.grpc.xds;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.MoreObjects;
import io.grpc.Internal;
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancerProvider;
@ -80,5 +81,16 @@ public final class LrsLoadBalancerProvider extends LoadBalancerProvider {
this.locality = checkNotNull(locality, "locality");
this.childPolicy = checkNotNull(childPolicy, "childPolicy");
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("clusterName", clusterName)
.add("edsServiceName", edsServiceName)
.add("lrsServerName", lrsServerName)
.add("locality", locality)
.add("childPolicy", childPolicy)
.toString();
}
}
}