use of alluxio.grpc.GrpcChannel in project alluxio by Alluxio.
the class NetworkAddressUtils method pingService.
/**
* Test if the input address is serving an Alluxio service. This method make use of the
* gRPC protocol for performing service communication.
* This methods throws UnauthenticatedException if the user is not authenticated,
* StatusRuntimeException If the host not reachable or does not serve the given service.
*
* @param address the network address to ping
* @param serviceType the Alluxio service type
* @param conf Alluxio configuration
* @param userState the UserState
*/
public static void pingService(InetSocketAddress address, alluxio.grpc.ServiceType serviceType, AlluxioConfiguration conf, UserState userState) throws AlluxioStatusException {
Preconditions.checkNotNull(address, "address");
Preconditions.checkNotNull(serviceType, "serviceType");
GrpcChannel channel = GrpcChannelBuilder.newBuilder(GrpcServerAddress.create(address), conf).setClientType("PingService").disableAuthentication().setSubject(userState.getSubject()).build();
try {
ServiceVersionClientServiceGrpc.ServiceVersionClientServiceBlockingStub versionClient = ServiceVersionClientServiceGrpc.newBlockingStub(channel).withDeadlineAfter(conf.getMs(PropertyKey.USER_MASTER_POLLING_TIMEOUT), TimeUnit.MILLISECONDS);
versionClient.getServiceVersion(GetServiceVersionPRequest.newBuilder().setServiceType(serviceType).build());
} catch (Throwable t) {
throw AlluxioStatusException.fromThrowable(t);
} finally {
channel.shutdown();
}
}
use of alluxio.grpc.GrpcChannel in project alluxio by Alluxio.
the class ConfigurationUtils method loadConfiguration.
/**
* Loads configuration from meta master in one RPC.
*
* @param address the meta master address
* @param conf the existing configuration
* @param ignoreClusterConf do not load cluster configuration related information
* @param ignorePathConf do not load path configuration related information
* @return the RPC response
*/
public static GetConfigurationPResponse loadConfiguration(InetSocketAddress address, AlluxioConfiguration conf, boolean ignoreClusterConf, boolean ignorePathConf) throws AlluxioStatusException {
GrpcChannel channel = null;
try {
LOG.debug("Alluxio client (version {}) is trying to load configuration from meta master {}", RuntimeConstants.VERSION, address);
channel = GrpcChannelBuilder.newBuilder(GrpcServerAddress.create(address), conf).setClientType("ConfigurationUtils").disableAuthentication().build();
MetaMasterConfigurationServiceGrpc.MetaMasterConfigurationServiceBlockingStub client = MetaMasterConfigurationServiceGrpc.newBlockingStub(channel);
GetConfigurationPResponse response = client.getConfiguration(GetConfigurationPOptions.newBuilder().setRawValue(true).setIgnoreClusterConf(ignoreClusterConf).setIgnorePathConf(ignorePathConf).build());
LOG.debug("Alluxio client has loaded configuration from meta master {}", address);
return response;
} catch (io.grpc.StatusRuntimeException e) {
throw new UnavailableException(String.format("Failed to handshake with master %s to load cluster default configuration values: %s", address, e.getMessage()), e);
} catch (UnauthenticatedException e) {
throw new RuntimeException(String.format("Received authentication exception during boot-strap connect with host:%s", address), e);
} finally {
if (channel != null) {
channel.shutdown();
}
}
}
use of alluxio.grpc.GrpcChannel in project alluxio by Alluxio.
the class RpcClientTest method testClientClose.
@Test
public void testClientClose() throws Exception {
GrpcChannel mockChannel = mock(GrpcChannel.class);
RpcClient<ManagerAgentServiceGrpc.ManagerAgentServiceBlockingStub> client = new RpcClient<>(mAddr, ManagerAgentServiceGrpc::newBlockingStub, (addr) -> mockChannel);
client.get();
client.close();
verify(mockChannel).shutdown();
}
use of alluxio.grpc.GrpcChannel in project alluxio by Alluxio.
the class RpcClientTest method testUnhealthyChannel.
@Test
public void testUnhealthyChannel() throws Exception {
GrpcChannel mockChannel = mock(GrpcChannel.class);
doReturn(false).when(mockChannel).isShutdown();
doReturn(false).when(mockChannel).isHealthy();
RpcClient<ManagerAgentServiceGrpc.ManagerAgentServiceBlockingStub> client = new RpcClient<>(mAddr, ManagerAgentServiceGrpc::newBlockingStub, (addr) -> mockChannel);
client.get();
client.get();
verify(mockChannel).shutdown();
}
use of alluxio.grpc.GrpcChannel in project alluxio by Alluxio.
the class ZookeeperFailureIntegrationTest method rpcServiceAvailable.
/*
* This method uses a client with an explicit master address to ensure that the master has shut
* down its rpc service.
*/
private boolean rpcServiceAvailable() throws Exception {
MasterNetAddress netAddress = mCluster.getMasterAddresses().get(0);
InetSocketAddress address = new InetSocketAddress(netAddress.getHostname(), netAddress.getRpcPort());
try {
GrpcChannel channel = GrpcChannelBuilder.newBuilder(GrpcServerAddress.create(address), ServerConfiguration.global()).build();
FileSystemMasterClientServiceGrpc.FileSystemMasterClientServiceBlockingStub client = FileSystemMasterClientServiceGrpc.newBlockingStub(channel);
client.listStatus(ListStatusPRequest.getDefaultInstance());
} catch (Exception e) {
return false;
}
return true;
}
Aggregations