Search in sources :

Example 6 with ServerInfo

use of io.grpc.xds.Bootstrapper.ServerInfo in project grpc-java by grpc.

the class BootstrapperImplTest method parseBootstrap_multipleXdsServers.

@Test
public void parseBootstrap_multipleXdsServers() throws XdsInitializationException {
    String rawData = "{\n" + "  \"node\": {\n" + "    \"id\": \"ENVOY_NODE_ID\",\n" + "    \"cluster\": \"ENVOY_CLUSTER\",\n" + "    \"locality\": {\n" + "      \"region\": \"ENVOY_REGION\",\n" + "      \"zone\": \"ENVOY_ZONE\",\n" + "      \"sub_zone\": \"ENVOY_SUBZONE\"\n" + "    },\n" + "    \"metadata\": {\n" + "      \"TRAFFICDIRECTOR_INTERCEPTION_PORT\": \"ENVOY_PORT\",\n" + "      \"TRAFFICDIRECTOR_NETWORK_NAME\": \"VPC_NETWORK_NAME\"\n" + "    }\n" + "  },\n" + "  \"xds_servers\": [\n" + "    {\n" + "      \"server_uri\": \"trafficdirector-foo.googleapis.com:443\",\n" + "      \"channel_creds\": [\n" + "        {\"type\": \"tls\"}\n" + "      ]\n" + "    },\n" + "    {\n" + "      \"server_uri\": \"trafficdirector-bar.googleapis.com:443\",\n" + "      \"channel_creds\": [\n" + "        {\"type\": \"insecure\"}" + "      ]\n" + "    }\n" + "  ]\n" + "}";
    bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
    BootstrapInfo info = bootstrapper.bootstrap();
    assertThat(info.servers()).hasSize(2);
    List<ServerInfo> serverInfoList = info.servers();
    assertThat(serverInfoList.get(0).target()).isEqualTo("trafficdirector-foo.googleapis.com:443");
    assertThat(serverInfoList.get(0).channelCredentials()).isInstanceOf(TlsChannelCredentials.class);
    assertThat(serverInfoList.get(1).target()).isEqualTo("trafficdirector-bar.googleapis.com:443");
    assertThat(serverInfoList.get(1).channelCredentials()).isInstanceOf(InsecureChannelCredentials.class);
    assertThat(info.node()).isEqualTo(getNodeBuilder().setId("ENVOY_NODE_ID").setCluster("ENVOY_CLUSTER").setLocality(Locality.create("ENVOY_REGION", "ENVOY_ZONE", "ENVOY_SUBZONE")).setMetadata(ImmutableMap.of("TRAFFICDIRECTOR_INTERCEPTION_PORT", "ENVOY_PORT", "TRAFFICDIRECTOR_NETWORK_NAME", "VPC_NETWORK_NAME")).build());
}
Also used : BootstrapInfo(io.grpc.xds.Bootstrapper.BootstrapInfo) ServerInfo(io.grpc.xds.Bootstrapper.ServerInfo) Test(org.junit.Test)

Example 7 with ServerInfo

use of io.grpc.xds.Bootstrapper.ServerInfo in project grpc-java by grpc.

the class BootstrapperImplTest method parseBootstrap_useFirstSupportedChannelCredentials.

@Test
public void parseBootstrap_useFirstSupportedChannelCredentials() throws XdsInitializationException {
    String rawData = "{\n" + "  \"xds_servers\": [\n" + "    {\n" + "      \"server_uri\": \"" + SERVER_URI + "\",\n" + "      \"channel_creds\": [\n" + "        {\"type\": \"unsupported\"}, {\"type\": \"insecure\"}, {\"type\": \"tls\"}\n" + "      ]\n" + "    }\n" + "  ]\n" + "}";
    bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
    BootstrapInfo info = bootstrapper.bootstrap();
    assertThat(info.servers()).hasSize(1);
    ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
    assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
    assertThat(serverInfo.channelCredentials()).isInstanceOf(InsecureChannelCredentials.class);
    assertThat(info.node()).isEqualTo(getNodeBuilder().build());
}
Also used : BootstrapInfo(io.grpc.xds.Bootstrapper.BootstrapInfo) ServerInfo(io.grpc.xds.Bootstrapper.ServerInfo) Test(org.junit.Test)

