use of org.apache.drill.exec.rpc.Response in project drill by axbaretto.
the class ServerAuthenticationHandler method handleAuthFailure.
private static <S extends ServerConnection<S>, T extends EnumLite> void handleAuthFailure(final S connection, final ResponseSender sender, final Exception e, final T saslResponseType) throws RpcException {
final String remoteAddress = connection.getRemoteAddress().toString();
logger.debug("Authentication using mechanism {} with encryption context {} failed from client {} due to {}", connection.getSaslServer().getMechanismName(), connection.getEncryptionCtxtString(), remoteAddress, e);
// inform the client that authentication failed, and no more
sender.send(new Response(saslResponseType, SASL_FAILED_MESSAGE));
// drop connection
throw new RpcException(e);
}
use of org.apache.drill.exec.rpc.Response in project drill by axbaretto.
the class UserClient method handle.
@Override
protected void handle(UserToBitConnection connection, int rpcType, ByteBuf pBody, ByteBuf dBody, ResponseSender sender) throws RpcException {
if (!isAuthComplete()) {
// Remote should not be making any requests before authenticating, drop connection
throw new RpcException(String.format("Request of type %d is not allowed without authentication. " + "Remote on %s must authenticate before making requests. Connection dropped.", rpcType, connection.getRemoteAddress()));
}
switch(rpcType) {
case RpcType.QUERY_DATA_VALUE:
queryResultHandler.batchArrived(connection, pBody, dBody);
sender.send(new Response(RpcType.ACK, Acks.OK));
break;
case RpcType.QUERY_RESULT_VALUE:
queryResultHandler.resultArrived(pBody);
sender.send(new Response(RpcType.ACK, Acks.OK));
break;
default:
throw new RpcException(String.format("Unknown Rpc Type %d. ", rpcType));
}
}
use of org.apache.drill.exec.rpc.Response in project drill by apache.
the class UserClient method handle.
@Override
protected void handle(UserToBitConnection connection, int rpcType, ByteBuf pBody, ByteBuf dBody, ResponseSender sender) throws RpcException {
if (!isAuthComplete()) {
// Remote should not be making any requests before authenticating, drop connection
throw new RpcException(String.format("Request of type %d is not allowed without authentication. " + "Remote on %s must authenticate before making requests. Connection dropped.", rpcType, connection.getRemoteAddress()));
}
switch(rpcType) {
case RpcType.QUERY_DATA_VALUE:
queryResultHandler.batchArrived(connection, pBody, dBody);
sender.send(new Response(RpcType.ACK, Acks.OK));
break;
case RpcType.QUERY_RESULT_VALUE:
queryResultHandler.resultArrived(pBody);
sender.send(new Response(RpcType.ACK, Acks.OK));
break;
default:
throw new RpcException(String.format("Unknown Rpc Type %d. ", rpcType));
}
}
use of org.apache.drill.exec.rpc.Response in project drill by apache.
the class LocalControlConnectionManager method runCommand.
@Override
public void runCommand(RpcCommand cmd) {
final int rpcType = cmd.getRpcType().getNumber();
final ControlMessageHandler messageHandler = config.getMessageHandler();
if (RpcConstants.EXTRA_DEBUGGING) {
logger.debug("Received bit com message of type {} over local connection manager", rpcType);
}
switch(rpcType) {
case BitControl.RpcType.REQ_CANCEL_FRAGMENT_VALUE:
{
final ControlTunnel.SignalFragment signalFragment = ((ControlTunnel.SignalFragment) cmd);
final RpcOutcomeListener<Ack> outcomeListener = signalFragment.getOutcomeListener();
final Ack ackResponse = messageHandler.cancelFragment(signalFragment.getMessage());
outcomeListener.success(ackResponse, null);
break;
}
case BitControl.RpcType.REQ_CUSTOM_VALUE:
{
final ByteBuf[] dataBodies;
final RpcOutcomeListener<BitControl.CustomMessage> outcomeListener;
if (cmd instanceof ControlTunnel.CustomMessageSender) {
dataBodies = ((ControlTunnel.CustomMessageSender) cmd).getDataBodies();
outcomeListener = ((ControlTunnel.CustomMessageSender) cmd).getOutcomeListener();
} else if (cmd instanceof ControlTunnel.SyncCustomMessageSender) {
dataBodies = ((ControlTunnel.SyncCustomMessageSender) cmd).getDataBodies();
outcomeListener = ((ControlTunnel.SyncCustomMessageSender) cmd).getOutcomeListener();
} else {
throw new UnsupportedOperationException("Unknown Custom Type control message received");
}
DrillBuf reqDrillBuff;
try {
reqDrillBuff = convertToByteBuf(dataBodies);
} catch (Exception ex) {
outcomeListener.failed(new RpcException("Failed to allocate memory while sending request in " + "LocalControlConnectionManager#convertToByteBuff", ex));
return;
} finally {
releaseByteBuf(dataBodies);
}
try {
BitControl.CustomMessage message = (BitControl.CustomMessage) cmd.getMessage();
final Response response = messageHandler.getHandlerRegistry().handle(message, reqDrillBuff);
DrillBuf responseBuffer;
try {
responseBuffer = convertToByteBuf(response.dBodies);
} catch (Exception ex) {
outcomeListener.failed(new RpcException("Failed to allocate memory while sending response in " + "LocalControlConnectionManager#convertToByteBuff", ex));
return;
} finally {
releaseByteBuf(response.dBodies);
}
// Passed responseBuffer will be owned by consumer
outcomeListener.success((BitControl.CustomMessage) response.pBody, responseBuffer);
} catch (RpcException ex) {
cmd.getOutcomeListener().failed(ex);
} finally {
// Release the reqDrillBuff passed into handler
releaseByteBuf(reqDrillBuff);
}
break;
}
case BitControl.RpcType.REQ_RECEIVER_FINISHED_VALUE:
{
final ControlTunnel.ReceiverFinished receiverFinished = ((ControlTunnel.ReceiverFinished) cmd);
final RpcOutcomeListener<Ack> outcomeListener = receiverFinished.getOutcomeListener();
final Ack ackResponse = messageHandler.receivingFragmentFinished(receiverFinished.getMessage());
outcomeListener.success(ackResponse, null);
break;
}
case BitControl.RpcType.REQ_FRAGMENT_STATUS_VALUE:
{
final ControlTunnel.SendFragmentStatus fragmentStatus = ((ControlTunnel.SendFragmentStatus) cmd);
final RpcOutcomeListener<Ack> outcomeListener = fragmentStatus.getOutcomeListener();
final Ack ackResponse = messageHandler.requestFragmentStatus(fragmentStatus.getMessage());
outcomeListener.success(ackResponse, null);
break;
}
case BitControl.RpcType.REQ_QUERY_CANCEL_VALUE:
{
final ControlTunnel.CancelQuery cancelQuery = ((ControlTunnel.CancelQuery) cmd);
final RpcOutcomeListener<Ack> outcomeListener = cancelQuery.getOutcomeListener();
final Ack ackResponse = messageHandler.requestQueryCancel(cancelQuery.getMessage());
outcomeListener.success(ackResponse, null);
break;
}
case BitControl.RpcType.REQ_INITIALIZE_FRAGMENTS_VALUE:
{
final ControlTunnel.SendFragment sendFragment = ((ControlTunnel.SendFragment) cmd);
final RpcOutcomeListener<Ack> outcomeListener = sendFragment.getOutcomeListener();
try {
final Ack ackResponse = messageHandler.initializeFragment(sendFragment.getMessage());
outcomeListener.success(ackResponse, null);
} catch (RpcException ex) {
outcomeListener.failed(ex);
}
break;
}
case BitControl.RpcType.REQ_QUERY_STATUS_VALUE:
{
final ControlTunnel.RequestProfile requestProfile = ((ControlTunnel.RequestProfile) cmd);
final RpcOutcomeListener<UserBitShared.QueryProfile> outcomeListener = requestProfile.getOutcomeListener();
try {
final UserBitShared.QueryProfile profile = messageHandler.requestQueryStatus(requestProfile.getMessage());
outcomeListener.success(profile, null);
} catch (RpcException ex) {
outcomeListener.failed(ex);
}
break;
}
case BitControl.RpcType.REQ_UNPAUSE_FRAGMENT_VALUE:
{
final ControlTunnel.SignalFragment signalFragment = ((ControlTunnel.SignalFragment) cmd);
final RpcOutcomeListener<Ack> outcomeListener = signalFragment.getOutcomeListener();
final Ack ackResponse = messageHandler.resumeFragment(signalFragment.getMessage());
outcomeListener.success(ackResponse, null);
break;
}
default:
final RpcException rpcException = new RpcException(String.format("Unsupported control request type %s " + "received on LocalControlConnectionManager", rpcType));
cmd.getOutcomeListener().failed(rpcException);
}
}
use of org.apache.drill.exec.rpc.Response in project drill by apache.
the class UserServerRequestHandler method handle.
@Override
public void handle(BitToUserConnection connection, int rpcType, ByteBuf pBody, ByteBuf dBody, ResponseSender responseSender) throws RpcException {
switch(rpcType) {
case RpcType.RUN_QUERY_VALUE:
logger.debug("Received query to run. Returning query handle.");
try {
final RunQuery query = RunQuery.PARSER.parseFrom(new ByteBufInputStream(pBody));
final QueryId queryId = worker.submitWork(connection, query);
responseSender.send(new Response(RpcType.QUERY_HANDLE, queryId));
break;
} catch (InvalidProtocolBufferException e) {
throw new RpcException("Failure while decoding RunQuery body.", e);
}
case RpcType.CANCEL_QUERY_VALUE:
try {
final QueryId queryId = QueryId.PARSER.parseFrom(new ByteBufInputStream(pBody));
final Ack ack = worker.cancelQuery(queryId);
responseSender.send(new Response(RpcType.ACK, ack));
break;
} catch (InvalidProtocolBufferException e) {
throw new RpcException("Failure while decoding QueryId body.", e);
}
case RpcType.RESUME_PAUSED_QUERY_VALUE:
try {
final QueryId queryId = QueryId.PARSER.parseFrom(new ByteBufInputStream(pBody));
final Ack ack = worker.resumeQuery(queryId);
responseSender.send(new Response(RpcType.ACK, ack));
break;
} catch (final InvalidProtocolBufferException e) {
throw new RpcException("Failure while decoding QueryId body.", e);
}
case RpcType.GET_QUERY_PLAN_FRAGMENTS_VALUE:
try {
final GetQueryPlanFragments req = GetQueryPlanFragments.PARSER.parseFrom(new ByteBufInputStream(pBody));
responseSender.send(new Response(RpcType.QUERY_PLAN_FRAGMENTS, worker.getQueryPlan(connection, req)));
break;
} catch (final InvalidProtocolBufferException e) {
throw new RpcException("Failure while decoding GetQueryPlanFragments body.", e);
}
case RpcType.GET_CATALOGS_VALUE:
try {
final GetCatalogsReq req = GetCatalogsReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
worker.submitCatalogMetadataWork(connection.getSession(), req, responseSender);
break;
} catch (final InvalidProtocolBufferException e) {
throw new RpcException("Failure while decoding GetCatalogsReq body.", e);
}
case RpcType.GET_SCHEMAS_VALUE:
try {
final GetSchemasReq req = GetSchemasReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
worker.submitSchemasMetadataWork(connection.getSession(), req, responseSender);
break;
} catch (final InvalidProtocolBufferException e) {
throw new RpcException("Failure while decoding GetSchemasReq body.", e);
}
case RpcType.GET_TABLES_VALUE:
try {
final GetTablesReq req = GetTablesReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
worker.submitTablesMetadataWork(connection.getSession(), req, responseSender);
break;
} catch (final InvalidProtocolBufferException e) {
throw new RpcException("Failure while decoding GetTablesReq body.", e);
}
case RpcType.GET_COLUMNS_VALUE:
try {
final GetColumnsReq req = GetColumnsReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
worker.submitColumnsMetadataWork(connection.getSession(), req, responseSender);
break;
} catch (final InvalidProtocolBufferException e) {
throw new RpcException("Failure while decoding GetColumnsReq body.", e);
}
case RpcType.CREATE_PREPARED_STATEMENT_VALUE:
try {
final CreatePreparedStatementReq req = CreatePreparedStatementReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
worker.submitPreparedStatementWork(connection, req, responseSender);
break;
} catch (final InvalidProtocolBufferException e) {
throw new RpcException("Failure while decoding CreatePreparedStatementReq body.", e);
}
case RpcType.GET_SERVER_META_VALUE:
try {
final GetServerMetaReq req = GetServerMetaReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
worker.submitServerMetadataWork(connection.getSession(), req, responseSender);
break;
} catch (final InvalidProtocolBufferException e) {
throw new RpcException("Failure while decoding CreatePreparedStatementReq body.", e);
}
default:
throw new UnsupportedOperationException(String.format("UserServerRequestHandler received rpc of unknown type. Type was %d.", rpcType));
}
}
Aggregations