Search in sources :

Example 1 with RequestExecutionException

use of org.apache.cassandra.exceptions.RequestExecutionException in project cassandra by apache.

the class QueryMessage method execute.

public Message.Response execute(QueryState state, long queryStartNanoTime) {
    try {
        if (options.getPageSize() == 0)
            throw new ProtocolException("The page size cannot be 0");
        UUID tracingId = null;
        if (isTracingRequested()) {
            tracingId = UUIDGen.getTimeUUID();
            state.prepareTracingSession(tracingId);
        }
        if (state.traceNextQuery()) {
            state.createTracingSession();
            ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
            builder.put("query", query);
            if (options.getPageSize() > 0)
                builder.put("page_size", Integer.toString(options.getPageSize()));
            if (options.getConsistency() != null)
                builder.put("consistency_level", options.getConsistency().name());
            if (options.getSerialConsistency() != null)
                builder.put("serial_consistency_level", options.getSerialConsistency().name());
            Tracing.instance.begin("Execute CQL3 query", state.getClientAddress(), builder.build());
        }
        Message.Response response = ClientState.getCQLQueryHandler().process(query, state, options, getCustomPayload(), queryStartNanoTime);
        if (options.skipMetadata() && response instanceof ResultMessage.Rows)
            ((ResultMessage.Rows) response).result.metadata.setSkipMetadata();
        if (tracingId != null)
            response.setTracingId(tracingId);
        return response;
    } catch (Exception e) {
        JVMStabilityInspector.inspectThrowable(e);
        if (!((e instanceof RequestValidationException) || (e instanceof RequestExecutionException)))
            logger.error("Unexpected error during query", e);
        return ErrorMessage.fromException(e);
    } finally {
        Tracing.instance.stopSession();
    }
}
Also used : ProtocolException(org.apache.cassandra.transport.ProtocolException) RequestExecutionException(org.apache.cassandra.exceptions.RequestExecutionException) Message(org.apache.cassandra.transport.Message) UUID(java.util.UUID) RequestValidationException(org.apache.cassandra.exceptions.RequestValidationException) ImmutableMap(com.google.common.collect.ImmutableMap) RequestExecutionException(org.apache.cassandra.exceptions.RequestExecutionException) RequestValidationException(org.apache.cassandra.exceptions.RequestValidationException) ProtocolException(org.apache.cassandra.transport.ProtocolException)

Example 2 with RequestExecutionException

use of org.apache.cassandra.exceptions.RequestExecutionException in project cassandra by apache.

the class PasswordAuthenticator method queryHashedPassword.

private String queryHashedPassword(String username) {
    try {
        SelectStatement authenticationStatement = authenticationStatement();
        ResultMessage.Rows rows = authenticationStatement.execute(QueryState.forInternalCalls(), QueryOptions.forInternalCalls(consistencyForRole(username), Lists.newArrayList(ByteBufferUtil.bytes(username))), System.nanoTime());
        // a specific, but unchecked, exception to keep LoadingCache happy.
        if (rows.result.isEmpty())
            throw new AuthenticationException(String.format("Provided username %s and/or password are incorrect", username));
        UntypedResultSet result = UntypedResultSet.create(rows.result);
        if (!result.one().has(SALTED_HASH))
            throw new AuthenticationException(String.format("Provided username %s and/or password are incorrect", username));
        return result.one().getString(SALTED_HASH);
    } catch (RequestExecutionException e) {
        throw new AuthenticationException(String.format("Error performing internal authentication of user %s : %s", username, e.getMessage()));
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) SelectStatement(org.apache.cassandra.cql3.statements.SelectStatement) RequestExecutionException(org.apache.cassandra.exceptions.RequestExecutionException) AuthenticationException(org.apache.cassandra.exceptions.AuthenticationException) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage)

Aggregations

RequestExecutionException (org.apache.cassandra.exceptions.RequestExecutionException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 UUID (java.util.UUID)1 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)1 SelectStatement (org.apache.cassandra.cql3.statements.SelectStatement)1 AuthenticationException (org.apache.cassandra.exceptions.AuthenticationException)1 RequestValidationException (org.apache.cassandra.exceptions.RequestValidationException)1 Message (org.apache.cassandra.transport.Message)1 ProtocolException (org.apache.cassandra.transport.ProtocolException)1 ResultMessage (org.apache.cassandra.transport.messages.ResultMessage)1