Example 8 with ServerInfo

use of io.grpc.xds.Bootstrapper.ServerInfo in project grpc-java by grpc.

the class ClientXdsClientTestBase method setUp.

@Before
public void setUp() throws IOException {
    // Init mocks.
    MockitoAnnotations.initMocks(this);
    when(backoffPolicyProvider.get()).thenReturn(backoffPolicy1, backoffPolicy2);
    when(backoffPolicy1.nextBackoffNanos()).thenReturn(10L, 100L);
    when(backoffPolicy2.nextBackoffNanos()).thenReturn(20L, 200L);
    // Start the server and the client.
    originalEnableFaultInjection = ClientXdsClient.enableFaultInjection;
    ClientXdsClient.enableFaultInjection = true;
    originalEnableRbac = ClientXdsClient.enableRbac;
    assertThat(originalEnableRbac).isTrue();
    originalEnableLeastRequest = ClientXdsClient.enableLeastRequest;
    ClientXdsClient.enableLeastRequest = true;
    final String serverName = InProcessServerBuilder.generateName();
    cleanupRule.register(InProcessServerBuilder.forName(serverName).addService(createAdsService()).addService(createLrsService()).directExecutor().build().start());
    channel = cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
    XdsChannelFactory xdsChannelFactory = new XdsChannelFactory() {

        @Override
        ManagedChannel create(ServerInfo serverInfo) {
            if (serverInfo.target().equals(SERVER_URI)) {
                return channel;
            }
            if (serverInfo.target().equals(SERVER_URI_CUSTOME_AUTHORITY)) {
                if (channelForCustomAuthority == null) {
                    channelForCustomAuthority = cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
                }
                return channelForCustomAuthority;
            }
            if (serverInfo.target().equals(SERVER_URI_EMPTY_AUTHORITY)) {
                if (channelForEmptyAuthority == null) {
                    channelForEmptyAuthority = cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
                }
                return channelForEmptyAuthority;
            }
            throw new IllegalArgumentException("Can not create channel for " + serverInfo);
        }
    };
    Bootstrapper.BootstrapInfo bootstrapInfo = Bootstrapper.BootstrapInfo.builder().servers(Arrays.asList(Bootstrapper.ServerInfo.create(SERVER_URI, CHANNEL_CREDENTIALS, useProtocolV3()))).node(EnvoyProtoData.Node.newBuilder().build()).authorities(ImmutableMap.of("authority.xds.com", AuthorityInfo.create("xdstp://authority.xds.com/envoy.config.listener.v3.Listener/%s", ImmutableList.of(Bootstrapper.ServerInfo.create(SERVER_URI_CUSTOME_AUTHORITY, CHANNEL_CREDENTIALS, useProtocolV3()))), "", AuthorityInfo.create("xdstp:///envoy.config.listener.v3.Listener/%s", ImmutableList.of(Bootstrapper.ServerInfo.create(SERVER_URI_EMPTY_AUTHORITY, CHANNEL_CREDENTIALS, useProtocolV3()))))).certProviders(ImmutableMap.of("cert-instance-name", CertificateProviderInfo.create("file-watcher", ImmutableMap.<String, Object>of()))).build();
    xdsClient = new ClientXdsClient(xdsChannelFactory, bootstrapInfo, Context.ROOT, fakeClock.getScheduledExecutorService(), backoffPolicyProvider, fakeClock.getStopwatchSupplier(), timeProvider, tlsContextManager);
    assertThat(resourceDiscoveryCalls).isEmpty();
    assertThat(loadReportCalls).isEmpty();
}
Also used : XdsChannelFactory(io.grpc.xds.ClientXdsClient.XdsChannelFactory) ServerInfo(io.grpc.xds.Bootstrapper.ServerInfo) Before(org.junit.Before)

Example 9 with ServerInfo

use of io.grpc.xds.Bootstrapper.ServerInfo in project grpc-java by grpc.

the class BootstrapperImplTest method useV3ProtocolIfV3FeaturePresent.

