io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder Java Examples

The following examples show how to use io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GrpcExecutionFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
private static NettyChannelBuilder createSecureChannel(
    String host, int port, Optional<Path> certPath, Optional<Path> keyPath, Optional<Path> caPath)
    throws SSLException {

  SslContextBuilder contextBuilder = GrpcSslContexts.forClient();
  if (certPath.isPresent() && keyPath.isPresent()) {
    contextBuilder.keyManager(certPath.get().toFile(), keyPath.get().toFile());
  }
  if (caPath.isPresent()) {
    contextBuilder.trustManager(caPath.get().toFile());
  }

  return channelBuilder(host, port)
      .sslContext(contextBuilder.build())
      .negotiationType(NegotiationType.TLS);
}
 
Example #2
Source File: ShadingTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void tcnative() throws Exception {
  server = NettyServerBuilder.forPort(0)
      .useTransportSecurity(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"))
      .addService(new SimpleServiceImpl())
      .build().start();
  channel = NettyChannelBuilder
      .forAddress("localhost", server.getPort())
      .sslContext(
          GrpcSslContexts.configure(SslContextBuilder.forClient(), SslProvider.OPENSSL)
              .trustManager(TestUtils.loadCert("ca.pem")).build())
      .overrideAuthority("foo.test.google.fr")
      .build();
  SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(channel);
  assertThat(SimpleResponse.getDefaultInstance())
      .isEqualTo(stub.unaryRpc(SimpleRequest.getDefaultInstance()));
}
 
Example #3
Source File: DefaultPubSubSubscriberFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
@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)
							.setReturnImmediately(false)
							.setSubscription(projectSubscriptionName)
							.build();
	SubscriberGrpc.SubscriberBlockingStub stub = SubscriberGrpc.newBlockingStub(channel)
						.withCallCredentials(MoreCallCredentials.from(credentials));
	return new BlockingGrpcPubSubSubscriber(projectSubscriptionName, channel, stub, pullRequest, retries, timeout);
}
 
Example #4
Source File: ShadingTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void tcnative() throws Exception {
  server = NettyServerBuilder.forPort(0)
      .useTransportSecurity(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"))
      .addService(new SimpleServiceImpl())
      .build().start();
  channel = NettyChannelBuilder
      .forAddress("localhost", server.getPort())
      .sslContext(
          GrpcSslContexts.configure(SslContextBuilder.forClient(), SslProvider.OPENSSL)
              .trustManager(TestUtils.loadCert("ca.pem")).build())
      .overrideAuthority("foo.test.google.fr")
      .build();
  SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(channel);
  assertThat(SimpleResponse.getDefaultInstance())
      .isEqualTo(stub.unaryRpc(SimpleRequest.getDefaultInstance()));
}
 
Example #5
Source File: GrpcConnectionPool.java    From FATE-Serving with Apache License 2.0 6 votes vote down vote up
public synchronized ManagedChannel createManagedChannel(String ip, int port) throws Exception {

        if (logger.isDebugEnabled()) {
            logger.debug("create ManagedChannel");
        }
        NettyChannelBuilder builder = NettyChannelBuilder
                .forAddress(ip, port)
                .keepAliveTime(60, TimeUnit.SECONDS)
                .keepAliveTimeout(60, TimeUnit.SECONDS)
                .keepAliveWithoutCalls(true)
                .idleTimeout(60, TimeUnit.SECONDS)
                .perRpcBufferLimit(128 << 20)
                .flowControlWindow(32 << 20)
                .maxInboundMessageSize(32 << 20)
                .enableRetry()
                .retryBufferSize(16 << 20)
                .maxRetryAttempts(20);      // todo: configurable
                builder.negotiationType(NegotiationType.PLAINTEXT)
                .usePlaintext();

        return builder.build();


    }
 
Example #6
Source File: DefaultPubSubSubscriberFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
@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)
							.setReturnImmediately(false)
							.setSubscription(projectSubscriptionName)
							.build();
	SubscriberGrpc.SubscriberBlockingStub stub = SubscriberGrpc.newBlockingStub(channel)
						.withCallCredentials(MoreCallCredentials.from(credentials));
	return new BlockingGrpcPubSubSubscriber(projectSubscriptionName, channel, stub, pullRequest, retries, timeout);
}
 
