Search in sources :

Example 6 with GrpcChannel

use of alluxio.grpc.GrpcChannel in project alluxio by Alluxio.

the class GrpcMessagingClient method connect.

/**
 * Creates a client and connects to the given address.
 *
 * @param address the server address
 * @return future of connection result
 */
public CompletableFuture<GrpcMessagingConnection> connect(InetSocketAddress address) {
    LOG.debug("Creating a messaging client connection to: {}", address);
    final GrpcMessagingContext threadContext = GrpcMessagingContext.currentContextOrThrow();
    // Future for this connection.
    final CompletableFuture<GrpcMessagingConnection> connectionFuture = new CompletableFuture<>();
    // Spawn gRPC connection building on a common pool.
    final CompletableFuture<GrpcMessagingConnection> buildFuture = CompletableFuture.supplyAsync(() -> {
        try {
            // Create a new gRPC channel for requested connection.
            GrpcChannel channel = GrpcChannelBuilder.newBuilder(GrpcServerAddress.create(address.getHostString(), address), mConf).setClientType(mClientType).setSubject(mUserState.getSubject()).build();
            // Create stub for receiving stream from server.
            MessagingServiceGrpc.MessagingServiceStub messageClientStub = MessagingServiceGrpc.newStub(channel);
            // Create client connection that is bound to remote server stream.
            GrpcMessagingConnection clientConnection = new GrpcMessagingClientConnection(threadContext, mExecutor, channel, mConf.getMs(PropertyKey.MASTER_EMBEDDED_JOURNAL_TRANSPORT_REQUEST_TIMEOUT_MS));
            clientConnection.setTargetObserver(messageClientStub.connect(clientConnection));
            LOG.debug("Created a messaging client connection: {}", clientConnection);
            return clientConnection;
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }, mExecutor);
    // When connection is build, complete the connection future with it on a catalyst thread context
    // for setting up the connection.
    buildFuture.whenComplete((result, error) -> {
        threadContext.execute(() -> {
            if (error == null) {
                connectionFuture.complete(result);
            } else {
                connectionFuture.completeExceptionally(error);
            }
        });
    });
    return connectionFuture;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) MessagingServiceGrpc(alluxio.grpc.MessagingServiceGrpc) GrpcChannel(alluxio.grpc.GrpcChannel)

Example 7 with GrpcChannel

use of alluxio.grpc.GrpcChannel in project alluxio by Alluxio.

the class GrpcSecurityTest method testAuthenticationRevoked.

@Test
public void testAuthenticationRevoked() throws Exception {
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName());
    mConfiguration.set(PropertyKey.AUTHENTICATION_INACTIVE_CHANNEL_REAUTHENTICATE_PERIOD, "250ms");
    GrpcServer server = createServer(AuthType.SIMPLE);
    try {
        server.start();
        UserState us = UserState.Factory.create(mConfiguration);
        GrpcChannel channel = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration).setSubject(us.getSubject()).build();
        Assert.assertTrue(channel.isHealthy());
        /*
       * Sleeping will ensure that authentication sessions for the channel will expire on the
       * server. This should have propagated back to the client and its health status should reflect
       * that.
       *
       * Sleep more than authentication revocation timeout.
       */
        Thread.sleep(500);
        Assert.assertFalse(channel.isHealthy());
    } finally {
        server.shutdown();
    }
}
Also used : UserState(alluxio.security.user.UserState) GrpcServer(alluxio.grpc.GrpcServer) GrpcChannel(alluxio.grpc.GrpcChannel) Test(org.junit.Test)

Example 8 with GrpcChannel

use of alluxio.grpc.GrpcChannel in project alluxio by Alluxio.

the class GrpcSecurityTest method testAuthenticationClosed.