@Test
public void useV3ProtocolIfV3FeaturePresent() throws XdsInitializationException {
    String rawData = "{\n" + "  \"xds_servers\": [\n" + "    {\n" + "      \"server_uri\": \"" + SERVER_URI + "\",\n" + "      \"channel_creds\": [\n" + "        {\"type\": \"insecure\"}\n" + "      ],\n" + "      \"server_features\": [\"xds_v3\"]\n" + "    }\n" + "  ]\n" + "}";
    bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
    BootstrapInfo info = bootstrapper.bootstrap();
    ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
    assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
    assertThat(serverInfo.channelCredentials()).isInstanceOf(InsecureChannelCredentials.class);
    assertThat(serverInfo.useProtocolV3()).isTrue();
}
Also used : BootstrapInfo(io.grpc.xds.Bootstrapper.BootstrapInfo) ServerInfo(io.grpc.xds.Bootstrapper.ServerInfo) Test(org.junit.Test)

Example 10 with ServerInfo

use of io.grpc.xds.Bootstrapper.ServerInfo in project grpc-java by grpc.

the class BootstrapperImplTest method parseBootstrap_IgnoreIrrelevantFields.

@Test
public void parseBootstrap_IgnoreIrrelevantFields() throws XdsInitializationException {
    String rawData = "{\n" + "  \"node\": {\n" + "    \"id\": \"ENVOY_NODE_ID\",\n" + "    \"cluster\": \"ENVOY_CLUSTER\",\n" + "    \"locality\": {},\n" + "    \"metadata\": {\n" + "      \"TRAFFICDIRECTOR_INTERCEPTION_PORT\": \"ENVOY_PORT\",\n" + "      \"TRAFFICDIRECTOR_NETWORK_NAME\": \"VPC_NETWORK_NAME\"\n" + "    }\n" + "  },\n" + "  \"xds_servers\": [\n" + "    {\n" + "      \"server_uri\": \"" + SERVER_URI + "\",\n" + "      \"ignore\": \"something irrelevant\"," + "      \"channel_creds\": [\n" + "        {\"type\": \"insecure\"}\n" + "      ]\n" + "    }\n" + "  ],\n" + "  \"ignore\": \"something irrelevant\"\n" + "}";
    bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
    BootstrapInfo info = bootstrapper.bootstrap();
    assertThat(info.servers()).hasSize(1);
    ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
    assertThat(serverInfo.target()).isEqualTo(SERVER_URI);
    assertThat(serverInfo.channelCredentials()).isInstanceOf(InsecureChannelCredentials.class);
    assertThat(info.node()).isEqualTo(getNodeBuilder().setId("ENVOY_NODE_ID").setCluster("ENVOY_CLUSTER").setLocality(Locality.create("", "", "")).setMetadata(ImmutableMap.of("TRAFFICDIRECTOR_INTERCEPTION_PORT", "ENVOY_PORT", "TRAFFICDIRECTOR_NETWORK_NAME", "VPC_NETWORK_NAME")).build());
}
Also used : BootstrapInfo(io.grpc.xds.Bootstrapper.BootstrapInfo) ServerInfo(io.grpc.xds.Bootstrapper.ServerInfo) Test(org.junit.Test)

Aggregations

ServerInfo (io.grpc.xds.Bootstrapper.ServerInfo)12 BootstrapInfo (io.grpc.xds.Bootstrapper.BootstrapInfo)10 Test (org.junit.Test)10 RefCountedXdsClientObjectPool (io.grpc.xds.SharedXdsClientPoolProvider.RefCountedXdsClientObjectPool)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Thresholds (io.envoyproxy.envoy.config.cluster.v3.CircuitBreakers.Thresholds)1 Cluster (io.envoyproxy.envoy.config.cluster.v3.Cluster)1 DiscoveryType (io.envoyproxy.envoy.config.cluster.v3.Cluster.DiscoveryType)1 SocketAddress (io.envoyproxy.envoy.config.core.v3.SocketAddress)1 ClusterLoadAssignment (io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment)1 XdsChannelFactory (io.grpc.xds.ClientXdsClient.XdsChannelFactory)1 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)1 UpstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext)1 InetSocketAddress (java.net.InetSocketAddress)1 Before (org.junit.Before)1