Search in sources :

Example 16 with VisibleForTesting

use of io.crate.common.annotations.VisibleForTesting in project crate by crate.

the class SqlHttpHandler method ensureSession.

@VisibleForTesting
Session ensureSession(FullHttpRequest request) {
    String defaultSchema = request.headers().get(REQUEST_HEADER_SCHEMA);
    User authenticatedUser = userFromAuthHeader(request.headers().get(HttpHeaderNames.AUTHORIZATION));
    Session session = this.session;
    if (session == null) {
        session = sqlOperations.createSession(defaultSchema, authenticatedUser);
    } else if (session.sessionContext().authenticatedUser().equals(authenticatedUser) == false) {
        session.close();
        session = sqlOperations.createSession(defaultSchema, authenticatedUser);
    }
    this.session = session;
    return session;
}
Also used : User(io.crate.user.User) Session(io.crate.action.sql.Session) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Example 17 with VisibleForTesting

use of io.crate.common.annotations.VisibleForTesting in project crate by crate.

the class TcpTransport method handleException.

@VisibleForTesting
static void handleException(Logger logger, TcpChannel channel, Exception e, Lifecycle lifecycle, OutboundHandler outboundHandler) {
    if (!lifecycle.started()) {
        // just close and ignore - we are already stopped and just need to make sure we release all resources
        CloseableChannel.closeChannel(channel, false);
        return;
    }
    if (isCloseConnectionException(e)) {
        logger.debug(() -> new ParameterizedMessage("close connection exception caught on transport layer [{}], disconnecting from relevant node", channel), e);
        // close the channel, which will cause a node to be disconnected if relevant
        CloseableChannel.closeChannel(channel, false);
    } else if (isConnectException(e)) {
        logger.debug(() -> new ParameterizedMessage("connect exception caught on transport layer [{}]", channel), e);
        // close the channel as safe measure, which will cause a node to be disconnected if relevant
        CloseableChannel.closeChannel(channel, false);
    } else if (e instanceof BindException) {
        logger.debug(() -> new ParameterizedMessage("bind exception caught on transport layer [{}]", channel), e);
        // close the channel as safe measure, which will cause a node to be disconnected if relevant
        CloseableChannel.closeChannel(channel, false);
    } else if (e instanceof CancelledKeyException) {
        logger.debug(() -> new ParameterizedMessage("cancelled key exception caught on transport layer [{}], disconnecting from relevant node", channel), e);
        // close the channel as safe measure, which will cause a node to be disconnected if relevant
        CloseableChannel.closeChannel(channel, false);
    } else if (e instanceof TcpTransport.HttpRequestOnTransportException) {
        // in case we are able to return data, serialize the exception content and sent it back to the client
        if (channel.isOpen()) {
            BytesArray message = new BytesArray(e.getMessage().getBytes(StandardCharsets.UTF_8));
            outboundHandler.sendBytes(channel, message, ActionListener.wrap(() -> CloseableChannel.closeChannel(channel)));
        }
    } else if (e instanceof StreamCorruptedException) {
        logger.warn(() -> new ParameterizedMessage("{}, [{}], closing connection", e.getMessage(), channel));
        CloseableChannel.closeChannel(channel, false);
    } else {
        logger.warn(() -> new ParameterizedMessage("exception caught on transport layer [{}], closing connection", channel), e);
        // close the channel, which will cause a node to be disconnected if relevant
        CloseableChannel.closeChannel(channel, false);
    }
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) CancelledKeyException(java.nio.channels.CancelledKeyException) BindException(java.net.BindException) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) StreamCorruptedException(java.io.StreamCorruptedException) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Example 18 with VisibleForTesting

use of io.crate.common.annotations.VisibleForTesting in project crate by crate.

the class TransportShardAction method validateMapping.

@VisibleForTesting
public static void validateMapping(Iterator<Mapper> mappers, boolean nested) {
    while (mappers.hasNext()) {
        Mapper mapper = mappers.next();
        if (nested) {
            ColumnIdent.validateObjectKey(mapper.simpleName());
        } else {
            ColumnIdent.validateColumnName(mapper.simpleName());
        }
        validateMapping(mapper.iterator(), true);
    }
}
Also used : Mapper(org.elasticsearch.index.mapper.Mapper) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Example 19 with VisibleForTesting