Example #7
Source File: GrpcToReactorServerBuilderTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private void createReactorGrpcServer(ReactorSampleServiceImpl reactorSampleService) throws Exception {
    this.reactorSampleService = reactorSampleService;

    DefaultGrpcToReactorServerFactory<SampleContext> factory = new DefaultGrpcToReactorServerFactory<>(SampleContext.class, SampleContextServerInterceptor::serverResolve);
    ServerServiceDefinition serviceDefinition = factory.apply(SampleServiceGrpc.getServiceDescriptor(), reactorSampleService, ReactorSampleServiceImpl.class);

    this.server = NettyServerBuilder.forPort(0)
            .addService(ServerInterceptors.intercept(serviceDefinition, new SampleContextServerInterceptor()))
            .build()
            .start();

    this.channel = NettyChannelBuilder.forTarget("localhost:" + server.getPort())
            .negotiationType(NegotiationType.PLAINTEXT)
            .build();

    this.client = ReactorToGrpcClientBuilder.newBuilder(SampleServiceReactorClient.class, SampleServiceGrpc.newStub(channel), SampleServiceGrpc.getServiceDescriptor(), SampleContext.class)
            .withTimeout(TIMEOUT_DURATION)
            .withStreamingTimeout(Duration.ofMillis(ReactorToGrpcClientBuilder.DEFAULT_STREAMING_TIMEOUT_MS))
            .withGrpcStubDecorator(SampleContextServerInterceptor::attachClientContext)
            .build();
}
 
Example #8
Source File: ReactorToGrpcClientBuilderTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.sampleService = new SampleServiceImpl();
    this.server = NettyServerBuilder.forPort(0)
            .addService(ServerInterceptors.intercept(sampleService, new SampleContextServerInterceptor()))
            .build()
            .start();
    this.channel = NettyChannelBuilder.forTarget("localhost:" + server.getPort())
            .negotiationType(NegotiationType.PLAINTEXT)
            .build();

    this.client = ReactorToGrpcClientBuilder.newBuilder(SampleServiceReactorClient.class, SampleServiceGrpc.newStub(channel), SampleServiceGrpc.getServiceDescriptor(), SampleContext.class)
            .withTimeout(TIMEOUT_DURATION)
            .withStreamingTimeout(Duration.ofMillis(ReactorToGrpcClientBuilder.DEFAULT_STREAMING_TIMEOUT_MS))
            .withGrpcStubDecorator(SampleContextServerInterceptor::attachClientContext)
            .build();
}
 
Example #9
Source File: LoadGeneratorMain.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Bean
@Named(API_ACCESS_CHANNEL)
public Channel getApiAccessChannel(@Named(GATEWAY_CHANNEL) Channel gatewayChannel,
                                   ApplicationArguments arguments) {
    List<String> federation = arguments.getOptionValues("federation");

    if (CollectionsExt.isNullOrEmpty(federation)) {
        return gatewayChannel;
    }

    return NettyChannelBuilder
            .forTarget(federation.get(0))
            .usePlaintext(true)
            .maxHeaderListSize(65536)
            .build();
}
 
Example #10
Source File: DefaultCellConnector.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Inject
public DefaultCellConnector(CellInfoResolver cellInfoResolver) {
    List<Cell> cells = cellInfoResolver.resolve();

    if (cells != null && !cells.isEmpty()) {
        channels = cells.stream()
                .collect(Collectors.toMap(
                        cell -> cell,
                        cell -> NettyChannelBuilder.forTarget(cell.getAddress())
                                .usePlaintext(true)
                                .loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance())
                                .build()
                ));
    } else {
        channels = Collections.emptyMap();
    }
}
 
