Search in sources :

Example 6 with BootstrapInfo

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

the class BootstrapperImplTest method parseBootstrap_singleXdsServer.

@Test
public void parseBootstrap_singleXdsServer() 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\": \"" + SERVER_URI + "\",\n" + "      \"channel_creds\": [\n" + "        {\"type\": \"insecure\"}\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().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 BootstrapInfo

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

the class BootstrapperImplTest method parseBootstrap_certProviderInstances.

@Test
public void parseBootstrap_certProviderInstances() throws XdsInitializationException {
    String rawData = "{\n" + "  \"xds_servers\": [],\n" + "  \"certificate_providers\": {\n" + "    \"gcp_id\": {\n" + "      \"plugin_name\": \"meshca\",\n" + "      \"config\": {\n" + "        \"server\": {\n" + "          \"api_type\": \"GRPC\",\n" + "          \"grpc_services\": [{\n" + "            \"google_grpc\": {\n" + "              \"target_uri\": \"meshca.com\",\n" + "              \"channel_credentials\": {\"google_default\": {}},\n" + "              \"call_credentials\": [{\n" + "                \"sts_service\": {\n" + "                  \"token_exchange_service\": \"securetoken.googleapis.com\",\n" + "                  \"subject_token_path\": \"/etc/secret/sajwt.token\"\n" + "                }\n" + // end call_credentials
    "              }]\n" + // end google_grpc
    "            },\n" + "            \"time_out\": {\"seconds\": 10}\n" + // end grpc_services
    "          }]\n" + // end server
    "        },\n" + "        \"certificate_lifetime\": {\"seconds\": 86400},\n" + "        \"renewal_grace_period\": {\"seconds\": 3600},\n" + "        \"key_type\": \"RSA\",\n" + "        \"key_size\": 2048,\n" + "        \"location\": \"https://container.googleapis.com/v1/project/test-project1/locations/test-zone2/clusters/test-cluster3\"\n" + // end config
    "      }\n" + // end gcp_id
    "    },\n" + "    \"file_provider\": {\n" + "      \"plugin_name\": \"file_watcher\",\n" + "      \"config\": {\"path\": \"/etc/secret/certs\"}\n" + "    }\n" + "  }\n" + "}";
    bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
    BootstrapInfo info = bootstrapper.bootstrap();
    assertThat(info.servers()).isEmpty();
    assertThat(info.node()).isEqualTo(getNodeBuilder().build());
    Map<String, Bootstrapper.CertificateProviderInfo> certProviders = info.certProviders();
    assertThat(certProviders).isNotNull();
    Bootstrapper.CertificateProviderInfo gcpId = certProviders.get("gcp_id");
    Bootstrapper.CertificateProviderInfo fileProvider = certProviders.get("file_provider");
    assertThat(gcpId.pluginName()).isEqualTo("meshca");
    assertThat(gcpId.config()).isInstanceOf(Map.class);
    assertThat(fileProvider.pluginName()).isEqualTo("file_watcher");
    assertThat(fileProvider.config()).isInstanceOf(Map.class);
    Map<String, ?> meshCaConfig = gcpId.config();
    assertThat(meshCaConfig.get("key_size")).isEqualTo(2048);
}
Also used : BootstrapInfo(io.grpc.xds.Bootstrapper.BootstrapInfo) Test(org.junit.Test)

Example 8 with BootstrapInfo

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

the class BootstrapperImplTest method useV2ProtocolByDefault.

@Test
public void useV2ProtocolByDefault() throws XdsInitializationException {
    String rawData = "{\n" + "  \"xds_servers\": [\n" + "    {\n" + "      \"server_uri\": \"" + SERVER_URI + "\",\n" + "      \"channel_creds\": [\n" + "        {\"type\": \"insecure\"}\n" + "      ],\n" + "      \"server_features\": []\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()).isFalse();
}
Also used : BootstrapInfo(io.grpc.xds.Bootstrapper.BootstrapInfo) ServerInfo(io.grpc.xds.Bootstrapper.ServerInfo) Test(org.junit.Test)

Example 9 with BootstrapInfo

use of io.grpc.xds.Bootstrapper.BootstrapInfo 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 10 with BootstrapInfo

use of io.grpc.xds.Bootstrapper.BootstrapInfo 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)

Aggregations

BootstrapInfo (io.grpc.xds.Bootstrapper.BootstrapInfo)17 Test (org.junit.Test)15 ServerInfo (io.grpc.xds.Bootstrapper.ServerInfo)10 RefCountedXdsClientObjectPool (io.grpc.xds.SharedXdsClientPoolProvider.RefCountedXdsClientObjectPool)3 AuthorityInfo (io.grpc.xds.Bootstrapper.AuthorityInfo)2