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);
}
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;
}
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;
}
};
}
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);
}
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);
}
Aggregations