Example #11
Source File: ConfigurationLeaderResolverComponent.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Bean(name = TITUS_MASTER_CHANNEL)
public Channel getManagedChannel(TitusMasterClientConfiguration configuration, LeaderResolver leaderResolver, TitusRuntime titusRuntime) {
    return NettyChannelBuilder
            .forTarget("leader://titusmaster")
            .nameResolverFactory(new LeaderNameResolverFactory(leaderResolver, configuration.getMasterGrpcPort(), titusRuntime))
            .usePlaintext(true)
            .maxHeaderListSize(65536)
            .build();
}
 
Example #12
Source File: PubSubSubscriberFactoryForEmulator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public PubSubSubscriber getSubscriber(Credentials credentials) throws IOException {
	ManagedChannel managedChannel = NettyChannelBuilder.forTarget(hostAndPort)
													.usePlaintext() // This is 'Ok' because this is ONLY used for testing.
													.build();

	PullRequest pullRequest = PullRequest.newBuilder()
										.setMaxMessages(maxMessagesPerPull)
										.setReturnImmediately(false)
										.setSubscription(projectSubscriptionName)
										.build();
	SubscriberGrpc.SubscriberBlockingStub stub = SubscriberGrpc.newBlockingStub(managedChannel);
	return new BlockingGrpcPubSubSubscriber(projectSubscriptionName, managedChannel, stub, pullRequest, retries, timeout);
}
 
Example #13
Source File: GrpcConfig.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
public static ManagedChannel getServerChannel()
{
    final NettyChannelBuilder channelBuilder =
        NettyChannelBuilder.forAddress(getServerHost(), getServerPort());
    if (getBoolean(TLS))
    {
        final Path certificatesDir = Configuration.certificatesDirectory();
        final SslContextBuilder sslClientContextBuilder = GrpcSslContexts.forClient()
            .trustManager(certificatesDir.resolve("ca.pem").toFile())
            .keyManager(
            certificatesDir.resolve("client.pem").toFile(), certificatesDir.resolve("client.key").toFile());

        try
        {
            channelBuilder.sslContext(sslClientContextBuilder.build());
        }
        catch (final SSLException ex)
        {
            LangUtil.rethrowUnchecked(ex);
        }
    }
    else
    {
        channelBuilder.usePlaintext();
    }
    return channelBuilder.build();
}
 
Example #14
Source File: ShadedNettyChannelFactory.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
@Override
protected NettyChannelBuilder newChannelBuilder(final String name) {
    final GrpcChannelProperties properties = getPropertiesFor(name);
    URI address = properties.getAddress();
    if (address == null) {
        address = URI.create(name);
    }
    return NettyChannelBuilder.forTarget(address.toString())
            .defaultLoadBalancingPolicy(properties.getDefaultLoadBalancingPolicy());
}
 
Example #15
Source File: TitusMasterConnectorModule.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@Named(MANAGED_CHANNEL_NAME)
Channel managedChannel(TitusMasterClientConfiguration configuration, LeaderResolver leaderResolver, TitusRuntime titusRuntime) {
    return NettyChannelBuilder
            .forTarget("leader://titusmaster")
            .nameResolverFactory(new LeaderNameResolverFactory(leaderResolver, configuration.getMasterGrpcPort(), titusRuntime))
            .usePlaintext(true)
            .maxHeaderListSize(65536)
            .build();
}
 
Example #16
Source File: CommandContext.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public synchronized ManagedChannel createChannel() {
    ManagedChannelBuilder channelBuilder = ManagedChannelBuilder.forAddress(host, port)
            .usePlaintext(true);
    if (channelBuilder instanceof NettyChannelBuilder) {
        NettyChannelBuilder nettyChannelBuilder = (NettyChannelBuilder) channelBuilder;
        nettyChannelBuilder.maxHeaderListSize(128 * 1024);
    }
    ManagedChannel channel = channelBuilder.build();

    channels.add(channel);
    return channel;
}
 
Example #17
Source File: LoadGeneratorMain.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Bean
@Named(SimulatedRemoteInstanceCloudConnector.SIMULATED_CLOUD)
public Channel getSimulatedCloudChannel(ApplicationArguments arguments) {
    List<String> cloud = arguments.getOptionValues("cloud");

    String cloudAddress = CollectionsExt.isNullOrEmpty(cloud) ? "localhost:8093" : cloud.get(0);

    return NettyChannelBuilder
            .forTarget(cloudAddress)
            .usePlaintext(true)
            .maxHeaderListSize(65536)
            .build();
}
 
