Search in sources :

Example 1 with Error

use of com.yahoo.messagebus.Error in project vespa by vespa-engine.

the class RPCNetwork method allocServiceAddress.

@Override
public boolean allocServiceAddress(RoutingNode recipient) {
    Hop hop = recipient.getRoute().getHop(0);
    String service = hop.getServiceName();
    Error error = resolveServiceAddress(recipient, service);
    if (error == null) {
        // service address resolved
        return true;
    }
    recipient.setError(error);
    // service address not resolved
    return false;
}
Also used : Hop(com.yahoo.messagebus.routing.Hop) Error(com.yahoo.messagebus.Error)

Example 2 with Error

use of com.yahoo.messagebus.Error in project vespa by vespa-engine.

the class RPCNetwork method replyError.

/**
 * Deliver an error reply to the recipients of a {@link SendContext} in a way that avoids entanglement.
 *
 * @param ctx     The send context that contains the recipient data.
 * @param errCode The error code to return.
 * @param errMsg  The error string to return.
 */
private void replyError(SendContext ctx, int errCode, String errMsg) {
    for (RoutingNode recipient : ctx.recipients) {
        Reply reply = new EmptyReply();
        reply.getTrace().setLevel(ctx.traceLevel);
        reply.addError(new Error(errCode, errMsg));
        owner.deliverReply(reply, recipient);
    }
}
Also used : RoutingNode(com.yahoo.messagebus.routing.RoutingNode) EmptyReply(com.yahoo.messagebus.EmptyReply) Reply(com.yahoo.messagebus.Reply) Error(com.yahoo.messagebus.Error) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 3 with Error

use of com.yahoo.messagebus.Error in project vespa by vespa-engine.

the class RPCSend method doRequestDone.

private void doRequestDone(Request req) {
    SendContext ctx = (SendContext) req.getContext();
    String serviceName = ((RPCServiceAddress) ctx.recipient.getServiceAddress()).getServiceName();
    Reply reply = null;
    Error error = null;
    if (!req.checkReturnTypes(getReturnSpec())) {
        // Map all known JRT errors to the appropriate message bus error.
        reply = new EmptyReply();
        switch(req.errorCode()) {
            case com.yahoo.jrt.ErrorCode.TIMEOUT:
                error = new Error(ErrorCode.TIMEOUT, "A timeout occured while waiting for '" + serviceName + "' (" + ctx.timeout + " seconds expired); " + req.errorMessage());
                break;
            case com.yahoo.jrt.ErrorCode.CONNECTION:
                error = new Error(ErrorCode.CONNECTION_ERROR, "A connection error occured for '" + serviceName + "'; " + req.errorMessage());
                break;
            default:
                error = new Error(ErrorCode.NETWORK_ERROR, "A network error occured for '" + serviceName + "'; " + req.errorMessage());
        }
    } else {
        reply = createReply(req.returnValues(), serviceName, ctx.trace);
    }
    if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) {
        ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Reply (type " + reply.getType() + ") received at " + clientIdent + ".");
    }
    reply.getTrace().swap(ctx.trace);
    if (error != null) {
        reply.addError(error);
    }
    net.getOwner().deliverReply(reply, ctx.recipient);
}
Also used : Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 4 with Error

use of com.yahoo.messagebus.Error in project vespa by vespa-engine.

the class RPCSendV1 method createReply.

@Override
protected Reply createReply(Values ret, String serviceName, Trace trace) {
    Version version = new Version(ret.get(0).asUtf8Array());
    double retryDelay = ret.get(1).asDouble();
    int[] errorCodes = ret.get(2).asInt32Array();
    String[] errorMessages = ret.get(3).asStringArray();
    String[] errorServices = ret.get(4).asStringArray();
    Utf8Array protocolName = ret.get(5).asUtf8Array();
    byte[] payload = ret.get(6).asData();
    String replyTrace = ret.get(7).asString();
    // Make sure that the owner understands the protocol.
    Reply reply = null;
    Error error = null;
    if (payload.length > 0) {
        Object retval = decode(protocolName, version, payload);
        if (retval instanceof Reply) {
            reply = (Reply) retval;
        } else {
            error = (Error) retval;
        }
    }
    if (reply == null) {
        reply = new EmptyReply();
    }
    if (error != null) {
        reply.addError(error);
    }
    reply.setRetryDelay(retryDelay);
    for (int i = 0; i < errorCodes.length && i < errorMessages.length; i++) {
        reply.addError(new Error(errorCodes[i], errorMessages[i], errorServices[i].length() > 0 ? errorServices[i] : serviceName));
    }
    if (trace.getLevel() > 0) {
        trace.getRoot().addChild(TraceNode.decode(replyTrace));
    }
    return reply;
}
Also used : Version(com.yahoo.component.Version) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) Utf8Array(com.yahoo.text.Utf8Array) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 5 with Error

use of com.yahoo.messagebus.Error in project vespa by vespa-engine.

the class RPCSendV2 method createResponse.

@Override
protected void createResponse(Values ret, Reply reply, Version version, byte[] payload) {
    ret.add(new Int8Value(CompressionType.NONE.getCode()));
    ret.add(new Int32Value(0));
    ret.add(new DataValue(new byte[0]));
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString(VERSION_F, version.toString());
    root.setDouble(RETRYDELAY_F, reply.getRetryDelay());
    root.setString(PROTOCOL_F, reply.getProtocol().toString());
    root.setData(BLOB_F, payload);
    if (reply.getTrace().getLevel() > 0) {
        root.setString(TRACE_F, reply.getTrace().getRoot().encode());
    }
    if (reply.getNumErrors() > 0) {
        Cursor array = root.setArray(ERRORS_F);
        for (int i = 0; i < reply.getNumErrors(); i++) {
            Cursor e = array.addObject();
            Error mbusE = reply.getError(i);
            e.setLong(CODE_F, mbusE.getCode());
            e.setString(MSG_F, mbusE.getMessage());
            if (mbusE.getService() != null) {
                e.setString(SERVICE_F, mbusE.getService());
            }
        }
    }
    byte[] serializedSlime = BinaryFormat.encode(slime);
    Compressor.Compression compressionResult = compressor.compress(serializedSlime);
    ret.add(new Int8Value(compressionResult.type().getCode()));
    ret.add(new Int32Value(compressionResult.uncompressedSize()));
    ret.add(new DataValue(compressionResult.data()));
}
Also used : DataValue(com.yahoo.jrt.DataValue) Int8Value(com.yahoo.jrt.Int8Value) Int32Value(com.yahoo.jrt.Int32Value) Error(com.yahoo.messagebus.Error) Compressor(com.yahoo.compress.Compressor) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Aggregations

Error (com.yahoo.messagebus.Error)51 Test (org.junit.Test)22 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)10 EmptyReply (com.yahoo.messagebus.EmptyReply)9 Reply (com.yahoo.messagebus.Reply)9 Receptor (com.yahoo.messagebus.test.Receptor)9 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 ParseException (com.yahoo.document.select.parser.ParseException)4 CustomPolicyFactory (com.yahoo.messagebus.routing.test.CustomPolicyFactory)4 BucketId (com.yahoo.document.BucketId)3 Message (com.yahoo.messagebus.Message)3 Version (com.yahoo.component.Version)2 DataValue (com.yahoo.jrt.DataValue)2 Protocol (com.yahoo.messagebus.Protocol)2 Hop (com.yahoo.messagebus.routing.Hop)2 Slime (com.yahoo.slime.Slime)2 Utf8Array (com.yahoo.text.Utf8Array)2 Utf8String (com.yahoo.text.Utf8String)2 IOException (java.io.IOException)2