Search in sources :

Example 51 with RpcException

use of org.apache.drill.exec.rpc.RpcException in project drill by apache.

the class StatusHandler method success.

@Override
public void success(Ack value, ByteBuf buffer) {
    sendingAccountor.decrement();
    if (value.getOk()) {
        return;
    }
    logger.error("Data not accepted downstream. Stopping future sends.");
    // if we didn't get ack ok, we'll need to kill the query.
    consumer.accept(new RpcException("Data not accepted downstream."));
}
Also used : RpcException(org.apache.drill.exec.rpc.RpcException)

Example 52 with RpcException

use of org.apache.drill.exec.rpc.RpcException in project drill by apache.

the class QueryResultHandler method resultArrived.

/**
 * Maps internal low-level API protocol to {@link UserResultsListener}-level API protocol.
 * handles data result messages
 */
public void resultArrived(ByteBuf pBody) throws RpcException {
    QueryResult queryResult = RpcBus.get(pBody, QueryResult.PARSER);
    QueryId queryId = queryResult.getQueryId();
    QueryState queryState = queryResult.getQueryState();
    if (logger.isDebugEnabled()) {
        logger.debug("resultArrived: queryState: {}, queryId = {}", queryState, QueryIdHelper.getQueryId(queryId));
    }
    assert queryResult.hasQueryState() : "received query result without QueryState";
    boolean isFailureResult = QueryState.FAILED == queryState;
    // CANCELED queries are handled the same way as COMPLETED
    boolean isTerminalResult;
    switch(queryState) {
        case FAILED:
        case CANCELED:
        case COMPLETED:
            isTerminalResult = true;
            break;
        default:
            logger.error("Unexpected/unhandled QueryState " + queryState + " (for query " + queryId + ")");
            isTerminalResult = false;
            break;
    }
    assert isFailureResult || queryResult.getErrorCount() == 0 : "Error count for the query batch is non-zero but QueryState != FAILED";
    UserResultsListener resultsListener = newUserResultsListener(queryId);
    try {
        if (isFailureResult) {
            // Failure case--pass on via submissionFailed(...).
            resultsListener.submissionFailed(new UserRemoteException(queryResult.getError(0)));
        // Note: Listener is removed in finally below.
        } else if (isTerminalResult) {
            // A successful completion/canceled case--pass on via resultArrived
            try {
                resultsListener.queryCompleted(queryState);
            } catch (Exception e) {
                resultsListener.submissionFailed(UserException.systemError(e).build(logger));
            }
        } else {
            logger.warn("queryState {} was ignored", queryState);
        }
    } finally {
        if (isTerminalResult) {
            // for it?
            if ((!(resultsListener instanceof BufferingResultsListener) || ((BufferingResultsListener) resultsListener).output != null)) {
                queryIdToResultsListenersMap.remove(queryId, resultsListener);
            }
        }
    }
}
Also used : QueryResult(org.apache.drill.exec.proto.UserBitShared.QueryResult) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) QueryState(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState) UserException(org.apache.drill.common.exceptions.UserException) RpcException(org.apache.drill.exec.rpc.RpcException) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException)

Example 53 with RpcException

use of org.apache.drill.exec.rpc.RpcException in project drill by apache.

the class UserClient method prepareSaslHandshake.