Example #18
Source File: LoadGeneratorMain.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Bean
@Named(GATEWAY_CHANNEL)
public Channel getGatewayChannel(ApplicationArguments arguments) {
    List<String> gateway = arguments.getOptionValues("gateway");

    String gatewayAddress = CollectionsExt.isNullOrEmpty(gateway) ? "localhost:8091" : gateway.get(0);

    return NettyChannelBuilder
            .forTarget(gatewayAddress)
            .usePlaintext(true)
            .maxHeaderListSize(65536)
            .build();
}
 
Example #19
Source File: EmbeddedTitusGateway.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private ManagedChannel getOrCreateGrpcChannel() {
    if (grpcChannel == null) {
        this.grpcChannel = NettyChannelBuilder.forAddress("localhost", getGrpcPort())
                .usePlaintext(true)
                .maxHeaderListSize(65536)
                .build();
    }
    return grpcChannel;
}
 
Example #20
Source File: TasksPublisherConfiguration.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private ManagedChannel getTitusGrpcChannel() {
    return NettyChannelBuilder.forAddress(titusApiHost, titusApiPort)
            .loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance())
            .keepAliveTime(GRPC_KEEP_ALIVE_TIME, TimeUnit.SECONDS)
            .keepAliveTimeout(GRPC_KEEP_ALIVE_TIMEOUT, TimeUnit.SECONDS)
            .userAgent(GRPC_CLIENT_AGENT)
            .usePlaintext(true)
            .build();
}
 
Example #21
Source File: ShadedNettyChannelFactory.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
@Override
protected NettyChannelBuilder newChannelBuilder(final String name) {
    final GrpcChannelProperties properties = getPropertiesFor(name);
    URI address = properties.getAddress();
    if (address == null) {
        address = URI.create(name);
    }
    return NettyChannelBuilder.forTarget(address.toString())
            .defaultLoadBalancingPolicy(properties.getDefaultLoadBalancingPolicy());
}
 
Example #22
Source File: TripleClientTransport.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * Create new connection
 *
 * @param url
 */
private ManagedChannel initChannel(ProviderInfo url) {
    ClientInterceptor clientHeaderClientInterceptor = buildClientHeaderClientInterceptor();
    NettyChannelBuilder builder = NettyChannelBuilder.forAddress(url.getHost(), url.getPort());
    builder.usePlaintext();
    builder.disableRetry();
    builder.intercept(clientHeaderClientInterceptor);
    return builder.build();
}
 
Example #23
Source File: PubSubSubscriberFactoryForEmulator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public PubSubSubscriber getSubscriber(Credentials credentials) throws IOException {
	ManagedChannel managedChannel = NettyChannelBuilder.forTarget(hostAndPort)
													.usePlaintext() // This is 'Ok' because this is ONLY used for testing.
													.build();

	PullRequest pullRequest = PullRequest.newBuilder()
										.setMaxMessages(maxMessagesPerPull)
										.setReturnImmediately(false)
										.setSubscription(projectSubscriptionName)
										.build();
	SubscriberGrpc.SubscriberBlockingStub stub = SubscriberGrpc.newBlockingStub(managedChannel);
	return new BlockingGrpcPubSubSubscriber(projectSubscriptionName, managedChannel, stub, pullRequest, retries, timeout);
}
 
