Search in sources :

Example 16 with ClusterResolverConfig

use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig in project grpc-java by grpc.

the class CdsLoadBalancer2Test method aggregateCluster_discoveryErrorAfterChildLbCreated_propagateToChildLb.

@Test
public void aggregateCluster_discoveryErrorAfterChildLbCreated_propagateToChildLb() {
    String cluster1 = "cluster-01.googleapis.com";
    // CLUSTER (aggr.) -> [cluster1 (logical DNS)]
    CdsUpdate update = CdsUpdate.forAggregate(CLUSTER, Collections.singletonList(cluster1)).roundRobinLbPolicy().build();
    xdsClient.deliverCdsUpdate(CLUSTER, update);
    CdsUpdate update1 = CdsUpdate.forLogicalDns(cluster1, DNS_HOST_NAME, LRS_SERVER_INFO, 200L, null).roundRobinLbPolicy().build();
    xdsClient.deliverCdsUpdate(cluster1, update1);
    FakeLoadBalancer childLb = Iterables.getOnlyElement(childBalancers);
    ClusterResolverConfig childLbConfig = (ClusterResolverConfig) childLb.config;
    assertThat(childLbConfig.discoveryMechanisms).hasSize(1);
    Status error = Status.RESOURCE_EXHAUSTED.withDescription("OOM");
    xdsClient.deliverError(error);
    assertThat(childLb.upstreamError).isEqualTo(error);
    // child LB may choose to keep working
    assertThat(childLb.shutdown).isFalse();
}
Also used : Status(io.grpc.Status) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) CdsUpdate(io.grpc.xds.XdsClient.CdsUpdate) Test(org.junit.Test)

Example 17 with ClusterResolverConfig

use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig in project grpc-java by grpc.

the class ClusterResolverLoadBalancer method handleResolvedAddresses.

@Override
public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
    logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
    if (xdsClientPool == null) {
        xdsClientPool = resolvedAddresses.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL);
        xdsClient = xdsClientPool.getObject();
    }
    ClusterResolverConfig config = (ClusterResolverConfig) resolvedAddresses.getLoadBalancingPolicyConfig();
    if (!Objects.equals(this.config, config)) {
        logger.log(XdsLogLevel.DEBUG, "Config: {0}", config);
        delegate.switchTo(new ClusterResolverLbStateFactory());
        this.config = config;
        delegate.handleResolvedAddresses(resolvedAddresses);
    }
}
Also used : ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig)

Example 18 with ClusterResolverConfig

use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig in project grpc-java by grpc.

the class CdsLoadBalancer2Test method nonAggregateCluster_resourceRevoked.

@Test
public void nonAggregateCluster_resourceRevoked() {
    CdsUpdate update = CdsUpdate.forLogicalDns(CLUSTER, DNS_HOST_NAME, null, 100L, upstreamTlsContext).roundRobinLbPolicy().build();
    xdsClient.deliverCdsUpdate(CLUSTER, update);
    assertThat(childBalancers).hasSize(1);
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    ClusterResolverConfig childLbConfig = (ClusterResolverConfig) childBalancer.config;
    DiscoveryMechanism instance = Iterables.getOnlyElement(childLbConfig.discoveryMechanisms);
    assertDiscoveryMechanism(instance, CLUSTER, DiscoveryMechanism.Type.LOGICAL_DNS, null, DNS_HOST_NAME, null, 100L, upstreamTlsContext);
    xdsClient.deliverResourceNotExist(CLUSTER);
    assertThat(childBalancer.shutdown).isTrue();
    Status unavailable = Status.UNAVAILABLE.withDescription("CDS error: found 0 leaf (logical DNS or EDS) clusters for root cluster " + CLUSTER);
    verify(helper).updateBalancingState(eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
    assertPicker(pickerCaptor.getValue(), unavailable, null);
    assertThat(childBalancer.shutdown).isTrue();
    assertThat(childBalancers).isEmpty();
}
Also used : Status(io.grpc.Status) DiscoveryMechanism(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig.DiscoveryMechanism) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) CdsUpdate(io.grpc.xds.XdsClient.CdsUpdate) Test(org.junit.Test)

