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;
}
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();
}
}
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();
}
}
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;
}
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();
}
}
Aggregations