Search in sources :

Example 36 with ManagedChannel

use of io.grpc.ManagedChannel in project seldon-core by SeldonIO.

the class SeldonGrpcServer method getChannel.

/**
 * Using the principal from authorization return a client gRPC channel to connect to the engine running the prediction graph.
 * @return ManagedChannel
 */
public ManagedChannel getChannel() {
    final String principal = getPrincipal();
    if (principal == null) {
        throw new SeldonAPIException(SeldonAPIException.ApiExceptionType.APIFE_GRPC_NO_PRINCIPAL_FOUND, "");
    }
    final DeploymentSpec deploymentSpec = deploymentStore.getDeployment(principal);
    if (deploymentSpec == null) {
        throw new SeldonAPIException(SeldonAPIException.ApiExceptionType.APIFE_NO_RUNNING_DEPLOYMENT, "Principal is " + principal);
    }
    ManagedChannel channel = channelStore.get(principal);
    if (channel == null) {
        throw new SeldonAPIException(SeldonAPIException.ApiExceptionType.APIFE_GRPC_NO_GRPC_CHANNEL_FOUND, "Principal is " + principal);
    }
    return channel;
}
Also used : SeldonAPIException(io.seldon.apife.exception.SeldonAPIException) DeploymentSpec(io.seldon.protos.DeploymentProtos.DeploymentSpec) ManagedChannel(io.grpc.ManagedChannel)

Example 37 with ManagedChannel

use of io.grpc.ManagedChannel in project flink by apache.

the class DefaultPubSubSubscriberFactory method getSubscriber.

@Override
public PubSubSubscriber getSubscriber(Credentials credentials) throws IOException {
    ManagedChannel channel = NettyChannelBuilder.forTarget(SubscriberStubSettings.getDefaultEndpoint()).negotiationType(NegotiationType.TLS).sslContext(GrpcSslContexts.forClient().ciphers(null).build()).build();
    PullRequest pullRequest = PullRequest.newBuilder().setMaxMessages(maxMessagesPerPull).setSubscription(projectSubscriptionName).build();
    SubscriberGrpc.SubscriberBlockingStub stub = SubscriberGrpc.newBlockingStub(channel).withCallCredentials(MoreCallCredentials.from(credentials));
    return new BlockingGrpcPubSubSubscriber(projectSubscriptionName, channel, stub, pullRequest, retries, timeout);
}
Also used : PullRequest(com.google.pubsub.v1.PullRequest) ManagedChannel(io.grpc.ManagedChannel) SubscriberGrpc(com.google.pubsub.v1.SubscriberGrpc)

Example 38 with ManagedChannel

use of io.grpc.ManagedChannel in project flink by apache.

the class PubSubSubscriberFactoryForEmulator method getSubscriber.

@Override
public PubSubSubscriber getSubscriber(Credentials credentials) throws IOException {
    ManagedChannel managedChannel = NettyChannelBuilder.forTarget(hostAndPort).usePlaintext().build();
    PullRequest pullRequest = PullRequest.newBuilder().setMaxMessages(maxMessagesPerPull).setSubscription(projectSubscriptionName).build();
    SubscriberGrpc.SubscriberBlockingStub stub = SubscriberGrpc.newBlockingStub(managedChannel);
    return new BlockingGrpcPubSubSubscriber(projectSubscriptionName, managedChannel, stub, pullRequest, retries, timeout);
}
Also used : BlockingGrpcPubSubSubscriber(org.apache.flink.streaming.connectors.gcp.pubsub.BlockingGrpcPubSubSubscriber) PullRequest(com.google.pubsub.v1.PullRequest) ManagedChannel(io.grpc.ManagedChannel) SubscriberGrpc(com.google.pubsub.v1.SubscriberGrpc)

Example 39 with ManagedChannel

use of io.grpc.ManagedChannel in project pinpoint by naver.

the class GrpcDataSender method release.

protected void release() {
    ExecutorUtils.shutdownExecutorService(name, executor);
    final ManagedChannel managedChannel = this.managedChannel;
    if (managedChannel != null) {
        ManagedChannelUtils.shutdownManagedChannel(name, managedChannel);
    }
    final ChannelFactory channelFactory = this.channelFactory;
    if (channelFactory != null) {
        channelFactory.close();
    }
}
Also used : ManagedChannel(io.grpc.ManagedChannel) ChannelFactory(com.navercorp.pinpoint.grpc.client.ChannelFactory)

Example 40 with ManagedChannel

use of io.grpc.ManagedChannel in project pinpoint by naver.

the class DefaultChannelFactory method build.

@Override
public ManagedChannel build(String channelName, String host, int port) {
    final NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress(host, port);
    channelBuilder.usePlaintext();
    logger.info("ChannelType:{}", channelType.getSimpleName());
    channelBuilder.channelType(channelType);
    channelBuilder.eventLoopGroup(eventLoopGroup);
    setupInternal(channelBuilder);
    channelBuilder.defaultLoadBalancingPolicy(GrpcUtil.DEFAULT_LB_POLICY);
    addHeader(channelBuilder);
    addClientInterceptor(channelBuilder);
    channelBuilder.executor(executorService);
    if (nameResolverProvider != null) {
        logger.info("Set nameResolverProvider {}. channelName={}, host={}, port={}", this.nameResolverProvider, channelName, host, port);
        setNameResolverFactory(channelBuilder, this.nameResolverProvider);
    }
    setupClientOption(channelBuilder);
    if (sslClientConfig.isEnable()) {
        SslContext sslContext = null;
        try {
            sslContext = SslContextFactory.create(sslClientConfig);
        } catch (SSLException e) {
            throw new SecurityException(e);
        }
        channelBuilder.sslContext(sslContext);
        channelBuilder.negotiationType(NegotiationType.TLS);
    }
    channelBuilder.maxTraceEvents(clientOption.getMaxTraceEvent());
    final ManagedChannel channel = channelBuilder.build();
    return channel;
}
Also used : InternalNettyChannelBuilder(io.grpc.netty.InternalNettyChannelBuilder) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) ManagedChannel(io.grpc.ManagedChannel) SSLException(javax.net.ssl.SSLException) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

ManagedChannel (io.grpc.ManagedChannel)164 Test (org.junit.Test)92 CountDownLatch (java.util.concurrent.CountDownLatch)26 ManagedChannel (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel)26 ArrayList (java.util.ArrayList)20 Metadata (io.grpc.Metadata)18 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)15 ExecutorService (java.util.concurrent.ExecutorService)13 ByteString (com.google.protobuf.ByteString)12 Status (io.grpc.Status)12 StreamObserver (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver)11 StreamObserver (io.grpc.stub.StreamObserver)10 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)10 CallOptions (io.grpc.CallOptions)9 Subchannel (io.grpc.LoadBalancer.Subchannel)9 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)9 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)9 Endpoints (org.apache.beam.model.pipeline.v1.Endpoints)9