Search in sources :

Example 1 with ServerError

use of org.apache.cassandra.stargate.transport.ServerError in project stargate by stargate.

the class ProxyProtocolQueryInterceptor method resolveAllPeers.

@SuppressWarnings("NonAtomicOperationOnVolatileField")
private void resolveAllPeers() {
    if (!Strings.isNullOrEmpty(proxyDnsName)) {
        try {
            // This task runs asynchronously, so it does not have context about a particular client. We
            // can't predict if connections will be public or private, so resolve everything.
            // Note that this also generates events, so private clients will get events for public
            // addresses, and vice versa. This is not a problem because client drivers ignore events if
            // they don't recognize the address.
            publicPeers = resolvePeers(proxyDnsName, publicPeers);
            privatePeers = resolvePeers(internalProxyDnsName, privatePeers);
        } catch (UnknownHostException e) {
            throw new ServerError("Unable to resolve DNS for proxy protocol peers table", e);
        }
        scheduler.schedule(this::resolveAllPeers, resolveDelaySecs, TimeUnit.SECONDS);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ServerError(org.apache.cassandra.stargate.transport.ServerError)

Example 2 with ServerError

use of org.apache.cassandra.stargate.transport.ServerError in project stargate by stargate.

the class ErrorMessage method fromException.

/**
 * @param e the exception
 * @param unexpectedExceptionHandler a callback for handling unexpected exceptions. If null, or if
 *     this returns false, the error is logged at ERROR level via sl4fj
 */
public static ErrorMessage fromException(Throwable e, Predicate<Throwable> unexpectedExceptionHandler) {
    int streamId = 0;
    // or some other internal exception, extract that and use it.
    if (e instanceof CodecException) {
        Throwable cause = e.getCause();
        if (cause != null) {
            if (cause instanceof WrappedException) {
                streamId = ((WrappedException) cause).streamId;
                e = cause.getCause();
            } else if (cause instanceof PersistenceException) {
                e = cause;
            }
        }
    } else if (e instanceof WrappedException) {
        streamId = ((WrappedException) e).streamId;
        e = e.getCause();
    }
    if (e instanceof PersistenceException) {
        ErrorMessage message = new ErrorMessage((PersistenceException) e, streamId);
        if (e instanceof ProtocolException) {
            // if the driver attempted to connect with a protocol version not supported then
            // respond with the appropiate version, see ProtocolVersion.decode()
            ProtocolVersion forcedProtocolVersion = ((ProtocolException) e).getForcedProtocolVersion();
            if (forcedProtocolVersion != null)
                message.forcedProtocolVersion = forcedProtocolVersion;
        }
        return message;
    }
    // Unexpected exception
    if (unexpectedExceptionHandler == null || !unexpectedExceptionHandler.apply(e))
        logger.error("Unexpected exception during request", e);
    return new ErrorMessage(new ServerError(e), streamId);
}
Also used : ProtocolException(org.apache.cassandra.stargate.transport.ProtocolException) ServerError(org.apache.cassandra.stargate.transport.ServerError) PersistenceException(org.apache.cassandra.stargate.exceptions.PersistenceException) CodecException(io.netty.handler.codec.CodecException) ProtocolVersion(org.apache.cassandra.stargate.transport.ProtocolVersion)

Aggregations

ServerError (org.apache.cassandra.stargate.transport.ServerError)2 CodecException (io.netty.handler.codec.CodecException)1 UnknownHostException (java.net.UnknownHostException)1 PersistenceException (org.apache.cassandra.stargate.exceptions.PersistenceException)1 ProtocolException (org.apache.cassandra.stargate.transport.ProtocolException)1 ProtocolVersion (org.apache.cassandra.stargate.transport.ProtocolVersion)1