use of io.grpc.xds.CdsLoadBalancerProvider.CdsConfig in project grpc-java by grpc.
the class CdsLoadBalancer2 method handleResolvedAddresses.
@Override
public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
if (this.resolvedAddresses != null) {
return;
}
logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
this.resolvedAddresses = resolvedAddresses;
xdsClientPool = resolvedAddresses.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL);
xdsClient = xdsClientPool.getObject();
CdsConfig config = (CdsConfig) resolvedAddresses.getLoadBalancingPolicyConfig();
logger.log(XdsLogLevel.INFO, "Config: {0}", config);
cdsLbState = new CdsLbState(config.name);
cdsLbState.start();
}
use of io.grpc.xds.CdsLoadBalancerProvider.CdsConfig in project grpc-java by grpc.
the class CdsLoadBalancer2Test method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(helper.getSynchronizationContext()).thenReturn(syncContext);
lbRegistry.register(new FakeLoadBalancerProvider(CLUSTER_RESOLVER_POLICY_NAME));
lbRegistry.register(new FakeLoadBalancerProvider("round_robin"));
lbRegistry.register(new FakeLoadBalancerProvider("ring_hash_experimental"));
lbRegistry.register(new FakeLoadBalancerProvider("least_request_experimental"));
loadBalancer = new CdsLoadBalancer2(helper, lbRegistry);
loadBalancer.handleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(Collections.<EquivalentAddressGroup>emptyList()).setAttributes(// Other attributes not used by cluster_resolver LB are omitted.
Attributes.newBuilder().set(InternalXdsAttributes.XDS_CLIENT_POOL, xdsClientPool).build()).setLoadBalancingPolicyConfig(new CdsConfig(CLUSTER)).build());
assertThat(Iterables.getOnlyElement(xdsClient.watchers.keySet())).isEqualTo(CLUSTER);
}
use of io.grpc.xds.CdsLoadBalancerProvider.CdsConfig in project grpc-java by grpc.
the class CdsLoadBalancerProviderTest method parseCdsLoadBalancingPolicyConfig.
@Test
public void parseCdsLoadBalancingPolicyConfig() throws IOException {
CdsLoadBalancerProvider provider = new CdsLoadBalancerProvider();
String rawCdsLbConfig = "{\n" + " \"cluster\": \"cluster-foo.googleapis.com\"\n" + "}";
@SuppressWarnings("unchecked") Map<String, ?> rawLbConfigMap = (Map<String, ?>) JsonParser.parse(rawCdsLbConfig);
ConfigOrError result = provider.parseLoadBalancingPolicyConfig(rawLbConfigMap);
assertThat(result.getConfig()).isNotNull();
CdsConfig config = (CdsConfig) result.getConfig();
assertThat(config.name).isEqualTo("cluster-foo.googleapis.com");
}
Aggregations