Example #24
Source File: MetaStep.java    From metastore with Apache License 2.0 4 votes vote down vote up
public MetaStep(String... args) throws IOException, ArgumentParserException {
  ArgumentParser parser = ArgumentParsers.newFor("metastep").build();

  Subparsers subparsers = parser.addSubparsers().help("sub-command help");

  Subparser submitParser = subparsers.addParser("publish").help("publish help");
  submitParser.setDefault("sub-command", "publish");
  submitParser.addArgument("--package_prefix").required(false);
  submitParser.addArgument("--package_name").required(false);
  submitParser.addArgument("--file_name").required(false);
  submitParser.addArgument("--descriptor_set").required(false);
  submitParser.addArgument("--profile").required(false);
  submitParser.addArgument("--workspace").required(false);
  submitParser.addArgument("--server").required(true);
  submitParser.addArgument("--registry").required(false);
  submitParser.addArgument("--tls").required(false);
  submitParser.addArgument("--tls_env").required(false);
  submitParser.addArgument("--source").required(false);
  submitParser.addArgument("--comment").required(true);
  submitParser.addArgument("--user").required(false);
  submitParser.addArgument("--email").required(false);
  submitParser.addArgument("--include").nargs("*").required(false);

  Subparser validateParser = subparsers.addParser("validate").help("validate help");
  validateParser.setDefault("sub-command", "validate");
  validateParser.addArgument("--package_prefix").required(false);
  validateParser.addArgument("--package_name").required(false);
  validateParser.addArgument("--file_name").required(false);
  validateParser.addArgument("--descriptor_set").required(false);
  validateParser.addArgument("--profile").required(false);
  validateParser.addArgument("--workspace").required(false);
  validateParser.addArgument("--server").required(true);
  validateParser.addArgument("--registry").required(false);
  validateParser.addArgument("--tls").required(false);
  validateParser.addArgument("--tls_env").required(false);
  validateParser.addArgument("--source").required(false);
  validateParser.addArgument("--include").nargs("*").required(false);
  res = parser.parseArgs(args);

  descriptorFile = File.createTempFile("descriptor", ".pb");

  String server = res.getString("server");
  String[] sp = server.split(":");
  String host = sp[0];
  int port = Integer.parseInt(sp[1]);

  String protoWorkspace = res.getString("workspace");
  if (protoWorkspace == null) {
    protoWorkspace = "/var/workspace";
  }
  workspace = new File(protoWorkspace);
  System.out.println("Workspace set to: " + workspace);

  protoIncludes = res.getList("include");
  if (protoIncludes == null) {
    protoIncludes = new ArrayList<>();
  }
  protoIncludes.add("/usr/include");

  if (res.get("source") != null) {
    includeSource = true;
  }

  String tlsFileName = res.getString("tls");
  if (tlsFileName == null) {
    String tlsEnv = res.getString("tls_env");
    if (tlsEnv != null) {
      File tlsFile = File.createTempFile("tls", ".pem");
      tlsFileName = tlsFile.getAbsolutePath();
      String tlsBase64 = System.getenv(tlsEnv);
      if (tlsBase64 == null) {
        throw new RuntimeException("No ENVIRONMENT_VARIABLE of name " + tlsEnv + " found.");
      }
      try (FileOutputStream writer = new FileOutputStream(tlsFile)) {
        writer.write(Base64.getDecoder().decode(tlsBase64));
      }
    }
  }

  NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress(host, port);
  if (tlsFileName != null) {
    SslContext sslContext =
        GrpcSslContexts.forClient().trustManager(new File(tlsFileName)).build();

    channelBuilder.sslContext(sslContext).useTransportSecurity().build();
  } else {
    channelBuilder.usePlaintext();
  }
  schemaRegistry = RegistryGrpc.newBlockingStub(channelBuilder.build());
}
 
