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