use of io.crate.common.annotations.VisibleForTesting in project crate by crate.

the class FileWriterCountCollector method toNestedStringObjectMap.

@VisibleForTesting
static Map<String, Object> toNestedStringObjectMap(Map<ColumnIdent, Object> columnIdentObjectMap) {
    Map<String, Object> nestedMap = new HashMap<>();
    Map<String, Object> parent = nestedMap;
    for (Map.Entry<ColumnIdent, Object> entry : columnIdentObjectMap.entrySet()) {
        ColumnIdent key = entry.getKey();
        Object value = entry.getValue();
        if (key.path().isEmpty()) {
            nestedMap.put(key.name(), value);
        } else {
            LinkedList<String> path = new LinkedList<>(key.path());
            path.add(0, key.name());
            while (true) {
                String currentKey = path.pop();
                if (path.isEmpty()) {
                    parent.put(currentKey, value);
                    break;
                }
                Object o = parent.get(currentKey);
                if (o == null) {
                    Map<String, Object> child = new HashMap<>();
                    parent.put(currentKey, child);
                    parent = child;
                } else {
                    assert o instanceof Map : "o must be instance of Map";
                    parent = (Map) o;
                }
            }
        }
    }
    return nestedMap;
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Example 20 with VisibleForTesting

use of io.crate.common.annotations.VisibleForTesting in project crate by crate.

the class Schemas method getNewCurrentSchemas.

@VisibleForTesting
static Set<String> getNewCurrentSchemas(Metadata metadata) {
    Set<String> schemas = new HashSet<>();
    // 'doc' schema is always available and has the special property that its indices
    // don't have to be prefixed with the schema name
    schemas.add(DOC_SCHEMA_NAME);
    for (String index : metadata.getConcreteAllIndices()) {
        addIfSchema(schemas, index);
    }
    for (ObjectCursor<String> cursor : metadata.templates().keys()) {
        addIfSchema(schemas, cursor.value);
    }
    UserDefinedFunctionsMetadata udfMetadata = metadata.custom(UserDefinedFunctionsMetadata.TYPE);
    if (udfMetadata != null) {
        udfMetadata.functionsMetadata().stream().map(UserDefinedFunctionMetadata::schema).forEach(schemas::add);
    }
    ViewsMetadata viewsMetadata = metadata.custom(ViewsMetadata.TYPE);
    if (viewsMetadata != null) {
        StreamSupport.stream(viewsMetadata.names().spliterator(), false).map(IndexParts::new).map(IndexParts::getSchema).forEach(schemas::add);
    }
    return schemas;
}
Also used : UserDefinedFunctionsMetadata(io.crate.expression.udf.UserDefinedFunctionsMetadata) ViewsMetadata(io.crate.metadata.view.ViewsMetadata) HashSet(java.util.HashSet) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (io.crate.common.annotations.VisibleForTesting)36 Row (io.crate.data.Row)12 Symbol (io.crate.expression.symbol.Symbol)12 SubQueryResults (io.crate.planner.operators.SubQueryResults)11 Settings (org.elasticsearch.common.settings.Settings)11 RowConsumer (io.crate.data.RowConsumer)10 NodeContext (io.crate.metadata.NodeContext)10 DependencyCarrier (io.crate.planner.DependencyCarrier)10 Plan (io.crate.planner.Plan)10 PlannerContext (io.crate.planner.PlannerContext)10 Function (java.util.function.Function)10 SymbolEvaluator (io.crate.analyze.SymbolEvaluator)9 Row1 (io.crate.data.Row1)9 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)9 ArrayList (java.util.ArrayList)8 OneRowActionListener (io.crate.execution.support.OneRowActionListener)7 Map (java.util.Map)7 ColumnIdent (io.crate.metadata.ColumnIdent)6 DocTableInfo (io.crate.metadata.doc.DocTableInfo)5 Nullable (javax.annotation.Nullable)5