Example #25
Source File: ClientGrpcConfig.java    From flair-engine with Apache License 2.0 4 votes vote down vote up
private ManagedChannelFactory createManagedChannelFactory(String serviceName,
                                                          boolean tlsEnabled,
                                                          String trustCertCollectionFile,
                                                          String clientCertChainFile,
                                                          String clientPrivateKeyFile) {
    Supplier<ManagedChannel> dynamicManagedChannel = () -> {

        NettyChannelBuilder nettyChannelBuilder;

        if (flairCachingConfig.getUrl() == null) {
            InstanceInfo instanceInfo = client.getNextServerFromEureka(serviceName, false);

            nettyChannelBuilder = NettyChannelBuilder.forAddress(
                    tlsEnabled ? instanceInfo.getHostName() : instanceInfo.getIPAddr(),
                    instanceInfo.getPort());

            log.info("GRPC config: Hostname {} IP {} port {} secure port {} secure vip {}",
                    instanceInfo.getHostName(), instanceInfo.getIPAddr(), instanceInfo.getPort(), instanceInfo.getSecurePort(),
                    instanceInfo.getSecureVipAddress());
        } else {
            nettyChannelBuilder = NettyChannelBuilder.forTarget(flairCachingConfig.getUrl());

            log.info("GRPC config: Hostname url {}", flairCachingConfig.getUrl());
        }

        if (tlsEnabled) {

            nettyChannelBuilder.negotiationType(NegotiationType.TLS);

            log.info("GRPC config: GRPC TLS enabled");

            try {
                nettyChannelBuilder.sslContext(buildSslContext(
                        trustCertCollectionFile,
                        clientCertChainFile,
                        clientPrivateKeyFile
                ));
            } catch (SSLException e) {
                log.error("GRPC config: error", e);
            }
        } else {
            nettyChannelBuilder.usePlaintext();
        }
        return nettyChannelBuilder.build();
    };
    return new ManagedChannelFactory(dynamicManagedChannel);
}
 
Example #26
Source File: ShadingTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void serviceLoaderFindsNetty() throws Exception {
  assertThat(ServerBuilder.forPort(0)).isInstanceOf(NettyServerBuilder.class);
  assertThat(ManagedChannelBuilder.forAddress("localhost", 1234))
      .isInstanceOf(NettyChannelBuilder.class);
}
 
Example #27
Source File: GrpcExecutionFactory.java    From buck with Apache License 2.0 4 votes vote down vote up
/** The remote strategy connects to a remote grpc remote execution service. */
public static RemoteExecutionClients createRemote(
    String executionEngineHost,
    int executionEnginePort,
    String casHost,
    int casPort,
    int casDeadline,
    boolean insecure,
    boolean casInsecure,
    Optional<Path> certPath,
    Optional<Path> keyPath,
    Optional<Path> caPath,
    RemoteExecutionStrategyConfig strategyConfig,
    MetadataProvider metadataProvider,
    BuckEventBus buckEventBus)
    throws SSLException {

  ManagedChannel executionEngineChannel;
  if (insecure) {
    executionEngineChannel =
        createInsecureChannel(executionEngineHost, executionEnginePort).build();
  } else {
    executionEngineChannel =
        createSecureChannel(executionEngineHost, executionEnginePort, certPath, keyPath, caPath)
            .build();
  }

  NettyChannelBuilder casChannelBuilder;
  if (casInsecure) {
    casChannelBuilder = createInsecureChannel(casHost, casPort);
  } else {
    casChannelBuilder = createSecureChannel(casHost, casPort, certPath, keyPath, caPath);
  }
  casChannelBuilder.flowControlWindow(100 * 1024 * 1024);

  return new GrpcRemoteExecutionClients(
      "buck",
      executionEngineChannel,
      casChannelBuilder.build(),
      casDeadline,
      metadataProvider,
      buckEventBus,
      strategyConfig);
}
 
Example #28
Source File: GrpcExecutionFactory.java    From buck with Apache License 2.0 4 votes vote down vote up
private static NettyChannelBuilder channelBuilder(String host, int port) {
  return NettyChannelBuilder.forAddress(host, port)
      .maxInboundMessageSize(MAX_INBOUND_MESSAGE_SIZE)
      .intercept(getRetryInterceptor());
}
 
Example #29
Source File: GrpcExecutionFactory.java    From buck with Apache License 2.0 4 votes vote down vote up
private static NettyChannelBuilder createInsecureChannel(String host, int port) {
  return channelBuilder(host, port).usePlaintext(true);
}
 
Example #30
Source File: ShadingTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Test
public void serviceLoaderFindsNetty() throws Exception {
  assertThat(ServerBuilder.forPort(0)).isInstanceOf(NettyServerBuilder.class);
  assertThat(ManagedChannelBuilder.forAddress("localhost", 1234))
      .isInstanceOf(NettyChannelBuilder.class);
}