@Override
protected void prepareSaslHandshake(final RpcConnectionHandler<UserToBitConnection> connectionHandler, List<String> serverAuthMechanisms) {
    try {
        final Map<String, String> saslProperties = properties.stringPropertiesAsMap();
        // Set correct QOP property and Strength based on server needs encryption or not.
        // If ChunkMode is enabled then negotiate for buffer size equal to wrapChunkSize,
        // If ChunkMode is disabled then negotiate for MAX_WRAPPED_SIZE buffer size.
        saslProperties.putAll(SaslProperties.getSaslProperties(connection.isEncryptionEnabled(), connection.getMaxWrappedSize()));
        final AuthenticatorFactory factory = getAuthenticatorFactory(properties, serverAuthMechanisms);
        final String mechanismName = factory.getSimpleName();
        logger.trace("Will try to authenticate to server using {} mechanism with encryption context {}", mechanismName, connection.getEncryptionCtxtString());
        // Update the thread context class loader to current class loader
        // See DRILL-6063 for detailed description
        final ClassLoader oldThreadCtxtCL = Thread.currentThread().getContextClassLoader();
        final ClassLoader newThreadCtxtCL = this.getClass().getClassLoader();
        Thread.currentThread().setContextClassLoader(newThreadCtxtCL);
        final UserGroupInformation ugi = factory.createAndLoginUser(saslProperties);
        // Reset the thread context class loader to original one
        Thread.currentThread().setContextClassLoader(oldThreadCtxtCL);
        startSaslHandshake(connectionHandler, saslProperties, ugi, factory, RpcType.SASL_MESSAGE);
    } catch (IOException e) {
        logger.error("Failed while doing setup for starting SASL handshake for connection {}", connection.getName());
        final Exception ex = new RpcException(String.format("Failed to initiate authentication for connection %s", connection.getName()), e);
        connectionHandler.connectionFailed(RpcConnectionHandler.FailureType.AUTHENTICATION, ex);
    }
}
Also used : RpcException(org.apache.drill.exec.rpc.RpcException) NonTransientRpcException(org.apache.drill.exec.rpc.NonTransientRpcException) IOException(java.io.IOException) AuthenticatorFactory(org.apache.drill.exec.rpc.security.AuthenticatorFactory) RpcException(org.apache.drill.exec.rpc.RpcException) TimeoutException(java.util.concurrent.TimeoutException) SaslException(javax.security.sasl.SaslException) NonTransientRpcException(org.apache.drill.exec.rpc.NonTransientRpcException) InvalidConnectionInfoException(org.apache.drill.exec.client.InvalidConnectionInfoException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) DrillException(org.apache.drill.common.exceptions.DrillException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 54 with RpcException

use of org.apache.drill.exec.rpc.RpcException in project drill by apache.

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);
}
Also used : Response(org.apache.drill.exec.rpc.Response) RpcException(org.apache.drill.exec.rpc.RpcException) ByteString(com.google.protobuf.ByteString)

Example 55 with RpcException

use of org.apache.drill.exec.rpc.RpcException in project drill by apache.

the class ServerAuthenticationHandler method handle.

@Override
public void handle(S connection, int rpcType, ByteBuf pBody, ByteBuf dBody, ResponseSender sender) throws RpcException {
    final String remoteAddress = connection.getRemoteAddress().toString();
    // exchange involves server "challenges" and client "responses" (initiated by client)
    if (saslRequestTypeValue == rpcType) {
        final SaslMessage saslResponse;
        try {
            saslResponse = SaslMessage.PARSER.parseFrom(new ByteBufInputStream(pBody));
        } catch (final InvalidProtocolBufferException e) {
            handleAuthFailure(connection, sender, e, saslResponseType);
            return;
        }
        logger.trace("Received SASL message {} from {}", saslResponse.getStatus(), remoteAddress);
        final SaslResponseProcessor processor = RESPONSE_PROCESSORS.get(saslResponse.getStatus());
        if (processor == null) {
            logger.info("Unknown message type from client from {}. Will stop authentication.", remoteAddress);
            handleAuthFailure(connection, sender, new SaslException("Received unexpected message"), saslResponseType);
            return;
        }
        final SaslResponseContext<S, T> context = new SaslResponseContext<>(saslResponse, connection, sender, requestHandler, saslResponseType);
        try {
            processor.process(context);
        } catch (final Exception e) {
            handleAuthFailure(connection, sender, e, saslResponseType);
        }
    } else {
        // drop connection
        throw new RpcException(String.format("Request of type %d is not allowed without authentication. Client on %s must authenticate " + "before making requests. Connection dropped. [Details: %s]", rpcType, remoteAddress, connection.getEncryptionCtxtString()));
    }
}
Also used : RpcException(org.apache.drill.exec.rpc.RpcException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SaslMessage(org.apache.drill.exec.proto.UserBitShared.SaslMessage) ByteString(com.google.protobuf.ByteString) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) SaslException(javax.security.sasl.SaslException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) RpcException(org.apache.drill.exec.rpc.RpcException) IOException(java.io.IOException) SaslException(javax.security.sasl.SaslException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Aggregations

RpcException (org.apache.drill.exec.rpc.RpcException)56 Test (org.junit.Test)22 ExecutionException (java.util.concurrent.ExecutionException)18 IOException (java.io.IOException)15 NonTransientRpcException (org.apache.drill.exec.rpc.NonTransientRpcException)12 Connection (java.sql.Connection)10 SQLException (java.sql.SQLException)10 JdbcTest (org.apache.drill.categories.JdbcTest)10 Response (org.apache.drill.exec.rpc.Response)9 Properties (java.util.Properties)8 SaslException (javax.security.sasl.SaslException)8 QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)8 UserException (org.apache.drill.common.exceptions.UserException)6 DrillBuf (io.netty.buffer.DrillBuf)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ByteString (com.google.protobuf.ByteString)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)4 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)4 DrillException (org.apache.drill.common.exceptions.DrillException)4 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)4