Search in sources :

Example 1 with DiscoveryResponse

use of io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse in project grpc-java by grpc.

the class MessagePrinterTest method printLdsResponse_v3.

@Test
public void printLdsResponse_v3() {
    Listener listener = Listener.newBuilder().setName("foo.googleapis.com:8080").setAddress(Address.newBuilder().setSocketAddress(SocketAddress.newBuilder().setAddress("10.0.0.1").setPortValue(8080))).addFilterChains(FilterChain.newBuilder().addFilters(Filter.getDefaultInstance()).setTransportSocket(TransportSocket.newBuilder().setName("envoy.transport_sockets.tls").setTypedConfig(Any.pack(DownstreamTlsContext.newBuilder().setCommonTlsContext(CommonTlsContext.newBuilder().addTlsCertificateSdsSecretConfigs(SdsSecretConfig.getDefaultInstance())).build())))).setApiListener(ApiListener.newBuilder().setApiListener(Any.pack(HttpConnectionManager.newBuilder().setRds(Rds.newBuilder().setRouteConfigName("route-foo.googleapis.com").setConfigSource(ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance()))).build()))).build();
    DiscoveryResponse response = DiscoveryResponse.newBuilder().setTypeUrl("type.googleapis.com/envoy.config.listener.v3.Listener").setVersionInfo("0").addResources(Any.pack(listener)).setNonce("0000").build();
    String expectedString = "{\n" + "  \"versionInfo\": \"0\",\n" + "  \"resources\": [{\n" + "    \"@type\": \"type.googleapis.com/envoy.config.listener.v3.Listener\",\n" + "    \"name\": \"foo.googleapis.com:8080\",\n" + "    \"address\": {\n" + "      \"socketAddress\": {\n" + "        \"address\": \"10.0.0.1\",\n" + "        \"portValue\": 8080\n" + "      }\n" + "    },\n" + "    \"filterChains\": [{\n" + "      \"filters\": [{\n" + "      }],\n" + "      \"transportSocket\": {\n" + "        \"name\": \"envoy.transport_sockets.tls\",\n" + "        \"typedConfig\": {\n" + "          \"@type\": \"type.googleapis.com/envoy.extensions.transport_sockets" + ".tls.v3.DownstreamTlsContext\",\n" + "          \"commonTlsContext\": {\n" + "            \"tlsCertificateSdsSecretConfigs\": [{\n" + "            }]\n" + "          }\n" + "        }\n" + "      }\n" + "    }],\n" + "    \"apiListener\": {\n" + "      \"apiListener\": {\n" + "        \"@type\": \"type.googleapis.com/envoy.extensions.filters.network" + ".http_connection_manager.v3.HttpConnectionManager\",\n" + "        \"rds\": {\n" + "          \"configSource\": {\n" + "            \"ads\": {\n" + "            }\n" + "          },\n" + "          \"routeConfigName\": \"route-foo.googleapis.com\"\n" + "        }\n" + "      }\n" + "    }\n" + "  }],\n" + "  \"typeUrl\": \"type.googleapis.com/envoy.config.listener.v3.Listener\",\n" + "  \"nonce\": \"0000\"\n" + "}";
    String res = MessagePrinter.print(response);
    assertThat(res).isEqualTo(expectedString);
}
Also used : DiscoveryResponse(io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse) Listener(io.envoyproxy.envoy.config.listener.v3.Listener) ApiListener(io.envoyproxy.envoy.config.listener.v3.ApiListener) Test(org.junit.Test)

Example 2 with DiscoveryResponse

use of io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse in project metron by apache.

the class TaxiiHandler method discoverPollingClient.

private static DiscoveryResults discoverPollingClient(URL proxy, URL endpoint, String username, String password, HttpClientContext context, String defaultCollection) throws Exception {
    DiscoveryResults results = new DiscoveryResults();
    {
        HttpClient discoverClient = buildClient(proxy, username, password);
        String sessionID = MessageHelper.generateMessageId();
        // Prepare the message to send.
        DiscoveryRequest request = messageFactory.get().createDiscoveryRequest().withMessageId(sessionID);
        DiscoveryResponse response = call(discoverClient, endpoint.toURI(), request, context, DiscoveryResponse.class);
        for (ServiceInstanceType serviceInstance : response.getServiceInstances()) {
            if (serviceInstance.isAvailable() && serviceInstance.getServiceType() == ServiceTypeEnum.POLL) {
                results.pollEndpoint = new URL(serviceInstance.getAddress());
            } else if (serviceInstance.isAvailable() && serviceInstance.getServiceType() == ServiceTypeEnum.COLLECTION_MANAGEMENT) {
                results.collectionManagementEndpoint = new URL(serviceInstance.getAddress());
            }
        }
        if (results.pollEndpoint == null) {
            throw new RuntimeException("Unable to discover a poll TAXII feed");
        }
    }
    if (defaultCollection == null) // get collections
    {
        HttpClient discoverClient = buildClient(proxy, username, password);
        String sessionID = MessageHelper.generateMessageId();
        CollectionInformationRequest request = messageFactory.get().createCollectionInformationRequest().withMessageId(sessionID);
        CollectionInformationResponse response = call(discoverClient, results.collectionManagementEndpoint.toURI(), request, context, CollectionInformationResponse.class);
        LOG.info("Unable to find the default collection; available collections are:");
        for (CollectionRecordType c : response.getCollections()) {
            LOG.info(c.getCollectionName());
            results.collections.add(c.getCollectionName());
        }
        System.exit(0);
    }
    return results;
}
Also used : CollectionInformationResponse(org.mitre.taxii.messages.xml11.CollectionInformationResponse) ServiceInstanceType(org.mitre.taxii.messages.xml11.ServiceInstanceType) DiscoveryResponse(org.mitre.taxii.messages.xml11.DiscoveryResponse) CollectionRecordType(org.mitre.taxii.messages.xml11.CollectionRecordType) HttpClient(org.mitre.taxii.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) CollectionInformationRequest(org.mitre.taxii.messages.xml11.CollectionInformationRequest) DiscoveryRequest(org.mitre.taxii.messages.xml11.DiscoveryRequest) URL(java.net.URL)

