protected void stopServing() throws Exception { if (isServing()) { LOG.info("Stopping RPC server on {} @ {}", this, mRpcBindSocket.getInetAddress()); if (!mGrpcServer.shutdown()) { LOG.warn("RPC Server shutdown timed out."); } } if (mWebServer != null) { mWebServer.stop(); mWebServer = null; } }
@Override public void awaitTermination() { mServer.awaitTermination(); } }
/** * @return true if the system is the leader (serving the rpc server), false otherwise */ public boolean isServing() { return mGrpcServer != null && mGrpcServer.isServing(); }
@Test public void testNotEqualKeys() throws Exception { GrpcManagedChannelPool.ChannelKey key1 = GrpcManagedChannelPool.ChannelKey.create(); GrpcManagedChannelPool.ChannelKey key2 = GrpcManagedChannelPool.ChannelKey.create(); GrpcServer server1 = GrpcServerBuilder.forAddress(new InetSocketAddress("0.0.0.0", 0), sConf).build().start(); GrpcServer server2 = GrpcServerBuilder.forAddress(new InetSocketAddress("0.0.0.0", 0), sConf).build().start(); SocketAddress address1 = new InetSocketAddress("localhost", server1.getBindPort()); SocketAddress address2 = new InetSocketAddress("localhost", server2.getBindPort()); key1.setAddress(address1); key2.setAddress(address2); ManagedChannel channel1 = GrpcManagedChannelPool.INSTANCE().acquireManagedChannel(key1); ManagedChannel channel2 = GrpcManagedChannelPool.INSTANCE().acquireManagedChannel(key2); assertTrue(channel1 != channel2); GrpcManagedChannelPool.INSTANCE().releaseManagedChannel(key1); GrpcManagedChannelPool.INSTANCE().releaseManagedChannel(key2); server2.shutdown(); server2.shutdown(); }
private void startServingRPCServer() { try { if (mBindSocket != null) { // Socket opened for auto bind. // Close it. mBindSocket.close(); } LOG.info("Starting gRPC server on address {}", mRpcAddress); GrpcServerBuilder serverBuilder = GrpcServerBuilder.forAddress(mRpcAddress, ServerConfiguration.global()); for (Map.Entry<alluxio.grpc.ServiceType, GrpcService> serviceEntry : mJobWorker.getServices() .entrySet()) { LOG.info("Registered service:{}", serviceEntry.getKey().name()); serverBuilder.addService(serviceEntry.getValue()); } mGrpcServer = serverBuilder.build().start(); LOG.info("Started gRPC server on address {}", mRpcAddress); // Wait until the server is shut down. mGrpcServer.awaitTermination(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Creates a new instance of {@link GrpcDataServer}. * * @param address the server address * @param workerProcess the Alluxio worker process */ public GrpcDataServer(final SocketAddress address, final WorkerProcess workerProcess) { mSocketAddress = address; try { mServer = createServerBuilder(address, NettyUtils.getWorkerChannel( ServerConfiguration.global())) .addService(new GrpcService(new BlockWorkerImpl(workerProcess))) .flowControlWindow((int) mFlowControlWindow) .keepAliveTime(mKeepAliveTimeMs, TimeUnit.MILLISECONDS) .keepAliveTimeout(mKeepAliveTimeoutMs, TimeUnit.MILLISECONDS) .build() .start(); // There is no way to query domain socket address afterwards. // So store the bind address if it's domain socket address. if (address instanceof DomainSocketAddress) { mDomainSocketAddress = (DomainSocketAddress) address; } } catch (IOException e) { LOG.error("Server failed to start on {}", address.toString(), e); throw new RuntimeException(e); } LOG.info("Server started, listening on {}", address.toString()); }
@Override public SocketAddress getBindAddress() { if (mDomainSocketAddress != null) { return mDomainSocketAddress; } else { // Server is created with Inet address. int port = mServer.getBindPort(); if (port < 0) { return null; } return new InetSocketAddress(port); } }
/** * Build the server. * It attaches required services and interceptors for authentication. * * @return the built {@link GrpcServer} */ public GrpcServer build() { addService(new GrpcService(new ServiceVersionClientServiceHandler(mServices)) .disableAuthentication()); return new GrpcServer(mNettyServerBuilder.build(), mConfiguration.getMs(PropertyKey.MASTER_GRPC_SERVER_SHUTDOWN_TIMEOUT)); } }
@Test public void testEqualKeys() throws Exception { GrpcManagedChannelPool.ChannelKey key1 = GrpcManagedChannelPool.ChannelKey.create(); GrpcManagedChannelPool.ChannelKey key2 = GrpcManagedChannelPool.ChannelKey.create(); GrpcServer server1 = GrpcServerBuilder.forAddress(new InetSocketAddress("0.0.0.0", 0), sConf).build().start(); SocketAddress address = new InetSocketAddress("localhost", server1.getBindPort()); key1.setAddress(address); key2.setAddress(address); ManagedChannel channel1 = GrpcManagedChannelPool.INSTANCE().acquireManagedChannel(key1); ManagedChannel channel2 = GrpcManagedChannelPool.INSTANCE().acquireManagedChannel(key2); assertTrue(channel1 == channel2); GrpcManagedChannelPool.INSTANCE().releaseManagedChannel(key1); GrpcManagedChannelPool.INSTANCE().releaseManagedChannel(key2); server1.shutdown(); }
/** * Starts the gRPC server. The AlluxioMaster registers the Services of registered * {@link Master}s and meta services. */ protected void startServingRPCServer() { // TODO(ggezer) Executor threads not reused until thread capacity is hit. //ExecutorService executorService = Executors.newFixedThreadPool(mMaxWorkerThreads); try { SocketAddress bindAddress = getRpcAddressFromBindSocket(); LOG.info("Starting gRPC server on address {}", bindAddress); GrpcServerBuilder serverBuilder = GrpcServerBuilder.forAddress(bindAddress, ServerConfiguration.global()); registerServices(serverBuilder, mJobMaster.getServices()); mGrpcServer = serverBuilder.build().start(); LOG.info("Started gRPC server on address {}", bindAddress); // Wait until the server is shut down. mGrpcServer.awaitTermination(); } catch (IOException e) { throw new RuntimeException(e); } }
private InetSocketAddress getServerConnectAddress(GrpcServer server) { return new InetSocketAddress(NetworkAddressUtils .getLocalHostName((int) mConfiguration .getMs(PropertyKey.NETWORK_HOST_RESOLUTION_TIMEOUT_MS)), server.getBindPort()); }
@Test public void testEqualKeysNoPooling() throws Exception { GrpcManagedChannelPool.ChannelKey key1 = GrpcManagedChannelPool.ChannelKey.create() .setPoolingStrategy(GrpcManagedChannelPool.PoolingStrategy.DISABLED); GrpcManagedChannelPool.ChannelKey key2 = GrpcManagedChannelPool.ChannelKey.create() .setPoolingStrategy(GrpcManagedChannelPool.PoolingStrategy.DISABLED); GrpcServer server1 = GrpcServerBuilder.forAddress(new InetSocketAddress("0.0.0.0", 0), sConf).build().start(); SocketAddress address = new InetSocketAddress("localhost", server1.getBindPort()); key1.setAddress(address); key2.setAddress(address); ManagedChannel channel1 = GrpcManagedChannelPool.INSTANCE().acquireManagedChannel(key1); ManagedChannel channel2 = GrpcManagedChannelPool.INSTANCE().acquireManagedChannel(key2); assertTrue(channel1 != channel2); GrpcManagedChannelPool.INSTANCE().releaseManagedChannel(key1); GrpcManagedChannelPool.INSTANCE().releaseManagedChannel(key2); server1.shutdown(); } }
@Test public void testDisabledAuthentication() throws Exception { GrpcServer server = createServer(AuthType.SIMPLE); server.start(); GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration); channelBuilder.disableAuthentication().build(); server.shutdown(); }
/** * Starts the gRPC server. The AlluxioMaster registers the Services of registered * {@link Master}s and meta services. */ protected void startServingRPCServer() { // TODO(ggezer) Executor threads not reused until thread capacity is hit. // ExecutorService executorService = Executors.newFixedThreadPool(mMaxWorkerThreads); try { SocketAddress bindAddress = getRpcAddressFromBindSocket(); LOG.info("Starting gRPC server on address {}", bindAddress); GrpcServerBuilder serverBuilder = GrpcServerBuilder.forAddress(bindAddress, ServerConfiguration.global()); for (Master master : mRegistry.getServers()) { registerServices(serverBuilder, master.getServices()); } mGrpcServer = serverBuilder.build().start(); mSafeModeManager.notifyRpcServerStarted(); LOG.info("Started gRPC server on address {}", bindAddress); // Wait until the server is shut down. mGrpcServer.awaitTermination(); } catch (IOException e) { throw new RuntimeException(e); } }
private void stopServing() { if (isServing()) { if (!mGrpcServer.shutdown()) { LOG.warn("RPC server shutdown timed out."); } } try { mWebServer.stop(); } catch (Exception e) { LOG.error("Failed to stop web server", e); } }
@Override public boolean isClosed() { return !mServer.isServing(); }
@Test public void testEqualKeysComplex() throws Exception { GrpcManagedChannelPool.ChannelKey key1 = GrpcManagedChannelPool.ChannelKey.create(); GrpcManagedChannelPool.ChannelKey key2 = GrpcManagedChannelPool.ChannelKey.create(); GrpcServer server1 = GrpcServerBuilder.forAddress(new InetSocketAddress("0.0.0.0", 0), sConf).build().start(); SocketAddress address = new InetSocketAddress("localhost", server1.getBindPort()); key1.setAddress(address); key2.setAddress(address); key1.setFlowControlWindow(100); key2.setFlowControlWindow(100); key1.setMaxInboundMessageSize(100); key2.setMaxInboundMessageSize(100); key1.setKeepAliveTime(100, TimeUnit.MINUTES); key2.setKeepAliveTime(100, TimeUnit.MINUTES); key1.setKeepAliveTimeout(100, TimeUnit.MINUTES); key2.setKeepAliveTimeout(100, TimeUnit.MINUTES); ManagedChannel channel1 = GrpcManagedChannelPool.INSTANCE().acquireManagedChannel(key1); ManagedChannel channel2 = GrpcManagedChannelPool.INSTANCE().acquireManagedChannel(key2); assertTrue(channel1 == channel2); GrpcManagedChannelPool.INSTANCE().releaseManagedChannel(key1); GrpcManagedChannelPool.INSTANCE().releaseManagedChannel(key2); server1.shutdown(); }
@Test public void testAuthMismatch() throws Exception { GrpcServer server = createServer(AuthType.NOSASL); server.start(); mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE); GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration); mThrown.expect(UnauthenticatedException.class); channelBuilder.build(); server.shutdown(); }