Example 19 with ClusterResolverConfig

use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig in project grpc-java by grpc.

the class CdsLoadBalancer2Test method nonAggregateCluster_resourceUpdate.

@Test
public void nonAggregateCluster_resourceUpdate() {
    CdsUpdate update = CdsUpdate.forEds(CLUSTER, null, null, 100L, upstreamTlsContext).roundRobinLbPolicy().build();
    xdsClient.deliverCdsUpdate(CLUSTER, update);
    assertThat(childBalancers).hasSize(1);
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    ClusterResolverConfig childLbConfig = (ClusterResolverConfig) childBalancer.config;
    DiscoveryMechanism instance = Iterables.getOnlyElement(childLbConfig.discoveryMechanisms);
    assertDiscoveryMechanism(instance, CLUSTER, DiscoveryMechanism.Type.EDS, null, null, null, 100L, upstreamTlsContext);
    update = CdsUpdate.forEds(CLUSTER, EDS_SERVICE_NAME, LRS_SERVER_INFO, 200L, null).roundRobinLbPolicy().build();
    xdsClient.deliverCdsUpdate(CLUSTER, update);
    childLbConfig = (ClusterResolverConfig) childBalancer.config;
    instance = Iterables.getOnlyElement(childLbConfig.discoveryMechanisms);
    assertDiscoveryMechanism(instance, CLUSTER, DiscoveryMechanism.Type.EDS, EDS_SERVICE_NAME, null, LRS_SERVER_INFO, 200L, null);
}
Also used : DiscoveryMechanism(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig.DiscoveryMechanism) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) CdsUpdate(io.grpc.xds.XdsClient.CdsUpdate) Test(org.junit.Test)

Example 20 with ClusterResolverConfig

use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method handleNameResolutionErrorFromUpstream_beforeChildLbCreated_returnErrorPicker.

@Test
public void handleNameResolutionErrorFromUpstream_beforeChildLbCreated_returnErrorPicker() {
    ClusterResolverConfig config = new ClusterResolverConfig(Arrays.asList(edsDiscoveryMechanism1, logicalDnsDiscoveryMechanism), roundRobin);
    deliverLbConfig(config);
    assertThat(xdsClient.watchers.keySet()).containsExactly(EDS_SERVICE_NAME1);
    assertResolverCreated("/" + DNS_HOST_NAME);
    assertThat(childBalancers).isEmpty();
    reset(helper);
    Status upstreamError = Status.UNAVAILABLE.withDescription("unreachable");
    loadBalancer.handleNameResolutionError(upstreamError);
    verify(helper).updateBalancingState(eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
    assertPicker(pickerCaptor.getValue(), upstreamError, null);
}
Also used : Status(io.grpc.Status) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) Test(org.junit.Test)

Aggregations

ClusterResolverConfig (io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig)30 Test (org.junit.Test)29 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)17 LocalityLbEndpoints (io.grpc.xds.Endpoints.LocalityLbEndpoints)12 Status (io.grpc.Status)9 PriorityLbConfig (io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig)9 CdsUpdate (io.grpc.xds.XdsClient.CdsUpdate)9 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)6 ClusterImplConfig (io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig)5 DiscoveryMechanism (io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig.DiscoveryMechanism)5 PriorityChildConfig (io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig.PriorityChildConfig)5 ConnectivityState (io.grpc.ConnectivityState)3 WeightedTargetConfig (io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedTargetConfig)3 RingHashConfig (io.grpc.xds.RingHashLoadBalancer.RingHashConfig)2 InOrder (org.mockito.InOrder)2 ScheduledTask (io.grpc.internal.FakeClock.ScheduledTask)1 LeastRequestConfig (io.grpc.xds.LeastRequestLoadBalancer.LeastRequestConfig)1 WeightedPolicySelection (io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedPolicySelection)1