Example 3 with DiscoveryResponse

use of io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse in project grpc-java by grpc.

the class ClientXdsClientV3Test method createAdsService.

@Override
protected BindableService createAdsService() {
    return new AggregatedDiscoveryServiceImplBase() {

        @Override
        public StreamObserver<DiscoveryRequest> streamAggregatedResources(final StreamObserver<DiscoveryResponse> responseObserver) {
            // ensure previous call was ended
            assertThat(adsEnded.get()).isTrue();
            adsEnded.set(false);
            @SuppressWarnings("unchecked") StreamObserver<DiscoveryRequest> requestObserver = mock(StreamObserver.class);
            DiscoveryRpcCall call = new DiscoveryRpcCallV3(requestObserver, responseObserver);
            resourceDiscoveryCalls.offer(call);
            Context.current().addListener(new CancellationListener() {

                @Override
                public void cancelled(Context context) {
                    adsEnded.set(true);
                }
            }, MoreExecutors.directExecutor());
            return requestObserver;
        }
    };
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) Context(io.grpc.Context) UpstreamTlsContext(io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext) CertificateValidationContext(io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext) CommonTlsContext(io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext) CancellationListener(io.grpc.Context.CancellationListener) DiscoveryRequest(io.envoyproxy.envoy.service.discovery.v3.DiscoveryRequest) AggregatedDiscoveryServiceImplBase(io.envoyproxy.envoy.service.discovery.v3.AggregatedDiscoveryServiceGrpc.AggregatedDiscoveryServiceImplBase)

Example 4 with DiscoveryResponse

use of io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse in project grpc-java by grpc.

the class MessagePrinterTest method printCdsResponse_v3.

@Test
public void printCdsResponse_v3() {
    Cluster cluster = Cluster.newBuilder().setName("cluster-foo.googleapis.com").setEdsClusterConfig(EdsClusterConfig.newBuilder().setServiceName("backend-service-foo.googleapis.com").setEdsConfig(ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance()))).setLrsServer(ConfigSource.newBuilder().setSelf(SelfConfigSource.getDefaultInstance())).setLbPolicy(LbPolicy.ROUND_ROBIN).setTransportSocket(TransportSocket.newBuilder().setTypedConfig(Any.pack(UpstreamTlsContext.newBuilder().setCommonTlsContext(CommonTlsContext.newBuilder().addTlsCertificateSdsSecretConfigs(SdsSecretConfig.getDefaultInstance())).build()))).build();
    DiscoveryResponse response = DiscoveryResponse.newBuilder().setTypeUrl("type.googleapis.com/envoy.config.cluster.v3.Cluster").setVersionInfo("0").addResources(Any.pack(cluster)).setNonce("0000").build();
    String expectedString = "{\n" + "  \"versionInfo\": \"0\",\n" + "  \"resources\": [{\n" + "    \"@type\": \"type.googleapis.com/envoy.config.cluster.v3.Cluster\",\n" + "    \"name\": \"cluster-foo.googleapis.com\",\n" + "    \"edsClusterConfig\": {\n" + "      \"edsConfig\": {\n" + "        \"ads\": {\n" + "        }\n" + "      },\n" + "      \"serviceName\": \"backend-service-foo.googleapis.com\"\n" + "    },\n" + "    \"transportSocket\": {\n" + "      \"typedConfig\": {\n" + "        \"@type\": \"type.googleapis.com/envoy.extensions.transport_sockets.tls.v3" + ".UpstreamTlsContext\",\n" + "        \"commonTlsContext\": {\n" + "          \"tlsCertificateSdsSecretConfigs\": [{\n" + "          }]\n" + "        }\n" + "      }\n" + "    },\n" + "    \"lrsServer\": {\n" + "      \"self\": {\n" + "      }\n" + "    }\n" + "  }],\n" + "  \"typeUrl\": \"type.googleapis.com/envoy.config.cluster.v3.Cluster\",\n" + "  \"nonce\": \"0000\"\n" + "}";
    String res = MessagePrinter.print(response);
    assertThat(res).isEqualTo(expectedString);
}
Also used : DiscoveryResponse(io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse) Cluster(io.envoyproxy.envoy.config.cluster.v3.Cluster) Test(org.junit.Test)

