Skip to content

Commit

Permalink
xds: move XdsLoadBalancer.XdsConfig to XdsLoadBalancerProvider
Browse files Browse the repository at this point in the history
`XdsLoadBalancer` will be replaced by `XdsLoadBalancer2`, and `XdsConfig` is better fit in `XdsLoadBalancerProvider`.
  • Loading branch information
dapengzhang0 authored Aug 16, 2019
1 parent 2c0b2de commit 9dbbcf5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 47 deletions.
47 changes: 2 additions & 45 deletions xds/src/main/java/io/grpc/xds/XdsLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static java.util.logging.Level.FINEST;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import io.grpc.Attributes;
Expand All @@ -47,6 +46,7 @@
import io.grpc.xds.LoadReportClientImpl.LoadReportClientFactory;
import io.grpc.xds.LocalityStore.LocalityStoreImpl;
import io.grpc.xds.XdsComms.AdsStreamCallback;
import io.grpc.xds.XdsLoadBalancerProvider.XdsConfig;
import io.grpc.xds.XdsSubchannelPickers.ErrorPicker;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -196,7 +196,7 @@ public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
}

private void handleNewConfig(XdsConfig xdsConfig) {
String newBalancerName = xdsConfig.newBalancerName;
String newBalancerName = xdsConfig.balancerName;
LbConfig childPolicy = xdsConfig.childPolicy;
ManagedChannel lbChannel;
if (xdsLbState == null) {
Expand Down Expand Up @@ -476,47 +476,4 @@ public void run() {
}
}

/**
* Represents a successfully parsed and validated LoadBalancingConfig for XDS.
*/
static final class XdsConfig {
private final String newBalancerName;
// TODO(carl-mastrangelo): make these Object's containing the fully parsed child configs.
@Nullable
private final LbConfig childPolicy;
@Nullable
private final LbConfig fallbackPolicy;

XdsConfig(
String newBalancerName, @Nullable LbConfig childPolicy, @Nullable LbConfig fallbackPolicy) {
this.newBalancerName = checkNotNull(newBalancerName, "newBalancerName");
this.childPolicy = childPolicy;
this.fallbackPolicy = fallbackPolicy;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("newBalancerName", newBalancerName)
.add("childPolicy", childPolicy)
.add("fallbackPolicy", fallbackPolicy)
.toString();
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof XdsConfig)) {
return false;
}
XdsConfig that = (XdsConfig) obj;
return Objects.equal(this.newBalancerName, that.newBalancerName)
&& Objects.equal(this.childPolicy, that.childPolicy)
&& Objects.equal(this.fallbackPolicy, that.fallbackPolicy);
}

@Override
public int hashCode() {
return Objects.hashCode(newBalancerName, childPolicy, fallbackPolicy);
}
}
}
49 changes: 48 additions & 1 deletion xds/src/main/java/io/grpc/xds/XdsLoadBalancerProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

package io.grpc.xds;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableMap;
import io.grpc.Internal;
import io.grpc.LoadBalancer;
Expand All @@ -28,7 +32,6 @@
import io.grpc.internal.ExponentialBackoffPolicy;
import io.grpc.internal.ServiceConfigUtil;
import io.grpc.internal.ServiceConfigUtil.LbConfig;
import io.grpc.xds.XdsLoadBalancer.XdsConfig;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -120,4 +123,48 @@ private static LbConfig selectSupportedLbPolicy(
}
return null;
}

/**
* Represents a successfully parsed and validated LoadBalancingConfig for XDS.
*/
static final class XdsConfig {
final String balancerName;
// TODO(carl-mastrangelo): make these Object's containing the fully parsed child configs.
@Nullable
final LbConfig childPolicy;
@Nullable
final LbConfig fallbackPolicy;

XdsConfig(
String balancerName, @Nullable LbConfig childPolicy, @Nullable LbConfig fallbackPolicy) {
this.balancerName = checkNotNull(balancerName, "balancerName");
this.childPolicy = childPolicy;
this.fallbackPolicy = fallbackPolicy;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("balancerName", balancerName)
.add("childPolicy", childPolicy)
.add("fallbackPolicy", fallbackPolicy)
.toString();
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof XdsConfig)) {
return false;
}
XdsConfig that = (XdsConfig) obj;
return Objects.equal(this.balancerName, that.balancerName)
&& Objects.equal(this.childPolicy, that.childPolicy)
&& Objects.equal(this.fallbackPolicy, that.fallbackPolicy);
}

@Override
public int hashCode() {
return Objects.hashCode(balancerName, childPolicy, fallbackPolicy);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import io.grpc.internal.JsonParser;
import io.grpc.internal.ServiceConfigUtil;
import io.grpc.internal.ServiceConfigUtil.LbConfig;
import io.grpc.xds.XdsLoadBalancer.XdsConfig;
import io.grpc.xds.XdsLoadBalancerProvider.XdsConfig;
import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
Expand Down

0 comments on commit 9dbbcf5

Please sign in to comment.