Search in sources :

Example 1 with DiscoveryRequest

use of io.envoyproxy.envoy.service.discovery.v3.DiscoveryRequest 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 2 with DiscoveryRequest

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

the class ClientXdsClientV2Test 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 DiscoveryRpcCallV2(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) CommonTlsContext(io.envoyproxy.envoy.api.v2.auth.CommonTlsContext) UpstreamTlsContext(io.envoyproxy.envoy.api.v2.auth.UpstreamTlsContext) CancellationListener(io.grpc.Context.CancellationListener) DiscoveryRequest(io.envoyproxy.envoy.api.v2.DiscoveryRequest) AggregatedDiscoveryServiceImplBase(io.envoyproxy.envoy.service.discovery.v2.AggregatedDiscoveryServiceGrpc.AggregatedDiscoveryServiceImplBase)

Example 3 with DiscoveryRequest

use of io.envoyproxy.envoy.service.discovery.v3.DiscoveryRequest 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)

Aggregations

Context (io.grpc.Context)2 CancellationListener (io.grpc.Context.CancellationListener)2 StreamObserver (io.grpc.stub.StreamObserver)2 DiscoveryRequest (io.envoyproxy.envoy.api.v2.DiscoveryRequest)1 CommonTlsContext (io.envoyproxy.envoy.api.v2.auth.CommonTlsContext)1 UpstreamTlsContext (io.envoyproxy.envoy.api.v2.auth.UpstreamTlsContext)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.v2.AggregatedDiscoveryServiceGrpc.AggregatedDiscoveryServiceImplBase)1 AggregatedDiscoveryServiceImplBase (io.envoyproxy.envoy.service.discovery.v3.AggregatedDiscoveryServiceGrpc.AggregatedDiscoveryServiceImplBase)1 DiscoveryRequest (io.envoyproxy.envoy.service.discovery.v3.DiscoveryRequest)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 CollectionRecordType (org.mitre.taxii.messages.xml11.CollectionRecordType)1 DiscoveryRequest (org.mitre.taxii.messages.xml11.DiscoveryRequest)1 DiscoveryResponse (org.mitre.taxii.messages.xml11.DiscoveryResponse)1