Search in sources :

Example 1 with GrpcChannel

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();
    }
}
Also used : ServiceVersionClientServiceGrpc(alluxio.grpc.ServiceVersionClientServiceGrpc) GrpcChannel(alluxio.grpc.GrpcChannel)

Example 2 with GrpcChannel

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();
        }
    }
}
Also used : MetaMasterConfigurationServiceGrpc(alluxio.grpc.MetaMasterConfigurationServiceGrpc) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) UnavailableException(alluxio.exception.status.UnavailableException) GetConfigurationPResponse(alluxio.grpc.GetConfigurationPResponse) GrpcChannel(alluxio.grpc.GrpcChannel)

Example 3 with GrpcChannel

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();
}
Also used : ManagerAgentServiceGrpc(alluxio.hub.proto.ManagerAgentServiceGrpc) GrpcChannel(alluxio.grpc.GrpcChannel) Test(org.junit.Test) BaseHubTest(alluxio.hub.test.BaseHubTest)

Example 4 with GrpcChannel

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();
}
Also used : ManagerAgentServiceGrpc(alluxio.hub.proto.ManagerAgentServiceGrpc) GrpcChannel(alluxio.grpc.GrpcChannel) Test(org.junit.Test) BaseHubTest(alluxio.hub.test.BaseHubTest)

Example 5 with GrpcChannel

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;
}
Also used : FileSystemMasterClientServiceGrpc(alluxio.grpc.FileSystemMasterClientServiceGrpc) MasterNetAddress(alluxio.multi.process.MasterNetAddress) InetSocketAddress(java.net.InetSocketAddress) GrpcChannel(alluxio.grpc.GrpcChannel)

Aggregations

GrpcChannel (alluxio.grpc.GrpcChannel)10 Test (org.junit.Test)4 InetSocketAddress (java.net.InetSocketAddress)3 UnauthenticatedException (alluxio.exception.status.UnauthenticatedException)2 GrpcServer (alluxio.grpc.GrpcServer)2 ServiceVersionClientServiceGrpc (alluxio.grpc.ServiceVersionClientServiceGrpc)2 ManagerAgentServiceGrpc (alluxio.hub.proto.ManagerAgentServiceGrpc)2 BaseHubTest (alluxio.hub.test.BaseHubTest)2 UserState (alluxio.security.user.UserState)2 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)1 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)1 UnavailableException (alluxio.exception.status.UnavailableException)1 FileSystemMasterClientServiceGrpc (alluxio.grpc.FileSystemMasterClientServiceGrpc)1 GetConfigurationPResponse (alluxio.grpc.GetConfigurationPResponse)1 GrpcConnection (alluxio.grpc.GrpcConnection)1 MessagingServiceGrpc (alluxio.grpc.MessagingServiceGrpc)1 MetaMasterConfigurationServiceGrpc (alluxio.grpc.MetaMasterConfigurationServiceGrpc)1 ServiceType (alluxio.grpc.ServiceType)1 HubAuthenticationInterceptor (alluxio.hub.manager.rpc.interceptor.HubAuthenticationInterceptor)1 MasterNetAddress (alluxio.multi.process.MasterNetAddress)1