/** * Test if the input address is serving an Alluxio service. This method make use of the * gRPC protocol for performing service communication. * * @param address the network address to ping * @param serviceType the Alluxio service type * @param conf Alluxio configuration * @throws UnauthenticatedException If the user is not authenticated * @throws StatusRuntimeException If the host not reachable or does not serve the given service */ public static void pingService(InetSocketAddress address, alluxio.grpc.ServiceType serviceType, AlluxioConfiguration conf) throws UnauthenticatedException, UnavailableException { Preconditions.checkNotNull(address, "address"); Preconditions.checkNotNull(serviceType, "serviceType"); GrpcChannel channel = GrpcChannelBuilder.newBuilder(address, conf).build(); ServiceVersionClientServiceGrpc.ServiceVersionClientServiceBlockingStub versionClient = ServiceVersionClientServiceGrpc.newBlockingStub(channel); versionClient.getServiceVersion( GetServiceVersionPRequest.newBuilder().setServiceType(serviceType).build()); channel.shutdown(); } }
private void pingMetaService(InetSocketAddress address) throws UnauthenticatedException, UnavailableException { GrpcChannel channel = GrpcChannelBuilder.newBuilder(address, mConfiguration).build(); ServiceVersionClientServiceGrpc.ServiceVersionClientServiceBlockingStub versionClient = ServiceVersionClientServiceGrpc.newBlockingStub(channel); versionClient.getServiceVersion(GetServiceVersionPRequest.newBuilder() .setServiceType(ServiceType.META_MASTER_CLIENT_SERVICE).build()); channel.shutdown(); }
channel = GrpcChannelBuilder.newBuilder(address, conf).disableAuthentication().build(); MetaMasterConfigurationServiceGrpc.MetaMasterConfigurationServiceBlockingStub client = MetaMasterConfigurationServiceGrpc.newBlockingStub(channel);
.newBuilder(mAddress, mContext.getConf()) .setSubject(mContext.getSubject()) .build();
@Test public void testSimpleAuthentication() throws Exception { GrpcServer server = createServer(AuthType.SIMPLE); server.start(); GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration); channelBuilder.build(); server.shutdown(); }
@Test public void testNoSaslAuthentication() throws Exception { GrpcServer server = createServer(AuthType.NOSASL); server.start(); GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration); channelBuilder.build(); server.shutdown(); }
private GrpcChannel buildChannel(Subject subject, SocketAddress address, GrpcManagedChannelPool.PoolingStrategy poolingStrategy, AlluxioConfiguration alluxioConf) throws UnauthenticatedException, UnavailableException { return GrpcChannelBuilder.newBuilder(address, alluxioConf).setSubject(subject) .setChannelType(NettyUtils .getClientChannelClass(!(address instanceof InetSocketAddress), alluxioConf)) .setPoolingStrategy(poolingStrategy) .setEventLoopGroup(WORKER_GROUP) .setKeepAliveTimeout(alluxioConf.getMs(PropertyKey.USER_NETWORK_KEEPALIVE_TIMEOUT_MS), TimeUnit.MILLISECONDS) .setMaxInboundMessageSize( (int) alluxioConf.getBytes(PropertyKey.USER_NETWORK_MAX_INBOUND_MESSAGE_SIZE)) .setFlowControlWindow( (int) alluxioConf.getBytes(PropertyKey.USER_NETWORK_FLOWCONTROL_WINDOW)) .build(); } }
@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(); }
@Test public void testCustomAuthentication() throws Exception { mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.CUSTOM.getAuthName()); mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER_CLASS, ExactlyMatchAuthenticationProvider.class.getName()); GrpcServer server = createServer(AuthType.CUSTOM); server.start(); GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration); channelBuilder.setCredentials(ExactlyMatchAuthenticationProvider.USERNAME, ExactlyMatchAuthenticationProvider.PASSWORD, null).build(); server.shutdown(); }
@Test public void testCustomAuthenticationFails() throws Exception { mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.CUSTOM.getAuthName()); mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER_CLASS, ExactlyMatchAuthenticationProvider.class.getName()); GrpcServer server = createServer(AuthType.CUSTOM); server.start(); GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration); mThrown.expect(UnauthenticatedException.class); channelBuilder.setCredentials("fail", "fail", null).build(); server.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(); }