@Test
public void testAuthenticationClosed() throws Exception {
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName());
    GrpcServer server = createServer(AuthType.SIMPLE);
    try {
        server.start();
        UserState us = UserState.Factory.create(mConfiguration);
        GrpcChannel channel = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration).setSubject(us.getSubject()).build();
        // Grab internal channel-Id.
        GrpcConnection connection = Whitebox.getInternalState(channel, "mConnection");
        UUID channelId = connection.getChannelKey().getChannelId();
        // Assert that authentication server has a login info for the channel.
        Assert.assertNotNull(server.getAuthenticationServer().getUserInfoForChannel(channelId));
        // Shutdown channel.
        channel.shutdown();
        // Assert that authentication server doesn't contain login info for the channel anymore.
        // Wait in a loop. Because closing the authentication will propagate asynchronously.
        CommonUtils.waitFor("login state removed", () -> {
            try {
                server.getAuthenticationServer().getUserInfoForChannel(channelId);
                return false;
            } catch (UnauthenticatedException exc) {
                return true;
            }
        }, WaitForOptions.defaults().setTimeoutMs(S_AUTHENTICATION_PROPOGATE_TIMEOUT));
    } finally {
        server.shutdown();
    }
}
Also used : UserState(alluxio.security.user.UserState) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) GrpcConnection(alluxio.grpc.GrpcConnection) GrpcServer(alluxio.grpc.GrpcServer) UUID(java.util.UUID) GrpcChannel(alluxio.grpc.GrpcChannel) Test(org.junit.Test)

Example 9 with GrpcChannel

use of alluxio.grpc.GrpcChannel in project alluxio by Alluxio.

the class ManagerProcessContext method getHostedAsyncStub.

private HostedManagerServiceGrpc.HostedManagerServiceStub getHostedAsyncStub() {
    AlluxioConfiguration modifiedConfig = getConfWithHubTlsEnabled();
    LOG.debug("Connecting to hosted hub with TLS enabled={}", modifiedConfig.getBoolean(PropertyKey.NETWORK_TLS_ENABLED));
    if (mHostedAsyncSub == null) {
        InetSocketAddress addr = NetworkAddressUtils.getConnectAddress(NetworkAddressUtils.ServiceType.HUB_HOSTED_RPC, modifiedConfig);
        try {
            GrpcChannel channel = RpcClient.createChannel(addr, modifiedConfig);
            channel.intercept(new HubAuthenticationInterceptor(HubAuthentication.newBuilder().setApiKey(modifiedConfig.getString(PropertyKey.HUB_AUTHENTICATION_API_KEY)).setSecretKey(modifiedConfig.getString(PropertyKey.HUB_AUTHENTICATION_SECRET_KEY)).build()));
            mHostedAsyncSub = HostedManagerServiceGrpc.newStub(channel);
        } catch (AlluxioStatusException e) {
            LOG.error("Error connecting to hosted hub {}", e);
        }
    }
    return mHostedAsyncSub;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) HubAuthenticationInterceptor(alluxio.hub.manager.rpc.interceptor.HubAuthenticationInterceptor) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) GrpcChannel(alluxio.grpc.GrpcChannel)

Example 10 with GrpcChannel

use of alluxio.grpc.GrpcChannel in project alluxio by Alluxio.

the class PollingMasterInquireClient method pingMetaService.

private void pingMetaService(InetSocketAddress address) throws AlluxioStatusException {
    // disable authentication in the channel since version service does not require authentication
    GrpcChannel channel = GrpcChannelBuilder.newBuilder(GrpcServerAddress.create(address), mConfiguration).setSubject(mUserState.getSubject()).setClientType("MasterInquireClient").disableAuthentication().build();
    ServiceVersionClientServiceGrpc.ServiceVersionClientServiceBlockingStub versionClient = ServiceVersionClientServiceGrpc.newBlockingStub(channel).withDeadlineAfter(mConfiguration.getMs(PropertyKey.USER_MASTER_POLLING_TIMEOUT), TimeUnit.MILLISECONDS);
    List<InetSocketAddress> addresses = ConfigurationUtils.getJobMasterRpcAddresses(mConfiguration);
    ServiceType serviceType = addresses.contains(address) ? ServiceType.JOB_MASTER_CLIENT_SERVICE : ServiceType.META_MASTER_CLIENT_SERVICE;
    try {
        versionClient.getServiceVersion(GetServiceVersionPRequest.newBuilder().setServiceType(serviceType).build());
    } catch (StatusRuntimeException e) {
        throw AlluxioStatusException.fromThrowable(e);
    } finally {
        channel.shutdown();
    }
}
Also used : ServiceVersionClientServiceGrpc(alluxio.grpc.ServiceVersionClientServiceGrpc) InetSocketAddress(java.net.InetSocketAddress) ServiceType(alluxio.grpc.ServiceType) StatusRuntimeException(io.grpc.StatusRuntimeException) 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