Example 5 with DiscoveryResponse

use of io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse in project grpc-java by grpc.

the class MessagePrinterTest method printEdsResponse_v3.

@Test
public void printEdsResponse_v3() {
    ClusterLoadAssignment clusterLoadAssignment = ClusterLoadAssignment.newBuilder().setClusterName("cluster-foo.googleapis.com").setPolicy(Policy.newBuilder().addDropOverloads(DropOverload.newBuilder().setCategory("throttle").setDropPercentage(FractionalPercent.newBuilder().setNumerator(80).setDenominator(DenominatorType.HUNDRED)))).addEndpoints(LocalityLbEndpoints.newBuilder().setLocality(Locality.newBuilder().setRegion("region").setZone("zone").setSubZone("subzone")).setPriority(1).setLoadBalancingWeight(UInt32Value.newBuilder().setValue(20)).addLbEndpoints(LbEndpoint.newBuilder().setLoadBalancingWeight(UInt32Value.newBuilder().setValue(100)).setHealthStatus(HealthStatus.UNHEALTHY).setEndpoint(Endpoint.newBuilder().setAddress(Address.newBuilder().setSocketAddress(SocketAddress.newBuilder().setAddress("10.0.0.1").setPortValue(8001)))))).build();
    DiscoveryResponse response = DiscoveryResponse.newBuilder().setTypeUrl("type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment").setVersionInfo("0").addResources(Any.pack(clusterLoadAssignment)).setNonce("0000").build();
    String expectedString = "{\n" + "  \"versionInfo\": \"0\",\n" + "  \"resources\": [{\n" + "    \"@type\": \"type.googleapis.com/envoy.config.endpoint.v3" + ".ClusterLoadAssignment\",\n" + "    \"clusterName\": \"cluster-foo.googleapis.com\",\n" + "    \"endpoints\": [{\n" + "      \"locality\": {\n" + "        \"region\": \"region\",\n" + "        \"zone\": \"zone\",\n" + "        \"subZone\": \"subzone\"\n" + "      },\n" + "      \"lbEndpoints\": [{\n" + "        \"endpoint\": {\n" + "          \"address\": {\n" + "            \"socketAddress\": {\n" + "              \"address\": \"10.0.0.1\",\n" + "              \"portValue\": 8001\n" + "            }\n" + "          }\n" + "        },\n" + "        \"healthStatus\": \"UNHEALTHY\",\n" + "        \"loadBalancingWeight\": 100\n" + "      }],\n" + "      \"loadBalancingWeight\": 20,\n" + "      \"priority\": 1\n" + "    }],\n" + "    \"policy\": {\n" + "      \"dropOverloads\": [{\n" + "        \"category\": \"throttle\",\n" + "        \"dropPercentage\": {\n" + "          \"numerator\": 80\n" + "        }\n" + "      }]\n" + "    }\n" + "  }],\n" + "  \"typeUrl\": \"type.googleapis.com/envoy.config.endpoint.v3" + ".ClusterLoadAssignment\",\n" + "  \"nonce\": \"0000\"\n" + "}";
    String res = MessagePrinter.print(response);
    assertThat(res).isEqualTo(expectedString);
}
Also used : DiscoveryResponse(io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse) ClusterLoadAssignment(io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment) Test(org.junit.Test)

Aggregations

DiscoveryResponse (io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse)4 Test (org.junit.Test)4 Cluster (io.envoyproxy.envoy.config.cluster.v3.Cluster)1 ClusterLoadAssignment (io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment)1 ApiListener (io.envoyproxy.envoy.config.listener.v3.ApiListener)1 Listener (io.envoyproxy.envoy.config.listener.v3.Listener)1 RouteConfiguration (io.envoyproxy.envoy.config.route.v3.RouteConfiguration)1 CertificateValidationContext (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext)1 CommonTlsContext (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext)1 UpstreamTlsContext (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext)1 AggregatedDiscoveryServiceImplBase (io.envoyproxy.envoy.service.discovery.v3.AggregatedDiscoveryServiceGrpc.AggregatedDiscoveryServiceImplBase)1 DiscoveryRequest (io.envoyproxy.envoy.service.discovery.v3.DiscoveryRequest)1 Context (io.grpc.Context)1 CancellationListener (io.grpc.Context.CancellationListener)1 StreamObserver (io.grpc.stub.StreamObserver)1 URL (java.net.URL)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 HttpClient (org.mitre.taxii.client.HttpClient)1 CollectionInformationRequest (org.mitre.taxii.messages.xml11.CollectionInformationRequest)1 CollectionInformationResponse (org.mitre.taxii.messages.xml11.CollectionInformationResponse)1